From b021d038c2217903e511ca3673d5f2f1b996c4d4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 9 Nov 2014 09:58:44 +0100 Subject: audio/out: make ao_request_reload() idempotent This is what you would expect. Before this commit, each ao_request_reload() call would just queue a reload command, and then recreate the AO for the number of times the function was called. Instead of sending a command, introduce some sort of event retrieval mechanism. At least for the reload case, use atomics, because we're too lazy to setup an extra mutex. --- audio/out/ao.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'audio/out/ao.c') diff --git a/audio/out/ao.c b/audio/out/ao.c index baf6db1e45..b92a78ff26 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -397,6 +397,22 @@ bool ao_eof_reached(struct ao *ao) return ao->api->get_eof ? ao->api->get_eof(ao) : true; } +// Query the AO_EVENT_*s as requested by the events parameter, and return them. +int ao_query_and_reset_events(struct ao *ao, int events) +{ + int actual_events = 0; + if (atomic_load(&ao->request_reload)) // don't need to reset it + actual_events |= AO_EVENT_RELOAD; + return actual_events & events; +} + +// Request that the player core destroys and recreates the AO. +void ao_request_reload(struct ao *ao) +{ + atomic_store(&ao->request_reload, true); + mp_input_wakeup(ao->input_ctx); +} + bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, struct mp_chmap *map) { @@ -409,13 +425,6 @@ bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, return mp_chmap_sel_get_def(s, map, num); } -// Request that the player core destroys and recreates the AO. -void ao_request_reload(struct ao *ao) -{ - const char *cmd[] = {"ao_reload", NULL}; - mp_input_run_cmd(ao->input_ctx, cmd); -} - // --- The following functions just return immutable information. void ao_get_format(struct ao *ao, struct mp_audio *format) -- cgit v1.2.3