Commit cccb0ffc authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/put_bits: Always check buffer end before writing

This causes a overall slowdown of 0.1 % (tested with mpeg4 single thread encoding of matrixbench at QP=3)
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent a3023862
...@@ -163,9 +163,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) ...@@ -163,9 +163,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
#ifdef BITSTREAM_WRITER_LE #ifdef BITSTREAM_WRITER_LE
bit_buf |= value << (32 - bit_left); bit_buf |= value << (32 - bit_left);
if (n >= bit_left) { if (n >= bit_left) {
av_assert2(s->buf_ptr+3<s->buf_end); if (3 < s->buf_end - s->buf_ptr) {
AV_WL32(s->buf_ptr, bit_buf); AV_WL32(s->buf_ptr, bit_buf);
s->buf_ptr += 4; s->buf_ptr += 4;
} else {
av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
av_assert2(0);
}
bit_buf = value >> bit_left; bit_buf = value >> bit_left;
bit_left += 32; bit_left += 32;
} }
...@@ -177,9 +181,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) ...@@ -177,9 +181,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
} else { } else {
bit_buf <<= bit_left; bit_buf <<= bit_left;
bit_buf |= value >> (n - bit_left); bit_buf |= value >> (n - bit_left);
av_assert2(s->buf_ptr+3<s->buf_end); if (3 < s->buf_end - s->buf_ptr) {
AV_WB32(s->buf_ptr, bit_buf); AV_WB32(s->buf_ptr, bit_buf);
s->buf_ptr += 4; s->buf_ptr += 4;
} else {
av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
av_assert2(0);
}
bit_left += 32 - n; bit_left += 32 - n;
bit_buf = value; bit_buf = value;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment