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 |
20 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: decoder.c,v 1.49.2.3 2003-03-26 10:29:51 suxen_drol Exp $ |
* $Id: decoder.c,v 1.49.2.8 2003-06-09 19:41:53 edgomez Exp $ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
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 |
} |
} |
738 |
} |
} |
739 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
740 |
|
|
741 |
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)); |
742 |
|
|
743 |
mcbpc = get_mcbpc_intra(bs); |
mcbpc = get_mcbpc_intra(bs); |
744 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
765 |
|
|
766 |
if (dec->interlacing) { |
if (dec->interlacing) { |
767 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
768 |
DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct); |
769 |
} |
} |
770 |
|
|
771 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
803 |
mv.x = get_mv(bs, fcode); |
mv.x = get_mv(bs, fcode); |
804 |
mv.y = get_mv(bs, fcode); |
mv.y = get_mv(bs, fcode); |
805 |
|
|
806 |
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); |
807 |
|
|
808 |
mv.x += pmv.x; |
mv.x += pmv.x; |
809 |
mv.y += pmv.y; |
mv.y += pmv.y; |
902 |
} |
} |
903 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
904 |
|
|
905 |
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)); |
906 |
|
|
907 |
/* 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 */ |
908 |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
if (!(BitstreamGetBit(bs))) /* block _is_ coded */ |
920 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
921 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
922 |
|
|
923 |
DPRINTF(DPRINTF_MB, "mode %i", mb->mode); |
DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode); |
924 |
DPRINTF(DPRINTF_MB, "cbpc %i", cbpc); |
DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc); |
925 |
acpred_flag = 0; |
acpred_flag = 0; |
926 |
|
|
927 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
936 |
} |
} |
937 |
|
|
938 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
939 |
DPRINTF(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); |
DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
940 |
|
|
941 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
942 |
|
|
943 |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
944 |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
945 |
DPRINTF(DPRINTF_MB, "dquant %i", dquant); |
DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant); |
946 |
quant += dquant; |
quant += dquant; |
947 |
if (quant > 31) { |
if (quant > 31) { |
948 |
quant = 31; |
quant = 31; |
949 |
} else if (quant < 1) { |
} else if (quant < 1) { |
950 |
quant = 1; |
quant = 1; |
951 |
} |
} |
952 |
DPRINTF(DPRINTF_MB, "quant %i", quant); |
DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant); |
953 |
} |
} |
954 |
mb->quant = quant; |
mb->quant = quant; |
955 |
|
|
956 |
if (dec->interlacing) { |
if (dec->interlacing) { |
957 |
if (cbp || intra) { |
if (cbp || intra) { |
958 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
959 |
DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
960 |
} |
} |
961 |
|
|
962 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
963 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
964 |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
965 |
|
|
966 |
if (mb->field_pred) { |
if (mb->field_pred) { |
967 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
968 |
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); |
969 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
970 |
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); |
971 |
} |
} |
972 |
} |
} |
973 |
} |
} |
1692 |
break; |
break; |
1693 |
|
|
1694 |
default: |
default: |
1695 |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
DPRINTF(XVID_DEBUG_ERROR,"Not support B-frame mb_type = %i\n", mb->mb_type); |
1696 |
} |
} |
1697 |
} /* End of for */ |
} /* End of for */ |
1698 |
} |
} |
1722 |
{ |
{ |
1723 |
stats->type = coding2type(coding_type); |
stats->type = coding2type(coding_type); |
1724 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1725 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; /* XXX: todo */ |
1726 |
} |
} |
1727 |
} |
} |
1728 |
|
|
1742 |
WARPPOINTS gmc_warp; |
WARPPOINTS gmc_warp; |
1743 |
int coding_type; |
int coding_type; |
1744 |
int success, output, seen_something; |
int success, output, seen_something; |
1745 |
|
idctFuncPtr idct_save; |
1746 |
|
|
1747 |
if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
if (XVID_MAJOR(frame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
1748 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
1788 |
success = 0; |
success = 0; |
1789 |
output = 0; |
output = 0; |
1790 |
seen_something = 0; |
seen_something = 0; |
1791 |
|
idct_save = idct; |
1792 |
|
|
1793 |
repeat: |
repeat: |
1794 |
|
|
1795 |
coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1796 |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
1797 |
|
|
1798 |
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", |
1799 |
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); |
1800 |
|
|
1801 |
if (coding_type == -1) /* nothing */ |
if (coding_type == -1) /* nothing */ |
1830 |
|
|
1831 |
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 */ |
1832 |
|
|
1833 |
|
#if defined(ARCH_IS_IA32) |
1834 |
|
/* |
1835 |
|
* /!\ Ugly hack /!\ |
1836 |
|
* IA32: Prior to xvid bitstream 10, we were using Walten's mmx/xmm idct |
1837 |
|
*/ |
1838 |
|
if((idct == simple_idct_mmx) && (dec->bs_version < 10)) |
1839 |
|
idct = idct_mmx; |
1840 |
|
#endif |
1841 |
|
|
1842 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1843 |
if (dec->packed_mode && coding_type == N_VOP) |
if (dec->packed_mode && coding_type == N_VOP) |
1865 |
fcode_forward, intra_dc_threshold, &gmc_warp); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1866 |
break; |
break; |
1867 |
case N_VOP : |
case N_VOP : |
1868 |
// XXX: not_coded vops are not used for forward prediction |
/* XXX: not_coded vops are not used for forward prediction */ |
1869 |
// we should not swap(last_mbs,mbs) |
/* we should not swap(last_mbs,mbs) */ |
1870 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1871 |
break; |
break; |
1872 |
} |
} |
1907 |
|
|
1908 |
if (dec->low_delay) |
if (dec->low_delay) |
1909 |
{ |
{ |
1910 |
DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); |
DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
1911 |
dec->low_delay = 1; |
dec->low_delay = 1; |
1912 |
} |
} |
1913 |
|
|
1967 |
emms(); |
emms(); |
1968 |
stop_global_timer(); |
stop_global_timer(); |
1969 |
|
|
1970 |
|
idct = idct_save; |
1971 |
|
|
1972 |
return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
1973 |
} |
} |