[Ffmpeg-devel] [PATCH] Swscaler multithreading
Michael Niedermayer
michaelni
Fri Aug 18 12:32:15 CEST 2006
Hi
On Thu, Aug 17, 2006 at 10:15:48PM +0900, Haruhiko Yamagata wrote:
> Hello. Thank you for your great product swscaler. I implemented
> multithreading of swscaler for ffdshow port and posted patch on April 2006.
> Since then I debuged and now I would like to port back. I didn't have Linux
> running PC, so I thought it should be very hard to port back, but Cygwin
> allowed me to do it easier. Some OS dependent functions are not
> implemented. Please help me to compleate.
>
> [Tested environment]
> Mingw32+mplayer, Cygwin+mplayer are tested.
> Native posix systems are not tested.
> I think it's probably OK on posix, because pthread.c works on Cygwin.
> OS2 and BeOS are not tested at all, though os2thread.c
> and beosthread.c are included.
>
> [How to compile multithreaded version]
> On posix system(including Cygwin), default configuration is multithreaded.
> Please implement GetCPUCount - pthread.c.
>
> Mingw32 : There is no option for configure as far as I know.
> Add "#define HAVE_THREADS" to config.h.
> Add "HAVE_W32THREADS = yes" to config.mak.
>
> OS2 :
> Add "#define HAVE_THREADS" to config.h.
> Add "HAVE_OS2THREADS = yes" to config.mak.
> Please implement GetCPUCount - os2thread.c.
> Please degug.
>
> BeOS :
> Add "#define HAVE_THREADS" to config.h.
> Add "HAVE_BEOSTHREADS = yes" to config.mak.
> Please implement GetCPUCount - beosthread.c.
> Please degug.
>
> [How to use]
> To specify the number of threads, use sws_getContextEx.
> sws_getContextEx has parameter for threadCount.
>
> /**
> * @param threadCount : number of threads. Set threadCount=0 to GetCPUCount
> automatically.
> */
> SwsContext *sws_getContextEx(int srcW,
> int srcH,
> int origSrcFormat,
> int dstW,
> int dstH,
> int origDstFormat,
> int flags,
> SwsFilter *srcFilter,
> SwsFilter *dstFilter,
> double *param,
> int threadCount
> );
>
> sws_getContextEx calls GetCPUCount to get threadCount, if threadCount==0.
>
> Multithreading should be avoided if the output buffer
> is the video RAM(It's much slower).
>
> [GetCPUCount]
> GetCPUCount is expected to return number of system processors.
> If the processor is Pentium4-HT it is counted 1,
> because multithreading on P4HT is not faster at all.
> It depends on OS and I couldn't implement except for Mingw32.
> Please help me.
>
> [Overview of implementation]
> SwsContext is copied for each thread.
> Picture is simply divided by the number of threads.
> Asymmetric division is long term TODO.
>
> [About MPlayer]
> I don't know why and where it is called from, but MPlayer divids
> picture to pieces(16lines/call). In this setting, swscaler
> multithreading cannot take effect at all. Whole picture should
> be given at once to see effect of multithreading.
no, the X lines/call variant is how the swscaler is supposed to be used
if possible as the small number of lines will often fit in the L2 cache
each of these calls though could be happening on a different cpu for the
multithreading case and the caller would have to ensure that each call
receives enough lines so its able to calculate all the needed output lines
with the same method other filters could also be easily changed to support
multithreading, implementing multithreading in each filter (postprocess,
swscale, denoise, deinterlacing, telecine, ...) is not optiomal due to
the dulicated work and code
and functions should be static or have a prefix like sws_ or ff_ or av_
to avoid name clashes
[...]
>
> +// Be carefull when you modify SwsContext after returning from sws_getContext.
> +// SwsContext is copied to array for multithreading.
> +// sws_scale_ordered modify c->sliceDir. It does not matter for now.
> SwsContext *sws_getContext(int srcW, int srcH, int origSrcFormat, int dstW, int dstH, int origDstFormat, int flags,
comments should be written in a doxygen compatible way if possible
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is
More information about the ffmpeg-devel
mailing list