pv->parser = av_parser_init( codec_id );
pv->context = avcodec_alloc_context();
- avcodec_open( pv->context, codec );
+ hb_avcodec_open( pv->context, codec );
return 0;
}
}
if ( pv->context && pv->context->codec )
{
- avcodec_close( pv->context );
+ hb_avcodec_close( pv->context );
}
if ( pv->list )
{
// There's a mis-feature in ffmpeg that causes the context to be
// incorrectly initialized the 1st time avcodec_open is called.
// If you close it and open a 2nd time, it finishes the job.
- avcodec_open( pv->context, codec );
- avcodec_close( pv->context );
- avcodec_open( pv->context, codec );
+ hb_avcodec_open( pv->context, codec );
+ hb_avcodec_close( pv->context );
+ hb_avcodec_open( pv->context, codec );
}
if( in->start >= 0 )
if ( ! pv->context->codec )
{
AVCodec *codec = avcodec_find_decoder( pv->context->codec_id );
- avcodec_open( pv->context, codec );
+ hb_avcodec_open( pv->context, codec );
}
// set up our best guess at the frame duration.
// the frame rate in the codec is usually bogus but it's sometimes
avctx_enc->flags |= CODEC_FLAG_QPEL;
}
- avcodec_open(avctx_enc, enc);
+ hb_avcodec_open(avctx_enc, enc);
}
pv->mcdeint_frame = avcodec_alloc_frame();
{
if( pv->mcdeint_avctx_enc )
{
- avcodec_close( pv->mcdeint_avctx_enc );
+ hb_avcodec_close( pv->mcdeint_avctx_enc );
av_freep( &pv->mcdeint_avctx_enc );
}
if( pv->mcdeint_outbuf )
avctx_enc->flags |= CODEC_FLAG_QPEL;
}
- avcodec_open(avctx_enc, enc);
+ hb_avcodec_open(avctx_enc, enc);
}
pv->mcdeint_frame = avcodec_alloc_frame();
{
if( pv->mcdeint_avctx_enc )
{
- avcodec_close( pv->mcdeint_avctx_enc );
+ hb_avcodec_close( pv->mcdeint_avctx_enc );
av_freep( &pv->mcdeint_avctx_enc );
}
if( pv->mcdeint_outbuf )
}
}
- if( avcodec_open( context, codec ) )
+ if( hb_avcodec_open( context, codec ) )
{
hb_log( "hb_work_encavcodec_init: avcodec_open failed" );
}
{
hb_deep_log( 2, "encavcodec: closing libavcodec" );
avcodec_flush_buffers( pv->context );
- avcodec_close( pv->context );
+ hb_avcodec_close( pv->context );
}
if( pv->file )
{
};
+hb_lock_t *hb_avcodec_lock;
hb_work_object_t * hb_objects = NULL;
static void thread_func( void * );
+void hb_avcodec_init()
+{
+ hb_avcodec_lock = hb_lock_init();
+ av_register_all();
+}
+
+int hb_avcodec_open(AVCodecContext *avctx, AVCodec *codec)
+{
+ int ret;
+ hb_lock( hb_avcodec_lock );
+ ret = avcodec_open(avctx, codec);
+ hb_unlock( hb_avcodec_lock );
+ return ret;
+}
+
+int hb_avcodec_close(AVCodecContext *avctx)
+{
+ int ret;
+ hb_lock( hb_avcodec_lock );
+ ret = avcodec_close(avctx);
+ hb_unlock( hb_avcodec_lock );
+ return ret;
+}
+
/**
* Registers work objects, by adding the work object to a liked list.
* @param w Handle to hb_work_object_t to register.
h->pause_lock = hb_lock_init();
/* libavcodec */
- av_register_all();
+ hb_avcodec_init();
/* Start library thread */
hb_log( "hb_init: starting libhb thread" );
context->error_recognition = 1;
context->error_concealment = FF_EC_GUESS_MVS|FF_EC_DEBLOCK;
AVCodec *codec = avcodec_find_decoder( context->codec_id );
- avcodec_open( context, codec );
+ hb_avcodec_open( context, codec );
}
// The ffmpeg stream reader / parser shares a lot of state with the
c->sample_rate = sync->audio->config.in.samplerate;
c->channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( sync->audio->config.in.channel_layout );
- if( avcodec_open( c, codec ) < 0 )
+ if( hb_avcodec_open( c, codec ) < 0 )
{
hb_log( "sync: avcodec_open failed" );
return;
}
free( zeros );
- avcodec_close( c );
+ hb_avcodec_close( c );
av_free( c );
}
else