3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Decoder main module - |
* - Decoder main module - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002 MinChen <chenm001@163.com> |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* 2002 Peter Ross <pross@xvid.org> |
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
8 |
* |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
10 |
* it under the terms of the GNU General Public License as published by |
* |
11 |
|
* XviD is free software; you can redistribute it and/or modify it |
12 |
|
* under the terms of the GNU General Public License as published by |
13 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
14 |
* (at your option) any later version. |
* (at your option) any later version. |
15 |
* |
* |
22 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
* |
* |
25 |
*************************************************************************/ |
* Under section 8 of the GNU General Public License, the copyright |
26 |
|
* holders of XVID explicitly forbid distribution in the following |
27 |
/************************************************************************** |
* countries: |
28 |
|
* |
29 |
|
* - Japan |
30 |
|
* - United States of America |
31 |
* |
* |
32 |
* History: |
* Linking XviD statically or dynamically with other modules is making a |
33 |
|
* combined work based on XviD. Thus, the terms and conditions of the |
34 |
|
* GNU General Public License cover the whole combination. |
35 |
* |
* |
36 |
* 15.07.2002 fix a bug in B-frame decode at DIRECT mode |
* As a special exception, the copyright holders of XviD give you |
37 |
* MinChen <chenm001@163.com> |
* permission to link XviD with independent modules that communicate with |
38 |
* 10.07.2002 added BFRAMES_DEC_DEBUG support |
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
39 |
* Fix a little bug for low_delay flage |
* license terms of these independent modules, and to copy and distribute |
40 |
* MinChen <chenm001@163.com> |
* the resulting combined work under terms of your choice, provided that |
41 |
* 28.06.2002 added basic resync support to iframe/pframe_decode() |
* every copy of the combined work is accompanied by a complete copy of |
42 |
* 22.06.2002 added primative N_VOP support |
* the source code of XviD (the version of XviD used to produce the |
43 |
* #define BFRAMES_DEC now enables Minchen's bframe decoder |
* combined work), being distributed under the terms of the GNU General |
44 |
* 08.05.2002 add low_delay support for B_VOP decode |
* Public License plus this exception. An independent module is a module |
45 |
* MinChen <chenm001@163.com> |
* which is not derived from or based on XviD. |
46 |
* 05.05.2002 fix some B-frame decode problem |
* |
47 |
* 02.05.2002 add B-frame decode support(have some problem); |
* Note that people who make modified versions of XviD are not obligated |
48 |
* MinChen <chenm001@163.com> |
* to grant this special exception for their modified versions; it is |
49 |
* 22.04.2002 add some B-frame decode support; chenm001 <chenm001@163.com> |
* their choice whether to do so. The GNU General Public License gives |
50 |
* 29.03.2002 interlacing fix - compensated block wasn't being used when |
* permission to release a modified version without this exception; this |
51 |
* reconstructing blocks, thus artifacts |
* exception also makes it possible to release a modified version which |
52 |
* interlacing speedup - used transfers to re-interlace |
* carries forward this exception. |
|
* interlaced decoding should be as fast as progressive now |
|
|
* 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 <pross@cs.rmit.edu.au> |
|
53 |
* |
* |
54 |
* $Id$ |
* $Id$ |
55 |
* |
* |
375 |
|
|
376 |
start_timer(); |
start_timer(); |
377 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
378 |
DEBUG("QUARTERPEL"); |
DPRINTF(DPRINTF_DEBUG, "QUARTERPEL\n"); |
379 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
380 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
381 |
interpolate8x8_quarterpel(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, |
505 |
|
|
506 |
if (dec->interlacing) { |
if (dec->interlacing) { |
507 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
508 |
DEBUG1("deci: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_DEBUG, "deci: field_dct: %d", mb->field_dct); |
509 |
} |
} |
510 |
|
|
511 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
581 |
|
|
582 |
start_timer(); |
start_timer(); |
583 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
584 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
585 |
stop_edges_timer(); |
stop_edges_timer(); |
586 |
|
|
587 |
bound = 0; |
bound = 0; |
649 |
mb->quant = quant; |
mb->quant = quant; |
650 |
|
|
651 |
if (dec->interlacing) { |
if (dec->interlacing) { |
652 |
|
if (cbp || intra) { |
653 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
654 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_DEBUG, "decp: field_dct: %d", mb->field_dct); |
655 |
|
} |
656 |
|
|
657 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
658 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
659 |
DEBUG1("decp: field_pred: ", mb->field_pred); |
DPRINTF(DPRINTF_DEBUG, "decp: field_pred: %d", mb->field_pred); |
660 |
|
|
661 |
if (mb->field_pred) { |
if (mb->field_pred) { |
662 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
663 |
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
DPRINTF(DPRINTF_DEBUG, "decp: field_for_top: %d", mb->field_for_top); |
664 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
665 |
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
DPRINTF(DPRINTF_DEBUG, "decp: field_for_bot: %d", mb->field_for_bot); |
666 |
} |
} |
667 |
} |
} |
668 |
} |
} |
702 |
rounding); |
rounding); |
703 |
} else // not coded |
} else // not coded |
704 |
{ |
{ |
705 |
DEBUG2("P-frame MB at (X,Y)=",x,y); |
DPRINTF(DPRINTF_DEBUG, "P-frame MB at (X,Y)=(%d,%d)", x, y); |
706 |
|
|
707 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
708 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
709 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
1139 |
|
|
1140 |
start_timer(); |
start_timer(); |
1141 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1142 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1143 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1144 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1145 |
stop_edges_timer(); |
stop_edges_timer(); |
1146 |
|
|
1147 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1275 |
break; |
break; |
1276 |
|
|
1277 |
default: |
default: |
1278 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DPRINTF(DPRINTF_ERROR, "Not support B-frame mb_type = %d", mb->mb_type); |
1279 |
} |
} |
1280 |
|
|
1281 |
} // end of FOR |
} // end of FOR |
1333 |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
1334 |
intra_dc_threshold); |
intra_dc_threshold); |
1335 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1336 |
DEBUG1("P_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "P_VOP Time=%d", dec->time); |
1337 |
#endif |
#endif |
1338 |
break; |
break; |
1339 |
|
|
1340 |
case I_VOP: |
case I_VOP: |
1341 |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
1342 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1343 |
DEBUG1("I_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "I_VOP Time=%d", dec->time); |
1344 |
#endif |
#endif |
1345 |
break; |
break; |
1346 |
|
|
1347 |
case B_VOP: |
case B_VOP: |
1348 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1349 |
if (dec->time_pp > dec->time_bp) { |
if (dec->time_pp > dec->time_bp) { |
1350 |
DEBUG1("B_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "B_VOP Time=%d", dec->time); |
1351 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1352 |
} else { |
} else { |
1353 |
DEBUG("broken B-frame!"); |
DPRINTF(DPRINTF_DEBUG, "Broken B_VOP"); |
1354 |
} |
} |
1355 |
#else |
#else |
1356 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1368 |
|
|
1369 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1370 |
if (frame->length != BitstreamPos(&bs) / 8){ |
if (frame->length != BitstreamPos(&bs) / 8){ |
1371 |
DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); |
DPRINTF(DPRINTF_DEBUG, "InLen: %d / UseLen: %d", frame->length, BitstreamPos(&bs) / 8); |
1372 |
} |
} |
1373 |
#endif |
#endif |
1374 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1376 |
|
|
1377 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1378 |
// test if no B_VOP |
// test if no B_VOP |
1379 |
if (dec->low_delay) { |
if (dec->low_delay || dec->frames == 0) { |
1380 |
#endif |
#endif |
1381 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
1382 |
frame->image, frame->stride, frame->colorspace); |
frame->image, frame->stride, frame->colorspace); |
1383 |
|
|
1384 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1385 |
} else { |
} else { |
1386 |
if (dec->frames >= 0) { |
if (dec->frames >= 1) { |
1387 |
start_timer(); |
start_timer(); |
1388 |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
1389 |
image_output(&dec->refn[0], dec->width, dec->height, |
image_output(&dec->refn[0], dec->width, dec->height, |