--- decoder.c 2005/12/24 01:06:20 1.76 +++ decoder.c 2010/08/10 15:00:34 1.83 @@ -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: decoder.c,v 1.76 2005/12/24 01:06:20 Isibaar Exp $ + * $Id: decoder.c,v 1.83 2010/08/10 15:00:34 Isibaar Exp $ * ****************************************************************************/ @@ -195,11 +195,23 @@ dec->low_delay = 0; dec->packed_mode = 0; dec->time_inc_resolution = 1; /* until VOL header says otherwise */ + dec->ver_id = 1; + + if (create->fourcc == ((int)('X')|((int)('V')<<8)| + ((int)('I')<<16)|((int)('D')<<24))) { /* XVID */ + dec->bs_version = 0; /* Initially assume oldest xvid version */ + } + else { + dec->bs_version = 0xffff; /* Initialize to very high value -> assume bugfree stream */ + } dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); - if (dec->fixed_dimensions) - return decoder_resize(dec); + if (dec->fixed_dimensions) { + int ret = decoder_resize(dec); + if (ret == XVID_ERR_MEMORY) create->handle = NULL; + return ret; + } else return 0; } @@ -745,7 +757,7 @@ bound = read_video_packet_header(bs, dec, 0, &quant, NULL, NULL, &intra_dc_threshold); x = bound % mb_width; - y = bound / mb_width; + y = MIN((bound / mb_width), (mb_height-1)); } mb = &dec->mbs[y * dec->mb_width + x]; @@ -972,7 +984,7 @@ bound = read_video_packet_header(bs, dec, fcode - 1, &quant, &fcode, NULL, &intra_dc_threshold); x = bound % mb_width; - y = bound / mb_width; + y = MIN((bound / mb_width), (mb_height-1)); } mb = &dec->mbs[y * dec->mb_width + x]; @@ -1332,6 +1344,13 @@ return -1; } +static int __inline get_resync_len_b(const int fcode_backward, + const int fcode_forward) { + int resync_len = ((fcode_forward>fcode_backward) ? fcode_forward : fcode_backward) - 1; + if (resync_len < 1) resync_len = 1; + return resync_len; +} + static void decoder_bframe(DECODER * dec, Bitstream * bs, @@ -1343,6 +1362,7 @@ VECTOR mv; const VECTOR zeromv = {0,0}; int i; + int resync_len; if (!dec->is_edged[0]) { start_timer(); @@ -1360,22 +1380,24 @@ stop_edges_timer(); } + resync_len = get_resync_len_b(fcode_backward, fcode_forward); for (y = 0; y < dec->mb_height; y++) { /* Initialize Pred Motion Vector */ dec->p_fmv = dec->p_bmv = zeromv; for (x = 0; x < dec->mb_width; x++) { MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; - const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward; int intra_dc_threshold; /* fake variable */ - if (check_resync_marker(bs, fcode_max - 1)) { - int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant, + if (check_resync_marker(bs, resync_len)) { + int bound = read_video_packet_header(bs, dec, resync_len, &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold); x = bound % dec->mb_width; - y = bound / dec->mb_width; + y = MIN((bound / dec->mb_width), (dec->mb_height-1)); /* reset predicted macroblocks */ dec->p_fmv = dec->p_bmv = zeromv; + /* update resync len with new fcodes */ + resync_len = get_resync_len_b(fcode_backward, fcode_forward); } mv = @@ -1615,7 +1637,7 @@ if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */ if (coding_type == -3) - decoder_resize(dec); + if (decoder_resize(dec)) return XVID_ERR_MEMORY; if(stats) { stats->type = XVID_TYPE_VOL;