From 885e99131259094a829c4023719ebee979aa72f3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 8 Jul 2016 16:08:11 +0200 Subject: ao_coreaudio: error out when selecting invalid device When selecting a device that simply doesn't exist with --audio-device, AudioUnit will still initialize and start playback without complaining. But it will never call the audio render callback, which leads to audio playback simply not progressing. I couldn't find a way to get AudioUnit to report an error at all, so here's a crappy hack that takes care of this in most cases. We assume that all devices have a kAudioDevicePropertyDeviceIsAlive property. Invalid devices will error when querying the property (with 'obj!' as status code). This is not the correct fix, because we try to double-guess AudioUnit's behavior by accessing a lower label API. Suggestions welcome. --- audio/out/ao_coreaudio_utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index 8f9690fc22..0bcc0d62a1 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -114,6 +114,13 @@ OSStatus ca_select_device(struct ao *ao, char* name, AudioDeviceID *device) kAudioObjectSystemObject, &p_addr, 0, 0, &size, &v); CFRelease(uid); CHECK_CA_ERROR("unable to query for device UID"); + + uint32_t is_alive = 1; + err = CA_GET(*device, kAudioDevicePropertyDeviceIsAlive, &is_alive); + CHECK_CA_ERROR("could not check whether device is alive (invalid device?)"); + + if (!is_alive) + MP_WARN(ao, "device is not alive!\n"); } else { // device not set by user, get the default one err = CA_GET(kAudioObjectSystemObject, -- cgit v1.2.3