[FFmpeg-devel] Patch: Enable OpenCL with Win32 threads

Matt Oliver protogonoi at gmail.com
Tue Apr 15 15:15:23 CEST 2014

Currently opencl support can only be enabled when using native pthreads.
This is because the existing code uses a pthread mutex object for thread
synchronization. FFmpeg already has some native win32/os2 thread wrapper
functions that can be used however the existing opencl code uses a static
mutex initialization define (PTHREAD_MUTEX_INITIALIZER) that is specific to

Since all the win32/os2 thread wrappers need a call to the _init function
to initialise the mutex this cant be done statically the way it is
currently. To fix this would require rewriting functions so that there is
an explicit function call to initialise the mutex variable. There is
already a opencl_init function but the get/set functions also need the lock
and these are used to set parameters that are then used for the _init
function. So without some serious rewriting there is not an elegant
solution to this.

That said atleast for the windows case there is some win32 black magic that
can be done to keep the existing code. I added a patch that creates
the PTHREAD_MUTEX_INITIALIZER define for the ffmpeg win32 thread wrapper.
Ive tested this and seen others use it as well so although not specifically
documented it does work.

A second patch is attached that adds win32 thread support to the opencl
code (small changes to include w32 wrapper header and stdint.h as this is
not implicitly included on windows).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: w32thread-Add-pthread-compat-static-init.patch
Type: application/octet-stream
Size: 1184 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140415/c5d8646d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opencl-Add-Win32-support.patch
Type: application/octet-stream
Size: 2329 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140415/c5d8646d/attachment-0001.obj>

More information about the ffmpeg-devel mailing list