From 196619671d8bde5112f82b5ec5db881ff8e99f43 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 14 Apr 2014 22:33:41 +0200 Subject: client API: remove mpv_event_pause_reason And slightly adjust the semantics of MPV_EVENT_PAUSE/MPV_EVENT_UNPAUSE. The real pause state can now be queried with the "core-idle" property, the user pause state with the "pause" property, whether the player is paused due to cache with "paused-for-cache", and the keep open event can be guessed with the "eof-reached" property. --- DOCS/man/en/lua.rst | 26 +++++--------------------- libmpv/client.h | 35 +++++------------------------------ player/client.c | 4 ---- player/command.c | 10 +++++----- player/core.h | 9 ++------- player/loadfile.c | 2 +- player/lua.c | 16 ---------------- player/playloop.c | 24 ++++++++++-------------- 8 files changed, 28 insertions(+), 98 deletions(-) diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst index f29df4a6d9..2cea513327 100644 --- a/DOCS/man/en/lua.rst +++ b/DOCS/man/en/lua.rst @@ -464,29 +464,13 @@ List of events when the ``start-file`` or ``shutdown`` events happen. ``pause`` - Playback was paused. - - Has the following event fields: - - ``real_paused`` - Current playback pause state as boolean. - - ``user_paused`` - User requested pause state. - - ``by_command`` - If the action was triggered by an input command (or via an user key - binding). It's false if it was an automatic action. - - ``by_cache`` - If the action was triggered by a low (or recovering) cache state. - - ``by_keep_open`` - If the pausing was triggered because the end of playback was reached, - and the "keep-open" option is enabled, 0 otherwise. + Playback was paused. This also happens when for example the player is + paused on low network cache. Then the event type indicates the pause state + (like the property "pause" as opposed to the "core-idle" propetty), and you + might be multiple ``pause`` events in a row. ``unpause`` - Playback was unpaused. + Playback was unpaused. See above for details. ``tick`` Called after a video frame was displayed. This is a hack, and you should diff --git a/libmpv/client.h b/libmpv/client.h index bd529d8677..0539903e8e 100644 --- a/libmpv/client.h +++ b/libmpv/client.h @@ -843,11 +843,14 @@ typedef enum mpv_event_id { */ MPV_EVENT_IDLE = 11, /** - * Playback was paused. + * Playback was paused. This indicates the logical pause state (like the + * property "pause" as opposed to the "core-idle" propetty). This event + * is sent whenever any pause state changes, not only the logical state, + * so you might get multiple MPV_EVENT_PAUSE events in a row. */ MPV_EVENT_PAUSE = 12, /** - * Playback was unpaused. + * Playback was unpaused. See MPV_EVENT_PAUSE for not so obvious details. */ MPV_EVENT_UNPAUSE = 13, /** @@ -975,32 +978,6 @@ typedef struct mpv_event_log_message { const char *text; } mpv_event_log_message; -typedef struct mpv_event_pause_reason { - /** - * Actual pause state (0 or 1) - */ - int real_paused; - /** - * User requested pause state (0 or 1) - */ - int user_paused; - /** - * 1 if the action was triggered by an input command (or via an user key - * binding), 0 otherwise. - */ - int by_command; - /** - * 1 if the action was triggered by a low (or recovering) cache state, - * 0 otherwise. - */ - int by_cache; - /** - * 1 if the pausing was triggered because the end of playback was reached, - * and the "keep-open" option is enabled, 0 otherwise. - */ - int by_keep_open; -} mpv_event_pause_reason; - typedef struct mpv_event_end_file { /** * Identifies the reason why playback was stopped: @@ -1063,8 +1040,6 @@ typedef struct mpv_event { * MPV_EVENT_GET_PROPERTY_REPLY: mpv_event_property* * MPV_EVENT_PROPERTY_CHANGE: mpv_event_property* * MPV_EVENT_LOG_MESSAGE: mpv_event_log_message* - * MPV_EVENT_PAUSE: mpv_event_pause_reason* - * MPV_EVENT_UNPAUSE: mpv_event_pause_reason* * MPV_EVENT_SCRIPT_INPUT_DISPATCH: mpv_event_script_input_dispatch* * MPV_EVENT_CLIENT_MESSAGE: mpv_event_client_message* * MPV_EVENT_END_FILE: mpv_event_end_file* diff --git a/player/client.c b/player/client.c index 7bca58e4c5..9e12d75afa 100644 --- a/player/client.c +++ b/player/client.c @@ -391,10 +391,6 @@ static void status_reply(struct mpv_handle *ctx, int event, static void dup_event_data(struct mpv_event *ev) { switch (ev->event_id) { - case MPV_EVENT_PAUSE: - case MPV_EVENT_UNPAUSE: - ev->data = talloc_memdup(NULL, ev->data, sizeof(mpv_event_pause_reason)); - break; case MPV_EVENT_CLIENT_MESSAGE: { struct mpv_event_client_message *src = ev->data; struct mpv_event_client_message *msg = diff --git a/player/command.c b/player/command.c index f718cb3147..9834b97b8a 100644 --- a/player/command.c +++ b/player/command.c @@ -975,9 +975,9 @@ static int mp_property_pause(m_option_t *prop, int action, void *arg, if (action == M_PROPERTY_SET) { if (*(int *)arg) { - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); } else { - unpause_player(mpctx, PAUSE_BY_COMMAND); + unpause_player(mpctx); } return M_PROPERTY_OK; } @@ -3596,12 +3596,12 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } if (cmd->flags & MP_PAUSING) - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); if (cmd->flags & MP_PAUSING_TOGGLE) { if (opts->pause) - unpause_player(mpctx, PAUSE_BY_COMMAND); + unpause_player(mpctx); else - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); } } diff --git a/player/core.h b/player/core.h index 8a8a13cb97..a360be4aa8 100644 --- a/player/core.h +++ b/player/core.h @@ -97,11 +97,6 @@ enum seek_type { MPSEEK_FACTOR, }; -// A bit-mask would be best, but I preferred not to use that with the client API. -#define PAUSE_BY_COMMAND ((mpv_event_pause_reason){.by_command=1}) -#define PAUSE_BY_CACHE ((mpv_event_pause_reason){.by_cache=1}) -#define PAUSE_BY_KEEP_OPEN ((mpv_event_pause_reason){.by_keep_open=1}) - struct track { enum stream_type type; @@ -431,8 +426,8 @@ void set_osd_function(struct MPContext *mpctx, int osd_function); void set_osd_subtitle(struct MPContext *mpctx, const char *text); // playloop.c -void pause_player(struct MPContext *mpctx, mpv_event_pause_reason reason); -void unpause_player(struct MPContext *mpctx, mpv_event_pause_reason reason); +void pause_player(struct MPContext *mpctx); +void unpause_player(struct MPContext *mpctx); void add_step_frame(struct MPContext *mpctx, int dir); void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount, int exact, bool immediate); diff --git a/player/loadfile.c b/player/loadfile.c index f2164d205b..b8dab59b66 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1354,7 +1354,7 @@ goto_reopen_demuxer: ; get_relative_time(mpctx); // reset current delta if (mpctx->opts->pause) - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); mp_notify(mpctx, MPV_EVENT_FILE_LOADED, NULL); diff --git a/player/lua.c b/player/lua.c index 36cbadcd3b..141d95248a 100644 --- a/player/lua.c +++ b/player/lua.c @@ -475,22 +475,6 @@ static int script_wait_event(lua_State *L) lua_setfield(L, -2, "args"); // event break; } - case MPV_EVENT_PAUSE: - case MPV_EVENT_UNPAUSE: - { - mpv_event_pause_reason *msg = event->data; - lua_pushboolean(L, msg->real_paused); - lua_setfield(L, -2, "real_paused"); - lua_pushboolean(L, msg->user_paused); - lua_setfield(L, -2, "user_paused"); - lua_pushboolean(L, msg->by_command); - lua_setfield(L, -2, "by_command"); - lua_pushboolean(L, msg->by_cache); - lua_setfield(L, -2, "by_cache"); - lua_pushboolean(L, msg->by_keep_open); - lua_setfield(L, -2, "by_keep_open"); - break; - } case MPV_EVENT_PROPERTY_CHANGE: { mpv_event_property *prop = event->data; lua_pushstring(L, prop->name); diff --git a/player/playloop.c b/player/playloop.c index 20a3104596..707dc6de5c 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -78,7 +78,7 @@ static const char av_desync_help_text[] = "If none of this helps you, file a bug report.\n\n"; -void pause_player(struct MPContext *mpctx, mpv_event_pause_reason reason) +void pause_player(struct MPContext *mpctx) { mpctx->opts->pause = 1; @@ -107,12 +107,10 @@ void pause_player(struct MPContext *mpctx, mpv_event_pause_reason reason) MP_SMODE(mpctx, "ID_PAUSED\n"); end: - reason.user_paused = !!mpctx->opts->pause; - reason.real_paused = !!mpctx->paused; - mp_notify(mpctx, MPV_EVENT_PAUSE, &reason); + mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0); } -void unpause_player(struct MPContext *mpctx, mpv_event_pause_reason reason) +void unpause_player(struct MPContext *mpctx) { mpctx->opts->pause = 0; @@ -134,9 +132,7 @@ void unpause_player(struct MPContext *mpctx, mpv_event_pause_reason reason) (void)get_relative_time(mpctx); // ignore time that passed during pause end: - reason.user_paused = !!mpctx->opts->pause; - reason.real_paused = !!mpctx->paused; - mp_notify(mpctx, MPV_EVENT_UNPAUSE, &reason); + mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0); } static void draw_osd(struct MPContext *mpctx) @@ -165,12 +161,12 @@ void add_step_frame(struct MPContext *mpctx, int dir) return; if (dir > 0) { mpctx->step_frames += 1; - unpause_player(mpctx, PAUSE_BY_COMMAND); + unpause_player(mpctx); } else if (dir < 0) { if (!mpctx->backstep_active && !mpctx->hrseek_active) { mpctx->backstep_active = true; mpctx->backstep_start_seek_ts = mpctx->vo_pts_history_seek_ts; - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); } } } @@ -662,14 +658,14 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) if (cache < 0 || cache >= opts->stream_cache_min_percent || idle) { mpctx->paused_for_cache = false; if (!opts->pause) - unpause_player(mpctx, PAUSE_BY_CACHE); + unpause_player(mpctx); } } else { if (cache >= 0 && cache <= opts->stream_cache_pause && !idle && opts->stream_cache_pause < opts->stream_cache_min_percent) { bool prev_paused_user = opts->pause; - pause_player(mpctx, PAUSE_BY_CACHE); + pause_player(mpctx); mpctx->paused_for_cache = true; opts->pause = prev_paused_user; } @@ -836,7 +832,7 @@ static void handle_keep_open(struct MPContext *mpctx) mpctx->stop_play = KEEP_PLAYING; mpctx->playback_pts = mpctx->last_vo_pts; mpctx->eof_reached = true; - pause_player(mpctx, PAUSE_BY_KEEP_OPEN); + pause_player(mpctx); } } @@ -1248,7 +1244,7 @@ void run_playloop(struct MPContext *mpctx) if (new_frame_shown) mpctx->step_frames--; if (mpctx->step_frames == 0) - pause_player(mpctx, PAUSE_BY_COMMAND); + pause_player(mpctx); } } -- cgit v1.2.3