--- trunk/xvidcore/src/bitstream/bitstream.c 2004/03/22 22:36:25 1382 +++ trunk/xvidcore/src/bitstream/bitstream.c 2004/10/03 16:20:51 1553 @@ -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.42 2004-03-22 22:36:23 edgomez Exp $ + * $Id: bitstream.c,v 1.47 2004-10-03 16:20:51 syskin Exp $ * ****************************************************************************/ @@ -71,8 +71,10 @@ matrix[scan_tables[0][i++]] = value; } while (value != 0 && i < 64); - i--; /* fix little bug at coeff not full */ + if (value != 0) return; + + i--; while (i < 64) { matrix[scan_tables[0][i++]] = last; } @@ -393,7 +395,7 @@ int32_t time_increment = 0; int resize = 0; - do { + while ((BitstreamPos(bs) >> 3) + 4 <= bs->length) { BitstreamByteAlign(bs); start_code = BitstreamShowBits(bs, 32); @@ -547,7 +549,7 @@ #endif if (dec->time_inc_resolution > 0) { - dec->time_inc_bits = log2bin(dec->time_inc_resolution-1); + dec->time_inc_bits = MAX(log2bin(dec->time_inc_resolution-1), 1); } else { #if 0 dec->time_inc_bits = 0; @@ -814,23 +816,12 @@ if (coding_type != B_VOP) { dec->last_time_base = dec->time_base; dec->time_base += time_incr; - dec->time = time_increment; - -#if 0 - dec->time_base * dec->time_inc_resolution + - time_increment; -#endif - dec->time_pp = (uint32_t) - (dec->time_inc_resolution + dec->time - dec->last_non_b_time)%dec->time_inc_resolution; + 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; } else { - dec->time = time_increment; -#if 0 - (dec->last_time_base + - time_incr) * dec->time_inc_resolution + time_increment; -#endif - dec->time_bp = (uint32_t) - (dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution; + 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); } DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", dec->time_pp); DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", dec->time_bp); @@ -1001,6 +992,7 @@ BitstreamSkip(bs, 32); /* user_data_start_code */ + memset(tmp, 0, 256); tmp[0] = BitstreamShowBits(bs, 8); for(i = 1; i < 256; i++){ @@ -1023,7 +1015,7 @@ else sscanf(tmp, "XviD%d", &dec->bs_version); - DPRINTF(XVID_DEBUG_HEADER, "xvid bitstream version=%i", dec->bs_version); + DPRINTF(XVID_DEBUG_HEADER, "xvid bitstream version=%i\n", dec->bs_version); } /* divx detection */ @@ -1046,7 +1038,6 @@ BitstreamSkip(bs, 8); } } - while ((BitstreamPos(bs) >> 3) < bs->length); #if 0 DPRINTF("*** WARNING: no vop_start_code found"); @@ -1196,8 +1187,8 @@ WRITE_MARKER(); if (pParam->fincr>0) { - BitstreamPutBit(bs, 1); /* fixed_vop_rate = 1 */ - BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase-1)); /* fixed_vop_time_increment */ + BitstreamPutBit(bs, 1); /* fixed_vop_rate = 1 */ + BitstreamPutBits(bs, pParam->fincr, MAX(log2bin(pParam->fbase-1),1)); /* fixed_vop_time_increment */ }else{ BitstreamPutBit(bs, 0); /* fixed_vop_rate = 0 */ } @@ -1272,16 +1263,14 @@ } /* xvid id */ -#define XVID_ID "XviD" XVID_BS_VERSION { - char xvid_id_string[100]; - - if (frame->vop_flags & XVID_VOP_CARTOON) - sprintf(xvid_id_string, "%sC", XVID_ID); - else - sprintf(xvid_id_string, "%s", XVID_ID); - - BitstreamWriteUserData(bs, xvid_id_string, strlen(xvid_id_string)); + const char xvid_user_format[] = "XviD%04d%c"; + char xvid_user_data[100]; + sprintf(xvid_user_data, + xvid_user_format, + XVID_BS_VERSION, + (frame->vop_flags & XVID_VOP_CARTOON)?'C':'\0'); + BitstreamWriteUserData(bs, xvid_user_data, strlen(xvid_user_data)); } } @@ -1323,8 +1312,7 @@ WRITE_MARKER(); /* time_increment: value=nth_of_sec, nbits = log2(resolution) */ - - BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase-1)); + BitstreamPutBits(bs, frame->ticks, MAX(log2bin(pParam->fbase-1), 1)); #if 0 DPRINTF("[%i:%i] %c", frame->seconds, frame->ticks,