mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
26b6873ffd
commit
885e991312
|
@ -114,6 +114,13 @@ OSStatus ca_select_device(struct ao *ao, char* name, AudioDeviceID *device)
|
||||||
kAudioObjectSystemObject, &p_addr, 0, 0, &size, &v);
|
kAudioObjectSystemObject, &p_addr, 0, 0, &size, &v);
|
||||||
CFRelease(uid);
|
CFRelease(uid);
|
||||||
CHECK_CA_ERROR("unable to query for device 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 {
|
} else {
|
||||||
// device not set by user, get the default one
|
// device not set by user, get the default one
|
||||||
err = CA_GET(kAudioObjectSystemObject,
|
err = CA_GET(kAudioObjectSystemObject,
|
||||||
|
|
Loading…
Reference in New Issue