]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/put_bits: Relax requirements to rebase PutBitContext
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 16 Nov 2019 05:24:29 +0000 (06:24 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 16 Nov 2019 19:57:45 +0000 (20:57 +0100)
The earlier requirement was for the new buffer to be bigger than the old
one. This has been relaxed to only demand that the new buffer can hold
all the data written so far. This is in preparation for further commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/put_bits.h

index 1ceb1cc766246dff19de5d7baf97a5c79a3bc157..7d11a3576a5c1d4c026198a4f8278a7099cb0a66 100644 (file)
@@ -61,17 +61,25 @@ static inline void init_put_bits(PutBitContext *s, uint8_t *buffer,
     s->bit_buf      = 0;
 }
 
+/**
+ * @return the total number of bits written to the bitstream.
+ */
+static inline int put_bits_count(PutBitContext *s)
+{
+    return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+}
+
 /**
  * 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
+ *                    must be large enough to hold everything written so far
  */
 static inline void rebase_put_bits(PutBitContext *s, uint8_t *buffer,
                                    int buffer_size)
 {
-    av_assert0(8*buffer_size > s->size_in_bits);
+    av_assert0(8*buffer_size >= put_bits_count(s));
 
     s->buf_end = buffer + buffer_size;
     s->buf_ptr = buffer + (s->buf_ptr - s->buf);
@@ -79,14 +87,6 @@ static inline void rebase_put_bits(PutBitContext *s, uint8_t *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)
-{
-    return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
-}
-
 /**
  * @return the number of bits available in the bitstream.
  */