[FFmpeg-devel] Input/output devices, global data, thread safety, mutexes, etc...

Stefano Sabatini stefano.sabatini-lala at poste.it
Sun Jul 24 15:58:51 CEST 2011

On date Saturday 2011-07-23 22:17:20 -0400, Jonathan Baldwin encoded:
> I need to know whether I need to mutex global data in libavdevice
> devices (shared between instances.) Do FFmpeg/Libav and other programs
> that utilize libavdevice run different device instances in different
> threads? Is there any plan to do so?

>From what I remember, avcodec_open() can't be called by separate
threads (so you can have no more than one thread initializing a codec
context at the same time). As an extension, since initializing a
device/format may require to open a codec, you may need to extend the
lock to the format/device initialization (but: check code and docs),
maybe someone can confirm.

> Regardless, I'd like to know the recommended way to create mutexes
> inside FFmpeg (it couldn't hurt to know.) I'm pretty sure I'm not
> allowed to directly call pthreads, and I've heard there is an API that
> libav* exposes to make itself "thread-safe" to host applications.

If you mean a threading wrapper libav* has nothing of that, but
pthreads are portable enough these days (with the possible exception
of VC), but then I'm not sure if you mean adding code for adding
mutexes *in libav* itself, which may be problematic from the
portability point of view.
FFmpeg = Fanciful and Fostering Moronic Pitiful Exxagerate Gnome

More information about the ffmpeg-devel mailing list