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 |
* * |
* * |
96 |
|
|
97 |
for (l = 0; l < 64; l++) { // run |
for (l = 0; l < 64; l++) { // run |
98 |
int32_t level = k; |
int32_t level = k; |
99 |
uint32_t run = l; |
ptr_t run = l; |
100 |
|
|
101 |
if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) { // level < max_level and run < max_run |
if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) { // level < max_level and run < max_run |
102 |
|
|
412 |
Statistics * pStat) |
Statistics * pStat) |
413 |
{ |
{ |
414 |
|
|
|
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
|
|
|
|
415 |
if (frame->coding_type == P_VOP) { |
if (frame->coding_type == P_VOP) { |
416 |
if (pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 && |
if (pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 && |
417 |
pMB->mvs[0].y == 0) { |
pMB->mvs[0].y == 0) { |
418 |
|
|
419 |
|
#ifdef _DISABLE_SKIP |
420 |
|
/* disable SKIP when Bframes active until some workaround for the B-SKIP problem is found */ |
421 |
|
BitstreamPutBit(bs, 0); // always coded! |
422 |
|
#else |
423 |
BitstreamPutBit(bs, 1); // not_coded |
BitstreamPutBit(bs, 1); // not_coded |
424 |
|
|
425 |
return; |
return; |
426 |
|
#endif |
427 |
} else |
} else |
428 |
BitstreamPutBit(bs, 0); // coded |
BitstreamPutBit(bs, 0); // coded |
429 |
} |
} |
430 |
|
|
431 |
if (intra) |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) |
432 |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
433 |
else |
else |
434 |
CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
523 |
int i; |
int i; |
524 |
|
|
525 |
/* ------------------------------------------------------------------ |
/* ------------------------------------------------------------------ |
526 |
when a block is skipped it is decoded DIRECT(0,) |
when a block is skipped it is decoded DIRECT(0,0) |
527 |
hence are interpolated from forward & backward frames |
hence is interpolated from forward & backward frames |
528 |
------------------------------------------------------------------ */ |
------------------------------------------------------------------ */ |
529 |
|
|
530 |
if (mb->mode == 5) { |
if (mb->mode == MODE_DIRECT_NONE_MV) { |
531 |
BitstreamPutBit(bs, 1); // skipped |
BitstreamPutBit(bs, 1); // skipped |
532 |
return; |
return; |
533 |
} |
} |
561 |
} |
} |
562 |
|
|
563 |
if (mb->mode == MODE_DIRECT) { |
if (mb->mode == MODE_DIRECT) { |
564 |
// TODO: direct |
CodeVector(bs, mb->mvs[0].x, 1, pStat); /* fcode is always 1 for delta vector */ |
565 |
|
CodeVector(bs, mb->mvs[0].y, 1, pStat); /* prediction is always (0,0) */ |
566 |
} |
} |
567 |
|
|
568 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
578 |
* decoding stuff starts here * |
* decoding stuff starts here * |
579 |
***************************************************************/ |
***************************************************************/ |
580 |
|
|
581 |
|
|
582 |
|
// for IVOP addbits == 0 |
583 |
|
// for PVOP addbits == fcode - 1 |
584 |
|
// for BVOP addbits == max(fcode,bcode) - 1 |
585 |
|
// returns true or false |
586 |
|
int |
587 |
|
check_resync_marker(Bitstream * bs, int addbits) |
588 |
|
{ |
589 |
|
uint32_t nbits; |
590 |
|
uint32_t code; |
591 |
|
uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits; |
592 |
|
|
593 |
|
nbits = BitstreamNumBitsToByteAlign(bs); |
594 |
|
code = BitstreamShowBits(bs, nbits); |
595 |
|
|
596 |
|
if (code == (((uint32_t)1 << (nbits - 1)) - 1)) |
597 |
|
{ |
598 |
|
return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER; |
599 |
|
} |
600 |
|
|
601 |
|
return 0; |
602 |
|
} |
603 |
|
|
604 |
|
|
605 |
|
|
606 |
int |
int |
607 |
get_mcbpc_intra(Bitstream * bs) |
get_mcbpc_intra(Bitstream * bs) |
608 |
{ |
{ |
609 |
|
|
610 |
uint32_t index; |
uint32_t index; |
611 |
|
|
612 |
while ((index = BitstreamShowBits(bs, 9)) == 1) |
index = BitstreamShowBits(bs, 9); |
|
BitstreamSkip(bs, 9); |
|
|
|
|
613 |
index >>= 3; |
index >>= 3; |
614 |
|
|
615 |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
624 |
|
|
625 |
uint32_t index; |
uint32_t index; |
626 |
|
|
627 |
while ((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1) |
index = CLIP(BitstreamShowBits(bs, 9), 256); |
|
BitstreamSkip(bs, 9); |
|
628 |
|
|
629 |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
630 |
|
|
779 |
} |
} |
780 |
coeff += run; |
coeff += run; |
781 |
block[scan[coeff]] = level; |
block[scan[coeff]] = level; |
782 |
|
|
783 |
|
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); |
784 |
|
//DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); |
785 |
|
|
786 |
if (level < -127 || level > 127) { |
if (level < -127 || level > 127) { |
787 |
DEBUG1("warning: intra_overflow", level); |
DEBUG1("warning: intra_overflow", level); |
788 |
} |
} |
812 |
p += run; |
p += run; |
813 |
|
|
814 |
block[scan[p]] = level; |
block[scan[p]] = level; |
815 |
|
|
816 |
|
DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); |
817 |
|
// DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32)); |
818 |
|
|
819 |
if (level < -127 || level > 127) { |
if (level < -127 || level > 127) { |
820 |
DEBUG1("warning: inter_overflow", level); |
DEBUG1("warning: inter_overflow", level); |
821 |
} |
} |