Skip to content

Commit 7858e1f

Browse files
guidocellakasper93
authored andcommitted
command: remember the language when reloading tracks
In 5871ba8 I took the language from the filename when reloading tracks noting "that backing up t->lang and restoring it if nt->lang is NULL would work incorrectly when lang is in the stream and it is removed before reloading", but actually external tracks don't have language in the stream, it is set in the container, and reload commands only affect external tracks. So just back up the language before reloading and then restore the old language. This preserves the language after reloading when it is not in the filename but it was specified manually in an add command, e.g. sub-add foo.srt '' '' en. Hearing impaired, forced and default flags were already being set from their values from before reloading the track, so setting them again from the filename only caused the same issue that they would get unset if they were manually added with add commands. We still don't restore the old language if nt->lang is already set for the edge case of doing something like sub-add foo.mkv and changing the foo.mkv's sub track language before reloading.
1 parent 2c893e8 commit 7858e1f

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

player/command.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6425,9 +6425,11 @@ static void cmd_track_reload(void *p)
64256425

64266426
struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i);
64276427
int nt_num = -1;
6428+
char *lang = NULL;
64286429

64296430
if (t && t->is_external && t->external_filename) {
64306431
char *filename = talloc_strdup(NULL, t->external_filename);
6432+
lang = talloc_steal(NULL, t->lang);
64316433
enum track_flags flags = 0;
64326434
flags |= t->attached_picture ? TRACK_ATTACHED_PICTURE : 0;
64336435
flags |= t->hearing_impaired_track ? TRACK_HEARING_IMPAIRED : 0;
@@ -6442,19 +6444,16 @@ static void cmd_track_reload(void *p)
64426444

64436445
if (nt_num < 0) {
64446446
cmd->success = false;
6447+
talloc_free(lang);
64456448
return;
64466449
}
64476450

64486451
struct track *nt = mpctx->tracks[nt_num];
64496452

6450-
if (!nt->lang) {
6451-
enum track_flags flags = 0;
6452-
bstr lang = mp_guess_lang_from_filename(bstr0(nt->external_filename), NULL,
6453-
&flags);
6454-
nt->lang = bstrto0(nt, lang);
6455-
nt->hearing_impaired_track = flags & TRACK_HEARING_IMPAIRED;
6456-
nt->forced_track = flags & TRACK_FORCED;
6457-
nt->default_track = flags & TRACK_DEFAULT;
6453+
if (nt->lang) {
6454+
talloc_free(lang);
6455+
} else {
6456+
nt->lang = talloc_steal(nt, lang);
64586457
}
64596458

64606459
mp_switch_track(mpctx, nt->type, nt, 0);

0 commit comments

Comments
 (0)