--- trunk/xvidcore/src/bitstream/bitstream.c 2002/03/26 11:16:08 69 +++ trunk/xvidcore/src/bitstream/bitstream.c 2002/05/01 13:00:02 152 @@ -40,8 +40,10 @@ /****************************************************************************** * * * Revision history: * - * * - * 26.03.2002 interlacing support + * * + * 01.05.2002 added BVOP support to BitstreamWriteVopHeader + * 15.04.2002 rewrite log2bin use asm386 By MinChen * + * 26.03.2002 interlacing support * * 03.03.2002 qmatrix writing * * 03.03.2002 merged BITREADER and BITWRITER * * 30.02.2002 intra_dc_threshold support * @@ -55,8 +57,11 @@ #include "zigzag.h" #include "../quant/quant_matrix.h" + static int __inline log2bin(int value) { +/* Changed by Chenm001 */ +#ifndef WIN32 int n = 0; while (value) { @@ -64,6 +69,12 @@ n++; } return n; +#else + __asm{ + bsr eax,value + inc eax + } +#endif } @@ -284,7 +295,7 @@ } - if (dec->interlacing = BitstreamGetBit(bs)) + if ((dec->interlacing = BitstreamGetBit(bs))) { DEBUG("vol: interlacing"); } @@ -518,11 +529,11 @@ if (dec->interlacing) { - if (dec->top_field_first = BitstreamGetBit(bs)) + if ((dec->top_field_first = BitstreamGetBit(bs))) { DEBUG("vop: top_field_first"); } - if (dec->alternate_vertical_scan = BitstreamGetBit(bs)) + if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { DEBUG("vop: alternate_vertical_scan"); } @@ -589,7 +600,7 @@ write vol header */ void BitstreamWriteVolHeader(Bitstream * const bs, - const MBParam * pParam) + const MBParam * pParam, const FRAMEINFO * frame) { // video object_start_code & vo_id BitstreamPad(bs); @@ -630,15 +641,15 @@ BitstreamPutBits(bs, pParam->height, 13); // height WRITE_MARKER(); - BitstreamPutBit(bs, pParam->global_flags & XVID_INTERLACING); // interlace + BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) BitstreamPutBit(bs, 0); // sprite_enable BitstreamPutBit(bs, 0); // not_in_bit // quant_type 0=h.263 1=mpeg4(quantizer tables) - BitstreamPutBit(bs, pParam->quant_type); + BitstreamPutBit(bs, pParam->m_quant_type); - if (pParam->quant_type) + if (pParam->m_quant_type) { BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat if (get_intra_matrix_status()) @@ -670,38 +681,59 @@ (decoder uses these values to determine precise time since last resync) */ void BitstreamWriteVopHeader(Bitstream * const bs, - const MBParam * pParam) + const MBParam * pParam, + const FRAMEINFO * frame) { +#ifdef BFRAMES + uint32_t i; +#endif BitstreamPad(bs); BitstreamPutBits(bs, VOP_START_CODE, 32); - BitstreamPutBits(bs, pParam->coding_type, 2); + BitstreamPutBits(bs, frame->coding_type, 2); // time_base = 0 write n x PutBit(1), PutBit(0) +#ifdef BFRAMES + for (i = 0; i < frame->seconds; i++) + { + BitstreamPutBit(bs, 1); + } + BitstreamPutBit(bs, 0); +#else BitstreamPutBits(bs, 0, 1); +#endif WRITE_MARKER(); // time_increment: value=nth_of_sec, nbits = log2(resolution) +#ifdef BFRAMES + BitstreamPutBits(bs, frame->ticks, 5); + dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B'); +#else BitstreamPutBits(bs, 1, 1); +#endif WRITE_MARKER(); BitstreamPutBits(bs, 1, 1); // vop_coded - if (pParam->coding_type != I_VOP) - BitstreamPutBits(bs, pParam->rounding_type, 1); + if (frame->coding_type != I_VOP) + BitstreamPutBits(bs, frame->rounding_type, 1); BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold - if (pParam->global_flags & XVID_INTERLACING) + if (frame->global_flags & XVID_INTERLACING) { BitstreamPutBit(bs, 1); // top field first BitstreamPutBit(bs, 0); // alternate vertical scan } - BitstreamPutBits(bs, pParam->quant, 5); // quantizer + BitstreamPutBits(bs, frame->quant, 5); // quantizer - if (pParam->coding_type != I_VOP) - BitstreamPutBits(bs, pParam->fixed_code, 3); // fixed_code = [1,4] + if (frame->coding_type != I_VOP) + BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code + + if (frame->coding_type == B_VOP) + BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code + }