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

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


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

ALSA: fix selecting the audio format

If set_format() fails, the parameters are unrecoverable.
Use test_format() instead.

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

 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 7ecdd8c..152f88b 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -373,20 +373,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