--- mbcoding.c 2002/06/14 13:24:58 1.18 +++ mbcoding.c 2002/09/04 03:23:28 1.25 @@ -41,6 +41,7 @@ * * * Revision history: * * * + * 28.06.2002 added check_resync_marker() * * 14.04.2002 bframe encoding * * 08.03.2002 initial version; isibaar * * * @@ -369,8 +370,10 @@ // interlacing if (frame->global_flags & XVID_INTERLACING) { - BitstreamPutBit(bs, pMB->field_dct); - DEBUG1("codep: field_dct: ", pMB->field_dct); + if (pMB->cbp) { + BitstreamPutBit(bs, pMB->field_dct); + DEBUG1("codep: field_dct: ", pMB->field_dct); + } // if inter block, write field ME flag if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { @@ -411,24 +414,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 +522,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 +560,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 +577,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 +622,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 +778,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 +811,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); }