From 4de22d1cbc1ff8201f66629ca75de32e7e7ed223 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 1 Mar 2014 15:46:39 +0100 Subject: client API: fix playloop thread wakeup The playloop usually waits in select(), using a timeout needed for refilling audio and video buffers. This means the client API needs a separate mechanism to interrupt the select() call. This mechanism exists, but I forgot to use it. This commit fixes it. If it works, this will make the client API react faster, epsecially in audio-only mode. If video is enabled, the reaction time is capped to 50ms (or somewhat faster if the framerate is >20 fps), because the playloop stops reacting to anything in order to render and time the next video frame. (This will be fixed later by moving the VO to its own thread.) --- player/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'player') diff --git a/player/main.c b/player/main.c index e510081d5b..bf97a39a3a 100644 --- a/player/main.c +++ b/player/main.c @@ -143,6 +143,7 @@ void mp_destroy(struct MPContext *mpctx) command_uninit(mpctx); + mp_dispatch_set_wakeup_fn(mpctx->dispatch, NULL, NULL); mp_input_uninit(mpctx->input); osd_free(mpctx->osd); @@ -353,6 +354,12 @@ struct MPContext *mp_create(void) return mpctx; } +static void wakeup_playloop(void *ctx) +{ + struct MPContext *mpctx = ctx; + mp_input_wakeup(mpctx->input); +} + // Finish mpctx initialization. This must be done after setting up all options. // Some of the initializations depend on the options, and can't be changed or // undone later. @@ -372,6 +379,8 @@ int mp_initialize(struct MPContext *mpctx) mpctx->input = mp_input_init(mpctx->global); stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); + mp_dispatch_set_wakeup_fn(mpctx->dispatch, wakeup_playloop, mpctx); + #if HAVE_ENCODING if (opts->encode_output.file && *opts->encode_output.file) { mpctx->encode_lavc_ctx = encode_lavc_init(&opts->encode_output, -- cgit v1.2.3