--- decoder.c 2003/10/16 12:16:00 1.49.2.17 +++ decoder.c 2003/11/30 16:13:15 1.49.2.20 @@ -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.17 2003/10/16 12:16:00 syskin Exp $ + * $Id: decoder.c,v 1.49.2.20 2003/11/30 16:13:15 edgomez Exp $ * ****************************************************************************/ @@ -41,6 +41,7 @@ #include "bitstream/mbcoding.h" #include "quant/quant.h" +#include "quant/quant_matrix.h" #include "dct/idct.h" #include "dct/fdct.h" #include "utils/mem_transfer.h" @@ -175,8 +176,15 @@ if (dec == NULL) { return XVID_ERR_MEMORY; } + memset(dec, 0, sizeof(DECODER)); + dec->mpeg_quant_matrices = xvid_malloc(sizeof(uint16_t) * 64 * 8, CACHE_LINE); + if (dec->mpeg_quant_matrices == NULL) { + xvid_free(dec); + return XVID_ERR_MEMORY; + } + create->handle = dec; dec->width = create->width; @@ -196,6 +204,7 @@ dec->last_mbs = NULL; init_timer(); + init_mpeg_matrix(dec->mpeg_quant_matrices); /* For B-frame support (used to save reference frame's time */ dec->frames = 0; @@ -226,6 +235,7 @@ image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); image_destroy(&dec->cur, dec->edged_width, dec->edged_height); + xvid_free(dec->mpeg_quant_matrices); xvid_free(dec); write_timer(); @@ -321,9 +331,9 @@ start_timer(); if (dec->quant_type == 0) { - dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); + dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices); } else { - dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); + dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, dec->mpeg_quant_matrices); } stop_iquant_timer(); @@ -373,7 +383,8 @@ 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, next_block = stride * (reduced_resolution ? 16 : 8); + int stride = dec->edged_width; + int next_block = stride * (reduced_resolution ? 16 : 8); const int stride2 = stride/2; int i; const uint32_t iQuant = pMB->quant; @@ -391,7 +402,7 @@ stop_coding_timer(); start_timer(); - dequant(&data[i * 64], block, iQuant); + dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices); stop_iquant_timer(); start_timer(); @@ -450,7 +461,6 @@ { uint32_t stride = dec->edged_width; uint32_t stride2 = stride / 2; - uint32_t next_block = stride * (reduced_resolution ? 16 : 8); uint32_t i; uint8_t *pY_Cur, *pU_Cur, *pV_Cur; @@ -963,7 +973,6 @@ { uint32_t stride = dec->edged_width; uint32_t stride2 = stride / 2; - uint32_t next_block = stride * 8; int uv_dx, uv_dy; int b_uv_dx, b_uv_dy; uint8_t *pY_Cur, *pU_Cur, *pV_Cur; @@ -1165,15 +1174,6 @@ const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; int i; -#ifdef BFRAMES_DEC_DEBUG - 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->mode,mb->cbp); \ - } -#endif - start_timer(); image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, dec->width, dec->height); @@ -1181,18 +1181,23 @@ dec->width, dec->height); stop_edges_timer(); -#ifdef BFRAMES_DEC_DEBUG - if (!first){ - fp=fopen("C:\\XVIDDBG.TXT","w"); - } -#endif - for (y = 0; y < dec->mb_height; y++) { /* Initialize Pred Motion Vector */ dec->p_fmv = dec->p_bmv = zeromv; for (x = 0; x < dec->mb_width; x++) { MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; + const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward; + uint32_t intra_dc_threshold; /* fake variable */ + + if (check_resync_marker(bs, fcode_max - 1)) { + int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant, + &fcode_forward, &fcode_backward, &intra_dc_threshold); + x = bound % dec->mb_width; + y = bound / dec->mb_width; + /* reset predicted macroblocks */ + dec->p_fmv = dec->p_bmv = zeromv; + } mv = mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = @@ -1305,14 +1310,6 @@ } } /* End of for */ } - -#ifdef BFRAMES_DEC_DEBUG - if (!first){ - first=1; - if (fp) - fclose(fp); - } -#endif } /* perform post processing if necessary, and output the image */