--- trunk/xvidcore/src/bitstream/mbcoding.c 2002/06/12 20:38:41 195 +++ trunk/xvidcore/src/bitstream/mbcoding.c 2002/07/28 13:06:46 347 @@ -41,6 +41,7 @@ * * * Revision history: * * * + * 28.06.2002 added check_resync_marker() * * 14.04.2002 bframe encoding * * 08.03.2002 initial version; isibaar * * * @@ -95,7 +96,7 @@ for (l = 0; l < 64; l++) { // run int32_t level = k; - uint32_t run = l; + ptr_t run = l; if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) { // level < max_level and run < max_run @@ -411,24 +412,26 @@ Statistics * pStat) { - int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); - if (frame->coding_type == P_VOP) { - if (pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 && - pMB->mvs[0].y == 0) { - BitstreamPutBit(bs, 1); // not_coded - return; - } else BitstreamPutBit(bs, 0); // coded } - if (intra) + if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); else CodeBlockInter(frame, pMB, qcoeff, bs, pStat); } + +void +MBSkip(Bitstream * bs) +{ + BitstreamPutBit(bs, 1); // not coded + return; +} + + /*************************************************************** * bframe encoding start ***************************************************************/ @@ -517,11 +520,11 @@ int i; /* ------------------------------------------------------------------ - when a block is skipped it is decoded DIRECT(0,) - hence are interpolated from forward & backward frames + when a block is skipped it is decoded DIRECT(0,0) + hence is interpolated from forward & backward frames ------------------------------------------------------------------ */ - if (mb->mode == 5) { + if (mb->mode == MODE_DIRECT_NONE_MV) { BitstreamPutBit(bs, 1); // skipped return; } @@ -555,7 +558,8 @@ } if (mb->mode == MODE_DIRECT) { - // TODO: direct + CodeVector(bs, mb->deltamv.x, 1, pStat); /* fcode is always 1 for delta vector */ + CodeVector(bs, mb->deltamv.y, 1, pStat); /* prediction is always (0,0) */ } for (i = 0; i < 6; i++) { @@ -571,15 +575,38 @@ * decoding stuff starts here * ***************************************************************/ + +// for IVOP addbits == 0 +// for PVOP addbits == fcode - 1 +// for BVOP addbits == max(fcode,bcode) - 1 +// returns true or false +int +check_resync_marker(Bitstream * bs, int addbits) +{ + uint32_t nbits; + uint32_t code; + uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits; + + nbits = BitstreamNumBitsToByteAlign(bs); + code = BitstreamShowBits(bs, nbits); + + if (code == (((uint32_t)1 << (nbits - 1)) - 1)) + { + return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER; + } + + return 0; +} + + + int get_mcbpc_intra(Bitstream * bs) { uint32_t index; - while ((index = BitstreamShowBits(bs, 9)) == 1) - BitstreamSkip(bs, 9); - + index = BitstreamShowBits(bs, 9); index >>= 3; BitstreamSkip(bs, mcbpc_intra_table[index].len); @@ -593,9 +620,8 @@ { uint32_t index; - - while ((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1) - BitstreamSkip(bs, 9); + + index = CLIP(BitstreamShowBits(bs, 9), 256); BitstreamSkip(bs, mcbpc_inter_table[index].len); @@ -750,6 +776,10 @@ } coeff += run; block[scan[coeff]] = level; + + DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); + //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); + if (level < -127 || level > 127) { DEBUG1("warning: intra_overflow", level); } @@ -779,6 +809,10 @@ p += run; block[scan[p]] = level; + + DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); + // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32)); + if (level < -127 || level > 127) { DEBUG1("warning: inter_overflow", level); }