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 |
* |
* |
|
*************************************************************************/ |
|
|
|
|
|
/************************************************************************** |
|
|
* |
|
|
* 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> |
|
|
* |
|
22 |
* $Id$ |
* $Id$ |
23 |
* |
* |
24 |
*************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <stdlib.h> |
#include <stdlib.h> |
57 |
#include "image/image.h" |
#include "image/image.h" |
58 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
59 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
60 |
|
#include "image/postprocessing.h" |
61 |
|
|
62 |
int |
int |
63 |
decoder_resize(DECODER * dec) |
decoder_resize(DECODER * dec) |
64 |
{ |
{ |
65 |
/* free existing */ |
/* free existing */ |
|
|
|
66 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
67 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
68 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
77 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
78 |
|
|
79 |
/* realloc */ |
/* realloc */ |
|
|
|
80 |
dec->mb_width = (dec->width + 15) / 16; |
dec->mb_width = (dec->width + 15) / 16; |
81 |
dec->mb_height = (dec->height + 15) / 16; |
dec->mb_height = (dec->height + 15) / 16; |
82 |
|
|
94 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
95 |
} |
} |
96 |
|
|
97 |
// add by chenm001 <chenm001@163.com> |
/* Support B-frame to reference last 2 frame */ |
|
// for support B-frame to reference last 2 frame |
|
98 |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
99 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
100 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
142 |
} |
} |
143 |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
144 |
|
|
145 |
// add by chenm001 <chenm001@163.com> |
/* For skip MB flag */ |
|
// for skip MB flag |
|
146 |
dec->last_mbs = |
dec->last_mbs = |
147 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
148 |
CACHE_LINE); |
CACHE_LINE); |
194 |
|
|
195 |
init_timer(); |
init_timer(); |
196 |
|
|
197 |
// 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 |
|
198 |
dec->frames = 0; |
dec->frames = 0; |
199 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
200 |
dec->low_delay = 0; |
dec->low_delay = 0; |
215 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
216 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
217 |
|
|
218 |
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); /* image based GMC */ |
/* image based GMC */ |
219 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
220 |
|
|
221 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
222 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
// decode an intra macroblock |
/* decode an intra macroblock */ |
|
|
|
242 |
void |
void |
243 |
decoder_mbintra(DECODER * dec, |
decoder_mbintra(DECODER * dec, |
244 |
MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
273 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
274 |
} |
} |
275 |
|
|
276 |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
memset(block, 0, 6 * 64 * sizeof(int16_t)); /* clear */ |
277 |
|
|
278 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
279 |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
296 |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0; |
dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0; |
297 |
|
|
298 |
if (dc_size > 8) { |
if (dc_size > 8) { |
299 |
BitstreamSkip(bs, 1); // marker |
BitstreamSkip(bs, 1); /* marker */ |
300 |
} |
} |
301 |
|
|
302 |
block[i * 64 + 0] = dc_dif; |
block[i * 64 + 0] = dc_dif; |
308 |
} |
} |
309 |
|
|
310 |
start_timer(); |
start_timer(); |
311 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
312 |
{ |
{ |
313 |
int direction = dec->alternate_vertical_scan ? |
int direction = dec->alternate_vertical_scan ? |
314 |
2 : pMB->acpred_directions[i]; |
2 : pMB->acpred_directions[i]; |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
// decode an inter macroblock |
/* decode an inter macroblock */ |
|
|
|
369 |
void |
void |
370 |
decoder_mbinter(DECODER * dec, |
decoder_mbinter(DECODER * dec, |
371 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
479 |
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, |
480 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
481 |
|
|
482 |
// set_block(pY_Cur, stride, 32, 32, 127); |
/* set_block(pY_Cur, stride, 32, 32, 127); */ |
483 |
} |
} |
484 |
else |
else |
485 |
{ |
{ |
519 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
520 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
521 |
|
|
522 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
523 |
{ |
{ |
524 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
525 |
|
|
526 |
start_timer(); |
start_timer(); |
527 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
584 |
{ |
{ |
585 |
int length = 1 << (fcode+4); |
int length = 1 << (fcode+4); |
586 |
|
|
587 |
// if (quarterpel) value *= 2; |
/* if (quarterpel) value *= 2; */ |
588 |
|
|
589 |
if (value < -length) |
if (value < -length) |
590 |
return -length; |
return -length; |
634 |
} |
} |
635 |
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; |
636 |
|
|
637 |
/* transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); |
/* |
638 |
|
transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); |
639 |
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); |
640 |
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); |
641 |
*/ |
*/ |
648 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
649 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
650 |
|
|
651 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
652 |
{ |
{ |
653 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
654 |
|
|
655 |
start_timer(); |
start_timer(); |
656 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
671 |
} |
} |
672 |
|
|
673 |
/* interlace + GMC is this possible ??? */ |
/* interlace + GMC is this possible ??? */ |
674 |
/* if (dec->interlacing && pMB->field_dct) { |
/* |
675 |
|
if (dec->interlacing && pMB->field_dct) { |
676 |
next_block = stride; |
next_block = stride; |
677 |
stride *= 2; |
stride *= 2; |
678 |
} |
} |
857 |
if (gmc_warp) |
if (gmc_warp) |
858 |
{ |
{ |
859 |
|
|
860 |
// 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 */ |
861 |
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
862 |
{ |
{ |
863 |
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
886 |
for (x = 0; x < mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
887 |
MACROBLOCK *mb; |
MACROBLOCK *mb; |
888 |
|
|
889 |
// skip stuffing |
/* skip stuffing */ |
890 |
while (BitstreamShowBits(bs, 10) == 1) |
while (BitstreamShowBits(bs, 10) == 1) |
891 |
BitstreamSkip(bs, 10); |
BitstreamSkip(bs, 10); |
892 |
|
|
901 |
|
|
902 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
903 |
|
|
904 |
//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 */ |
905 |
if (!(BitstreamGetBit(bs))) // block _is_ coded |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
906 |
{ |
{ |
907 |
uint32_t mcbpc; |
uint32_t mcbpc; |
908 |
uint32_t cbpc; |
uint32_t cbpc; |
910 |
uint32_t cbpy; |
uint32_t cbpy; |
911 |
uint32_t cbp; |
uint32_t cbp; |
912 |
uint32_t intra; |
uint32_t intra; |
913 |
int mcsel = 0; // mcsel: '0'=local motion, '1'=GMC |
int mcsel = 0; /* mcsel: '0'=local motion, '1'=GMC */ |
914 |
|
|
915 |
cp_mb++; |
cp_mb++; |
916 |
mcbpc = get_mcbpc_inter(bs); |
mcbpc = get_mcbpc_inter(bs); |
992 |
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); |
993 |
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); |
994 |
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); |
995 |
} else // MODE_INTRA, MODE_INTRA_Q |
} else /* MODE_INTRA, MODE_INTRA_Q */ |
996 |
{ |
{ |
997 |
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 = |
998 |
0; |
0; |
1030 |
|
|
1031 |
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; |
1032 |
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; |
1033 |
// copy macroblock directly from ref to cur |
/* copy macroblock directly from ref to cur */ |
1034 |
|
|
1035 |
start_timer(); |
start_timer(); |
1036 |
|
|
1078 |
} |
} |
1079 |
|
|
1080 |
|
|
1081 |
// add by MinChen <chenm001@163.com> |
/* decode B-frame motion vector */ |
|
// decode B-frame motion vector |
|
1082 |
void |
void |
1083 |
get_b_motion_vector(DECODER * dec, |
get_b_motion_vector(DECODER * dec, |
1084 |
Bitstream * bs, |
Bitstream * bs, |
1122 |
} |
} |
1123 |
|
|
1124 |
|
|
1125 |
// add by MinChen <chenm001@163.com> |
/* decode an B-frame forward & backward inter macroblock */ |
|
// decode an B-frame forward & backward inter macroblock |
|
1126 |
void |
void |
1127 |
decoder_bf_mbinter(DECODER * dec, |
decoder_bf_mbinter(DECODER * dec, |
1128 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
1206 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1207 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1208 |
|
|
1209 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
1210 |
{ |
{ |
1211 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1212 |
|
|
1213 |
start_timer(); |
start_timer(); |
1214 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
1249 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1250 |
} |
} |
1251 |
|
|
1252 |
// add by MinChen <chenm001@163.com> |
/* decode an B-frame direct & inter macroblock */ |
|
// decode an B-frame direct & inter macroblock |
|
1253 |
void |
void |
1254 |
decoder_bf_interpolate_mbinter(DECODER * dec, |
decoder_bf_interpolate_mbinter(DECODER * dec, |
1255 |
IMAGE forward, |
IMAGE forward, |
1446 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1447 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1448 |
|
|
1449 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) /* coded */ |
1450 |
{ |
{ |
1451 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1452 |
|
|
1453 |
start_timer(); |
start_timer(); |
1454 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64], direction); |
1490 |
} |
} |
1491 |
|
|
1492 |
|
|
1493 |
// add by MinChen <chenm001@163.com> |
/* for decode B-frame dbquant */ |
|
// for decode B-frame dbquant |
|
1494 |
int32_t __inline |
int32_t __inline |
1495 |
get_dbquant(Bitstream * bs) |
get_dbquant(Bitstream * bs) |
1496 |
{ |
{ |
1497 |
if (!BitstreamGetBit(bs)) // '0' |
if (!BitstreamGetBit(bs)) /* '0' */ |
1498 |
return (0); |
return (0); |
1499 |
else if (!BitstreamGetBit(bs)) // '10' |
else if (!BitstreamGetBit(bs)) /* '10' */ |
1500 |
return (-2); |
return (-2); |
1501 |
else |
else /* '11' */ |
1502 |
return (2); // '11' |
return (2); |
1503 |
} |
} |
1504 |
|
|
1505 |
// add by MinChen <chenm001@163.com> |
/* |
1506 |
// for decode B-frame mb_type |
* For decode B-frame mb_type |
1507 |
// bit ret_value |
* bit ret_value |
1508 |
// 1 0 |
* 1 0 |
1509 |
// 01 1 |
* 01 1 |
1510 |
// 001 2 |
* 001 2 |
1511 |
// 0001 3 |
* 0001 3 |
1512 |
|
*/ |
1513 |
int32_t __inline |
int32_t __inline |
1514 |
get_mbtype(Bitstream * bs) |
get_mbtype(Bitstream * bs) |
1515 |
{ |
{ |
1558 |
#endif |
#endif |
1559 |
|
|
1560 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1561 |
// Initialize Pred Motion Vector |
/* Initialize Pred Motion Vector */ |
1562 |
dec->p_fmv = dec->p_bmv = zeromv; |
dec->p_fmv = dec->p_bmv = zeromv; |
1563 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
1564 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
1568 |
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] = |
1569 |
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; |
1570 |
|
|
1571 |
// skip if the co-located P_VOP macroblock is not coded |
/* |
1572 |
// if not codec in co-located S_VOP macroblock is _not_ automatically skipped |
* skip if the co-located P_VOP macroblock is not coded |
1573 |
|
* if not codec in co-located S_VOP macroblock is _not_ |
1574 |
|
* automatically skipped |
1575 |
|
*/ |
1576 |
|
|
1577 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1578 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
1579 |
mb->cbp = 0; |
mb->cbp = 0; |
1580 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1581 |
mb->mb_type = MODE_NOT_CODED; |
mb->mb_type = MODE_NOT_CODED; |
1583 |
#endif |
#endif |
1584 |
mb->mb_type = MODE_FORWARD; |
mb->mb_type = MODE_FORWARD; |
1585 |
mb->quant = last_mb->quant; |
mb->quant = last_mb->quant; |
1586 |
//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; |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
1588 |
|
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
1589 |
|
*/ |
1590 |
|
|
1591 |
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); |
1592 |
continue; |
continue; |
1593 |
} |
} |
1594 |
|
|
1595 |
if (!BitstreamGetBit(bs)) { // modb=='0' |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
1596 |
const uint8_t modb2 = BitstreamGetBit(bs); |
const uint8_t modb2 = BitstreamGetBit(bs); |
1597 |
|
|
1598 |
mb->mb_type = get_mbtype(bs); |
mb->mb_type = get_mbtype(bs); |
1599 |
|
|
1600 |
if (!modb2) { // modb=='00' |
if (!modb2) { /* modb=='00' */ |
1601 |
mb->cbp = BitstreamGetBits(bs, 6); |
mb->cbp = BitstreamGetBits(bs, 6); |
1602 |
} else { |
} else { |
1603 |
mb->cbp = 0; |
mb->cbp = 0; |
1618 |
|
|
1619 |
mb->quant = quant; |
mb->quant = quant; |
1620 |
mb->mode = MODE_INTER4V; |
mb->mode = MODE_INTER4V; |
1621 |
//DEBUG1("Switch bm_type=",mb->mb_type); |
/* DEBUG1("Switch bm_type=",mb->mb_type); */ |
1622 |
|
|
1623 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1624 |
BFRAME_DEBUG |
BFRAME_DEBUG |
1647 |
/ TRD |
/ TRD |
1648 |
: mb->mvs[i].y - last_mb->mvs[i].y); |
: mb->mvs[i].y - last_mb->mvs[i].y); |
1649 |
} |
} |
1650 |
//DEBUG("B-frame Direct!\n"); |
/* DEBUG("B-frame Direct!\n"); */ |
1651 |
} |
} |
1652 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1653 |
mb, x, y, bs); |
mb, x, y, bs); |
1665 |
|
|
1666 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1667 |
mb, x, y, bs); |
mb, x, y, bs); |
1668 |
//DEBUG("B-frame Bidir!\n"); |
/* DEBUG("B-frame Bidir!\n"); */ |
1669 |
break; |
break; |
1670 |
|
|
1671 |
case MODE_BACKWARD: |
case MODE_BACKWARD: |
1675 |
|
|
1676 |
mb->mode = MODE_INTER; |
mb->mode = MODE_INTER; |
1677 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
1678 |
//DEBUG("B-frame Backward!\n"); |
/* DEBUG("B-frame Backward!\n"); */ |
1679 |
break; |
break; |
1680 |
|
|
1681 |
case MODE_FORWARD: |
case MODE_FORWARD: |
1685 |
|
|
1686 |
mb->mode = MODE_INTER; |
mb->mode = MODE_INTER; |
1687 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
1688 |
//DEBUG("B-frame Forward!\n"); |
/* DEBUG("B-frame Forward!\n"); */ |
1689 |
break; |
break; |
1690 |
|
|
1691 |
default: |
default: |
1692 |
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); |
1693 |
} |
} |
1694 |
|
} /* End of for */ |
|
} // end of FOR |
|
1695 |
} |
} |
1696 |
|
|
1697 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1698 |
if (!first){ |
if (!first){ |
1699 |
first=1; |
first=1; |
1703 |
#endif |
#endif |
1704 |
} |
} |
1705 |
|
|
1706 |
// swap two MACROBLOCK array |
/* swap two MACROBLOCK array */ |
1707 |
void |
void |
1708 |
mb_swap(MACROBLOCK ** mb1, |
mb_swap(MACROBLOCK ** mb1, |
1709 |
MACROBLOCK ** mb2) |
MACROBLOCK ** mb2) |
1724 |
{ |
{ |
1725 |
/* note: image is stored to tmp */ |
/* note: image is stored to tmp */ |
1726 |
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1727 |
image_deblock_rrv(&dec->tmp, dec->edged_width, |
image_deblock(&dec->tmp, dec->edged_width, |
1728 |
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1729 |
8, frame->general); |
frame->general); |
1730 |
img = &dec->tmp; |
img = &dec->tmp; |
1731 |
} |
} |
1732 |
|
|
1749 |
uint32_t fcode_backward; |
uint32_t fcode_backward; |
1750 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
1751 |
WARPPOINTS gmc_warp; |
WARPPOINTS gmc_warp; |
1752 |
uint32_t vop_type; |
int vop_type; |
1753 |
int success = 0; |
int success = 0; |
1754 |
int output = 0; |
int output = 0; |
1755 |
int seen_something = 0; |
int seen_something = 0; |
1777 |
{ |
{ |
1778 |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1779 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1780 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1781 |
} |
} |
1782 |
|
|
1783 |
emms(); |
emms(); |
1788 |
|
|
1789 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1790 |
|
|
1791 |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
/* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */ |
1792 |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1793 |
{ |
{ |
1794 |
if (stats) |
if (stats) |
1838 |
goto repeat; |
goto repeat; |
1839 |
} |
} |
1840 |
|
|
1841 |
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 */ |
1842 |
|
|
1843 |
|
|
1844 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1968 |
{ |
{ |
1969 |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1970 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1971 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1972 |
} |
} |
1973 |
|
|
1974 |
emms(); |
emms(); |