[FFmpeg-cvslog] opus_rc: rename total_bits_used to total_bits and #define some constants

Rostislav Pehlivanov git at videolan.org
Sat Feb 4 14:07:59 EET 2017


ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Wed Feb  1 03:13:04 2017 +0000| [084f3addda7531a22d656b769120c6453e880226] | committer: Rostislav Pehlivanov

opus_rc: rename total_bits_used to total_bits and #define some constants

Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>

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

 libavcodec/opus_celt.c |  2 +-
 libavcodec/opus_rc.c   | 19 +++++++++++++------
 libavcodec/opus_rc.h   |  6 +++---
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c
index c115ee7..96fedb7 100644
--- a/libavcodec/opus_celt.c
+++ b/libavcodec/opus_celt.c
@@ -1641,7 +1641,7 @@ int ff_celt_decode_frame(CeltContext *s, OpusRangeCoder *rc,
 
     if (silence) {
         consumed = s->framebits;
-        rc->total_read_bits += s->framebits - opus_rc_tell(rc);
+        rc->total_bits += s->framebits - opus_rc_tell(rc);
     }
 
     /* obtain post-filter options */
diff --git a/libavcodec/opus_rc.c b/libavcodec/opus_rc.c
index 1f9af04..b0e72f6 100644
--- a/libavcodec/opus_rc.c
+++ b/libavcodec/opus_rc.c
@@ -22,12 +22,19 @@
 
 #include "opus_rc.h"
 
+#define OPUS_RC_BITS 32
+#define OPUS_RC_SYM  8
+#define OPUS_RC_CEIL ((1 << OPUS_RC_SYM) - 1)
+#define OPUS_RC_TOP (1u << 31)
+#define OPUS_RC_BOT (OPUS_RC_TOP >> OPUS_RC_SYM)
+#define OPUS_RC_SHIFT (OPUS_RC_BITS - OPUS_RC_SYM - 1)
+
 static av_always_inline void opus_rc_dec_normalize(OpusRangeCoder *rc)
 {
-    while (rc->range <= 1<<23) {
-        rc->value = ((rc->value << 8) | (get_bits(&rc->gb, 8) ^ 0xFF)) & ((1u << 31) - 1);
-        rc->range          <<= 8;
-        rc->total_read_bits += 8;
+    while (rc->range <= OPUS_RC_BOT) {
+        rc->value = ((rc->value << OPUS_RC_SYM) | (get_bits(&rc->gb, OPUS_RC_SYM) ^ OPUS_RC_CEIL)) & (OPUS_RC_TOP - 1);
+        rc->range     <<= OPUS_RC_SYM;
+        rc->total_bits += OPUS_RC_SYM;
     }
 }
 
@@ -93,7 +100,7 @@ uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count)
     value = av_mod_uintp2(rc->rb.cacheval, count);
     rc->rb.cacheval    >>= count;
     rc->rb.cachelen     -= count;
-    rc->total_read_bits += count;
+    rc->total_bits      += count;
 
     return value;
 }
@@ -206,7 +213,7 @@ int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size)
 
     rc->range = 128;
     rc->value = 127 - get_bits(&rc->gb, 7);
-    rc->total_read_bits = 9;
+    rc->total_bits = 9;
     opus_rc_dec_normalize(rc);
 
     return 0;
diff --git a/libavcodec/opus_rc.h b/libavcodec/opus_rc.h
index 68ebc05..9f5253b 100644
--- a/libavcodec/opus_rc.h
+++ b/libavcodec/opus_rc.h
@@ -40,7 +40,7 @@ typedef struct OpusRangeCoder {
     RawBitsContext rb;
     uint32_t range;
     uint32_t value;
-    uint32_t total_read_bits;
+    uint32_t total_bits;
 } OpusRangeCoder;
 
 /**
@@ -49,14 +49,14 @@ typedef struct OpusRangeCoder {
  */
 static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
 {
-    return rc->total_read_bits - av_log2(rc->range) - 1;
+    return rc->total_bits - av_log2(rc->range) - 1;
 }
 
 static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)
 {
     uint32_t i, total_bits, rcbuffer, range;
 
-    total_bits = rc->total_read_bits << 3;
+    total_bits = rc->total_bits << 3;
     rcbuffer   = av_log2(rc->range) + 1;
     range      = rc->range >> (rcbuffer-16);
 



More information about the ffmpeg-cvslog mailing list