Skip to content

Commit 065933f

Browse files
committed
loadfile: fix --loop-playlist=N with --prefetch-playlist
With --prefetch-playlist and --loop-playlist, mp_next_file() is called continously since the last second of playback or when viewing an image, which decreases --loop-playlist=N to 1. Fix this by adding a flag to mp_next_file() to specify whether to decrement --loop-playlist=N. The first playlist entry is still prefetched when it's the next one, but without decrementing --loop-playlist=N.
1 parent ca7aeb7 commit 065933f

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

player/command.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5636,7 +5636,7 @@ static void cmd_playlist_next_prev(void *p)
56365636
int dir = *(int *)cmd->priv;
56375637
int force = cmd->args[0].v.i;
56385638

5639-
struct playlist_entry *e = mp_next_file(mpctx, dir, force);
5639+
struct playlist_entry *e = mp_next_file(mpctx, dir, force, true);
56405640
if (!e && !force) {
56415641
cmd->success = false;
56425642
return;

player/core.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
531531
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer);
532532
bool mp_remove_track(struct MPContext *mpctx, struct track *track);
533533
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
534-
bool force);
534+
bool force, bool update_loop);
535535
void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
536536
void mp_play_files(struct MPContext *mpctx);
537537
void update_demuxer_properties(struct MPContext *mpctx);

player/loadfile.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ void prefetch_next(struct MPContext *mpctx)
12531253
if (!mpctx->opts->prefetch_open)
12541254
return;
12551255

1256-
struct playlist_entry *new_entry = mp_next_file(mpctx, +1, false);
1256+
struct playlist_entry *new_entry = mp_next_file(mpctx, +1, false, false);
12571257
if (new_entry && !mpctx->open_active && new_entry->filename) {
12581258
MP_VERBOSE(mpctx, "Prefetching: %s\n", new_entry->filename);
12591259
start_open(mpctx, new_entry->filename, new_entry->stream_flags, true);
@@ -1914,7 +1914,7 @@ static void play_current_file(struct MPContext *mpctx)
19141914
process_hooks(mpctx, "on_after_end_file");
19151915

19161916
if (playlist_prev_continue) {
1917-
struct playlist_entry *e = mp_next_file(mpctx, -1, false);
1917+
struct playlist_entry *e = mp_next_file(mpctx, -1, false, true);
19181918
if (e) {
19191919
mp_set_playlist_entry(mpctx, e);
19201920
play_current_file(mpctx);
@@ -1926,18 +1926,19 @@ static void play_current_file(struct MPContext *mpctx)
19261926
// it can have side-effects and mutate mpctx.
19271927
// direction: -1 (previous) or +1 (next)
19281928
// force: if true, don't skip playlist entries marked as failed
1929+
// update_loop: whether to decrement --loop-playlist=N if it was specified
19291930
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
1930-
bool force)
1931+
bool force, bool update_loop)
19311932
{
19321933
struct playlist_entry *next = playlist_get_next(mpctx->playlist, direction);
19331934
if (next && direction < 0 && !force)
19341935
next->playlist_prev_attempt = true;
19351936
if (!next && mpctx->opts->loop_times != 1) {
19361937
if (direction > 0) {
1937-
if (mpctx->opts->shuffle)
1938+
if (mpctx->opts->shuffle && update_loop)
19381939
playlist_shuffle(mpctx->playlist);
19391940
next = playlist_get_first(mpctx->playlist);
1940-
if (next && mpctx->opts->loop_times > 1) {
1941+
if (next && mpctx->opts->loop_times > 1 && update_loop) {
19411942
mpctx->opts->loop_times--;
19421943
m_config_notify_change_opt_ptr(mpctx->mconfig,
19431944
&mpctx->opts->loop_times);
@@ -1996,7 +1997,7 @@ void mp_play_files(struct MPContext *mpctx)
19961997
if (mpctx->stop_play == PT_NEXT_ENTRY || mpctx->stop_play == PT_ERROR ||
19971998
mpctx->stop_play == AT_END_OF_FILE)
19981999
{
1999-
new_entry = mp_next_file(mpctx, +1, false);
2000+
new_entry = mp_next_file(mpctx, +1, false, true);
20002001
} else if (mpctx->stop_play == PT_CURRENT_ENTRY) {
20012002
new_entry = mpctx->playlist->current;
20022003
}

0 commit comments

Comments
 (0)