--- bitstream.c 2003/03/26 14:56:48 1.39.2.6 +++ bitstream.c 2003/07/28 12:36:29 1.41 @@ -521,8 +521,7 @@ 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_ASP && + BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE && BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX { DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", @@ -641,7 +640,7 @@ { if (dec->fixed_dimensions) { - DPRINTF(DPRINTF_ERROR, "decoder width/height does not match bitstream"); + DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); return -1; } resize = 1; @@ -1069,7 +1068,13 @@ BitstreamSkip(bs, 8); } - DPRINTF(DPRINTF_STARTCODE, ": %s", tmp); + DPRINTF(DPRINTF_STARTCODE, ": %s\n", tmp); + + /* read xvid bitstream version */ + if(strncmp(tmp, "XviD", 4) == 0) { + sscanf(tmp, "XviD%d", &dec->bs_version); + DPRINTF(DPRINTF_HEADER, "xvid bitstream version=%i", dec->bs_version); + } /* divx detection */ i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); @@ -1124,29 +1129,23 @@ */ void BitstreamWriteVolHeader(Bitstream * const bs, - const MBParam * pParam) + const MBParam * pParam, + const FRAMEINFO * const frame) { 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 */ - int vol_type_ind=VIDOBJLAY_TYPE_SIMPLE; - if ( (pParam->vol_flags & XVID_VOL_QUARTERPEL) || - (pParam->vol_flags & XVID_VOL_GMC) || - (pParam->vol_flags & XVID_VOL_REDUCED_ENABLE)) + if ( pParam->m_quarterpel || (frame->global_flags & XVID_GMC) || + (pParam->global & XVID_GLOBAL_REDUCED)) vol_ver_id = 2; - if ((pParam->vol_flags & XVID_VOL_REDUCED_ENABLE)) { + if ((pParam->global & XVID_GLOBAL_REDUCED)) profile = 0x93; /* advanced realtime simple profile/level 3 */ - vol_type_ind = VIDOBJLAY_TYPE_ART_SIMPLE; - } - if ((pParam->vol_flags & XVID_VOL_QUARTERPEL) || - (pParam->vol_flags & XVID_VOL_GMC)) { + if (pParam->m_quarterpel || (frame->global_flags & XVID_GMC)) profile = 0xf3; /* advanced simple profile/level 2 */ - vol_type_ind = VIDOBJLAY_TYPE_ASP; - } // visual_object_sequence_start_code // BitstreamPad(bs); @@ -1160,10 +1159,13 @@ BitstreamPad(bs); BitstreamPutBits(bs, VISOBJ_START_CODE, 32); BitstreamPutBits(bs, 0, 1); // is_visual_object_identifier + + /* Video type */ BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4); // visual_object_type - + BitstreamPutBit(bs, 0); /* video_signal_type */ + // video object_start_code & vo_id - BitstreamPad(bs); + BitstreamPadAlways(bs); // next_start_code() BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); // video_object_layer_start_code & vol_id @@ -1181,7 +1183,7 @@ { BitstreamPutBit(bs, 1); // is_object_layer_identified BitstreamPutBits(bs, vol_ver_id, 4); // vol_ver_id == 2 - BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ?? + BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==highest, 7==lowest) } BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) @@ -1210,12 +1212,8 @@ WRITE_MARKER(); - 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 - } + BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 + BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment WRITE_MARKER(); BitstreamPutBits(bs, pParam->width, 13); // width @@ -1223,11 +1221,11 @@ BitstreamPutBits(bs, pParam->height, 13); // height WRITE_MARKER(); - BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_INTERLACING); // interlace + BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) if (vol_ver_id != 1) - { if ((pParam->vol_flags & XVID_VOL_GMC)) + { if (frame->global_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 @@ -1245,9 +1243,9 @@ BitstreamPutBit(bs, 0); // not_8_bit // quant_type 0=h.263 1=mpeg4(quantizer tables) - BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_MPEGQUANT); + BitstreamPutBit(bs, pParam->m_quant_type); - if ((pParam->vol_flags & XVID_VOL_MPEGQUANT)) { + if (pParam->m_quant_type) { BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat if (get_intra_matrix_status()) { bs_put_matrix(bs, get_intra_matrix()); @@ -1261,7 +1259,7 @@ } if (vol_ver_id != 1) { - if ((pParam->vol_flags & XVID_VOL_QUARTERPEL)) + if (pParam->m_quarterpel) BitstreamPutBit(bs, 1); // quarterpel else BitstreamPutBit(bs, 0); // no quarterpel @@ -1275,15 +1273,17 @@ { BitstreamPutBit(bs, 0); // newpred_enable - BitstreamPutBit(bs, (pParam->vol_flags & XVID_VOL_REDUCED_ENABLE)?1:0); + BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0); /* reduced_resolution_vop_enabled */ } BitstreamPutBit(bs, 0); // scalability + BitstreamPadAlways(bs); // next_start_code() + /* fake divx5 id, to ensure compatibility with divx5 decoder */ -#define DIVX5_ID "DivX000b000p" - if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED)) { +#define DIVX5_ID "DivX501b481p" + if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); } @@ -1332,6 +1332,14 @@ if (!vop_coded) { BitstreamPutBits(bs, 0, 1); +#if 0 + BitstreamPadAlways(bs); /* next_start_code() */ +#endif + /* NB: It's up to the function caller to write the next_start_code(). + * At the moment encoder.c respects that requisite because a VOP + * always ends with a next_start_code either if it's coded or not + * and encoder.c terminates a frame with a next_start_code in whatever + * case */ return; } @@ -1340,14 +1348,14 @@ if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) BitstreamPutBits(bs, frame->rounding_type, 1); - if ((frame->vol_flags & XVID_VOL_REDUCED_ENABLE)) - BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_REDUCED)?1:0); + if ((pParam->global & XVID_GLOBAL_REDUCED)) + BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0); BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold - if ((frame->vol_flags & XVID_VOL_INTERLACING)) { - BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_TOPFIELDFIRST)); - BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_ALTERNATESCAN)); + if (frame->global_flags & XVID_INTERLACING) { + BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST)); + BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN)); } if (frame->coding_type == S_VOP) { @@ -1361,7 +1369,7 @@ bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] WRITE_MARKER(); - if ((frame->vol_flags & XVID_VOL_QUARTERPEL)) + if (pParam->m_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); }