[Xvid-devel] bug in thread count calculation

Lukasz Marek lukasz.m.luki2 at gmail.com
Tue Nov 25 15:31:37 CET 2014


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


More information about the Xvid-devel mailing list