[vlc-devel] [PATCH] WAV Mux : Extend the muxer to support non-PCM codecs.

Jai Menon jmenon86 at gmail.com
Sat Jun 26 19:29:37 CEST 2010


The current muxer generates invalid files whenever any streams
with  non-PCM codecs are used as input. This is fixed by using
a VLC codec ID-to-waveformat tag map. The map has been populated
with some codecs to begin with and can be extended as necessary.
---
 modules/mux/wav.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/modules/mux/wav.c b/modules/mux/wav.c
index f2f4091..5d74517 100644
--- a/modules/mux/wav.c
+++ b/modules/mux/wav.c
@@ -97,6 +97,20 @@ static const uint32_t pi_channels_out[] =
       WAVE_SPEAKER_BACK_CENTER,
       WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT, 0 };
 
+static const uint32_t wformat_map[][2] = {
+    { VLC_CODEC_U8,    WAVE_FORMAT_PCM },
+    { VLC_CODEC_S16L,  WAVE_FORMAT_PCM },
+    { VLC_CODEC_S24L,  WAVE_FORMAT_PCM },
+    { VLC_CODEC_S32L,  WAVE_FORMAT_PCM },
+    { VLC_CODEC_A52,   WAVE_FORMAT_A52 },
+    { VLC_CODEC_DTS,   WAVE_FORMAT_DTS },
+    { VLC_CODEC_FL32,  WAVE_FORMAT_IEEE_FLOAT },
+    { VLC_CODEC_FL64,  WAVE_FORMAT_IEEE_FLOAT },
+    { VLC_CODEC_ALAW,  WAVE_FORMAT_ALAW },
+    { VLC_CODEC_MULAW, WAVE_FORMAT_MULAW },
+    { 0, 0 }
+};
+
 /*****************************************************************************
  * Open:
  *****************************************************************************/
@@ -164,7 +178,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     GUID subformat_guid = {0, 0, 0x10,{0x80, 0, 0, 0xaa, 0, 0x38, 0x9b, 0x71}};
     sout_mux_sys_t *p_sys = p_mux->p_sys;
     WAVEFORMATEX *p_waveformat = &p_sys->waveformat.Format;
-    int i_bytes_per_sample, i_format;
+    int i_bytes_per_sample, i_format, i;
     bool b_ext;
 
     if( p_input->p_fmt->i_cat != AUDIO_ES )
@@ -204,8 +218,17 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                  p_sys->i_channel_mask, (int)p_sys->b_chan_reorder );
     }
 
-    i_format = p_input->p_fmt->i_codec == VLC_CODEC_FL32 ?
-        WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM;
+    i_format = WAVE_FORMAT_UNKNOWN;
+
+    for( i = 0; wformat_map[i][0]; i++)
+    {
+        if( wformat_map[i][0] == p_input->p_fmt->i_codec )
+        {
+            i_format = wformat_map[i][1];
+            break;
+        }
+    }
+
     b_ext = p_sys->b_ext = p_input->p_fmt->audio.i_channels > 2;
 
     /* Build a WAV header for the output data */
-- 
1.7.1




More information about the vlc-devel mailing list