[vlc-commits] ALSA: follow initialization order from snd_pcm_set_params()

Rémi Denis-Courmont git at videolan.org
Wed May 30 18:20:43 CEST 2012


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 12 10:05:16 2012 +0300| [13f28a4e75f496e22b37e632c4d347fc0dd5873a] | committer: Rémi Denis-Courmont

ALSA: follow initialization order from snd_pcm_set_params()

This should fix support for or work around bugs in, some drivers:
 * explicitly disable soft-resampler,
 * define access mode before sample format,
 * set buffer before period,
 * use period time rather than period count.
(cherry picked from commit d80d6da77e3074d3ecc67fb70a8305d08f137f43)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=13f28a4e75f496e22b37e632c4d347fc0dd5873a
---

 modules/audio_output/alsa.c |   53 ++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index a29b3fa..c742721 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -361,6 +361,21 @@ static int Open (vlc_object_t *obj)
     snd_pcm_hw_params_any (pcm, hw);
     Dump (aout, "initial hardware setup:\n", snd_pcm_hw_params_dump, hw);
 
+    val = snd_pcm_hw_params_set_rate_resample(pcm, hw, 0);
+    if (val)
+    {
+        msg_Err (aout, "cannot disable resampling: %s", snd_strerror (val));
+        goto error;
+    }
+
+    val = snd_pcm_hw_params_set_access (pcm, hw,
+                                        SND_PCM_ACCESS_RW_INTERLEAVED);
+    if (val)
+    {
+        msg_Err (aout, "cannot set access mode: %s", snd_strerror (val));
+        goto error;
+    }
+
     /* Set sample format */
     if (snd_pcm_hw_params_test_format (pcm, hw, pcm_format) == 0)
         ;
@@ -395,14 +410,6 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
 
-    val = snd_pcm_hw_params_set_access (pcm, hw,
-                                        SND_PCM_ACCESS_RW_INTERLEAVED);
-    if (val)
-    {
-        msg_Err (aout, "cannot set access mode: %s", snd_strerror (val));
-        goto error;
-    }
-
     /* Set channels count */
     /* By default, ALSA plug will pad missing channels with zeroes, which is
      * usually fine. However, it will also discard extraneous channels, which
@@ -428,30 +435,30 @@ static int Open (vlc_object_t *obj)
         msg_Dbg (aout, "resampling from %d Hz to %d Hz",
                  aout->format.i_rate, rate);
 
-    /* Set number of periods (at least two) */
-    param = 2;
-    val = snd_pcm_hw_params_set_periods_min (pcm, hw, &param, NULL);
-    if (val)
-    {
-        msg_Err (aout, "cannot set minimum of %u periods: %s", param,
-                 snd_strerror (val));
-        goto error;
-    }
-
     /* Set buffer size */
     param = AOUT_MAX_ADVANCE_TIME;
     val = snd_pcm_hw_params_set_buffer_time_near (pcm, hw, &param, NULL);
     if (val)
     {
-        msg_Err (aout, "cannot set buffer duration near %u us: %s",
-                 param, snd_strerror (val));
+        msg_Err (aout, "cannot set buffer duration: %s", snd_strerror (val));
         goto error;
     }
-
-    val = snd_pcm_hw_params_set_periods_first (pcm, hw, &param, NULL);
+#if 1
+    val = snd_pcm_hw_params_get_buffer_time (hw, &param, NULL);
+    if (val)
+    {
+        msg_Warn (aout, "cannot get buffer time: %s", snd_strerror(val));
+        param = AOUT_MIN_PREPARE_TIME;
+    }
+    else
+        param /= 2;
+#else /* work-around for PulseAudio: */
+    param = AOUT_MIN_PREPARE_TIME;
+#endif
+    val = snd_pcm_hw_params_set_period_time_near (pcm, hw, &param, NULL);
     if (val)
     {
-        msg_Err (aout, "cannot select periods: %s", snd_strerror (val));
+        msg_Err (aout, "cannot set period: %s", snd_strerror (val));
         goto error;
     }
 



More information about the vlc-commits mailing list