From 43d7c6118d64a8b2772e2d9e0c13413968e776f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Thu, 1 Oct 2009 15:40:29 +0000 Subject: put_bits can only reliably write up to 31 bit bits, above it relies on undefined shift behaviour. Document this, fix the assert and add a put_bits32 to handle writing 32 bits and use that where necessary. Originally committed as revision 20124 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/put_bits.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'libavcodec/put_bits.h') diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h index 4b4b3a873a..b081c26842 100644 --- a/libavcodec/put_bits.h +++ b/libavcodec/put_bits.h @@ -136,6 +136,10 @@ void ff_put_string(PutBitContext * pbc, const char *s, int terminate_string); */ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); +/** + * Write up to 31 bits into a bitstream. + * Use put_bits32 to write 32 bits. + */ static inline void put_bits(PutBitContext *s, int n, unsigned int value) #ifndef ALT_BITSTREAM_WRITER { @@ -143,7 +147,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) int bit_left; // printf("put_bits=%d %x\n", n, value); - assert(n == 32 || value < (1U << n)); + assert(n <= 31 && value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; @@ -259,6 +263,22 @@ static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) put_bits(pb, bits, val & ((1<> 16; +#ifdef ALT_BITSTREAM_WRITER_LE + put_bits(s, 16, lo); + put_bits(s, 16, hi); +#else + put_bits(s, 16, hi); + put_bits(s, 16, lo); +#endif +} + /** * Returns the pointer to the byte where the bitstream writer will put * the next bit. -- cgit v1.2.3