osxaudio: iterate device only if needed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2251>
This commit is contained in:
Ignacio Casal Quinteiro 2022-03-30 12:48:02 +02:00 committed by GStreamer Marge Bot
parent a4a4d295a1
commit 57fed3c911

View file

@ -1183,11 +1183,28 @@ done:
static gboolean
gst_core_audio_select_device_impl (GstCoreAudio * core_audio)
{
AudioDeviceID *devices = NULL;
AudioDeviceID device_id = core_audio->device_id;
gint i, ndevices = 0;
gboolean output = !core_audio->is_src;
gboolean res = FALSE;
/* Here we decide if selected device is valid or autoselect
* the default one when required */
if (device_id == kAudioDeviceUnknown) {
AudioDeviceID default_device_id;
/* Find the ID of the default output device */
default_device_id = _audio_system_get_default_device (output);
if (default_device_id != kAudioDeviceUnknown) {
device_id = default_device_id;
res = TRUE;
} else {
GST_ERROR ("No device of required type available");
res = FALSE;
}
} else {
AudioDeviceID *devices = NULL;
gint i, ndevices = 0;
#ifdef GST_CORE_AUDIO_DEBUG
AudioChannelLayout *channel_layout;
#endif
@ -1196,6 +1213,7 @@ gst_core_audio_select_device_impl (GstCoreAudio * core_audio)
if (ndevices < 1) {
GST_ERROR ("no audio output devices found");
g_free (devices);
goto done;
}
@ -1226,22 +1244,6 @@ gst_core_audio_select_device_impl (GstCoreAudio * core_audio)
}
#endif
/* Here we decide if selected device is valid or autoselect
* the default one when required */
if (device_id == kAudioDeviceUnknown) {
AudioDeviceID default_device_id;
/* Find the ID of the default output device */
default_device_id = _audio_system_get_default_device (output);
if (default_device_id != kAudioDeviceUnknown) {
device_id = default_device_id;
res = TRUE;
} else {
GST_ERROR ("No device of required type available");
res = FALSE;
}
} else {
for (i = 0; i < ndevices; i++) {
if (device_id == devices[i]) {
res = TRUE;
@ -1249,6 +1251,8 @@ gst_core_audio_select_device_impl (GstCoreAudio * core_audio)
}
}
g_free (devices);
if (res && !_audio_device_is_alive (device_id, output)) {
GST_ERROR ("Requested device not usable");
res = FALSE;
@ -1260,7 +1264,6 @@ gst_core_audio_select_device_impl (GstCoreAudio * core_audio)
core_audio->device_id = device_id;
done:
g_free (devices);
return res;
}