--- trunk/xvidcore/src/bitstream/bitstream.c 2005/10/06 10:46:42 1644 +++ trunk/xvidcore/src/bitstream/bitstream.c 2019/11/03 11:50:49 2177 @@ -20,7 +20,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bitstream.c,v 1.54 2005-10-06 10:46:42 Isibaar Exp $ + * $Id$ * ****************************************************************************/ @@ -65,7 +65,7 @@ }; -void +static void bs_get_matrix(Bitstream * bs, uint8_t * matrix) { @@ -129,7 +129,7 @@ } } - mbnum = BitstreamGetBits(bs, mbnum_bits); /* macroblock_number */ + mbnum = (mbnum_bits == 0) ? 0 : BitstreamGetBits(bs, mbnum_bits); /* macroblock_number */ DPRINTF(XVID_DEBUG_HEADER, "mbnum %i\n", mbnum); if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) @@ -153,6 +153,8 @@ READ_MARKER(); if (dec->time_inc_bits) time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ + else + time_increment = 0; READ_MARKER(); DPRINTF(XVID_DEBUG_HEADER,"time %i:%i\n", time_base, time_increment); @@ -398,7 +400,6 @@ uint32_t start_code; uint32_t time_incr = 0; int32_t time_increment = 0; - int resize = 0; while ((BitstreamPos(bs) >> 3) + 4 <= bs->length) { @@ -423,18 +424,17 @@ DPRINTF(XVID_DEBUG_STARTCODE, "\n"); } else if (start_code == VISOBJ_START_CODE) { - int visobj_ver_id; DPRINTF(XVID_DEBUG_STARTCODE, "\n"); BitstreamSkip(bs, 32); /* visual_object_start_code */ if (BitstreamGetBit(bs)) /* is_visual_object_identified */ { - visobj_ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ - DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id); + dec->ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ + DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", dec->ver_id); BitstreamSkip(bs, 3); /* visual_object_priority */ } else { - visobj_ver_id = 1; + dec->ver_id = 1; } if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ @@ -467,6 +467,7 @@ BitstreamSkip(bs, 32); /* video_object_start_code */ } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { + uint32_t width = 0, height = 0; DPRINTF(XVID_DEBUG_STARTCODE, "\n"); DPRINTF(XVID_DEBUG_HEADER, "vol id %i\n", start_code & VIDOBJLAY_START_CODE_MASK); @@ -483,7 +484,7 @@ DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id); BitstreamSkip(bs, 3); /* video_object_layer_priority */ } else { - vol_ver_id = 1; + vol_ver_id = dec->ver_id; } dec->aspect_ratio = BitstreamGetBits(bs, 4); @@ -567,8 +568,6 @@ if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) { - uint32_t width, height; - READ_MARKER(); width = BitstreamGetBits(bs, 13); /* video_object_layer_width */ READ_MARKER(); @@ -577,18 +576,6 @@ DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width); DPRINTF(XVID_DEBUG_HEADER, "height %i\n", height); - - if (dec->width != width || dec->height != height) - { - if (dec->fixed_dimensions) - { - DPRINTF(XVID_DEBUG_ERROR, "decoder width/height does not match bitstream\n"); - return -1; - } - resize = 1; - dec->width = width; - dec->height = height; - } } dec->interlacing = BitstreamGetBit(bs); @@ -765,7 +752,19 @@ } - return (resize ? -3 : -2 ); /* VOL */ + if (((width > 0) && (height > 0)) && (dec->width != width || dec->height != height)) + { + if (dec->fixed_dimensions) + { + DPRINTF(XVID_DEBUG_ERROR, "decoder width/height does not match bitstream\n"); + return -1; + } + dec->width = width; + dec->height = height; + return -3; + } + + return -2; /* VOL */ } else if (start_code == GRPOFVOP_START_CODE) { @@ -816,11 +815,12 @@ dec->time_base += time_incr; dec->time = dec->time_base*dec->time_inc_resolution + time_increment; dec->time_pp = (int32_t)(dec->time - dec->last_non_b_time); - dec->last_non_b_time = dec->time; + dec->last_non_b_time = dec->time; } else { - dec->time = (dec->last_time_base + time_incr)*dec->time_inc_resolution + time_increment; + dec->time = (dec->last_time_base + time_incr)*dec->time_inc_resolution + time_increment; dec->time_bp = dec->time_pp - (int32_t)(dec->last_non_b_time - dec->time); } + if (dec->time_pp <= 0) dec->time_pp = 1; DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", dec->time_pp); DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", dec->time_bp); @@ -860,8 +860,9 @@ dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && (coding_type == P_VOP || coding_type == I_VOP)) { - if (BitstreamGetBit(bs)); + if (BitstreamGetBit(bs)) { DPRINTF(XVID_DEBUG_ERROR, "RRV not supported (anymore)\n"); + } } if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { @@ -919,7 +920,7 @@ int i; - for (i = 0 ; i < dec->sprite_warping_points; i++) + for (i = 0 ; i < MIN(4, dec->sprite_warping_points); i++) { int length; int x = 0, y = 0; @@ -1024,6 +1025,11 @@ version, build, dec->packed_mode); } + if ((dec->bs_version == 0) && (build > 0) && + (build != 1393)) { /* non-xvid stream with xvid fourcc */ + dec->bs_version = 0xffff; + } + } else /* start_code == ? */ { if (BitstreamShowBits(bs, 24) == 0x000001) { @@ -1067,7 +1073,8 @@ void BitstreamWriteVolHeader(Bitstream * const bs, const MBParam * pParam, - const FRAMEINFO * const frame) + const FRAMEINFO * const frame, + const int num_slices) { static const unsigned int vo_id = 0; static const unsigned int vol_id = 0; @@ -1232,7 +1239,12 @@ } BitstreamPutBit(bs, 1); /* complexity_estimation_disable */ - BitstreamPutBit(bs, 1); /* resync_marker_disable */ + + if (num_slices > 1) + BitstreamPutBit(bs, 0); /* resync_marker_enabled */ + else + BitstreamPutBit(bs, 1); /* resync_marker_disabled */ + BitstreamPutBit(bs, 0); /* data_partitioned */ if (vol_ver_id != 1) { @@ -1247,7 +1259,7 @@ /* divx5 userdata string */ #define DIVX5_ID ((char *)"DivX503b1393") if ((pParam->global_flags & XVID_GLOBAL_DIVX5_USERDATA)) { - BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); + BitstreamWriteUserData(bs, DIVX5_ID, (uint32_t)strlen(DIVX5_ID)); if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED)) BitstreamPutBits(bs, 'p', 8); } @@ -1260,7 +1272,7 @@ xvid_user_format, XVID_BS_VERSION, (frame->vop_flags & XVID_VOP_CARTOON)?'C':'\0'); - BitstreamWriteUserData(bs, xvid_user_data, strlen(xvid_user_data)); + BitstreamWriteUserData(bs, xvid_user_data, (uint32_t)strlen(xvid_user_data)); } } @@ -1381,7 +1393,7 @@ const char *data, const unsigned int length) { - int i; + unsigned int i; BitstreamPad(bs); BitstreamPutBits(bs, USERDATA_START_CODE, 32); @@ -1441,12 +1453,11 @@ if (frame->coding_type == I_VOP) nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER; /* 16 zeros followed by a 1. */ - else if (frame->coding_type == P_VOP) - nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER-1 + frame->fcode; - else /* B_VOP */ - nbitsresyncmarker = MAX(NUMBITS_VP_RESYNC_MARKER, NUMBITS_VP_RESYNC_MARKER-1 + MAX(frame->fcode, frame->bcode)); + else if (frame->coding_type == B_VOP) /* B_VOP */ + nbitsresyncmarker = MAX(NUMBITS_VP_RESYNC_MARKER+1, NUMBITS_VP_RESYNC_MARKER + MAX(frame->fcode, frame->bcode) - 1); + else /*(frame->coding_type == P_VOP)*/ + nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + frame->fcode - 1; - BitstreamPadAlways(bs); BitstreamPutBits(bs, RESYNC_MARKER, nbitsresyncmarker); BitstreamPutBits(bs, mbnum, mbnum_bits); BitstreamPutBits(bs, frame->quant, 5);