--- bitstream.c 2003/01/13 14:33:24 1.28.2.18 +++ bitstream.c 2003/07/28 12:36:29 1.41 @@ -41,8 +41,8 @@ * * * Revision history: * * * - * 05.01.2003 GMC support - gruel * - * 04.10.2002 qpel support - Isibaar * + * 05.01.2003 GMC support - gruel * + * 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 * @@ -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 { @@ -558,18 +558,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; @@ -1058,6 +1069,12 @@ } 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); @@ -1139,17 +1156,20 @@ BitstreamPutBits(bs, profile, 8); // visual_object_start_code - BitstreamPadAlways(bs); + 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 - BitstreamPadAlways(bs); + BitstreamPadAlways(bs); // next_start_code() BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); // video_object_layer_start_code & vol_id - BitstreamPadAlways(bs); + BitstreamPad(bs); BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32); BitstreamPutBit(bs, 0); // random_accessible_vol @@ -1163,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) @@ -1259,6 +1279,8 @@ BitstreamPutBit(bs, 0); // scalability + BitstreamPadAlways(bs); // next_start_code() + /* fake divx5 id, to ensure compatibility with divx5 decoder */ #define DIVX5_ID "DivX501b481p" if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { @@ -1310,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; } @@ -1371,7 +1401,7 @@ { int i; - BitstreamPadAlways(bs); + BitstreamPad(bs); BitstreamPutBits(bs, USERDATA_START_CODE, 32); for (i = 0; i < length; i++) {