From 0a796e98405c2252b58e6ac06b4d395aded568a9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 17 Jul 2020 14:21:42 +0200 Subject: command: add another variant of revert-seek Requested. See manpage additions. Not sure if it actually deserves to be a first class feature, rather than an external script or so. Fixes: #7913 --- DOCS/man/input.rst | 6 ++++++ player/command.c | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index eee5ba8614..16daa1fb82 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -277,6 +277,12 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_). Mark the current time position. The next normal ``revert-seek`` command will seek back to this point, no matter how many seeks happened since last time. + mark-permanent + If set, mark the current position, and do not change the mark position + before the next ``revert-seek`` command that has ``mark`` or + ``mark-permanent`` set (or playback of the current file ends). Until + this happens, ``revert-seek`` will always seek to the marked point. This + flag cannot be combined with ``mark``. Using it without any arguments gives you the default behavior. diff --git a/player/command.c b/player/command.c index dd6efbea86..8a546608eb 100644 --- a/player/command.c +++ b/player/command.c @@ -84,6 +84,7 @@ struct command_ctx { double last_seek_time; double last_seek_pts; double marked_pts; + bool marked_permanent; char **warned_deprecated; int num_warned_deprecated; @@ -4649,11 +4650,14 @@ static void cmd_revert_seek(void *p) double oldpts = cmdctx->last_seek_pts; if (cmdctx->marked_pts != MP_NOPTS_VALUE) oldpts = cmdctx->marked_pts; - if (cmd->args[0].v.i == 1) { + if (cmd->args[0].v.i & 3) { cmdctx->marked_pts = get_current_time(mpctx); + cmdctx->marked_permanent = cmd->args[0].v.i & 1; } else if (oldpts != MP_NOPTS_VALUE) { - cmdctx->last_seek_pts = get_current_time(mpctx); - cmdctx->marked_pts = MP_NOPTS_VALUE; + if (!cmdctx->marked_permanent) { + cmdctx->marked_pts = MP_NOPTS_VALUE; + cmdctx->last_seek_pts = get_current_time(mpctx); + } queue_seek(mpctx, MPSEEK_ABSOLUTE, oldpts, MPSEEK_EXACT, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, OSD_REW); @@ -5794,7 +5798,8 @@ const struct mp_cmd_def mp_cmds[] = { .scalable = true, }, { "revert-seek", cmd_revert_seek, - { {"flags", OPT_FLAGS(v.i, {"mark", 1}), .flags = MP_CMD_OPT_ARG} }, + { {"flags", OPT_FLAGS(v.i, {"mark", 2|0}, {"mark-permanent", 2|1}), + .flags = MP_CMD_OPT_ARG} }, }, { "quit", cmd_quit, { {"code", OPT_INT(v.i), .flags = MP_CMD_OPT_ARG} }, .priv = &(const bool){0} }, @@ -6235,6 +6240,7 @@ static void command_event(struct MPContext *mpctx, int event, void *arg) if (event == MPV_EVENT_START_FILE) { ctx->last_seek_pts = MP_NOPTS_VALUE; ctx->marked_pts = MP_NOPTS_VALUE; + ctx->marked_permanent = false; } if (event == MPV_EVENT_PLAYBACK_RESTART) -- cgit v1.2.3