[FFmpeg-devel] [PATCH]Support pcm_s32 in alsa

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Mar 31 18:37:22 CEST 2011


Hi!

Attached patch allows playback of pcm_s32 via -f alsa.

Any objections?

Carl Eugen
-------------- next part --------------
diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c
index 8e3535e..71bdccb 100644
--- a/libavdevice/alsa-audio-common.c
+++ b/libavdevice/alsa-audio-common.c
@@ -36,6 +36,8 @@
 static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
 {
     switch(codec_id) {
+        case CODEC_ID_PCM_S32LE: return SND_PCM_FORMAT_S32_LE;
+        case CODEC_ID_PCM_S32BE: return SND_PCM_FORMAT_S32_BE;
         case CODEC_ID_PCM_S16LE: return SND_PCM_FORMAT_S16_LE;
         case CODEC_ID_PCM_S16BE: return SND_PCM_FORMAT_S16_BE;
         case CODEC_ID_PCM_S8:    return SND_PCM_FORMAT_S8;
@@ -60,6 +62,23 @@ static void alsa_reorder_s16_out_51(const void *in_v, void *out_v, int n)
     }
 }
 
+static void alsa_reorder_s32_out_51(const void *in_v, void *out_v, int n)
+{
+    const int32_t *in = in_v;
+    int32_t *out = out_v;
+
+    while (n-- > 0) {
+        out[0] = in[0];
+        out[1] = in[1];
+        out[2] = in[4];
+        out[3] = in[5];
+        out[4] = in[2];
+        out[5] = in[3];
+        in  += 6;
+        out += 6;
+    }
+}
+
 static void alsa_reorder_s16_out_71(const void *in_v, void *out_v, int n)
 {
     const int16_t *in = in_v;
@@ -79,6 +98,25 @@ static void alsa_reorder_s16_out_71(const void *in_v, void *out_v, int n)
     }
 }
 
+static void alsa_reorder_s32_out_71(const void *in_v, void *out_v, int n)
+{
+    const int32_t *in = in_v;
+    int32_t *out = out_v;
+
+    while (n-- > 0) {
+        out[0] = in[0];
+        out[1] = in[1];
+        out[2] = in[4];
+        out[3] = in[5];
+        out[4] = in[2];
+        out[5] = in[3];
+        out[6] = in[6];
+        out[7] = in[7];
+        in  += 8;
+        out += 8;
+    }
+}
+
 #define REORDER_DUMMY ((void *)1)
 
 static av_cold ff_reorder_func find_reorder_func(int codec_id,
@@ -93,6 +131,12 @@ static av_cold ff_reorder_func find_reorder_func(int codec_id,
         layout == AV_CH_LAYOUT_7POINT1 ?
             out ? alsa_reorder_s16_out_71 : NULL :
             NULL :
+    codec_id == CODEC_ID_PCM_S32LE || codec_id == CODEC_ID_PCM_S32BE ?
+        layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ?
+            out ? alsa_reorder_s32_out_51 : NULL :
+        layout == AV_CH_LAYOUT_7POINT1 ?
+            out ? alsa_reorder_s32_out_71 : NULL :
+	    NULL :
         NULL;
 }
 


More information about the ffmpeg-devel mailing list