[Xvid-devel] bug in thread count calculation

Michael Militzer michael at xvid.org
Wed Nov 26 00:09:50 CET 2014


Hi Lukasz,

thanks for pointing this out! I've checked in a patch based on what you
suggested.

Regards,
Michael


Quoting Lukasz Marek <lukasz.m.luki2 at gmail.com>:

> Hello,
>
> During some tests of ffmpeg encoders (it uses libxvidcore) I noticed there
> is not allocated memory in use.
> Bad line is encoder.c:466
>
> bug is in following code
>
> #ifndef HAVE_PTHREAD
>                 int t = MAX(1, create->num_threads);
> #else
>                 int t = MIN(create->num_threads, (int)
> (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */
> #endif
>
> For height <=16 pEnc->mbParam.mb_height is 1. (it is calculated earlier as
> (height +15) /16) so it produces t = 0.
> It is later used in
>
> pEnc->smpData = xvid_malloc(t*sizeof(SMPData), CACHE_LINE);
>
> Im not sure what is correct fix, but one of follows may help
>
> #ifndef HAVE_PTHREAD
>                 int t = MAX(1, create->num_threads);
> #else
>                 int t = MIN(create->num_threads, (int)
> (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */
>                 t = MAX(1, t);
> #endif
>
> or
>
> #ifndef HAVE_PTHREAD
>                 int t = MAX(1, create->num_threads);
> #else
>                 int t = MIN(create->num_threads, (int)
> (pEnc->mbParam.height>>1)); /* at least two rows per thread */
> #endif
>
> or
>
> #ifndef HAVE_PTHREAD
>                 int t = MAX(1, create->num_threads);
> #else
>                 int t = MIN(create->num_threads, (int)
> (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */
> #endif
>                 if (!t)
>                     goto xvid_err_nosmp;
>
> Regards,
> Lukasz Marek
> _______________________________________________
> Xvid-devel mailing list
> Xvid-devel at xvid.org
> http://list.xvid.org/mailman/listinfo/xvid-devel
>
>






More information about the Xvid-devel mailing list