Commit dd5f0b9f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

ffmpeg: use var_GetGlobalMutex

parent 48d06067
......@@ -89,17 +89,17 @@ 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_value_t lockval;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
var_Create( p_dec->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
if( lock == NULL )
return VLC_EGENERIC;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
{
msg_Err( p_dec, "out of memory" );
return VLC_EGENERIC;
return VLC_ENOMEM;
}
p_sys->p_context = p_context;
......@@ -134,15 +134,15 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
}
/* ***** Open the codec ***** */
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
if (avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0)
{
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
free( p_sys );
return VLC_EGENERIC;
}
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
......
......@@ -195,10 +195,7 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
int i_codec_id, i_cat;
const char *psz_namecodec;
vlc_value_t val;
vlc_value_t lockval;
var_Create( p_enc->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
var_Get( p_enc->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
if( !E_(GetFfmpegCodec)( p_enc->fmt_out.i_codec, &i_cat, &i_codec_id,
&psz_namecodec ) )
......@@ -533,10 +530,10 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
p_context->extradata = NULL;
p_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
if( avcodec_open( p_context, p_codec ) )
{
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
if( p_enc->fmt_in.i_cat == AUDIO_ES &&
(p_context->channels > 2 || i_codec_id == CODEC_ID_MP2
|| i_codec_id == CODEC_ID_MP3) )
......@@ -586,10 +583,10 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
}
p_context->codec = NULL;
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
if( avcodec_open( p_context, p_codec ) )
{
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Err( p_enc, "cannot open encoder" );
intf_UserFatal( p_enc, VLC_FALSE, _("Streaming / Transcoding failed"),
_("VLC could not open the encoder.") );
......@@ -606,7 +603,7 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
return VLC_EGENERIC;
}
}
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock);
p_enc->fmt_out.i_extra = p_context->extradata_size;
if( p_enc->fmt_out.i_extra )
......@@ -1005,9 +1002,7 @@ void E_(CloseEncoder)( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
vlc_value_t lockval;
var_Get( p_enc->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
if ( p_sys->b_inited && p_enc->i_threads >= 1 )
{
......@@ -1027,9 +1022,9 @@ void E_(CloseEncoder)( vlc_object_t *p_this )
free( pp_contexts );
}
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
avcodec_close( p_sys->p_context );
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
av_free( p_sys->p_context );
if( p_sys->p_buffer ) free( p_sys->p_buffer );
......
......@@ -335,9 +335,7 @@ static void CloseDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
switch( p_sys->i_cat )
{
......@@ -354,9 +352,9 @@ static void CloseDecoder( vlc_object_t *p_this )
if( p_sys->p_context->extradata )
free( p_sys->p_context->extradata );
p_sys->p_context->extradata = NULL;
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
avcodec_close( p_sys->p_context );
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Dbg( p_dec, "ffmpeg codec (%s) stopped", p_sys->psz_namecodec );
av_free( p_sys->p_context );
}
......@@ -424,11 +422,9 @@ void E_(LibavcodecCallback)( void *p_opaque, int i_level,
void E_(InitLibavcodec)( vlc_object_t *p_object )
{
static int b_ffmpeginit = 0;
vlc_value_t lockval;
vlc_mutex_t *lock;
var_Create( p_object->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
var_Get( p_object->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
/* *** init ffmpeg library (libavcodec) *** */
if( !b_ffmpeginit )
......@@ -446,7 +442,7 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
msg_Dbg( p_object, "libavcodec already initialized" );
}
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
}
/*****************************************************************************
......
......@@ -214,18 +214,18 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
AVCodec *p_codec, int i_codec_id, const char *psz_namecodec )
{
decoder_sys_t *p_sys;
vlc_value_t lockval;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
vlc_value_t val;
var_Create( p_dec->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
if( lock == NULL )
return VLC_EGENERIC;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
{
msg_Err( p_dec, "out of memory" );
return VLC_EGENERIC;
return VLC_ENOMEM;
}
p_dec->p_sys->p_context = p_context;
......@@ -330,15 +330,15 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
p_sys->p_context->palctrl = &palette_control;
/* ***** Open the codec ***** */
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
if( avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0 )
{
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
free( p_sys );
return VLC_EGENERIC;
}
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment