summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-08 23:02:02 +0200
committerwm4 <wm4@nowhere>2012-09-18 21:08:20 +0200
commitc32082a1a7634e8a5e0bb2551056fe64e357d395 (patch)
treee02f18ad6c2f0b2745b2c54974103cf8552d0680 /mplayer.c
parentc8154630bfc1b35da59e7db8c09e85c4f8d5904c (diff)
downloadmpv-c32082a1a7634e8a5e0bb2551056fe64e357d395.tar.bz2
mpv-c32082a1a7634e8a5e0bb2551056fe64e357d395.tar.xz
mplayer: selectively reset track selection when playing multiple files
Normally, video/audio/sub track selection is persistent across files played in the same mplayer instance. This is wanted, because settings should not be reset across files in general. However, if the track layout of a file is completely different from the previous, this will essentially select random tracks. In this case, keeping the track selection is confusing and unwanted. Reset the track selection to default if the track layout changes. The track layout is determined by number of tracks, track order, default flag, whether the track is an external subtitle, and track language. If a track layout change is detected when playing a new file, the -sid, -aid and -vid options are reset to "auto". This behavior is enabled only if the user selects tracks manually (via keybinds and the "switch_audio" slave properties etc.). If no user interactions take place, options specified on the command line will follow the old behavior.
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/mplayer.c b/mplayer.c
index 0d2d97e5f3..11cb4235ca 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1966,6 +1966,22 @@ static void reinit_subs(struct MPContext *mpctx)
}
}
+static char *track_layout_hash(struct MPContext *mpctx)
+{
+ char *h = talloc_strdup(NULL, "");
+ for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
+ for (int n = 0; n < mpctx->num_tracks; n++) {
+ struct track *track = mpctx->tracks[n];
+ if (track->type != type)
+ continue;
+ h = talloc_asprintf_append_buffer(h, "%d-%d-%d-%d-%s\n", type,
+ track->user_tid, track->default_track, track->is_external,
+ track->lang ? track->lang : "");
+ }
+ }
+ return h;
+}
+
void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
struct track *track)
{
@@ -1997,6 +2013,9 @@ void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
mpctx->opts.sub_id = user_tid;
reinit_subs(mpctx);
}
+
+ talloc_free(mpctx->track_layout_hash);
+ mpctx->track_layout_hash = talloc_steal(mpctx, track_layout_hash(mpctx));
}
struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
@@ -3492,6 +3511,30 @@ static struct track *select_track(struct MPContext *mpctx,
return pick;
}
+// Normally, video/audio/sub track selection is persistent across files. This
+// code resets track selection if the new file has a different track layout.
+static void check_previous_track_selection(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = &mpctx->opts;
+
+ if (!mpctx->track_layout_hash)
+ return;
+
+ char *h = track_layout_hash(mpctx);
+ if (strcmp(h, mpctx->track_layout_hash) != 0) {
+ // Reset selection, but only if they're not "auto" or "off".
+ if (opts->video_id >= 0)
+ mpctx->opts.video_id = -1;
+ if (opts->audio_id >= 0)
+ mpctx->opts.audio_id = -1;
+ if (opts->sub_id >= 0)
+ mpctx->opts.sub_id = -1;
+ talloc_free(mpctx->track_layout_hash);
+ mpctx->track_layout_hash = NULL;
+ }
+ talloc_free(h);
+}
+
static void init_input(struct MPContext *mpctx)
{
mpctx->input = mp_input_init(&mpctx->opts.input);
@@ -3860,6 +3903,8 @@ goto_enable_cache:
open_audiofiles_from_options(mpctx);
open_subfiles_from_options(mpctx);
+ check_previous_track_selection(mpctx);
+
mpctx->current_track[STREAM_VIDEO] =
select_track(mpctx, STREAM_VIDEO, mpctx->opts.video_id, NULL, true);
mpctx->current_track[STREAM_AUDIO] =