[FFmpeg-cvslog] bitstream: add get_bits64() to support reading more than 32 bits at once

Michael Niedermayer git at videolan.org
Sat Dec 8 15:07:09 CET 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Sep 30 02:39:55 2012 +0200| [41540b36a19d326e778268e910aff4217b20eb97] | committer: Justin Ruggles

bitstream: add get_bits64() to support reading more than 32 bits at once

Also remove a duplicate function in the MPEG-TS demuxer.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
Signed-off-by: Justin Ruggles <justin.ruggles at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=41540b36a19d326e778268e910aff4217b20eb97
---

 libavcodec/get_bits.h |   18 ++++++++++++++++++
 libavformat/mpegts.c  |   13 -------------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index f91441c..c56a2c2 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -313,6 +313,24 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n)
     }
 }
 
+/*
+ * Read 0-64 bits.
+ */
+static inline uint64_t get_bits64(GetBitContext *s, int n)
+{
+    if (n <= 32) {
+        return get_bits_long(s, n);
+    } else {
+#ifdef BITSTREAM_READER_LE
+        uint64_t ret = get_bits_long(s, 32);
+        return ret | (uint64_t)get_bits_long(s, n - 32) << 32;
+#else
+        uint64_t ret = (uint64_t)get_bits_long(s, n - 32) << 32;
+        return ret | get_bits_long(s, 32);
+#endif
+    }
+}
+
 /**
  * Read 0-32 bits as a signed integer.
  */
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 4aabcd7..7c4d447 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -665,19 +665,6 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
     pes->flags = 0;
 }
 
-static uint64_t get_bits64(GetBitContext *gb, int bits)
-{
-    uint64_t ret = 0;
-    while (bits > 17) {
-        ret <<= 17;
-        ret |= get_bits(gb, 17);
-        bits -= 17;
-    }
-    ret <<= bits;
-    ret |= get_bits(gb, bits);
-    return ret;
-}
-
 static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
 {
     GetBitContext gb;



More information about the ffmpeg-cvslog mailing list