--- decoder.c 2003/12/13 13:52:25 1.49.2.25 +++ decoder.c 2004/07/24 11:46:08 1.63 @@ -4,7 +4,7 @@ * - Decoder Module - * * Copyright(C) 2002 MinChen - * 2002-2003 Peter Ross + * 2002-2004 Peter Ross * * This program is free software ; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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.49.2.25 2003/12/13 13:52:25 syskin Exp $ + * $Id: decoder.c,v 1.63 2004/07/24 11:46:08 edgomez Exp $ * ****************************************************************************/ @@ -48,6 +48,7 @@ #include "image/interpolate8x8.h" #include "image/reduced.h" #include "image/font.h" +#include "image/qpel.h" #include "bitstream/mbcoding.h" #include "prediction/mbprediction.h" @@ -61,6 +62,11 @@ #include "image/postprocessing.h" #include "utils/mem_align.h" +#ifdef ARCH_IS_IA32 +#define interpolate16x16_quarterpel new_interpolate16x16_quarterpel +#define interpolate8x8_quarterpel new_interpolate8x8_quarterpel +#endif + static int decoder_resize(DECODER * dec) { @@ -77,6 +83,8 @@ xvid_free(dec->last_mbs); if (dec->mbs) xvid_free(dec->mbs); + if (dec->qscale) + xvid_free(dec->qscale); /* realloc */ dec->mb_width = (dec->width + 15) / 16; @@ -161,6 +169,13 @@ memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); + /* nothing happens if that fails */ + dec->qscale = + xvid_malloc(sizeof(int) * dec->mb_width * dec->mb_height, CACHE_LINE); + + if (dec->qscale) + memset(dec->qscale, 0, sizeof(int) * dec->mb_width * dec->mb_height); + return 0; } @@ -200,11 +215,12 @@ /* image based GMC */ image_null(&dec->gmc); - dec->mbs = NULL; dec->last_mbs = NULL; + dec->qscale = NULL; init_timer(); + init_postproc(&dec->postproc); init_mpeg_matrix(dec->mpeg_quant_matrices); /* For B-frame support (used to save reference frame's time */ @@ -212,6 +228,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); @@ -227,6 +244,7 @@ { xvid_free(dec->last_mbs); xvid_free(dec->mbs); + xvid_free(dec->qscale); /* image based GMC */ image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); @@ -327,7 +345,7 @@ stop_coding_timer(); start_timer(); - add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors); + add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version); stop_prediction_timer(); start_timer(); @@ -381,7 +399,6 @@ const int reduced_resolution, const MACROBLOCK * pMB) { - DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE); DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); int stride = dec->edged_width; @@ -390,23 +407,30 @@ int i; const uint32_t iQuant = pMB->quant; const int direction = dec->alternate_vertical_scan ? 2 : 0; - const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter; + typedef void (*get_inter_block_function_t)( + Bitstream * bs, + int16_t * block, + int direction, + const int quant, + const uint16_t *matrix); + + const get_inter_block_function_t get_inter_block = (dec->quant_type == 0) + ? get_inter_block_h263 + : get_inter_block_mpeg; + + memset(&data[0], 0, 6*64*sizeof(int16_t)); /* clear */ for (i = 0; i < 6; i++) { if (cbp & (1 << (5 - i))) { /* coded */ - memset(block, 0, 64 * sizeof(int16_t)); /* clear */ + /* Decode coeffs and dequantize on the fly */ start_timer(); - get_inter_block(bs, block, direction); + get_inter_block(bs, &data[i*64], direction, iQuant, get_inter_matrix(dec->mpeg_quant_matrices)); stop_coding_timer(); start_timer(); - dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices); - stop_iquant_timer(); - - start_timer(); idct(&data[i * 64]); stop_idct_timer(); } @@ -485,6 +509,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 */ @@ -776,10 +827,13 @@ mb_height = (dec->height + 31) / 32; } - start_timer(); - image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height); - 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 */ @@ -850,12 +904,12 @@ mb->quant = quant; if (dec->interlacing) { - if ((cbp || intra) && !mcsel) { + if (cbp || intra) { mb->field_dct = BitstreamGetBit(bs); DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); } - if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { + if ((mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) && !mcsel) { mb->field_pred = BitstreamGetBit(bs); DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); @@ -899,6 +953,7 @@ } else if (gmc_warp) { /* a not coded S(GMC)-VOP macroblock */ mb->mode = MODE_NOT_CODED_GMC; + mb->quant = quant; decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding); if(dec->out_frm && cp_mb > 0) { @@ -908,6 +963,7 @@ st_mb = x+1; } else { /* not coded P_VOP macroblock */ mb->mode = MODE_NOT_CODED; + mb->quant = quant; mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; @@ -934,7 +990,9 @@ get_b_motion_vector(Bitstream * bs, VECTOR * mv, int fcode, - const VECTOR pmv) + const VECTOR pmv, + const DECODER * const dec, + const int x, const int y) { const int scale_fac = 1 << (fcode - 1); const int high = (32 * scale_fac) - 1; @@ -986,7 +1044,6 @@ if (!direct) { uv_dx = pMB->mvs[0].x; uv_dy = pMB->mvs[0].y; - b_uv_dx = pMB->b_mvs[0].x; b_uv_dy = pMB->b_mvs[0].y; @@ -999,21 +1056,20 @@ uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; - b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3]; b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; } else { - if(dec->quarterpel) { - uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); - uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); - b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2); - b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2); - } else { - uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; - uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; - b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; - b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; + uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; + uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; + b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; + b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; + + if (dec->quarterpel) { + uv_dx /= 2; + uv_dy /= 2; + b_uv_dx /= 2; + b_uv_dy /= 2; } uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; @@ -1049,8 +1105,8 @@ pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); - interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, - 16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); + interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos + 8, + pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); } interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx, @@ -1097,32 +1153,32 @@ interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, - stride, 1, 8); + stride, 0, 8); interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, - stride, 1, 8); + stride, 0, 8); interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, - stride, 1, 8); + stride, 0, 8); interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, - stride, 1, 8); + stride, 0, 8); interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, - stride2, 1, 8); + stride2, 0, 8); interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, - stride2, 1, 8); + stride2, 0, 8); stop_comp_timer(); @@ -1172,15 +1228,23 @@ 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; int i; - start_timer(); - image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height); - image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, - dec->width, dec->height); - 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 */ @@ -1263,18 +1327,19 @@ switch (mb->mode) { case MODE_DIRECT: - get_b_motion_vector(bs, &mv, 1, zeromv); + get_b_motion_vector(bs, &mv, 1, zeromv, dec, x, y); case MODE_DIRECT_NONE_MV: for (i = 0; i < 4; i++) { - mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x); - mb->b_mvs[i].x = (int32_t) ((mv.x == 0) - ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD - : mb->mvs[i].x - last_mb->mvs[i].x); - mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y); - mb->b_mvs[i].y = (int32_t) ((mv.y == 0) - ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD - : mb->mvs[i].y - last_mb->mvs[i].y); + mb->mvs[i].x = last_mb->mvs[i].x*dec->time_bp/dec->time_pp + mv.x; + mb->mvs[i].y = last_mb->mvs[i].y*dec->time_bp/dec->time_pp + mv.y; + + mb->b_mvs[i].x = (mv.x) + ? mb->mvs[i].x - last_mb->mvs[i].x + : last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp; + mb->b_mvs[i].y = (mv.y) + ? mb->mvs[i].y - last_mb->mvs[i].y + : last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp; } decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], @@ -1282,10 +1347,10 @@ break; case MODE_INTERPOLATE: - get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv); + get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y); dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; - get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv); + get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv, dec, x, y); dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0]; decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], @@ -1293,14 +1358,14 @@ break; case MODE_BACKWARD: - get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv); + get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y); dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0); break; case MODE_FORWARD: - get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv); + get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y); dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1); @@ -1315,15 +1380,22 @@ /* perform post processing if necessary, and output the image */ void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, - xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) + xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, + int coding_type, int quant) { - if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV) && mbs != NULL) /* post process */ + 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) || brightness!=0) + && mbs != NULL) /* post process */ { /* note: image is stored to tmp */ image_copy(&dec->tmp, img, dec->edged_width, dec->height); - image_deblock(&dec->tmp, dec->edged_width, - mbs, dec->mb_width, dec->mb_height, dec->mb_width, - frame->general); + image_postproc(&dec->postproc, &dec->tmp, dec->edged_width, + mbs, dec->mb_width, dec->mb_height, dec->mb_width, + frame->general, brightness, dec->frames, (coding_type == B_VOP)); img = &dec->tmp; } @@ -1335,6 +1407,14 @@ stats->type = coding2type(coding_type); stats->data.vop.time_base = (int)dec->time_base; stats->data.vop.time_increment = 0; /* XXX: todo */ + stats->data.vop.qscale_stride = dec->mb_width; + stats->data.vop.qscale = dec->qscale; + if (stats->data.vop.qscale != NULL && mbs != NULL) { + int i; + for (i = 0; i < dec->mb_width*dec->mb_height; i++) + stats->data.vop.qscale[i] = mbs[i].quant; + } else + stats->data.vop.qscale = NULL; } } @@ -1347,7 +1427,7 @@ Bitstream bs; uint32_t rounding; uint32_t reduced_resolution; - uint32_t quant; + uint32_t quant = 2; uint32_t fcode_forward; uint32_t fcode_backward; uint32_t intra_dc_threshold; @@ -1370,7 +1450,7 @@ /* if not decoding "low_delay/packed", and this isn't low_delay and we have a reference frame, then outout the reference frame */ if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) { - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); dec->frames = 0; ret = 0; } else { @@ -1435,12 +1515,17 @@ 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 */ if (dec->packed_mode && coding_type == N_VOP) { if (dec->low_delay_default && dec->frames > 0) { - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); output = 1; } /* ignore otherwise */ @@ -1474,17 +1559,19 @@ /* note: for packed_mode, output is performed when the special-N_VOP is decoded */ if (!(dec->low_delay_default && dec->packed_mode)) { if (dec->low_delay) { - decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); + decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); output = 1; } else if (dec->frames > 0) { /* is the reference frame valid? */ /* output the reference frame */ - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); output = 1; } } 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; @@ -1496,30 +1583,32 @@ if (dec->low_delay) { DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); - dec->low_delay = 1; + dec->low_delay = 0; } if (dec->frames < 2) { /* attemping to decode a bvop without atleast 2 reference frames */ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, "broken b-frame, mising ref frames"); - stats->type = XVID_TYPE_NOTHING; + if (stats) stats->type = XVID_TYPE_NOTHING; } else if (dec->time_pp <= dec->time_bp) { /* this occurs when dx50_bvop_compatibility==0 sequences are decoded in vfw. */ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp); - stats->type = XVID_TYPE_NOTHING; + if (stats) stats->type = XVID_TYPE_NOTHING; } else { decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); - decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); + decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); } output = 1; dec->frames++; } - BitstreamByteAlign(&bs); +#if 0 /* Avoids to read to much data because of 32bit reads in our BS functions */ + BitstreamByteAlign(&bs); +#endif /* low_delay_default mode: repeat in packed_mode */ if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) { @@ -1534,7 +1623,7 @@ if (dec->low_delay_default && output == 0) { if (dec->packed_mode && seen_something) { /* output the recently decoded frame */ - decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); + decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); } else { image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, @@ -1542,7 +1631,7 @@ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, "bframe decoder lag"); - decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP); + decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant); if (stats) stats->type = XVID_TYPE_NOTHING; } } @@ -1550,5 +1639,5 @@ emms(); stop_global_timer(); - return BitstreamPos(&bs) / 8; /* number of bytes consumed */ + return (BitstreamPos(&bs) + 7) / 8; /* number of bytes consumed */ }