41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
45 |
|
* 26.03.2002 interlacing support * |
46 |
* 03.03.2002 qmatrix writing * |
* 03.03.2002 qmatrix writing * |
47 |
* 03.03.2002 merged BITREADER and BITWRITER * |
* 03.03.2002 merged BITREADER and BITWRITER * |
48 |
* 30.02.2002 intra_dc_threshold support * |
* 30.02.2002 intra_dc_threshold support * |
56 |
#include "zigzag.h" |
#include "zigzag.h" |
57 |
#include "../quant/quant_matrix.h" |
#include "../quant/quant_matrix.h" |
58 |
|
|
59 |
|
|
60 |
static int __inline log2bin(int value) |
static int __inline log2bin(int value) |
61 |
{ |
{ |
62 |
|
/* Changed by Chenm001 */ |
63 |
|
#ifndef WIN32 |
64 |
int n = 0; |
int n = 0; |
65 |
while (value) |
while (value) |
66 |
{ |
{ |
68 |
n++; |
n++; |
69 |
} |
} |
70 |
return n; |
return n; |
71 |
|
#else |
72 |
|
__asm{ |
73 |
|
bsr eax,value |
74 |
|
inc eax |
75 |
|
} |
76 |
|
#endif |
77 |
} |
} |
78 |
|
|
79 |
|
|
294 |
|
|
295 |
} |
} |
296 |
|
|
297 |
if (BitstreamGetBit(bs)) // interlaced |
if ((dec->interlacing = BitstreamGetBit(bs))) |
298 |
{ |
{ |
299 |
DEBUG("TODO: interlaced"); |
DEBUG("vol: interlacing"); |
|
// TODO |
|
|
return -1; |
|
300 |
} |
} |
301 |
|
|
302 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
526 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
527 |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
528 |
|
|
529 |
/* if (interlaced) |
if (dec->interlacing) |
530 |
{ |
{ |
531 |
BitstreamSkip(bs, 1); // top_field_first |
if ((dec->top_field_first = BitstreamGetBit(bs))) |
532 |
BitstreamSkip(bs, 1); // alternative_vertical_scan_flag |
{ |
533 |
*/ |
DEBUG("vop: top_field_first"); |
534 |
|
} |
535 |
|
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) |
536 |
|
{ |
537 |
|
DEBUG("vop: alternate_vertical_scan"); |
538 |
|
} |
539 |
|
} |
540 |
} |
} |
541 |
|
|
542 |
*quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant |
*quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant |
599 |
write vol header |
write vol header |
600 |
*/ |
*/ |
601 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void BitstreamWriteVolHeader(Bitstream * const bs, |
602 |
const int width, |
const MBParam * pParam, const FRAMEINFO * frame) |
|
const int height, |
|
|
const int quant_type) |
|
603 |
{ |
{ |
604 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
605 |
BitstreamPad(bs); |
BitstreamPad(bs); |
635 |
// BitstreamPutBits(bs, 0, 15); |
// BitstreamPutBits(bs, 0, 15); |
636 |
|
|
637 |
WRITE_MARKER(); |
WRITE_MARKER(); |
638 |
BitstreamPutBits(bs, width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
639 |
WRITE_MARKER(); |
WRITE_MARKER(); |
640 |
BitstreamPutBits(bs, height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); // height |
641 |
WRITE_MARKER(); |
WRITE_MARKER(); |
642 |
|
|
643 |
BitstreamPutBit(bs, 0); // interlace |
BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace |
644 |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
645 |
BitstreamPutBit(bs, 0); // sprite_enable |
BitstreamPutBit(bs, 0); // sprite_enable |
646 |
BitstreamPutBit(bs, 0); // not_in_bit |
BitstreamPutBit(bs, 0); // not_in_bit |
647 |
|
|
648 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
649 |
BitstreamPutBit(bs, quant_type); |
BitstreamPutBit(bs, pParam->m_quant_type); |
650 |
|
|
651 |
if (quant_type) |
if (pParam->m_quant_type) |
652 |
{ |
{ |
653 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
654 |
if (get_intra_matrix_status()) |
if (get_intra_matrix_status()) |
680 |
(decoder uses these values to determine precise time since last resync) |
(decoder uses these values to determine precise time since last resync) |
681 |
*/ |
*/ |
682 |
void BitstreamWriteVopHeader(Bitstream * const bs, |
void BitstreamWriteVopHeader(Bitstream * const bs, |
683 |
VOP_TYPE prediction_type, |
const MBParam * pParam, |
684 |
const int rounding_type, |
const FRAMEINFO * frame) |
|
const uint32_t quant, |
|
|
const uint32_t fcode) |
|
685 |
{ |
{ |
686 |
BitstreamPad(bs); |
BitstreamPad(bs); |
687 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
688 |
|
|
689 |
BitstreamPutBits(bs, prediction_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
690 |
|
|
691 |
// time_base = 0 write n x PutBit(1), PutBit(0) |
// time_base = 0 write n x PutBit(1), PutBit(0) |
692 |
BitstreamPutBits(bs, 0, 1); |
BitstreamPutBits(bs, 0, 1); |
700 |
|
|
701 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); // vop_coded |
702 |
|
|
703 |
if (prediction_type != I_VOP) |
if (frame->coding_type != I_VOP) |
704 |
BitstreamPutBits(bs, rounding_type, 1); |
BitstreamPutBits(bs, frame->rounding_type, 1); |
705 |
|
|
706 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
707 |
|
|
708 |
BitstreamPutBits(bs, quant, 5); // quantizer |
if (frame->global_flags & XVID_INTERLACING) |
709 |
|
{ |
710 |
|
BitstreamPutBit(bs, 1); // top field first |
711 |
|
BitstreamPutBit(bs, 0); // alternate vertical scan |
712 |
|
} |
713 |
|
|
714 |
|
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
715 |
|
|
716 |
if (prediction_type != I_VOP) |
if (frame->coding_type != I_VOP) |
717 |
BitstreamPutBits(bs, fcode, 3); // fixed_code = [1,4] |
BitstreamPutBits(bs, frame->fcode, 3); // fixed_code = [1,4] |
718 |
} |
} |