diff options
Diffstat (limited to 'libavcodec/get_bits.h')
-rw-r--r-- | libavcodec/get_bits.h | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index f91441c120..a1a48ab87d 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -1,20 +1,20 @@ /* * copyright (c) 2004 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 */ @@ -30,6 +30,7 @@ #include "libavutil/common.h" #include "libavutil/intreadwrite.h" #include "libavutil/log.h" +#include "libavutil/avassert.h" #include "mathops.h" /* @@ -53,9 +54,7 @@ typedef struct GetBitContext { const uint8_t *buffer, *buffer_end; int index; int size_in_bits; -#if !UNCHECKED_BITSTREAM_READER int size_in_bits_plus8; -#endif } GetBitContext; #define VLC_TYPE int16_t @@ -123,7 +122,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #if UNCHECKED_BITSTREAM_READER #define OPEN_READER(name, gb) \ unsigned int name##_index = (gb)->index; \ - unsigned int av_unused name##_cache = 0 + av_unused unsigned int name##_cache #define HAVE_BITS_REMAINING(name, gb) 1 #else @@ -224,6 +223,7 @@ static inline int get_sbits(GetBitContext *s, int n) { register int tmp; OPEN_READER(re, s); + av_assert2(n>0 && n<=25); UPDATE_CACHE(re, s); tmp = SHOW_SBITS(re, s, n); LAST_SKIP_BITS(re, s, n); @@ -238,6 +238,7 @@ static inline unsigned int get_bits(GetBitContext *s, int n) { register int tmp; OPEN_READER(re, s); + av_assert2(n>0 && n<=25); UPDATE_CACHE(re, s); tmp = SHOW_UBITS(re, s, n); LAST_SKIP_BITS(re, s, n); @@ -252,6 +253,7 @@ static inline unsigned int show_bits(GetBitContext *s, int n) { register int tmp; OPEN_READER(re, s); + av_assert2(n>0 && n<=25); UPDATE_CACHE(re, s); tmp = SHOW_UBITS(re, s, n); return tmp; @@ -300,20 +302,40 @@ static inline void skip_bits1(GetBitContext *s) */ static inline unsigned int get_bits_long(GetBitContext *s, int n) { - if (n <= MIN_CACHE_BITS) + if (!n) { + return 0; + } else if (n <= MIN_CACHE_BITS) return get_bits(s, n); else { #ifdef BITSTREAM_READER_LE - int ret = get_bits(s, 16); + unsigned ret = get_bits(s, 16); return ret | (get_bits(s, n-16) << 16); #else - int ret = get_bits(s, 16) << (n-16); + unsigned ret = get_bits(s, 16) << (n-16); return ret | get_bits(s, n-16); #endif } } /** + * Read 0-64 bits. + */ +static inline uint64_t get_bits_longlong(GetBitContext *s, int n) +{ + if (n <= 32) + return get_bits_long(s, n); + else { +#ifdef BITSTREAM_READER_LE + uint64_t ret = get_bits_long(s, 32); + return ret | (((uint64_t)get_bits_long(s, n-32)) << 32); +#else + uint64_t ret = ((uint64_t)get_bits_long(s, 32)) << (n-32); + return ret | get_bits_long(s, n-32); +#endif + } +} + +/** * Read 0-32 bits as a signed integer. */ static inline int get_sbits_long(GetBitContext *s, int n) @@ -360,9 +382,7 @@ static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, s->buffer = buffer; s->size_in_bits = bit_size; -#if !UNCHECKED_BITSTREAM_READER s->size_in_bits_plus8 = bit_size + 8; -#endif s->buffer_end = buffer + buffer_size; s->index = 0; } |