The new code is guaranteed to read at least 32bits, which is likely ok with the usual case that get_bits without cache can read up to 25. --- libavcodec/get_bits.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index 4f75f9dd84..da054ebfcb 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -608,21 +608,44 @@ static inline void skip_bits1(GetBitContext *s) */ static inline unsigned int get_bits_long(GetBitContext *s, int n) { + unsigned ret = 0; av_assert2(n>=0 && n<=32); if (!n) { return 0; #if CACHED_BITSTREAM_READER } - return get_bits(s, n); + +# ifdef BITSTREAM_READER_LE + unsigned left = 0; +# endif + if (n > s->bits_left) { + n -= s->bits_left; +# ifdef BITSTREAM_READER_LE + left = s->bits_left; + ret = get_val(s, s->bits_left, 1); + refill_all(s, 1); +# else + ret = get_val(s, s->bits_left, 0); + refill_all(s, 0); +# endif + } + +#ifdef BITSTREAM_READER_LE + ret = get_val(s, n, 1) << left | ret; +#else + ret = get_val(s, n, 0) | ret << n; +#endif + + return ret; #else } else if (n <= MIN_CACHE_BITS) { return get_bits(s, n); } else { #ifdef BITSTREAM_READER_LE - unsigned ret = get_bits(s, 16); + ret = get_bits(s, 16); return ret | (get_bits(s, n - 16) << 16); #else - unsigned ret = get_bits(s, 16) << (n - 16); + ret = get_bits(s, 16) << (n - 16); return ret | get_bits(s, n - 16); #endif } -- 2.26.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".