41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 28.06.2002 added check_resync_marker() * |
45 |
* 14.04.2002 bframe encoding * |
* 14.04.2002 bframe encoding * |
46 |
* 08.03.2002 initial version; isibaar * |
* 08.03.2002 initial version; isibaar * |
47 |
* * |
* * |
370 |
|
|
371 |
// interlacing |
// interlacing |
372 |
if (frame->global_flags & XVID_INTERLACING) { |
if (frame->global_flags & XVID_INTERLACING) { |
373 |
|
if (pMB->cbp) { |
374 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
375 |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
376 |
|
} |
377 |
|
|
378 |
// if inter block, write field ME flag |
// if inter block, write field ME flag |
379 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
414 |
Statistics * pStat) |
Statistics * pStat) |
415 |
{ |
{ |
416 |
|
|
|
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
|
|
|
|
417 |
if (frame->coding_type == P_VOP) { |
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 |
|
418 |
BitstreamPutBit(bs, 0); // coded |
BitstreamPutBit(bs, 0); // coded |
419 |
} |
} |
420 |
|
|
421 |
if (intra) |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) |
422 |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
423 |
else |
else |
424 |
CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
425 |
|
|
426 |
} |
} |
427 |
|
|
428 |
|
|
429 |
|
void |
430 |
|
MBSkip(Bitstream * bs) |
431 |
|
{ |
432 |
|
BitstreamPutBit(bs, 1); // not coded |
433 |
|
return; |
434 |
|
} |
435 |
|
|
436 |
|
|
437 |
/*************************************************************** |
/*************************************************************** |
438 |
* bframe encoding start |
* bframe encoding start |
439 |
***************************************************************/ |
***************************************************************/ |
522 |
int i; |
int i; |
523 |
|
|
524 |
/* ------------------------------------------------------------------ |
/* ------------------------------------------------------------------ |
525 |
when a block is skipped it is decoded DIRECT(0,) |
when a block is skipped it is decoded DIRECT(0,0) |
526 |
hence are interpolated from forward & backward frames |
hence is interpolated from forward & backward frames |
527 |
------------------------------------------------------------------ */ |
------------------------------------------------------------------ */ |
528 |
|
|
529 |
if (mb->mode == 5) { |
if (mb->mode == MODE_DIRECT_NONE_MV) { |
530 |
BitstreamPutBit(bs, 1); // skipped |
BitstreamPutBit(bs, 1); // skipped |
531 |
return; |
return; |
532 |
} |
} |
560 |
} |
} |
561 |
|
|
562 |
if (mb->mode == MODE_DIRECT) { |
if (mb->mode == MODE_DIRECT) { |
563 |
// TODO: direct |
CodeVector(bs, mb->deltamv.x, 1, pStat); /* fcode is always 1 for delta vector */ |
564 |
|
CodeVector(bs, mb->deltamv.y, 1, pStat); /* prediction is always (0,0) */ |
565 |
} |
} |
566 |
|
|
567 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
577 |
* decoding stuff starts here * |
* decoding stuff starts here * |
578 |
***************************************************************/ |
***************************************************************/ |
579 |
|
|
580 |
|
|
581 |
|
// for IVOP addbits == 0 |
582 |
|
// for PVOP addbits == fcode - 1 |
583 |
|
// for BVOP addbits == max(fcode,bcode) - 1 |
584 |
|
// returns true or false |
585 |
|
int |
586 |
|
check_resync_marker(Bitstream * bs, int addbits) |
587 |
|
{ |
588 |
|
uint32_t nbits; |
589 |
|
uint32_t code; |
590 |
|
uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits; |
591 |
|
|
592 |
|
nbits = BitstreamNumBitsToByteAlign(bs); |
593 |
|
code = BitstreamShowBits(bs, nbits); |
594 |
|
|
595 |
|
if (code == (((uint32_t)1 << (nbits - 1)) - 1)) |
596 |
|
{ |
597 |
|
return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER; |
598 |
|
} |
599 |
|
|
600 |
|
return 0; |
601 |
|
} |
602 |
|
|
603 |
|
|
604 |
|
|
605 |
int |
int |
606 |
get_mcbpc_intra(Bitstream * bs) |
get_mcbpc_intra(Bitstream * bs) |
607 |
{ |
{ |
608 |
|
|
609 |
uint32_t index; |
uint32_t index; |
610 |
|
|
611 |
while ((index = BitstreamShowBits(bs, 9)) == 1) |
index = BitstreamShowBits(bs, 9); |
|
BitstreamSkip(bs, 9); |
|
|
|
|
612 |
index >>= 3; |
index >>= 3; |
613 |
|
|
614 |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
623 |
|
|
624 |
uint32_t index; |
uint32_t index; |
625 |
|
|
626 |
while ((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1) |
index = CLIP(BitstreamShowBits(bs, 9), 256); |
|
BitstreamSkip(bs, 9); |
|
627 |
|
|
628 |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
629 |
|
|
778 |
} |
} |
779 |
coeff += run; |
coeff += run; |
780 |
block[scan[coeff]] = level; |
block[scan[coeff]] = level; |
781 |
|
|
782 |
|
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); |
783 |
|
//DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); |
784 |
|
|
785 |
if (level < -127 || level > 127) { |
if (level < -127 || level > 127) { |
786 |
DEBUG1("warning: intra_overflow", level); |
DEBUG1("warning: intra_overflow", level); |
787 |
} |
} |
811 |
p += run; |
p += run; |
812 |
|
|
813 |
block[scan[p]] = level; |
block[scan[p]] = level; |
814 |
|
|
815 |
|
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); |
816 |
|
// DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32)); |
817 |
|
|
818 |
if (level < -127 || level > 127) { |
if (level < -127 || level > 127) { |
819 |
DEBUG1("warning: inter_overflow", level); |
DEBUG1("warning: inter_overflow", level); |
820 |
} |
} |