X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fcabac_functions.h;h=4b8f1bca8a384f4a33ee6513aa7acf52114f23f8;hb=607ad990d31e6be52980970e5ce8cd25ab3de812;hp=b150aabcc44200e61b3c5d779b057a2aaef1198e;hpb=55b9ef18e4a139fc24a3b695cb3c176f3ced09b8;p=ffmpeg diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h index b150aabcc44..4b8f1bca8a3 100644 --- a/libavcodec/cabac_functions.h +++ b/libavcodec/cabac_functions.h @@ -32,13 +32,20 @@ #include "cabac.h" #include "config.h" +#if ARCH_AARCH64 +# include "aarch64/cabac.h" +#endif +#if ARCH_ARM +# include "arm/cabac.h" +#endif #if ARCH_X86 # include "x86/cabac.h" #endif -extern const uint8_t ff_h264_norm_shift[512]; -extern uint8_t ff_h264_mlps_state[4*64]; -extern uint8_t ff_h264_lps_range[4*2*64]; ///< rangeTabLPS +static uint8_t * const ff_h264_norm_shift = ff_h264_cabac_tables + H264_NORM_SHIFT_OFFSET; +static uint8_t * const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS_RANGE_OFFSET; +static uint8_t * const ff_h264_mlps_state = ff_h264_cabac_tables + H264_MLPS_STATE_OFFSET; +static uint8_t * const ff_h264_last_coeff_flag_offset_8x8 = ff_h264_cabac_tables + H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET; static void refill(CABACContext *c){ #if CABAC_BITS == 16 @@ -47,7 +54,8 @@ static void refill(CABACContext *c){ c->low+= c->bytestream[0]<<1; #endif c->low -= CABAC_MASK; - c->bytestream+= CABAC_BITS/8; + if (c->bytestream < c->bytestream_end) + c->bytestream += CABAC_BITS / 8; } static inline void renorm_cabac_decoder_once(CABACContext *c){ @@ -74,7 +82,8 @@ static void refill2(CABACContext *c){ #endif c->low += x<bytestream+= CABAC_BITS/8; + if (c->bytestream < c->bytestream_end) + c->bytestream += CABAC_BITS/8; } static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ @@ -109,6 +118,7 @@ static int av_unused get_cabac(CABACContext *c, uint8_t * const state){ return get_cabac_inline(c,state); } +#ifndef get_cabac_bypass static int av_unused get_cabac_bypass(CABACContext *c){ int range; c->low += c->low; @@ -124,7 +134,7 @@ static int av_unused get_cabac_bypass(CABACContext *c){ return 1; } } - +#endif #ifndef get_cabac_bypass_sign static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ @@ -157,4 +167,24 @@ static int av_unused get_cabac_terminate(CABACContext *c){ } } +/** + * Skip @p n bytes and reset the decoder. + * @return the address of the first skipped byte or NULL if there's less than @p n bytes left + */ +static av_unused const uint8_t* skip_bytes(CABACContext *c, int n) { + const uint8_t *ptr = c->bytestream; + + if (c->low & 0x1) + ptr--; +#if CABAC_BITS == 16 + if (c->low & 0x1FF) + ptr--; +#endif + if ((int) (c->bytestream_end - ptr) < n) + return NULL; + ff_init_cabac_decoder(c, ptr + n, c->bytestream_end - ptr - n); + + return ptr; +} + #endif /* AVCODEC_CABAC_FUNCTIONS_H */