Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadfile: fix --loop-playlist=N with --prefetch-playlist #15296

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -5636,7 +5636,7 @@ static void cmd_playlist_next_prev(void *p)
int dir = *(int *)cmd->priv;
int force = cmd->args[0].v.i;

struct playlist_entry *e = mp_next_file(mpctx, dir, force);
struct playlist_entry *e = mp_next_file(mpctx, dir, force, true);
if (!e && !force) {
cmd->success = false;
return;
Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer);
bool mp_remove_track(struct MPContext *mpctx, struct track *track);
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
bool force);
bool force, bool update_loop);
void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
void mp_play_files(struct MPContext *mpctx);
void update_demuxer_properties(struct MPContext *mpctx);
Expand Down
20 changes: 12 additions & 8 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,11 +1250,11 @@ static void open_demux_reentrant(struct MPContext *mpctx)

void prefetch_next(struct MPContext *mpctx)
{
if (!mpctx->opts->prefetch_open)
if (!mpctx->opts->prefetch_open || mpctx->open_active)
return;

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

if (playlist_prev_continue) {
struct playlist_entry *e = mp_next_file(mpctx, -1, false);
struct playlist_entry *e = mp_next_file(mpctx, -1, false, true);
if (e) {
mp_set_playlist_entry(mpctx, e);
play_current_file(mpctx);
Expand All @@ -1926,18 +1926,22 @@ static void play_current_file(struct MPContext *mpctx)
// it can have side-effects and mutate mpctx.
// direction: -1 (previous) or +1 (next)
// force: if true, don't skip playlist entries marked as failed
// update_loop: whether to decrement --loop-playlist=N if it was specified
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
bool force)
bool force, bool update_loop)
{
struct playlist_entry *next = playlist_get_next(mpctx->playlist, direction);
if (next && direction < 0 && !force)
next->playlist_prev_attempt = true;
if (!next && mpctx->opts->loop_times != 1) {
if (direction > 0) {
if (mpctx->opts->shuffle)
if (mpctx->opts->shuffle) {
if (!update_loop)
return NULL;
playlist_shuffle(mpctx->playlist);
}
next = playlist_get_first(mpctx->playlist);
if (next && mpctx->opts->loop_times > 1) {
if (next && mpctx->opts->loop_times > 1 && update_loop) {
mpctx->opts->loop_times--;
m_config_notify_change_opt_ptr(mpctx->mconfig,
&mpctx->opts->loop_times);
Expand Down Expand Up @@ -1996,7 +2000,7 @@ void mp_play_files(struct MPContext *mpctx)
if (mpctx->stop_play == PT_NEXT_ENTRY || mpctx->stop_play == PT_ERROR ||
mpctx->stop_play == AT_END_OF_FILE)
{
new_entry = mp_next_file(mpctx, +1, false);
new_entry = mp_next_file(mpctx, +1, false, true);
} else if (mpctx->stop_play == PT_CURRENT_ENTRY) {
new_entry = mpctx->playlist->current;
}
Expand Down
Loading