player: avoid duplicate track auto selection

Since a track may not be selected twice, it makes sense e.g. for
secondary subtitles to select the next best match and avoid the
duplicate selection.
This allows for example `--slang=en,ja --secondary-sid=auto` to select
'en' as primary and 'ja' as secondary without needing to know the actual
sid for 'ja'.
This commit is contained in:
Stephan Hilb 2019-03-01 22:33:24 +01:00 committed by wm4
parent 60ab82df32
commit acba87e53f
1 changed files with 14 additions and 1 deletions

View File

@ -495,12 +495,23 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs,
}
return t1->user_tid <= t2->user_tid;
}
static bool duplicate_track(struct MPContext *mpctx, int order,
enum stream_type type, struct track *track)
{
for (int i = 0; i < order; i++) {
if (mpctx->current_track[i][type] == track)
return true;
}
return false;
}
struct track *select_default_track(struct MPContext *mpctx, int order,
enum stream_type type)
{
struct MPOpts *opts = mpctx->opts;
int tid = opts->stream_id[order][type];
char **langs = order == 0 ? opts->stream_lang[type] : NULL;
char **langs = opts->stream_lang[type];
if (tid == -2)
return NULL;
bool select_fallback = type == STREAM_VIDEO || type == STREAM_AUDIO;
@ -513,6 +524,8 @@ struct track *select_default_track(struct MPContext *mpctx, int order,
return track;
if (track->no_auto_select)
continue;
if (duplicate_track(mpctx, order, type, track))
continue;
if (!pick || compare_track(track, pick, langs, mpctx->opts))
pick = track;
}