1 /*
2 * Copyright (c) 2012 Andrew D'Addesio
3 * Copyright (c) 2013-2014 Mozilla Corporation
4 * Copyright (c) 2017 Rostislav Pehlivanov <atomnuker@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef AVCODEC_OPUS_RC_H
24 #define AVCODEC_OPUS_RC_H
25
26 #include <stdint.h>
27
29
31
32 #define opus_ilog(i) (av_log2(i) + !!(i))
33
40
47
48 /* Encoder */
50 uint8_t *
rng_cur;
/* Current range coded byte */
51 int ext;
/* Awaiting propagation */
52 int rem;
/* Carryout flag */
53
54 /* Encoding stats */
57
58 /**
59 * CELT: estimate bits of entropy that have thus far been consumed for the
60 * current CELT frame, to integer and fractional (1/8th bit) precision
61 */
63 {
65 }
66
68 {
69 uint32_t
i, total_bits, rcbuffer,
range;
70
74
75 for (
i = 0;
i < 3;
i++) {
79 rcbuffer = rcbuffer << 1 |
bit;
81 }
82
83 return total_bits - rcbuffer;
84 }
85
88
91
94
97
100
103
106
109
112
113 #define OPUS_RC_CHECKPOINT_UPDATE(rc) \
114 rc_rollback_bits = opus_rc_tell_frac(rc); \
115 rc_rollback_ctx = *rc
116
117 #define OPUS_RC_CHECKPOINT_SPAWN(rc) \
118 uint32_t rc_rollback_bits = opus_rc_tell_frac(rc); \
119 OpusRangeCoder rc_rollback_ctx = *rc \
120
121 #define OPUS_RC_CHECKPOINT_BITS(rc) \
122 (opus_rc_tell_frac(rc) - rc_rollback_bits)
123
124 #define OPUS_RC_CHECKPOINT_ROLLBACK(rc) \
125 memcpy(rc, &rc_rollback_ctx, sizeof(OpusRangeCoder)); \
126
127 #endif /* AVCODEC_OPUS_RC_H */