diff options
Diffstat (limited to 'libavcodec/put_bits.h')
-rw-r--r-- | libavcodec/put_bits.h | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h index 17666fa..81be6b3 100644 --- a/libavcodec/put_bits.h +++ b/libavcodec/put_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 */ @@ -28,9 +28,9 @@ #include <stdint.h> #include <stddef.h> -#include <assert.h> #include "libavutil/intreadwrite.h" +#include "libavutil/avassert.h" typedef struct PutBitContext { uint32_t bit_buf; @@ -62,6 +62,24 @@ static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, } /** + * Rebase the bit writer onto a reallocated buffer. + * + * @param buffer the buffer where to put bits + * @param buffer_size the size in bytes of buffer, + * must be larger than the previous size + */ +static inline void rebase_put_bits(PutBitContext *s, uint8_t *buffer, + int buffer_size) +{ + av_assert0(8*buffer_size > s->size_in_bits); + + s->buf_end = buffer + buffer_size; + s->buf_ptr = buffer + (s->buf_ptr - s->buf); + s->buf = buffer; + s->size_in_bits = 8 * buffer_size; +} + +/** * @return the total number of bits written to the bitstream. */ static inline int put_bits_count(PutBitContext *s) @@ -136,7 +154,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) unsigned int bit_buf; int bit_left; - assert(n <= 31 && value < (1U << n)); + av_assert2(n <= 31 && value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; @@ -145,6 +163,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) #ifdef BITSTREAM_WRITER_LE bit_buf |= value << (32 - bit_left); if (n >= bit_left) { + av_assert2(s->buf_ptr+3<s->buf_end); AV_WL32(s->buf_ptr, bit_buf); s->buf_ptr += 4; bit_buf = (bit_left == 32) ? 0 : value >> bit_left; @@ -158,6 +177,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) } else { bit_buf <<= bit_left; bit_buf |= value >> (n - bit_left); + av_assert2(s->buf_ptr+3<s->buf_end); AV_WB32(s->buf_ptr, bit_buf); s->buf_ptr += 4; bit_left += 32 - n; @@ -171,7 +191,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) static inline void put_sbits(PutBitContext *pb, int n, int32_t value) { - assert(n >= 0 && n <= 31); + av_assert2(n >= 0 && n <= 31); put_bits(pb, n, value & ((1 << n) - 1)); } @@ -207,8 +227,8 @@ static inline uint8_t *put_bits_ptr(PutBitContext *s) */ static inline void skip_put_bytes(PutBitContext *s, int n) { - assert((put_bits_count(s) & 7) == 0); - assert(s->bit_left == 32); + av_assert2((put_bits_count(s) & 7) == 0); + av_assert2(s->bit_left == 32); s->buf_ptr += n; } |