From 9c530c7ee9ac0641e58ac1203bd46675e8700cc5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 12 May 2018 18:47:43 +0200 Subject: command: make "subprocess" explicitly abortable Now mpv_abort_async_command() can be used to stop the process. --- DOCS/man/input.rst | 2 ++ player/command.c | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 6d05c5fc5d..cadf515567 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -363,6 +363,8 @@ List of Input Commands it was somehow killed or returned an error status has to be queried from the result value. + This command can be asynchronously aborted via API. + ``quit []`` Exit the player. If an argument is given, it's used as process exit code. diff --git a/player/command.c b/player/command.c index cd623c03f4..ffe9683adb 100644 --- a/player/command.c +++ b/player/command.c @@ -5700,15 +5700,16 @@ static void cmd_subprocess(void *p) .capture = {0, cmd->args[3].v.i, cmd->args[4].v.i}, }; - struct mp_cancel *cancel = NULL; - if (playback_only) - cancel = mpctx->playback_abort; + pthread_mutex_lock(&mpctx->abort_lock); + cmd->abort->coupled_to_playback = playback_only; + mp_abort_recheck_locked(mpctx, cmd->abort); + pthread_mutex_unlock(&mpctx->abort_lock); mp_core_unlock(mpctx); char *error = NULL; - int status = mp_subprocess(args, cancel, &ctx, subprocess_stdout, - subprocess_stderr, &error); + int status = mp_subprocess(args, cmd->abort->cancel, &ctx, + subprocess_stdout, subprocess_stderr, &error); mp_core_lock(mpctx); @@ -6156,6 +6157,7 @@ const struct mp_cmd_def mp_cmds[] = { OPT_FLAG("capture_stderr", v.i, 0, OPTDEF_INT(0)), }, .spawn_thread = true, + .can_abort = true, }, { "set", cmd_set, { ARG_STRING, ARG_STRING } }, -- cgit v1.2.3