[vlc-commits] commit: Mostly restore libmad functionality ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Fri Apr 16 16:59:40 CEST 2010


vlc/vlc-1.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Apr 16 17:57:56 2010 +0300| [23a652ed177b70ba2949023f7d00288e65f61515] | committer: Rémi Denis-Courmont 

Mostly restore libmad functionality

The 1.1 fix is still slightly better thanks resizable aout_buffer_t.

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.0.git/?a=commit;h=23a652ed177b70ba2949023f7d00288e65f61515
---

 modules/codec/mpeg_audio.c |   57 +++++++++++++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/modules/codec/mpeg_audio.c b/modules/codec/mpeg_audio.c
index b8bf3e5..be31295 100644
--- a/modules/codec/mpeg_audio.c
+++ b/modules/codec/mpeg_audio.c
@@ -96,8 +96,8 @@ static int  OpenPacketizer( vlc_object_t * );
 static void CloseDecoder  ( vlc_object_t * );
 static void *DecodeBlock  ( decoder_t *, block_t ** );
 
-static uint8_t       *GetOutBuffer ( decoder_t *, block_t ** );
-static block_t       *GetAoutBuffer( decoder_t * );
+static uint8_t       *GetOutBuffer ( decoder_t *, void **, size_t * );
+static aout_buffer_t *GetAoutBuffer( decoder_t * );
 static block_t       *GetSoutBuffer( decoder_t * );
 
 static int SyncInfo( uint32_t i_header, unsigned int * pi_channels,
@@ -172,15 +172,10 @@ static int Open( vlc_object_t *p_this )
 static int OpenDecoder( vlc_object_t *p_this )
 {
     /* HACK: Don't use this codec if we don't have an mpga audio filter */
-#if 0
     if( !module_exists( "mpgatofixed32" ) )
         return VLC_EGENERIC;
 
     return Open( p_this );
-#else
-    msg_Dbg( p_this, "skipping broken module" );
-    return VLC_EGENERIC;
-#endif
 }
 
 static int OpenPacketizer( vlc_object_t *p_this )
@@ -205,7 +200,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     uint8_t p_header[MAD_BUFFER_GUARD];
     uint32_t i_header;
     uint8_t *p_buf;
-    block_t *p_out_buffer;
+    void *p_out_buffer;
 
     if( !pp_block || !*pp_block ) return NULL;
 
@@ -449,7 +444,10 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             p_sys->i_state = STATE_SEND_DATA;
 
         case STATE_SEND_DATA:
-            if( !(p_buf = GetOutBuffer( p_dec, &p_out_buffer )) )
+        {
+            size_t i_len;
+
+            if( !(p_buf = GetOutBuffer( p_dec, &p_out_buffer, &i_len )) )
             {
                 //p_dec->b_error = true;
                 return NULL;
@@ -464,12 +462,13 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             /* Copy the whole frame into the buffer. When we reach this point
              * we already know we have enough data available. */
             block_GetBytes( &p_sys->bytestream,
-                            p_buf, __MIN( (unsigned)p_sys->i_frame_size, p_out_buffer->i_buffer ) );
+                        p_buf, __MIN( (unsigned)p_sys->i_frame_size, i_len ) );
 
             /* Get beginning of next frame for libmad */
             if( !p_sys->b_packetizer )
             {
-                assert( p_out_buffer->i_buffer >= (unsigned)p_sys->i_frame_size + MAD_BUFFER_GUARD );
+                assert( ((aout_buffer_t *)p_out_buffer)->i_size
+                        >= (size_t)p_sys->i_frame_size + MAD_BUFFER_GUARD );
                 memcpy( p_buf + p_sys->i_frame_size,
                         p_header, MAD_BUFFER_GUARD );
             }
@@ -485,6 +484,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
             return p_out_buffer;
         }
+        }
     }
 
     return NULL;
@@ -493,7 +493,8 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 /*****************************************************************************
  * GetOutBuffer:
  *****************************************************************************/
-static uint8_t *GetOutBuffer( decoder_t *p_dec, block_t **pp_out_buffer )
+static uint8_t *GetOutBuffer( decoder_t *p_dec, void **pp_out_buffer,
+                              size_t *pi_len )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     uint8_t *p_buf;
@@ -522,13 +523,25 @@ static uint8_t *GetOutBuffer( decoder_t *p_dec, block_t **pp_out_buffer )
     if( p_sys->b_packetizer )
     {
         block_t *p_sout_buffer = GetSoutBuffer( p_dec );
-        p_buf = p_sout_buffer ? p_sout_buffer->p_buffer : NULL;
+        if( p_sout_buffer )
+        {
+            p_buf = p_sout_buffer->p_buffer;
+            *pi_len = p_sout_buffer->i_buffer;
+        }
+        else
+            p_buf = NULL;
         *pp_out_buffer = p_sout_buffer;
     }
     else
     {
-        block_t *p_aout_buffer = GetAoutBuffer( p_dec );
-        p_buf = p_aout_buffer ? p_aout_buffer->p_buffer : NULL;
+        aout_buffer_t *p_aout_buffer = GetAoutBuffer( p_dec );
+        if( p_aout_buffer )
+        {
+            p_buf = p_aout_buffer->p_buffer;
+            *pi_len = p_aout_buffer->i_size;
+        }
+        else
+            p_buf = NULL;
         *pp_out_buffer = p_aout_buffer;
     }
 
@@ -538,7 +551,7 @@ static uint8_t *GetOutBuffer( decoder_t *p_dec, block_t **pp_out_buffer )
 /*****************************************************************************
  * GetAoutBuffer:
  *****************************************************************************/
-static block_t *GetAoutBuffer( decoder_t *p_dec )
+static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     aout_buffer_t *p_buf;
@@ -553,14 +566,14 @@ static block_t *GetAoutBuffer( decoder_t *p_dec )
     p_sys->b_discontinuity = false;
 
     /* Hack for libmad filter */
-#if 0
-    p_buf = block_Realloc( p_buf, 0, p_sys->i_frame_size + MAD_BUFFER_GUARD );
+    if( p_buf->i_size < p_sys->i_frame_size + MAD_BUFFER_GUARD )
+    {
+        decoder_DeleteAudioBuffer( p_dec, p_buf );
+        return NULL;
+    }
+    p_buf->i_nb_bytes = p_sys->i_frame_size + MAD_BUFFER_GUARD;
 
     return p_buf;
-#else
-    decoder_DeleteAudioBuffer( p_dec, p_buf );
-    return 0;
-#endif
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list