From b586bc2dbec6495e65ef1a34045f6d66a7112d9d Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 14 Apr 2017 18:56:03 +0200 Subject: player: fix core-idle and eof-reached update notifcations Make mpv_observe_property() work correctly on them even with --keep-open-pause=no. This also changes the situations in which the screensaver is enabled/disabled subtly. --- player/command.c | 8 ++++---- player/command.h | 1 + player/core.h | 5 ++++- player/loadfile.c | 4 +++- player/playloop.c | 30 +++++++++++++++++++++++++----- 5 files changed, 37 insertions(+), 11 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index ab2d43984a..73081e89f9 100644 --- a/player/command.c +++ b/player/command.c @@ -1503,8 +1503,7 @@ static int mp_property_core_idle(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - bool idle = mpctx->paused || !mpctx->restart_complete || !mpctx->playing; - return m_property_flag_ro(action, arg, idle); + return m_property_flag_ro(action, arg, !mpctx->playback_active); } static int mp_property_idle(void *ctx, struct m_property *prop, @@ -4093,8 +4092,8 @@ static const char *const *const mp_event_property_change[] = { E(MPV_EVENT_TRACK_SWITCHED, "vid", "video", "aid", "audio", "sid", "sub", "secondary-sid"), E(MPV_EVENT_IDLE, "*"), - E(MPV_EVENT_PAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), - E(MPV_EVENT_UNPAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), + E(MPV_EVENT_PAUSE, "pause"), + E(MPV_EVENT_UNPAUSE, "pause"), E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync", "percent-pos", "time-remaining", "playtime-remaining", "playback-time", "estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count", @@ -4126,6 +4125,7 @@ static const char *const *const mp_event_property_change[] = { "fullscreen"), E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", "playlist-count", "playlist/count"), + E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"), }; #undef E diff --git a/player/command.h b/player/command.h index 27a4d39913..75ac687332 100644 --- a/player/command.h +++ b/player/command.h @@ -56,6 +56,7 @@ enum { MP_EVENT_WIN_RESIZE, MP_EVENT_WIN_STATE, MP_EVENT_CHANGE_PLAYLIST, + MP_EVENT_CORE_IDLE, }; bool mp_hook_test_completion(struct MPContext *mpctx, char *type); diff --git a/player/core.h b/player/core.h index 1e1c7f0baa..b9fa706f7d 100644 --- a/player/core.h +++ b/player/core.h @@ -415,7 +415,9 @@ typedef struct MPContext { int last_chapter_seek; double last_chapter_pts; - bool paused; + bool paused; // internal pause state + bool playback_active; // not paused, restarting, loading, unloading + // step this many frames, then pause int step_frames; // Counted down each frame, stop playback if 0 is reached. (-1 = disable) @@ -560,6 +562,7 @@ double get_relative_time(struct MPContext *mpctx); void reset_playback_state(struct MPContext *mpctx); void set_pause_state(struct MPContext *mpctx, bool user_pause); void update_internal_pause_state(struct MPContext *mpctx); +void update_core_idle_state(struct MPContext *mpctx); void add_step_frame(struct MPContext *mpctx, int dir); void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount, enum seek_precision exact, int flags); diff --git a/player/loadfile.c b/player/loadfile.c index 1542e16e49..1aa4c4a49d 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1281,6 +1281,9 @@ reopen_file: terminate_playback: + mpctx->playback_active = false; + update_core_idle_state(mpctx); + process_unload_hooks(mpctx); if (mpctx->stop_play == KEEP_PLAYING) @@ -1306,7 +1309,6 @@ terminate_playback: uninit_audio_out(mpctx); mpctx->playback_initialized = false; - update_screensaver_state(mpctx); if (mpctx->stop_play == PT_RELOAD_FILE) { mpctx->stop_play = KEEP_PLAYING; diff --git a/player/playloop.c b/player/playloop.c index 9f3abefa78..2c3143ab61 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -120,6 +120,22 @@ double get_relative_time(struct MPContext *mpctx) return delta * 0.000001; } +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 && !eof; + + if (mpctx->playback_active != active) { + mpctx->playback_active = active; + + update_screensaver_state(mpctx); + + mp_notify(mpctx, MP_EVENT_CORE_IDLE, NULL); + } +} + // The value passed here is the new value for mpctx->opts->pause void set_pause_state(struct MPContext *mpctx, bool user_pause) { @@ -159,10 +175,10 @@ void set_pause_state(struct MPContext *mpctx, bool user_pause) } } - if (send_update) { - update_screensaver_state(mpctx); + update_core_idle_state(mpctx); + + if (send_update) mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0); - } } void update_internal_pause_state(struct MPContext *mpctx) @@ -175,8 +191,7 @@ void update_screensaver_state(struct MPContext *mpctx) if (!mpctx->video_out) return; - bool saver_state = mpctx->opts->pause || !mpctx->opts->stop_screensaver || - !mpctx->playback_initialized; + bool saver_state = !mpctx->playback_active || !mpctx->opts->stop_screensaver; vo_control_async(mpctx->video_out, saver_state ? VOCTRL_RESTORE_SCREENSAVER : VOCTRL_KILL_SCREENSAVER, NULL); } @@ -227,6 +242,8 @@ void reset_playback_state(struct MPContext *mpctx) #if HAVE_ENCODING encode_lavc_discontinuity(mpctx->encode_lavc_ctx); #endif + + update_core_idle_state(mpctx); } static void mp_seek(MPContext *mpctx, struct seek_params seek) @@ -980,6 +997,7 @@ static void handle_playback_restart(struct MPContext *mpctx) mpctx->audio_allow_second_chance_seek = false; handle_playback_time(mpctx); mp_notify(mpctx, MPV_EVENT_PLAYBACK_RESTART, NULL); + update_core_idle_state(mpctx); if (!mpctx->playing_msg_shown) { if (opts->playing_msg && opts->playing_msg[0]) { char *msg = @@ -1103,6 +1121,8 @@ void run_playloop(struct MPContext *mpctx) handle_sstep(mpctx); + update_core_idle_state(mpctx); + if (mpctx->stop_play) return; -- cgit v1.2.3