diff mbox series

[FFmpeg-devel,3/7] get_xbits: request fewer bits

Message ID 20200414102503.7858-4-christophe.gisquet@gmail.com
State New
Headers show
Series Port cache bitstream reader to 32bits, and improve
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate fail Make fate failed

Commit Message

Christophe Gisquet April 14, 2020, 10:24 a.m. UTC
Also allows it to not break 32bits readers.
---
 libavcodec/get_bits.h | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index cb4df98e54..59bfbdd88b 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -367,8 +367,24 @@  static inline void skip_remaining(GetBitContext *s, unsigned n)
 static inline int get_xbits(GetBitContext *s, int n)
 {
 #if CACHED_BITSTREAM_READER
-    int32_t cache = show_bits(s, 32);
-    int sign = ~cache >> 31;
+    int32_t cache;
+    int sign;
+
+    if (n > s->bits_left)
+#ifdef BITSTREAM_READER_LE
+        refill_half(s, 1);
+#else
+        refill_half(s, 0);
+#endif
+
+#if BITSTREAM_BITS == 32
+    cache = s->cache;
+#elif defined(BITSTREAM_READER_LE)
+    cache = s->cache & 0xFFFFFFFF;
+#else
+    cache = s->cache >> 32;
+#endif
+    sign = ~cache >> 31;
     skip_remaining(s, n);
 
     return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign;