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 |
54 |
#include "utils/timer.h" |
#include "utils/timer.h" |
55 |
#include "utils/emms.h" |
#include "utils/emms.h" |
56 |
#include "motion/motion.h" |
#include "motion/motion.h" |
57 |
|
#include "motion/gmc.h" |
58 |
|
|
59 |
#include "image/image.h" |
#include "image/image.h" |
60 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
169 |
{ |
{ |
170 |
DECODER *dec; |
DECODER *dec; |
171 |
|
|
172 |
if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
173 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
174 |
|
|
175 |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
584 |
stop_transfer_timer(); |
stop_transfer_timer(); |
585 |
} |
} |
586 |
|
|
|
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; |
|
|
} |
|
|
|
|
587 |
|
|
588 |
static void |
static void |
589 |
decoder_mbgmc(DECODER * dec, |
decoder_mbgmc(DECODER * dec, |
616 |
|
|
617 |
/* this is where the calculations are done */ |
/* this is where the calculations are done */ |
618 |
|
|
619 |
{ |
{ NEW_GMC_DATA * gmc_data = &dec->new_gmc_data; |
620 |
pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos, |
|
621 |
stride, stride2, dec->quarterpel, rounding, &dec->cur); |
gmc_data->predict_16x16(gmc_data, |
622 |
|
dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y, |
623 |
|
stride, stride, x_pos, y_pos, rounding); |
624 |
|
|
625 |
|
gmc_data->predict_8x8(gmc_data, |
626 |
|
dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u, |
627 |
|
dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v, |
628 |
|
stride2, stride2, x_pos, y_pos, rounding); |
629 |
|
|
630 |
|
gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel); |
631 |
|
|
632 |
pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
633 |
pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); |
pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); |
858 |
{ |
{ |
859 |
|
|
860 |
/* 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 */ |
861 |
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
/* { |
862 |
{ |
fprintf(stderr,"GMC parameters acc=%d(-> 1/%d), %d pts!!!\n", |
|
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 |
(2 << dec->sprite_warping_accuracy), gmc_warp, |
dec->sprite_warping_accuracy, gmc_warp, |
869 |
dec->width, dec->height, &dec->gmc_data); |
dec->width, dec->height, &dec->new_gmc_data); |
870 |
|
|
871 |
/* 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); |
|
|
*/ |
|
872 |
} |
} |
873 |
|
|
874 |
bound = 0; |
bound = 0; |
915 |
|
|
916 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
917 |
|
|
|
if (intra) { |
|
|
acpred_flag = BitstreamGetBit(bs); |
|
|
} |
|
|
|
|
918 |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
|
{ |
|
919 |
mcsel = BitstreamGetBit(bs); |
mcsel = BitstreamGetBit(bs); |
920 |
} |
|
921 |
|
if (intra) |
922 |
|
acpred_flag = BitstreamGetBit(bs); |
923 |
|
|
924 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
925 |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
940 |
mb->quant = quant; |
mb->quant = quant; |
941 |
|
|
942 |
if (dec->interlacing) { |
if (dec->interlacing) { |
943 |
if (cbp || intra) { |
if ((cbp || intra) && !mcsel) { |
944 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
945 |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
946 |
} |
} |
1600 |
quant = 1; |
quant = 1; |
1601 |
} |
} |
1602 |
} |
} |
1603 |
|
|
1604 |
|
if (dec->interlacing) { |
1605 |
|
if (mb->cbp) { |
1606 |
|
mb->field_dct = BitstreamGetBit(bs); |
1607 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
1608 |
|
} |
1609 |
|
|
1610 |
|
if (mb->mb_type) { |
1611 |
|
mb->field_pred = BitstreamGetBit(bs); |
1612 |
|
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
1613 |
|
|
1614 |
|
if (mb->field_pred) { |
1615 |
|
mb->field_for_top = BitstreamGetBit(bs); |
1616 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
1617 |
|
mb->field_for_bot = BitstreamGetBit(bs); |
1618 |
|
DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
1619 |
|
} |
1620 |
|
} |
1621 |
|
} |
1622 |
|
|
1623 |
} else { |
} else { |
1624 |
mb->mb_type = MODE_DIRECT_NONE_MV; |
mb->mb_type = MODE_DIRECT_NONE_MV; |
1625 |
mb->cbp = 0; |
mb->cbp = 0; |
1728 |
{ |
{ |
1729 |
stats->type = coding2type(coding_type); |
stats->type = coding2type(coding_type); |
1730 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1731 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1732 |
} |
} |
1733 |
} |
} |
1734 |
|
|
1749 |
int coding_type; |
int coding_type; |
1750 |
int success, output, seen_something; |
int success, output, seen_something; |
1751 |
|
|
1752 |
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 */ |
1753 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
1754 |
|
|
1755 |
start_global_timer(); |
start_global_timer(); |
1834 |
|
|
1835 |
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 */ |
1836 |
|
|
|
|
|
1837 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1838 |
if (dec->packed_mode && coding_type == N_VOP) |
if (dec->packed_mode && coding_type == N_VOP) |
1839 |
{ |
{ |
1860 |
fcode_forward, intra_dc_threshold, &gmc_warp); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1861 |
break; |
break; |
1862 |
case N_VOP : |
case N_VOP : |
1863 |
// XXX: not_coded vops are not used for forward prediction |
/* XXX: not_coded vops are not used for forward prediction */ |
1864 |
// we should not swap(last_mbs,mbs) |
/* we should not swap(last_mbs,mbs) */ |
1865 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1866 |
break; |
break; |
1867 |
} |
} |