From 25a941666ad8691dfc0f389baf642fa2690ba334 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 9 Jun 2010 18:22:05 -0700 Subject: Prevent multiple PulseAudio devices from getting the same name --- Alc/pulseaudio.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'Alc') diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c index e4c6f2fc..594126cf 100644 --- a/Alc/pulseaudio.c +++ b/Alc/pulseaudio.c @@ -410,7 +410,10 @@ static void sink_info_callback(pa_context *context, const pa_sink_info *info, in static void sink_device_callback(pa_context *context, const pa_sink_info *info, int eol, void *pdata) //{{{ { pa_threaded_mainloop *loop = pdata; + char str[1024]; void *temp; + int count; + ALuint i; (void)context; @@ -420,12 +423,24 @@ static void sink_device_callback(pa_context *context, const pa_sink_info *info, return; } + count = 0; + do { + if(count == 0) + snprintf(str, sizeof(str), "%s via PulseAudio", info->description); + else + snprintf(str, sizeof(str), "%s #%d via PulseAudio", info->description, count+1); + count++; + + for(i = 0;i < numDevNames;i++) + { + if(strcmp(str, allDevNameMap[i].name) == 0) + break; + } + } while(i != numDevNames); + temp = realloc(allDevNameMap, (numDevNames+1) * sizeof(*allDevNameMap)); if(temp) { - char str[1024]; - snprintf(str, sizeof(str), "%s via PulseAudio", info->description); - allDevNameMap = temp; allDevNameMap[numDevNames].name = strdup(str); allDevNameMap[numDevNames].device_name = strdup(info->name); @@ -436,7 +451,10 @@ static void sink_device_callback(pa_context *context, const pa_sink_info *info, static void source_device_callback(pa_context *context, const pa_source_info *info, int eol, void *pdata) //{{{ { pa_threaded_mainloop *loop = pdata; + char str[1024]; void *temp; + int count; + ALuint i; (void)context; @@ -446,12 +464,24 @@ static void source_device_callback(pa_context *context, const pa_source_info *in return; } + count = 0; + do { + if(count == 0) + snprintf(str, sizeof(str), "%s via PulseAudio", info->description); + else + snprintf(str, sizeof(str), "%s #%d via PulseAudio", info->description, count+1); + count++; + + for(i = 0;i < numCaptureDevNames;i++) + { + if(strcmp(str, allCaptureDevNameMap[i].name) == 0) + break; + } + } while(i != numCaptureDevNames); + temp = realloc(allCaptureDevNameMap, (numCaptureDevNames+1) * sizeof(*allCaptureDevNameMap)); if(temp) { - char str[256]; - snprintf(str, sizeof(str), "%s via PulseAudio", info->description); - allCaptureDevNameMap = temp; allCaptureDevNameMap[numCaptureDevNames].name = strdup(str); allCaptureDevNameMap[numCaptureDevNames].device_name = strdup(info->name); -- cgit v1.2.3