From acba87e53ffaf964b5fa7bbad9f5185d8c14d8ad Mon Sep 17 00:00:00 2001 From: Stephan Hilb Date: Fri, 1 Mar 2019 22:33:24 +0100 Subject: 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'. --- player/loadfile.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/player/loadfile.c b/player/loadfile.c index 58a60faaca..747793b645 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -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; } -- cgit v1.2.3