3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Decoder Module - |
* - Decoder Module - |
5 |
* |
* |
6 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
* Copyright(C) 2002 MinChen <chenm001@163.com> |
7 |
|
* 2002-2003 Peter Ross <pross@xvid.org> |
8 |
* |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
10 |
* 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 |
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); |
305 |
block[i * 64 + 0] = dc_dif; |
block[i * 64 + 0] = dc_dif; |
306 |
start_coeff = 1; |
start_coeff = 1; |
307 |
|
|
308 |
DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif); |
DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif); |
309 |
} else { |
} else { |
310 |
start_coeff = 0; |
start_coeff = 0; |
311 |
} |
} |
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 |
|
|
734 |
} |
} |
735 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
736 |
|
|
737 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", 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(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", 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(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); |
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); |
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", |
|
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; |
890 |
} |
} |
891 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
892 |
|
|
893 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); |
894 |
|
|
895 |
/* 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 */ |
896 |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
908 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
909 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
910 |
|
|
911 |
DPRINTF(DPRINTF_MB, "mode %i", mb->mode); |
DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode); |
912 |
DPRINTF(DPRINTF_MB, "cbpc %i", cbpc); |
DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc); |
913 |
acpred_flag = 0; |
acpred_flag = 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(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
925 |
|
|
926 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
927 |
|
|
928 |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
929 |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
930 |
DPRINTF(DPRINTF_MB, "dquant %i", dquant); |
DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant); |
931 |
quant += dquant; |
quant += dquant; |
932 |
if (quant > 31) { |
if (quant > 31) { |
933 |
quant = 31; |
quant = 31; |
934 |
} else if (quant < 1) { |
} else if (quant < 1) { |
935 |
quant = 1; |
quant = 1; |
936 |
} |
} |
937 |
DPRINTF(DPRINTF_MB, "quant %i", quant); |
DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant); |
938 |
} |
} |
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(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
945 |
} |
} |
946 |
|
|
947 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
948 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
949 |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
950 |
|
|
951 |
if (mb->field_pred) { |
if (mb->field_pred) { |
952 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
953 |
DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); |
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
954 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
955 |
DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); |
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
956 |
} |
} |
957 |
} |
} |
958 |
} |
} |
1138 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1139 |
|
|
1140 |
|
|
|
if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
|
1141 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1142 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1143 |
|
|
1144 |
if (dec->quarterpel) |
if (dec->quarterpel) { |
|
{ |
|
1145 |
uv_dx /= 2; |
uv_dx /= 2; |
1146 |
uv_dy /= 2; |
uv_dy /= 2; |
1147 |
} |
} |
1148 |
|
|
1149 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1150 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
|
} else { |
|
|
int sum; |
|
|
|
|
|
if(dec->quarterpel) |
|
|
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
|
|
else |
|
|
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
|
|
|
|
|
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
|
|
|
|
if(dec->quarterpel) |
|
|
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
|
|
else |
|
|
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
|
|
|
|
|
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
|
} |
|
1151 |
|
|
1152 |
start_timer(); |
start_timer(); |
1153 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1154 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, |
1155 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1156 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1157 |
} |
} else { |
|
else { |
|
1158 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos, |
1159 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1160 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos, |
1161 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1162 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8, |
1163 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1164 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8, |
1165 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1166 |
} |
} |
1167 |
|
|
1168 |
interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, |
1174 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1175 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1176 |
|
|
1177 |
if (cbp & (1 << (5 - i))) /* coded */ |
if (cbp & (1 << (5 - i))) { /* coded */ |
1178 |
{ |
|
1179 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1180 |
|
|
1181 |
start_timer(); |
start_timer(); |
1183 |
stop_coding_timer(); |
stop_coding_timer(); |
1184 |
|
|
1185 |
start_timer(); |
start_timer(); |
1186 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) |
1187 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
1188 |
} else { |
else |
1189 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
1190 |
} |
|
1191 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1192 |
|
|
1193 |
start_timer(); |
start_timer(); |
1217 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1218 |
} |
} |
1219 |
|
|
1220 |
/* decode an B-frame direct & inter macroblock */ |
/* decode an B-frame direct & interpolate macroblock */ |
1221 |
void |
void |
1222 |
decoder_bf_interpolate_mbinter(DECODER * dec, |
decoder_bf_interpolate_mbinter(DECODER * dec, |
1223 |
IMAGE forward, |
IMAGE forward, |
1225 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
1226 |
const uint32_t x_pos, |
const uint32_t x_pos, |
1227 |
const uint32_t y_pos, |
const uint32_t y_pos, |
1228 |
Bitstream * bs) |
Bitstream * bs, |
1229 |
|
const int direct) |
1230 |
{ |
{ |
1231 |
|
|
1232 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
1247 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1248 |
|
|
1249 |
|
|
1250 |
if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
if (!direct) { |
1251 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1252 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1253 |
|
|
1304 |
|
|
1305 |
start_timer(); |
start_timer(); |
1306 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1307 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if(!direct) |
1308 |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1309 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1310 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1342 |
|
|
1343 |
|
|
1344 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1345 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if(!direct) |
1346 |
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1347 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1348 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1415 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1416 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1417 |
|
|
1418 |
if (cbp & (1 << (5 - i))) /* coded */ |
if (cbp & (1 << (5 - i))) { /* coded */ |
|
{ |
|
1419 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1420 |
|
|
1421 |
start_timer(); |
start_timer(); |
1424 |
|
|
1425 |
start_timer(); |
start_timer(); |
1426 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
1427 |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
1428 |
} else { |
} else { |
1429 |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
1430 |
} |
} |
1431 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1432 |
|
|
1508 |
FILE *fp; |
FILE *fp; |
1509 |
static char first=0; |
static char first=0; |
1510 |
#define BFRAME_DEBUG if (!first && fp){ \ |
#define BFRAME_DEBUG if (!first && fp){ \ |
1511 |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \ |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ |
1512 |
} |
} |
1513 |
#endif |
#endif |
1514 |
|
|
1545 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1546 |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
1547 |
mb->cbp = 0; |
mb->cbp = 0; |
1548 |
#ifdef BFRAMES_DEC_DEBUG |
mb->mode = MODE_FORWARD; |
|
mb->mb_type = MODE_NOT_CODED; |
|
|
BFRAME_DEBUG |
|
|
#endif |
|
|
mb->mb_type = MODE_FORWARD; |
|
1549 |
mb->quant = last_mb->quant; |
mb->quant = last_mb->quant; |
1550 |
/* |
/* |
1551 |
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; |
1559 |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
1560 |
const uint8_t modb2 = BitstreamGetBit(bs); |
const uint8_t modb2 = BitstreamGetBit(bs); |
1561 |
|
|
1562 |
mb->mb_type = get_mbtype(bs); |
mb->mode = get_mbtype(bs); |
1563 |
|
|
1564 |
if (!modb2) { /* modb=='00' */ |
if (!modb2) { /* modb=='00' */ |
1565 |
mb->cbp = BitstreamGetBits(bs, 6); |
mb->cbp = BitstreamGetBits(bs, 6); |
1566 |
} else { |
} else { |
1567 |
mb->cbp = 0; |
mb->cbp = 0; |
1568 |
} |
} |
1569 |
if (mb->mb_type && mb->cbp) { |
if (mb->mode && mb->cbp) { |
1570 |
quant += get_dbquant(bs); |
quant += get_dbquant(bs); |
1571 |
|
|
1572 |
if (quant > 31) { |
if (quant > 31) { |
1575 |
quant = 1; |
quant = 1; |
1576 |
} |
} |
1577 |
} |
} |
1578 |
|
|
1579 |
|
if (dec->interlacing) { |
1580 |
|
if (mb->cbp) { |
1581 |
|
mb->field_dct = BitstreamGetBit(bs); |
1582 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
1583 |
|
} |
1584 |
|
|
1585 |
|
if (mb->mode) { |
1586 |
|
mb->field_pred = BitstreamGetBit(bs); |
1587 |
|
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
1588 |
|
|
1589 |
|
if (mb->field_pred) { |
1590 |
|
mb->field_for_top = BitstreamGetBit(bs); |
1591 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
1592 |
|
mb->field_for_bot = BitstreamGetBit(bs); |
1593 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
1594 |
|
} |
1595 |
|
} |
1596 |
|
} |
1597 |
|
|
1598 |
} else { |
} else { |
1599 |
mb->mb_type = MODE_DIRECT_NONE_MV; |
mb->mode = MODE_DIRECT_NONE_MV; |
1600 |
mb->cbp = 0; |
mb->cbp = 0; |
1601 |
} |
} |
1602 |
|
|
1603 |
mb->quant = quant; |
mb->quant = quant; |
1604 |
mb->mode = MODE_INTER4V; |
/* DEBUG1("Switch bm_type=",mb->mode); */ |
|
/* DEBUG1("Switch bm_type=",mb->mb_type); */ |
|
1605 |
|
|
1606 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1607 |
BFRAME_DEBUG |
BFRAME_DEBUG |
1608 |
#endif |
#endif |
1609 |
|
|
1610 |
switch (mb->mb_type) { |
switch (mb->mode) { |
1611 |
case MODE_DIRECT: |
case MODE_DIRECT: |
1612 |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
1613 |
|
|
1633 |
/* DEBUG("B-frame Direct!\n"); */ |
/* DEBUG("B-frame Direct!\n"); */ |
1634 |
} |
} |
1635 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1636 |
mb, x, y, bs); |
mb, x, y, bs, 1); |
1637 |
break; |
break; |
1638 |
|
|
1639 |
case MODE_INTERPOLATE: |
case MODE_INTERPOLATE: |
1647 |
mb->b_mvs[3] = mb->b_mvs[0]; |
mb->b_mvs[3] = mb->b_mvs[0]; |
1648 |
|
|
1649 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1650 |
mb, x, y, bs); |
mb, x, y, bs, 0); |
1651 |
/* DEBUG("B-frame Bidir!\n"); */ |
/* DEBUG("B-frame Bidir!\n"); */ |
1652 |
break; |
break; |
1653 |
|
|
1656 |
dec->p_bmv); |
dec->p_bmv); |
1657 |
dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1658 |
|
|
|
mb->mode = MODE_INTER; |
|
1659 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
1660 |
/* DEBUG("B-frame Backward!\n"); */ |
/* DEBUG("B-frame Backward!\n"); */ |
1661 |
break; |
break; |
1665 |
dec->p_fmv); |
dec->p_fmv); |
1666 |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1667 |
|
|
|
mb->mode = MODE_INTER; |
|
1668 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
1669 |
/* DEBUG("B-frame Forward!\n"); */ |
/* DEBUG("B-frame Forward!\n"); */ |
1670 |
break; |
break; |
1671 |
|
|
1672 |
default: |
default: |
1673 |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode); |
1674 |
} |
} |
1675 |
} /* End of for */ |
} /* End of for */ |
1676 |
} |
} |
1684 |
#endif |
#endif |
1685 |
} |
} |
1686 |
|
|
|
/* swap two MACROBLOCK array */ |
|
|
void |
|
|
mb_swap(MACROBLOCK ** mb1, |
|
|
MACROBLOCK ** mb2) |
|
|
{ |
|
|
MACROBLOCK *temp = *mb1; |
|
|
|
|
|
*mb1 = *mb2; |
|
|
*mb2 = temp; |
|
|
} |
|
1687 |
|
|
1688 |
|
|
1689 |
/* perform post processing if necessary, and output the image */ |
/* perform post processing if necessary, and output the image */ |
1700 |
{ |
{ |
1701 |
stats->type = coding2type(coding_type); |
stats->type = coding2type(coding_type); |
1702 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1703 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1704 |
} |
} |
1705 |
} |
} |
1706 |
|
|
1721 |
int coding_type; |
int coding_type; |
1722 |
int success, output, seen_something; |
int success, output, seen_something; |
1723 |
|
|
1724 |
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 */ |
1725 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
1726 |
|
|
1727 |
start_global_timer(); |
start_global_timer(); |
1733 |
|
|
1734 |
if (frame->length < 0) /* decoder flush */ |
if (frame->length < 0) /* decoder flush */ |
1735 |
{ |
{ |
1736 |
|
int ret; |
1737 |
/* 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 |
1738 |
we have a reference frame, then outout the reference frame */ |
we have a reference frame, then outout the reference frame */ |
1739 |
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) { |
|
{ |
|
1740 |
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); |
1741 |
|
dec->frames = 0; |
1742 |
|
ret = 0; |
1743 |
}else{ |
}else{ |
1744 |
if (stats) stats->type = XVID_TYPE_NOTHING; |
if (stats) stats->type = XVID_TYPE_NOTHING; |
1745 |
|
ret = XVID_ERR_END; |
1746 |
} |
} |
1747 |
|
|
1748 |
emms(); |
emms(); |
1749 |
stop_global_timer(); |
stop_global_timer(); |
1750 |
return 0; |
return ret; |
1751 |
} |
} |
1752 |
|
|
1753 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1771 |
coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1772 |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
1773 |
|
|
1774 |
DPRINTF(DPRINTF_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i", |
DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i\n", |
1775 |
coding_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
coding_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1776 |
|
|
1777 |
if (coding_type == -1) /* nothing */ |
if (coding_type == -1) /* nothing */ |
1806 |
|
|
1807 |
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 */ |
1808 |
|
|
|
|
|
1809 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1810 |
if (dec->packed_mode && coding_type == N_VOP) |
if (dec->packed_mode && coding_type == N_VOP) |
1811 |
{ |
{ |
1832 |
fcode_forward, intra_dc_threshold, &gmc_warp); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1833 |
break; |
break; |
1834 |
case N_VOP : |
case N_VOP : |
1835 |
// XXX: not_coded vops are not used for forward prediction |
/* XXX: not_coded vops are not used for forward prediction */ |
1836 |
// we should not swap(last_mbs,mbs) |
/* we should not swap(last_mbs,mbs) */ |
1837 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1838 |
break; |
break; |
1839 |
} |
} |
1863 |
|
|
1864 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1865 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1866 |
mb_swap(&dec->mbs, &dec->last_mbs); |
SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); |
1867 |
dec->last_reduced_resolution = reduced_resolution; |
dec->last_reduced_resolution = reduced_resolution; |
1868 |
dec->last_coding_type = coding_type; |
dec->last_coding_type = coding_type; |
1869 |
|
|
1874 |
|
|
1875 |
if (dec->low_delay) |
if (dec->low_delay) |
1876 |
{ |
{ |
1877 |
DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); |
DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
1878 |
dec->low_delay = 1; |
dec->low_delay = 1; |
1879 |
} |
} |
1880 |
|
|