[vlc-commits] ALSA: fix selecting the audio format

Rémi Denis-Courmont git at videolan.org
Wed Mar 7 20:04:00 CET 2012


vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Mar  7 20:07:01 2012 +0200| [d31ca17bc7d3297e641f100ec281610bd6991f2d] | committer: Rémi Denis-Courmont

ALSA: fix selecting the audio format

If set_format() fails, the parameters are unrecoverable.
Use test_format() instead.
(cherry picked from commit 2a66249d1b9773b7ba2f6ebebbf8619c1f339de7)

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

 modules/audio_output/alsa.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index ebcf650..7006662 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -371,20 +371,35 @@ static int Open (vlc_object_t *obj)
     Dump (aout, "initial hardware setup:\n", snd_pcm_hw_params_dump, hw);
 
     /* Set sample format */
-    val = snd_pcm_hw_params_set_format (pcm, hw, pcm_format);
-    if (val == 0)
+    if (snd_pcm_hw_params_test_format (pcm, hw, pcm_format) == 0)
         ;
-    else if (pcm_format != SND_PCM_FORMAT_FLOAT
-     && snd_pcm_hw_params_set_format (pcm, hw, SND_PCM_FORMAT_FLOAT) == 0)
+    else
+    if (snd_pcm_hw_params_test_format (pcm, hw, SND_PCM_FORMAT_FLOAT) == 0)
+    {
         fourcc = VLC_CODEC_FL32;
-    else if (pcm_format != SND_PCM_FORMAT_S32
-     && snd_pcm_hw_params_set_format (pcm, hw, SND_PCM_FORMAT_S32) == 0)
+        pcm_format = SND_PCM_FORMAT_FLOAT;
+    }
+    else
+    if (snd_pcm_hw_params_test_format (pcm, hw, SND_PCM_FORMAT_S32) == 0)
+    {
         fourcc = VLC_CODEC_S32N;
-    else if (pcm_format != SND_PCM_FORMAT_S16
-     && snd_pcm_hw_params_set_format (pcm, hw, SND_PCM_FORMAT_S16) == 0)
+        pcm_format = SND_PCM_FORMAT_S32;
+    }
+    else
+    if (snd_pcm_hw_params_test_format (pcm, hw, SND_PCM_FORMAT_S16) == 0)
+    {
         fourcc = VLC_CODEC_S16N;
+        pcm_format = SND_PCM_FORMAT_S16;
+    }
     else
     {
+        msg_Err (aout, "no supported sample format");
+        goto error;
+    }
+
+    val = snd_pcm_hw_params_set_format (pcm, hw, pcm_format);
+    if (val)
+    {
         msg_Err (aout, "cannot set sample format: %s", snd_strerror (val));
         goto error;
     }



More information about the vlc-commits mailing list