--- decoder.c 2002/10/11 15:07:32 1.37.2.5 +++ decoder.c 2002/09/21 03:07:56 1.38 @@ -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.37.2.5 2002/10/11 15:07:32 Isibaar Exp $ + * $Id: decoder.c,v 1.38 2002/09/21 03:07:56 suxen_drol Exp $ * *************************************************************************/ @@ -136,15 +136,6 @@ return XVID_ERR_MEMORY; } - if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { - image_destroy(&dec->cur, dec->edged_width, dec->edged_height); - image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); - image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); - image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); - xvid_free(dec); - return XVID_ERR_MEMORY; - } - dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE); @@ -153,7 +144,6 @@ image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); - image_destroy(&dec->refh, dec->edged_width, dec->edged_height); xvid_free(dec); return XVID_ERR_MEMORY; } @@ -171,7 +161,6 @@ image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); - image_destroy(&dec->refh, dec->edged_width, dec->edged_height); xvid_free(dec); return XVID_ERR_MEMORY; } @@ -197,7 +186,6 @@ image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); - image_destroy(&dec->refh, dec->edged_width, dec->edged_height); image_destroy(&dec->cur, dec->edged_width, dec->edged_height); xvid_free(dec); @@ -280,10 +268,8 @@ start_timer(); if (cbp & (1 << (5 - i))) // coded { - int direction = dec->alternate_vertical_scan ? - 2 : pMB->acpred_directions[i]; - - get_intra_block(bs, &block[i * 64], direction, start_coeff); + get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i], + start_coeff); } stop_coding_timer(); @@ -370,30 +356,6 @@ uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; - - start_timer(); - if(dec->quarterpel) { - interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, - dec->refh.y + 128, 16*x_pos, 16*y_pos, - pMB->mvs[0].x, pMB->mvs[0].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, - uv_dx, uv_dy, stride2, rounding); - stop_comp_timer(); - } else { int sum; sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; @@ -413,49 +375,44 @@ } uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); + } - start_timer(); - if(dec->quarterpel) { - interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, - dec->refh.y + 128, 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, dec->refh.y, dec->refh.y + 64, - dec->refh.y + 128, 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, dec->refh.y, dec->refh.y + 64, - dec->refh.y + 128, 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, dec->refh.y, dec->refh.y + 64, - dec->refh.y + 128, 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, + start_timer(); + if(dec->quarterpel) { + DEBUG("QUARTERPEL"); + 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_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, + 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_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, + 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_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, + 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); - } - - 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, - uv_dx, uv_dy, stride2, rounding); - stop_comp_timer(); + } + 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); } - for (i = 0; i < 6; i++) { - int direction = dec->alternate_vertical_scan ? 2 : 0; + 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, + uv_dx, uv_dy, stride2, rounding); + stop_comp_timer(); + for (i = 0; i < 6; i++) { if (cbp & (1 << (5 - i))) // coded { memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear start_timer(); - get_inter_block(bs, &block[i * 64], direction); + get_inter_block(bs, &block[i * 64]); stop_coding_timer(); start_timer(); @@ -628,7 +585,7 @@ start_timer(); image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height); + dec->width, dec->height, dec->interlacing); stop_edges_timer(); bound = 0; @@ -749,6 +706,7 @@ rounding); } else // not coded { + DEBUG2("P-frame MB at (X,Y)=",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; @@ -918,14 +876,12 @@ stop_comp_timer(); for (i = 0; i < 6; i++) { - int direction = dec->alternate_vertical_scan ? 2 : 0; - if (cbp & (1 << (5 - i))) // coded { memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear start_timer(); - get_inter_block(bs, &block[i * 64], direction); + get_inter_block(bs, &block[i * 64]); stop_coding_timer(); start_timer(); @@ -963,6 +919,7 @@ stop_transfer_timer(); } + // add by MinChen // decode an B-frame direct & inter macroblock void @@ -1070,47 +1027,27 @@ interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, b_uv_dx, b_uv_dy, stride2, 0); - interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, - dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, - dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, - stride, 0); - - interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, - dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, - dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, - stride, 0); - - interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, - dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, - dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, - stride, 0); - - interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, - dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, - dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, - stride, 0); - - interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, - dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, - dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, - stride2, 0); - - interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, - dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, - dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, - stride2, 0); - + interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos, + stride); + interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos, + stride); + interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8, + stride); + interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, + 16 * y_pos + 8, stride); + interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos, + stride2); + interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos, + stride2); stop_comp_timer(); for (i = 0; i < 6; i++) { - int direction = dec->alternate_vertical_scan ? 2 : 0; - if (cbp & (1 << (5 - i))) // coded { memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear start_timer(); - get_inter_block(bs, &block[i * 64], direction); + get_inter_block(bs, &block[i * 64]); stop_coding_timer(); start_timer(); @@ -1205,9 +1142,9 @@ start_timer(); image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, - dec->width, dec->height); + dec->width, dec->height, dec->interlacing); image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, - dec->width, dec->height); + dec->width, dec->height, dec->interlacing); stop_edges_timer(); #ifdef BFRAMES_DEC_DEBUG @@ -1385,9 +1322,6 @@ BitstreamInit(&bs, frame->bitstream, frame->length); - if(BitstreamShowBits(&bs, 8) == 0x7f) - return XVID_ERR_OK; - // add by chenm001 // for support B-frame to reference last 2 frame dec->frames++; @@ -1429,9 +1363,6 @@ case N_VOP: // vop not coded // when low_delay==0, N_VOP's should interpolate between the past and future frames image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); -#ifdef BFRAMES_DEC - DEBUG1("N_VOP Time=", dec->time); -#endif break; default: