comparison h264.c @ 2312:cb958ec6dfee libavcodec

decode intra cabac mb_type cleanup
author michael
date Sat, 23 Oct 2004 12:07:57 +0000
parents cdbb2f30e08b
children b5376aef1fe0
comparison
equal deleted inserted replaced
2311:cdbb2f30e08b 2312:cb958ec6dfee
3784 write_back_non_zero_count(h); 3784 write_back_non_zero_count(h);
3785 3785
3786 return 0; 3786 return 0;
3787 } 3787 }
3788 3788
3789 static int decode_cabac_mb_type( H264Context *h ) { 3789 static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) {
3790 MpegEncContext * const s = &h->s; 3790 uint8_t *state= &h->cabac_state[ctx_base];
3791 3791 int mb_type;
3792 if( h->slice_type == I_TYPE ) { 3792
3793 if(intra_slice){
3794 MpegEncContext * const s = &h->s;
3793 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 3795 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
3794 int ctx = 0; 3796 int ctx=0;
3795 int mb_type;
3796
3797 if( s->mb_x > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-1] ) ) 3797 if( s->mb_x > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-1] ) )
3798 ctx++; 3798 ctx++;
3799 if( s->mb_y > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-s->mb_stride] ) ) 3799 if( s->mb_y > 0 && !IS_INTRA4x4( s->current_picture.mb_type[mb_xy-s->mb_stride] ) )
3800 ctx++; 3800 ctx++;
3801 3801 if( get_cabac( &h->cabac, &state[ctx] ) == 0 )
3802 if( get_cabac( &h->cabac, &h->cabac_state[3+ctx] ) == 0 )
3803 return 0; /* I4x4 */ 3802 return 0; /* I4x4 */
3804 3803 state += 2;
3805 if( get_cabac_terminate( &h->cabac ) ) 3804 }else{
3806 return 25; /* PCM */ 3805 if( get_cabac( &h->cabac, &state[0] ) == 0 )
3807 3806 return 0; /* I4x4 */
3808 mb_type = 1; /* I16x16 */ 3807 }
3809 if( get_cabac( &h->cabac, &h->cabac_state[3+3] ) ) 3808
3810 mb_type += 12; /* cbp_luma != 0 */ 3809 if( get_cabac_terminate( &h->cabac ) )
3811 3810 return 25; /* PCM */
3812 if( get_cabac( &h->cabac, &h->cabac_state[3+4] ) ) { 3811
3813 if( get_cabac( &h->cabac, &h->cabac_state[3+5] ) ) 3812 mb_type = 1; /* I16x16 */
3814 mb_type += 4 * 2; /* cbp_chroma == 2 */ 3813 if( get_cabac( &h->cabac, &state[1] ) )
3815 else 3814 mb_type += 12; /* cbp_luma != 0 */
3816 mb_type += 4 * 1; /* cbp_chroma == 1 */ 3815
3817 } 3816 if( get_cabac( &h->cabac, &state[2] ) ) {
3818 if( get_cabac( &h->cabac, &h->cabac_state[3+6] ) ) 3817 if( get_cabac( &h->cabac, &state[2+intra_slice] ) )
3819 mb_type += 2; 3818 mb_type += 4 * 2; /* cbp_chroma == 2 */
3820 if( get_cabac( &h->cabac, &h->cabac_state[3+7] ) ) 3819 else
3821 mb_type += 1; 3820 mb_type += 4 * 1; /* cbp_chroma == 1 */
3822 return mb_type; 3821 }
3823 3822 if( get_cabac( &h->cabac, &state[3+intra_slice] ) )
3823 mb_type += 2;
3824 if( get_cabac( &h->cabac, &state[3+2*intra_slice] ) )
3825 mb_type += 1;
3826 return mb_type;
3827 }
3828
3829 static int decode_cabac_mb_type( H264Context *h ) {
3830 MpegEncContext * const s = &h->s;
3831
3832 if( h->slice_type == I_TYPE ) {
3833 return decode_cabac_intra_mb_type(h, 3, 1);
3824 } else if( h->slice_type == P_TYPE ) { 3834 } else if( h->slice_type == P_TYPE ) {
3825 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) { 3835 if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) {
3826 /* P-type */ 3836 /* P-type */
3827 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) { 3837 if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) {
3828 if( get_cabac( &h->cabac, &h->cabac_state[16] ) == 0 ) 3838 if( get_cabac( &h->cabac, &h->cabac_state[16] ) == 0 )
3834 return 2; /* P_L0_D8x16; */ 3844 return 2; /* P_L0_D8x16; */
3835 else 3845 else
3836 return 1; /* P_L0_D16x8; */ 3846 return 1; /* P_L0_D16x8; */
3837 } 3847 }
3838 } else { 3848 } else {
3839 int mb_type; 3849 return decode_cabac_intra_mb_type(h, 17, 0) + 5;
3840 /* I-type */
3841 if( get_cabac( &h->cabac, &h->cabac_state[17] ) == 0 )
3842 return 5+0; /* I_4x4 */
3843 if( get_cabac_terminate( &h->cabac ) )
3844 return 5+25; /*I_PCM */
3845 mb_type = 5+1; /* I16x16 */
3846 if( get_cabac( &h->cabac, &h->cabac_state[17+1] ) )
3847 mb_type += 12; /* cbp_luma != 0 */
3848
3849 if( get_cabac( &h->cabac, &h->cabac_state[17+2] ) ) {
3850 if( get_cabac( &h->cabac, &h->cabac_state[17+2] ) )
3851 mb_type += 4 * 2; /* cbp_chroma == 2 */
3852 else
3853 mb_type += 4 * 1; /* cbp_chroma == 1 */
3854 }
3855 if( get_cabac( &h->cabac, &h->cabac_state[17+3] ) )
3856 mb_type += 2;
3857 if( get_cabac( &h->cabac, &h->cabac_state[17+3] ) )
3858 mb_type += 1;
3859
3860 return mb_type;
3861 } 3850 }
3862 } else if( h->slice_type == B_TYPE ) { 3851 } else if( h->slice_type == B_TYPE ) {
3863 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 3852 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
3864 int ctx = 0; 3853 int ctx = 0;
3865 int bits; 3854 int bits;
3883 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1; 3872 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1;
3884 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ); 3873 bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] );
3885 if( bits < 8 ) 3874 if( bits < 8 )
3886 return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ 3875 return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */
3887 else if( bits == 13 ) { 3876 else if( bits == 13 ) {
3888 int mb_type; 3877 return decode_cabac_intra_mb_type(h, 32, 0) + 23;
3889 /* I-type */
3890 if( get_cabac( &h->cabac, &h->cabac_state[32] ) == 0 )
3891 return 23+0; /* I_4x4 */
3892 if( get_cabac_terminate( &h->cabac ) )
3893 return 23+25; /* I_PCM */
3894 mb_type = 23+1; /* I_16x16 */
3895 if( get_cabac( &h->cabac, &h->cabac_state[32+1] ) )
3896 mb_type += 12; /* cbp_luma != 0 */
3897
3898 if( get_cabac( &h->cabac, &h->cabac_state[32+2] ) ) {
3899 if( get_cabac( &h->cabac, &h->cabac_state[32+2] ) )
3900 mb_type += 4 * 2; /* cbp_chroma == 2 */
3901 else
3902 mb_type += 4 * 1; /* cbp_chroma == 1 */
3903 }
3904 if( get_cabac( &h->cabac, &h->cabac_state[32+3] ) )
3905 mb_type += 2;
3906 if( get_cabac( &h->cabac, &h->cabac_state[32+3] ) )
3907 mb_type += 1;
3908
3909 return mb_type;
3910 } else if( bits == 14 ) 3878 } else if( bits == 14 )
3911 return 11; /* B_L1_L0_8x16 */ 3879 return 11; /* B_L1_L0_8x16 */
3912 else if( bits == 15 ) 3880 else if( bits == 15 )
3913 return 22; /* B_8x8 */ 3881 return 22; /* B_8x8 */
3914 3882
5451 5419
5452 profile_idc= get_bits(&s->gb, 8); 5420 profile_idc= get_bits(&s->gb, 8);
5453 get_bits1(&s->gb); //constraint_set0_flag 5421 get_bits1(&s->gb); //constraint_set0_flag
5454 get_bits1(&s->gb); //constraint_set1_flag 5422 get_bits1(&s->gb); //constraint_set1_flag
5455 get_bits1(&s->gb); //constraint_set2_flag 5423 get_bits1(&s->gb); //constraint_set2_flag
5456 get_bits(&s->gb, 5); // reserved 5424 get_bits1(&s->gb); //constraint_set3_flag
5425 get_bits(&s->gb, 4); // reserved
5457 level_idc= get_bits(&s->gb, 8); 5426 level_idc= get_bits(&s->gb, 8);
5458 sps_id= get_ue_golomb(&s->gb); 5427 sps_id= get_ue_golomb(&s->gb);
5459 5428
5460 sps= &h->sps_buffer[ sps_id ]; 5429 sps= &h->sps_buffer[ sps_id ];
5461 sps->profile_idc= profile_idc; 5430 sps->profile_idc= profile_idc;
5462 sps->level_idc= level_idc; 5431 sps->level_idc= level_idc;
5463 5432
5464 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; 5433 sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
5465 sps->poc_type= get_ue_golomb(&s->gb); 5434 sps->poc_type= get_ue_golomb(&s->gb);
5466 5435
5467 if(sps->poc_type == 0){ //FIXME #define 5436 if(sps->poc_type == 0){ //FIXME #define
5468 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; 5437 sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4;