From f411f3145ba2f6eebc658917d0879d5e573bbdf0 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Tue, 4 Jun 2024 21:51:03 +0200 Subject: [PATCH] player: don't decrement --loop-file=N and add remaining-file-loops This stops decreasing numerical values of --loop-file on each iteration so that loop-file=N loops every playlist entry without having to add --loop-file to --reset-on-next-file. The current behavior confuses users as seen in: https://github.com/mpv-player/mpv/issues/2481 https://github.com/mpv-player/mpv/issues/5943 https://github.com/mpv-player/mpv/issues/11291 https://github.com/mpv-player/mpv/issues/13860 https://www.reddit.com/r/mpv/comments/rcwnrw/looping_each_file_n_times_in_a_playlist/ Also options are supposed to reflect the value configured by the user and not change on their own. A remaining-file-loops property is exposed as a replacement to check how many loops are left. --- DOCS/interface-changes/loop.txt | 2 ++ DOCS/man/input.rst | 6 ++++++ player/command.c | 14 +++++++++++++- player/core.h | 2 ++ player/loadfile.c | 3 +++ player/playloop.c | 8 ++++---- 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 DOCS/interface-changes/loop.txt diff --git a/DOCS/interface-changes/loop.txt b/DOCS/interface-changes/loop.txt new file mode 100644 index 0000000000..624a85b682 --- /dev/null +++ b/DOCS/interface-changes/loop.txt @@ -0,0 +1,2 @@ +numerical values of `--loop-file` no longer decrease on each iteration +add `remaining-file-loops` property as a replacement to get the remaining loop count diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 6d527cddec..91510b6bd0 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2142,6 +2142,12 @@ Property list ``playback-time/full`` ``playback-time`` with milliseconds. +``remaining-file-loops`` + How many more times the current file is going to be looped. This is + initialized from the value of ``--loop-file``. This counts the number of + times it causes the player to seek to the beginning of the file, so it is 0 + the last the time is played. -1 corresponds to infinity. + ``chapter`` (RW) Current chapter number. The number of the first chapter is 0. diff --git a/player/command.c b/player/command.c index cd69636976..ae9b39605d 100644 --- a/player/command.c +++ b/player/command.c @@ -869,6 +869,13 @@ static int mp_property_playtime_remaining(void *ctx, struct m_property *prop, return property_time(action, arg, remaining / speed); } +static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + return m_property_int_ro(action, arg, mpctx->remaining_file_loops); +} + /// Current chapter (RW) static int mp_property_chapter(void *ctx, struct m_property *prop, int action, void *arg) @@ -3999,7 +4006,7 @@ static const struct m_property mp_properties_base[] = { {"audio-pts", mp_property_audio_pts}, {"playtime-remaining", mp_property_playtime_remaining}, M_PROPERTY_ALIAS("playback-time", "time-pos"), - {"chapter", mp_property_chapter}, + {"remaining-file-loops", mp_property_remaining_file_loops}, {"edition", mp_property_edition}, {"current-edition", mp_property_current_edition}, {"chapters", mp_property_chapters}, @@ -7484,6 +7491,11 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, mpctx->stop_play = PT_CURRENT_ENTRY; } + if (opt_ptr == &opts->loop_file) { + mpctx->remaining_file_loops = opts->loop_file; + mp_notify_property(mpctx, "remaining-file-loops"); + } + if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1]) { update_ab_loop_clip(mpctx); // Update if visible diff --git a/player/core.h b/player/core.h index 28acc26c5d..ccef0d92e6 100644 --- a/player/core.h +++ b/player/core.h @@ -421,6 +421,8 @@ typedef struct MPContext { int max_frames; bool playing_msg_shown; + int remaining_file_loops; + bool paused_for_cache; bool demux_underrun; double cache_stop_time; diff --git a/player/loadfile.c b/player/loadfile.c index f819074a2b..3c32f53704 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1633,6 +1633,9 @@ static void play_current_file(struct MPContext *mpctx) load_per_file_options(mpctx->mconfig, mpctx->playing->params, mpctx->playing->num_params); + mpctx->remaining_file_loops = mpctx->opts->loop_file; + mp_notify_property(mpctx, "remaining-file-loops"); + mpctx->max_frames = opts->play_frames; handle_force_window(mpctx, false); diff --git a/player/playloop.c b/player/playloop.c index ef73bdbbb8..9f3456d535 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -901,10 +901,10 @@ static void handle_loop_file(struct MPContext *mpctx) } target = ab[0]; prec = MPSEEK_EXACT; - } else if (opts->loop_file) { - if (opts->loop_file > 0) { - opts->loop_file--; - m_config_notify_change_opt_ptr(mpctx->mconfig, &opts->loop_file); + } else if (mpctx->remaining_file_loops) { + if (mpctx->remaining_file_loops > 0) { + mpctx->remaining_file_loops--; + mp_notify_property(mpctx, "remaining-file-loops"); } target = get_start_time(mpctx, mpctx->play_dir); }