--- decoder.c 2002/06/30 10:46:29 1.23 +++ decoder.c 2002/07/15 00:26:38 1.29 @@ -32,9 +32,12 @@ * * History: * + * 10.07.2002 added BFRAMES_DEC_DEBUG support + * Fix a little bug for low_delay flage + * MinChen * 28.06.2002 added basic resync support to iframe/pframe_decode() - * 22.06.2002 added primative N_VOP support - * #define BFRAMES_DEC now enables Minchenm's bframe decoder + * 22.06.2002 added primative N_VOP support + * #define BFRAMES_DEC now enables Minchen's bframe decoder * 08.05.2002 add low_delay support for B_VOP decode * MinChen * 05.05.2002 fix some B-frame decode problem @@ -50,13 +53,17 @@ * 22.12.2001 lock based interpolation * 01.12.2001 inital version; (c)2001 peter ross * - * $Id: decoder.c,v 1.23 2002/06/30 10:46:29 suxen_drol Exp $ + * $Id: decoder.c,v 1.29 2002/07/15 00:26:38 chenm001 Exp $ * *************************************************************************/ #include #include +#ifdef BFRAMES_DEC_DEBUG + #define BFRAMES_DEC +#endif + #include "xvid.h" #include "portab.h" @@ -501,25 +508,18 @@ int low = ((-32) * scale_fac); int range = (64 * scale_fac); - VECTOR pmv[4]; - int32_t psad[4]; - + VECTOR pmv; int mv_x, mv_y; - int pmv_x, pmv_y; - - get_pmvdata2(dec->mbs, x, y, dec->mb_width, k, pmv, psad, bound); - - pmv_x = pmv[0].x; - pmv_y = pmv[0].y; + pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); mv_x = get_mv(bs, fcode); mv_y = get_mv(bs, fcode); - DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv_x, pmv_y); + DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y); - mv_x += pmv_x; - mv_y += pmv_y; + mv_x += pmv.x; + mv_y += pmv.y; if (mv_x < low) { mv_x += range; @@ -1089,6 +1089,13 @@ uint32_t x, y; VECTOR mv, zeromv; +#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->mb_type,mb->cbp); \ + } +#endif start_timer(); image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, @@ -1096,6 +1103,11 @@ //image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); 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 @@ -1104,17 +1116,19 @@ MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; - mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = - 0; + mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = 0; // the last P_VOP is skip macroblock ? if (last_mb->mode == MODE_NOT_CODED) { //DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); - mb->mb_type = MODE_FORWARD; mb->cbp = 0; +#ifdef BFRAMES_DEC_DEBUG + mb->mb_type = MODE_NOT_CODED; + BFRAME_DEBUG +#endif + mb->mb_type = MODE_FORWARD; mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; - mb->quant = 8; decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); continue; @@ -1151,6 +1165,9 @@ mb->mode = MODE_INTER; //DEBUG1("Switch bm_type=",mb->mb_type); +#ifdef BFRAMES_DEC_DEBUG + BFRAME_DEBUG +#endif switch (mb->mb_type) { case MODE_DIRECT: get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], 1, zeromv); @@ -1231,11 +1248,19 @@ break; default: - DEBUG1("Not support B-frame mb_type =", mb->mb_type); + //DEBUG1("Not support B-frame mb_type =", mb->mb_type); + ; } } // end of FOR } +#ifdef BFRAMES_DEC_DEBUG + if (!first){ + first=1; + if (fp) + fclose(fp); + } +#endif } // swap two MACROBLOCK array @@ -1313,17 +1338,24 @@ return XVID_ERR_FAIL; } +#ifdef BFRAMES_DEC_DEBUG + if (frame->length != BitstreamPos(&bs) / 8){ + DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); + } +#endif frame->length = BitstreamPos(&bs) / 8; + #ifdef BFRAMES_DEC // test if no B_VOP if (dec->low_delay) { #endif - image_output(&dec->cur, dec->width, dec->height, dec->edged_width, + image_output(&dec->cur, dec->width, dec->height, dec->edged_width, frame->image, frame->stride, frame->colorspace); + #ifdef BFRAMES_DEC } else { - if (dec->frames >= 1) { + if (dec->frames >= 0) { start_timer(); if ((vop_type == I_VOP || vop_type == P_VOP)) { image_output(&dec->refn[0], dec->width, dec->height, @@ -1343,7 +1375,7 @@ image_swap(&dec->refn[0], &dec->refn[1]); image_swap(&dec->cur, &dec->refn[0]); // swap MACROBLOCK - if (dec->low_delay && vop_type == P_VOP) + if (!dec->low_delay && vop_type == P_VOP) mb_swap(&dec->mbs, &dec->last_mbs); }