]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/audio.c
Too many problems with new ffmpeg detection, reverting to last known good (rev 25403).
[vlc] / modules / codec / ffmpeg / audio.c
index 175b7e20b3df44b64ec30e3b98ac0f21e8b9b2d1..9bc9cef9e6ae38b360d48b2b6722938e563d0033 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_aout.h>
 #include <vlc_codec.h>
@@ -89,10 +93,6 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
                       AVCodec *p_codec, int i_codec_id, const char *psz_namecodec )
 {
     decoder_sys_t *p_sys;
-    vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
-
-    if( lock == NULL )
-        return VLC_EGENERIC;
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys =
@@ -132,13 +132,23 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
                 p_sys->p_context->extradata_size, 0,
                 FF_INPUT_BUFFER_PADDING_SIZE );
     }
+    else
+        p_sys->p_context->extradata = NULL;
 
     /* ***** Open the codec ***** */
-    vlc_mutex_lock( lock );
+    vlc_mutex_t *lock = var_AcquireMutex( "avcodec" );
+    if( lock == NULL )
+    {
+        free( p_sys->p_context->extradata );
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
+
     if (avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0)
     {
         vlc_mutex_unlock( lock );
         msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
+        free( p_sys->p_context->extradata );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -253,10 +263,16 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
     p_block->i_buffer -= FF_INPUT_BUFFER_PADDING_SIZE;
     memset( &p_block->p_buffer[p_block->i_buffer], 0, FF_INPUT_BUFFER_PADDING_SIZE );
 
+#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(0<<8)+0)
     i_output = __MAX( AVCODEC_MAX_AUDIO_FRAME_SIZE, p_block->i_buffer );
     i_used = avcodec_decode_audio2( p_sys->p_context,
                                    (int16_t*)p_sys->p_output, &i_output,
                                    p_block->p_buffer, p_block->i_buffer );
+#else
+    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 );
+#endif
 
     if( i_used < 0 || i_output < 0 )
     {
@@ -267,7 +283,7 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
         block_Release( p_block );
         return NULL;
     }
-    else if( i_used > p_block->i_buffer )
+    else if( (size_t)i_used > p_block->i_buffer )
     {
         i_used = p_block->i_buffer;
     }