--- decoder.c 2002/06/14 13:21:13 1.20 +++ decoder.c 2002/06/28 15:14:40 1.22 @@ -32,6 +32,9 @@ * * History: * + * 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 * 08.05.2002 add low_delay support for B_VOP decode * MinChen * 05.05.2002 fix some B-frame decode problem @@ -47,7 +50,7 @@ * 22.12.2001 lock based interpolation * 01.12.2001 inital version; (c)2001 peter ross * - * $Id: decoder.c,v 1.20 2002/06/14 13:21:13 Isibaar Exp $ + * $Id: decoder.c,v 1.22 2002/06/28 15:14:40 suxen_drol Exp $ * *************************************************************************/ @@ -201,7 +204,9 @@ const uint32_t cbp, Bitstream * bs, const uint32_t quant, - const uint32_t intra_dc_threshold) + const uint32_t intra_dc_threshold, + const unsigned int bound_x, + const unsigned int bound_y) { DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); @@ -227,7 +232,7 @@ start_timer(); predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], - iQuant, iDcScaler, predictors); + iQuant, iDcScaler, predictors, bound_x, bound_y); if (!acpred_flag) { pMB->acpred_directions[i] = 0; } @@ -420,12 +425,14 @@ int quant, int intra_dc_threshold) { - + uint32_t bound_x, bound_y; uint32_t x, y; + bound_x = bound_y = 0; + for (y = 0; y < dec->mb_height; y++) { for (x = 0; x < dec->mb_width; x++) { - MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; + MACROBLOCK *mb; uint32_t mcbpc; uint32_t cbpc; @@ -433,17 +440,22 @@ uint32_t cbpy; uint32_t cbp; + skip_stuffing(bs); + if (check_resync_marker(bs, 0)) + { + int mbnum = read_video_packet_header(bs, 0); + x = bound_x = mbnum % dec->mb_width; + y = bound_y = mbnum / dec->mb_width; + } + + mb = &dec->mbs[y * dec->mb_width + x]; + mcbpc = get_mcbpc_intra(bs); mb->mode = mcbpc & 7; cbpc = (mcbpc >> 4); acpred_flag = BitstreamGetBit(bs); - if (mb->mode == MODE_STUFFING) { - DEBUG("-- STUFFING ?"); - continue; - } - cbpy = get_cbpy(bs, 1); cbp = (cbpy << 2) | cbpc; @@ -463,7 +475,7 @@ } decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, - intra_dc_threshold); + intra_dc_threshold, bound_x, bound_y); } } @@ -477,7 +489,9 @@ int y, int k, VECTOR * mv, - int fcode) + int fcode, + const int bound_x, + const int bound_y) { int scale_fac = 1 << (fcode - 1); @@ -492,7 +506,7 @@ int pmv_x, pmv_y; - get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad); + get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad, bound_x, bound_y); pmv_x = pmv[0].x; pmv_y = pmv[0].y; @@ -531,15 +545,27 @@ { uint32_t x, y; + uint32_t bound_x, bound_y; start_timer(); image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); stop_edges_timer(); + bound_x = bound_y = 0; + for (y = 0; y < dec->mb_height; y++) { for (x = 0; x < dec->mb_width; x++) { - MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; + MACROBLOCK *mb; + + skip_stuffing(bs); + if (check_resync_marker(bs, 0)) + { + int mbnum = read_video_packet_header(bs, 0); + x = bound_x = mbnum % dec->mb_width; + y = bound_y = mbnum / dec->mb_width; + } + mb = &dec->mbs[y * dec->mb_width + x]; //if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded if (!(BitstreamGetBit(bs))) // not_coded @@ -562,11 +588,6 @@ acpred_flag = BitstreamGetBit(bs); } - if (mb->mode == MODE_STUFFING) { - DEBUG("-- STUFFING ?"); - continue; - } - cbpy = get_cbpy(bs, intra); cbp = (cbpy << 2) | cbpc; @@ -600,12 +621,12 @@ if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { if (dec->interlacing && mb->field_pred) { get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], - fcode); + fcode, bound_x, bound_y); get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], - fcode); + fcode, bound_x, bound_y); } else { get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], - fcode); + fcode, bound_x, bound_y); 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 = @@ -613,10 +634,10 @@ } } else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) { - get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); - get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode); - get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode); - get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode); + get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound_x, bound_y); + get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound_x, bound_y); + get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound_x, bound_y); + get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound_x, bound_y); } else // MODE_INTRA, MODE_INTRA_Q { mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = @@ -624,7 +645,7 @@ mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, - intra_dc_threshold); + intra_dc_threshold, bound_x, bound_y); continue; } @@ -1250,17 +1271,21 @@ break; case B_VOP: -#ifdef BFRAMES +#ifdef BFRAMES_DEC if (dec->time_pp > dec->time_bp) { DEBUG1("B_VOP Time=", dec->time); decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); } else { DEBUG("broken B-frame!"); } +#else + image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); #endif break; 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); break; default: @@ -1269,13 +1294,13 @@ frame->length = BitstreamPos(&bs) / 8; -#ifdef BFRAMES +#ifdef BFRAMES_DEC // test if no B_VOP if (dec->low_delay) { #endif image_output(&dec->cur, dec->width, dec->height, dec->edged_width, frame->image, frame->stride, frame->colorspace); -#ifdef BFRAMES +#ifdef BFRAMES_DEC } else { if (dec->frames >= 1) { start_timer();