27 #ifndef AVCODEC_CABAC_FUNCTIONS_H 28 #define AVCODEC_CABAC_FUNCTIONS_H 35 #ifndef UNCHECKED_BITSTREAM_READER 36 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER 40 # include "aarch64/cabac.h" 43 # include "arm/cabac.h" 46 # include "x86/cabac.h" 49 # include "mips/cabac.h" 52 static const uint8_t *
const ff_h264_norm_shift = ff_h264_cabac_tables + H264_NORM_SHIFT_OFFSET;
53 static const uint8_t *
const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS_RANGE_OFFSET;
54 static const uint8_t *
const ff_h264_mlps_state = ff_h264_cabac_tables + H264_MLPS_STATE_OFFSET;
55 static const uint8_t *
const ff_h264_last_coeff_flag_offset_8x8 = ff_h264_cabac_tables + H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET;
57 #if !defined(get_cabac_bypass) || !defined(get_cabac_terminate) 60 c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
62 c->low+= c->bytestream[0]<<1;
65 #if !UNCHECKED_BITSTREAM_READER 66 if (c->bytestream < c->bytestream_end)
68 c->bytestream += CABAC_BITS / 8;
72 #ifndef get_cabac_terminate 73 static inline void renorm_cabac_decoder_once(
CABACContext *c){
74 int shift= (uint32_t)(c->range - 0x100)>>31;
77 if(!(c->low & CABAC_MASK))
82 #ifndef get_cabac_inline 87 x= c->low ^ (c->low-1);
88 i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
90 i = ff_ctz(c->low) - CABAC_BITS;
96 x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
98 x+= c->bytestream[0]<<1;
102 #if !UNCHECKED_BITSTREAM_READER 103 if (c->bytestream < c->bytestream_end)
105 c->bytestream += CABAC_BITS/8;
109 #ifndef get_cabac_inline 110 static av_always_inline
int get_cabac_inline(
CABACContext *c, uint8_t *
const state){
112 int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
115 c->range -= RangeLPS;
116 lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
118 c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
119 c->range += (RangeLPS - c->range) & lps_mask;
122 *state= (ff_h264_mlps_state+128)[s];
125 lps_mask= ff_h264_norm_shift[c->range];
126 c->range<<= lps_mask;
128 if(!(c->low & CABAC_MASK))
134 static int av_noinline av_unused get_cabac_noinline(
CABACContext *c, uint8_t *
const state){
135 return get_cabac_inline(c,state);
138 static int av_unused get_cabac(
CABACContext *c, uint8_t *
const state){
139 return get_cabac_inline(c,state);
142 #ifndef get_cabac_bypass 147 if(!(c->low & CABAC_MASK))
150 range= c->range<<(CABAC_BITS+1);
160 #ifndef get_cabac_bypass_sign 161 static av_always_inline
int get_cabac_bypass_sign(
CABACContext *c,
int val){
165 if(!(c->low & CABAC_MASK))
168 range= c->range<<(CABAC_BITS+1);
173 return (val^mask)-mask;
180 #ifndef get_cabac_terminate 181 static int av_unused get_cabac_terminate(
CABACContext *c){
183 if(c->low < c->range<<(CABAC_BITS+1)){
184 renorm_cabac_decoder_once(c);
187 return c->bytestream - c->bytestream_start;
197 static av_unused
const uint8_t* skip_bytes(
CABACContext *c,
int n) {
198 const uint8_t *ptr = c->bytestream;
206 if ((
int) (c->bytestream_end - ptr) < n)
int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
Definition: cabac.c:177