1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Decoder main module - |
* - Decoder Module - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* 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. |
|
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
*************************************************************************/ |
* $Id: decoder.c,v 1.49 2003-02-19 21:59:30 edgomez Exp $ |
|
|
|
|
/************************************************************************** |
|
|
* |
|
|
* History: |
|
|
* |
|
|
* 15.07.2002 fix a bug in B-frame decode at DIRECT mode |
|
|
* MinChen <chenm001@163.com> |
|
|
* 10.07.2002 added BFRAMES_DEC_DEBUG support |
|
|
* Fix a little bug for low_delay flage |
|
|
* MinChen <chenm001@163.com> |
|
|
* 28.06.2002 added basic resync support to iframe/pframe_decode() |
|
|
* 22.06.2002 added primative N_VOP support |
|
|
* #define BFRAMES_DEC now enables Minchen's bframe decoder |
|
|
* 08.05.2002 add low_delay support for B_VOP decode |
|
|
* MinChen <chenm001@163.com> |
|
|
* 05.05.2002 fix some B-frame decode problem |
|
|
* 02.05.2002 add B-frame decode support(have some problem); |
|
|
* MinChen <chenm001@163.com> |
|
|
* 22.04.2002 add some B-frame decode support; chenm001 <chenm001@163.com> |
|
|
* 29.03.2002 interlacing fix - compensated block wasn't being used when |
|
|
* reconstructing blocks, thus artifacts |
|
|
* interlacing speedup - used transfers to re-interlace |
|
|
* 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> |
|
23 |
* |
* |
24 |
* $Id: decoder.c,v 1.47 2003-02-15 15:22:17 edgomez Exp $ |
****************************************************************************/ |
|
* |
|
|
*************************************************************************/ |
|
25 |
|
|
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <stdlib.h> |
#include <stdlib.h> |
62 |
decoder_resize(DECODER * dec) |
decoder_resize(DECODER * dec) |
63 |
{ |
{ |
64 |
/* free existing */ |
/* free existing */ |
|
|
|
65 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
66 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
67 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
76 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
77 |
|
|
78 |
/* realloc */ |
/* realloc */ |
|
|
|
79 |
dec->mb_width = (dec->width + 15) / 16; |
dec->mb_width = (dec->width + 15) / 16; |
80 |
dec->mb_height = (dec->height + 15) / 16; |
dec->mb_height = (dec->height + 15) / 16; |
81 |
|
|
93 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
94 |
} |
} |
95 |
|
|
96 |
// add by chenm001 <chenm001@163.com> |
/* Support B-frame to reference last 2 frame */ |
|
// for support B-frame to reference last 2 frame |
|
97 |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
98 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
99 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
141 |
} |
} |
142 |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
143 |
|
|
144 |
// add by chenm001 <chenm001@163.com> |
/* For skip MB flag */ |
|
// for skip MB flag |
|
145 |
dec->last_mbs = |
dec->last_mbs = |
146 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
147 |
CACHE_LINE); |
CACHE_LINE); |
193 |
|
|
194 |
init_timer(); |
init_timer(); |
195 |
|
|
196 |
// add by chenm001 <chenm001@163.com> |
/* For B-frame support (used to save reference frame's time */ |
|
// for support B-frame to save reference frame's time |
|
197 |
dec->frames = 0; |
dec->frames = 0; |
198 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
199 |
dec->low_delay = 0; |
dec->low_delay = 0; |
214 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
215 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
216 |
|
|
217 |
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); /* image based GMC */ |
/* image based GMC */ |
218 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
219 |
|
|
220 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
221 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
// decode an intra macroblock |
/* decode an intra macroblock */ |
|
|
|
241 |
void |
void |
242 |
decoder_mbintra(DECODER * dec, |
decoder_mbintra(DECODER * dec, |
243 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
272 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
273 |
} |
} |
274 |
|
|
275 |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
memset(block, 0, 6 * 64 * sizeof(int16_t)); /* clear */ |
276 |
|
|
277 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
278 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
295 |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0; |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0; |
296 |
|
|
297 |
if (dc_size > 8) { |
if (dc_size > 8) { |
298 |
BitstreamSkip(bs, 1); // marker |
BitstreamSkip(bs, 1); /* marker */ |
299 |
} |
} |
300 |
|
|
301 |
block[i * 64 + 0] = dc_dif; |
block[i * 64 + 0] = dc_dif; |
307 |
} |
} |
308 |
|
|
309 |
start_timer(); |
start_timer(); |
310 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
311 |
{ |
{ |
312 |
int direction = dec->alternate_vertical_scan ? |
int direction = dec->alternate_vertical_scan ? |
313 |
2 : pMB->acpred_directions[i]; |
2 : pMB->acpred_directions[i]; |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
// decode an inter macroblock |
/* decode an inter macroblock */ |
|
|
|
368 |
void |
void |
369 |
decoder_mbinter(DECODER * dec, |
decoder_mbinter(DECODER * dec, |
370 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
478 |
interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos, |
interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos, |
479 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
480 |
|
|
481 |
// set_block(pY_Cur, stride, 32, 32, 127); |
/* set_block(pY_Cur, stride, 32, 32, 127); */ |
482 |
} |
} |
483 |
else |
else |
484 |
{ |
{ |
518 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
519 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
520 |
|
|
521 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
522 |
{ |
{ |
523 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
524 |
|
|
525 |
start_timer(); |
start_timer(); |
526 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
583 |
{ |
{ |
584 |
int length = 1 << (fcode+4); |
int length = 1 << (fcode+4); |
585 |
|
|
586 |
// if (quarterpel) value *= 2; |
/* if (quarterpel) value *= 2; */ |
587 |
|
|
588 |
if (value < -length) |
if (value < -length) |
589 |
return -length; |
return -length; |
633 |
} |
} |
634 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
635 |
|
|
636 |
/* transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); |
/* |
637 |
|
transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); |
638 |
transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
639 |
transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
640 |
*/ |
*/ |
647 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
648 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
649 |
|
|
650 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
651 |
{ |
{ |
652 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
653 |
|
|
654 |
start_timer(); |
start_timer(); |
655 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
670 |
} |
} |
671 |
|
|
672 |
/* interlace + GMC is this possible ??? */ |
/* interlace + GMC is this possible ??? */ |
673 |
/* if (dec->interlacing && pMB->field_dct) { |
/* |
674 |
|
if (dec->interlacing && pMB->field_dct) { |
675 |
next_block = stride; |
next_block = stride; |
676 |
stride *= 2; |
stride *= 2; |
677 |
} |
} |
856 |
if (gmc_warp) |
if (gmc_warp) |
857 |
{ |
{ |
858 |
|
|
859 |
// accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
/* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ |
860 |
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
861 |
{ |
{ |
862 |
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
885 |
for (x = 0; x < mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
886 |
MACROBLOCK *mb; |
MACROBLOCK *mb; |
887 |
|
|
888 |
// skip stuffing |
/* skip stuffing */ |
889 |
while (BitstreamShowBits(bs, 10) == 1) |
while (BitstreamShowBits(bs, 10) == 1) |
890 |
BitstreamSkip(bs, 10); |
BitstreamSkip(bs, 10); |
891 |
|
|
900 |
|
|
901 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
902 |
|
|
903 |
//if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded |
/* if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) */ /* not_coded */ |
904 |
if (!(BitstreamGetBit(bs))) // block _is_ coded |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
905 |
{ |
{ |
906 |
uint32_t mcbpc; |
uint32_t mcbpc; |
907 |
uint32_t cbpc; |
uint32_t cbpc; |
909 |
uint32_t cbpy; |
uint32_t cbpy; |
910 |
uint32_t cbp; |
uint32_t cbp; |
911 |
uint32_t intra; |
uint32_t intra; |
912 |
int mcsel = 0; // mcsel: '0'=local motion, '1'=GMC |
int mcsel = 0; /* mcsel: '0'=local motion, '1'=GMC */ |
913 |
|
|
914 |
cp_mb++; |
cp_mb++; |
915 |
mcbpc = get_mcbpc_inter(bs); |
mcbpc = get_mcbpc_inter(bs); |
991 |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); |
992 |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); |
993 |
get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound); |
get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound); |
994 |
} else // MODE_INTRA, MODE_INTRA_Q |
} else /* MODE_INTRA, MODE_INTRA_Q */ |
995 |
{ |
{ |
996 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
997 |
0; |
0; |
1029 |
|
|
1030 |
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; |
1031 |
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; |
1032 |
// copy macroblock directly from ref to cur |
/* copy macroblock directly from ref to cur */ |
1033 |
|
|
1034 |
start_timer(); |
start_timer(); |
1035 |
|
|
1077 |
} |
} |
1078 |
|
|
1079 |
|
|
1080 |
// add by MinChen <chenm001@163.com> |
/* decode B-frame motion vector */ |
|
// decode B-frame motion vector |
|
1081 |
void |
void |
1082 |
get_b_motion_vector(DECODER * dec, |
get_b_motion_vector(DECODER * dec, |
1083 |
Bitstream * bs, |
Bitstream * bs, |
1121 |
} |
} |
1122 |
|
|
1123 |
|
|
1124 |
// add by MinChen <chenm001@163.com> |
/* decode an B-frame forward & backward inter macroblock */ |
|
// decode an B-frame forward & backward inter macroblock |
|
1125 |
void |
void |
1126 |
decoder_bf_mbinter(DECODER * dec, |
decoder_bf_mbinter(DECODER * dec, |
1127 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
1205 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1206 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1207 |
|
|
1208 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
1209 |
{ |
{ |
1210 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1211 |
|
|
1212 |
start_timer(); |
start_timer(); |
1213 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
1248 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1249 |
} |
} |
1250 |
|
|
1251 |
// add by MinChen <chenm001@163.com> |
/* decode an B-frame direct & inter macroblock */ |
|
// decode an B-frame direct & inter macroblock |
|
1252 |
void |
void |
1253 |
decoder_bf_interpolate_mbinter(DECODER * dec, |
decoder_bf_interpolate_mbinter(DECODER * dec, |
1254 |
IMAGE forward, |
IMAGE forward, |
1445 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1446 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1447 |
|
|
1448 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
1449 |
{ |
{ |
1450 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1451 |
|
|
1452 |
start_timer(); |
start_timer(); |
1453 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
1489 |
} |
} |
1490 |
|
|
1491 |
|
|
1492 |
// add by MinChen <chenm001@163.com> |
/* for decode B-frame dbquant */ |
|
// for decode B-frame dbquant |
|
1493 |
int32_t __inline |
int32_t __inline |
1494 |
get_dbquant(Bitstream * bs) |
get_dbquant(Bitstream * bs) |
1495 |
{ |
{ |
1496 |
if (!BitstreamGetBit(bs)) // '0' |
if (!BitstreamGetBit(bs)) /* '0' */ |
1497 |
return (0); |
return (0); |
1498 |
else if (!BitstreamGetBit(bs)) // '10' |
else if (!BitstreamGetBit(bs)) /* '10' */ |
1499 |
return (-2); |
return (-2); |
1500 |
else |
else /* '11' */ |
1501 |
return (2); // '11' |
return (2); |
1502 |
} |
} |
1503 |
|
|
1504 |
// add by MinChen <chenm001@163.com> |
/* |
1505 |
// for decode B-frame mb_type |
* For decode B-frame mb_type |
1506 |
// bit ret_value |
* bit ret_value |
1507 |
// 1 0 |
* 1 0 |
1508 |
// 01 1 |
* 01 1 |
1509 |
// 001 2 |
* 001 2 |
1510 |
// 0001 3 |
* 0001 3 |
1511 |
|
*/ |
1512 |
int32_t __inline |
int32_t __inline |
1513 |
get_mbtype(Bitstream * bs) |
get_mbtype(Bitstream * bs) |
1514 |
{ |
{ |
1557 |
#endif |
#endif |
1558 |
|
|
1559 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1560 |
// Initialize Pred Motion Vector |
/* Initialize Pred Motion Vector */ |
1561 |
dec->p_fmv = dec->p_bmv = zeromv; |
dec->p_fmv = dec->p_bmv = zeromv; |
1562 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
1563 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
1567 |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
1568 |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
1569 |
|
|
1570 |
// skip if the co-located P_VOP macroblock is not coded |
/* |
1571 |
// if not codec in co-located S_VOP macroblock is _not_ automatically skipped |
* skip if the co-located P_VOP macroblock is not coded |
1572 |
|
* if not codec in co-located S_VOP macroblock is _not_ |
1573 |
|
* automatically skipped |
1574 |
|
*/ |
1575 |
|
|
1576 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1577 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
1578 |
mb->cbp = 0; |
mb->cbp = 0; |
1579 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1580 |
mb->mb_type = MODE_NOT_CODED; |
mb->mb_type = MODE_NOT_CODED; |
1582 |
#endif |
#endif |
1583 |
mb->mb_type = MODE_FORWARD; |
mb->mb_type = MODE_FORWARD; |
1584 |
mb->quant = last_mb->quant; |
mb->quant = last_mb->quant; |
1585 |
//mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
/* |
1586 |
//mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
1587 |
|
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
1588 |
|
*/ |
1589 |
|
|
1590 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1); |
1591 |
continue; |
continue; |
1592 |
} |
} |
1593 |
|
|
1594 |
if (!BitstreamGetBit(bs)) { // modb=='0' |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
1595 |
const uint8_t modb2 = BitstreamGetBit(bs); |
const uint8_t modb2 = BitstreamGetBit(bs); |
1596 |
|
|
1597 |
mb->mb_type = get_mbtype(bs); |
mb->mb_type = get_mbtype(bs); |
1598 |
|
|
1599 |
if (!modb2) { // modb=='00' |
if (!modb2) { /* modb=='00' */ |
1600 |
mb->cbp = BitstreamGetBits(bs, 6); |
mb->cbp = BitstreamGetBits(bs, 6); |
1601 |
} else { |
} else { |
1602 |
mb->cbp = 0; |
mb->cbp = 0; |
1617 |
|
|
1618 |
mb->quant = quant; |
mb->quant = quant; |
1619 |
mb->mode = MODE_INTER4V; |
mb->mode = MODE_INTER4V; |
1620 |
//DEBUG1("Switch bm_type=",mb->mb_type); |
/* DEBUG1("Switch bm_type=",mb->mb_type); */ |
1621 |
|
|
1622 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1623 |
BFRAME_DEBUG |
BFRAME_DEBUG |
1646 |
/ TRD |
/ TRD |
1647 |
: mb->mvs[i].y - last_mb->mvs[i].y); |
: mb->mvs[i].y - last_mb->mvs[i].y); |
1648 |
} |
} |
1649 |
//DEBUG("B-frame Direct!\n"); |
/* DEBUG("B-frame Direct!\n"); */ |
1650 |
} |
} |
1651 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1652 |
mb, x, y, bs); |
mb, x, y, bs); |
1664 |
|
|
1665 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1666 |
mb, x, y, bs); |
mb, x, y, bs); |
1667 |
//DEBUG("B-frame Bidir!\n"); |
/* DEBUG("B-frame Bidir!\n"); */ |
1668 |
break; |
break; |
1669 |
|
|
1670 |
case MODE_BACKWARD: |
case MODE_BACKWARD: |
1674 |
|
|
1675 |
mb->mode = MODE_INTER; |
mb->mode = MODE_INTER; |
1676 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
1677 |
//DEBUG("B-frame Backward!\n"); |
/* DEBUG("B-frame Backward!\n"); */ |
1678 |
break; |
break; |
1679 |
|
|
1680 |
case MODE_FORWARD: |
case MODE_FORWARD: |
1684 |
|
|
1685 |
mb->mode = MODE_INTER; |
mb->mode = MODE_INTER; |
1686 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
1687 |
//DEBUG("B-frame Forward!\n"); |
/* DEBUG("B-frame Forward!\n"); */ |
1688 |
break; |
break; |
1689 |
|
|
1690 |
default: |
default: |
1691 |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
1692 |
} |
} |
1693 |
|
} /* End of for */ |
|
} // end of FOR |
|
1694 |
} |
} |
1695 |
|
|
1696 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1697 |
if (!first){ |
if (!first){ |
1698 |
first=1; |
first=1; |
1702 |
#endif |
#endif |
1703 |
} |
} |
1704 |
|
|
1705 |
// swap two MACROBLOCK array |
/* swap two MACROBLOCK array */ |
1706 |
void |
void |
1707 |
mb_swap(MACROBLOCK ** mb1, |
mb_swap(MACROBLOCK ** mb1, |
1708 |
MACROBLOCK ** mb2) |
MACROBLOCK ** mb2) |
1748 |
uint32_t fcode_backward; |
uint32_t fcode_backward; |
1749 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
1750 |
WARPPOINTS gmc_warp; |
WARPPOINTS gmc_warp; |
1751 |
uint32_t vop_type; |
int vop_type; |
1752 |
int success = 0; |
int success = 0; |
1753 |
int output = 0; |
int output = 0; |
1754 |
int seen_something = 0; |
int seen_something = 0; |
1776 |
{ |
{ |
1777 |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1778 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1779 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1780 |
} |
} |
1781 |
|
|
1782 |
emms(); |
emms(); |
1787 |
|
|
1788 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1789 |
|
|
1790 |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
/* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */ |
1791 |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1792 |
{ |
{ |
1793 |
if (stats) |
if (stats) |
1837 |
goto repeat; |
goto repeat; |
1838 |
} |
} |
1839 |
|
|
1840 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; // init pred vector to 0 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; /* init pred vector to 0 */ |
1841 |
|
|
1842 |
|
|
1843 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1967 |
{ |
{ |
1968 |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1969 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1970 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1971 |
} |
} |
1972 |
|
|
1973 |
emms(); |
emms(); |