--- bitstream.c 2002/07/24 00:49:16 1.26 +++ bitstream.c 2002/10/05 21:27:20 1.28.2.3 @@ -41,15 +41,16 @@ * * * Revision history: * * * + * 04.10.2002 qpel support - Isibaar * * 11.07.2002 add VOP width & height return to dec when dec->width * * or dec->height is 0 (for use in examples/ex1.c) * * MinChen * * 22.05.2002 bs_put_matrix fix * * 20.05.2002 added BitstreamWriteUserData * - * 19.06.2002 Fix a little bug in use custom quant matrix * - * MinChen * - * 08.05.2002 add low_delay support for B_VOP decode * - * MinChen * + * 19.06.2002 Fix a little bug in use custom quant matrix * + * MinChen * + * 08.05.2002 add low_delay support for B_VOP decode * + * MinChen * * 06.05.2002 low_delay * * 06.05.2002 fixed fincr/fbase error * * 01.05.2002 added BVOP support to BitstreamWriteVopHeader * @@ -57,10 +58,10 @@ * 26.03.2002 interlacing support * * 03.03.2002 qmatrix writing * * 03.03.2002 merged BITREADER and BITWRITER * - * 30.02.2002 intra_dc_threshold support * - * 04.12.2001 support for additional headers * - * 16.12.2001 inital version * - * + * 30.02.2002 intra_dc_threshold support * + * 04.12.2001 support for additional headers * + * 16.12.2001 inital version * + * * ******************************************************************************/ @@ -619,6 +620,9 @@ *intra_dc_threshold = intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; + dec->top_field_first = 0; + dec->alternate_vertical_scan = 0; + if (dec->interlacing) { dec->top_field_first = BitstreamGetBit(bs); DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first); @@ -711,22 +715,32 @@ BitstreamPutBit(bs, 0); // random_accessible_vol BitstreamPutBits(bs, 0, 8); // video_object_type_indication - BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) + + if (pParam->m_quarterpel == 0) + { + BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) + } + else + { + BitstreamPutBit(bs, 1); // is_object_layer_identified + BitstreamPutBits(bs, 2, 4); // vol_ver_id == 2 + BitstreamPutBits(bs, 0, 3); // vol_ver_priority = 0 ?? + } + BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) + BitstreamPutBit(bs, 1); // vol_control_parameters + BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" + #ifdef BFRAMES if (pParam->max_bframes > 0) { - //DPRINTF("low_delay=1"); - BitstreamPutBit(bs, 1); // vol_control_parameters - BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" BitstreamPutBit(bs, 0); // low_delay - BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) } else #endif { - BitstreamPutBits(bs, 0, 1); // vol_control_parameters (0=not given) + BitstreamPutBit(bs, 1); // low_delay } - + BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) @@ -740,7 +754,7 @@ #ifdef BFRAMES BitstreamPutBits(bs, pParam->fbase, 16); #else - BitstreamPutBits(bs, 2, 16); + BitstreamPutBits(bs, pParam->fbase, 16); #endif WRITE_MARKER(); @@ -749,7 +763,8 @@ BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment #else - BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 + BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 + BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment #endif WRITE_MARKER(); @@ -760,7 +775,16 @@ BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) - BitstreamPutBit(bs, 0); // sprite_enable + + if (pParam->m_quarterpel == 0) + { + BitstreamPutBit(bs, 0); // sprite_enable + } + else + { + BitstreamPutBits(bs, 0, 2); // sprite_enable + } + BitstreamPutBit(bs, 0); // not_in_bit // quant_type 0=h.263 1=mpeg4(quantizer tables) @@ -779,9 +803,21 @@ } + if (pParam->m_quarterpel) + { + BitstreamPutBit(bs, 1); + } + BitstreamPutBit(bs, 1); // complexity_estimation_disable BitstreamPutBit(bs, 1); // resync_marker_disable BitstreamPutBit(bs, 0); // data_partitioned + + if (pParam->m_quarterpel) + { + BitstreamPutBit(bs, 0); // newpred_enable + BitstreamPutBit(bs, 0); // reduced_resolution_vop_enabled + } + BitstreamPutBit(bs, 0); // scalability } @@ -800,22 +836,24 @@ const FRAMEINFO * frame, int vop_coded) { -#ifdef BFRAMES uint32_t i; -#endif + BitstreamPad(bs); BitstreamPutBits(bs, VOP_START_CODE, 32); 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); + for (i = 0; i < frame->seconds; i++) { + BitstreamPutBit(bs, 1); + } + BitstreamPutBit(bs, 0); +// BitstreamPutBits(bs, 0, 1); #endif WRITE_MARKER(); @@ -827,7 +865,8 @@ frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B');*/ #else - BitstreamPutBits(bs, 1, 1); + BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); +// BitstreamPutBits(bs, 1, 1); #endif WRITE_MARKER(); @@ -845,8 +884,8 @@ BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold if (frame->global_flags & XVID_INTERLACING) { - BitstreamPutBit(bs, 1); // top field first - BitstreamPutBit(bs, 0); // alternate vertical scan + BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST)); + BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN)); } BitstreamPutBits(bs, frame->quant, 5); // quantizer