summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_coreaudio_utils.c
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-06-30 19:09:03 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-07-02 21:43:07 +0200
commit041557b639fad95919068aba617c0cd1bd7cc6a1 (patch)
treeeef70e4de890cdf2bbba2b81e306d84839e9982e /audio/out/ao_coreaudio_utils.c
parent7084e800bebdb2a9c1420763a5d1b17d75054bfc (diff)
downloadmpv-041557b639fad95919068aba617c0cd1bd7cc6a1.tar.bz2
mpv-041557b639fad95919068aba617c0cd1bd7cc6a1.tar.xz
ao_coreaudio: move spdif code to a new AO
The mplayer1/2/mpv CoreAudio audio output historically contained both usage of AUHAL APIs (these go through the CoreAudio audio server) and the Device based APIs (used only for output of compressed formats in exclusive mode). The latter is a very unwieldy and low level API and pretty much forces us to write a lot of code for little workr. Also with the widespread of HDMI, the actual need for outputting compressed audio directly to the device is getting lower (it was very useful with S/PDIF for bandwidth constraints not allowing a number if channels transmitted in LPCM). Considering how invasive it is (uses hog/exclusive mode), the new AO (`ao_coreaudio_device`) is not going to be autoprobed but the user will have to select it.
Diffstat (limited to 'audio/out/ao_coreaudio_utils.c')
-rw-r--r--audio/out/ao_coreaudio_utils.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 052f63d608..4656c2c508 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -26,6 +26,68 @@
#include "audio/out/ao_coreaudio_properties.h"
#include "osdep/timer.h"
+void ca_print_device_list(struct ao *ao)
+{
+ char *help = talloc_strdup(NULL, "Available output devices:\n");
+
+ AudioDeviceID *devs;
+ size_t n_devs;
+
+ OSStatus err =
+ CA_GET_ARY(kAudioObjectSystemObject, kAudioHardwarePropertyDevices,
+ &devs, &n_devs);
+
+ CHECK_CA_ERROR("Failed to get list of output devices.");
+
+ for (int i = 0; i < n_devs; i++) {
+ char *name;
+ err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &name);
+
+ if (err == noErr)
+ talloc_steal(devs, name);
+ else
+ name = "Unknown";
+
+ help = talloc_asprintf_append(
+ help, " * %s (id: %" PRIu32 ")\n", name, devs[i]);
+ }
+
+ talloc_free(devs);
+
+coreaudio_error:
+ MP_INFO(ao, "%s", help);
+ talloc_free(help);
+}
+
+OSStatus ca_select_device(struct ao *ao, int selection, AudioDeviceID *device)
+{
+ OSStatus err = noErr;
+ *device = 0;
+ if (selection < 0) {
+ // device not set by user, get the default one
+ err = CA_GET(kAudioObjectSystemObject,
+ kAudioHardwarePropertyDefaultOutputDevice,
+ device);
+ CHECK_CA_ERROR("could not get default audio device");
+ } else {
+ *device = selection;
+ }
+
+ if (mp_msg_test(ao->log, MSGL_V)) {
+ char *name;
+ err = CA_GET_STR(*device, kAudioObjectPropertyName, &name);
+ CHECK_CA_ERROR("could not get selected audio device name");
+
+ MP_VERBOSE(ao, "selected audio output device: %s (%" PRIu32 ")\n",
+ name, *device);
+
+ talloc_free(name);
+ }
+
+coreaudio_error:
+ return err;
+}
+
char *fourcc_repr(void *talloc_ctx, uint32_t code)
{
// Extract FourCC letters from the uint32_t and finde out if it's a valid