summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-04-14 18:22:45 +0200
committerwm4 <wm4@nowhere>2017-04-14 18:22:45 +0200
commit419624fb068ed4e7f449fa4fd0dda8edf161ac1c (patch)
treed74b3c2c12fdf79aa8bb8cc6f289b7b7d7e2ceca /player
parentae0a40259fa9ce45d34c966da067e20a69156330 (diff)
downloadmpv-419624fb068ed4e7f449fa4fd0dda8edf161ac1c.tar.bz2
mpv-419624fb068ed4e7f449fa4fd0dda8edf161ac1c.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/command.c10
-rw-r--r--player/core.h4
-rw-r--r--player/loadfile.c3
-rw-r--r--player/playloop.c97
-rw-r--r--player/video.c4
5 files changed, 53 insertions, 65 deletions
diff --git a/player/command.c b/player/command.c
index 618e47dcf0..ab2d43984a 100644
--- a/player/command.c
+++ b/player/command.c
@@ -1493,11 +1493,7 @@ static int mp_property_pause(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (mpctx->playback_initialized && action == M_PROPERTY_SET) {
- if (*(int *)arg) {
- pause_player(mpctx);
- } else {
- unpause_player(mpctx);
- }
+ set_pause_state(mpctx, *(int *)arg);
return M_PROPERTY_OK;
}
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) {
if (mpctx->step_frames < 1)
- pause_player(mpctx);
+ set_pause_state(mpctx, true);
} else {
if (cmd->repeated) {
- unpause_player(mpctx);
+ set_pause_state(mpctx, false);
} else {
add_step_frame(mpctx, 1);
}
diff --git a/player/core.h b/player/core.h
index b958db56d5..1e1c7f0baa 100644
--- a/player/core.h
+++ b/player/core.h
@@ -558,8 +558,8 @@ void mp_wakeup_core_cb(void *ctx);
void mp_process_input(struct MPContext *mpctx);
double get_relative_time(struct MPContext *mpctx);
void reset_playback_state(struct MPContext *mpctx);
-void pause_player(struct MPContext *mpctx);
-void unpause_player(struct MPContext *mpctx);
+void set_pause_state(struct MPContext *mpctx, bool user_pause);
+void update_internal_pause_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 7c6894033d..1542e16e49 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1268,8 +1268,7 @@ reopen_file:
execute_queued_seek(mpctx);
}
- if (mpctx->opts->pause)
- pause_player(mpctx);
+ update_internal_pause_state(mpctx);
open_recorder(mpctx, true);
diff --git a/player/playloop.c b/player/playloop.c
index 2b33705426..9f3abefa78 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -120,58 +120,54 @@ double get_relative_time(struct MPContext *mpctx)
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;
-
- update_screensaver_state(mpctx);
-
- if (mpctx->paused)
- goto end;
- mpctx->paused = true;
- mpctx->step_frames = 0;
- 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)
- ao_pause(mpctx->ao);
- if (mpctx->video_out)
- vo_set_paused(mpctx->video_out, true);
+ struct MPOpts *opts = mpctx->opts;
+ bool send_update = false;
- mp_wakeup_core(mpctx);
+ if (opts->pause != user_pause)
+ send_update = true;
+ opts->pause = user_pause;
-end:
- mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
-}
+ bool internal_paused = opts->pause || mpctx->paused_for_cache;
+ if (internal_paused != mpctx->paused) {
+ mpctx->paused = internal_paused;
+ send_update = true;
-void unpause_player(struct MPContext *mpctx)
-{
- mpctx->opts->pause = 0;
+ if (mpctx->ao && mpctx->ao_chain) {
+ if (internal_paused) {
+ ao_pause(mpctx->ao);
+ } else {
+ ao_resume(mpctx->ao);
+ }
+ }
- update_screensaver_state(mpctx);
+ if (mpctx->video_out)
+ vo_set_paused(mpctx->video_out, internal_paused);
- 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_force_update = true;
+ mpctx->osd_function = 0;
+ 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
+ if (send_update) {
+ update_screensaver_state(mpctx);
+ mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
+ }
+}
-end:
- mp_notify(mpctx, 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)
@@ -191,11 +187,11 @@ void add_step_frame(struct MPContext *mpctx, int dir)
return;
if (dir > 0) {
mpctx->step_frames += 1;
- unpause_player(mpctx);
+ set_pause_state(mpctx, false);
} else if (dir < 0) {
if (!mpctx->hrseek_active) {
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->paused_for_cache = false;
- if (!opts->pause)
- unpause_player(mpctx);
+ update_internal_pause_state(mpctx);
force_update = true;
}
mp_set_timeout(mpctx, 0.2);
} else {
if (opts->cache_pausing && s.underrun) {
- bool prev_paused_user = opts->pause;
- pause_player(mpctx);
mpctx->paused_for_cache = true;
- opts->pause = prev_paused_user;
+ update_internal_pause_state(mpctx);
mpctx->cache_stop_time = now;
force_update = true;
}
@@ -763,7 +756,7 @@ static void handle_sstep(struct MPContext *mpctx)
if (mpctx->max_frames >= 0 && !mpctx->stop_play)
mpctx->stop_play = AT_END_OF_FILE; // force EOF even if audio left
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);
mpctx->playback_pts = mpctx->last_vo_pts;
}
- if (opts->keep_open_pause && !mpctx->opts->pause)
- pause_player(mpctx);
+ if (opts->keep_open_pause)
+ set_pause_state(mpctx, true);
}
}
diff --git a/player/video.c b/player/video.c
index eecfea5482..3bbb2dc275 100644
--- a/player/video.c
+++ b/player/video.c
@@ -1543,8 +1543,8 @@ void write_video(struct MPContext *mpctx)
if (mpctx->video_status != STATUS_EOF) {
if (mpctx->step_frames > 0) {
mpctx->step_frames--;
- if (!mpctx->step_frames && !opts->pause)
- pause_player(mpctx);
+ if (!mpctx->step_frames)
+ set_pause_state(mpctx, true);
}
if (mpctx->max_frames == 0 && !mpctx->stop_play)
mpctx->stop_play = AT_END_OF_FILE;