--- trunk/xvidcore/src/bitstream/mbcoding.c 2005/09/13 12:12:15 1632 +++ trunk/xvidcore/src/bitstream/mbcoding.c 2007/06/27 14:38:05 1775 @@ -19,7 +19,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: mbcoding.c,v 1.52 2005-09-13 12:12:15 suxen_drol Exp $ + * $Id: mbcoding.c,v 1.55 2007-06-27 14:38:05 Isibaar Exp $ * ****************************************************************************/ @@ -36,6 +36,13 @@ #include "../utils/mbfunctions.h" +#ifdef _DEBUG +# include "../motion/estimation.h" +# include "../motion/motion_inlines.h" +# include +#endif + + #define LEVELOFFSET 32 /* Initialized once during xvid_global call @@ -572,13 +579,28 @@ #endif } } + + bits = BitstreamPos(bs); + /* code motion vector(s) if motion is local */ if (!pMB->mcsel) for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { CodeVector(bs, pMB->pmvs[i].x, frame->fcode); CodeVector(bs, pMB->pmvs[i].y, frame->fcode); + +#ifdef _DEBUG + if (i == 0) /* for simplicity */ { + int coded_length = BitstreamPos(bs) - bits; + int estimated_length = d_mv_bits(pMB->pmvs[i].x, pMB->pmvs[i].y, zeroMV, frame->fcode, 0); + assert(estimated_length == coded_length); + d_mv_bits(pMB->pmvs[i].x, pMB->pmvs[i].y, zeroMV, frame->fcode, 0); + } +#endif } + bits = BitstreamPos(bs) - bits; + pStat->iMVBits += bits; + bits = BitstreamPos(bs); /* code block coeffs */ @@ -746,6 +768,7 @@ } } + bits = BitstreamPos(bs); switch (mb->mode) { case MODE_INTERPOLATE: @@ -762,6 +785,7 @@ CodeVector(bs, mb->pmvs[3].y, 1); /* prediction is always (0,0) */ default: break; } + pStat->iMVBits += BitstreamPos(bs) - bits; bits = BitstreamPos(bs); for (i = 0; i < 6; i++) { @@ -1067,18 +1091,11 @@ do { level = get_coeff(bs, &run, &last, 1, 0); - if (run == -1) { - DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run"); - break; - } coeff += run; - -#ifdef _DEBUG - if(coeff>=64) { - DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); - return; + if ((run|coeff)&~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif block[scan[coeff]] = level; @@ -1115,18 +1132,11 @@ p = 0; do { level = get_coeff(bs, &run, &last, 0, 0); - if (run == -1) { - DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run"); - break; - } p += run; - -#ifdef _DEBUG - if(p>=64) { - DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); - return; + if ((p|run)&~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif if (level < 0) { level = level*quant_m_2 - quant_add; @@ -1157,18 +1167,11 @@ p = 0; do { level = get_coeff(bs, &run, &last, 0, 0); - if (run == -1) { - DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run"); - break; - } p += run; - -#ifdef _DEBUG - if(p>=64) { - DPRINTF(XVID_DEBUG_ERROR,"error: overflow in coefficient index\n"); - return; + if ((p|run)&~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif if (level < 0) { level = ((2 * -level + 1) * matrix[scan[p]] * quant) >> 4;