/*****************************************************************************
* Preamble
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
#include <vlc_aout.h>
#include <vlc_codec.h>
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 =
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;
}
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 )
{
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;
}