summaryrefslogtreecommitdiff
path: root/libavcodec/opus_rc.h
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-11-07 22:33:11 +0000
committerRostislav Pehlivanov <atomnuker@gmail.com>2016-11-08 14:18:59 +0000
commit317be31eaf4f07b3bbeb703e8ee73d04b08a587c (patch)
tree9a07a44dde6a86a34bb8d6f7675b8eeaabd15f56 /libavcodec/opus_rc.h
parent0660a09dd1d12e17216d44ec42584690d812b7f3 (diff)
opus: move the entropy decoding functions to opus_rc.c
The intention is to have both encoding and decoding functions in opus_rc.c. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'libavcodec/opus_rc.h')
-rw-r--r--libavcodec/opus_rc.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/libavcodec/opus_rc.h b/libavcodec/opus_rc.h
new file mode 100644
index 0000000000..68ebc05af6
--- /dev/null
+++ b/libavcodec/opus_rc.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2012 Andrew D'Addesio
+ * Copyright (c) 2013-2014 Mozilla Corporation
+ * Copyright (c) 2016 Rostislav Pehlivanov <atomnuker@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_OPUS_RC_H
+#define AVCODEC_OPUS_RC_H
+
+#include <stdint.h>
+#include "get_bits.h"
+
+#define opus_ilog(i) (av_log2(i) + !!(i))
+
+typedef struct RawBitsContext {
+ const uint8_t *position;
+ uint32_t bytes;
+ uint32_t cachelen;
+ uint32_t cacheval;
+} RawBitsContext;
+
+typedef struct OpusRangeCoder {
+ GetBitContext gb;
+ RawBitsContext rb;
+ uint32_t range;
+ uint32_t value;
+ uint32_t total_read_bits;
+} OpusRangeCoder;
+
+/**
+ * CELT: estimate bits of entropy that have thus far been consumed for the
+ * current CELT frame, to integer and fractional (1/8th bit) precision
+ */
+static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
+{
+ return rc->total_read_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;
+ rcbuffer = av_log2(rc->range) + 1;
+ range = rc->range >> (rcbuffer-16);
+
+ for (i = 0; i < 3; i++) {
+ int bit;
+ range = range * range >> 15;
+ bit = range >> 16;
+ rcbuffer = rcbuffer << 1 | bit;
+ range >>= bit;
+ }
+
+ return total_bits - rcbuffer;
+}
+
+uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf);
+uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits);
+uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size);
+uint32_t ff_opus_rc_dec_uint_step(OpusRangeCoder *rc, int k0);
+uint32_t ff_opus_rc_dec_uint_tri(OpusRangeCoder *rc, int qn);
+uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count);
+int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay);
+
+int ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size);
+void ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes);
+
+#endif /* AVCODEC_OPUS_RC_H */