--- decoder.c 2002/06/14 13:21:13 1.20 +++ decoder.c 2002/07/09 01:09:33 1.25 @@ -32,6 +32,8 @@ * * History: * + * 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 +49,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.25 2002/07/09 01:09:33 chenm001 Exp $ * *************************************************************************/ @@ -166,6 +168,122 @@ } + +/* **************************************************************** +NIC 28.06.2002 + riscritta la 'decoder_create' per cambiarne l'interfaccia e poterla + usare nella dll caricata dall'IM1 player + IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) +**************************************************************** */ +//XVID_DEC_FRAME * frame + +int +IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) +{ + DECODER *dec; + Bitstream bs; + uint32_t rounding; + uint32_t quant; + uint32_t fcode_forward; + uint32_t fcode_backward; + uint32_t intra_dc_threshold; + + dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); + if (dec == NULL) { + return XVID_ERR_MEMORY; + } + param->handle = dec; + + + BitstreamInit(&bs, frame->bitstream, frame->length);//NIC + + //NIC + BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward, + &fcode_backward, &intra_dc_threshold); + + + param->width = dec->width; //NIC added + param->height = dec->height; //NIC added + //dec->width = param->width; //NIC commentate + //dec->height = param->height; //NIC commentate + + dec->mb_width = (dec->width + 15) / 16; + dec->mb_height = (dec->height + 15) / 16; + + dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; + dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; + dec->low_delay = 0; + + if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { + xvid_free(dec); + return XVID_ERR_MEMORY; + } + + if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) { + image_destroy(&dec->cur, dec->edged_width, dec->edged_height); + xvid_free(dec); + return XVID_ERR_MEMORY; + } + // add by chenm001 + // for support B-frame to reference last 2 frame + if (image_create(&dec->refn[1], 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); + xvid_free(dec); + return XVID_ERR_MEMORY; + } + if (image_create(&dec->refn[2], 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); + xvid_free(dec); + return XVID_ERR_MEMORY; + } + + dec->mbs = + xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, + CACHE_LINE); + if (dec->mbs == NULL) { + 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; + } + + memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); + + // add by chenm001 + // for skip MB flag + dec->last_mbs = + xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, + CACHE_LINE); + if (dec->last_mbs == NULL) { + xvid_free(dec->mbs); + 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; + } + + memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); + + init_timer(); + + // add by chenm001 + // for support B-frame to save reference frame's time + dec->frames = -1; + dec->time = dec->time_base = dec->last_time_base = 0; + + return XVID_ERR_OK; +} +/* **************************************************************** + END NIC +**************************************************************** */ + int decoder_destroy(DECODER * dec) { @@ -1241,26 +1359,35 @@ case P_VOP: decoder_pframe(dec, &bs, rounding, quant, fcode_forward, intra_dc_threshold); + printf("P_VOP Time=%ld\n",dec->time); DEBUG1("P_VOP Time=", dec->time); break; case I_VOP: decoder_iframe(dec, &bs, quant, intra_dc_threshold); + printf("I_VOP Time=%ld\n",dec->time); DEBUG1("I_VOP Time=", dec->time); break; case B_VOP: -#ifdef BFRAMES +#ifdef BFRAMES_DEC if (dec->time_pp > dec->time_bp) { + printf("I_VOP Time=%ld\n",dec->time); DEBUG1("B_VOP Time=", dec->time); decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); } else { DEBUG("broken B-frame!"); } +#else + printf("Che minchia ne so\n"); + 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); + printf("N_VOP vop not coded\n"); break; default: @@ -1269,13 +1396,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();