mirror of
https://github.com/mpv-player/mpv
synced 2025-01-03 13:32:16 +00:00
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.
This commit is contained in:
parent
8aa8417aa3
commit
144571da9b
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user