[FFmpeg-devel] why avcodec_open/close() need thread locking?

Michael Niedermayer michaelni at gmx.at
Fri Jun 1 00:59:08 CEST 2012


On Thu, May 31, 2012 at 09:33:43PM +0800, gw wrote:
> hi all
> 
>     I see that in avcodec_open/close, there are some code like below:
> 
>     /* If there is a user-supplied mutex locking routine, call it. */
>     if (ff_lockmgr_cb) {
>         if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
>             return -1;
>     }
> 
>     entangled_thread_counter++;
>     if(entangled_thread_counter != 1){
>         av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around
> avcodec_open/close()\n");
>         ret = -1;
>         goto end;
>     }
> 
> 
> does it mean that avcodec_open/close() is not thread safe ?

avcodec.h:

 * @warning This function is not thread safe!
[...]
int avcodec_open(AVCodecContext *avctx, AVCodec *codec);



> 
> is this lock necessary ?

if the functions are called from multiple threads at the same time
a lock is neccessary, if not its not. Note that some code like
av_find_stream_info() calls avcodec_open() too

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120601/20de165b/attachment.asc>


More information about the ffmpeg-devel mailing list