diff options
author | wm4 <wm4@nowhere> | 2016-09-16 14:23:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-16 14:37:48 +0200 |
commit | b8ade7c99b830ee9870040bcfc1f2c3d3a64d172 (patch) | |
tree | 48df8031d90be4e6e1f9c9c4045a72e21c33862c /player | |
parent | f845f64c2abe4361084b4bc07f5f1ea5dd43ec9f (diff) | |
download | mpv-b8ade7c99b830ee9870040bcfc1f2c3d3a64d172.tar.bz2 mpv-b8ade7c99b830ee9870040bcfc1f2c3d3a64d172.tar.xz |
player, ao, vo: don't call mp_input_wakeup() directly
Currently, calling mp_input_wakeup() will wake up the core thread (also
called the playloop). This seems odd, but currently the core indeed
calls mp_input_wait() when it has nothing more to do. It's done this way
because MPlayer used input_ctx as central "mainloop".
This is probably going to change. Remove direct calls to this function,
and replace it with mp_wakeup_core() calls. ao and vo are changed to use
opaque callbacks and not use input_ctx for this purpose. Other code
already uses opaque callbacks, or has legitimate reasons to use
input_ctx directly (such as sending actual user input).
Diffstat (limited to 'player')
-rw-r--r-- | player/audio.c | 4 | ||||
-rw-r--r-- | player/client.c | 7 | ||||
-rw-r--r-- | player/command.c | 22 | ||||
-rw-r--r-- | player/core.h | 2 | ||||
-rw-r--r-- | player/loadfile.c | 2 | ||||
-rw-r--r-- | player/lua.c | 2 | ||||
-rw-r--r-- | player/main.c | 2 | ||||
-rw-r--r-- | player/misc.c | 2 | ||||
-rw-r--r-- | player/playloop.c | 19 | ||||
-rw-r--r-- | player/video.c | 2 |
10 files changed, 46 insertions, 18 deletions
diff --git a/player/audio.c b/player/audio.c index 1329057033..7bcd5c87bb 100644 --- a/player/audio.c +++ b/player/audio.c @@ -397,8 +397,8 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx) mp_audio_set_channels(&afs->output, &afs->output.channels); - mpctx->ao = ao_init_best(mpctx->global, ao_flags, mpctx->input, - mpctx->encode_lavc_ctx, afs->output.rate, + mpctx->ao = ao_init_best(mpctx->global, ao_flags, mp_wakeup_core_cb, + mpctx, mpctx->encode_lavc_ctx, afs->output.rate, afs->output.format, afs->output.channels); ao_c->ao = mpctx->ao; diff --git a/player/client.c b/player/client.c index 803ef36fca..807fab5df6 100644 --- a/player/client.c +++ b/player/client.c @@ -424,8 +424,7 @@ void mpv_detach_destroy(mpv_handle *ctx) ctx = NULL; // shutdown_clients() sleeps to avoid wasting CPU. // mp_hook_test_completion() also relies on this a bit. - if (clients->mpctx->input) - mp_input_wakeup(clients->mpctx->input); + mp_wakeup_core(clients->mpctx); break; } } @@ -759,8 +758,8 @@ mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout) pthread_mutex_lock(&ctx->lock); - if (!ctx->fuzzy_initialized && ctx->clients->mpctx->input) - mp_input_wakeup(ctx->clients->mpctx->input); + if (!ctx->fuzzy_initialized) + mp_wakeup_core(ctx->clients->mpctx); ctx->fuzzy_initialized = true; if (timeout < 0) diff --git a/player/command.c b/player/command.c index 1b7f9eb088..bc103d0c6b 100644 --- a/player/command.c +++ b/player/command.c @@ -190,7 +190,7 @@ void mp_hook_run(struct MPContext *mpctx, char *client, char *type) next->active = true; if (!send_hook_msg(mpctx, next, "hook_run")) { hook_remove(mpctx, index); - mp_input_wakeup(mpctx->input); // repeat next iteration to finish + mp_wakeup_core(mpctx); // repeat next iteration to finish } } @@ -1742,14 +1742,24 @@ static void reload_audio_output(struct MPContext *mpctx) ao_request_reload(mpctx->ao); } +static void create_hotplug(struct MPContext *mpctx) +{ + struct command_ctx *cmd = mpctx->command_ctx; + + if (!cmd->hotplug) { + cmd->hotplug = ao_hotplug_create(mpctx->global, mp_wakeup_core_cb, + mpctx); + } +} + static int mp_property_audio_device(void *ctx, struct m_property *prop, int action, void *arg) { struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; if (action == M_PROPERTY_PRINT) { - if (!cmd->hotplug) - cmd->hotplug = ao_hotplug_create(mpctx->global, mpctx->input); + create_hotplug(mpctx); + struct ao_device_list *list = ao_hotplug_get_device_list(cmd->hotplug); for (int n = 0; n < list->num_devices; n++) { struct ao_device_desc *dev = &list->devices[n]; @@ -1770,8 +1780,7 @@ static int mp_property_audio_devices(void *ctx, struct m_property *prop, { struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; - if (!cmd->hotplug) - cmd->hotplug = ao_hotplug_create(mpctx->global, mpctx->input); + create_hotplug(mpctx); struct ao_device_list *list = ao_hotplug_get_device_list(cmd->hotplug); return m_property_read_list(action, arg, list->num_devices, @@ -1790,8 +1799,7 @@ static int mp_property_ao_detected_device(void *ctx,struct m_property *prop, { struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; - if (!cmd->hotplug) - cmd->hotplug = ao_hotplug_create(mpctx->global, mpctx->input); + create_hotplug(mpctx); const char *d = ao_hotplug_get_detected_device(cmd->hotplug); return m_property_strdup_ro(action, arg, d); diff --git a/player/core.h b/player/core.h index 0ffb47404c..3fa2c102b4 100644 --- a/player/core.h +++ b/player/core.h @@ -511,6 +511,8 @@ void set_osd_bar_chapters(struct MPContext *mpctx, int type); // playloop.c void mp_wait_events(struct MPContext *mpctx, double sleeptime); +void mp_wakeup_core(struct MPContext *mpctx); +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); diff --git a/player/loadfile.c b/player/loadfile.c index ebead19e4e..e89047f0aa 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -204,7 +204,7 @@ void reselect_demux_stream(struct MPContext *mpctx, struct track *track) static void wakeup_demux(void *pctx) { struct MPContext *mpctx = pctx; - mp_input_wakeup(mpctx->input); + mp_wakeup_core(mpctx); } static void enable_demux_thread(struct MPContext *mpctx, struct demuxer *demux) diff --git a/player/lua.c b/player/lua.c index 84d7295640..b805a34ca8 100644 --- a/player/lua.c +++ b/player/lua.c @@ -971,7 +971,7 @@ static int script_set_osd_ass(lua_State *L) if (!text[0]) text = " "; // force external OSD initialization osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text); - mp_input_wakeup(ctx->mpctx->input); + mp_wakeup_core(ctx->mpctx); return 0; } diff --git a/player/main.c b/player/main.c index b3a08082d8..7d2aa399ea 100644 --- a/player/main.c +++ b/player/main.c @@ -306,7 +306,7 @@ static int cfg_include(void *ctx, char *filename, int flags) void wakeup_playloop(void *ctx) { struct MPContext *mpctx = ctx; - mp_input_wakeup(mpctx->input); + mp_wakeup_core(mpctx); } struct MPContext *mp_create(void) diff --git a/player/misc.c b/player/misc.c index 17232ff828..65aad50de7 100644 --- a/player/misc.c +++ b/player/misc.c @@ -267,7 +267,7 @@ static void *thread_wrapper(void *pctx) pthread_mutex_lock(&args->mutex); args->done = true; pthread_mutex_unlock(&args->mutex); - mp_input_wakeup(args->mpctx->input); // this interrupts mp_idle() + mp_wakeup_core(args->mpctx); // this interrupts mp_idle() return NULL; } diff --git a/player/playloop.c b/player/playloop.c index 449813c777..f2f421021d 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -50,13 +50,28 @@ #include "client.h" #include "command.h" -// Wait until mp_input_wakeup(mpctx->input) is called, since the last time +// Wait until mp_wakeup_core() 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) { mp_input_wait(mpctx->input, sleeptime); } +// Cause the playloop to run. This can be called from any thread. If called +// from within the playloop itself, it will be run immediately again, instead +// of going to sleep in the next mp_wait_events(). +void mp_wakeup_core(struct MPContext *mpctx) +{ + mp_input_wakeup(mpctx->input); +} + +// Opaque callback variant of mp_wakeup_core(). +void mp_wakeup_core_cb(void *ctx) +{ + struct MPContext *mpctx = ctx; + mp_wakeup_core(mpctx); +} + // 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) @@ -816,6 +831,8 @@ int handle_force_window(struct MPContext *mpctx, bool force) .osd = mpctx->osd, .encode_lavc_ctx = mpctx->encode_lavc_ctx, .opengl_cb_context = mpctx->gl_cb_ctx, + .wakeup_cb = mp_wakeup_core_cb, + .wakeup_ctx = mpctx, }; mpctx->video_out = init_best_video_out(mpctx->global, &ex); if (!mpctx->video_out) diff --git a/player/video.c b/player/video.c index 5e87564690..e66426f24d 100644 --- a/player/video.c +++ b/player/video.c @@ -466,6 +466,8 @@ int reinit_video_chain_src(struct MPContext *mpctx, struct lavfi_pad *src) .osd = mpctx->osd, .encode_lavc_ctx = mpctx->encode_lavc_ctx, .opengl_cb_context = mpctx->gl_cb_ctx, + .wakeup_cb = mp_wakeup_core_cb, + .wakeup_ctx = mpctx, }; mpctx->video_out = init_best_video_out(mpctx->global, &ex); if (!mpctx->video_out) { |