diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2016-04-11 19:18:50 +0200 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2017-02-11 20:29:44 +0100 |
commit | 9c2d36fcaf8748b9baa9aba9264abefce711d67b (patch) | |
tree | de6f7d360c30676bd8cc21bf49e6bbf1110f5f71 /libavcodec/bitstream.h | |
parent | ba30b74686f0cb6c9dd465ac4820059c48bf9d08 (diff) | |
download | ffmpeg-streaming-9c2d36fcaf8748b9baa9aba9264abefce711d67b.zip ffmpeg-streaming-9c2d36fcaf8748b9baa9aba9264abefce711d67b.tar.gz |
dv: Convert to the new bitstream reader
Diffstat (limited to 'libavcodec/bitstream.h')
-rw-r--r-- | libavcodec/bitstream.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libavcodec/bitstream.h b/libavcodec/bitstream.h index 996e32e..894a13e 100644 --- a/libavcodec/bitstream.h +++ b/libavcodec/bitstream.h @@ -384,4 +384,32 @@ static inline int bitstream_apply_sign(BitstreamContext *bc, int val) return (val ^ sign) - sign; } +/* Unwind the cache so a refill_32 can fill it again. */ +static inline void bitstream_unwind(BitstreamContext *bc) +{ + int unwind = 4; + int unwind_bits = unwind * 8; + + if (bc->bits_left < unwind_bits) + return; + + bc->bits >>= unwind_bits; + bc->bits <<= unwind_bits; + bc->bits_left -= unwind_bits; + bc->ptr -= unwind; +} + +/* Unget up to 32 bits. */ +static inline void bitstream_unget(BitstreamContext *bc, uint64_t value, + size_t amount) +{ + size_t cache_size = sizeof(bc->bits) * 8; + + if (bc->bits_left + amount > cache_size) + bitstream_unwind(bc); + + bc->bits = (bc->bits >> amount) | (value << (cache_size - amount)); + bc->bits_left += amount; +} + #endif /* AVCODEC_BITSTREAM_H */ |