summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libhb/decavcodec.c12
-rw-r--r--libhb/decomb.c4
-rw-r--r--libhb/deinterlace.c4
-rw-r--r--libhb/encavcodec.c4
-rw-r--r--libhb/hb.c27
-rwxr-xr-xlibhb/stream.c2
-rw-r--r--libhb/sync.c4
7 files changed, 41 insertions, 16 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index d443b4ac0..12c9802bb 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -197,7 +197,7 @@ static int decavcodecInit( hb_work_object_t * w, hb_job_t * job )
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;
}
@@ -229,7 +229,7 @@ static void decavcodecClose( hb_work_object_t * w )
}
if ( pv->context && pv->context->codec )
{
- avcodec_close( pv->context );
+ hb_avcodec_close( pv->context );
}
if ( pv->list )
{
@@ -798,9 +798,9 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
// 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 )
@@ -902,7 +902,7 @@ static void init_ffmpeg_context( hb_work_object_t *w )
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
diff --git a/libhb/decomb.c b/libhb/decomb.c
index 2194f5633..4fb573045 100644
--- a/libhb/decomb.c
+++ b/libhb/decomb.c
@@ -1309,7 +1309,7 @@ hb_filter_private_t * hb_decomb_init( int pix_fmt,
avctx_enc->flags |= CODEC_FLAG_QPEL;
}
- avcodec_open(avctx_enc, enc);
+ hb_avcodec_open(avctx_enc, enc);
}
pv->mcdeint_frame = avcodec_alloc_frame();
@@ -1413,7 +1413,7 @@ void hb_decomb_close( hb_filter_private_t * pv )
{
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 )
diff --git a/libhb/deinterlace.c b/libhb/deinterlace.c
index b6b10fe43..b7d672ad3 100644
--- a/libhb/deinterlace.c
+++ b/libhb/deinterlace.c
@@ -653,7 +653,7 @@ hb_filter_private_t * hb_deinterlace_init( int pix_fmt,
avctx_enc->flags |= CODEC_FLAG_QPEL;
}
- avcodec_open(avctx_enc, enc);
+ hb_avcodec_open(avctx_enc, enc);
}
pv->mcdeint_frame = avcodec_alloc_frame();
@@ -726,7 +726,7 @@ void hb_deinterlace_close( hb_filter_private_t * pv )
{
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 )
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c
index d22d30d3d..5cf8c5072 100644
--- a/libhb/encavcodec.c
+++ b/libhb/encavcodec.c
@@ -159,7 +159,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
}
}
- if( avcodec_open( context, codec ) )
+ if( hb_avcodec_open( context, codec ) )
{
hb_log( "hb_work_encavcodec_init: avcodec_open failed" );
}
@@ -194,7 +194,7 @@ void encavcodecClose( hb_work_object_t * w )
{
hb_deep_log( 2, "encavcodec: closing libavcodec" );
avcodec_flush_buffers( pv->context );
- avcodec_close( pv->context );
+ hb_avcodec_close( pv->context );
}
if( pv->file )
{
diff --git a/libhb/hb.c b/libhb/hb.c
index 31b45c2df..72eb2b030 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -44,10 +44,35 @@ struct hb_handle_s
};
+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.
@@ -121,7 +146,7 @@ hb_handle_t * hb_init_real( int verbose, int update_check )
h->pause_lock = hb_lock_init();
/* libavcodec */
- av_register_all();
+ hb_avcodec_init();
/* Start library thread */
hb_log( "hb_init: starting libhb thread" );
diff --git a/libhb/stream.c b/libhb/stream.c
index abe827ede..2fd308c74 100755
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -2460,7 +2460,7 @@ static void ffmpeg_add_codec( hb_stream_t *stream, int stream_index )
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
diff --git a/libhb/sync.c b/libhb/sync.c
index e81095907..411c65610 100644
--- a/libhb/sync.c
+++ b/libhb/sync.c
@@ -238,7 +238,7 @@ static void InitAudio( hb_work_object_t * w, int i )
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;
@@ -257,7 +257,7 @@ static void InitAudio( hb_work_object_t * w, int i )
}
free( zeros );
- avcodec_close( c );
+ hb_avcodec_close( c );
av_free( c );
}
else