[FFmpeg-devel] [PATCH 6/7] avcodec/put_bits: add put_leb()

James Almer jamrial at gmail.com
Tue Jan 30 19:32:17 EET 2024


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/put_bits.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 4561dc131a..04dedd3342 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -370,6 +370,22 @@ static inline void put_sbits63(PutBitContext *pb, int n, int64_t value)
     put_bits64(pb, n, (uint64_t)(value) & (~(UINT64_MAX << n)));
 }
 
+static inline void put_leb(PutBitContext *s, unsigned value)
+{
+    int len;
+    uint8_t byte;
+
+    len = (av_log2(value) + 7) / 7;
+
+    for (int i = 0; i < len; i++) {
+        byte = value >> (7 * i) & 0x7f;
+        if (i < len - 1)
+            byte |= 0x80;
+
+        put_bits_no_assert(s, 8, byte);
+    }
+}
+
 /**
  * Return the pointer to the byte where the bitstream writer will put
  * the next bit.
-- 
2.43.0



More information about the ffmpeg-devel mailing list