diff options
author | jstebbins <[email protected]> | 2011-03-10 23:34:08 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-03-10 23:34:08 +0000 |
commit | 94b58a7b733fac763a8b9c8d4a3f9348540d47aa (patch) | |
tree | 4ebac9f35abc34f0b984f0d8887ea631fe7260cc /libhb | |
parent | 23518c8922f6d29f5604b8e91b350088eeb0a755 (diff) |
Use ffmpeg's lock manager for locking needed by ffmpeg
This lets ffmpeg tell us when it needs a lock instead of
us trying to guess which functions we need to wrap in a mutex.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3834 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/hb.c | 49 | ||||
-rw-r--r-- | libhb/hbffmpeg.h | 1 | ||||
-rw-r--r-- | libhb/stream.c | 2 |
3 files changed, 33 insertions, 19 deletions
diff --git a/libhb/hb.c b/libhb/hb.c index 46720c138..92e743cc6 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -57,7 +57,6 @@ struct hb_handle_s }; -hb_lock_t *hb_avcodec_lock; hb_work_object_t * hb_objects = NULL; int hb_instance_counter = 0; int hb_process_initialized = 0; @@ -65,27 +64,52 @@ int hb_process_initialized = 0; static void thread_func( void * ); hb_title_t * hb_get_title_by_index( hb_handle_t *, int ); +hb_lock_t *hb_avcodec_lock; +static int ff_lockmgr_cb(void **mutex, enum AVLockOp op) +{ + switch ( op ) + { + case AV_LOCK_CREATE: + { + hb_avcodec_lock = hb_lock_init(); + *mutex = hb_avcodec_lock; + } break; + case AV_LOCK_DESTROY: + { + hb_lock_close( &hb_avcodec_lock ); + *mutex = NULL; + } break; + case AV_LOCK_OBTAIN: + { + hb_lock( (hb_lock_t*)*mutex ); + } break; + case AV_LOCK_RELEASE: + { + hb_unlock( (hb_lock_t*)*mutex ); + } break; + default: + break; + } + return 0; +} + void hb_avcodec_init() { - hb_avcodec_lock = hb_lock_init(); + av_lockmgr_register( ff_lockmgr_cb ); 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_av_find_stream_info(AVFormatContext *ic) +int hb_avcodec_close(AVCodecContext *avctx) { int ret; - hb_lock( hb_avcodec_lock ); - ret = av_find_stream_info( ic ); - hb_unlock( hb_avcodec_lock ); + ret = avcodec_close(avctx); return ret; } @@ -124,15 +148,6 @@ hb_sws_get_context(int srcW, int srcH, enum PixelFormat srcFormat, return ctx; } -int hb_avcodec_close(AVCodecContext *avctx) -{ - int ret; - hb_lock( hb_avcodec_lock ); - ret = avcodec_close(avctx); - hb_unlock( hb_avcodec_lock ); - return ret; -} - int hb_ff_layout_xlat(int64_t ff_channel_layout, int channels) { int hb_layout; diff --git a/libhb/hbffmpeg.h b/libhb/hbffmpeg.h index 9953aa7ba..097fae250 100644 --- a/libhb/hbffmpeg.h +++ b/libhb/hbffmpeg.h @@ -9,7 +9,6 @@ void hb_avcodec_init(void); int hb_avcodec_open( AVCodecContext *, struct AVCodec * ); int hb_avcodec_close( AVCodecContext * ); -int hb_av_find_stream_info(AVFormatContext *ic); int hb_ff_layout_xlat(int64_t ff_layout, int channels); struct SwsContext* hb_sws_get_context(int srcW, int srcH, enum PixelFormat srcFormat, diff --git a/libhb/stream.c b/libhb/stream.c index 3d80a590b..65abcb421 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -2909,7 +2909,7 @@ static int ffmpeg_open( hb_stream_t *stream, hb_title_t *title ) { return 0; } - if ( hb_av_find_stream_info( ic ) < 0 ) + if ( av_find_stream_info( ic ) < 0 ) goto fail; stream->ffmpeg_ic = ic; |