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 /audio/out/ao.c | |
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 'audio/out/ao.c')
-rw-r--r-- | audio/out/ao.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c index cd2b9e8089..15c0f8139e 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -28,7 +28,6 @@ #include "audio/format.h" #include "audio/audio.h" -#include "input/input.h" #include "options/options.h" #include "options/m_config.h" #include "common/msg.h" @@ -127,8 +126,11 @@ const struct m_obj_list ao_obj_list = { }; static struct ao *ao_alloc(bool probing, struct mpv_global *global, - struct input_ctx *input_ctx, char *name, char **args) + void (*wakeup_cb)(void *ctx), void *wakeup_ctx, + char *name, char **args) { + assert(wakeup_cb); + struct MPOpts *opts = global->opts; struct mp_log *log = mp_log_new(NULL, global->log, "ao"); struct m_obj_desc desc; @@ -143,7 +145,8 @@ static struct ao *ao_alloc(bool probing, struct mpv_global *global, .driver = desc.p, .probing = probing, .global = global, - .input_ctx = input_ctx, + .wakeup_cb = wakeup_cb, + .wakeup_ctx = wakeup_ctx, .log = mp_log_new(ao, log, name), .def_buffer = opts->audio_buffer, .client_name = talloc_strdup(ao, opts->audio_client_name), @@ -161,12 +164,12 @@ error: } static struct ao *ao_init(bool probing, struct mpv_global *global, - struct input_ctx *input_ctx, + void (*wakeup_cb)(void *ctx), void *wakeup_ctx, struct encode_lavc_context *encode_lavc_ctx, int flags, int samplerate, int format, struct mp_chmap channels, char *dev, char *name, char **args) { - struct ao *ao = ao_alloc(probing, global, input_ctx, name, args); + struct ao *ao = ao_alloc(probing, global, wakeup_cb, wakeup_ctx, name, args); if (!ao) return NULL; ao->samplerate = samplerate; @@ -197,8 +200,9 @@ static struct ao *ao_init(bool probing, struct mpv_global *global, snprintf(redirect, sizeof(redirect), "%s", ao->redirect); snprintf(rdevice, sizeof(rdevice), "%s", ao->device ? ao->device : ""); talloc_free(ao); - return ao_init(probing, global, input_ctx, encode_lavc_ctx, flags, - samplerate, format, channels, rdevice, redirect, NULL); + return ao_init(probing, global, wakeup_cb, wakeup_ctx, + encode_lavc_ctx, flags, samplerate, format, channels, + rdevice, redirect, NULL); } goto fail; } @@ -248,7 +252,7 @@ static void split_ao_device(void *tmp, char *opt, char **out_ao, char **out_dev) struct ao *ao_init_best(struct mpv_global *global, int init_flags, - struct input_ctx *input_ctx, + void (*wakeup_cb)(void *ctx), void *wakeup_ctx, struct encode_lavc_context *encode_lavc_ctx, int samplerate, int format, struct mp_chmap channels) { @@ -304,8 +308,8 @@ struct ao *ao_init_best(struct mpv_global *global, dev = pref_dev; mp_verbose(log, "Using preferred device '%s'\n", dev); } - ao = ao_init(probing, global, input_ctx, encode_lavc_ctx, init_flags, - samplerate, format, channels, dev, + ao = ao_init(probing, global, wakeup_cb, wakeup_ctx, encode_lavc_ctx, + init_flags, samplerate, format, channels, dev, entry->name, entry->attribs); if (ao) break; @@ -409,8 +413,7 @@ int ao_query_and_reset_events(struct ao *ao, int events) static void ao_add_events(struct ao *ao, int events) { atomic_fetch_or(&ao->events_, events); - if (ao->input_ctx) - mp_input_wakeup(ao->input_ctx); + ao->wakeup_cb(ao->wakeup_ctx); } // Request that the player core destroys and recreates the AO. Fully thread-safe. @@ -494,7 +497,8 @@ bool ao_untimed(struct ao *ao) struct ao_hotplug { struct mpv_global *global; - struct input_ctx *input_ctx; + void (*wakeup_cb)(void *ctx); + void *wakeup_ctx; // A single AO instance is used to listen to hotplug events. It wouldn't // make much sense to allow multiple AO drivers; all sane platforms have // a single such audio API. @@ -506,12 +510,14 @@ struct ao_hotplug { }; struct ao_hotplug *ao_hotplug_create(struct mpv_global *global, - struct input_ctx *input_ctx) + void (*wakeup_cb)(void *ctx), + void *wakeup_ctx) { struct ao_hotplug *hp = talloc_ptrtype(NULL, hp); *hp = (struct ao_hotplug){ .global = global, - .input_ctx = input_ctx, + .wakeup_cb = wakeup_cb, + .wakeup_ctx = wakeup_ctx, .needs_update = true, }; return hp; @@ -564,7 +570,7 @@ struct ao_device_list *ao_hotplug_get_device_list(struct ao_hotplug *hp) if (d == &audio_out_null) break; // don't add unsafe/special entries - struct ao *ao = ao_alloc(true, hp->global, hp->input_ctx, + struct ao *ao = ao_alloc(true, hp->global, hp->wakeup_cb, hp->wakeup_ctx, (char *)d->name, NULL); if (!ao) continue; @@ -605,9 +611,13 @@ void ao_hotplug_destroy(struct ao_hotplug *hp) talloc_free(hp); } +static void dummy_wakeup(void *ctx) +{ +} + void ao_print_devices(struct mpv_global *global, struct mp_log *log) { - struct ao_hotplug *hp = ao_hotplug_create(global, NULL); + struct ao_hotplug *hp = ao_hotplug_create(global, dummy_wakeup, NULL); struct ao_device_list *list = ao_hotplug_get_device_list(hp); mp_info(log, "List of detected audio devices:\n"); for (int n = 0; n < list->num_devices; n++) { |