mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
player: unmess pause state handling
Merge the pause_player() and unpause_player() functions. Make sure the pause events are emitted properly. We can now set the internal pause state based on a predicate, instead of e.g. handle_pause_on_low_cache() making a mess to trigger the internal pause state as wanted. Preparation for some more changes.
This commit is contained in:
parent
ae0a40259f
commit
419624fb06
@ -1493,11 +1493,7 @@ static int mp_property_pause(void *ctx, struct m_property *prop,
|
|||||||
MPContext *mpctx = ctx;
|
MPContext *mpctx = ctx;
|
||||||
|
|
||||||
if (mpctx->playback_initialized && action == M_PROPERTY_SET) {
|
if (mpctx->playback_initialized && action == M_PROPERTY_SET) {
|
||||||
if (*(int *)arg) {
|
set_pause_state(mpctx, *(int *)arg);
|
||||||
pause_player(mpctx);
|
|
||||||
} else {
|
|
||||||
unpause_player(mpctx);
|
|
||||||
}
|
|
||||||
return M_PROPERTY_OK;
|
return M_PROPERTY_OK;
|
||||||
}
|
}
|
||||||
return mp_property_generic_option(mpctx, prop, action, arg);
|
return mp_property_generic_option(mpctx, prop, action, arg);
|
||||||
@ -5018,10 +5014,10 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
|
|||||||
if (cmd->is_up_down) {
|
if (cmd->is_up_down) {
|
||||||
if (cmd->is_up) {
|
if (cmd->is_up) {
|
||||||
if (mpctx->step_frames < 1)
|
if (mpctx->step_frames < 1)
|
||||||
pause_player(mpctx);
|
set_pause_state(mpctx, true);
|
||||||
} else {
|
} else {
|
||||||
if (cmd->repeated) {
|
if (cmd->repeated) {
|
||||||
unpause_player(mpctx);
|
set_pause_state(mpctx, false);
|
||||||
} else {
|
} else {
|
||||||
add_step_frame(mpctx, 1);
|
add_step_frame(mpctx, 1);
|
||||||
}
|
}
|
||||||
|
@ -558,8 +558,8 @@ void mp_wakeup_core_cb(void *ctx);
|
|||||||
void mp_process_input(struct MPContext *mpctx);
|
void mp_process_input(struct MPContext *mpctx);
|
||||||
double get_relative_time(struct MPContext *mpctx);
|
double get_relative_time(struct MPContext *mpctx);
|
||||||
void reset_playback_state(struct MPContext *mpctx);
|
void reset_playback_state(struct MPContext *mpctx);
|
||||||
void pause_player(struct MPContext *mpctx);
|
void set_pause_state(struct MPContext *mpctx, bool user_pause);
|
||||||
void unpause_player(struct MPContext *mpctx);
|
void update_internal_pause_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);
|
||||||
|
@ -1268,8 +1268,7 @@ reopen_file:
|
|||||||
execute_queued_seek(mpctx);
|
execute_queued_seek(mpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpctx->opts->pause)
|
update_internal_pause_state(mpctx);
|
||||||
pause_player(mpctx);
|
|
||||||
|
|
||||||
open_recorder(mpctx, true);
|
open_recorder(mpctx, true);
|
||||||
|
|
||||||
|
@ -120,58 +120,54 @@ double get_relative_time(struct MPContext *mpctx)
|
|||||||
return delta * 0.000001;
|
return delta * 0.000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause_player(struct MPContext *mpctx)
|
// The value passed here is the new value for mpctx->opts->pause
|
||||||
|
void set_pause_state(struct MPContext *mpctx, bool user_pause)
|
||||||
{
|
{
|
||||||
mpctx->opts->pause = 1;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
|
bool send_update = false;
|
||||||
|
|
||||||
update_screensaver_state(mpctx);
|
if (opts->pause != user_pause)
|
||||||
|
send_update = true;
|
||||||
|
opts->pause = user_pause;
|
||||||
|
|
||||||
if (mpctx->paused)
|
bool internal_paused = opts->pause || mpctx->paused_for_cache;
|
||||||
goto end;
|
if (internal_paused != mpctx->paused) {
|
||||||
mpctx->paused = true;
|
mpctx->paused = internal_paused;
|
||||||
mpctx->step_frames = 0;
|
send_update = true;
|
||||||
mpctx->time_frame -= get_relative_time(mpctx);
|
|
||||||
mpctx->osd_function = 0;
|
|
||||||
mpctx->osd_force_update = true;
|
|
||||||
mpctx->paused_for_cache = false;
|
|
||||||
|
|
||||||
if (mpctx->ao && mpctx->ao_chain)
|
if (mpctx->ao && mpctx->ao_chain) {
|
||||||
|
if (internal_paused) {
|
||||||
ao_pause(mpctx->ao);
|
ao_pause(mpctx->ao);
|
||||||
if (mpctx->video_out)
|
} else {
|
||||||
vo_set_paused(mpctx->video_out, true);
|
ao_resume(mpctx->ao);
|
||||||
|
}
|
||||||
mp_wakeup_core(mpctx);
|
|
||||||
|
|
||||||
end:
|
|
||||||
mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpause_player(struct MPContext *mpctx)
|
if (mpctx->video_out)
|
||||||
{
|
vo_set_paused(mpctx->video_out, internal_paused);
|
||||||
mpctx->opts->pause = 0;
|
|
||||||
|
|
||||||
update_screensaver_state(mpctx);
|
|
||||||
|
|
||||||
if (!mpctx->paused)
|
|
||||||
goto end;
|
|
||||||
// Don't actually unpause while cache is loading.
|
|
||||||
if (mpctx->paused_for_cache)
|
|
||||||
goto end;
|
|
||||||
mpctx->paused = false;
|
|
||||||
mpctx->osd_function = 0;
|
mpctx->osd_function = 0;
|
||||||
mpctx->osd_force_update = true;
|
mpctx->osd_force_update = true;
|
||||||
|
|
||||||
if (mpctx->ao && mpctx->ao_chain)
|
|
||||||
ao_resume(mpctx->ao);
|
|
||||||
if (mpctx->video_out)
|
|
||||||
vo_set_paused(mpctx->video_out, false);
|
|
||||||
|
|
||||||
mp_wakeup_core(mpctx);
|
mp_wakeup_core(mpctx);
|
||||||
|
|
||||||
|
if (internal_paused) {
|
||||||
|
mpctx->step_frames = 0;
|
||||||
|
mpctx->time_frame -= get_relative_time(mpctx);
|
||||||
|
} else {
|
||||||
(void)get_relative_time(mpctx); // ignore time that passed during pause
|
(void)get_relative_time(mpctx); // ignore time that passed during pause
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
if (send_update) {
|
||||||
mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
|
update_screensaver_state(mpctx);
|
||||||
|
mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_internal_pause_state(struct MPContext *mpctx)
|
||||||
|
{
|
||||||
|
set_pause_state(mpctx, mpctx->opts->pause);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_screensaver_state(struct MPContext *mpctx)
|
void update_screensaver_state(struct MPContext *mpctx)
|
||||||
@ -191,11 +187,11 @@ void add_step_frame(struct MPContext *mpctx, int dir)
|
|||||||
return;
|
return;
|
||||||
if (dir > 0) {
|
if (dir > 0) {
|
||||||
mpctx->step_frames += 1;
|
mpctx->step_frames += 1;
|
||||||
unpause_player(mpctx);
|
set_pause_state(mpctx, false);
|
||||||
} else if (dir < 0) {
|
} else if (dir < 0) {
|
||||||
if (!mpctx->hrseek_active) {
|
if (!mpctx->hrseek_active) {
|
||||||
queue_seek(mpctx, MPSEEK_BACKSTEP, 0, MPSEEK_VERY_EXACT, 0);
|
queue_seek(mpctx, MPSEEK_BACKSTEP, 0, MPSEEK_VERY_EXACT, 0);
|
||||||
pause_player(mpctx);
|
set_pause_state(mpctx, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,17 +615,14 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
|||||||
mpctx->cache_wait_time /= 1.5 - 0.1;
|
mpctx->cache_wait_time /= 1.5 - 0.1;
|
||||||
}
|
}
|
||||||
mpctx->paused_for_cache = false;
|
mpctx->paused_for_cache = false;
|
||||||
if (!opts->pause)
|
update_internal_pause_state(mpctx);
|
||||||
unpause_player(mpctx);
|
|
||||||
force_update = true;
|
force_update = true;
|
||||||
}
|
}
|
||||||
mp_set_timeout(mpctx, 0.2);
|
mp_set_timeout(mpctx, 0.2);
|
||||||
} else {
|
} else {
|
||||||
if (opts->cache_pausing && s.underrun) {
|
if (opts->cache_pausing && s.underrun) {
|
||||||
bool prev_paused_user = opts->pause;
|
|
||||||
pause_player(mpctx);
|
|
||||||
mpctx->paused_for_cache = true;
|
mpctx->paused_for_cache = true;
|
||||||
opts->pause = prev_paused_user;
|
update_internal_pause_state(mpctx);
|
||||||
mpctx->cache_stop_time = now;
|
mpctx->cache_stop_time = now;
|
||||||
force_update = true;
|
force_update = true;
|
||||||
}
|
}
|
||||||
@ -763,7 +756,7 @@ static void handle_sstep(struct MPContext *mpctx)
|
|||||||
if (mpctx->max_frames >= 0 && !mpctx->stop_play)
|
if (mpctx->max_frames >= 0 && !mpctx->stop_play)
|
||||||
mpctx->stop_play = AT_END_OF_FILE; // force EOF even if audio left
|
mpctx->stop_play = AT_END_OF_FILE; // force EOF even if audio left
|
||||||
if (mpctx->step_frames > 0 && !mpctx->paused)
|
if (mpctx->step_frames > 0 && !mpctx->paused)
|
||||||
pause_player(mpctx);
|
set_pause_state(mpctx, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -831,8 +824,8 @@ static void handle_keep_open(struct MPContext *mpctx)
|
|||||||
seek_to_last_frame(mpctx);
|
seek_to_last_frame(mpctx);
|
||||||
mpctx->playback_pts = mpctx->last_vo_pts;
|
mpctx->playback_pts = mpctx->last_vo_pts;
|
||||||
}
|
}
|
||||||
if (opts->keep_open_pause && !mpctx->opts->pause)
|
if (opts->keep_open_pause)
|
||||||
pause_player(mpctx);
|
set_pause_state(mpctx, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1543,8 +1543,8 @@ void write_video(struct MPContext *mpctx)
|
|||||||
if (mpctx->video_status != STATUS_EOF) {
|
if (mpctx->video_status != STATUS_EOF) {
|
||||||
if (mpctx->step_frames > 0) {
|
if (mpctx->step_frames > 0) {
|
||||||
mpctx->step_frames--;
|
mpctx->step_frames--;
|
||||||
if (!mpctx->step_frames && !opts->pause)
|
if (!mpctx->step_frames)
|
||||||
pause_player(mpctx);
|
set_pause_state(mpctx, true);
|
||||||
}
|
}
|
||||||
if (mpctx->max_frames == 0 && !mpctx->stop_play)
|
if (mpctx->max_frames == 0 && !mpctx->stop_play)
|
||||||
mpctx->stop_play = AT_END_OF_FILE;
|
mpctx->stop_play = AT_END_OF_FILE;
|
||||||
|
Loading…
Reference in New Issue
Block a user