H.264句法和语法总结(十四)CAVLC 残差句法

residual_block_cavlc( coeffLevel, maxNumCoeff ) {  C      Descriptor
    for( i = 0; i < maxNumCoeff; i++ )          
        coeffLevel[ i ] = 0     
    // coeff_token      指明了非零系数的个数,拖尾系数的个数。      
    coeff_token 
    if( TotalCoeff( coeff_token ) > 0 ) {          
        if( TotalCoeff( coeff_token ) > 10    &&    TrailingOnes( coeff_token ) <
3 )
            suffixLength = 1          
        else          
            suffixLength = 0          
        for( i = 0; i < TotalCoeff( coeff_token ); i++ )          
            if( i < TrailingOnes( coeff_token ) ) {           
                // trailing_ones_sign_flag  拖尾系数的符号
                    -     如果trailing_ones_sign_flag = 0,  相应的拖尾系数是+1。
                    -     否则,trailing_ones_sign_flag =1,相应的拖尾系数是-1。 
                trailing_ones_sign_flag  
                level[ i ] = 1 – 2 * trailing_ones_sign_flag          
            } else {          
                // level_prefix and level_suffix  非零系数值的前缀和后缀。 
                level_prefix 
                levelCode = ( level_prefix << suffixLength )          
                if( suffixLength > 0    | |    level_prefix >= 14 ) {          
                    level_suffix  
                    levelCode += level_suffix          
                }          
                if( level_prefix    = =    15    &&    suffixLength    = =    0 )          
                    levelCode += 15          
                if( i    = =    TrailingOnes( coeff_token )    &&    
                      TrailingOnes( coeff_token ) < 3 )
                    levelCode += 2          
                if( levelCode % 2    = =    0 )          
                    level[ i ] = ( levelCode + 2 ) >> 1          
                else          
                    level[ i ] = ( –levelCode – 1 ) >> 1          
                if( suffixLength    = =    0 )          
                    suffixLength = 1          
                if( Abs( level[ i ] )    >    ( 3 << ( suffixLength – 1 ) )    &&    
                      suffixLength < 6 )
                    suffixLength++          
            }          
        if( TotalCoeff( coeff_token ) < maxNumCoeff ) {          
            // total_zeros    系数中 0 的总个数。
            total_zeros   
            zerosLeft = total_zeros          
        } else          
            zerosLeft = 0          
        for( i = 0; i < TotalCoeff( coeff_token ) – 1; i++ ) {          
            if( zerosLeft > 0 ) {          
               
                run_before   
                run[ i ] = run_before          
            } else          
                run[ i ] = 0          
            zerosLeft = zerosLeft – run[ i ]          
        }          
        run[ TotalCoeff( coeff_token ) – 1 ] = zerosLeft          
        coeffNum = -1          
        for( i = TotalCoeff( coeff_token ) – 1; i >= 0; i-- ) {          
            coeffNum += run[ i ] + 1          
            coeffLevel[ coeffNum ] = level[ i ]            
        }          
    }          
}

你可能感兴趣的:(token,Descriptor,h.264)