[vlc-devel] [PATCH] AVI: support WAVEFORMATEXTENSIBLE for audio

Jean-Baptiste Kempf jb at videolan.org
Thu May 12 01:53:27 CEST 2011


This is notably used by files produced by FFmpeg
Closes #4742
---
 modules/demux/avi/avi.c    |   12 ++++++++----
 modules/demux/avi/libavi.c |   13 +++++++++----
 modules/demux/avi/libavi.h |    1 +
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/modules/demux/avi/avi.c b/modules/demux/avi/avi.c
index df525ad..f0a9999 100644
--- a/modules/demux/avi/avi.c
+++ b/modules/demux/avi/avi.c
@@ -401,8 +401,12 @@ static int Open( vlc_object_t * p_this )
         {
             case( AVIFOURCC_auds ):
                 tk->i_cat   = AUDIO_ES;
-                tk->i_codec = AVI_FourccGetCodec( AUDIO_ES,
-                                                  p_auds->p_wf->wFormatTag );
+                if( p_auds->p_wf->wFormatTag != WAVE_FORMAT_EXTENSIBLE )
+                    tk->i_codec = AVI_FourccGetCodec( AUDIO_ES,
+                                                      p_auds->p_wf->wFormatTag );
+                else
+                    tk->i_codec = AVI_FourccGetCodec( AUDIO_ES,
+                                                      p_auds->p_wfe->SubFormat.Data1 );
 
                 tk->i_blocksize = p_auds->p_wf->nBlockAlign;
                 if( tk->i_blocksize == 0 )
@@ -435,8 +439,8 @@ static int Open( vlc_object_t * p_this )
                 fmt.b_packetized            = !tk->i_blocksize;
 
                 msg_Dbg( p_demux,
-                    "stream[%d] audio(0x%x) %d channels %dHz %dbits",
-                    i, p_auds->p_wf->wFormatTag, p_auds->p_wf->nChannels,
+                    "stream[%d] audio(%4.4s) %d channels %dHz %dbits",
+                    i, (char*)&tk->i_codec, p_auds->p_wf->nChannels,
                     p_auds->p_wf->nSamplesPerSec,
                     p_auds->p_wf->wBitsPerSample );
 
diff --git a/modules/demux/avi/libavi.c b/modules/demux/avi/libavi.c
index 0031a16..a8edc2a 100644
--- a/modules/demux/avi/libavi.c
+++ b/modules/demux/avi/libavi.c
@@ -336,16 +336,19 @@ static int AVI_ChunkRead_strf( stream_t *s, avi_chunk_t *p_chk )
         case( AVIFOURCC_auds ):
             p_chk->strf.auds.i_cat = AUDIO_ES;
             p_chk->strf.auds.p_wf = malloc( __MAX( p_chk->common.i_chunk_size, sizeof( WAVEFORMATEX ) ) );
+            p_chk->strf.auds.p_wfe = malloc( __MAX( p_chk->common.i_chunk_size, sizeof( WAVEFORMATEXTENSIBLE ) ) );
             AVI_READ2BYTES( p_chk->strf.auds.p_wf->wFormatTag );
             AVI_READ2BYTES( p_chk->strf.auds.p_wf->nChannels );
             AVI_READ4BYTES( p_chk->strf.auds.p_wf->nSamplesPerSec );
             AVI_READ4BYTES( p_chk->strf.auds.p_wf->nAvgBytesPerSec );
             AVI_READ2BYTES( p_chk->strf.auds.p_wf->nBlockAlign );
             AVI_READ2BYTES( p_chk->strf.auds.p_wf->wBitsPerSample );
+
             if( p_chk->strf.auds.p_wf->wFormatTag != WAVE_FORMAT_PCM
                  && p_chk->common.i_chunk_size > sizeof( WAVEFORMATEX ) )
             {
                 AVI_READ2BYTES( p_chk->strf.auds.p_wf->cbSize );
+
                 /* prevent segfault */
                 if( p_chk->strf.auds.p_wf->cbSize >
                         p_chk->common.i_chunk_size - sizeof( WAVEFORMATEX ) )
@@ -353,11 +356,12 @@ static int AVI_ChunkRead_strf( stream_t *s, avi_chunk_t *p_chk )
                     p_chk->strf.auds.p_wf->cbSize =
                         p_chk->common.i_chunk_size - sizeof( WAVEFORMATEX );
                 }
-                if( p_chk->strf.auds.p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE )
+
+                if( p_chk->strf.auds.p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE
+                    && p_chk->common.i_chunk_size > sizeof( WAVEFORMATEXTENSIBLE ) )
                 {
-                    /* Found an extensible header atm almost nothing uses that. */
-                    msg_Warn( (vlc_object_t*)s, "WAVE_FORMAT_EXTENSIBLE or "
-                              "vorbis audio dectected: not supported" );
+                    msg_Dbg( s, "Extended header found" );
+                    memcpy( p_chk->strf.auds.p_wfe, p_read - sizeof( WAVEFORMATEX ), sizeof( WAVEFORMATEXTENSIBLE ) );
                 }
             }
             else
@@ -428,6 +432,7 @@ static void AVI_ChunkFree_strf( avi_chunk_t *p_chk )
     if( p_strf->common.i_cat == AUDIO_ES )
     {
         FREENULL( p_strf->auds.p_wf );
+        FREENULL( p_strf->auds.p_wfe );
     }
     else if( p_strf->common.i_cat == VIDEO_ES )
     {
diff --git a/modules/demux/avi/libavi.h b/modules/demux/avi/libavi.h
index 3862cf9..a104373 100644
--- a/modules/demux/avi/libavi.h
+++ b/modules/demux/avi/libavi.h
@@ -119,6 +119,7 @@ typedef struct avi_chunk_strf_auds_s
     AVI_CHUNK_COMMON
     int             i_cat;
     WAVEFORMATEX    *p_wf;
+    WAVEFORMATEXTENSIBLE *p_wfe;
 } avi_chunk_strf_auds_t;
 
 typedef struct avi_chunk_strf_vids_s
-- 
1.7.5.1




More information about the vlc-devel mailing list