--- decoder.c 2004/07/10 17:49:31 1.61 +++ decoder.c 2005/03/27 03:59:41 1.69 @@ -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.61 2004/07/10 17:49:31 edgomez Exp $ + * $Id: decoder.c,v 1.69 2005/03/27 03:59:41 suxen_drol Exp $ * ****************************************************************************/ @@ -46,8 +46,8 @@ #include "dct/fdct.h" #include "utils/mem_transfer.h" #include "image/interpolate8x8.h" -#include "image/reduced.h" #include "image/font.h" +#include "image/qpel.h" #include "bitstream/mbcoding.h" #include "prediction/mbprediction.h" @@ -270,8 +270,7 @@ Bitstream * bs, const uint32_t quant, const uint32_t intra_dc_threshold, - const unsigned int bound, - const int reduced_resolution) + const unsigned int bound) { DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); @@ -284,15 +283,9 @@ uint32_t iQuant = pMB->quant; uint8_t *pY_Cur, *pU_Cur, *pV_Cur; - if (reduced_resolution) { - pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); - pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); - pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); - }else{ - pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); - pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); - pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); - } + pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); + pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); + pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); memset(block, 0, 6 * 64 * sizeof(int16_t)); /* clear */ @@ -362,24 +355,12 @@ } start_timer(); - - if (reduced_resolution) - { - next_block*=2; - copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); - copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); - copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); - copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); - copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); - copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); - }else{ - transfer_16to8copy(pY_Cur, &data[0 * 64], stride); - transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); - transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); - transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); - transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); - transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); - } + transfer_16to8copy(pY_Cur, &data[0 * 64], stride); + transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); + transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); + transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); + transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); + transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); stop_transfer_timer(); } @@ -390,14 +371,12 @@ uint8_t * pY_Cur, uint8_t * pU_Cur, uint8_t * pV_Cur, - const int reduced_resolution, const MACROBLOCK * pMB) { - DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); + DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE); int stride = dec->edged_width; - int next_block = stride * (reduced_resolution ? 16 : 8); - const int stride2 = stride/2; + int next_block = stride * 8; int i; const uint32_t iQuant = pMB->quant; const int direction = dec->alternate_vertical_scan ? 2 : 0; @@ -407,63 +386,93 @@ int direction, const int quant, const uint16_t *matrix); + typedef void (*add_residual_function_t)( + uint8_t *predicted_block, + const int16_t *residual, + int stride); const get_inter_block_function_t get_inter_block = (dec->quant_type == 0) - ? get_inter_block_h263 - : get_inter_block_mpeg; + ? (get_inter_block_function_t)get_inter_block_h263 + : (get_inter_block_function_t)get_inter_block_mpeg; + + uint8_t *dst[6]; + int strides[6]; - memset(&data[0], 0, 6*64*sizeof(int16_t)); /* clear */ - for (i = 0; i < 6; i++) { + if (dec->interlacing && pMB->field_dct) { + next_block = stride; + stride *= 2; + } - if (cbp & (1 << (5 - i))) { /* coded */ + dst[0] = pY_Cur; + dst[2] = pY_Cur + next_block; + dst[1] = dst[0] + 8; + dst[3] = dst[2] + 8; + dst[4] = pU_Cur; + dst[5] = pV_Cur; + strides[0] = strides[1] = strides[2] = strides[3] = stride; + strides[4] = stride/2; + strides[5] = stride/2; + + for (i = 0; i < 6; i++) { + /* Process only coded blocks */ + if (cbp & (1 << (5 - i))) { + /* Clear the block */ + memset(&data[0], 0, 64*sizeof(int16_t)); /* Decode coeffs and dequantize on the fly */ start_timer(); - get_inter_block(bs, &data[i*64], direction, iQuant, get_inter_matrix(dec->mpeg_quant_matrices)); + get_inter_block(bs, &data[0], direction, iQuant, get_inter_matrix(dec->mpeg_quant_matrices)); stop_coding_timer(); + /* iDCT */ start_timer(); - idct(&data[i * 64]); + idct(&data[0]); stop_idct_timer(); - } - } - if (dec->interlacing && pMB->field_dct) { - next_block = stride; - stride *= 2; + /* Add this residual to the predicted block */ + start_timer(); + transfer_16to8add(dst[i], &data[0], strides[i]); + stop_transfer_timer(); + } } +} - start_timer(); - if (reduced_resolution) { - if (cbp & 32) - add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); - if (cbp & 16) - add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); - if (cbp & 8) - add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); - if (cbp & 4) - add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); - if (cbp & 2) - add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); - if (cbp & 1) - add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); - } else { - if (cbp & 32) - transfer_16to8add(pY_Cur, &data[0 * 64], stride); - if (cbp & 16) - transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); - if (cbp & 8) - transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); - if (cbp & 4) - transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride); - if (cbp & 2) - transfer_16to8add(pU_Cur, &data[4 * 64], stride2); - if (cbp & 1) - transfer_16to8add(pV_Cur, &data[5 * 64], stride2); - } - stop_transfer_timer(); +static void __inline +validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec) +{ + /* clip a vector to valid range + prevents crashes if bitstream is broken + */ + int shift = 5 + dec->quarterpel; + int xborder_high = (int)(dec->mb_width - x_pos) << shift; + int xborder_low = (-(int)x_pos-1) << shift; + int yborder_high = (int)(dec->mb_height - y_pos) << shift; + int yborder_low = (-(int)y_pos-1) << shift; + +#define CHECK_MV(mv) \ + do { \ + if ((mv).x > xborder_high) { \ + DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", (mv).x, xborder_high, x_pos, y_pos); \ + (mv).x = xborder_high; \ + } else if ((mv).x < xborder_low) { \ + DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", (mv).x, xborder_low, x_pos, y_pos); \ + (mv).x = xborder_low; \ + } \ + if ((mv).y > yborder_high) { \ + DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", (mv).y, yborder_high, x_pos, y_pos); \ + (mv).y = yborder_high; \ + } else if ((mv).y < yborder_low) { \ + DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", (mv).y, yborder_low, x_pos, y_pos); \ + (mv).y = yborder_low; \ + } \ + } while (0) + + CHECK_MV(mv[0]); + CHECK_MV(mv[1]); + CHECK_MV(mv[2]); + CHECK_MV(mv[3]); } /* decode an inter macroblock */ @@ -475,7 +484,6 @@ const uint32_t cbp, Bitstream * bs, const uint32_t rounding, - const int reduced_resolution, const int ref) { uint32_t stride = dec->edged_width; @@ -487,48 +495,13 @@ int uv_dx, uv_dy; VECTOR mv[4]; /* local copy of mvs */ - if (reduced_resolution) { - pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); - pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); - pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); - for (i = 0; i < 4; i++) { - mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x); - mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y); - } - } else { - pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); - pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); - pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); - for (i = 0; i < 4; i++) - mv[i] = pMB->mvs[i]; - } + pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); + pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); + pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); + for (i = 0; i < 4; i++) + 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; - } - } - } + validate_vector(mv, x_pos, y_pos, dec); start_timer(); @@ -543,10 +516,7 @@ uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; - if (reduced_resolution) - interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, - mv[0].x, mv[0].y, stride, rounding); - else if (dec->quarterpel) + if (dec->quarterpel) interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, dec->qtmp.y + 128, 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding); @@ -567,21 +537,7 @@ uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf]; - if (reduced_resolution) { - interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, - mv[0].x, mv[0].y, stride, rounding); - interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos, - mv[1].x, mv[1].y, stride, rounding); - interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16, - mv[2].x, mv[2].y, stride, rounding); - interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16, - mv[3].x, mv[3].y, stride, rounding); - interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos, - uv_dx, uv_dy, stride2, rounding); - interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos, - uv_dx, uv_dy, stride2, rounding); - - } else if (dec->quarterpel) { + if (dec->quarterpel) { interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, dec->qtmp.y + 128, 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding); @@ -607,23 +563,15 @@ } /* chroma */ - if (reduced_resolution) { - interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, - uv_dx, uv_dy, stride2, rounding); - interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, - uv_dx, uv_dy, stride2, rounding); - } else { - interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, - uv_dx, uv_dy, stride2, rounding); - interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos, - uv_dx, uv_dy, stride2, rounding); - } + interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, + uv_dx, uv_dy, stride2, rounding); + interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos, + uv_dx, uv_dy, stride2, rounding); stop_comp_timer(); if (cbp) - decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, - reduced_resolution, pMB); + decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB); } static void @@ -670,7 +618,7 @@ stop_transfer_timer(); if (cbp) - decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB); + decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB); } @@ -678,19 +626,13 @@ static void decoder_iframe(DECODER * dec, Bitstream * bs, - int reduced_resolution, int quant, int intra_dc_threshold) { uint32_t bound; uint32_t x, y; - uint32_t mb_width = dec->mb_width; - uint32_t mb_height = dec->mb_height; - - if (reduced_resolution) { - mb_width = (dec->width + 31) / 32; - mb_height = (dec->height + 31) / 32; - } + const uint32_t mb_width = dec->mb_width; + const uint32_t mb_height = dec->mb_height; bound = 0; @@ -746,7 +688,7 @@ } decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, - intra_dc_threshold, bound, reduced_resolution); + intra_dc_threshold, bound); } if(dec->out_frm) @@ -804,7 +746,6 @@ decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, - int reduced_resolution, int quant, int fcode, int intra_dc_threshold, @@ -813,13 +754,8 @@ uint32_t x, y; uint32_t bound; int cp_mb, st_mb; - uint32_t mb_width = dec->mb_width; - uint32_t mb_height = dec->mb_height; - - if (reduced_resolution) { - mb_width = (dec->width + 31) / 32; - mb_height = (dec->height + 31) / 32; - } + const uint32_t mb_width = dec->mb_width; + const uint32_t mb_height = dec->mb_height; if (!dec->is_edged[0]) { start_timer(); @@ -938,12 +874,11 @@ 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; decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, - intra_dc_threshold, bound, reduced_resolution); + intra_dc_threshold, bound); continue; } - decoder_mbinter(dec, mb, x, y, cbp, bs, - rounding, reduced_resolution, 0); + decoder_mbinter(dec, mb, x, y, cbp, bs, rounding, 0); } else if (gmc_warp) { /* a not coded S(GMC)-VOP macroblock */ mb->mode = MODE_NOT_CODED_GMC; @@ -963,7 +898,7 @@ mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; decoder_mbinter(dec, mb, x, y, 0, bs, - rounding, reduced_resolution, 0); + rounding, 0); if(dec->out_frm && cp_mb > 0) { output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); @@ -1018,7 +953,7 @@ decoder_bf_interpolate_mbinter(DECODER * dec, IMAGE forward, IMAGE backward, - const MACROBLOCK * pMB, + MACROBLOCK * pMB, const uint32_t x_pos, const uint32_t y_pos, Bitstream * bs, @@ -1035,10 +970,12 @@ pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); + validate_vector(pMB->mvs, x_pos, y_pos, dec); + validate_vector(pMB->b_mvs, x_pos, y_pos, dec); + 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; @@ -1051,21 +988,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]; @@ -1113,73 +1049,43 @@ if(dec->quarterpel) { if(!direct) { - interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, - dec->qtmp.y + 128, 16*x_pos, 16*y_pos, - pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); + interpolate16x16_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, + dec->qtmp.y + 128, 16*x_pos, 16*y_pos, + pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); } else { - interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, - dec->qtmp.y + 128, 16*x_pos, 16*y_pos, - pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); - interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, - dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, - pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); - interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, - dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, - pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); - interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, - dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, - pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); + interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, + dec->qtmp.y + 128, 16*x_pos, 16*y_pos, + pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); + interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, + dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, + pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); + interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, + dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, + pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); + interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, + dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, + pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); } } else { - interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, - pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); - interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, - 16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); - interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, - 16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); - interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, - 16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); - } - - interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, - b_uv_dx, b_uv_dy, stride2, 0); - interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos, - b_uv_dx, b_uv_dy, stride2, 0); - - 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); - - 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); - - 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); - - 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); - - 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); - - 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); + interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos, 16 * y_pos, + pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); + interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos + 8, + 16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); + interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos, + 16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); + interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos + 8, + 16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); + } + + interpolate8x8_add_switch(dec->cur.u, backward.u, 8 * x_pos, 8 * y_pos, + b_uv_dx, b_uv_dy, stride2, 0); + interpolate8x8_add_switch(dec->cur.v, backward.v, 8 * x_pos, 8 * y_pos, + b_uv_dx, b_uv_dy, stride2, 0); stop_comp_timer(); if (cbp) - decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB); + decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, pMB); } /* for decode B-frame dbquant */ @@ -1274,7 +1180,7 @@ if (last_mb->mode == MODE_NOT_CODED) { mb->cbp = 0; mb->mode = MODE_FORWARD; - decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1); + decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1); continue; } @@ -1357,14 +1263,14 @@ 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); + decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0); break; case MODE_FORWARD: 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); + decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1); break; default: @@ -1414,7 +1320,6 @@ } } - int decoder_decode(DECODER * dec, xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) @@ -1422,7 +1327,6 @@ Bitstream bs; uint32_t rounding; - uint32_t reduced_resolution; uint32_t quant = 2; uint32_t fcode_forward; uint32_t fcode_backward; @@ -1477,10 +1381,16 @@ repeat: - coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, + coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); - DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i\n", + DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%" +#if defined(_MSC_VER) + "I64" +#else + "ll" +#endif + "i, time_pp=%i, time_bp=%i\n", coding_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); if (coding_type == -1) { /* nothing */ @@ -1528,14 +1438,14 @@ } else if (coding_type != B_VOP) { switch(coding_type) { case I_VOP : - decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); + decoder_iframe(dec, &bs, quant, intra_dc_threshold); break; case P_VOP : - decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, + decoder_pframe(dec, &bs, rounding, quant, fcode_forward, intra_dc_threshold, NULL); break; case S_VOP : - decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, + decoder_pframe(dec, &bs, rounding, quant, fcode_forward, intra_dc_threshold, &gmc_warp); break; case N_VOP : @@ -1546,12 +1456,6 @@ break; } - if (reduced_resolution) { - image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, - (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, - 16, 0); - } - /* 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) { @@ -1569,7 +1473,6 @@ 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; dec->frames++; @@ -1614,19 +1517,22 @@ done : - /* low_delay_default mode: if we've gotten here without outputting anything, - then output the recently decoded frame, or print an error message */ - if (dec->low_delay_default && output == 0) { - if (dec->packed_mode && seen_something) { - /* output the recently decoded frame */ + /* if we reach here without outputing anything _and_ + the calling application has specified low_delay_default, + we *must* output something. + this always occurs on the first call to decode() call + when bframes are present in the bitstream. it may also + occur if no vops were seen in the bitstream + + if packed_mode is enabled, then we output the recently + decoded frame (the very first ivop). otherwise we have + nothing to display, and therefore output a black screen. + */ + if (dec->low_delay_default && output == 0) { + if (dec->packed_mode && seen_something) { decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); - } else { + } 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, - "warning: nothing to output"); - image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, - "bframe decoder lag"); - decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant); if (stats) stats->type = XVID_TYPE_NOTHING; }