[FFmpeg-devel] [PATCH] Make avcodec_thread_init set the thread_count in the encoder when there isn't support for threads compiled in
Stefano Sabatini
stefano.sabatini-lala
Sun Mar 9 13:00:36 CET 2008
On date Saturday 2008-03-08 20:31:25 +0100, Michael Dorr encoded:
> On Saturday 08 March 2008 07:25:49 pm Stefano Sabatini wrote:
> > On date Saturday 2008-03-08 18:55:26 +0100, Michael Niedermayer encoded:
> > > On Sat, Mar 08, 2008 at 06:33:27PM +0100, Stefano Sabatini wrote:
> > > > Hi,
> > > > as in $subject.
> > > >
> > > > If threads support is not enabled and threads count is set to a
> > > > value greater than MAX_THREADS (currently is 8), then encoder is
> > > > initialized with a value of thread_count equal to 1, then
> > > > enc->threads_count is set to the value set by the user, finally
> > > > libavcodec crashes when it tryies to free the first thread beyond
> > > > MAX_THREADS (this happens when quitting ffplay).
> > >
> > > the command line parsing code should not accept >MAX_THREADS
> >
> > [...]
> >
> > I agree, but MAX_THREADS is defined in libavcodec/mpegvideo.h, which
> > is not public, furthermore the patch implements the correct behaviour
> > for opening an encoder so I'd like to see it applied.
>
> Shouldn't manually setting enc->thread_count be omitted completely, since it
> gets set correctly in avcodec_thread_init anyway (and if thread_init isn't
> called, it defaults to 1, which is also correct)? Theoretically,
> avcodec_thread_init could fail, then enc->thread_count and the 'real' number
> of threads will differ, and ffmpeg will crash ...
Hi,
if thread support is enabled, enc->thread_count is setted by
avcodec_thread_init, and if this number is greater than THREADS_MAX
the avcodec_open (condition which isn't checked by
avcodec_init_threads) will fail when opening the encoder.
If thread support isn't enabled, the reasonable thing to do seems to
me to set enc->thread_count to thread_count rather than require the
user to do it manually as in ffplay.c, then the avcodec_open will fail
anyway.
This patch implements this solution.
By the way: shouldn't avcodec_thread_init if threads support is not
compiled *always* return 0 as opposed to the current behaviour of
returning -1?
A further fix could make avcodec_thread_init fail when thread_count is
greater than THREADS_MAX.
Furthermore we should check for the error code returned by
avcodec_thread_init as suggested by Michael Dorr.
Best regards.
--
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: set-thread-count-in-thread-init-if-not-threads.patch
Type: text/x-diff
Size: 351 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080309/ffb10542/attachment.patch>
More information about the ffmpeg-devel
mailing list