1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

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) int action, void *arg)
{ {
MPContext *mpctx = ctx; MPContext *mpctx = ctx;
bool idle = mpctx->paused || !mpctx->restart_complete || !mpctx->playing; return m_property_flag_ro(action, arg, !mpctx->playback_active);
return m_property_flag_ro(action, arg, idle);
} }
static int mp_property_idle(void *ctx, struct m_property *prop, 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", E(MPV_EVENT_TRACK_SWITCHED, "vid", "video", "aid", "audio", "sid", "sub",
"secondary-sid"), "secondary-sid"),
E(MPV_EVENT_IDLE, "*"), E(MPV_EVENT_IDLE, "*"),
E(MPV_EVENT_PAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), E(MPV_EVENT_PAUSE, "pause"),
E(MPV_EVENT_UNPAUSE, "pause", "paused-on-cache", "core-idle", "eof-reached"), E(MPV_EVENT_UNPAUSE, "pause"),
E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync", E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync",
"percent-pos", "time-remaining", "playtime-remaining", "playback-time", "percent-pos", "time-remaining", "playtime-remaining", "playback-time",
"estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count", "estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count",
@ -4126,6 +4125,7 @@ static const char *const *const mp_event_property_change[] = {
"fullscreen"), "fullscreen"),
E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",
"playlist-count", "playlist/count"), "playlist-count", "playlist/count"),
E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),
}; };
#undef E #undef E

View File

@ -56,6 +56,7 @@ enum {
MP_EVENT_WIN_RESIZE, MP_EVENT_WIN_RESIZE,
MP_EVENT_WIN_STATE, MP_EVENT_WIN_STATE,
MP_EVENT_CHANGE_PLAYLIST, MP_EVENT_CHANGE_PLAYLIST,
MP_EVENT_CORE_IDLE,
}; };
bool mp_hook_test_completion(struct MPContext *mpctx, char *type); bool mp_hook_test_completion(struct MPContext *mpctx, char *type);

View File

@ -415,7 +415,9 @@ typedef struct MPContext {
int last_chapter_seek; int last_chapter_seek;
double last_chapter_pts; 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 // step this many frames, then pause
int step_frames; int step_frames;
// Counted down each frame, stop playback if 0 is reached. (-1 = disable) // 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 reset_playback_state(struct MPContext *mpctx);
void set_pause_state(struct MPContext *mpctx, bool user_pause); void set_pause_state(struct MPContext *mpctx, bool user_pause);
void update_internal_pause_state(struct MPContext *mpctx); 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 add_step_frame(struct MPContext *mpctx, int dir);
void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount, void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
enum seek_precision exact, int flags); enum seek_precision exact, int flags);

View File

@ -1281,6 +1281,9 @@ reopen_file:
terminate_playback: terminate_playback:
mpctx->playback_active = false;
update_core_idle_state(mpctx);
process_unload_hooks(mpctx); process_unload_hooks(mpctx);
if (mpctx->stop_play == KEEP_PLAYING) if (mpctx->stop_play == KEEP_PLAYING)
@ -1306,7 +1309,6 @@ terminate_playback:
uninit_audio_out(mpctx); uninit_audio_out(mpctx);
mpctx->playback_initialized = false; mpctx->playback_initialized = false;
update_screensaver_state(mpctx);
if (mpctx->stop_play == PT_RELOAD_FILE) { if (mpctx->stop_play == PT_RELOAD_FILE) {
mpctx->stop_play = KEEP_PLAYING; mpctx->stop_play = KEEP_PLAYING;

View File

@ -120,6 +120,22 @@ double get_relative_time(struct MPContext *mpctx)
return delta * 0.000001; 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 // The value passed here is the new value for mpctx->opts->pause
void set_pause_state(struct MPContext *mpctx, bool user_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_core_idle_state(mpctx);
update_screensaver_state(mpctx);
if (send_update)
mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0); mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
}
} }
void update_internal_pause_state(struct MPContext *mpctx) void update_internal_pause_state(struct MPContext *mpctx)
@ -175,8 +191,7 @@ void update_screensaver_state(struct MPContext *mpctx)
if (!mpctx->video_out) if (!mpctx->video_out)
return; return;
bool saver_state = mpctx->opts->pause || !mpctx->opts->stop_screensaver || bool saver_state = !mpctx->playback_active || !mpctx->opts->stop_screensaver;
!mpctx->playback_initialized;
vo_control_async(mpctx->video_out, saver_state ? VOCTRL_RESTORE_SCREENSAVER vo_control_async(mpctx->video_out, saver_state ? VOCTRL_RESTORE_SCREENSAVER
: VOCTRL_KILL_SCREENSAVER, NULL); : VOCTRL_KILL_SCREENSAVER, NULL);
} }
@ -227,6 +242,8 @@ void reset_playback_state(struct MPContext *mpctx)
#if HAVE_ENCODING #if HAVE_ENCODING
encode_lavc_discontinuity(mpctx->encode_lavc_ctx); encode_lavc_discontinuity(mpctx->encode_lavc_ctx);
#endif #endif
update_core_idle_state(mpctx);
} }
static void mp_seek(MPContext *mpctx, struct seek_params seek) 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; mpctx->audio_allow_second_chance_seek = false;
handle_playback_time(mpctx); handle_playback_time(mpctx);
mp_notify(mpctx, MPV_EVENT_PLAYBACK_RESTART, NULL); mp_notify(mpctx, MPV_EVENT_PLAYBACK_RESTART, NULL);
update_core_idle_state(mpctx);
if (!mpctx->playing_msg_shown) { if (!mpctx->playing_msg_shown) {
if (opts->playing_msg && opts->playing_msg[0]) { if (opts->playing_msg && opts->playing_msg[0]) {
char *msg = char *msg =
@ -1103,6 +1121,8 @@ void run_playloop(struct MPContext *mpctx)
handle_sstep(mpctx); handle_sstep(mpctx);
update_core_idle_state(mpctx);
if (mpctx->stop_play) if (mpctx->stop_play)
return; return;