summaryrefslogtreecommitdiffstats
path: root/player/loadfile.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-19 18:25:54 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:35 +0200
commit8816e1117ee65039dbb5700219ba3537d3e5290e (patch)
tree346500d09a27d91a1cd5c4e987b052e635e64978 /player/loadfile.c
parentc24520b7f3651dbd4cbdffe93a187c3d213ff845 (diff)
downloadmpv-8816e1117ee65039dbb5700219ba3537d3e5290e.tar.bz2
mpv-8816e1117ee65039dbb5700219ba3537d3e5290e.tar.xz
player: change the role of the "stop_play" and "playing" variable
Before this, mpctx->playing was often used to determine whether certain new state could be added to the playback state. In particular this affected external files (which added tracks and demuxers). The variable was checked to prevent that they were added before the corresponding uninit code. We want to make a small part of uninit asynchronous, but mpctx->playing needs to stay in the place where it is. It can't be used for this purpose anymore. Use mpctx->stop_play instead. Make it never have the value 0 outside of loading/playback. On unloading, it obviously has to be non-0. Change some other code in playloop.c to use this, because it seems slightly more correct. But mostly this is preparation for the following commit.
Diffstat (limited to 'player/loadfile.c')
-rw-r--r--player/loadfile.c25
1 files changed, 14 insertions, 11 deletions
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;