--- mbcoding.c 2006/01/19 22:25:23 1.53 +++ mbcoding.c 2010/10/15 16:20:48 1.59 @@ -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.53 2006/01/19 22:25:23 Isibaar Exp $ + * $Id: mbcoding.c,v 1.59 2010/10/15 16:20:48 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 @@ -580,6 +587,15 @@ 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); + +#if 0 /* #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; @@ -1059,7 +1075,7 @@ return (level << 20) >> 20; error: - *run = VLC_ERROR; + *run = 64; return 0; } @@ -1071,22 +1087,15 @@ { const uint16_t *scan = scan_tables[direction]; - int level, run, last; + int level, run, last = 0; 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 (coeff & ~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif block[scan[coeff]] = level; @@ -1118,23 +1127,16 @@ int p; int level; int run; - int last; + int last = 0; 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 & ~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif if (level < 0) { level = level*quant_m_2 - quant_add; @@ -1160,23 +1162,16 @@ int p; int level; int run; - int last; + int last = 0; 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 & ~63) { + DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run or index"); + break; } -#endif if (level < 0) { level = ((2 * -level + 1) * matrix[scan[p]] * quant) >> 4; @@ -1977,7 +1972,7 @@ 26708, 29545, 29472, 26223, 30580, 29281, 8293, 29545, 25632, 29285, 30313, 25701, 26144, 28530, 8301, 26740, 8293, 20039, 8277, 20551, 8268, 30296, 17513, 25376, - 25711, 25445, 10272, 11825, 11825, 10544, 2606, 28505, + 25711, 25445, 10272, 11825, 11827, 10544, 2606, 28505, 29301, 29472, 26223, 30580, 29281, 8293, 26980, 29811, 26994, 30050, 28532, 8306, 24936, 8307, 28532, 26400, 30313, 8293, 25441, 25955, 29555, 29728, 8303, 29801,