41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
* 26.03.2002 interlacing support |
* 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 |
|
|
599 |
write vol header |
write vol header |
600 |
*/ |
*/ |
601 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void BitstreamWriteVolHeader(Bitstream * const bs, |
602 |
const MBParam * pParam) |
const MBParam * pParam, const FRAMEINFO * frame) |
603 |
{ |
{ |
604 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
605 |
BitstreamPad(bs); |
BitstreamPad(bs); |
640 |
BitstreamPutBits(bs, pParam->height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); // height |
641 |
WRITE_MARKER(); |
WRITE_MARKER(); |
642 |
|
|
643 |
BitstreamPutBit(bs, pParam->global_flags & XVID_INTERLACING); // 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, pParam->quant_type); |
BitstreamPutBit(bs, pParam->m_quant_type); |
650 |
|
|
651 |
if (pParam->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 |
const MBParam * pParam) |
const MBParam * pParam, |
684 |
|
const FRAMEINFO * frame) |
685 |
{ |
{ |
686 |
BitstreamPad(bs); |
BitstreamPad(bs); |
687 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
688 |
|
|
689 |
BitstreamPutBits(bs, pParam->coding_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 (pParam->coding_type != I_VOP) |
if (frame->coding_type != I_VOP) |
704 |
BitstreamPutBits(bs, pParam->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 |
if (pParam->global_flags & XVID_INTERLACING) |
if (frame->global_flags & XVID_INTERLACING) |
709 |
{ |
{ |
710 |
BitstreamPutBit(bs, 1); // top field first |
BitstreamPutBit(bs, 1); // top field first |
711 |
BitstreamPutBit(bs, 0); // alternate vertical scan |
BitstreamPutBit(bs, 0); // alternate vertical scan |
712 |
} |
} |
713 |
|
|
714 |
BitstreamPutBits(bs, pParam->quant, 5); // quantizer |
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
715 |
|
|
716 |
if (pParam->coding_type != I_VOP) |
if (frame->coding_type != I_VOP) |
717 |
BitstreamPutBits(bs, pParam->fixed_code, 3); // fixed_code = [1,4] |
BitstreamPutBits(bs, frame->fcode, 3); // fixed_code = [1,4] |
718 |
} |
} |