comparison h263.c @ 1637:7799582dc9b8 libavcodec

h263 alternative inter vlc support
author michael
date Sat, 29 Nov 2003 08:37:51 +0000
parents 27806cccec2a
children 3e2b774edce4
comparison
equal deleted inserted replaced
1636:d9d98cdcfcde 1637:7799582dc9b8
244 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ 244 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
245 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ 245 put_bits(&s->pb,1,0); /* Deblocking Filter: off */
246 put_bits(&s->pb,1,0); /* Slice Structured: off */ 246 put_bits(&s->pb,1,0); /* Slice Structured: off */
247 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ 247 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
248 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ 248 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
249 put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */ 249 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */
250 put_bits(&s->pb,1,0); /* Modified Quantization: off */ 250 put_bits(&s->pb,1,0); /* Modified Quantization: off */
251 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ 251 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
252 put_bits(&s->pb,3,0); /* Reserved */ 252 put_bits(&s->pb,3,0); /* Reserved */
253 253
254 put_bits(&s->pb, 3, s->pict_type == P_TYPE); 254 put_bits(&s->pb, 3, s->pict_type == P_TYPE);
1069 return; 1069 return;
1070 } 1070 }
1071 put_bits(&s->pb, 1, 0); /* mb coded */ 1071 put_bits(&s->pb, 1, 0); /* mb coded */
1072 1072
1073 cbpc = cbp & 3; 1073 cbpc = cbp & 3;
1074 cbpy = cbp >> 2;
1075 if(s->alt_inter_vlc==0 || cbpc!=3)
1076 cbpy ^= 0xF;
1074 if(s->dquant) cbpc+= 8; 1077 if(s->dquant) cbpc+= 8;
1075 cbpy = cbp >> 2;
1076 cbpy ^= 0xf;
1077 if(s->mv_type==MV_TYPE_16X16){ 1078 if(s->mv_type==MV_TYPE_16X16){
1078 put_bits(&s->pb, 1079 put_bits(&s->pb,
1079 inter_MCBPC_bits[cbpc], 1080 inter_MCBPC_bits[cbpc],
1080 inter_MCBPC_code[cbpc]); 1081 inter_MCBPC_code[cbpc]);
1081 1082
1802 i = 1; 1803 i = 1;
1803 } else { 1804 } else {
1804 i = 0; 1805 i = 0;
1805 if (s->h263_aic && s->mb_intra) 1806 if (s->h263_aic && s->mb_intra)
1806 rl = &rl_intra_aic; 1807 rl = &rl_intra_aic;
1808
1809 if(s->alt_inter_vlc && !s->mb_intra){
1810 int aic_vlc_bits=0;
1811 int inter_vlc_bits=0;
1812 int wrong_pos=-1;
1813 int aic_code;
1814
1815 last_index = s->block_last_index[n];
1816 last_non_zero = i - 1;
1817 for (; i <= last_index; i++) {
1818 j = s->intra_scantable.permutated[i];
1819 level = block[j];
1820 if (level) {
1821 run = i - last_non_zero - 1;
1822 last = (i == last_index);
1823
1824 code = get_rl_index(rl, last, run, level);
1825 aic_code = get_rl_index(&rl_intra_aic, last, run, level);
1826 inter_vlc_bits += rl->table_vlc[code][1]+1;
1827 aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1;
1828
1829 if (code == rl->n) {
1830 inter_vlc_bits += 1+6+8;
1831 }
1832 if (aic_code == rl_intra_aic.n) {
1833 aic_vlc_bits += 1+6+8;
1834 wrong_pos += run + 1;
1835 }else
1836 wrong_pos += wrong_run[aic_code];
1837 last_non_zero = i;
1838 }
1839 }
1840 i = 0;
1841 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
1842 rl = &rl_intra_aic;
1843 }
1807 } 1844 }
1808 1845
1809 /* AC coefs */ 1846 /* AC coefs */
1810 last_index = s->block_last_index[n]; 1847 last_index = s->block_last_index[n];
1811 last_non_zero = i - 1; 1848 last_non_zero = i - 1;
3472 3509
3473 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) 3510 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
3474 s->mcsel= get_bits1(&s->gb); 3511 s->mcsel= get_bits1(&s->gb);
3475 else s->mcsel= 0; 3512 else s->mcsel= 0;
3476 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); 3513 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
3477 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); 3514
3515 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
3516 cbpy ^= 0xF;
3517
3518 cbp = (cbpc & 3) | (cbpy << 2);
3478 if (dquant) { 3519 if (dquant) {
3479 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); 3520 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
3480 } 3521 }
3481 if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE))) 3522 if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE)))
3482 s->interlaced_dct= get_bits1(&s->gb); 3523 s->interlaced_dct= get_bits1(&s->gb);
3863 int n, int coded) 3904 int n, int coded)
3864 { 3905 {
3865 int code, level, i, j, last, run; 3906 int code, level, i, j, last, run;
3866 RLTable *rl = &rl_inter; 3907 RLTable *rl = &rl_inter;
3867 const uint8_t *scan_table; 3908 const uint8_t *scan_table;
3909 GetBitContext gb= s->gb;
3868 3910
3869 scan_table = s->intra_scantable.permutated; 3911 scan_table = s->intra_scantable.permutated;
3870 if (s->h263_aic && s->mb_intra) { 3912 if (s->h263_aic && s->mb_intra) {
3871 rl = &rl_intra_aic; 3913 rl = &rl_intra_aic;
3872 i = 0; 3914 i = 0;
3914 if (s->mb_intra && s->h263_aic) 3956 if (s->mb_intra && s->h263_aic)
3915 goto not_coded; 3957 goto not_coded;
3916 s->block_last_index[n] = i - 1; 3958 s->block_last_index[n] = i - 1;
3917 return 0; 3959 return 0;
3918 } 3960 }
3919 3961 retry:
3920 for(;;) { 3962 for(;;) {
3921 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); 3963 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
3922 if (code < 0){ 3964 if (code < 0){
3923 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); 3965 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
3924 return -1; 3966 return -1;
3955 if (get_bits1(&s->gb)) 3997 if (get_bits1(&s->gb))
3956 level = -level; 3998 level = -level;
3957 } 3999 }
3958 i += run; 4000 i += run;
3959 if (i >= 64){ 4001 if (i >= 64){
4002 if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){
4003 //looks like a hack but no, its the way its supposed to work ...
4004 rl = &rl_intra_aic;
4005 i = 0;
4006 s->gb= gb;
4007 memset(block, 0, sizeof(DCTELEM)*64);
4008 goto retry;
4009 }
3960 av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y); 4010 av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
3961 return -1; 4011 return -1;
3962 } 4012 }
3963 j = scan_table[i]; 4013 j = scan_table[i];
3964 block[j] = level; 4014 block[j] = level;
4406 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); 4456 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
4407 } 4457 }
4408 if (get_bits1(&s->gb) != 0) { 4458 if (get_bits1(&s->gb) != 0) {
4409 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); 4459 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
4410 } 4460 }
4411 if (get_bits1(&s->gb) != 0) { 4461 s->alt_inter_vlc= get_bits1(&s->gb);
4412 av_log(s->avctx, AV_LOG_ERROR, "Alternative Inter VLC not supported\n");
4413 }
4414 if (get_bits1(&s->gb) != 0) { 4462 if (get_bits1(&s->gb) != 0) {
4415 av_log(s->avctx, AV_LOG_ERROR, "Modified Quantization not supported\n"); 4463 av_log(s->avctx, AV_LOG_ERROR, "Modified Quantization not supported\n");
4416 } 4464 }
4417 4465
4418 skip_bits(&s->gb, 1); /* Prevent start code emulation */ 4466 skip_bits(&s->gb, 1); /* Prevent start code emulation */
4489 s->y_dc_scale_table= 4537 s->y_dc_scale_table=
4490 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; 4538 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
4491 } 4539 }
4492 4540
4493 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 4541 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
4494 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s\n", 4542 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s\n",
4495 s->qscale, av_get_pict_type_char(s->pict_type), 4543 s->qscale, av_get_pict_type_char(s->pict_type),
4496 s->gb.size_in_bits, 1-s->no_rounding, 4544 s->gb.size_in_bits, 1-s->no_rounding,
4497 s->obmc ? " AP" : "", 4545 s->obmc ? " AP" : "",
4498 s->umvplus ? " UMV" : "", 4546 s->umvplus ? " UMV" : "",
4499 s->h263_long_vectors ? " LONG" : "", 4547 s->h263_long_vectors ? " LONG" : "",
4500 s->h263_plus ? " +" : "", 4548 s->h263_plus ? " +" : "",
4501 s->h263_aic ? " AIC" : "" 4549 s->h263_aic ? " AIC" : "",
4550 s->alt_inter_vlc ? " AIV" : ""
4502 ); 4551 );
4503 } 4552 }
4504 #if 1 4553 #if 1
4505 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){ 4554 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){
4506 int i,j; 4555 int i,j;