[vlc-commits] ALSA: refine buffer / period parameters

Rémi Denis-Courmont git at videolan.org
Wed Mar 7 19:27:18 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Mar  7 20:25:11 2012 +0200| [2dd544eb847556972c6bdd49e1eb0c281122f448] | committer: Rémi Denis-Courmont

ALSA: refine buffer / period parameters

We really need at least two periods: with only one period we could hit
a buffer underrun after a buffer overrun (a REALLY dumb failure...).
Then we have a favorite buffer size. Then we pick the least number of
periods to reduce wakeups (but at least 2 anyway).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2dd544eb847556972c6bdd49e1eb0c281122f448
---

 modules/audio_output/alsa.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index 152f88b..5f6385b 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -439,26 +439,32 @@ 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_Warn (aout, "cannot set buffer duration near %u us: %s",
-                  param, snd_strerror (val));
-    val = snd_pcm_hw_params_set_buffer_time_last (pcm, hw, &param, NULL);
-    if (val)
-        msg_Warn (aout, "cannot set buffer duration: %s", snd_strerror (val));
+    {
+        msg_Err (aout, "cannot set buffer duration near %u us: %s",
+                 param, snd_strerror (val));
+        goto error;
+    }
 
-    /* Set number of periods (at least two) */
-    param = 2;
-    val = snd_pcm_hw_params_set_periods_min (pcm, hw, &param, NULL);
-    if (val)
-        msg_Warn (aout, "cannot set minimum of %u periods: %s", param,
-                  snd_strerror (val));
     val = snd_pcm_hw_params_set_periods_first (pcm, hw, &param, NULL);
     if (val)
-        msg_Warn (aout, "cannot set periods count near %u: %s", param,
-                  snd_strerror (val));
+    {
+        msg_Err (aout, "cannot select periods: %s", snd_strerror (val));
+        goto error;
+    }
 
     /* Commit hardware parameters */
     val = snd_pcm_hw_params (pcm, hw);



More information about the vlc-commits mailing list