]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/audio.c
For consistency, remove references to vlc from libvlc
[vlc] / modules / codec / ffmpeg / audio.c
index 5b33b95931fe02ce23f0ee089d859b3d50361961..325608a111ba2b0fc162f2f6f3e3f49e7eff96ab 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * audio.c: audio decoder using ffmpeg library
  *****************************************************************************
- * Copyright (C) 1999-2003 VideoLAN
+ * Copyright (C) 1999-2003 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -89,7 +89,7 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
     decoder_sys_t *p_sys;
     vlc_value_t lockval;
 
-    var_Get( p_dec->p_libvlc, "avcodec", &lockval );
+    var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys =
@@ -109,14 +109,24 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
     p_sys->p_context->channels = p_dec->fmt_in.audio.i_channels;
     p_sys->p_context->block_align = p_dec->fmt_in.audio.i_blockalign;
     p_sys->p_context->bit_rate = p_dec->fmt_in.i_bitrate;
+    p_sys->p_context->bits_per_sample = p_dec->fmt_in.audio.i_bitspersample;
 
     if( ( p_sys->p_context->extradata_size = p_dec->fmt_in.i_extra ) > 0 )
     {
+        int i_offset = 0;
+
+        if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'f', 'l', 'a', 'c' ) )
+            i_offset = 8;
+
+        p_sys->p_context->extradata_size -= i_offset;
         p_sys->p_context->extradata =
-            malloc( p_dec->fmt_in.i_extra + FF_INPUT_BUFFER_PADDING_SIZE );
+            malloc( p_sys->p_context->extradata_size +
+                    FF_INPUT_BUFFER_PADDING_SIZE );
         memcpy( p_sys->p_context->extradata,
-                p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
-        memset( (char*)p_sys->p_context->extradata + p_dec->fmt_in.i_extra, 0,
+                (char*)p_dec->fmt_in.p_extra + i_offset,
+                p_sys->p_context->extradata_size );
+        memset( (char*)p_sys->p_context->extradata +
+                p_sys->p_context->extradata_size, 0,
                 FF_INPUT_BUFFER_PADDING_SIZE );
     }
 
@@ -133,7 +143,7 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
 
     msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
 
-    p_sys->p_output = malloc( 3 * AVCODEC_MAX_AUDIO_FRAME_SIZE );
+    p_sys->p_output = malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE );
     p_sys->p_samples = NULL;
     p_sys->i_samples = 0;
 
@@ -209,12 +219,19 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    if( p_block->i_buffer <= 0 || p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
+    if( p_block->i_buffer <= 0 ||
+        (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) )
     {
         block_Release( p_block );
         return NULL;
     }
 
+    if( p_block->i_buffer > AVCODEC_MAX_AUDIO_FRAME_SIZE )
+    {
+        /* Grow output buffer if necessary (eg. for PCM data) */
+        p_sys->p_output = realloc(p_sys->p_output, p_block->i_buffer);
+    }
+
     i_used = avcodec_decode_audio( p_sys->p_context,
                                    (int16_t*)p_sys->p_output, &i_output,
                                    p_block->p_buffer, p_block->i_buffer );
@@ -244,7 +261,7 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    if( p_dec->fmt_out.audio.i_rate != p_sys->p_context->sample_rate )
+    if( p_dec->fmt_out.audio.i_rate != (unsigned int)p_sys->p_context->sample_rate )
     {
         aout_DateInit( &p_sys->end_date, p_sys->p_context->sample_rate );
         aout_DateSet( &p_sys->end_date, p_block->i_pts );