--- decoder.c 2003/03/26 10:29:51 1.49.2.3 +++ decoder.c 2003/10/14 14:22:45 1.49.2.16 @@ -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.16 2003/10/14 14:22:45 syskin Exp $ * ****************************************************************************/ @@ -39,8 +40,7 @@ #include "bitstream/bitstream.h" #include "bitstream/mbcoding.h" -#include "quant/quant_h263.h" -#include "quant/quant_mpeg4.h" +#include "quant/quant.h" #include "dct/idct.h" #include "dct/fdct.h" #include "utils/mem_transfer.h" @@ -53,6 +53,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" @@ -70,7 +71,7 @@ image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); - if (dec->last_mbs) + if (dec->last_mbs) xvid_free(dec->last_mbs); if (dec->mbs) xvid_free(dec->mbs); @@ -167,7 +168,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); @@ -207,7 +208,7 @@ if (dec->fixed_dimensions) return decoder_resize(dec); else - return 0; + return 0; } @@ -304,7 +305,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; } @@ -325,9 +326,9 @@ start_timer(); if (dec->quant_type == 0) { - dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); + dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); } else { - dequant4_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); + dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); } stop_iquant_timer(); @@ -409,12 +410,12 @@ for (i = 0; i < 4; i++) mv[i] = pMB->mvs[i]; } - + if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { uv_dx = mv[0].x / (1 + dec->quarterpel); uv_dy = mv[0].y / (1 + dec->quarterpel); - + uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; @@ -450,7 +451,7 @@ } else { /* MODE_INTER4V */ int sum; - + if(dec->quarterpel) sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2); else @@ -474,7 +475,7 @@ 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, + 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); @@ -482,7 +483,7 @@ uv_dx, uv_dy, stride2, rounding); /* set_block(pY_Cur, stride, 32, 32, 127); */ - } + } else { if(dec->quarterpel) { @@ -506,7 +507,7 @@ mv[1].x, mv[1].y, stride, rounding); interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos + 8, mv[2].x, mv[2].y, stride, rounding); - interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos + 8, + interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos + 8, mv[3].x, mv[3].y, stride, rounding); } @@ -531,9 +532,9 @@ start_timer(); if (dec->quant_type == 0) { - dequant_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); } else { - dequant4_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); } stop_iquant_timer(); @@ -582,19 +583,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, @@ -624,18 +612,27 @@ pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; start_timer(); - + /* 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); } pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; - + /* transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos << 3), stride2); @@ -644,7 +641,7 @@ stop_transfer_timer(); - + if (!cbp) return; for (i = 0; i < 6; i++) { @@ -660,9 +657,9 @@ start_timer(); if (dec->quant_type == 0) { - dequant_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); } else { - dequant4_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); } stop_iquant_timer(); @@ -707,7 +704,7 @@ 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; @@ -730,14 +727,14 @@ if (check_resync_marker(bs, 0)) { - bound = read_video_packet_header(bs, dec, 0, + bound = read_video_packet_header(bs, dec, 0, &quant, NULL, NULL, &intra_dc_threshold); x = bound % mb_width; y = bound / mb_width; } 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 +761,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 +799,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; @@ -844,7 +841,7 @@ 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; @@ -857,28 +854,20 @@ stop_edges_timer(); if (gmc_warp) - { + { /* 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); + }*/ -/* 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); -*/ + generate_GMCparameters( dec->sprite_warping_points, + dec->sprite_warping_accuracy, gmc_warp, + dec->width, dec->height, &dec->new_gmc_data); + +/* image warping is done block-based in decoder_mbgmc(), now */ } bound = 0; @@ -894,14 +883,14 @@ if (check_resync_marker(bs, fcode - 1)) { - bound = read_video_packet_header(bs, dec, fcode - 1, + bound = read_video_packet_header(bs, dec, fcode - 1, &quant, &fcode, NULL, &intra_dc_threshold); x = bound % mb_width; y = bound / mb_width; } 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 */ @@ -918,59 +907,56 @@ mcbpc = get_mcbpc_inter(bs); 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); - if (intra) { - acpred_flag = BitstreamGetBit(bs); - } - if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) - { mcsel = BitstreamGetBit(bs); - } + + if (intra) + acpred_flag = BitstreamGetBit(bs); 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) { + if ((cbp || intra) && !mcsel) { 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); } } } - + if (mcsel) { decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant, rounding, reduced_resolution); @@ -1039,7 +1025,7 @@ if (reduced_resolution) { transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x), - dec->refn[0].y + (32*y)*dec->edged_width + (32*x), + dec->refn[0].y + (32*y)*dec->edged_width + (32*x), dec->edged_width); transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x), @@ -1053,7 +1039,7 @@ else { transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), - dec->refn[0].y + (16*y)*dec->edged_width + (16*x), + dec->refn[0].y + (16*y)*dec->edged_width + (16*x), dec->edged_width); transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), @@ -1064,7 +1050,7 @@ dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x), dec->edged_width/2); } - + stop_transfer_timer(); if(dec->out_frm && cp_mb > 0) { @@ -1152,51 +1138,31 @@ pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); - if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { - uv_dx = pMB->mvs[0].x; - uv_dy = pMB->mvs[0].y; + uv_dx = pMB->mvs[0].x; + uv_dy = pMB->mvs[0].y; - if (dec->quarterpel) - { + if (dec->quarterpel) { uv_dx /= 2; uv_dy /= 2; - } - - uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; - uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; - } else { - int sum; - - if(dec->quarterpel) - sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); - else - sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; - - uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; - - if(dec->quarterpel) - sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); - else - sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; - - uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; } + uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; + uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; + start_timer(); 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, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); - } - else { + } else { interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos, - pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); + pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8, - pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); - interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8, - pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); + pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); + interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8, + pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); } interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, @@ -1208,8 +1174,8 @@ for (i = 0; i < 6; i++) { int direction = dec->alternate_vertical_scan ? 2 : 0; - if (cbp & (1 << (5 - i))) /* coded */ - { + if (cbp & (1 << (5 - i))) { /* coded */ + memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ start_timer(); @@ -1217,11 +1183,11 @@ stop_coding_timer(); start_timer(); - if (dec->quant_type == 0) { - dequant_inter(&data[i * 64], &block[i * 64], iQuant); - } else { - dequant4_inter(&data[i * 64], &block[i * 64], iQuant); - } + if (dec->quant_type == 0) + dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); + else + dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); + stop_iquant_timer(); start_timer(); @@ -1251,7 +1217,7 @@ stop_transfer_timer(); } -/* decode an B-frame direct & inter macroblock */ +/* decode an B-frame direct & interpolate macroblock */ void decoder_bf_interpolate_mbinter(DECODER * dec, IMAGE forward, @@ -1259,7 +1225,8 @@ const MACROBLOCK * pMB, const uint32_t x_pos, const uint32_t y_pos, - Bitstream * bs) + Bitstream * bs, + const int direct) { DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); @@ -1280,7 +1247,7 @@ pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); - if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { + if (!direct) { uv_dx = pMB->mvs[0].x; uv_dy = pMB->mvs[0].y; @@ -1337,7 +1304,7 @@ start_timer(); if(dec->quarterpel) { - if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) + if(!direct) interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, dec->qtmp.y + 128, 16*x_pos, 16*y_pos, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); @@ -1375,7 +1342,7 @@ if(dec->quarterpel) { - if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) + 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); @@ -1448,8 +1415,7 @@ for (i = 0; i < 6; i++) { int direction = dec->alternate_vertical_scan ? 2 : 0; - if (cbp & (1 << (5 - i))) /* coded */ - { + if (cbp & (1 << (5 - i))) { /* coded */ memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ start_timer(); @@ -1458,9 +1424,9 @@ start_timer(); if (dec->quant_type == 0) { - dequant_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); } else { - dequant4_inter(&data[i * 64], &block[i * 64], iQuant); + dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); } stop_iquant_timer(); @@ -1542,7 +1508,7 @@ FILE *fp; static char first=0; #define BFRAME_DEBUG if (!first && fp){ \ - fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \ + fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ } #endif @@ -1571,7 +1537,7 @@ mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; /* - * skip if the co-located P_VOP macroblock is not coded + * skip if the co-located P_VOP macroblock is not coded * if not codec in co-located S_VOP macroblock is _not_ * automatically skipped */ @@ -1579,11 +1545,7 @@ if (last_mb->mode == MODE_NOT_CODED) { /* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ mb->cbp = 0; -#ifdef BFRAMES_DEC_DEBUG - mb->mb_type = MODE_NOT_CODED; - BFRAME_DEBUG -#endif - mb->mb_type = MODE_FORWARD; + mb->mode = MODE_FORWARD; mb->quant = last_mb->quant; /* mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; @@ -1597,14 +1559,14 @@ if (!BitstreamGetBit(bs)) { /* modb=='0' */ const uint8_t modb2 = BitstreamGetBit(bs); - mb->mb_type = get_mbtype(bs); + mb->mode = get_mbtype(bs); if (!modb2) { /* modb=='00' */ mb->cbp = BitstreamGetBits(bs, 6); } else { mb->cbp = 0; } - if (mb->mb_type && mb->cbp) { + if (mb->mode && mb->cbp) { quant += get_dbquant(bs); if (quant > 31) { @@ -1613,25 +1575,44 @@ quant = 1; } } + + if (dec->interlacing) { + if (mb->cbp) { + mb->field_dct = BitstreamGetBit(bs); + DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); + } + + if (mb->mode) { + mb->field_pred = BitstreamGetBit(bs); + DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); + + if (mb->field_pred) { + mb->field_for_top = BitstreamGetBit(bs); + DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); + mb->field_for_bot = BitstreamGetBit(bs); + DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); + } + } + } + } else { - mb->mb_type = MODE_DIRECT_NONE_MV; + mb->mode = MODE_DIRECT_NONE_MV; mb->cbp = 0; } mb->quant = quant; - mb->mode = MODE_INTER4V; - /* DEBUG1("Switch bm_type=",mb->mb_type); */ + /* DEBUG1("Switch bm_type=",mb->mode); */ #ifdef BFRAMES_DEC_DEBUG BFRAME_DEBUG #endif - switch (mb->mb_type) { + switch (mb->mode) { case MODE_DIRECT: get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); case MODE_DIRECT_NONE_MV: - { + { const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; int i; @@ -1652,7 +1633,7 @@ /* DEBUG("B-frame Direct!\n"); */ } decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], - mb, x, y, bs); + mb, x, y, bs, 1); break; case MODE_INTERPOLATE: @@ -1666,7 +1647,7 @@ mb->b_mvs[3] = mb->b_mvs[0]; decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], - mb, x, y, bs); + mb, x, y, bs, 0); /* DEBUG("B-frame Bidir!\n"); */ break; @@ -1675,7 +1656,6 @@ dec->p_bmv); dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; - mb->mode = MODE_INTER; decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); /* DEBUG("B-frame Backward!\n"); */ break; @@ -1685,13 +1665,12 @@ dec->p_fmv); dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; - mb->mode = MODE_INTER; decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); /* DEBUG("B-frame Forward!\n"); */ break; default: - DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); + DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode); } } /* End of for */ } @@ -1708,7 +1687,7 @@ /* perform post processing if necessary, and output the image */ -void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, +void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) { @@ -1721,7 +1700,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 */ } } @@ -1742,7 +1721,7 @@ int coding_type; int success, output, seen_something; - 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(); @@ -1789,10 +1768,10 @@ repeat: - coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, + 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 */ @@ -1807,7 +1786,7 @@ { if (coding_type == -3) decoder_resize(dec); - + if (stats) { stats->type = XVID_TYPE_VOL; @@ -1823,11 +1802,10 @@ return BitstreamPos(&bs)/8; /* number of bytes consumed */ } 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) { @@ -1846,16 +1824,16 @@ decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); break; case P_VOP : - decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, + decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, fcode_forward, intra_dc_threshold, NULL); break; case S_VOP : - decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, + decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, 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 +1874,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; } @@ -1906,7 +1884,7 @@ image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, "broken b-frame, mising ref frames"); }else if (dec->time_pp <= dec->time_bp) { - /* this occurs when dx50_bvop_compatibility==0 sequences are + /* 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); @@ -1947,7 +1925,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); if (stats) stats->type = XVID_TYPE_NOTHING; }