From f061befb3338c5cd6837701b4232dad48340ab6c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 12 Feb 2015 16:53:56 +0100 Subject: 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. --- TOOLS/lua/README.md | 2 ++ TOOLS/lua/audio-hotplug-test.lua | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 TOOLS/lua/audio-hotplug-test.lua (limited to 'TOOLS/lua') diff --git a/TOOLS/lua/README.md b/TOOLS/lua/README.md index f7cdf2a590..e9044823cd 100644 --- a/TOOLS/lua/README.md +++ b/TOOLS/lua/README.md @@ -10,3 +10,5 @@ to mpv's command line. Where appropriate, they may also be placed in ~/.config/mpv/scripts/ from where they will be automatically loaded when mpv starts. + +Some of these are just for testing mpv internals. diff --git a/TOOLS/lua/audio-hotplug-test.lua b/TOOLS/lua/audio-hotplug-test.lua new file mode 100644 index 0000000000..8dedc68cbe --- /dev/null +++ b/TOOLS/lua/audio-hotplug-test.lua @@ -0,0 +1,8 @@ +local utils = require("mp.utils") + +mp.observe_property("audio-device-list", "native", function(name, val) + print("Audio device list changed:") + for index, e in ipairs(val) do + print(" - '" .. e.name .. "' (" .. e.description .. ")") + end +end) -- cgit v1.2.3