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

Hendrik Leppkes h.leppkes at gmail.com
Tue Apr 15 15:25:33 CEST 2014


On Tue, Apr 15, 2014 at 3:15 PM, Matt Oliver <protogonoi at gmail.com> wrote:
> 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
> pthreads.
>
> 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.

Using undocumented implementation specific things seems like a terrible hack.
Windows thread API has no static initialization, and thats the end of
the story, doing anything else seems error prone and evil, and should
be avoided at all cost.

If you want this to work with the Win32 Thread API, you should
re-write it to be able to use init.
Or, just build with pthreads, it doesn't really have any downsides.

- Hendrik


More information about the ffmpeg-devel mailing list