summaryrefslogtreecommitdiffstats
path: root/audio/out/internal.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-12 16:53:56 +0100
committerwm4 <wm4@nowhere>2015-02-12 17:17:41 +0100
commitf061befb3338c5cd6837701b4232dad48340ab6c (patch)
tree13d8526248cc5bf68fb5d563fbf4cdd6e5dcc2aa /audio/out/internal.h
parentc152c590843a192761cff585a84ce57385d83d40 (diff)
downloadmpv-f061befb3338c5cd6837701b4232dad48340ab6c.tar.bz2
mpv-f061befb3338c5cd6837701b4232dad48340ab6c.tar.xz
audio: add device change notification for hotplugging
Not very important for the command line player; but GUI applications will want to know about this. This only adds the internal API; support for specific audio outputs comes later. This reuses the ao struct as context for the hotplug event listener, similar to how the "old" device listing API did. This is probably a bit unclean and confusing. One argument got reusing it is that otherwise rewriting parts of ao_pulse would be required (because the PulseAudio API requires so damn much boilerplate). Another is that --ao-defaults is applied to the hotplug dummy ao struct, which automatically applies such defaults even to the hotplug context. Notification works through the property observation mechanism in the client API. The notification chain is a bit complicated: the AO notifies the player, which in turn notifies the clients, which in turn will actually retrieve the device list. (It still has the advantage that it's slightly cleaner, since the AO stuff doesn't need to know about client API issues.) The weird handling of atomic flags in ao.c is because we still don't require real atomics from the compiler. Otherwise we'd just use atomic bitwise operations.
Diffstat (limited to 'audio/out/internal.h')
-rw-r--r--audio/out/internal.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/audio/out/internal.h b/audio/out/internal.h
index 9414208923..19402861a2 100644
--- a/audio/out/internal.h
+++ b/audio/out/internal.h
@@ -59,7 +59,8 @@ struct ao {
// Used during init: if init fails, redirect to this ao
char *redirect;
- atomic_bool request_reload;
+ // Internal events (use ao_request_reload(), ao_hotplug_event())
+ atomic_bool request_reload, request_hotplug;
int buffer;
double def_buffer;
@@ -161,17 +162,19 @@ struct ao_driver {
// Return the list of devices currently available in the system. Use
// ao_device_list_add() to add entries. The selected device will be set as
// ao->device (using ao_device_desc.name).
- // Warning: the ao struct passed doesn't necessarily have ao_driver->init()
- // called on it - in this case, ->uninit() won't be called either
- // after this function. The idea is that list_devs can be called
- // both when no audio or when audio is active. the latter can
- // happen if the audio config change at runtime, and in this case
- // we don't want to force a new connection to the audio server
- // just to update the device list. For runtime updates, ->init()
- // will have been called. In both cases, ao->priv is properly
- // allocated. (Runtime updates are not used/supported yet.)
+ // Warning: the ao struct passed is not initialized with ao_driver->init().
+ // Instead, hotplug_init/hotplug_uninit is called. If these
+ // callbacks are not set, no driver initialization call is done
+ // on the ao struct.
void (*list_devs)(struct ao *ao, struct ao_device_list *list);
+ // If set, these are called before/after ao_driver->list_devs is called.
+ // It is also assumed that the driver can do hotplugging - which means
+ // it is expected to call ao_hotplug_event(ao) whenever the system's
+ // audio device list changes. The player will then call list_devs() again.
+ int (*hotplug_init)(struct ao *ao);
+ void (*hotplug_uninit)(struct ao *ao);
+
// For option parsing (see vo.h)
int priv_size;
const void *priv_defaults;