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 |
39 |
#include "bitstream/bitstream.h" |
#include "bitstream/bitstream.h" |
40 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
41 |
|
|
42 |
#include "quant/quant.h" |
#include "quant/quant_h263.h" |
43 |
|
#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" |
|
#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 |
} |
} |
322 |
|
|
323 |
start_timer(); |
start_timer(); |
324 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
325 |
dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
dequant_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
326 |
} else { |
} else { |
327 |
dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
dequant4_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
328 |
} |
} |
329 |
stop_iquant_timer(); |
stop_iquant_timer(); |
330 |
|
|
528 |
|
|
529 |
start_timer(); |
start_timer(); |
530 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
531 |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
532 |
} else { |
} else { |
533 |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
534 |
} |
} |
535 |
stop_iquant_timer(); |
stop_iquant_timer(); |
536 |
|
|
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); |
657 |
|
|
658 |
start_timer(); |
start_timer(); |
659 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
660 |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
661 |
} else { |
} else { |
662 |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant4_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(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) && !mcsel) { |
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 |
} |
} |
1149 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1150 |
|
|
1151 |
|
|
1152 |
|
if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
1153 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1154 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1155 |
|
|
1156 |
if (dec->quarterpel) { |
if (dec->quarterpel) |
1157 |
|
{ |
1158 |
uv_dx /= 2; |
uv_dx /= 2; |
1159 |
uv_dy /= 2; |
uv_dy /= 2; |
1160 |
} |
} |
1161 |
|
|
1162 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1163 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
1164 |
|
} else { |
1165 |
|
int sum; |
1166 |
|
|
1167 |
|
if(dec->quarterpel) |
1168 |
|
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
1169 |
|
else |
1170 |
|
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1171 |
|
|
1172 |
|
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
1173 |
|
|
1174 |
|
if(dec->quarterpel) |
1175 |
|
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
1176 |
|
else |
1177 |
|
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1178 |
|
|
1179 |
|
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
1180 |
|
} |
1181 |
|
|
1182 |
start_timer(); |
start_timer(); |
1183 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1184 |
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, |
1185 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1186 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1187 |
} else { |
} |
1188 |
|
else { |
1189 |
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, |
1190 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1191 |
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, |
1192 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1193 |
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, |
1194 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1195 |
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, |
1196 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1197 |
} |
} |
1198 |
|
|
1199 |
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, |
1205 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1206 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1207 |
|
|
1208 |
if (cbp & (1 << (5 - i))) { /* coded */ |
if (cbp & (1 << (5 - i))) /* coded */ |
1209 |
|
{ |
1210 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1211 |
|
|
1212 |
start_timer(); |
start_timer(); |
1214 |
stop_coding_timer(); |
stop_coding_timer(); |
1215 |
|
|
1216 |
start_timer(); |
start_timer(); |
1217 |
if (dec->quant_type == 0) |
if (dec->quant_type == 0) { |
1218 |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
1219 |
else |
} else { |
1220 |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
1221 |
|
} |
1222 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1223 |
|
|
1224 |
start_timer(); |
start_timer(); |
1248 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1249 |
} |
} |
1250 |
|
|
1251 |
/* decode an B-frame direct & interpolate macroblock */ |
/* decode an B-frame direct & inter macroblock */ |
1252 |
void |
void |
1253 |
decoder_bf_interpolate_mbinter(DECODER * dec, |
decoder_bf_interpolate_mbinter(DECODER * dec, |
1254 |
IMAGE forward, |
IMAGE forward, |
1256 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
1257 |
const uint32_t x_pos, |
const uint32_t x_pos, |
1258 |
const uint32_t y_pos, |
const uint32_t y_pos, |
1259 |
Bitstream * bs, |
Bitstream * bs) |
|
const int direct) |
|
1260 |
{ |
{ |
1261 |
|
|
1262 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
1277 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1278 |
|
|
1279 |
|
|
1280 |
if (!direct) { |
if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
1281 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1282 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1283 |
|
|
1334 |
|
|
1335 |
start_timer(); |
start_timer(); |
1336 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1337 |
if(!direct) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1338 |
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, |
1339 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1340 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1372 |
|
|
1373 |
|
|
1374 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1375 |
if(!direct) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1376 |
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, |
1377 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1378 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1445 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1446 |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1447 |
|
|
1448 |
if (cbp & (1 << (5 - i))) { /* coded */ |
if (cbp & (1 << (5 - i))) /* coded */ |
1449 |
|
{ |
1450 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); /* clear */ |
1451 |
|
|
1452 |
start_timer(); |
start_timer(); |
1455 |
|
|
1456 |
start_timer(); |
start_timer(); |
1457 |
if (dec->quant_type == 0) { |
if (dec->quant_type == 0) { |
1458 |
dequant_h263_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
1459 |
} else { |
} else { |
1460 |
dequant_mpeg_inter(&data[i * 64], &block[i * 64], iQuant); |
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
1461 |
} |
} |
1462 |
stop_iquant_timer(); |
stop_iquant_timer(); |
1463 |
|
|
1539 |
FILE *fp; |
FILE *fp; |
1540 |
static char first=0; |
static char first=0; |
1541 |
#define BFRAME_DEBUG if (!first && fp){ \ |
#define BFRAME_DEBUG if (!first && fp){ \ |
1542 |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \ |
1543 |
} |
} |
1544 |
#endif |
#endif |
1545 |
|
|
1576 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1577 |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
/* DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); */ |
1578 |
mb->cbp = 0; |
mb->cbp = 0; |
1579 |
mb->mode = MODE_FORWARD; |
#ifdef BFRAMES_DEC_DEBUG |
1580 |
|
mb->mb_type = MODE_NOT_CODED; |
1581 |
|
BFRAME_DEBUG |
1582 |
|
#endif |
1583 |
|
mb->mb_type = MODE_FORWARD; |
1584 |
mb->quant = last_mb->quant; |
mb->quant = last_mb->quant; |
1585 |
/* |
/* |
1586 |
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; |
1594 |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
1595 |
const uint8_t modb2 = BitstreamGetBit(bs); |
const uint8_t modb2 = BitstreamGetBit(bs); |
1596 |
|
|
1597 |
mb->mode = get_mbtype(bs); |
mb->mb_type = get_mbtype(bs); |
1598 |
|
|
1599 |
if (!modb2) { /* modb=='00' */ |
if (!modb2) { /* modb=='00' */ |
1600 |
mb->cbp = BitstreamGetBits(bs, 6); |
mb->cbp = BitstreamGetBits(bs, 6); |
1601 |
} else { |
} else { |
1602 |
mb->cbp = 0; |
mb->cbp = 0; |
1603 |
} |
} |
1604 |
if (mb->mode && mb->cbp) { |
if (mb->mb_type && mb->cbp) { |
1605 |
quant += get_dbquant(bs); |
quant += get_dbquant(bs); |
1606 |
|
|
1607 |
if (quant > 31) { |
if (quant > 31) { |
1610 |
quant = 1; |
quant = 1; |
1611 |
} |
} |
1612 |
} |
} |
|
|
|
|
if (dec->interlacing) { |
|
|
if (mb->cbp) { |
|
|
mb->field_dct = BitstreamGetBit(bs); |
|
|
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
|
|
} |
|
|
|
|
|
if (mb->mode) { |
|
|
mb->field_pred = BitstreamGetBit(bs); |
|
|
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
|
|
|
|
|
if (mb->field_pred) { |
|
|
mb->field_for_top = BitstreamGetBit(bs); |
|
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
|
|
mb->field_for_bot = BitstreamGetBit(bs); |
|
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
1613 |
} else { |
} else { |
1614 |
mb->mode = MODE_DIRECT_NONE_MV; |
mb->mb_type = MODE_DIRECT_NONE_MV; |
1615 |
mb->cbp = 0; |
mb->cbp = 0; |
1616 |
} |
} |
1617 |
|
|
1618 |
mb->quant = quant; |
mb->quant = quant; |
1619 |
/* DEBUG1("Switch bm_type=",mb->mode); */ |
mb->mode = MODE_INTER4V; |
1620 |
|
/* DEBUG1("Switch bm_type=",mb->mb_type); */ |
1621 |
|
|
1622 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1623 |
BFRAME_DEBUG |
BFRAME_DEBUG |
1624 |
#endif |
#endif |
1625 |
|
|
1626 |
switch (mb->mode) { |
switch (mb->mb_type) { |
1627 |
case MODE_DIRECT: |
case MODE_DIRECT: |
1628 |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
1629 |
|
|
1649 |
/* DEBUG("B-frame Direct!\n"); */ |
/* DEBUG("B-frame Direct!\n"); */ |
1650 |
} |
} |
1651 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1652 |
mb, x, y, bs, 1); |
mb, x, y, bs); |
1653 |
break; |
break; |
1654 |
|
|
1655 |
case MODE_INTERPOLATE: |
case MODE_INTERPOLATE: |
1663 |
mb->b_mvs[3] = mb->b_mvs[0]; |
mb->b_mvs[3] = mb->b_mvs[0]; |
1664 |
|
|
1665 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1666 |
mb, x, y, bs, 0); |
mb, x, y, bs); |
1667 |
/* DEBUG("B-frame Bidir!\n"); */ |
/* DEBUG("B-frame Bidir!\n"); */ |
1668 |
break; |
break; |
1669 |
|
|
1672 |
dec->p_bmv); |
dec->p_bmv); |
1673 |
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]; |
1674 |
|
|
1675 |
|
mb->mode = MODE_INTER; |
1676 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
1677 |
/* DEBUG("B-frame Backward!\n"); */ |
/* DEBUG("B-frame Backward!\n"); */ |
1678 |
break; |
break; |
1682 |
dec->p_fmv); |
dec->p_fmv); |
1683 |
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]; |
1684 |
|
|
1685 |
|
mb->mode = MODE_INTER; |
1686 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
1687 |
/* DEBUG("B-frame Forward!\n"); */ |
/* DEBUG("B-frame Forward!\n"); */ |
1688 |
break; |
break; |
1689 |
|
|
1690 |
default: |
default: |
1691 |
DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode); |
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 |
} |
} |