From 7c07da57e3797b26c6e896bd27afc2ed7d639a18 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 12 Oct 2014 12:11:32 +0200 Subject: coreaudio: use the new device selection API The CoreAudio API is built around device IDs so we store the integer as string and read it back. --- audio/out/ao_coreaudio_utils.c | 44 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'audio/out/ao_coreaudio_utils.c') diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index 08214ef387..cc08f4c6ab 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -28,42 +28,36 @@ #include "osdep/endian.h" #include "audio/format.h" -void ca_print_device_list(struct ao *ao) +void ca_get_device_list(struct ao *ao, struct ao_device_list *list) { - 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]); + char name[32]; + char *desc; + sprintf(name, "%d", devs[i]); + err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &desc); + if (err != noErr) + desc = "Unknown"; + ao_device_list_add(list, ao, &(struct ao_device_desc){name, desc}); } - talloc_free(devs); - coreaudio_error: - MP_INFO(ao, "%s", help); - talloc_free(help); + return; } -OSStatus ca_select_device(struct ao *ao, int selection, AudioDeviceID *device) +OSStatus ca_select_device(struct ao *ao, char* name, AudioDeviceID *device) { OSStatus err = noErr; + int selection = name ? strtol(name, (char **)NULL, 10) : -1; + if (errno == EINVAL || errno == ERANGE) { + selection = -1; + MP_ERR(ao, "device identifier '%s' is invalid\n", name); + } *device = 0; if (selection < 0) { // device not set by user, get the default one @@ -76,14 +70,14 @@ OSStatus ca_select_device(struct ao *ao, int selection, AudioDeviceID *device) } if (mp_msg_test(ao->log, MSGL_V)) { - char *name; - err = CA_GET_STR(*device, kAudioObjectPropertyName, &name); + char *desc; + err = CA_GET_STR(*device, kAudioObjectPropertyName, &desc); CHECK_CA_ERROR("could not get selected audio device name"); MP_VERBOSE(ao, "selected audio output device: %s (%" PRIu32 ")\n", - name, *device); + desc, *device); - talloc_free(name); + talloc_free(desc); } coreaudio_error: -- cgit v1.2.3