comparison h263.c @ 10818:514dc1c87b2e libavcodec

Rename most non static h263 tables so their name contains h263.
author michael
date Fri, 08 Jan 2010 17:51:48 +0000
parents c03a8c6c755b
children 82d006235248
comparison
equal deleted inserted replaced
10817:d1fe22d92a65 10818:514dc1c87b2e
503 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) 503 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
504 { 504 {
505 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; 505 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
506 RLTable *rl; 506 RLTable *rl;
507 507
508 rl = &rl_inter; 508 rl = &ff_h263_rl_inter;
509 if (s->mb_intra && !s->h263_aic) { 509 if (s->mb_intra && !s->h263_aic) {
510 /* DC coef */ 510 /* DC coef */
511 level = block[0]; 511 level = block[0];
512 /* 255 cannot be represented, so we clamp */ 512 /* 255 cannot be represented, so we clamp */
513 if (level > 254) { 513 if (level > 254) {
721 if(s->alt_inter_vlc==0 || cbpc!=3) 721 if(s->alt_inter_vlc==0 || cbpc!=3)
722 cbpy ^= 0xF; 722 cbpy ^= 0xF;
723 if(s->dquant) cbpc+= 8; 723 if(s->dquant) cbpc+= 8;
724 if(s->mv_type==MV_TYPE_16X16){ 724 if(s->mv_type==MV_TYPE_16X16){
725 put_bits(&s->pb, 725 put_bits(&s->pb,
726 inter_MCBPC_bits[cbpc], 726 ff_h263_inter_MCBPC_bits[cbpc],
727 inter_MCBPC_code[cbpc]); 727 ff_h263_inter_MCBPC_code[cbpc]);
728 728
729 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); 729 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
730 if(s->dquant) 730 if(s->dquant)
731 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); 731 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
732 732
733 if(interleaved_stats){ 733 if(interleaved_stats){
734 s->misc_bits+= get_bits_diff(s); 734 s->misc_bits+= get_bits_diff(s);
748 /* To prevent Start Code emulation */ 748 /* To prevent Start Code emulation */
749 put_bits(&s->pb,1,1); 749 put_bits(&s->pb,1,1);
750 } 750 }
751 }else{ 751 }else{
752 put_bits(&s->pb, 752 put_bits(&s->pb,
753 inter_MCBPC_bits[cbpc+16], 753 ff_h263_inter_MCBPC_bits[cbpc+16],
754 inter_MCBPC_code[cbpc+16]); 754 ff_h263_inter_MCBPC_code[cbpc+16]);
755 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); 755 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
756 if(s->dquant) 756 if(s->dquant)
757 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); 757 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
758 758
759 if(interleaved_stats){ 759 if(interleaved_stats){
760 s->misc_bits+= get_bits_diff(s); 760 s->misc_bits+= get_bits_diff(s);
843 843
844 cbpc = cbp & 3; 844 cbpc = cbp & 3;
845 if (s->pict_type == FF_I_TYPE) { 845 if (s->pict_type == FF_I_TYPE) {
846 if(s->dquant) cbpc+=4; 846 if(s->dquant) cbpc+=4;
847 put_bits(&s->pb, 847 put_bits(&s->pb,
848 intra_MCBPC_bits[cbpc], 848 ff_h263_intra_MCBPC_bits[cbpc],
849 intra_MCBPC_code[cbpc]); 849 ff_h263_intra_MCBPC_code[cbpc]);
850 } else { 850 } else {
851 if(s->dquant) cbpc+=8; 851 if(s->dquant) cbpc+=8;
852 put_bits(&s->pb, 1, 0); /* mb coded */ 852 put_bits(&s->pb, 1, 0); /* mb coded */
853 put_bits(&s->pb, 853 put_bits(&s->pb,
854 inter_MCBPC_bits[cbpc + 4], 854 ff_h263_inter_MCBPC_bits[cbpc + 4],
855 inter_MCBPC_code[cbpc + 4]); 855 ff_h263_inter_MCBPC_code[cbpc + 4]);
856 } 856 }
857 if (s->h263_aic) { 857 if (s->h263_aic) {
858 /* XXX: currently, we do not try to use ac prediction */ 858 /* XXX: currently, we do not try to use ac prediction */
859 put_bits(&s->pb, 1, 0); /* no AC prediction */ 859 put_bits(&s->pb, 1, 0); /* no AC prediction */
860 } 860 }
861 cbpy = cbp >> 2; 861 cbpy = cbp >> 2;
862 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); 862 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
863 if(s->dquant) 863 if(s->dquant)
864 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); 864 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
865 865
866 if(interleaved_stats){ 866 if(interleaved_stats){
867 s->misc_bits+= get_bits_diff(s); 867 s->misc_bits+= get_bits_diff(s);
1245 static int done = 0; 1245 static int done = 0;
1246 1246
1247 if (!done) { 1247 if (!done) {
1248 done = 1; 1248 done = 1;
1249 1249
1250 init_rl(&rl_inter, static_rl_table_store[0]); 1250 init_rl(&ff_h263_rl_inter, static_rl_table_store[0]);
1251 init_rl(&rl_intra_aic, static_rl_table_store[1]); 1251 init_rl(&rl_intra_aic, static_rl_table_store[1]);
1252 1252
1253 init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len); 1253 init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len);
1254 init_uni_h263_rl_tab(&rl_inter , NULL, uni_h263_inter_rl_len); 1254 init_uni_h263_rl_tab(&ff_h263_rl_inter , NULL, uni_h263_inter_rl_len);
1255 1255
1256 init_mv_penalty_and_fcode(s); 1256 init_mv_penalty_and_fcode(s);
1257 } 1257 }
1258 s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p 1258 s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p
1259 1259
1303 #endif //CONFIG_ENCODERS 1303 #endif //CONFIG_ENCODERS
1304 1304
1305 /***********************************************/ 1305 /***********************************************/
1306 /* decoding */ 1306 /* decoding */
1307 1307
1308 VLC intra_MCBPC_vlc; 1308 VLC ff_h263_intra_MCBPC_vlc;
1309 VLC inter_MCBPC_vlc; 1309 VLC ff_h263_inter_MCBPC_vlc;
1310 VLC cbpy_vlc; 1310 VLC ff_h263_cbpy_vlc;
1311 static VLC mv_vlc; 1311 static VLC mv_vlc;
1312 static VLC h263_mbtype_b_vlc; 1312 static VLC h263_mbtype_b_vlc;
1313 static VLC cbpc_b_vlc; 1313 static VLC cbpc_b_vlc;
1314 1314
1315 /* init vlcs */ 1315 /* init vlcs */
1320 static int done = 0; 1320 static int done = 0;
1321 1321
1322 if (!done) { 1322 if (!done) {
1323 done = 1; 1323 done = 1;
1324 1324
1325 INIT_VLC_STATIC(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, 1325 INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
1326 intra_MCBPC_bits, 1, 1, 1326 ff_h263_intra_MCBPC_bits, 1, 1,
1327 intra_MCBPC_code, 1, 1, 72); 1327 ff_h263_intra_MCBPC_code, 1, 1, 72);
1328 INIT_VLC_STATIC(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, 1328 INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
1329 inter_MCBPC_bits, 1, 1, 1329 ff_h263_inter_MCBPC_bits, 1, 1,
1330 inter_MCBPC_code, 1, 1, 198); 1330 ff_h263_inter_MCBPC_code, 1, 1, 198);
1331 INIT_VLC_STATIC(&cbpy_vlc, CBPY_VLC_BITS, 16, 1331 INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
1332 &cbpy_tab[0][1], 2, 1, 1332 &ff_h263_cbpy_tab[0][1], 2, 1,
1333 &cbpy_tab[0][0], 2, 1, 64); 1333 &ff_h263_cbpy_tab[0][0], 2, 1, 64);
1334 INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, 1334 INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
1335 &mvtab[0][1], 2, 1, 1335 &mvtab[0][1], 2, 1,
1336 &mvtab[0][0], 2, 1, 538); 1336 &mvtab[0][0], 2, 1, 538);
1337 init_rl(&rl_inter, static_rl_table_store[0]); 1337 init_rl(&ff_h263_rl_inter, static_rl_table_store[0]);
1338 init_rl(&rl_intra_aic, static_rl_table_store[1]); 1338 init_rl(&rl_intra_aic, static_rl_table_store[1]);
1339 INIT_VLC_RL(rl_inter, 554); 1339 INIT_VLC_RL(ff_h263_rl_inter, 554);
1340 INIT_VLC_RL(rl_intra_aic, 554); 1340 INIT_VLC_RL(rl_intra_aic, 554);
1341 INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, 1341 INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
1342 &h263_mbtype_b_tab[0][1], 2, 1, 1342 &h263_mbtype_b_tab[0][1], 2, 1,
1343 &h263_mbtype_b_tab[0][0], 2, 1, 80); 1343 &h263_mbtype_b_tab[0][0], 2, 1, 80);
1344 INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, 1344 INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
1604 mot_val[1+stride]= mot_val[3+stride]= 0; 1604 mot_val[1+stride]= mot_val[3+stride]= 0;
1605 1605
1606 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; 1606 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
1607 goto end; 1607 goto end;
1608 } 1608 }
1609 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); 1609 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
1610 }while(cbpc == 20); 1610 }while(cbpc == 20);
1611 1611
1612 if(cbpc & 4){ 1612 if(cbpc & 4){
1613 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; 1613 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
1614 }else{ 1614 }else{
1615 get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); 1615 get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
1616 if (cbpc & 8) { 1616 if (cbpc & 8) {
1617 if(s->modified_quant){ 1617 if(s->modified_quant){
1618 if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); 1618 if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
1619 else skip_bits(&s->gb, 5); 1619 else skip_bits(&s->gb, 5);
1620 }else 1620 }else
1685 1685
1686 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, 1686 static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
1687 int n, int coded) 1687 int n, int coded)
1688 { 1688 {
1689 int code, level, i, j, last, run; 1689 int code, level, i, j, last, run;
1690 RLTable *rl = &rl_inter; 1690 RLTable *rl = &ff_h263_rl_inter;
1691 const uint8_t *scan_table; 1691 const uint8_t *scan_table;
1692 GetBitContext gb= s->gb; 1692 GetBitContext gb= s->gb;
1693 1693
1694 scan_table = s->intra_scantable.permutated; 1694 scan_table = s->intra_scantable.permutated;
1695 if (s->h263_aic && s->mb_intra) { 1695 if (s->h263_aic && s->mb_intra) {
1778 if (get_bits1(&s->gb)) 1778 if (get_bits1(&s->gb))
1779 level = -level; 1779 level = -level;
1780 } 1780 }
1781 i += run; 1781 i += run;
1782 if (i >= 64){ 1782 if (i >= 64){
1783 if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){ 1783 if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
1784 //Looks like a hack but no, it's the way it is supposed to work ... 1784 //Looks like a hack but no, it's the way it is supposed to work ...
1785 rl = &rl_intra_aic; 1785 rl = &rl_intra_aic;
1786 i = 0; 1786 i = 0;
1787 s->gb= gb; 1787 s->gb= gb;
1788 s->dsp.clear_block(block); 1788 s->dsp.clear_block(block);
1866 s->mv[0][0][0] = 0; 1866 s->mv[0][0][0] = 0;
1867 s->mv[0][0][1] = 0; 1867 s->mv[0][0][1] = 0;
1868 s->mb_skipped = !(s->obmc | s->loop_filter); 1868 s->mb_skipped = !(s->obmc | s->loop_filter);
1869 goto end; 1869 goto end;
1870 } 1870 }
1871 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); 1871 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
1872 if (cbpc < 0){ 1872 if (cbpc < 0){
1873 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); 1873 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
1874 return -1; 1874 return -1;
1875 } 1875 }
1876 }while(cbpc == 20); 1876 }while(cbpc == 20);
1881 s->mb_intra = ((cbpc & 4) != 0); 1881 s->mb_intra = ((cbpc & 4) != 0);
1882 if (s->mb_intra) goto intra; 1882 if (s->mb_intra) goto intra;
1883 1883
1884 if(s->pb_frame && get_bits1(&s->gb)) 1884 if(s->pb_frame && get_bits1(&s->gb))
1885 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); 1885 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
1886 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); 1886 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
1887 1887
1888 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) 1888 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
1889 cbpy ^= 0xF; 1889 cbpy ^= 0xF;
1890 1890
1891 cbp = (cbpc & 3) | (cbpy << 2); 1891 cbp = (cbpc & 3) | (cbpy << 2);
1975 if(s->mb_intra){ 1975 if(s->mb_intra){
1976 dquant = IS_QUANT(mb_type); 1976 dquant = IS_QUANT(mb_type);
1977 goto intra; 1977 goto intra;
1978 } 1978 }
1979 1979
1980 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); 1980 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
1981 1981
1982 if (cbpy < 0){ 1982 if (cbpy < 0){
1983 av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); 1983 av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
1984 return -1; 1984 return -1;
1985 } 1985 }
2033 } 2033 }
2034 2034
2035 s->current_picture.mb_type[xy]= mb_type; 2035 s->current_picture.mb_type[xy]= mb_type;
2036 } else { /* I-Frame */ 2036 } else { /* I-Frame */
2037 do{ 2037 do{
2038 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); 2038 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
2039 if (cbpc < 0){ 2039 if (cbpc < 0){
2040 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); 2040 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
2041 return -1; 2041 return -1;
2042 } 2042 }
2043 }while(cbpc == 8); 2043 }while(cbpc == 8);
2058 }else 2058 }else
2059 s->ac_pred = 0; 2059 s->ac_pred = 0;
2060 2060
2061 if(s->pb_frame && get_bits1(&s->gb)) 2061 if(s->pb_frame && get_bits1(&s->gb))
2062 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); 2062 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
2063 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); 2063 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
2064 if(cbpy<0){ 2064 if(cbpy<0){
2065 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); 2065 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
2066 return -1; 2066 return -1;
2067 } 2067 }
2068 cbp = (cbpc & 3) | (cbpy << 2); 2068 cbp = (cbpc & 3) | (cbpy << 2);