Mercurial > libavcodec.hg
diff put_bits.h @ 10344:2b8a327189cd libavcodec
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.
author | reimar |
---|---|
date | Thu, 01 Oct 2009 15:40:29 +0000 |
parents | 2887f410011f |
children | 784409693f16 |
line wrap: on
line diff
--- a/put_bits.h Thu Oct 01 15:30:27 2009 +0000 +++ b/put_bits.h Thu Oct 01 15:40:29 2009 +0000 @@ -136,6 +136,10 @@ */ 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 @@ 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; @@ -260,6 +264,22 @@ } /** + * Write exactly 32 bits into a bitstream + */ +static void av_unused put_bits32(PutBitContext *s, uint32_t value) +{ + int lo = value & 0xffff; + int hi = value >> 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. */