summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-18 21:38:17 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commit12d1404b04e90f5357882e5c1048d92305248cb9 (patch)
tree240ab8d9dfa37c63889a5608b7733fa8d5c31780 /player/command.c
parentf9713921a372aa14ea631b0c546d3fbeade32b71 (diff)
downloadmpv-12d1404b04e90f5357882e5c1048d92305248cb9.tar.bz2
mpv-12d1404b04e90f5357882e5c1048d92305248cb9.tar.xz
player: make various commands for managing external tracks abortable
Until now, they could be aborted only by ending playback, and calling mpv_abort_async_command didn't do anything. This requires furthering the mess how playback abort is done. The main reason why mp_cancel exists at all is to avoid that a "frozen" demuxer (blocked on network I/O or whatever) cannot freeze the core. The core should always get its way. Previously, there was a single mp_cancel handle, that could be signaled, and all demuxers would unfreeze. With external files, we might want to abort loading of a certain external file, which automatically means they need a separate mp_cancel. So give every demuxer its own mp_cancel, and "slave" it to whatever parent mp_cancel handles aborting. Since the mpv demuxer API conflates creating the demuxer and reading the file headers, mp_cancel strictly need to be created before the demuxer is created (or we couldn't abort loading). Although we give every demuxer its own mp_cancel (as "enforced" by cancel_and_free_demuxer), it's still rather messy to create/destroy it along with the demuxer.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/player/command.c b/player/command.c
index 9c6bce6aa1..fb8f6f14c5 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4981,8 +4981,10 @@ void run_command(struct MPContext *mpctx, struct mp_cmd *cmd,
assert(cmd->def->can_abort == !!ctx->abort);
- if (ctx->abort)
+ if (ctx->abort) {
+ ctx->abort->coupled_to_playback |= cmd->def->abort_on_playback_end;
mp_abort_add(mpctx, ctx->abort);
+ }
struct MPOpts *opts = mpctx->opts;
ctx->on_osd = cmd->flags & MP_ON_OSD_FLAGS;
@@ -5534,7 +5536,8 @@ static void cmd_track_add(void *p)
return;
}
}
- int first = mp_add_external_file(mpctx, cmd->args[0].v.s, type);
+ int first = mp_add_external_file(mpctx, cmd->args[0].v.s, type,
+ cmd->abort->cancel);
if (first < 0) {
cmd->success = false;
return;
@@ -5598,7 +5601,7 @@ static void cmd_track_reload(void *p)
if (t && t->is_external && t->external_filename) {
char *filename = talloc_strdup(NULL, t->external_filename);
mp_remove_track(mpctx, t);
- nt_num = mp_add_external_file(mpctx, filename, type);
+ nt_num = mp_add_external_file(mpctx, filename, type, cmd->abort->cancel);
talloc_free(filename);
}
@@ -5622,7 +5625,7 @@ static void cmd_rescan_external_files(void *p)
return;
}
- autoload_external_files(mpctx);
+ autoload_external_files(mpctx, cmd->abort->cancel);
if (!cmd->args[0].v.i && mpctx->playback_initialized) {
// somewhat fuzzy and not ideal
struct track *a = select_default_track(mpctx, 0, STREAM_AUDIO);
@@ -6098,6 +6101,8 @@ const struct mp_cmd_def mp_cmds[] = {
},
.priv = &(const int){STREAM_SUB},
.spawn_thread = true,
+ .can_abort = true,
+ .abort_on_playback_end = true,
},
{ "audio-add", cmd_track_add,
{
@@ -6109,6 +6114,8 @@ const struct mp_cmd_def mp_cmds[] = {
},
.priv = &(const int){STREAM_AUDIO},
.spawn_thread = true,
+ .can_abort = true,
+ .abort_on_playback_end = true,
},
{ "sub-remove", cmd_track_remove, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) },
@@ -6119,10 +6126,14 @@ const struct mp_cmd_def mp_cmds[] = {
{ "sub-reload", cmd_track_reload, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) },
.priv = &(const int){STREAM_SUB},
.spawn_thread = true,
+ .can_abort = true,
+ .abort_on_playback_end = true,
},
{ "audio-reload", cmd_track_reload, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) },
.priv = &(const int){STREAM_AUDIO},
.spawn_thread = true,
+ .can_abort = true,
+ .abort_on_playback_end = true,
},
{ "rescan-external-files", cmd_rescan_external_files,
@@ -6132,6 +6143,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"reselect", 0})),
},
.spawn_thread = true,
+ .can_abort = true,
+ .abort_on_playback_end = true,
},
{ "tv-last-channel", cmd_tv_last_channel, },