[pulseaudio-commits] r1865 - in /branches/lennart/src/modules: module-alsa-sink.c module-alsa-source.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Sep 18 16:35:06 PDT 2007


Author: lennart
Date: Wed Sep 19 01:35:05 2007
New Revision: 1865

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1865&root=pulseaudio&view=rev
Log:
fall back to plughw:, if hw: doesn't work, in the alsa source, too

Modified:
    branches/lennart/src/modules/module-alsa-sink.c
    branches/lennart/src/modules/module-alsa-source.c

Modified: branches/lennart/src/modules/module-alsa-sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-alsa-sink.c?rev=1865&root=pulseaudio&r1=1864&r2=1865&view=diff
==============================================================================
--- branches/lennart/src/modules/module-alsa-sink.c (original)
+++ branches/lennart/src/modules/module-alsa-sink.c Wed Sep 19 01:35:05 2007
@@ -774,6 +774,8 @@
         break;
     }
     
+    u->device_name = dev;
+        
     if (use_mmap && !b) {
         pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
         u->use_mmap = use_mmap = b;
@@ -787,8 +789,6 @@
         goto fail;
     }
 
-    u->device_name = dev;
-        
     if ((err = pa_alsa_set_sw_params(u->pcm_handle)) < 0) {
         pa_log("Failed to set software parameters: %s", snd_strerror(err));
         goto fail;

Modified: branches/lennart/src/modules/module-alsa-source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/modules/module-alsa-source.c?rev=1865&root=pulseaudio&r1=1864&r2=1865&view=diff
==============================================================================
--- branches/lennart/src/modules/module-alsa-source.c (original)
+++ branches/lennart/src/modules/module-alsa-source.c Wed Sep 19 01:35:05 2007
@@ -660,7 +660,7 @@
     
     pa_modargs *ma = NULL;
     struct userdata *u = NULL;
-    const char *dev;
+    char *dev;
     pa_sample_spec ss;
     pa_channel_map map;
     unsigned nfrags, frag_size;
@@ -718,24 +718,45 @@
     pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY, u->thread_mq.inq);
 
     snd_config_update_free_global();
-    if ((err = snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
-        pa_log("Error opening PCM device %s: %s", dev, snd_strerror(err));
-        goto fail;
-    }
-
-    u->device_name = pa_xstrdup(dev);
-
-    if ((err = snd_pcm_info(u->pcm_handle, pcm_info)) < 0) {
-        pa_log("Error fetching PCM info: %s", snd_strerror(err));
-        goto fail;
-    }
-
-    b = use_mmap;
-    if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, &b)) < 0) {
-        pa_log("Failed to set hardware parameters: %s", snd_strerror(err));
-        goto fail;
-    }
-
+
+    dev = pa_xstrdup(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE));
+    
+    for (;;) {
+        
+        if ((err = snd_pcm_open(&u->pcm_handle, dev, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
+            pa_log("Error opening PCM device %s: %s", dev, snd_strerror(err));
+            pa_xfree(dev);
+            goto fail;
+        }
+
+        b = use_mmap;
+        if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, &b)) < 0) {
+
+            if (err == -EPERM) {
+                /* Hmm, some hw is very exotic, so we retry with plughw, if hw didn't work */
+                
+                if (pa_startswith(dev, "hw:")) {
+                    char *d = pa_sprintf_malloc("plughw:%s", dev+3);
+                    pa_log_debug("Opening the device as '%s' didn't work, retrying with '%s'.", dev, d);
+                    pa_xfree(dev);
+                    dev = d;
+
+                    snd_pcm_close(u->pcm_handle);
+                    u->pcm_handle = NULL;
+                    continue;
+                }
+            }
+            
+            pa_log("Failed to set hardware parameters: %s", snd_strerror(err));
+            pa_xfree(dev);
+            goto fail;
+        }
+
+        break;
+    }
+
+    u->device_name = dev;
+    
     if (use_mmap && !b) {
         pa_log_info("Device doesn't support mmap(), falling back to UNIX read/write mode.");
         u->use_mmap = use_mmap = b;
@@ -743,6 +764,11 @@
 
     if (u->use_mmap)
         pa_log_info("Successfully enabled mmap() mode.");
+
+    if ((err = snd_pcm_info(u->pcm_handle, pcm_info)) < 0) {
+        pa_log("Error fetching PCM info: %s", snd_strerror(err));
+        goto fail;
+    }
 
     if ((err = pa_alsa_set_sw_params(u->pcm_handle)) < 0) {
         pa_log("Failed to set software parameters: %s", snd_strerror(err));




More information about the pulseaudio-commits mailing list