[pulseaudio-discuss] alsa: Fix device reservation fails when a device string has seperator(, )

Submitted by KimJeongYeon on April 26, 2016, 2:23 a.m.

Details

Message ID 1461637421-20056-1-git-send-email-jeongyeon.kim@samsung.com
State New
Headers show
Series "alsa: Fix device reservation fails when a device string has seperator(, )" ( rev: 2 ) in PulseAudio

Not browsing as part of any series.

Commit Message

KimJeongYeon April 26, 2016, 2:23 a.m.
For example, the device parameter of pa_alsa_get_reserve_name() is "hw:USB,0",
snd_card_get_index() always fails. Because seperator(,) wasn't regarded.
Therefore, JACK couldn't obtain audio device from Pulseaudio.

Signed-off-by: KimJeongYeon <jeongyeon.kim@samsung.com>
---
 src/modules/alsa/alsa-util.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index a4bb449..3221203 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -1345,22 +1345,31 @@  char *pa_alsa_get_driver_name_by_pcm(snd_pcm_t *pcm) {
 
 char *pa_alsa_get_reserve_name(const char *device) {
     const char *t;
+    char *dev;
+    size_t l;
     int i;
 
     pa_assert(device);
 
     if ((t = strchr(device, ':')))
-        device = t+1;
+        device = t + 1;
 
-    if ((i = snd_card_get_index(device)) < 0) {
+    l = strcspn(device, ",");
+    dev = pa_xstrndup(device, l);
+
+    if ((i = snd_card_get_index(dev)) < 0) {
         int32_t k;
 
-        if (pa_atoi(device, &k) < 0)
+        if (pa_atoi(dev, &k) < 0) {
+            pa_xfree(dev);
             return NULL;
+        }
 
         i = (int) k;
     }
 
+    pa_xfree(dev);
+
     return pa_sprintf_malloc("Audio%i", i);
 }
 
@@ -1514,7 +1523,7 @@  static int mixer_class_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_
 }
 
 static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask,
-			snd_hctl_elem_t *helem, snd_mixer_elem_t *melem)
+        snd_hctl_elem_t *helem, snd_mixer_elem_t *melem)
 {
     int err;
     const char *name = snd_hctl_elem_get_name(helem);
@@ -1531,7 +1540,7 @@  static int mixer_class_event(snd_mixer_class_t *class, unsigned int mask,
 
             if ((err = snd_mixer_elem_attach(new_melem, helem)) < 0) {
                 pa_log_warn("snd_mixer_elem_attach failed: %s", pa_alsa_strerror(err));
-		snd_mixer_elem_free(melem);
+                snd_mixer_elem_free(melem);
                 return 0;
             }