40 |
#include "bitstream/bitstream.h" |
#include "bitstream/bitstream.h" |
41 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
42 |
|
|
43 |
#include "quant/quant_h263.h" |
#include "quant/quant.h" |
|
#include "quant/quant_mpeg4.h" |
|
44 |
#include "dct/idct.h" |
#include "dct/idct.h" |
45 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
46 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
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" |
56 |
|
#include "motion/gmc.h" |
57 |
|
|
58 |
#include "image/image.h" |
#include "image/image.h" |
59 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
168 |
{ |
{ |
169 |
DECODER *dec; |
DECODER *dec; |
170 |
|
|
171 |
if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
172 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
173 |
|
|
174 |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
326 |
|
|
327 |
start_timer(); |
start_timer(); |
328 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
329 |
dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
330 |
} else { |
} else { |
331 |
dequant4_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
332 |
} |
} |
333 |
stop_iquant_timer(); |
stop_iquant_timer(); |
334 |
|
|
532 |
|
|
533 |
start_timer(); |
start_timer(); |
534 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
535 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
536 |
} else { |
} else { |
537 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
538 |
} |
} |
539 |
stop_iquant_timer(); |
stop_iquant_timer(); |
540 |
|
|
583 |
stop_transfer_timer(); |
stop_transfer_timer(); |
584 |
} |
} |
585 |
|
|
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
|
|
{ |
|
|
int length = 1 << (fcode+4); |
|
|
|
|
|
/* if (quarterpel) value *= 2; */ |
|
|
|
|
|
if (value < -length) |
|
|
return -length; |
|
|
else if (value >= length) |
|
|
return length-1; |
|
|
else return value; |
|
|
} |
|
|
|
|
586 |
|
|
587 |
static void |
static void |
588 |
decoder_mbgmc(DECODER * dec, |
decoder_mbgmc(DECODER * dec, |
615 |
|
|
616 |
/* this is where the calculations are done */ |
/* this is where the calculations are done */ |
617 |
|
|
618 |
{ |
{ NEW_GMC_DATA * gmc_data = &dec->new_gmc_data; |
619 |
pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos, |
|
620 |
stride, stride2, dec->quarterpel, rounding, &dec->cur); |
gmc_data->predict_16x16(gmc_data, |
621 |
|
dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y, |
622 |
|
stride, stride, x_pos, y_pos, rounding); |
623 |
|
|
624 |
|
gmc_data->predict_8x8(gmc_data, |
625 |
|
dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u, |
626 |
|
dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v, |
627 |
|
stride2, stride2, x_pos, y_pos, rounding); |
628 |
|
|
629 |
|
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); |
657 |
|
|
658 |
start_timer(); |
start_timer(); |
659 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
660 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
661 |
} else { |
} else { |
662 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
663 |
} |
} |
664 |
stop_iquant_timer(); |
stop_iquant_timer(); |
665 |
|
|
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", |
|
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
|
862 |
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
863 |
dec->sprite_warping_points); |
dec->sprite_warping_points); |
864 |
} |
}*/ |
865 |
|
|
866 |
generate_GMCparameters( dec->sprite_warping_points, |
generate_GMCparameters( dec->sprite_warping_points, |
867 |
(2 << dec->sprite_warping_accuracy), gmc_warp, |
dec->sprite_warping_accuracy, gmc_warp, |
868 |
dec->width, dec->height, &dec->gmc_data); |
dec->width, dec->height, &dec->new_gmc_data); |
869 |
|
|
870 |
/* image warping is done block-based in decoder_mbgmc(), now */ |
/* image warping is done block-based in decoder_mbgmc(), now */ |
|
/* |
|
|
generate_GMCimage(&dec->gmc_data, &dec->refn[0], |
|
|
mb_width, mb_height, |
|
|
dec->edged_width, dec->edged_width/2, |
|
|
fcode, dec->quarterpel, 0, |
|
|
rounding, dec->mbs, &dec->gmc); |
|
|
*/ |
|
871 |
} |
} |
872 |
|
|
873 |
bound = 0; |
bound = 0; |
914 |
|
|
915 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
916 |
|
|
|
if (intra) { |
|
|
acpred_flag = BitstreamGetBit(bs); |
|
|
} |
|
|
|
|
917 |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
|
{ |
|
918 |
mcsel = BitstreamGetBit(bs); |
mcsel = BitstreamGetBit(bs); |
919 |
} |
|
920 |
|
if (intra) |
921 |
|
acpred_flag = BitstreamGetBit(bs); |
922 |
|
|
923 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
924 |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
939 |
mb->quant = quant; |
mb->quant = quant; |
940 |
|
|
941 |
if (dec->interlacing) { |
if (dec->interlacing) { |
942 |
if (cbp || intra) { |
if ((cbp || intra) && !mcsel) { |
943 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
944 |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
945 |
} |
} |
1204 |
|
|
1205 |
start_timer(); |
start_timer(); |
1206 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
1207 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
1208 |
} else { |
} else { |
1209 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
1210 |
} |
} |
1211 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1212 |
|
|
1444 |
|
|
1445 |
start_timer(); |
start_timer(); |
1446 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
1447 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
1448 |
} else { |
} else { |
1449 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
1450 |
} |
} |
1451 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1452 |
|
|
1599 |
quant = 1; |
quant = 1; |
1600 |
} |
} |
1601 |
} |
} |
1602 |
|
|
1603 |
|
if (dec->interlacing) { |
1604 |
|
if (mb->cbp) { |
1605 |
|
mb->field_dct = BitstreamGetBit(bs); |
1606 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
1607 |
|
} |
1608 |
|
|
1609 |
|
if (mb->mb_type) { |
1610 |
|
mb->field_pred = BitstreamGetBit(bs); |
1611 |
|
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
1612 |
|
|
1613 |
|
if (mb->field_pred) { |
1614 |
|
mb->field_for_top = BitstreamGetBit(bs); |
1615 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
1616 |
|
mb->field_for_bot = BitstreamGetBit(bs); |
1617 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
1618 |
|
} |
1619 |
|
} |
1620 |
|
} |
1621 |
|
|
1622 |
} else { |
} else { |
1623 |
mb->mb_type = MODE_DIRECT_NONE_MV; |
mb->mb_type = MODE_DIRECT_NONE_MV; |
1624 |
mb->cbp = 0; |
mb->cbp = 0; |
1747 |
WARPPOINTS gmc_warp; |
WARPPOINTS gmc_warp; |
1748 |
int coding_type; |
int coding_type; |
1749 |
int success, output, seen_something; |
int success, output, seen_something; |
|
idctFuncPtr idct_save; |
|
1750 |
|
|
1751 |
if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
1752 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
1753 |
|
|
1754 |
start_global_timer(); |
start_global_timer(); |
1792 |
success = 0; |
success = 0; |
1793 |
output = 0; |
output = 0; |
1794 |
seen_something = 0; |
seen_something = 0; |
|
idct_save = idct; |
|
1795 |
|
|
1796 |
repeat: |
repeat: |
1797 |
|
|
1833 |
|
|
1834 |
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 */ |
1835 |
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
/* |
|
|
* /!\ Ugly hack /!\ |
|
|
* IA32: Prior to xvid bitstream 10, we were using Walten's mmx/xmm idct |
|
|
*/ |
|
|
if((idct == simple_idct_mmx) && (dec->bs_version < 10)) |
|
|
idct = idct_mmx; |
|
|
#endif |
|
|
|
|
1836 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1837 |
if (dec->packed_mode && coding_type == N_VOP) |
if (dec->packed_mode && coding_type == N_VOP) |
1838 |
{ |
{ |
1961 |
emms(); |
emms(); |
1962 |
stop_global_timer(); |
stop_global_timer(); |
1963 |
|
|
|
idct = idct_save; |
|
|
|
|
1964 |
return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
1965 |
} |
} |