summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-28 17:21:49 +0200
committerwm4 <wm4@nowhere>2015-09-28 22:03:14 +0200
commit144571da9b5b595d7bb49822e78887771554b68b (patch)
treed04075e62a604da01327f50c014589075ef3f395 /audio
parent8aa8417aa35fd30990a1695380f22179848c6463 (diff)
downloadmpv-144571da9b5b595d7bb49822e78887771554b68b.tar.bz2
mpv-144571da9b5b595d7bb49822e78887771554b68b.tar.xz
ao_coreaudio_utils: fix error handling in device listing code
This could sometimes cause crashes in hotplug events. (Apparently in cases when CoreAudio changes its state asynchronously, or such.) CA_GET_STR() does not set the string if there was an error, so errors have to be strictly checked before using it.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_coreaudio_utils.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index f6463a314a..7d14b3f75c 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -51,7 +51,9 @@ static bool ca_is_output_device(struct ao *ao, AudioDeviceID dev)
size_t n_buffers;
AudioBufferList *buffers;
const ca_scope scope = kAudioDevicePropertyStreamConfiguration;
- CA_GET_ARY_O(dev, scope, &buffers, &n_buffers);
+ OSStatus err = CA_GET_ARY_O(dev, scope, &buffers, &n_buffers);
+ if (err != noErr)
+ return false;
talloc_free(buffers);
return n_buffers > 0;
}
@@ -71,11 +73,16 @@ void ca_get_device_list(struct ao *ao, struct ao_device_list *list)
char *name;
char *desc;
err = CA_GET_STR(devs[i], kAudioDevicePropertyDeviceUID, &name);
+ if (err != noErr) {
+ MP_VERBOSE(ao, "skipping device %d, which has no UID\n", i);
+ talloc_free(ta_ctx);
+ continue;
+ }
talloc_steal(ta_ctx, name);
err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &desc);
- talloc_steal(ta_ctx, desc);
if (err != noErr)
- desc = "Unknown";
+ desc = talloc_strdup(NULL, "Unknown");
+ talloc_steal(ta_ctx, desc);
ao_device_list_add(list, ao, &(struct ao_device_desc){name, desc});
talloc_free(ta_ctx);
}