--- bitstream.c 2003/01/14 10:30:39 1.28.2.19 +++ bitstream.c 2003/03/26 10:39:53 1.39.2.4 @@ -438,7 +438,7 @@ uint32_t coding_type; uint32_t start_code; uint32_t time_incr = 0; - int32_t time_increment; + int32_t time_increment = 0; int resize = 0; do { @@ -521,7 +521,8 @@ BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ACE && - BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE && + BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE && + BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ASP && BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX { DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", @@ -558,18 +559,29 @@ DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); if (BitstreamGetBit(bs)) // vbv_parameters { + unsigned int bitrate; + unsigned int buffer_size; + unsigned int occupancy; + DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); - BitstreamSkip(bs, 15); // first_half_bitrate + + bitrate = BitstreamGetBits(bs,15) << 15; // first_half_bit_rate READ_MARKER(); - BitstreamSkip(bs, 15); // latter_half_bitrate + bitrate |= BitstreamGetBits(bs,15); // latter_half_bit_rate READ_MARKER(); - BitstreamSkip(bs, 15); // first_half_vbv_buffer_size + + buffer_size = BitstreamGetBits(bs, 15) << 3; // first_half_vbv_buffer_size READ_MARKER(); - BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size - BitstreamSkip(bs, 11); // first_half_vbv_occupancy + buffer_size |= BitstreamGetBits(bs, 3); // latter_half_vbv_buffer_size + + occupancy = BitstreamGetBits(bs, 11) << 15; // first_half_vbv_occupancy READ_MARKER(); - BitstreamSkip(bs, 15); // latter_half_vbv_occupancy + occupancy |= BitstreamGetBits(bs, 15); // latter_half_vbv_occupancy READ_MARKER(); + + DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate); + DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size); + DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy); } }else{ dec->low_delay = dec->low_delay_default; @@ -629,7 +641,7 @@ { if (dec->fixed_dimensions) { - DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); + DPRINTF(DPRINTF_ERROR, "decoder width/height does not match bitstream"); return -1; } resize = 1; @@ -1057,7 +1069,7 @@ BitstreamSkip(bs, 8); } - DPRINTF(DPRINTF_STARTCODE, ": %s\n", tmp); + DPRINTF(DPRINTF_STARTCODE, ": %s", tmp); /* divx detection */ i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); @@ -1112,22 +1124,23 @@ */ void BitstreamWriteVolHeader(Bitstream * const bs, - const MBParam * pParam, - const FRAMEINFO * const frame) + const MBParam * pParam) { static const unsigned int vo_id = 0; static const unsigned int vol_id = 0; int vol_ver_id=1; int profile = 0x03; /* simple profile/level 3 */ - if ( pParam->m_quarterpel || (frame->global_flags & XVID_GMC) || - (pParam->global & XVID_GLOBAL_REDUCED)) + if ( (pParam->vol_flags & XVID_QUARTERPEL) || + (pParam->vol_flags & XVID_GMC) || + (pParam->vol_flags & XVID_REDUCED_ENABLE)) vol_ver_id = 2; - if ((pParam->global & XVID_GLOBAL_REDUCED)) + if ((pParam->vol_flags & XVID_REDUCED_ENABLE)) profile = 0x93; /* advanced realtime simple profile/level 3 */ - if (pParam->m_quarterpel || (frame->global_flags & XVID_GMC)) + if ((pParam->vol_flags & XVID_QUARTERPEL) || + (pParam->vol_flags & XVID_GMC)) profile = 0xf3; /* advanced simple profile/level 2 */ // visual_object_sequence_start_code @@ -1192,8 +1205,12 @@ WRITE_MARKER(); - BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 - BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment + if (pParam->fincr>0) { + 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 + } WRITE_MARKER(); BitstreamPutBits(bs, pParam->width, 13); // width @@ -1201,11 +1218,11 @@ BitstreamPutBits(bs, pParam->height, 13); // height WRITE_MARKER(); - BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace + BitstreamPutBit(bs, pParam->vol_flags & XVID_INTERLACING); // interlace BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) if (vol_ver_id != 1) - { if (frame->global_flags & XVID_GMC) + { if ((pParam->vol_flags & XVID_GMC)) { BitstreamPutBits(bs, 2, 2); // sprite_enable=='GMC' BitstreamPutBits(bs, 2, 6); // no_of_sprite_warping_points BitstreamPutBits(bs, 3, 2); // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16 @@ -1223,9 +1240,9 @@ BitstreamPutBit(bs, 0); // not_8_bit // quant_type 0=h.263 1=mpeg4(quantizer tables) - BitstreamPutBit(bs, pParam->m_quant_type); + BitstreamPutBit(bs, pParam->vol_flags & XVID_MPEGQUANT); - if (pParam->m_quant_type) { + if ((pParam->vol_flags & XVID_MPEGQUANT)) { BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat if (get_intra_matrix_status()) { bs_put_matrix(bs, get_intra_matrix()); @@ -1239,7 +1256,7 @@ } if (vol_ver_id != 1) { - if (pParam->m_quarterpel) + if ((pParam->vol_flags & XVID_QUARTERPEL)) BitstreamPutBit(bs, 1); // quarterpel else BitstreamPutBit(bs, 0); // no quarterpel @@ -1253,15 +1270,15 @@ { BitstreamPutBit(bs, 0); // newpred_enable - BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0); + BitstreamPutBit(bs, (pParam->vol_flags & XVID_REDUCED_ENABLE)?1:0); /* reduced_resolution_vop_enabled */ } BitstreamPutBit(bs, 0); // scalability /* fake divx5 id, to ensure compatibility with divx5 decoder */ -#define DIVX5_ID "DivX501b481p" - if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { +#define DIVX5_ID "DivX000b000p" + if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_PACKED)) { BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); } @@ -1318,14 +1335,14 @@ if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) BitstreamPutBits(bs, frame->rounding_type, 1); - if ((pParam->global & XVID_GLOBAL_REDUCED)) - BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0); + if ((frame->vol_flags & XVID_REDUCED_ENABLE)) + BitstreamPutBit(bs, (frame->vop_flags & XVID_REDUCED)?1:0); BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold - if (frame->global_flags & XVID_INTERLACING) { - BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST)); - BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN)); + if ((frame->vol_flags & XVID_INTERLACING)) { + BitstreamPutBit(bs, (frame->vop_flags & XVID_TOPFIELDFIRST)); + BitstreamPutBit(bs, (frame->vop_flags & XVID_ALTERNATESCAN)); } if (frame->coding_type == S_VOP) { @@ -1339,7 +1356,7 @@ bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] WRITE_MARKER(); - if (pParam->m_quarterpel) + if ((frame->vol_flags & XVID_QUARTERPEL)) { DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].y/2); }