diff options
Diffstat (limited to 'libavcodec/cabac_functions.h')
-rw-r--r-- | libavcodec/cabac_functions.h | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h index beb5016..fe72a82 100644 --- a/libavcodec/cabac_functions.h +++ b/libavcodec/cabac_functions.h @@ -2,20 +2,20 @@ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -32,6 +32,10 @@ #include "cabac.h" #include "config.h" +#ifndef UNCHECKED_BITSTREAM_READER +#define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER +#endif + #if ARCH_AARCH64 # include "aarch64/cabac.h" #endif @@ -47,6 +51,7 @@ static const uint8_t * const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS static const uint8_t * const ff_h264_mlps_state = ff_h264_cabac_tables + H264_MLPS_STATE_OFFSET; static const uint8_t * const ff_h264_last_coeff_flag_offset_8x8 = ff_h264_cabac_tables + H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET; +#if !defined(get_cabac_bypass) || !defined(get_cabac_terminate) static void refill(CABACContext *c){ #if CABAC_BITS == 16 c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); @@ -54,10 +59,14 @@ static void refill(CABACContext *c){ c->low+= c->bytestream[0]<<1; #endif c->low -= CABAC_MASK; +#if !UNCHECKED_BITSTREAM_READER if (c->bytestream < c->bytestream_end) +#endif c->bytestream += CABAC_BITS / 8; } +#endif +#ifndef get_cabac_terminate static inline void renorm_cabac_decoder_once(CABACContext *c){ int shift= (uint32_t)(c->range - 0x100)>>31; c->range<<= shift; @@ -65,13 +74,18 @@ static inline void renorm_cabac_decoder_once(CABACContext *c){ if(!(c->low & CABAC_MASK)) refill(c); } +#endif #ifndef get_cabac_inline static void refill2(CABACContext *c){ - int i, x; - + int i; + unsigned x; +#if !HAVE_FAST_CLZ x= c->low ^ (c->low-1); i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)]; +#else + i = ff_ctz(c->low) - CABAC_BITS; +#endif x= -CABAC_MASK; @@ -82,10 +96,14 @@ static void refill2(CABACContext *c){ #endif c->low += x<<i; +#if !UNCHECKED_BITSTREAM_READER if (c->bytestream < c->bytestream_end) +#endif c->bytestream += CABAC_BITS/8; } +#endif +#ifndef get_cabac_inline static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ int s = *state; int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s]; @@ -156,6 +174,7 @@ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ /** * @return the number of bytes read or 0 if no end */ +#ifndef get_cabac_terminate static int av_unused get_cabac_terminate(CABACContext *c){ c->range -= 2; if(c->low < c->range<<(CABAC_BITS+1)){ @@ -165,11 +184,13 @@ static int av_unused get_cabac_terminate(CABACContext *c){ return c->bytestream - c->bytestream_start; } } +#endif /** * 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 */ +#ifndef skip_bytes static av_unused const uint8_t* skip_bytes(CABACContext *c, int n) { const uint8_t *ptr = c->bytestream; @@ -181,9 +202,11 @@ static av_unused const uint8_t* skip_bytes(CABACContext *c, int n) { #endif if ((int) (c->bytestream_end - ptr) < n) return NULL; - ff_init_cabac_decoder(c, ptr + n, c->bytestream_end - ptr - n); + if (ff_init_cabac_decoder(c, ptr + n, c->bytestream_end - ptr - n) < 0) + return NULL; return ptr; } +#endif #endif /* AVCODEC_CABAC_FUNCTIONS_H */ |