--- decoder.c 2003/03/26 10:29:51 1.49.2.3 +++ decoder.c 2003/08/02 15:08:12 1.49.2.10 @@ -3,23 +3,24 @@ * XVID MPEG-4 VIDEO CODEC * - Decoder Module - * - * This file is part of XviD, a free MPEG-4 video encoder/decoder + * Copyright(C) 2002 MinChen + * 2002-2003 Peter Ross * - * This program is free software; you can redistribute it and/or modify + * 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 - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation ; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of + * but WITHOUT ANY WARRANTY ; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * 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.3 2003/03/26 10:29:51 suxen_drol Exp $ + * $Id: decoder.c,v 1.49.2.10 2003/08/02 15:08:12 edgomez Exp $ * ****************************************************************************/ @@ -53,6 +54,7 @@ #include "utils/timer.h" #include "utils/emms.h" #include "motion/motion.h" +#include "motion/gmc.h" #include "image/image.h" #include "image/colorspace.h" @@ -167,7 +169,7 @@ { DECODER *dec; - if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ + if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ return XVID_ERR_VERSION; dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); @@ -304,7 +306,7 @@ block[i * 64 + 0] = dc_dif; start_coeff = 1; - DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif); + DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif); } else { start_coeff = 0; } @@ -582,19 +584,6 @@ stop_transfer_timer(); } -static __inline int gmc_sanitize(int value, int quarterpel, int fcode) -{ - int length = 1 << (fcode+4); - -/* if (quarterpel) value *= 2; */ - - if (value < -length) - return -length; - else if (value >= length) - return length-1; - else return value; -} - static void decoder_mbgmc(DECODER * dec, @@ -627,9 +616,18 @@ /* this is where the calculations are done */ - { - pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos, - stride, stride2, dec->quarterpel, rounding, &dec->cur); + { NEW_GMC_DATA * gmc_data = &dec->new_gmc_data; + + gmc_data->predict_16x16(gmc_data, + dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y, + stride, stride, x_pos, y_pos, rounding); + + gmc_data->predict_8x8(gmc_data, + dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u, + dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v, + stride2, stride2, x_pos, y_pos, rounding); + + gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel); pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); @@ -737,7 +735,7 @@ } mb = &dec->mbs[y * dec->mb_width + x]; - DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); + DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); mcbpc = get_mcbpc_intra(bs); mb->mode = mcbpc & 7; @@ -764,7 +762,7 @@ if (dec->interlacing) { mb->field_dct = BitstreamGetBit(bs); - DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); + DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct); } decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, @@ -802,7 +800,7 @@ mv.x = get_mv(bs, fcode); mv.y = get_mv(bs, fcode); - DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); + DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); mv.x += pmv.x; mv.y += pmv.y; @@ -860,25 +858,17 @@ { /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ - if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) - { - fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", +/* { + fprintf(stderr,"GMC parameters acc=%d(-> 1/%d), %d pts!!!\n", dec->sprite_warping_accuracy,(2<sprite_warping_accuracy), dec->sprite_warping_points); - } - + }*/ + generate_GMCparameters( dec->sprite_warping_points, - (2 << dec->sprite_warping_accuracy), gmc_warp, - dec->width, dec->height, &dec->gmc_data); + dec->sprite_warping_accuracy, gmc_warp, + dec->width, dec->height, &dec->new_gmc_data); /* image warping is done block-based in decoder_mbgmc(), now */ -/* - generate_GMCimage(&dec->gmc_data, &dec->refn[0], - mb_width, mb_height, - dec->edged_width, dec->edged_width/2, - fcode, dec->quarterpel, 0, - rounding, dec->mbs, &dec->gmc); -*/ } bound = 0; @@ -901,7 +891,7 @@ } mb = &dec->mbs[y * dec->mb_width + x]; - DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); + DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); /* if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) */ /* not_coded */ if (!(BitstreamGetBit(bs))) /* block _is_ coded */ @@ -919,8 +909,8 @@ mb->mode = mcbpc & 7; cbpc = (mcbpc >> 4); - DPRINTF(DPRINTF_MB, "mode %i", mb->mode); - DPRINTF(DPRINTF_MB, "cbpc %i", cbpc); + DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode); + DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc); acpred_flag = 0; intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); @@ -935,38 +925,38 @@ } cbpy = get_cbpy(bs, intra); - DPRINTF(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); + DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); cbp = (cbpy << 2) | cbpc; if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { int dquant = dquant_table[BitstreamGetBits(bs, 2)]; - DPRINTF(DPRINTF_MB, "dquant %i", dquant); + DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant); quant += dquant; if (quant > 31) { quant = 31; } else if (quant < 1) { quant = 1; } - DPRINTF(DPRINTF_MB, "quant %i", quant); + DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant); } mb->quant = quant; if (dec->interlacing) { if (cbp || intra) { mb->field_dct = BitstreamGetBit(bs); - DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); + DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); } if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { mb->field_pred = BitstreamGetBit(bs); - DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); + DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); if (mb->field_pred) { mb->field_for_top = BitstreamGetBit(bs); - DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); + DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); mb->field_for_bot = BitstreamGetBit(bs); - DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); + DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); } } } @@ -1691,7 +1681,7 @@ break; default: - DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); + DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", mb->mb_type); } } /* End of for */ } @@ -1721,7 +1711,7 @@ { 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.time_increment = 0; /* XXX: todo */ } } @@ -1741,8 +1731,9 @@ WARPPOINTS gmc_warp; int coding_type; int success, output, seen_something; + idctFuncPtr idct_save; - if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ + if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ return XVID_ERR_VERSION; start_global_timer(); @@ -1786,13 +1777,14 @@ success = 0; output = 0; seen_something = 0; + idct_save = idct; repeat: coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); - DPRINTF(DPRINTF_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i", + DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, 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 */ @@ -1827,6 +1819,14 @@ dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; /* init pred vector to 0 */ +#if defined(ARCH_IS_IA32) + /* + * /!\ Ugly hack /!\ + * IA32: Prior to xvid bitstream 10, we were using Walten's mmx/xmm idct + */ + if((idct == simple_idct_mmx) && (dec->bs_version < 10)) + idct = idct_mmx; +#endif /* packed_mode: special-N_VOP treament */ if (dec->packed_mode && coding_type == N_VOP) @@ -1854,8 +1854,8 @@ fcode_forward, intra_dc_threshold, &gmc_warp); break; case N_VOP : - // XXX: not_coded vops are not used for forward prediction - // we should not swap(last_mbs,mbs) + /* XXX: not_coded vops are not used for forward prediction */ + /* we should not swap(last_mbs,mbs) */ image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); break; } @@ -1896,7 +1896,7 @@ if (dec->low_delay) { - DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); + DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); dec->low_delay = 1; } @@ -1956,5 +1956,7 @@ emms(); stop_global_timer(); + idct = idct_save; + return BitstreamPos(&bs) / 8; /* number of bytes consumed */ }