From 7f9bcfbc7d84caccce6647b197b55e57b0b0892f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 4 Aug 2010 04:21:39 -0700 Subject: [PATCH] Do not enumerate PulseAudio devices if a context fails to connect --- Alc/pulseaudio.c | 53 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c index ee1499cf..2104d8c1 100644 --- a/Alc/pulseaudio.c +++ b/Alc/pulseaudio.c @@ -666,21 +666,6 @@ static void probe_devices(ALboolean capture) { pa_threaded_mainloop *loop; - if(capture == AL_FALSE) - { - allDevNameMap = malloc(sizeof(DevMap) * 1); - allDevNameMap[0].name = strdup("PulseAudio Default"); - allDevNameMap[0].device_name = NULL; - numDevNames = 1; - } - else - { - allCaptureDevNameMap = malloc(sizeof(DevMap) * 1); - allCaptureDevNameMap[0].name = strdup("PulseAudio Default"); - allCaptureDevNameMap[0].device_name = NULL; - numCaptureDevNames = 1; - } - if((loop=ppa_threaded_mainloop_new()) && ppa_threaded_mainloop_start(loop) >= 0) { @@ -693,9 +678,23 @@ static void probe_devices(ALboolean capture) pa_operation *o; if(capture == AL_FALSE) + { + allDevNameMap = malloc(sizeof(DevMap) * 1); + allDevNameMap[0].name = strdup("PulseAudio Default"); + allDevNameMap[0].device_name = NULL; + numDevNames = 1; + o = ppa_context_get_sink_info_list(context, sink_device_callback, loop); + } else + { + allCaptureDevNameMap = malloc(sizeof(DevMap) * 1); + allCaptureDevNameMap[0].name = strdup("PulseAudio Default"); + allCaptureDevNameMap[0].device_name = NULL; + numCaptureDevNames = 1; + o = ppa_context_get_source_info_list(context, source_device_callback, loop); + } while(ppa_operation_get_state(o) == PA_OPERATION_RUNNING) ppa_threaded_mainloop_wait(loop); ppa_operation_unref(o); @@ -1316,7 +1315,29 @@ void alc_pulse_probe(int type) //{{{ if(!pulse_load()) return; if(type == DEVICE_PROBE) - AppendDeviceList(pulse_device); + { + pa_threaded_mainloop *loop; + + if((loop=ppa_threaded_mainloop_new()) && + ppa_threaded_mainloop_start(loop) >= 0) + { + pa_context *context; + + ppa_threaded_mainloop_lock(loop); + context = connect_context(loop); + if(context) + { + AppendDeviceList(pulse_device); + + ppa_context_disconnect(context); + ppa_context_unref(context); + } + ppa_threaded_mainloop_unlock(loop); + ppa_threaded_mainloop_stop(loop); + } + if(loop) + ppa_threaded_mainloop_free(loop); + } else if(type == ALL_DEVICE_PROBE) { ALuint i;