280 |
} |
} |
281 |
|
|
282 |
|
|
283 |
static void |
static __inline void |
284 |
CodeBlockIntra(const FRAMEINFO * frame, |
CodeBlockIntra(const FRAMEINFO * frame, |
285 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
286 |
int16_t qcoeff[6 * 64], |
int16_t qcoeff[6 * 64], |
330 |
dcc_tab[qcoeff[i * 64 + 0] + 255].len); |
dcc_tab[qcoeff[i * 64 + 0] + 255].len); |
331 |
|
|
332 |
if (pMB->cbp & (1 << (5 - i))) { |
if (pMB->cbp & (1 << (5 - i))) { |
333 |
|
const uint16_t *scan_table = |
334 |
|
frame->global_flags & XVID_ALTERNATESCAN ? |
335 |
|
scan_tables[2] : scan_tables[pMB->acpred_directions[i]]; |
336 |
|
|
337 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
338 |
|
|
339 |
CodeCoeff(bs, &qcoeff[i * 64], intra_table, |
CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1); |
|
scan_tables[pMB->acpred_directions[i]], 1); |
|
340 |
|
|
341 |
bits = BitstreamPos(bs) - bits; |
bits = BitstreamPos(bs) - bits; |
342 |
pStat->iTextBits += bits; |
pStat->iTextBits += bits; |
373 |
|
|
374 |
// interlacing |
// interlacing |
375 |
if (frame->global_flags & XVID_INTERLACING) { |
if (frame->global_flags & XVID_INTERLACING) { |
376 |
|
if (pMB->cbp) { |
377 |
BitstreamPutBit(bs, pMB->field_dct); |
BitstreamPutBit(bs, pMB->field_dct); |
378 |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
DEBUG1("codep: field_dct: ", pMB->field_dct); |
379 |
|
} |
380 |
|
|
381 |
// if inter block, write field ME flag |
// if inter block, write field ME flag |
382 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
401 |
// code block coeffs |
// code block coeffs |
402 |
for (i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) |
403 |
if (pMB->cbp & (1 << (5 - i))) |
if (pMB->cbp & (1 << (5 - i))) |
404 |
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0); |
{ |
405 |
|
const uint16_t *scan_table = |
406 |
|
frame->global_flags & XVID_ALTERNATESCAN ? |
407 |
|
scan_tables[2] : scan_tables[0]; |
408 |
|
|
409 |
|
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0); |
410 |
|
} |
411 |
|
|
412 |
bits = BitstreamPos(bs) - bits; |
bits = BitstreamPos(bs) - bits; |
413 |
pStat->iTextBits += bits; |
pStat->iTextBits += bits; |
424 |
{ |
{ |
425 |
|
|
426 |
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) { |
|
|
|
|
|
#ifdef _DISABLE_SKIP |
|
|
/* disable SKIP when Bframes active until some workaround for the B-SKIP problem is found */ |
|
|
BitstreamPutBit(bs, 0); // always coded! |
|
|
#else |
|
|
BitstreamPutBit(bs, 1); // not_coded |
|
|
|
|
|
return; |
|
|
#endif |
|
|
} else |
|
427 |
BitstreamPutBit(bs, 0); // coded |
BitstreamPutBit(bs, 0); // coded |
428 |
} |
} |
429 |
|
|
434 |
|
|
435 |
} |
} |
436 |
|
|
437 |
|
/* |
438 |
|
// moved to mbcoding.h so that in can be 'static __inline' |
439 |
|
void |
440 |
|
MBSkip(Bitstream * bs) |
441 |
|
{ |
442 |
|
BitstreamPutBit(bs, 1); // not coded |
443 |
|
} |
444 |
|
*/ |
445 |
|
|
446 |
/*************************************************************** |
/*************************************************************** |
447 |
* bframe encoding start |
* bframe encoding start |
448 |
***************************************************************/ |
***************************************************************/ |
455 |
3 0001b forward mc+q dbquant, mvdf |
3 0001b forward mc+q dbquant, mvdf |
456 |
*/ |
*/ |
457 |
|
|
458 |
void |
static __inline void |
459 |
put_bvop_mbtype(Bitstream * bs, |
put_bvop_mbtype(Bitstream * bs, |
460 |
int value) |
int value) |
461 |
{ |
{ |
462 |
switch (value) { |
switch (value) { |
463 |
case 0: |
case MODE_FORWARD: |
|
BitstreamPutBit(bs, 1); |
|
|
return; |
|
|
|
|
|
case 1: |
|
|
BitstreamPutBit(bs, 0); |
|
|
BitstreamPutBit(bs, 1); |
|
|
return; |
|
|
|
|
|
case 2: |
|
|
BitstreamPutBit(bs, 0); |
|
|
BitstreamPutBit(bs, 0); |
|
|
BitstreamPutBit(bs, 1); |
|
|
return; |
|
|
|
|
|
case 3: |
|
464 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 0); |
465 |
|
case MODE_BACKWARD: |
466 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 0); |
467 |
|
case MODE_INTERPOLATE: |
468 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 0); |
469 |
|
case MODE_DIRECT: |
470 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
471 |
return; |
default: |
472 |
|
break; |
|
default:; // invalid! |
|
|
|
|
473 |
} |
} |
|
|
|
474 |
} |
} |
475 |
|
|
476 |
/* |
/* |
480 |
+2 11b |
+2 11b |
481 |
*/ |
*/ |
482 |
|
|
483 |
void |
static __inline void |
484 |
put_bvop_dbquant(Bitstream * bs, |
put_bvop_dbquant(Bitstream * bs, |
485 |
int value) |
int value) |
486 |
{ |
{ |
511 |
const int32_t fcode, |
const int32_t fcode, |
512 |
const int32_t bcode, |
const int32_t bcode, |
513 |
Bitstream * bs, |
Bitstream * bs, |
514 |
Statistics * pStat) |
Statistics * pStat, |
515 |
|
int direction) |
516 |
{ |
{ |
517 |
int i; |
int vcode = fcode; |
518 |
|
unsigned int i; |
519 |
|
|
520 |
/* ------------------------------------------------------------------ |
/* ------------------------------------------------------------------ |
521 |
when a block is skipped it is decoded DIRECT(0,0) |
when a block is skipped it is decoded DIRECT(0,0) |
545 |
put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0 |
put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0 |
546 |
} |
} |
547 |
|
|
548 |
if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) { |
switch (mb->mode) { |
549 |
CodeVector(bs, mb->pmvs[0].x, fcode, pStat); |
case MODE_INTERPOLATE: |
550 |
CodeVector(bs, mb->pmvs[0].y, fcode, pStat); |
CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode |
551 |
} |
CodeVector(bs, mb->pmvs[1].y, vcode, pStat); |
552 |
|
case MODE_BACKWARD: |
553 |
if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD) { |
vcode = bcode; |
554 |
CodeVector(bs, mb->b_pmvs[0].x, bcode, pStat); |
case MODE_FORWARD: |
555 |
CodeVector(bs, mb->b_pmvs[0].y, bcode, pStat); |
CodeVector(bs, mb->pmvs[0].x, vcode, pStat); |
556 |
} |
CodeVector(bs, mb->pmvs[0].y, vcode, pStat); |
557 |
|
break; |
558 |
if (mb->mode == MODE_DIRECT) { |
case MODE_DIRECT: |
559 |
CodeVector(bs, mb->mvs[0].x, 1, pStat); /* fcode is always 1 for delta vector */ |
CodeVector(bs, mb->pmvs[3].x, 1, pStat); // fcode is always 1 for delta vector |
560 |
CodeVector(bs, mb->mvs[0].y, 1, pStat); /* prediction is always (0,0) */ |
CodeVector(bs, mb->pmvs[3].y, 1, pStat); // prediction is always (0,0) |
561 |
|
default: break; |
562 |
} |
} |
563 |
|
|
564 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
565 |
if (mb->cbp & (1 << (5 - i))) { |
if (mb->cbp & (1 << (5 - i))) { |
566 |
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0); |
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[direction], 0); |
567 |
} |
} |
568 |
} |
} |
569 |
} |
} |
646 |
|
|
647 |
} |
} |
648 |
|
|
649 |
int |
static __inline int |
650 |
get_mv_data(Bitstream * bs) |
get_mv_data(Bitstream * bs) |
651 |
{ |
{ |
652 |
|
|
763 |
{ |
{ |
764 |
|
|
765 |
const uint16_t *scan = scan_tables[direction]; |
const uint16_t *scan = scan_tables[direction]; |
766 |
int level; |
int level, run, last; |
|
int run; |
|
|
int last; |
|
767 |
|
|
768 |
do { |
do { |
769 |
level = get_coeff(bs, &run, &last, 1, 0); |
level = get_coeff(bs, &run, &last, 1, 0); |
787 |
|
|
788 |
void |
void |
789 |
get_inter_block(Bitstream * bs, |
get_inter_block(Bitstream * bs, |
790 |
int16_t * block) |
int16_t * block, |
791 |
|
int direction) |
792 |
{ |
{ |
793 |
|
|
794 |
const uint16_t *scan = scan_tables[0]; |
const uint16_t *scan = scan_tables[direction]; |
795 |
int p; |
int p; |
796 |
int level; |
int level; |
797 |
int run; |
int run; |