32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 10.07.2002 added BFRAMES_DEC_DEBUG support |
36 |
|
* Fix a little bug for low_delay flage |
37 |
|
* MinChen <chenm001@163.com> |
38 |
* 28.06.2002 added basic resync support to iframe/pframe_decode() |
* 28.06.2002 added basic resync support to iframe/pframe_decode() |
39 |
* 22.06.2002 added primative N_VOP support |
* 22.06.2002 added primative N_VOP support |
40 |
* #define BFRAMES_DEC now enables Minchenm's bframe decoder |
* #define BFRAMES_DEC now enables Minchen's bframe decoder |
41 |
* 08.05.2002 add low_delay support for B_VOP decode |
* 08.05.2002 add low_delay support for B_VOP decode |
42 |
* MinChen <chenm001@163.com> |
* MinChen <chenm001@163.com> |
43 |
* 05.05.2002 fix some B-frame decode problem |
* 05.05.2002 fix some B-frame decode problem |
53 |
* 22.12.2001 lock based interpolation |
* 22.12.2001 lock based interpolation |
54 |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
55 |
* |
* |
56 |
* $Id: decoder.c,v 1.26 2002-07-09 01:37:22 chenm001 Exp $ |
* $Id: decoder.c,v 1.27 2002-07-11 00:15:59 chenm001 Exp $ |
57 |
* |
* |
58 |
*************************************************************************/ |
*************************************************************************/ |
59 |
|
|
60 |
#include <stdlib.h> |
#include <stdlib.h> |
61 |
#include <string.h> |
#include <string.h> |
62 |
|
|
63 |
|
#ifdef BFRAMES_DEC_DEBUG |
64 |
|
#define BFRAMES_DEC |
65 |
|
#endif |
66 |
|
|
67 |
#include "xvid.h" |
#include "xvid.h" |
68 |
#include "portab.h" |
#include "portab.h" |
69 |
|
|
1089 |
|
|
1090 |
uint32_t x, y; |
uint32_t x, y; |
1091 |
VECTOR mv, zeromv; |
VECTOR mv, zeromv; |
1092 |
|
#ifdef BFRAMES_DEC_DEBUG |
1093 |
|
FILE *fp; |
1094 |
|
static char first=0; |
1095 |
|
#define BFRAME_DEBUG if (!first && fp){ \ |
1096 |
|
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \ |
1097 |
|
} |
1098 |
|
#endif |
1099 |
|
|
1100 |
start_timer(); |
start_timer(); |
1101 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1103 |
//image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
//image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
1104 |
stop_edges_timer(); |
stop_edges_timer(); |
1105 |
|
|
1106 |
|
#ifdef BFRAMES_DEC_DEBUG |
1107 |
|
if (!first){ |
1108 |
|
fp=fopen("C:\\XVIDDBG.TXT","w"); |
1109 |
|
} |
1110 |
|
#endif |
1111 |
|
|
1112 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1113 |
// Initialize Pred Motion Vector |
// Initialize Pred Motion Vector |
1116 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
1117 |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
1118 |
|
|
1119 |
mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = |
mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = 0; |
|
0; |
|
1120 |
|
|
1121 |
// the last P_VOP is skip macroblock ? |
// the last P_VOP is skip macroblock ? |
1122 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1123 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
1124 |
mb->mb_type = MODE_FORWARD; |
mb->mb_type = MODE_NOT_CODED; |
1125 |
mb->cbp = 0; |
mb->cbp = 0; |
1126 |
|
#ifdef BFRAMES_DEC_DEBUG |
1127 |
|
BFRAME_DEBUG |
1128 |
|
#endif |
1129 |
|
mb->mb_type = MODE_FORWARD; |
1130 |
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 = mb->mvs[0].x; |
1131 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
1132 |
mb->quant = 8; |
mb->quant = 8; |
1166 |
mb->mode = MODE_INTER; |
mb->mode = MODE_INTER; |
1167 |
//DEBUG1("Switch bm_type=",mb->mb_type); |
//DEBUG1("Switch bm_type=",mb->mb_type); |
1168 |
|
|
1169 |
|
#ifdef BFRAMES_DEC_DEBUG |
1170 |
|
BFRAME_DEBUG |
1171 |
|
#endif |
1172 |
switch (mb->mb_type) { |
switch (mb->mb_type) { |
1173 |
case MODE_DIRECT: |
case MODE_DIRECT: |
1174 |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], 1, zeromv); |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], 1, zeromv); |
1249 |
break; |
break; |
1250 |
|
|
1251 |
default: |
default: |
1252 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
//DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
1253 |
|
; |
1254 |
} |
} |
1255 |
|
|
1256 |
} // end of FOR |
} // end of FOR |
1257 |
} |
} |
1258 |
|
#ifdef BFRAMES_DEC_DEBUG |
1259 |
|
if (!first){ |
1260 |
|
first=1; |
1261 |
|
if (fp) |
1262 |
|
fclose(fp); |
1263 |
|
} |
1264 |
|
#endif |
1265 |
} |
} |
1266 |
|
|
1267 |
// swap two MACROBLOCK array |
// swap two MACROBLOCK array |
1339 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1340 |
} |
} |
1341 |
|
|
1342 |
|
if (frame->length != BitstreamPos(&bs) / 8){ |
1343 |
|
DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); |
1344 |
|
} |
1345 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1346 |
|
|
1347 |
|
|
1348 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1349 |
// test if no B_VOP |
// test if no B_VOP |
1350 |
if (dec->low_delay) { |
if (dec->low_delay) { |
1351 |
#endif |
#endif |
1352 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
1353 |
frame->image, frame->stride, frame->colorspace); |
frame->image, frame->stride, frame->colorspace); |
1354 |
|
|
1355 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1356 |
} else { |
} else { |
1357 |
if (dec->frames >= 1) { |
if (dec->frames >= 0) { |
1358 |
start_timer(); |
start_timer(); |
1359 |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
1360 |
image_output(&dec->refn[0], dec->width, dec->height, |
image_output(&dec->refn[0], dec->width, dec->height, |
1374 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1375 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1376 |
// swap MACROBLOCK |
// swap MACROBLOCK |
1377 |
if (dec->low_delay && vop_type == P_VOP) |
if (!dec->low_delay && vop_type == P_VOP) |
1378 |
mb_swap(&dec->mbs, &dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1379 |
} |
} |
1380 |
|
|