summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-06 16:57:46 +0200
committerwm4 <wm4@nowhere>2014-09-06 16:57:46 +0200
commit348dfd93c4178633d3995a955045fafb7e9209d3 (patch)
treed7d9613b0727950ed155bb43459562979076cf75
parent94113e632f162d6331d0fdd559ffe9802330cd05 (diff)
downloadmpv-348dfd93c4178633d3995a955045fafb7e9209d3.tar.bz2
mpv-348dfd93c4178633d3995a955045fafb7e9209d3.tar.xz
player: minor refactoring
Expose the central event handling functions explicitly, so that other parts of the player can use them. No functional changes. Preparation for the next commit.
-rw-r--r--player/core.h2
-rw-r--r--player/playloop.c51
2 files changed, 31 insertions, 22 deletions
diff --git a/player/core.h b/player/core.h
index 341ea84c47..bd2a15d7d0 100644
--- a/player/core.h
+++ b/player/core.h
@@ -434,6 +434,8 @@ void set_osd_function(struct MPContext *mpctx, int osd_function);
void set_osd_subtitle(struct MPContext *mpctx, const char *text);
// playloop.c
+void mp_wait_events(struct MPContext *mpctx, double sleeptime);
+void mp_process_input(struct MPContext *mpctx);
void reset_playback_state(struct MPContext *mpctx);
void pause_player(struct MPContext *mpctx);
void unpause_player(struct MPContext *mpctx);
diff --git a/player/playloop.c b/player/playloop.c
index 0e35dcb88b..06c0f02bf6 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -52,6 +52,33 @@
#include "client.h"
#include "command.h"
+// Wait until mp_input_wakeup(mpctx->input) is called, since the last time
+// mp_wait_events() was called. (But see mp_process_input().)
+void mp_wait_events(struct MPContext *mpctx, double sleeptime)
+{
+ if (sleeptime > 0) {
+ MP_STATS(mpctx, "start sleep");
+ mp_input_get_cmd(mpctx->input, sleeptime * 1000, true);
+ MP_STATS(mpctx, "end sleep");
+ }
+}
+
+// Process any queued input, whether it's user input, or requests from client
+// API threads. This also resets the "wakeup" flag used with mp_wait_events().
+void mp_process_input(struct MPContext *mpctx)
+{
+ mp_cmd_t *cmd;
+ while ((cmd = mp_input_get_cmd(mpctx->input, 0, 1)) != NULL) {
+ mp_dispatch_queue_process(mpctx->dispatch, 0);
+ cmd = mp_input_get_cmd(mpctx->input, 0, 0);
+ run_command(mpctx, cmd);
+ mp_cmd_free(cmd);
+ if (mpctx->stop_play)
+ break;
+ }
+ mp_dispatch_queue_process(mpctx->dispatch, 0);
+}
+
void pause_player(struct MPContext *mpctx)
{
mpctx->opts->pause = 1;
@@ -626,22 +653,6 @@ static void handle_cursor_autohide(struct MPContext *mpctx)
mpctx->mouse_cursor_visible = mouse_cursor_visible;
}
-static void handle_input_and_seek_coalesce(struct MPContext *mpctx)
-{
- mp_cmd_t *cmd;
- while ((cmd = mp_input_get_cmd(mpctx->input, 0, 1)) != NULL) {
- mp_dispatch_queue_process(mpctx->dispatch, 0);
- MP_STATS(mpctx, "start command");
- cmd = mp_input_get_cmd(mpctx->input, 0, 0);
- run_command(mpctx, cmd);
- mp_cmd_free(cmd);
- MP_STATS(mpctx, "end command");
- if (mpctx->stop_play)
- break;
- }
- mp_dispatch_queue_process(mpctx->dispatch, 0);
-}
-
void add_frame_pts(struct MPContext *mpctx, double pts)
{
if (pts == MP_NOPTS_VALUE || mpctx->hrseek_framedrop) {
@@ -938,16 +949,12 @@ void run_playloop(struct MPContext *mpctx)
handle_osd_redraw(mpctx);
- if (mpctx->sleeptime > 0) {
- MP_STATS(mpctx, "start sleep");
- mp_input_get_cmd(mpctx->input, mpctx->sleeptime * 1000, true);
- MP_STATS(mpctx, "end sleep");
- }
+ mp_wait_events(mpctx, mpctx->sleeptime);
mpctx->sleeptime = 100.0; // infinite for all practical purposes
handle_pause_on_low_cache(mpctx);
- handle_input_and_seek_coalesce(mpctx);
+ mp_process_input(mpctx);
handle_backstep(mpctx);