Skip to content

Commit c2882c3

Browse files
filip-hejsekkasper93
authored andcommitted
player/loadfile: never autoselect tracks with wrong PID
Currently, we prefer selecting a track that matches the video program ID, but can fall back on a track with a different program ID when there is no such track or when no such track matches subs-fallback criteria. Change this to instead select no track when only tracks with wrong PID are available. Program ID will now act as a filter, not as a preference, and only files with either matching or unset PID will be considered for autoselect. Also, ignore the program ID of external tracks, as it doesn't make much sense to compare PIDs from different files.
1 parent 3e12e6f commit c2882c3

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

player/loadfile.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer)
473473
*/
474474
// Return whether t1 is preferred over t2
475475
static bool compare_track(struct track *t1, struct track *t2, char **langs, bool os_langs,
476-
struct MPOpts *opts, int preferred_program)
476+
struct MPOpts *opts)
477477
{
478478
bool sub = t2->type == STREAM_SUB;
479479
bool ext1 = t1->is_external && !t1->no_default;
@@ -486,11 +486,6 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs, bool
486486
}
487487
if (t1->auto_loaded != t2->auto_loaded)
488488
return !t1->auto_loaded;
489-
if (preferred_program != -1 && t1->program_id != -1 && t2->program_id != -1) {
490-
if ((t1->program_id == preferred_program) !=
491-
(t2->program_id == preferred_program))
492-
return t1->program_id == preferred_program;
493-
}
494489
int l1 = mp_match_lang(langs, t1->lang), l2 = mp_match_lang(langs, t2->lang);
495490
if (!os_langs && l1 != l2)
496491
return l1 > l2;
@@ -605,6 +600,9 @@ struct track *select_default_track(struct MPContext *mpctx, int order,
605600
continue;
606601
if (!opts->autoload_files && track->is_external)
607602
continue;
603+
if (preferred_program != -1 && !track->is_external &&
604+
track->program_id != -1 && track->program_id != preferred_program)
605+
continue;
608606
if (duplicate_track(mpctx, order, type, track))
609607
continue;
610608
if (sub) {
@@ -623,7 +621,7 @@ struct track *select_default_track(struct MPContext *mpctx, int order,
623621
continue;
624622
track->forced_select = forced;
625623
}
626-
if (!pick || compare_track(track, pick, langs, os_langs, mpctx->opts, preferred_program)) {
624+
if (!pick || compare_track(track, pick, langs, os_langs, mpctx->opts)) {
627625
pick = track;
628626
}
629627
}

test/libmpv_test_track_selection.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,13 @@ static void test_track_selection(char *file, char *path)
309309
check_string("track-list/1/selected", "no");
310310
check_string("track-list/3/selected", "no");
311311

312-
// because subs-fallback=default, the jpn track cannot be chosen
313-
// so we choose the eng track despite it having the wrong program ID
312+
// the eng track cannot be selected due to having the wrong program ID
313+
// because subs-fallback=default, the jpn track cannot be chosen either
314+
// so we get no subs
314315
set_property_string("slang", "eng");
315316
reload_file(path);
316-
check_string("current-tracks/sub/lang", "eng");
317-
check_string("track-list/1/selected", "yes");
317+
check_string("track-list/1/selected", "no");
318+
check_string("track-list/3/selected", "no");
318319

319320
// the jpn track is selected to match video program ID
320321
// even though the user requested eng subtitles

0 commit comments

Comments
 (0)