Mercurial > libavcodec.hg
comparison h263.c @ 1132:61c89e8ffa88 libavcodec
rvlc decoding support
author | michaelni |
---|---|
date | Wed, 12 Mar 2003 23:09:18 +0000 |
parents | 77ccf7fe3bd0 |
children | 47558360835e |
comparison
equal
deleted
inserted
replaced
1131:2575d16b62d7 | 1132:61c89e8ffa88 |
---|---|
68 static int h263p_decode_umotion(MpegEncContext * s, int pred); | 68 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
69 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, | 69 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
70 int n, int coded); | 70 int n, int coded); |
71 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); | 71 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); |
72 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | 72 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
73 int n, int coded, int intra); | 73 int n, int coded, int intra, int rvlc); |
74 static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr); | 74 static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr); |
75 #ifdef CONFIG_ENCODERS | 75 #ifdef CONFIG_ENCODERS |
76 static void mpeg4_inv_pred_ac(MpegEncContext * s, DCTELEM *block, int n, | 76 static void mpeg4_inv_pred_ac(MpegEncContext * s, DCTELEM *block, int n, |
77 int dir); | 77 int dir); |
78 #endif //CONFIG_ENCODERS | 78 #endif //CONFIG_ENCODERS |
2306 init_vlc(&mv_vlc, MV_VLC_BITS, 33, | 2306 init_vlc(&mv_vlc, MV_VLC_BITS, 33, |
2307 &mvtab[0][1], 2, 1, | 2307 &mvtab[0][1], 2, 1, |
2308 &mvtab[0][0], 2, 1); | 2308 &mvtab[0][0], 2, 1); |
2309 init_rl(&rl_inter); | 2309 init_rl(&rl_inter); |
2310 init_rl(&rl_intra); | 2310 init_rl(&rl_intra); |
2311 init_rl(&rvlc_rl_inter); | |
2312 init_rl(&rvlc_rl_intra); | |
2311 init_rl(&rl_intra_aic); | 2313 init_rl(&rl_intra_aic); |
2312 init_vlc_rl(&rl_inter); | 2314 init_vlc_rl(&rl_inter); |
2313 init_vlc_rl(&rl_intra); | 2315 init_vlc_rl(&rl_intra); |
2316 init_vlc_rl(&rvlc_rl_inter); | |
2317 init_vlc_rl(&rvlc_rl_intra); | |
2314 init_vlc_rl(&rl_intra_aic); | 2318 init_vlc_rl(&rl_intra_aic); |
2315 init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */, | 2319 init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */, |
2316 &DCtab_lum[0][1], 2, 1, | 2320 &DCtab_lum[0][1], 2, 1, |
2317 &DCtab_lum[0][0], 2, 1); | 2321 &DCtab_lum[0][0], 2, 1); |
2318 init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, | 2322 init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, |
3038 s->mcsel=0; | 3042 s->mcsel=0; |
3039 s->mb_skiped = 1; | 3043 s->mb_skiped = 1; |
3040 } | 3044 } |
3041 }else if(s->mb_intra){ | 3045 }else if(s->mb_intra){ |
3042 s->ac_pred = s->pred_dir_table[xy]>>7; | 3046 s->ac_pred = s->pred_dir_table[xy]>>7; |
3043 | |
3044 /* decode each block */ | |
3045 for (i = 0; i < 6; i++) { | |
3046 if(mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0){ | |
3047 fprintf(stderr, "texture corrupted at %d %d\n", s->mb_x, s->mb_y); | |
3048 return -1; | |
3049 } | |
3050 cbp+=cbp; | |
3051 } | |
3052 }else if(!s->mb_intra){ | 3047 }else if(!s->mb_intra){ |
3053 // s->mcsel= 0; //FIXME do we need to init that | 3048 // s->mcsel= 0; //FIXME do we need to init that |
3054 | 3049 |
3055 s->mv_dir = MV_DIR_FORWARD; | 3050 s->mv_dir = MV_DIR_FORWARD; |
3056 if (mb_type&MB_TYPE_INTER4V) { | 3051 if (mb_type&MB_TYPE_INTER4V) { |
3057 s->mv_type = MV_TYPE_8X8; | 3052 s->mv_type = MV_TYPE_8X8; |
3058 } else { | 3053 } else { |
3059 s->mv_type = MV_TYPE_16X16; | 3054 s->mv_type = MV_TYPE_16X16; |
3060 } | 3055 } |
3061 /* decode each block */ | |
3062 for (i = 0; i < 6; i++) { | |
3063 if(mpeg4_decode_block(s, block[i], i, cbp&32, 0) < 0){ | |
3064 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); | |
3065 return -1; | |
3066 } | |
3067 cbp+=cbp; | |
3068 } | |
3069 } | 3056 } |
3070 } else { /* I-Frame */ | 3057 } else { /* I-Frame */ |
3071 int i; | |
3072 s->mb_intra = 1; | 3058 s->mb_intra = 1; |
3073 s->ac_pred = s->pred_dir_table[xy]>>7; | 3059 s->ac_pred = s->pred_dir_table[xy]>>7; |
3074 | 3060 } |
3061 | |
3062 if (!(mb_type&MB_TYPE_SKIPED)) { | |
3063 int i; | |
3075 /* decode each block */ | 3064 /* decode each block */ |
3076 for (i = 0; i < 6; i++) { | 3065 for (i = 0; i < 6; i++) { |
3077 if(mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0){ | 3066 if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){ |
3078 fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y); | 3067 fprintf(stderr, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); |
3079 return -1; | 3068 return -1; |
3080 } | 3069 } |
3081 cbp+=cbp; | 3070 cbp+=cbp; |
3082 } | 3071 } |
3083 } | 3072 } |
3408 s->interlaced_dct= get_bits1(&s->gb); | 3397 s->interlaced_dct= get_bits1(&s->gb); |
3409 | 3398 |
3410 /* decode each block */ | 3399 /* decode each block */ |
3411 if (s->h263_pred) { | 3400 if (s->h263_pred) { |
3412 for (i = 0; i < 6; i++) { | 3401 for (i = 0; i < 6; i++) { |
3413 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1) < 0) | 3402 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0) |
3414 return -1; | 3403 return -1; |
3415 cbp+=cbp; | 3404 cbp+=cbp; |
3416 } | 3405 } |
3417 } else { | 3406 } else { |
3418 for (i = 0; i < 6; i++) { | 3407 for (i = 0; i < 6; i++) { |
3425 } | 3414 } |
3426 | 3415 |
3427 /* decode each block */ | 3416 /* decode each block */ |
3428 if (s->h263_pred) { | 3417 if (s->h263_pred) { |
3429 for (i = 0; i < 6; i++) { | 3418 for (i = 0; i < 6; i++) { |
3430 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0) < 0) | 3419 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0) |
3431 return -1; | 3420 return -1; |
3432 cbp+=cbp; | 3421 cbp+=cbp; |
3433 } | 3422 } |
3434 } else { | 3423 } else { |
3435 for (i = 0; i < 6; i++) { | 3424 for (i = 0; i < 6; i++) { |
3693 /** | 3682 /** |
3694 * decodes a block. | 3683 * decodes a block. |
3695 * @return <0 if an error occured | 3684 * @return <0 if an error occured |
3696 */ | 3685 */ |
3697 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | 3686 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
3698 int n, int coded, int intra) | 3687 int n, int coded, int intra, int rvlc) |
3699 { | 3688 { |
3700 int level, i, last, run; | 3689 int level, i, last, run; |
3701 int dc_pred_dir; | 3690 int dc_pred_dir; |
3702 RLTable * rl; | 3691 RLTable * rl; |
3703 RL_VLC_ELEM * rl_vlc; | 3692 RL_VLC_ELEM * rl_vlc; |
3704 const uint8_t * scan_table; | 3693 const uint8_t * scan_table; |
3705 int qmul, qadd; | 3694 int qmul, qadd; |
3706 | 3695 |
3696 //Note intra & rvlc should be optimized away if this is inlined | |
3697 | |
3707 if(intra) { | 3698 if(intra) { |
3708 /* DC coef */ | 3699 /* DC coef */ |
3709 if(s->partitioned_frame){ | 3700 if(s->partitioned_frame){ |
3710 level = s->dc_val[0][ s->block_index[n] ]; | 3701 level = s->dc_val[0][ s->block_index[n] ]; |
3711 if(n<4) level= (level + (s->y_dc_scale>>1))/s->y_dc_scale; //FIXME optimizs | 3702 if(n<4) level= (level + (s->y_dc_scale>>1))/s->y_dc_scale; //FIXME optimizs |
3718 } | 3709 } |
3719 block[0] = level; | 3710 block[0] = level; |
3720 i = 0; | 3711 i = 0; |
3721 if (!coded) | 3712 if (!coded) |
3722 goto not_coded; | 3713 goto not_coded; |
3723 rl = &rl_intra; | 3714 |
3724 rl_vlc = rl_intra.rl_vlc[0]; | 3715 if(rvlc){ |
3716 rl = &rvlc_rl_intra; | |
3717 rl_vlc = rvlc_rl_intra.rl_vlc[0]; | |
3718 }else{ | |
3719 rl = &rl_intra; | |
3720 rl_vlc = rl_intra.rl_vlc[0]; | |
3721 } | |
3725 if (s->ac_pred) { | 3722 if (s->ac_pred) { |
3726 if (dc_pred_dir == 0) | 3723 if (dc_pred_dir == 0) |
3727 scan_table = s->intra_v_scantable.permutated; /* left */ | 3724 scan_table = s->intra_v_scantable.permutated; /* left */ |
3728 else | 3725 else |
3729 scan_table = s->intra_h_scantable.permutated; /* top */ | 3726 scan_table = s->intra_h_scantable.permutated; /* top */ |
3736 i = -1; | 3733 i = -1; |
3737 if (!coded) { | 3734 if (!coded) { |
3738 s->block_last_index[n] = i; | 3735 s->block_last_index[n] = i; |
3739 return 0; | 3736 return 0; |
3740 } | 3737 } |
3741 rl = &rl_inter; | 3738 if(rvlc) rl = &rvlc_rl_inter; |
3739 else rl = &rl_inter; | |
3742 | 3740 |
3743 scan_table = s->intra_scantable.permutated; | 3741 scan_table = s->intra_scantable.permutated; |
3744 | 3742 |
3745 if(s->mpeg_quant){ | 3743 if(s->mpeg_quant){ |
3746 qmul=1; | 3744 qmul=1; |
3747 qadd=0; | 3745 qadd=0; |
3748 rl_vlc = rl_inter.rl_vlc[0]; | 3746 if(rvlc){ |
3747 rl_vlc = rvlc_rl_inter.rl_vlc[0]; | |
3748 }else{ | |
3749 rl_vlc = rl_inter.rl_vlc[0]; | |
3750 } | |
3749 }else{ | 3751 }else{ |
3750 qmul = s->qscale << 1; | 3752 qmul = s->qscale << 1; |
3751 qadd = (s->qscale - 1) | 1; | 3753 qadd = (s->qscale - 1) | 1; |
3752 rl_vlc = rl_inter.rl_vlc[s->qscale]; | 3754 if(rvlc){ |
3755 rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale]; | |
3756 }else{ | |
3757 rl_vlc = rl_inter.rl_vlc[s->qscale]; | |
3758 } | |
3753 } | 3759 } |
3754 } | 3760 } |
3755 { | 3761 { |
3756 OPEN_READER(re, &s->gb); | 3762 OPEN_READER(re, &s->gb); |
3757 for(;;) { | 3763 for(;;) { |
3758 UPDATE_CACHE(re, &s->gb); | 3764 UPDATE_CACHE(re, &s->gb); |
3759 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); | 3765 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); |
3760 if (level==0) { | 3766 if (level==0) { |
3767 /* escape */ | |
3768 if(rvlc){ | |
3769 if(SHOW_UBITS(re, &s->gb, 1)==0){ | |
3770 fprintf(stderr, "1. marker bit missing in rvlc esc\n"); | |
3771 return -1; | |
3772 }; SKIP_CACHE(re, &s->gb, 1); | |
3773 | |
3774 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); | |
3775 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); | |
3776 SKIP_COUNTER(re, &s->gb, 1+1+6); | |
3777 UPDATE_CACHE(re, &s->gb); | |
3778 | |
3779 if(SHOW_UBITS(re, &s->gb, 1)==0){ | |
3780 fprintf(stderr, "2. marker bit missing in rvlc esc\n"); | |
3781 return -1; | |
3782 }; SKIP_CACHE(re, &s->gb, 1); | |
3783 | |
3784 level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11); | |
3785 | |
3786 if(SHOW_UBITS(re, &s->gb, 5)!=0x10){ | |
3787 fprintf(stderr, "reverse esc missing\n"); | |
3788 return -1; | |
3789 }; SKIP_CACHE(re, &s->gb, 5); | |
3790 | |
3791 level= level * qmul + qadd; | |
3792 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); | |
3793 SKIP_COUNTER(re, &s->gb, 1+11+5+1); | |
3794 | |
3795 i+= run + 1; | |
3796 if(last) i+=192; | |
3797 }else{ | |
3761 int cache; | 3798 int cache; |
3762 cache= GET_CACHE(re, &s->gb); | 3799 cache= GET_CACHE(re, &s->gb); |
3763 /* escape */ | |
3764 if (cache&0x80000000) { | 3800 if (cache&0x80000000) { |
3765 if (cache&0x40000000) { | 3801 if (cache&0x40000000) { |
3766 /* third escape */ | 3802 /* third escape */ |
3767 SKIP_CACHE(re, &s->gb, 2); | 3803 SKIP_CACHE(re, &s->gb, 2); |
3768 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); | 3804 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); |
3840 i+= run; | 3876 i+= run; |
3841 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing | 3877 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing |
3842 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 3878 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
3843 LAST_SKIP_BITS(re, &s->gb, 1); | 3879 LAST_SKIP_BITS(re, &s->gb, 1); |
3844 } | 3880 } |
3881 } | |
3845 } else { | 3882 } else { |
3846 i+= run; | 3883 i+= run; |
3847 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | 3884 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
3848 LAST_SKIP_BITS(re, &s->gb, 1); | 3885 LAST_SKIP_BITS(re, &s->gb, 1); |
3849 } | 3886 } |