summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Hilb <stephan@ecshi.net>2019-03-01 22:33:24 +0100
committerwm4 <1387750+wm4@users.noreply.github.com>2019-10-18 12:11:11 +0200
commitacba87e53ffaf964b5fa7bbad9f5185d8c14d8ad (patch)
treec544e5c84e7166bcc43463aca5e8a065e1d4407d
parent60ab82df322bd91fd1c999dfaa3dd1784617734b (diff)
downloadmpv-acba87e53ffaf964b5fa7bbad9f5185d8c14d8ad.tar.bz2
mpv-acba87e53ffaf964b5fa7bbad9f5185d8c14d8ad.tar.xz
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'.
-rw-r--r--player/loadfile.c15
1 files changed, 14 insertions, 1 deletions
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;
}