diff mbox

[FFmpeg-devel,V5,2/4] lavc/put_bits: Add put_bits64() to support up to 64 bits.

Message ID 39e9574b-41c2-dc1b-5bf2-f2fe269b0f0a@gmail.com
State Accepted
Commit 2b7d9a1f3fa759c82aaa3569612b40d5ccb1e319
Headers show

Commit Message

Jun Zhao June 14, 2017, 3:01 a.m. UTC
From 703be162119f78e1815d1f3b23afb24978ff36d7 Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao@intel.com>
Date: Wed, 14 Jun 2017 10:22:10 +0800
Subject: [PATCH V5 2/4] lavc/put_bits: Add put_bits64() to support up to 64
 bits.

put_bits64() can write up to 64 bits into a bitstream.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Jun Zhao <jun.zhao@intel.com>
---
 libavcodec/put_bits.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Michael Niedermayer June 24, 2017, 7:59 p.m. UTC | #1
On Wed, Jun 14, 2017 at 11:01:42AM +0800, Jun Zhao wrote:
>  put_bits.h |   35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 5481728acedf2dae1e92f972d7043033384a0ca2  0002-lavc-put_bits-Add-put_bits64-to-support-up-to-64-bit.patch
> From 703be162119f78e1815d1f3b23afb24978ff36d7 Mon Sep 17 00:00:00 2001
> From: Jun Zhao <jun.zhao@intel.com>
> Date: Wed, 14 Jun 2017 10:22:10 +0800
> Subject: [PATCH V5 2/4] lavc/put_bits: Add put_bits64() to support up to 64
>  bits.
> 
> put_bits64() can write up to 64 bits into a bitstream.
> 
> Reviewed-by: Mark Thompson <sw@jkqxz.net>
> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
> Signed-off-by: Jun Zhao <jun.zhao@intel.com>
> ---
>  libavcodec/put_bits.h | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

applied this and the rest of the patchset.
If someone has an idea of better naming for the functions or other
then we should change this.
But the bug should not be left open

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 9bd45cd8ba..b85e88f28c 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -243,6 +243,41 @@  static void av_unused put_bits32(PutBitContext *s, uint32_t value)
 }
 
 /**
+ * Write up to 64 bits into a bitstream.
+ */
+static inline void put_bits64(PutBitContext *s, int n, uint64_t value)
+{
+    av_assert2((n == 64) || (n < 64 && value < (UINT64_C(1) << n)));
+
+    if (n < 32)
+        put_bits(s, n, value);
+    else if (n == 32)
+        put_bits32(s, value);
+    else if (n < 64) {
+        uint32_t lo = value & 0xffffffff;
+        uint32_t hi = value >> 32;
+#ifdef BITSTREAM_WRITER_LE
+        put_bits32(s, lo);
+        put_bits(s, n - 32, hi);
+#else
+        put_bits(s, n - 32, hi);
+        put_bits32(s, lo);
+#endif
+    } else {
+        uint32_t lo = value & 0xffffffff;
+        uint32_t hi = value >> 32;
+#ifdef BITSTREAM_WRITER_LE
+        put_bits32(s, lo);
+        put_bits32(s, hi);
+#else
+        put_bits32(s, hi);
+        put_bits32(s, lo);
+#endif
+
+    }
+}
+
+/**
  * Return the pointer to the byte where the bitstream writer will put
  * the next bit.
  */