20 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: decoder.c,v 1.49.2.21 2003-12-09 14:31:40 syskin Exp $ |
* $Id: decoder.c,v 1.49.2.28 2003-12-21 19:41:53 Isibaar Exp $ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
58 |
|
|
59 |
#include "image/image.h" |
#include "image/image.h" |
60 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
61 |
|
#include "image/postprocessing.h" |
62 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
63 |
|
|
64 |
static int |
static int |
205 |
dec->last_mbs = NULL; |
dec->last_mbs = NULL; |
206 |
|
|
207 |
init_timer(); |
init_timer(); |
208 |
|
init_postproc(&dec->postproc); |
209 |
init_mpeg_matrix(dec->mpeg_quant_matrices); |
init_mpeg_matrix(dec->mpeg_quant_matrices); |
210 |
|
|
211 |
/* For B-frame support (used to save reference frame's time */ |
/* For B-frame support (used to save reference frame's time */ |
1316 |
|
|
1317 |
/* perform post processing if necessary, and output the image */ |
/* perform post processing if necessary, and output the image */ |
1318 |
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1319 |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, |
1320 |
|
int coding_type, int quant) |
1321 |
{ |
{ |
1322 |
|
if (dec->cartoon_mode) |
1323 |
|
frame->general &= ~XVID_FILMEFFECT; |
1324 |
|
|
1325 |
|
if (frame->general & (XVID_DEBLOCKY|XVID_DEBLOCKUV|XVID_FILMEFFECT) && mbs != NULL) /* post process */ |
1326 |
|
{ |
1327 |
|
/* note: image is stored to tmp */ |
1328 |
|
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1329 |
|
image_postproc(&dec->postproc, &dec->tmp, dec->edged_width, |
1330 |
|
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1331 |
|
frame->general, dec->frames, (coding_type == B_VOP)); |
1332 |
|
img = &dec->tmp; |
1333 |
|
} |
1334 |
|
|
1335 |
image_output(img, dec->width, dec->height, |
image_output(img, dec->width, dec->height, |
1336 |
dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
1337 |
frame->output.csp, dec->interlacing); |
frame->output.csp, dec->interlacing); |
1375 |
/* if not decoding "low_delay/packed", and this isn't low_delay and |
/* if not decoding "low_delay/packed", and this isn't low_delay and |
1376 |
we have a reference frame, then outout the reference frame */ |
we have a reference frame, then outout the reference frame */ |
1377 |
if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) { |
if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) { |
1378 |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); |
1379 |
dec->frames = 0; |
dec->frames = 0; |
1380 |
ret = 0; |
ret = 0; |
1381 |
} else { |
} else { |
1445 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1446 |
if (dec->packed_mode && coding_type == N_VOP) { |
if (dec->packed_mode && coding_type == N_VOP) { |
1447 |
if (dec->low_delay_default && dec->frames > 0) { |
if (dec->low_delay_default && dec->frames > 0) { |
1448 |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); |
1449 |
output = 1; |
output = 1; |
1450 |
} |
} |
1451 |
/* ignore otherwise */ |
/* ignore otherwise */ |
1466 |
/* XXX: not_coded vops are not used for forward prediction */ |
/* XXX: not_coded vops are not used for forward prediction */ |
1467 |
/* we should not swap(last_mbs,mbs) */ |
/* we should not swap(last_mbs,mbs) */ |
1468 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1469 |
|
SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); /* it will be swapped back */ |
1470 |
break; |
break; |
1471 |
} |
} |
1472 |
|
|
1479 |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
1480 |
if (!(dec->low_delay_default && dec->packed_mode)) { |
if (!(dec->low_delay_default && dec->packed_mode)) { |
1481 |
if (dec->low_delay) { |
if (dec->low_delay) { |
1482 |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); |
1483 |
output = 1; |
output = 1; |
1484 |
} else if (dec->frames > 0) { /* is the reference frame valid? */ |
} else if (dec->frames > 0) { /* is the reference frame valid? */ |
1485 |
/* output the reference frame */ |
/* output the reference frame */ |
1486 |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); |
1487 |
output = 1; |
output = 1; |
1488 |
} |
} |
1489 |
} |
} |
1517 |
stats->type = XVID_TYPE_NOTHING; |
stats->type = XVID_TYPE_NOTHING; |
1518 |
} else { |
} else { |
1519 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1520 |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type, quant); |
1521 |
} |
} |
1522 |
|
|
1523 |
output = 1; |
output = 1; |
1539 |
if (dec->low_delay_default && output == 0) { |
if (dec->low_delay_default && output == 0) { |
1540 |
if (dec->packed_mode && seen_something) { |
if (dec->packed_mode && seen_something) { |
1541 |
/* output the recently decoded frame */ |
/* output the recently decoded frame */ |
1542 |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type, quant); |
1543 |
} else { |
} else { |
1544 |
image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
1545 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1547 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
1548 |
"bframe decoder lag"); |
"bframe decoder lag"); |
1549 |
|
|
1550 |
decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP); |
decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP, quant); |
1551 |
if (stats) stats->type = XVID_TYPE_NOTHING; |
if (stats) stats->type = XVID_TYPE_NOTHING; |
1552 |
} |
} |
1553 |
} |
} |