--- decoder.c 2004/08/10 21:58:55 1.65 +++ decoder.c 2004/12/05 13:56:13 1.68 @@ -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.65 2004/08/10 21:58:55 edgomez Exp $ + * $Id: decoder.c,v 1.68 2004/12/05 13:56:13 syskin Exp $ * ****************************************************************************/ @@ -46,7 +46,6 @@ #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" @@ -271,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); @@ -285,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 */ @@ -363,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(); } @@ -391,13 +371,12 @@ uint8_t * pY_Cur, uint8_t * pU_Cur, uint8_t * pV_Cur, - int reduced_resolution, const MACROBLOCK * pMB) { DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE); int stride = dec->edged_width; - int next_block = stride * (reduced_resolution ? 16 : 8); + int next_block = stride * 8; int i; const uint32_t iQuant = pMB->quant; const int direction = dec->alternate_vertical_scan ? 2 : 0; @@ -416,10 +395,6 @@ ? (get_inter_block_function_t)get_inter_block_h263 : (get_inter_block_function_t)get_inter_block_mpeg; - const add_residual_function_t add_residual = (reduced_resolution) - ? (add_residual_function_t)add_upsampled_8x8_16to8 - : (add_residual_function_t)transfer_16to8add; - uint8_t *dst[6]; int strides[6]; @@ -429,11 +404,10 @@ stride *= 2; } - reduced_resolution = !!reduced_resolution; dst[0] = pY_Cur; dst[2] = pY_Cur + next_block; - dst[1] = dst[0] + (8<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 */ static void decoder_mbinter(DECODER * dec, @@ -474,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; @@ -486,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]; - } - - 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; - } - } + 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]; - 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(); @@ -542,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); @@ -566,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); @@ -606,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 @@ -669,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); } @@ -677,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; @@ -745,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) @@ -803,7 +746,6 @@ decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, - int reduced_resolution, int quant, int fcode, int intra_dc_threshold, @@ -812,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(); @@ -937,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; @@ -962,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); @@ -1017,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, @@ -1034,6 +970,9 @@ 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; @@ -1146,7 +1085,7 @@ 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 */ @@ -1241,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; } @@ -1324,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: @@ -1381,7 +1320,6 @@ } } - int decoder_decode(DECODER * dec, xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) @@ -1389,7 +1327,6 @@ Bitstream bs; uint32_t rounding; - uint32_t reduced_resolution; uint32_t quant = 2; uint32_t fcode_forward; uint32_t fcode_backward; @@ -1444,7 +1381,7 @@ 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", @@ -1495,14 +1432,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 : @@ -1513,12 +1450,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) { @@ -1536,7 +1467,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++;