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.
This commit is contained in:
wm4 2017-04-14 18:56:03 +02:00
parent 419624fb06
commit b586bc2dbe
5 changed files with 37 additions and 11 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;