3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Decoder Module - |
* - Decoder Module - |
5 |
* |
* |
6 |
* Copyright(C) 2002 MinChen <chenm001@163.com> |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
|
* 2002-2003 Peter Ross <pross@xvid.org> |
|
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 |
53 |
#include "utils/timer.h" |
#include "utils/timer.h" |
54 |
#include "utils/emms.h" |
#include "utils/emms.h" |
55 |
#include "motion/motion.h" |
#include "motion/motion.h" |
|
#include "motion/gmc.h" |
|
56 |
|
|
57 |
#include "image/image.h" |
#include "image/image.h" |
58 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
158 |
|
|
159 |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
160 |
|
|
161 |
return 0; |
return XVID_ERR_OK; |
162 |
} |
} |
163 |
|
|
164 |
|
|
165 |
int |
int |
166 |
decoder_create(xvid_dec_create_t * create) |
decoder_create(XVID_DEC_PARAM * param) |
167 |
{ |
{ |
168 |
DECODER *dec; |
DECODER *dec; |
169 |
|
|
|
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
|
|
return XVID_ERR_VERSION; |
|
|
|
|
170 |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
171 |
if (dec == NULL) { |
if (dec == NULL) { |
172 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
173 |
} |
} |
174 |
memset(dec, 0, sizeof(DECODER)); |
memset(dec, 0, sizeof(DECODER)); |
175 |
|
|
176 |
create->handle = dec; |
param->handle = dec; |
177 |
|
|
178 |
dec->width = create->width; |
dec->width = param->width; |
179 |
dec->height = create->height; |
dec->height = param->height; |
180 |
|
|
181 |
image_null(&dec->cur); |
image_null(&dec->cur); |
182 |
image_null(&dec->refn[0]); |
image_null(&dec->refn[0]); |
204 |
if (dec->fixed_dimensions) |
if (dec->fixed_dimensions) |
205 |
return decoder_resize(dec); |
return decoder_resize(dec); |
206 |
else |
else |
207 |
return 0; |
return XVID_ERR_OK; |
208 |
} |
} |
209 |
|
|
210 |
|
|
225 |
xvid_free(dec); |
xvid_free(dec); |
226 |
|
|
227 |
write_timer(); |
write_timer(); |
228 |
return 0; |
return XVID_ERR_OK; |
229 |
} |
} |
230 |
|
|
231 |
|
|
301 |
block[i * 64 + 0] = dc_dif; |
block[i * 64 + 0] = dc_dif; |
302 |
start_coeff = 1; |
start_coeff = 1; |
303 |
|
|
304 |
DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif); |
DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif); |
305 |
} else { |
} else { |
306 |
start_coeff = 0; |
start_coeff = 0; |
307 |
} |
} |
579 |
stop_transfer_timer(); |
stop_transfer_timer(); |
580 |
} |
} |
581 |
|
|
582 |
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
583 |
|
{ |
584 |
|
int length = 1 << (fcode+4); |
585 |
|
|
586 |
|
/* if (quarterpel) value *= 2; */ |
587 |
|
|
588 |
|
if (value < -length) |
589 |
|
return -length; |
590 |
|
else if (value >= length) |
591 |
|
return length-1; |
592 |
|
else return value; |
593 |
|
} |
594 |
|
|
595 |
|
|
596 |
static void |
static void |
597 |
decoder_mbgmc(DECODER * dec, |
decoder_mbgmc(DECODER * dec, |
624 |
|
|
625 |
/* this is where the calculations are done */ |
/* this is where the calculations are done */ |
626 |
|
|
627 |
{ NEW_GMC_DATA * gmc_data = &dec->new_gmc_data; |
{ |
628 |
|
pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos, |
629 |
gmc_data->predict_16x16(gmc_data, |
stride, stride2, dec->quarterpel, rounding, &dec->cur); |
|
dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y, |
|
|
stride, stride, x_pos, y_pos, rounding); |
|
|
|
|
|
gmc_data->predict_8x8(gmc_data, |
|
|
dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u, |
|
|
dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v, |
|
|
stride2, stride2, x_pos, y_pos, rounding); |
|
|
|
|
|
gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel); |
|
630 |
|
|
631 |
pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
632 |
pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); |
pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); |
734 |
} |
} |
735 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
736 |
|
|
737 |
DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
738 |
|
|
739 |
mcbpc = get_mcbpc_intra(bs); |
mcbpc = get_mcbpc_intra(bs); |
740 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
761 |
|
|
762 |
if (dec->interlacing) { |
if (dec->interlacing) { |
763 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
764 |
DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct); |
DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
765 |
} |
} |
766 |
|
|
767 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
799 |
mv.x = get_mv(bs, fcode); |
mv.x = get_mv(bs, fcode); |
800 |
mv.y = get_mv(bs, fcode); |
mv.y = get_mv(bs, fcode); |
801 |
|
|
802 |
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); |
803 |
|
|
804 |
mv.x += pmv.x; |
mv.x += pmv.x; |
805 |
mv.y += pmv.y; |
mv.y += pmv.y; |
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) ) |
861 |
fprintf(stderr,"GMC parameters acc=%d(-> 1/%d), %d pts!!!\n", |
{ |
862 |
|
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
863 |
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
864 |
dec->sprite_warping_points); |
dec->sprite_warping_points); |
865 |
}*/ |
} |
866 |
|
|
867 |
generate_GMCparameters( dec->sprite_warping_points, |
generate_GMCparameters( dec->sprite_warping_points, |
868 |
dec->sprite_warping_accuracy, gmc_warp, |
(2 << dec->sprite_warping_accuracy), gmc_warp, |
869 |
dec->width, dec->height, &dec->new_gmc_data); |
dec->width, dec->height, &dec->gmc_data); |
870 |
|
|
871 |
/* image warping is done block-based in decoder_mbgmc(), now */ |
/* image warping is done block-based in decoder_mbgmc(), now */ |
872 |
|
/* |
873 |
|
generate_GMCimage(&dec->gmc_data, &dec->refn[0], |
874 |
|
mb_width, mb_height, |
875 |
|
dec->edged_width, dec->edged_width/2, |
876 |
|
fcode, dec->quarterpel, 0, |
877 |
|
rounding, dec->mbs, &dec->gmc); |
878 |
|
*/ |
879 |
} |
} |
880 |
|
|
881 |
bound = 0; |
bound = 0; |
898 |
} |
} |
899 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
900 |
|
|
901 |
DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", 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 */ |
916 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
917 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
918 |
|
|
919 |
DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode); |
DPRINTF(DPRINTF_MB, "mode %i", mb->mode); |
920 |
DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc); |
DPRINTF(DPRINTF_MB, "cbpc %i", cbpc); |
921 |
acpred_flag = 0; |
acpred_flag = 0; |
922 |
|
|
923 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
924 |
|
|
925 |
|
if (intra) { |
926 |
|
acpred_flag = BitstreamGetBit(bs); |
927 |
|
} |
928 |
|
|
929 |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
930 |
|
{ |
931 |
mcsel = BitstreamGetBit(bs); |
mcsel = BitstreamGetBit(bs); |
932 |
|
} |
|
if (intra) |
|
|
acpred_flag = BitstreamGetBit(bs); |
|
933 |
|
|
934 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
935 |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
DPRINTF(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); |
936 |
|
|
937 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
938 |
|
|
939 |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
940 |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
941 |
DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant); |
DPRINTF(DPRINTF_MB, "dquant %i", dquant); |
942 |
quant += dquant; |
quant += dquant; |
943 |
if (quant > 31) { |
if (quant > 31) { |
944 |
quant = 31; |
quant = 31; |
945 |
} else if (quant < 1) { |
} else if (quant < 1) { |
946 |
quant = 1; |
quant = 1; |
947 |
} |
} |
948 |
DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant); |
DPRINTF(DPRINTF_MB, "quant %i", quant); |
949 |
} |
} |
950 |
mb->quant = quant; |
mb->quant = quant; |
951 |
|
|
952 |
if (dec->interlacing) { |
if (dec->interlacing) { |
953 |
if (cbp || intra) { |
if (cbp || intra) { |
954 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
955 |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
956 |
} |
} |
957 |
|
|
958 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
959 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
960 |
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
961 |
|
|
962 |
if (mb->field_pred) { |
if (mb->field_pred) { |
963 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
964 |
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); |
965 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
966 |
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); |
967 |
} |
} |
968 |
} |
} |
969 |
} |
} |
1688 |
break; |
break; |
1689 |
|
|
1690 |
default: |
default: |
1691 |
DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", 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 |
} |
} |
1702 |
#endif |
#endif |
1703 |
} |
} |
1704 |
|
|
1705 |
|
/* swap two MACROBLOCK array */ |
1706 |
|
void |
1707 |
|
mb_swap(MACROBLOCK ** mb1, |
1708 |
|
MACROBLOCK ** mb2) |
1709 |
|
{ |
1710 |
|
MACROBLOCK *temp = *mb1; |
1711 |
|
|
1712 |
|
*mb1 = *mb2; |
1713 |
|
*mb2 = temp; |
1714 |
|
} |
1715 |
|
|
1716 |
|
|
1717 |
/* perform post processing if necessary, and output the image */ |
/* perform post processing if necessary, and output the image */ |
1718 |
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1719 |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) |
const XVID_DEC_FRAME * frame, int pp_disable) |
1720 |
{ |
{ |
1721 |
|
|
1722 |
|
if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable) /* post process */ |
|
image_output(img, dec->width, dec->height, |
|
|
dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
|
|
frame->output.csp, dec->interlacing); |
|
|
|
|
|
if (stats) |
|
1723 |
{ |
{ |
1724 |
stats->type = coding2type(coding_type); |
/* note: image is stored to tmp */ |
1725 |
stats->data.vop.time_base = (int)dec->time_base; |
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1726 |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
image_deblock_rrv(&dec->tmp, dec->edged_width, |
1727 |
|
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1728 |
|
8, frame->general); |
1729 |
|
img = &dec->tmp; |
1730 |
} |
} |
1731 |
|
|
1732 |
|
image_output(img, dec->width, dec->height, |
1733 |
|
dec->edged_width, frame->image, frame->stride, |
1734 |
|
frame->colorspace, dec->interlacing); |
1735 |
} |
} |
1736 |
|
|
1737 |
|
|
1738 |
int |
int |
1739 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1740 |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
1741 |
{ |
{ |
1742 |
|
|
1743 |
Bitstream bs; |
Bitstream bs; |
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 |
int coding_type; |
int vop_type; |
1752 |
int success, output, seen_something; |
int success = 0; |
1753 |
|
int output = 0; |
1754 |
if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
int seen_something = 0; |
1755 |
return XVID_ERR_VERSION; |
idctFuncPtr idct_save = idct; |
1756 |
|
|
1757 |
start_global_timer(); |
start_global_timer(); |
1758 |
|
|
1759 |
dec->low_delay_default = (frame->general & XVID_LOWDELAY); |
dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY); |
1760 |
if ((frame->general & XVID_DISCONTINUITY)) |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1761 |
|
|
1762 |
|
if ((frame->general & XVID_DEC_DISCONTINUITY)) |
1763 |
dec->frames = 0; |
dec->frames = 0; |
|
dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL; |
|
1764 |
|
|
1765 |
if (frame->length < 0) /* decoder flush */ |
if (frame->length < 0) /* decoder flush */ |
1766 |
{ |
{ |
|
int ret; |
|
1767 |
/* 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 |
1768 |
we have a reference frame, then outout the reference frame */ |
we have a reference frame, then outout the reference frame */ |
1769 |
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) |
1770 |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
{ |
1771 |
dec->frames = 0; |
decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution); |
1772 |
ret = 0; |
output = 1; |
1773 |
}else{ |
} |
1774 |
if (stats) stats->type = XVID_TYPE_NOTHING; |
|
1775 |
ret = XVID_ERR_END; |
frame->length = 0; |
1776 |
|
if (stats) |
1777 |
|
{ |
1778 |
|
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1779 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1780 |
|
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1781 |
} |
} |
1782 |
|
|
1783 |
emms(); |
emms(); |
1784 |
|
|
1785 |
stop_global_timer(); |
stop_global_timer(); |
1786 |
return ret; |
return XVID_ERR_OK; |
1787 |
} |
} |
1788 |
|
|
1789 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
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) |
1795 |
|
stats->notify = XVID_DEC_VOP; |
1796 |
|
frame->length = 1; |
1797 |
image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width, |
image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width, |
1798 |
(uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing); |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
|
if (stats) stats->type = XVID_TYPE_NOTHING; |
|
1799 |
emms(); |
emms(); |
1800 |
return 1; /* one byte consumed */ |
return XVID_ERR_OK; |
1801 |
} |
} |
1802 |
|
|
|
success = 0; |
|
|
output = 0; |
|
|
seen_something = 0; |
|
|
|
|
1803 |
repeat: |
repeat: |
1804 |
|
|
1805 |
coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
vop_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1806 |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
1807 |
|
|
1808 |
DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i\n", |
DPRINTF(DPRINTF_HEADER, "vop_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i", |
1809 |
coding_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
vop_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1810 |
|
|
1811 |
if (coding_type == -1) /* nothing */ |
if (vop_type == -1) |
1812 |
{ |
{ |
1813 |
if (success) goto done; |
if (success) goto done; |
|
if (stats) stats->type = XVID_TYPE_NOTHING; |
|
1814 |
emms(); |
emms(); |
1815 |
return BitstreamPos(&bs)/8; |
return XVID_ERR_FAIL; |
1816 |
} |
} |
1817 |
|
|
1818 |
if (coding_type == -2 || coding_type == -3) /* vol and/or resize */ |
if (vop_type == -2 || vop_type == -3) |
1819 |
{ |
{ |
1820 |
if (coding_type == -3) |
if (vop_type == -3) |
1821 |
decoder_resize(dec); |
decoder_resize(dec); |
1822 |
|
|
1823 |
if (stats) |
if (stats) |
1824 |
{ |
{ |
1825 |
stats->type = XVID_TYPE_VOL; |
stats->notify = XVID_DEC_VOL; |
1826 |
stats->data.vol.general = 0; |
stats->data.vol.general = 0; |
1827 |
/*XXX: if (dec->interlacing) |
if (dec->interlacing) |
1828 |
stats->data.vol.general |= ++INTERLACING; */ |
stats->data.vol.general |= XVID_INTERLACING; |
1829 |
stats->data.vol.width = dec->width; |
stats->data.vol.width = dec->width; |
1830 |
stats->data.vol.height = dec->height; |
stats->data.vol.height = dec->height; |
1831 |
stats->data.vol.par = dec->aspect_ratio; |
stats->data.vol.aspect_ratio = dec->aspect_ratio; |
1832 |
stats->data.vol.par_width = dec->par_width; |
stats->data.vol.par_width = dec->par_width; |
1833 |
stats->data.vol.par_height = dec->par_height; |
stats->data.vol.par_height = dec->par_height; |
1834 |
|
frame->length = BitstreamPos(&bs) / 8; |
1835 |
emms(); |
emms(); |
1836 |
return BitstreamPos(&bs)/8; /* number of bytes consumed */ |
return XVID_ERR_OK; |
1837 |
} |
} |
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 |
|
if((idct == simple_idct_mmx) && (dec->bs_version < 10)) /* rather ugly but should work */ |
1844 |
|
idct = idct_mmx; |
1845 |
|
|
1846 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1847 |
if (dec->packed_mode && coding_type == N_VOP) |
if (dec->packed_mode && vop_type == N_VOP) |
1848 |
{ |
{ |
1849 |
if (dec->low_delay_default && dec->frames > 0) |
if (dec->low_delay_default && dec->frames > 0) |
1850 |
{ |
{ |
1851 |
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, dec->last_reduced_resolution); |
1852 |
output = 1; |
output = 1; |
1853 |
} |
} |
1854 |
/* ignore otherwise */ |
/* ignore otherwise */ |
1855 |
} |
} |
1856 |
else if (coding_type != B_VOP) |
else if (vop_type != B_VOP) |
1857 |
{ |
{ |
1858 |
switch(coding_type) |
switch(vop_type) |
1859 |
{ |
{ |
1860 |
case I_VOP : |
case I_VOP : |
1861 |
decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); |
1869 |
fcode_forward, intra_dc_threshold, &gmc_warp); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1870 |
break; |
break; |
1871 |
case N_VOP : |
case N_VOP : |
|
/* XXX: not_coded vops are not used for forward prediction */ |
|
|
/* we should not swap(last_mbs,mbs) */ |
|
1872 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1873 |
break; |
break; |
1874 |
} |
} |
1877 |
{ |
{ |
1878 |
image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
1879 |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, |
1880 |
16, 0); |
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1881 |
} |
} |
1882 |
|
|
1883 |
/* 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 */ |
1885 |
{ |
{ |
1886 |
if (dec->low_delay) |
if (dec->low_delay) |
1887 |
{ |
{ |
1888 |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1889 |
output = 1; |
output = 1; |
1890 |
} |
} |
1891 |
else if (dec->frames > 0) /* is the reference frame valid? */ |
else if (dec->frames > 0) /* is the reference frame valid? */ |
1892 |
{ |
{ |
1893 |
/* output the reference frame */ |
/* output the reference frame */ |
1894 |
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, dec->last_reduced_resolution); |
1895 |
output = 1; |
output = 1; |
1896 |
} |
} |
1897 |
} |
} |
1898 |
|
|
1899 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1900 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1901 |
SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1902 |
dec->last_reduced_resolution = reduced_resolution; |
dec->last_reduced_resolution = reduced_resolution; |
|
dec->last_coding_type = coding_type; |
|
1903 |
|
|
1904 |
dec->frames++; |
dec->frames++; |
1905 |
seen_something = 1; |
seen_something = 1; |
1908 |
|
|
1909 |
if (dec->low_delay) |
if (dec->low_delay) |
1910 |
{ |
{ |
1911 |
DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); |
1912 |
dec->low_delay = 1; |
dec->low_delay = 1; |
1913 |
} |
} |
1914 |
|
|
1926 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1927 |
} |
} |
1928 |
|
|
1929 |
decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1930 |
output = 1; |
output = 1; |
1931 |
dec->frames++; |
dec->frames++; |
1932 |
} |
} |
1949 |
if (dec->packed_mode && seen_something) |
if (dec->packed_mode && seen_something) |
1950 |
{ |
{ |
1951 |
/* output the recently decoded frame */ |
/* output the recently decoded frame */ |
1952 |
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, dec->last_reduced_resolution); |
1953 |
|
output = 1; |
1954 |
} |
} |
1955 |
else |
else |
1956 |
{ |
{ |
1960 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
1961 |
"bframe decoder lag"); |
"bframe decoder lag"); |
1962 |
|
|
1963 |
decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP); |
decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/); |
1964 |
if (stats) stats->type = XVID_TYPE_NOTHING; |
} |
|
|
|
1965 |
} |
} |
1966 |
|
|
1967 |
|
idct = idct_save; |
1968 |
|
|
1969 |
|
frame->length = BitstreamPos(&bs) / 8; |
1970 |
|
|
1971 |
|
if (stats) |
1972 |
|
{ |
1973 |
|
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1974 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1975 |
|
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1976 |
} |
} |
1977 |
|
|
1978 |
emms(); |
emms(); |
1979 |
|
|
1980 |
stop_global_timer(); |
stop_global_timer(); |
1981 |
|
|
1982 |
return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
return XVID_ERR_OK; |
1983 |
} |
} |