mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-29 07:06:59 +08:00
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.)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user