command: fix some fringe play-dir behavior

This is pretty obscure but if you screw around with the play-dir option
to essentially create a ping-pong loop; mpv will get hit by an assertion
error. What's happening here is that changing the play-dir always
requires a seek. This is handled in player/command along with the other
runtime option changes. However, queue_seek can actually clear the value
of mpctx->stop_play if the file is ending. So while loadfile is
terminating playback and the play-dir gets changed, the value of
mpctx->stop_play gets cleared because of seek. This then hits that
assertion later when mpv tries to finish the file.

The fix is to just add some weird logic to play-dir in player/command.
We have to be sure that mpctx->play_dir matches the new direction
immediately when we get the change so explictly set it here and don't
wait for it later. Secondly, keep the old value of mpctx->stop_play
before the seek and restore it afterwards. This ensures that termination
still happens cleanly and allows the ping-pong loop to work. Fixes #10782
This commit is contained in:
Dudemanguy 2023-08-09 20:11:07 -05:00
parent 02a80f850b
commit 692ccca3a2
1 changed files with 6 additions and 0 deletions

View File

@ -6928,8 +6928,14 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
if (opt_ptr == &opts->play_dir) {
if (mpctx->play_dir != opts->play_dir) {
// Some weird things for play_dir.
// 1. The option must be set before we seek.
// 2. queue_seek can change the stop_play value; always keep the old one.
mpctx->play_dir = opts->play_dir;
int old_stop_play = mpctx->stop_play;
queue_seek(mpctx, MPSEEK_ABSOLUTE, get_current_time(mpctx),
MPSEEK_EXACT, 0);
mpctx->stop_play = old_stop_play;
}
}