Coverage Report

Created: 2026-05-23 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/opus/rc.h
Line
Count
Source
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
28
#include "libavcodec/get_bits.h"
29
30
#include "opus.h"
31
32
6.90M
#define opus_ilog(i) (av_log2(i) + !!(i))
33
34
typedef struct RawBitsContext {
35
    const uint8_t *position;
36
    uint32_t bytes;
37
    uint32_t cachelen;
38
    uint32_t cacheval;
39
} RawBitsContext;
40
41
typedef struct OpusRangeCoder {
42
    GetBitContext gb;
43
    RawBitsContext rb;
44
    uint32_t range;
45
    uint32_t value;
46
    uint32_t total_bits;
47
48
    /* Encoder */
49
    uint8_t buf[OPUS_MAX_FRAME_SIZE + 12]; /* memcpy vs (memmove + overreading) */
50
    uint8_t *rng_cur;                      /* Current range coded byte */
51
    int ext;                               /* Awaiting propagation */
52
    int rem;                               /* Carryout flag */
53
54
    /* Encoding stats */
55
    int waste;
56
} OpusRangeCoder;
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
 */
62
static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
63
4.29M
{
64
4.29M
    return rc->total_bits - av_log2(rc->range) - 1;
65
4.29M
}
Unexecuted instantiation: enc.c:opus_rc_tell
Unexecuted instantiation: enc_psy.c:opus_rc_tell
Unexecuted instantiation: pvq.c:opus_rc_tell
Unexecuted instantiation: rc.c:opus_rc_tell
celt.c:opus_rc_tell
Line
Count
Source
63
89.9k
{
64
89.9k
    return rc->total_bits - av_log2(rc->range) - 1;
65
89.9k
}
dec.c:opus_rc_tell
Line
Count
Source
63
262k
{
64
262k
    return rc->total_bits - av_log2(rc->range) - 1;
65
262k
}
dec_celt.c:opus_rc_tell
Line
Count
Source
63
3.94M
{
64
3.94M
    return rc->total_bits - av_log2(rc->range) - 1;
65
3.94M
}
Unexecuted instantiation: silk.c:opus_rc_tell
66
67
static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)
68
5.69M
{
69
5.69M
    uint32_t i, total_bits, rcbuffer, range;
70
71
5.69M
    total_bits = rc->total_bits << 3;
72
5.69M
    rcbuffer   = av_log2(rc->range) + 1;
73
5.69M
    range      = rc->range >> (rcbuffer-16);
74
75
22.7M
    for (i = 0; i < 3; i++) {
76
17.0M
        int bit;
77
17.0M
        range = range * range >> 15;
78
17.0M
        bit = range >> 16;
79
17.0M
        rcbuffer = rcbuffer << 1 | bit;
80
17.0M
        range >>= bit;
81
17.0M
    }
82
83
5.69M
    return total_bits - rcbuffer;
84
5.69M
}
Unexecuted instantiation: enc.c:opus_rc_tell_frac
Unexecuted instantiation: enc_psy.c:opus_rc_tell_frac
pvq.c:opus_rc_tell_frac
Line
Count
Source
68
2.48M
{
69
2.48M
    uint32_t i, total_bits, rcbuffer, range;
70
71
2.48M
    total_bits = rc->total_bits << 3;
72
2.48M
    rcbuffer   = av_log2(rc->range) + 1;
73
2.48M
    range      = rc->range >> (rcbuffer-16);
74
75
9.94M
    for (i = 0; i < 3; i++) {
76
7.46M
        int bit;
77
7.46M
        range = range * range >> 15;
78
7.46M
        bit = range >> 16;
79
7.46M
        rcbuffer = rcbuffer << 1 | bit;
80
7.46M
        range >>= bit;
81
7.46M
    }
82
83
2.48M
    return total_bits - rcbuffer;
84
2.48M
}
Unexecuted instantiation: rc.c:opus_rc_tell_frac
celt.c:opus_rc_tell_frac
Line
Count
Source
68
3.21M
{
69
3.21M
    uint32_t i, total_bits, rcbuffer, range;
70
71
3.21M
    total_bits = rc->total_bits << 3;
72
3.21M
    rcbuffer   = av_log2(rc->range) + 1;
73
3.21M
    range      = rc->range >> (rcbuffer-16);
74
75
12.8M
    for (i = 0; i < 3; i++) {
76
9.63M
        int bit;
77
9.63M
        range = range * range >> 15;
78
9.63M
        bit = range >> 16;
79
9.63M
        rcbuffer = rcbuffer << 1 | bit;
80
9.63M
        range >>= bit;
81
9.63M
    }
82
83
3.21M
    return total_bits - rcbuffer;
84
3.21M
}
Unexecuted instantiation: dec.c:opus_rc_tell_frac
Unexecuted instantiation: dec_celt.c:opus_rc_tell_frac
Unexecuted instantiation: silk.c:opus_rc_tell_frac
85
86
uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf);
87
void     ff_opus_rc_enc_cdf(OpusRangeCoder *rc, int val, const uint16_t *cdf);
88
89
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits);
90
void     ff_opus_rc_enc_log(OpusRangeCoder *rc, int val, uint32_t bits);
91
92
uint32_t ff_opus_rc_dec_uint_step(OpusRangeCoder *rc, int k0);
93
void     ff_opus_rc_enc_uint_step(OpusRangeCoder *rc, uint32_t val, int k0);
94
95
uint32_t ff_opus_rc_dec_uint_tri(OpusRangeCoder *rc, int qn);
96
void     ff_opus_rc_enc_uint_tri(OpusRangeCoder *rc, uint32_t k, int qn);
97
98
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size);
99
void     ff_opus_rc_enc_uint(OpusRangeCoder *rc, uint32_t val, uint32_t size);
100
101
uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count);
102
void     ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count);
103
104
int      ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay);
105
void     ff_opus_rc_enc_laplace(OpusRangeCoder *rc, int *value, uint32_t symbol, int decay);
106
107
int      ff_opus_rc_dec_init(OpusRangeCoder *rc, const uint8_t *data, int size);
108
void     ff_opus_rc_dec_raw_init(OpusRangeCoder *rc, const uint8_t *rightend, uint32_t bytes);
109
110
void     ff_opus_rc_enc_end(OpusRangeCoder *rc, uint8_t *dst, int size);
111
void     ff_opus_rc_enc_init(OpusRangeCoder *rc);
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
0
    uint32_t rc_rollback_bits = opus_rc_tell_frac(rc); \
119
0
    OpusRangeCoder rc_rollback_ctx = *rc \
120
121
#define OPUS_RC_CHECKPOINT_BITS(rc) \
122
0
    (opus_rc_tell_frac(rc) - rc_rollback_bits)
123
124
#define OPUS_RC_CHECKPOINT_ROLLBACK(rc) \
125
0
    memcpy(rc, &rc_rollback_ctx, sizeof(OpusRangeCoder)); \
126
127
#endif /* AVCODEC_OPUS_RC_H */