--- decoder.c 2004/04/10 04:30:07 1.53 +++ decoder.c 2004/05/21 14:40:15 1.57 @@ -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.53 2004/04/10 04:30:07 suxen_drol Exp $ + * $Id: decoder.c,v 1.57 2004/05/21 14:40:15 edgomez Exp $ * ****************************************************************************/ @@ -222,6 +222,7 @@ dec->time = dec->time_base = dec->last_time_base = 0; dec->low_delay = 0; dec->packed_mode = 0; + dec->time_inc_resolution = 1; /* until VOL header says otherwise */ dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); @@ -302,7 +303,7 @@ start_timer(); predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], - iQuant, iDcScaler, predictors, bound); + iQuant, iDcScaler, predictors, bound, dec->bs_version); if (!acpred_flag) { pMB->acpred_directions[i] = 0; } @@ -496,6 +497,33 @@ mv[i] = pMB->mvs[i]; } + for (i = 0; i < 4; i++) { + /* clip to valid range */ + int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel); + if (mv[i].x > border) { + DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos); + mv[i].x = border; + } else { + border = (-(int)x_pos-1) << (5 + dec->quarterpel); + if (mv[i].x < border) { + DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos); + mv[i].x = border; + } + } + + border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel); + if (mv[i].y > border) { + DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos); + mv[i].y = border; + } else { + border = (-(int)y_pos-1) << (5 + dec->quarterpel); + if (mv[i].y < border) { + DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos); + mv[i].y = border; + } + } + } + start_timer(); if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ @@ -761,20 +789,6 @@ mv.y -= range; } - /* clip to valid range */ - - if (mv.x > ((int)(dec->mb_width - x) << (5 + dec->quarterpel)) ) - mv.x = (int)(dec->mb_width - x) << (5 + dec->quarterpel); - - else if (mv.x < (int)(-x-1) << (5 + dec->quarterpel)) - mv.x = (int)(-x-1) << (5 + dec->quarterpel); - - if (mv.y > ((int)(dec->mb_height - y) << (5 + dec->quarterpel)) ) - mv.y = (int)(dec->mb_height - y) << (5 + dec->quarterpel); - - else if (mv.y < ((int)(-y-1)) << (5 + dec->quarterpel) ) - mv.y = (int)(-y-1) << (5 + dec->quarterpel); - ret_mv->x = mv.x; ret_mv->y = mv.y; } @@ -801,10 +815,13 @@ mb_height = (dec->height + 31) / 32; } - start_timer(); - image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height, dec->bs_version); - stop_edges_timer(); + if (!dec->is_edged[0]) { + start_timer(); + image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, + dec->width, dec->height, dec->bs_version); + dec->is_edged[0] = 1; + stop_edges_timer(); + } if (gmc_warp) { /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ @@ -986,20 +1003,6 @@ else if (mv_y > high) mv_y -= range; - - /* clip to valid range */ - if (mv_x > ((int)(dec->mb_width - x) << (5 + dec->quarterpel)) ) - mv_x = (int)(dec->mb_width - x) << (5 + dec->quarterpel); - - else if (mv_x < (int)(-x-1) << (5 + dec->quarterpel)) - mv_x = (int)(-x-1) << (5 + dec->quarterpel); - - if (mv_y > ((int)(dec->mb_height - y) << (5 + dec->quarterpel)) ) - mv_y = (int)(dec->mb_height - y) << (5 + dec->quarterpel); - - else if (mv_y < ((int)(-y-1)) << (5 + dec->quarterpel) ) - mv_y = (int)(-y-1) << (5 + dec->quarterpel); - mv->x = mv_x; mv->y = mv_y; } @@ -1215,15 +1218,24 @@ uint32_t x, y; VECTOR mv; const VECTOR zeromv = {0,0}; - const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; + const int32_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; int i; - start_timer(); - image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height, dec->bs_version); - image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, - dec->width, dec->height, dec->bs_version); - stop_edges_timer(); + if (!dec->is_edged[0]) { + start_timer(); + image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, + dec->width, dec->height, dec->bs_version); + dec->is_edged[0] = 1; + stop_edges_timer(); + } + + if (!dec->is_edged[1]) { + start_timer(); + image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, + dec->width, dec->height, dec->bs_version); + dec->is_edged[1] = 1; + stop_edges_timer(); + } for (y = 0; y < dec->mb_height; y++) { /* Initialize Pred Motion Vector */ @@ -1361,17 +1373,19 @@ xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type, int quant) { + const int brightness = XVID_VERSION_MINOR(frame->version) >= 1 ? frame->brightness : 0; + if (dec->cartoon_mode) frame->general &= ~XVID_FILMEFFECT; - if ((frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) || frame->brightness!=0) + if ((frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) || brightness!=0) && mbs != NULL) /* post process */ { /* note: image is stored to tmp */ image_copy(&dec->tmp, img, dec->edged_width, dec->height); image_postproc(&dec->postproc, &dec->tmp, dec->edged_width, mbs, dec->mb_width, dec->mb_height, dec->mb_width, - frame->general, frame->brightness, dec->frames, (coding_type == B_VOP)); + frame->general, brightness, dec->frames, (coding_type == B_VOP)); img = &dec->tmp; } @@ -1453,7 +1467,6 @@ success = 0; output = 0; - if (stats) stats->type = XVID_TYPE_NOTHING; seen_something = 0; repeat: @@ -1492,6 +1505,11 @@ goto repeat; } + if(dec->frames == 0 && coding_type != I_VOP) { + /* 1st frame is not an i-vop */ + goto repeat; + } + dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; /* init pred vector to 0 */ /* packed_mode: special-N_VOP treament */ @@ -1541,7 +1559,9 @@ } image_swap(&dec->refn[0], &dec->refn[1]); + dec->is_edged[1] = dec->is_edged[0]; image_swap(&dec->cur, &dec->refn[0]); + dec->is_edged[0] = 0; SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); dec->last_reduced_resolution = reduced_resolution; dec->last_coding_type = coding_type;