Skip to content

Commit

Permalink
player: don't decrement --loop-file=N and add remaining-file-loops
Browse files Browse the repository at this point in the history
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:

#2481
#5943
#11291
#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.
  • Loading branch information
guidocella committed Jun 5, 2024
1 parent e763072 commit 8190894
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions DOCS/interface-changes/loop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numerical values of `--loop-file` no longer decrease on each iteration
add `remaining-file-loops` property
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,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.

``chapter`` (RW)
Current chapter number. The number of the first chapter is 0.

Expand Down
15 changes: 15 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,15 @@ static int mp_property_playback_time(void *ctx, struct m_property *prop,
return property_time(action, arg, get_playback_time(mpctx));
}

static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (mpctx->remaining_file_loops == -1)
return m_property_double_ro(action, arg, INFINITY);
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)
Expand Down Expand Up @@ -4005,6 +4014,7 @@ static const struct m_property mp_properties_base[] = {
{"audio-pts", mp_property_audio_pts},
{"playtime-remaining", mp_property_playtime_remaining},
{"playback-time", mp_property_playback_time},
{"remaining-file-loops", mp_property_remaining_file_loops},
{"chapter", mp_property_chapter},
{"edition", mp_property_edition},
{"current-edition", mp_property_current_edition},
Expand Down Expand Up @@ -7496,6 +7506,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
Expand Down
2 changes: 2 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,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;
Expand Down
3 changes: 3 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,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);
Expand Down
8 changes: 4 additions & 4 deletions player/playloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8190894

Please sign in to comment.