From f5af5962378bd40a409716434a6a4d312e50c755 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Sep 2014 20:44:54 +0200 Subject: player: some more input refactoring Continues commit 348dfd93. Replace other places where input was manually fetched with common code. demux_was_interrupted() was a weird function; I'm not entirely sure about its original purpose, but now we can just replace it with simpler code as well. One difference is that we always look at the command queue, rather than just when cache initialization failed. Also, instead of discarding all but quit/playlist commands (aka abort command), run all commands. This could possibly lead to unwanted side-effects, like just ignoring commands that have no effect (consider pressing 'f' for fullscreen right on start: since the window is not created yet, it would get discarded). But playlist navigation still works as intended, and some if not all these problems already existed before that in some forms, so it should be ok. --- player/playloop.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'player/playloop.c') diff --git a/player/playloop.c b/player/playloop.c index 06c0f02bf6..d476137c12 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -56,27 +56,22 @@ // 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"); - } + mp_input_wait(mpctx->input, sleeptime); } // 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); + mp_dispatch_queue_process(mpctx->dispatch, 0); + for (;;) { + mp_cmd_t *cmd = mp_input_read_cmd(mpctx->input); + if (!cmd) + break; run_command(mpctx, cmd); mp_cmd_free(cmd); - if (mpctx->stop_play) - break; + mp_dispatch_queue_process(mpctx->dispatch, 0); } - mp_dispatch_queue_process(mpctx->dispatch, 0); } void pause_player(struct MPContext *mpctx) @@ -976,8 +971,6 @@ void idle_loop(struct MPContext *mpctx) while (mpctx->opts->player_idle_mode && !mpctx->playlist->current && mpctx->stop_play != PT_QUIT) { - mpctx->video_status = STATUS_EOF; - mpctx->audio_status = STATUS_EOF; if (need_reinit) { mp_notify(mpctx, MPV_EVENT_IDLE, NULL); handle_force_window(mpctx, true); @@ -988,16 +981,11 @@ void idle_loop(struct MPContext *mpctx) if (!mpctx->opts->force_vo) uninit |= INITIALIZED_VO; uninit_player(mpctx, uninit); - handle_force_window(mpctx, false); update_osd_msg(mpctx); handle_osd_redraw(mpctx); - mp_cmd_t *cmd = mp_input_get_cmd(mpctx->input, mpctx->sleeptime * 1000, - false); + mp_process_input(mpctx); + mp_wait_events(mpctx, mpctx->sleeptime); mpctx->sleeptime = 100.0; - if (cmd) - run_command(mpctx, cmd); - mp_cmd_free(cmd); - mp_dispatch_queue_process(mpctx->dispatch, 0); if (mpctx->opts->use_terminal) getch2_poll(); } -- cgit v1.2.3