summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-26 14:01:23 +0200
committerwm4 <wm4@nowhere>2015-05-26 14:01:23 +0200
commit88249baf5bb66e164b17bc53e10441c3c3111e45 (patch)
tree0157e34bc549da73fdcd08a7c8c1b8666d8afad0 /player/command.c
parentbdcd25d3c23b49704f3abe78dc0c523f20a71d45 (diff)
downloadmpv-88249baf5bb66e164b17bc53e10441c3c3111e45.tar.bz2
mpv-88249baf5bb66e164b17bc53e10441c3c3111e45.tar.xz
player: fix crashes when adding external tracks before loading main file
Adding an external audio track before loading the main file didn't work right. For one, mp_switch_track() assumes it is called after the main file is loaded. (The difference is that decoders are only initialized once the main file is loaded, and we avoid doing this before that for whatever reason.) To avoid further messiness, just allow mp_switch_track() to be called at any time. Also make it do what mp_mark_user_track_selection() did, since the latter requires current_track to be set. (One could probably simply allow current_track to be set at this point, but it'd interfere with default track selection anyway and thus would be pointless.) Fixes #1984.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/player/command.c b/player/command.c
index e0259b5038..1fdf6654be 100644
--- a/player/command.c
+++ b/player/command.c
@@ -1795,18 +1795,13 @@ static int property_switch_track(struct m_property *prop, int action, void *arg,
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sarg = arg;
mp_switch_track_n(mpctx, order, type,
- track_next(mpctx, order, type, sarg->inc >= 0 ? +1 : -1, track));
- mp_mark_user_track_selection(mpctx, order, type);
+ track_next(mpctx, order, type, sarg->inc >= 0 ? +1 : -1, track),
+ FLAG_MARK_SELECTION);
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
- if (mpctx->num_sources) {
- track = mp_track_by_tid(mpctx, type, *(int *)arg);
- mp_switch_track_n(mpctx, order, type, track);
- mp_mark_user_track_selection(mpctx, order, type);
- } else {
- mpctx->opts->stream_id[order][type] = *(int *)arg;
- }
+ track = mp_track_by_tid(mpctx, type, *(int *)arg);
+ mp_switch_track_n(mpctx, order, type, track, FLAG_MARK_SELECTION);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);
@@ -1837,7 +1832,7 @@ static int property_switch_track_ff(void *ctx, struct m_property *prop,
}
if (!track && id >= 0)
return M_PROPERTY_ERROR;
- mp_switch_track_n(mpctx, 0, type, track);
+ mp_switch_track_n(mpctx, 0, type, track, 0);
} else {
mpctx->opts->stream_id_ff[type] = *(int *)arg;
}
@@ -1986,11 +1981,11 @@ static int mp_property_program(void *ctx, struct m_property *prop,
return M_PROPERTY_ERROR;
}
mp_switch_track(mpctx, STREAM_VIDEO,
- find_track_by_demuxer_id(mpctx, STREAM_VIDEO, prog.vid));
+ find_track_by_demuxer_id(mpctx, STREAM_VIDEO, prog.vid), 0);
mp_switch_track(mpctx, STREAM_AUDIO,
- find_track_by_demuxer_id(mpctx, STREAM_AUDIO, prog.aid));
+ find_track_by_demuxer_id(mpctx, STREAM_AUDIO, prog.aid), 0);
mp_switch_track(mpctx, STREAM_SUB,
- find_track_by_demuxer_id(mpctx, STREAM_VIDEO, prog.sid));
+ find_track_by_demuxer_id(mpctx, STREAM_VIDEO, prog.sid), 0);
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = (struct m_option){
@@ -4583,8 +4578,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
struct track *t = find_track_with_url(mpctx, type,
cmd->args[0].v.s);
if (t) {
- mp_switch_track(mpctx, t->type, t);
- mp_mark_user_track_selection(mpctx, 0, t->type);
+ mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION);
return 0;
}
}
@@ -4594,8 +4588,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
if (cmd->args[1].v.i == 1) {
t->no_default = true;
} else {
- mp_switch_track(mpctx, t->type, t);
- mp_mark_user_track_selection(mpctx, 0, t->type);
+ mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION);
}
char *title = cmd->args[2].v.s;
if (title && title[0])
@@ -4630,7 +4623,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
talloc_free(filename);
}
if (nt) {
- mp_switch_track(mpctx, nt->type, nt);
+ mp_switch_track(mpctx, nt->type, nt, 0);
print_track_list(mpctx);
return 0;
}
@@ -4645,10 +4638,10 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
// somewhat fuzzy and not ideal
struct track *a = select_default_track(mpctx, 0, STREAM_AUDIO);
if (a && a->is_external)
- mp_switch_track(mpctx, STREAM_AUDIO, a);
+ mp_switch_track(mpctx, STREAM_AUDIO, a, 0);
struct track *s = select_default_track(mpctx, 0, STREAM_SUB);
if (s && s->is_external)
- mp_switch_track(mpctx, STREAM_SUB, s);
+ mp_switch_track(mpctx, STREAM_SUB, s, 0);
print_track_list(mpctx);
}