diff options
-rw-r--r-- | player/command.c | 4 | ||||
-rw-r--r-- | player/core.h | 5 | ||||
-rw-r--r-- | player/loadfile.c | 25 | ||||
-rw-r--r-- | player/main.c | 1 | ||||
-rw-r--r-- | player/playloop.c | 6 |
5 files changed, 23 insertions, 18 deletions
diff --git a/player/command.c b/player/command.c index 4c46203ab4..efd1304720 100644 --- a/player/command.c +++ b/player/command.c @@ -5522,7 +5522,7 @@ static void cmd_track_add(void *p) struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv; - if (!mpctx->playing) { + if (mpctx->stop_play) { cmd->success = false; return; } @@ -5623,7 +5623,7 @@ static void cmd_rescan_external_files(void *p) struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; - if (!mpctx->playing) { + if (mpctx->stop_play) { cmd->success = false; return; } diff --git a/player/core.h b/player/core.h index 39ea2fe07e..193537652b 100644 --- a/player/core.h +++ b/player/core.h @@ -37,12 +37,13 @@ // definitions used internally by the core player code enum stop_play_reason { - KEEP_PLAYING = 0, // must be 0, numeric values of others do not matter + KEEP_PLAYING = 0, // playback of a file is actually going on + // must be 0, numeric values of others do not matter AT_END_OF_FILE, // file has ended, prepare to play next // also returned on unrecoverable playback errors PT_NEXT_ENTRY, // prepare to play next entry in playlist PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current - PT_STOP, // stop playback, clear playlist + PT_STOP, // stop playback, or transient state when going to next PT_QUIT, // stop playback, quit player PT_ERROR, // play next playlist entry (due to an error) }; diff --git a/player/loadfile.c b/player/loadfile.c index 39ba179c02..a28bf491b4 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -662,7 +662,7 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename, // The command could have overlapped with playback exiting. (We don't care // if playback has started again meanwhile - weird, but not a problem.) - if (!mpctx->playing) + if (mpctx->stop_play) goto err_out; if (!demuxer) @@ -1248,6 +1248,8 @@ static void play_current_file(struct MPContext *mpctx) struct MPOpts *opts = mpctx->opts; double playback_start = -1e100; + assert(mpctx->stop_play); + mp_notify(mpctx, MPV_EVENT_START_FILE, NULL); mp_cancel_reset(mpctx->playback_abort); @@ -1473,16 +1475,16 @@ static void play_current_file(struct MPContext *mpctx) terminate_playback: - update_core_idle_state(mpctx); - - process_hooks(mpctx, "on_unload"); - - if (mpctx->stop_play == KEEP_PLAYING) - mpctx->stop_play = AT_END_OF_FILE; + if (!mpctx->stop_play) + mpctx->stop_play = PT_ERROR; if (mpctx->stop_play != AT_END_OF_FILE) clear_audio_output_buffers(mpctx); + update_core_idle_state(mpctx); + + process_hooks(mpctx, "on_unload"); + if (mpctx->step_frames) opts->pause = 1; @@ -1550,8 +1552,6 @@ terminate_playback: if (mpctx->playing) playlist_entry_unref(mpctx->playing); - // Note: a lot of things assume that the core won't be unlocked between - // uninitializing various playback-only resources (such as tracks). mpctx->playing = NULL; talloc_free(mpctx->filename); mpctx->filename = NULL; @@ -1564,6 +1564,8 @@ terminate_playback: } else { mpctx->files_played++; } + + assert(mpctx->stop_play); } // Determine the next file to play. Note that if this function returns non-NULL, @@ -1629,6 +1631,7 @@ void mp_play_files(struct MPContext *mpctx) prepare_playlist(mpctx, mpctx->playlist); for (;;) { + assert(mpctx->stop_play); idle_loop(mpctx); if (mpctx->stop_play == PT_QUIT) break; @@ -1639,14 +1642,14 @@ void mp_play_files(struct MPContext *mpctx) struct playlist_entry *new_entry = mpctx->playlist->current; if (mpctx->stop_play == PT_NEXT_ENTRY || mpctx->stop_play == PT_ERROR || - mpctx->stop_play == AT_END_OF_FILE || !mpctx->stop_play) + mpctx->stop_play == AT_END_OF_FILE || mpctx->stop_play == PT_STOP) { new_entry = mp_next_file(mpctx, +1, false, true); } mpctx->playlist->current = new_entry; mpctx->playlist->current_was_replaced = false; - mpctx->stop_play = 0; + mpctx->stop_play = PT_STOP; if (!mpctx->playlist->current && mpctx->opts->player_idle_mode < 2) break; diff --git a/player/main.c b/player/main.c index 6d2b862e02..6a7fc68004 100644 --- a/player/main.c +++ b/player/main.c @@ -283,6 +283,7 @@ struct MPContext *mp_create(void) .dispatch = mp_dispatch_create(mpctx), .playback_abort = mp_cancel_new(mpctx), .thread_pool = mp_thread_pool_create(mpctx, 0, 1, 30), + .stop_play = PT_STOP, }; pthread_mutex_init(&mpctx->abort_lock, NULL); diff --git a/player/playloop.c b/player/playloop.c index f51ddb5e5c..65086b2965 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -127,8 +127,8 @@ void update_core_idle_state(struct MPContext *mpctx) { bool eof = mpctx->video_status == STATUS_EOF && mpctx->audio_status == STATUS_EOF; - bool active = !mpctx->paused && mpctx->restart_complete && mpctx->playing && - mpctx->in_playloop && !eof; + bool active = !mpctx->paused && mpctx->restart_complete && + mpctx->stop_play && mpctx->in_playloop && !eof; if (mpctx->playback_active != active) { mpctx->playback_active = active; @@ -873,7 +873,7 @@ int handle_force_window(struct MPContext *mpctx, bool force) { // True if we're either in idle mode, or loading of the file has finished. // It's also set via force in some stages during file loading. - bool act = !mpctx->playing || mpctx->playback_initialized || force; + bool act = mpctx->stop_play || mpctx->playback_initialized || force; // On the other hand, if a video track is selected, but no video is ever // decoded on it, then create the window. |