--- decoder.c 2002/07/21 23:34:07 1.33 +++ decoder.c 2002/09/24 21:56:27 1.40 @@ -53,9 +53,9 @@ * 26.03.2002 interlacing support - moved transfers outside decode loop * 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block * 22.12.2001 lock based interpolation - * 01.12.2001 inital version; (c)2001 peter ross + * 01.12.2001 inital version; (c)2001 peter ross * - * $Id: decoder.c,v 1.33 2002/07/21 23:34:07 chl Exp $ + * $Id: decoder.c,v 1.40 2002/09/24 21:56:27 edgomez Exp $ * *************************************************************************/ @@ -348,36 +348,58 @@ uv_dx = pMB->mvs[0].x; uv_dy = pMB->mvs[0].y; + if (dec->quarterpel) + { + uv_dx = (uv_dx >> 1) | (uv_dx & 1); + uv_dy = (uv_dy >> 1) | (uv_dy & 1); + } + uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; } else { int sum; - sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; - uv_dx = - (sum == - 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + - (ABS(sum) / 16) * 2)); + + if (dec->quarterpel) + { + sum /= 2; + } + + uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; - uv_dy = - (sum == - 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + - (ABS(sum) / 16) * 2)); + + if (dec->quarterpel) + { + sum /= 2; + } + + uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); } start_timer(); - interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos, - pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); - interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, - 16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, - rounding); - interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, - 16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, - rounding); - interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, - 16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, - rounding); + if(dec->quarterpel) { + DPRINTF(DPRINTF_DEBUG, "QUARTERPEL\n"); + interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, + pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); + interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, + pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); + interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, + pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); + interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, + pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); + } + else { + interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, + pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); + interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, + pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); + interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, + pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); + interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, + pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); + } + interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, uv_dx, uv_dy, stride2, rounding); interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, @@ -487,7 +509,7 @@ if (dec->interlacing) { mb->field_dct = BitstreamGetBit(bs); - DEBUG1("deci: field_dct: ", mb->field_dct); + DPRINTF(DPRINTF_DEBUG, "deci: field_dct: %d", mb->field_dct); } decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, @@ -631,18 +653,20 @@ mb->quant = quant; if (dec->interlacing) { - mb->field_dct = BitstreamGetBit(bs); - DEBUG1("decp: field_dct: ", mb->field_dct); + if (cbp || intra) { + mb->field_dct = BitstreamGetBit(bs); + DPRINTF(DPRINTF_DEBUG, "decp: field_dct: %d", mb->field_dct); + } if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { mb->field_pred = BitstreamGetBit(bs); - DEBUG1("decp: field_pred: ", mb->field_pred); + DPRINTF(DPRINTF_DEBUG, "decp: field_pred: %d", mb->field_pred); if (mb->field_pred) { mb->field_for_top = BitstreamGetBit(bs); - DEBUG1("decp: field_for_top: ", mb->field_for_top); + DPRINTF(DPRINTF_DEBUG, "decp: field_for_top: %d", mb->field_for_top); mb->field_for_bot = BitstreamGetBit(bs); - DEBUG1("decp: field_for_bot: ", mb->field_for_bot); + DPRINTF(DPRINTF_DEBUG, "decp: field_for_bot: %d", mb->field_for_bot); } } } @@ -661,8 +685,8 @@ mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; } - } else if (mb->mode == - MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) { + } else if (mb->mode == MODE_INTER4V ) { + get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); @@ -682,7 +706,8 @@ rounding); } else // not coded { - //DEBUG2("P-frame MB at (X,Y)=",x,y); + DPRINTF(DPRINTF_DEBUG, "P-frame MB at (X,Y)=(%d,%d)", x, y); + mb->mode = MODE_NOT_CODED; 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; @@ -1254,18 +1279,9 @@ break; default: - DEBUG1("Not support B-frame mb_type =", mb->mb_type); - ; - } - - if ( (x==19) && (y==8) ) - { - fprintf(stderr,"D %d %d %d %d %d %d \n",0, mb->mb_type, - mb->mvs[0].x, mb->mvs[0].y,mb->b_mvs[0].x, mb->b_mvs[0].y ); + DPRINTF(DPRINTF_ERROR, "Not support B-frame mb_type = %d", mb->mb_type); } - - } // end of FOR } #ifdef BFRAMES_DEC_DEBUG @@ -1321,24 +1337,24 @@ decoder_pframe(dec, &bs, rounding, quant, fcode_forward, intra_dc_threshold); #ifdef BFRAMES_DEC - DEBUG1("P_VOP Time=", dec->time); + DPRINTF(DPRINTF_DEBUG, "P_VOP Time=%d", dec->time); #endif break; case I_VOP: decoder_iframe(dec, &bs, quant, intra_dc_threshold); #ifdef BFRAMES_DEC - DEBUG1("I_VOP Time=", dec->time); + DPRINTF(DPRINTF_DEBUG, "I_VOP Time=%d", dec->time); #endif break; case B_VOP: #ifdef BFRAMES_DEC if (dec->time_pp > dec->time_bp) { - DEBUG1("B_VOP Time=", dec->time); + DPRINTF(DPRINTF_DEBUG, "B_VOP Time=%d", dec->time); decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); } else { - DEBUG("broken B-frame!"); + DPRINTF(DPRINTF_DEBUG, "Broken B_VOP"); } #else image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); @@ -1356,7 +1372,7 @@ #ifdef BFRAMES_DEC_DEBUG if (frame->length != BitstreamPos(&bs) / 8){ - DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); + DPRINTF(DPRINTF_DEBUG, "InLen: %d / UseLen: %d", frame->length, BitstreamPos(&bs) / 8); } #endif frame->length = BitstreamPos(&bs) / 8; @@ -1364,14 +1380,14 @@ #ifdef BFRAMES_DEC // test if no B_VOP - if (dec->low_delay) { + if (dec->low_delay || dec->frames == 0) { #endif image_output(&dec->cur, dec->width, dec->height, dec->edged_width, frame->image, frame->stride, frame->colorspace); #ifdef BFRAMES_DEC } else { - if (dec->frames >= 0) { + if (dec->frames >= 1) { start_timer(); if ((vop_type == I_VOP || vop_type == P_VOP)) { image_output(&dec->refn[0], dec->width, dec->height,