Coverage Report

Created: 2026-04-01 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/vpx_rac.h
Line
Count
Source
1
/*
2
 * Copyright (C) 2006  Aurelien Jacobs <aurel@gnuage.org>
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21
/**
22
 * @file
23
 * Common VP5-VP9 range decoder stuff
24
 */
25
26
#ifndef AVCODEC_VPX_RAC_H
27
#define AVCODEC_VPX_RAC_H
28
29
#include <stdint.h>
30
31
#include "config.h"
32
#include "libavutil/attributes.h"
33
#include "bytestream.h"
34
35
typedef struct VPXRangeCoder {
36
    int high;
37
    int bits; /* stored negated (i.e. negative "bits" is a positive number of
38
                 bits left) in order to eliminate a negate in cache refilling */
39
    const uint8_t *buffer;
40
    const uint8_t *end;
41
    unsigned int code_word;
42
    int end_reached;
43
} VPXRangeCoder;
44
45
extern const uint8_t ff_vpx_norm_shift[256];
46
int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size);
47
48
/**
49
 * returns 1 if the end of the stream has been reached, 0 otherwise.
50
 */
51
static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c)
52
20.4M
{
53
20.4M
    if (c->end <= c->buffer && c->bits >= 0)
54
3.71M
        c->end_reached ++;
55
20.4M
    return c->end_reached > 10;
56
20.4M
}
vp8.c:vpx_rac_is_end
Line
Count
Source
52
8.54M
{
53
8.54M
    if (c->end <= c->buffer && c->bits >= 0)
54
1.26M
        c->end_reached ++;
55
8.54M
    return c->end_reached > 10;
56
8.54M
}
Unexecuted instantiation: vpx_rac.c:vpx_rac_is_end
vp6.c:vpx_rac_is_end
Line
Count
Source
52
5.99M
{
53
5.99M
    if (c->end <= c->buffer && c->bits >= 0)
54
1.09M
        c->end_reached ++;
55
5.99M
    return c->end_reached > 10;
56
5.99M
}
Unexecuted instantiation: vp56.c:vpx_rac_is_end
Unexecuted instantiation: vp56data.c:vpx_rac_is_end
vp5.c:vpx_rac_is_end
Line
Count
Source
52
764k
{
53
764k
    if (c->end <= c->buffer && c->bits >= 0)
54
227k
        c->end_reached ++;
55
764k
    return c->end_reached > 10;
56
764k
}
Unexecuted instantiation: webp.c:vpx_rac_is_end
vp9.c:vpx_rac_is_end
Line
Count
Source
52
5.10M
{
53
5.10M
    if (c->end <= c->buffer && c->bits >= 0)
54
1.12M
        c->end_reached ++;
55
5.10M
    return c->end_reached > 10;
56
5.10M
}
Unexecuted instantiation: vp9block.c:vpx_rac_is_end
Unexecuted instantiation: vp9data.c:vpx_rac_is_end
Unexecuted instantiation: vp9lpf.c:vpx_rac_is_end
Unexecuted instantiation: vp9mvs.c:vpx_rac_is_end
Unexecuted instantiation: vp9prob.c:vpx_rac_is_end
Unexecuted instantiation: vp9recon.c:vpx_rac_is_end
57
58
static av_always_inline unsigned int vpx_rac_renorm(VPXRangeCoder *c)
59
4.81G
{
60
4.81G
    int shift = ff_vpx_norm_shift[c->high];
61
4.81G
    int bits = c->bits;
62
4.81G
    unsigned int code_word = c->code_word;
63
64
4.81G
    c->high   <<= shift;
65
4.81G
    code_word <<= shift;
66
4.81G
    bits       += shift;
67
4.81G
    if(bits >= 0 && c->buffer < c->end) {
68
53.7M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
53.7M
        bits -= 16;
70
53.7M
    }
71
4.81G
    c->bits = bits;
72
4.81G
    return code_word;
73
4.81G
}
vp8.c:vpx_rac_renorm
Line
Count
Source
59
879M
{
60
879M
    int shift = ff_vpx_norm_shift[c->high];
61
879M
    int bits = c->bits;
62
879M
    unsigned int code_word = c->code_word;
63
64
879M
    c->high   <<= shift;
65
879M
    code_word <<= shift;
66
879M
    bits       += shift;
67
879M
    if(bits >= 0 && c->buffer < c->end) {
68
3.63M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
3.63M
        bits -= 16;
70
3.63M
    }
71
879M
    c->bits = bits;
72
879M
    return code_word;
73
879M
}
Unexecuted instantiation: vpx_rac.c:vpx_rac_renorm
vp6.c:vpx_rac_renorm
Line
Count
Source
59
1.68G
{
60
1.68G
    int shift = ff_vpx_norm_shift[c->high];
61
1.68G
    int bits = c->bits;
62
1.68G
    unsigned int code_word = c->code_word;
63
64
1.68G
    c->high   <<= shift;
65
1.68G
    code_word <<= shift;
66
1.68G
    bits       += shift;
67
1.68G
    if(bits >= 0 && c->buffer < c->end) {
68
3.14M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
3.14M
        bits -= 16;
70
3.14M
    }
71
1.68G
    c->bits = bits;
72
1.68G
    return code_word;
73
1.68G
}
vp56.c:vpx_rac_renorm
Line
Count
Source
59
74.0M
{
60
74.0M
    int shift = ff_vpx_norm_shift[c->high];
61
74.0M
    int bits = c->bits;
62
74.0M
    unsigned int code_word = c->code_word;
63
64
74.0M
    c->high   <<= shift;
65
74.0M
    code_word <<= shift;
66
74.0M
    bits       += shift;
67
74.0M
    if(bits >= 0 && c->buffer < c->end) {
68
232k
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
232k
        bits -= 16;
70
232k
    }
71
74.0M
    c->bits = bits;
72
74.0M
    return code_word;
73
74.0M
}
Unexecuted instantiation: vp56data.c:vpx_rac_renorm
vp5.c:vpx_rac_renorm
Line
Count
Source
59
832M
{
60
832M
    int shift = ff_vpx_norm_shift[c->high];
61
832M
    int bits = c->bits;
62
832M
    unsigned int code_word = c->code_word;
63
64
832M
    c->high   <<= shift;
65
832M
    code_word <<= shift;
66
832M
    bits       += shift;
67
832M
    if(bits >= 0 && c->buffer < c->end) {
68
1.32M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
1.32M
        bits -= 16;
70
1.32M
    }
71
832M
    c->bits = bits;
72
832M
    return code_word;
73
832M
}
Unexecuted instantiation: webp.c:vpx_rac_renorm
vp9.c:vpx_rac_renorm
Line
Count
Source
59
188M
{
60
188M
    int shift = ff_vpx_norm_shift[c->high];
61
188M
    int bits = c->bits;
62
188M
    unsigned int code_word = c->code_word;
63
64
188M
    c->high   <<= shift;
65
188M
    code_word <<= shift;
66
188M
    bits       += shift;
67
188M
    if(bits >= 0 && c->buffer < c->end) {
68
3.86M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
3.86M
        bits -= 16;
70
3.86M
    }
71
188M
    c->bits = bits;
72
188M
    return code_word;
73
188M
}
vp9block.c:vpx_rac_renorm
Line
Count
Source
59
981M
{
60
981M
    int shift = ff_vpx_norm_shift[c->high];
61
981M
    int bits = c->bits;
62
981M
    unsigned int code_word = c->code_word;
63
64
981M
    c->high   <<= shift;
65
981M
    code_word <<= shift;
66
981M
    bits       += shift;
67
981M
    if(bits >= 0 && c->buffer < c->end) {
68
35.9M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
35.9M
        bits -= 16;
70
35.9M
    }
71
981M
    c->bits = bits;
72
981M
    return code_word;
73
981M
}
Unexecuted instantiation: vp9data.c:vpx_rac_renorm
Unexecuted instantiation: vp9lpf.c:vpx_rac_renorm
vp9mvs.c:vpx_rac_renorm
Line
Count
Source
59
172M
{
60
172M
    int shift = ff_vpx_norm_shift[c->high];
61
172M
    int bits = c->bits;
62
172M
    unsigned int code_word = c->code_word;
63
64
172M
    c->high   <<= shift;
65
172M
    code_word <<= shift;
66
172M
    bits       += shift;
67
172M
    if(bits >= 0 && c->buffer < c->end) {
68
5.67M
        code_word |= bytestream_get_be16(&c->buffer) << bits;
69
5.67M
        bits -= 16;
70
5.67M
    }
71
172M
    c->bits = bits;
72
172M
    return code_word;
73
172M
}
Unexecuted instantiation: vp9prob.c:vpx_rac_renorm
Unexecuted instantiation: vp9recon.c:vpx_rac_renorm
74
75
#if   ARCH_ARM
76
#include "arm/vpx_arith.h"
77
#elif ARCH_X86
78
#include "x86/vpx_arith.h"
79
#endif
80
81
#ifndef vpx_rac_get_prob
82
2.31G
#define vpx_rac_get_prob vpx_rac_get_prob
83
static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob)
84
2.31G
{
85
2.31G
    unsigned int code_word = vpx_rac_renorm(c);
86
2.31G
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
2.31G
    unsigned int low_shift = low << 16;
88
2.31G
    int bit = code_word >= low_shift;
89
90
2.31G
    c->high = bit ? c->high - low : low;
91
2.31G
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
2.31G
    return bit;
94
2.31G
}
vp8.c:vpx_rac_get_prob
Line
Count
Source
84
547M
{
85
547M
    unsigned int code_word = vpx_rac_renorm(c);
86
547M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
547M
    unsigned int low_shift = low << 16;
88
547M
    int bit = code_word >= low_shift;
89
90
547M
    c->high = bit ? c->high - low : low;
91
547M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
547M
    return bit;
94
547M
}
Unexecuted instantiation: vpx_rac.c:vpx_rac_get_prob
vp6.c:vpx_rac_get_prob
Line
Count
Source
84
803M
{
85
803M
    unsigned int code_word = vpx_rac_renorm(c);
86
803M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
803M
    unsigned int low_shift = low << 16;
88
803M
    int bit = code_word >= low_shift;
89
90
803M
    c->high = bit ? c->high - low : low;
91
803M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
803M
    return bit;
94
803M
}
vp56.c:vpx_rac_get_prob
Line
Count
Source
84
370k
{
85
370k
    unsigned int code_word = vpx_rac_renorm(c);
86
370k
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
370k
    unsigned int low_shift = low << 16;
88
370k
    int bit = code_word >= low_shift;
89
90
370k
    c->high = bit ? c->high - low : low;
91
370k
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
370k
    return bit;
94
370k
}
Unexecuted instantiation: vp56data.c:vpx_rac_get_prob
vp5.c:vpx_rac_get_prob
Line
Count
Source
84
348M
{
85
348M
    unsigned int code_word = vpx_rac_renorm(c);
86
348M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
348M
    unsigned int low_shift = low << 16;
88
348M
    int bit = code_word >= low_shift;
89
90
348M
    c->high = bit ? c->high - low : low;
91
348M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
348M
    return bit;
94
348M
}
Unexecuted instantiation: webp.c:vpx_rac_get_prob
vp9.c:vpx_rac_get_prob
Line
Count
Source
84
73.0M
{
85
73.0M
    unsigned int code_word = vpx_rac_renorm(c);
86
73.0M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
73.0M
    unsigned int low_shift = low << 16;
88
73.0M
    int bit = code_word >= low_shift;
89
90
73.0M
    c->high = bit ? c->high - low : low;
91
73.0M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
73.0M
    return bit;
94
73.0M
}
vp9block.c:vpx_rac_get_prob
Line
Count
Source
84
367M
{
85
367M
    unsigned int code_word = vpx_rac_renorm(c);
86
367M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
367M
    unsigned int low_shift = low << 16;
88
367M
    int bit = code_word >= low_shift;
89
90
367M
    c->high = bit ? c->high - low : low;
91
367M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
367M
    return bit;
94
367M
}
Unexecuted instantiation: vp9data.c:vpx_rac_get_prob
Unexecuted instantiation: vp9lpf.c:vpx_rac_get_prob
vp9mvs.c:vpx_rac_get_prob
Line
Count
Source
84
172M
{
85
172M
    unsigned int code_word = vpx_rac_renorm(c);
86
172M
    unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
87
172M
    unsigned int low_shift = low << 16;
88
172M
    int bit = code_word >= low_shift;
89
90
172M
    c->high = bit ? c->high - low : low;
91
172M
    c->code_word = bit ? code_word - low_shift : code_word;
92
93
172M
    return bit;
94
172M
}
Unexecuted instantiation: vp9prob.c:vpx_rac_get_prob
Unexecuted instantiation: vp9recon.c:vpx_rac_get_prob
95
#endif
96
97
#ifndef vpx_rac_get_prob_branchy
98
// branchy variant, to be used where there's a branch based on the bit decoded
99
static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob)
100
2.03G
{
101
2.03G
    unsigned long code_word = vpx_rac_renorm(c);
102
2.03G
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
2.03G
    unsigned low_shift = low << 16;
104
105
2.03G
    if (code_word >= low_shift) {
106
1.07G
        c->high     -= low;
107
1.07G
        c->code_word = code_word - low_shift;
108
1.07G
        return 1;
109
1.07G
    }
110
111
964M
    c->high = low;
112
964M
    c->code_word = code_word;
113
964M
    return 0;
114
2.03G
}
vp8.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
331M
{
101
331M
    unsigned long code_word = vpx_rac_renorm(c);
102
331M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
331M
    unsigned low_shift = low << 16;
104
105
331M
    if (code_word >= low_shift) {
106
140M
        c->high     -= low;
107
140M
        c->code_word = code_word - low_shift;
108
140M
        return 1;
109
140M
    }
110
111
191M
    c->high = low;
112
191M
    c->code_word = code_word;
113
191M
    return 0;
114
331M
}
Unexecuted instantiation: vpx_rac.c:vpx_rac_get_prob_branchy
vp6.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
696M
{
101
696M
    unsigned long code_word = vpx_rac_renorm(c);
102
696M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
696M
    unsigned low_shift = low << 16;
104
105
696M
    if (code_word >= low_shift) {
106
458M
        c->high     -= low;
107
458M
        c->code_word = code_word - low_shift;
108
458M
        return 1;
109
458M
    }
110
111
238M
    c->high = low;
112
238M
    c->code_word = code_word;
113
238M
    return 0;
114
696M
}
vp56.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
28.6M
{
101
28.6M
    unsigned long code_word = vpx_rac_renorm(c);
102
28.6M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
28.6M
    unsigned low_shift = low << 16;
104
105
28.6M
    if (code_word >= low_shift) {
106
19.0M
        c->high     -= low;
107
19.0M
        c->code_word = code_word - low_shift;
108
19.0M
        return 1;
109
19.0M
    }
110
111
9.55M
    c->high = low;
112
9.55M
    c->code_word = code_word;
113
9.55M
    return 0;
114
28.6M
}
Unexecuted instantiation: vp56data.c:vpx_rac_get_prob_branchy
vp5.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
248M
{
101
248M
    unsigned long code_word = vpx_rac_renorm(c);
102
248M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
248M
    unsigned low_shift = low << 16;
104
105
248M
    if (code_word >= low_shift) {
106
224M
        c->high     -= low;
107
224M
        c->code_word = code_word - low_shift;
108
224M
        return 1;
109
224M
    }
110
111
23.6M
    c->high = low;
112
23.6M
    c->code_word = code_word;
113
23.6M
    return 0;
114
248M
}
Unexecuted instantiation: webp.c:vpx_rac_get_prob_branchy
vp9.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
115M
{
101
115M
    unsigned long code_word = vpx_rac_renorm(c);
102
115M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
115M
    unsigned low_shift = low << 16;
104
105
115M
    if (code_word >= low_shift) {
106
8.89M
        c->high     -= low;
107
8.89M
        c->code_word = code_word - low_shift;
108
8.89M
        return 1;
109
8.89M
    }
110
111
106M
    c->high = low;
112
106M
    c->code_word = code_word;
113
106M
    return 0;
114
115M
}
vp9block.c:vpx_rac_get_prob_branchy
Line
Count
Source
100
613M
{
101
613M
    unsigned long code_word = vpx_rac_renorm(c);
102
613M
    unsigned low = 1 + (((c->high - 1) * prob) >> 8);
103
613M
    unsigned low_shift = low << 16;
104
105
613M
    if (code_word >= low_shift) {
106
219M
        c->high     -= low;
107
219M
        c->code_word = code_word - low_shift;
108
219M
        return 1;
109
219M
    }
110
111
394M
    c->high = low;
112
394M
    c->code_word = code_word;
113
394M
    return 0;
114
613M
}
Unexecuted instantiation: vp9data.c:vpx_rac_get_prob_branchy
Unexecuted instantiation: vp9lpf.c:vpx_rac_get_prob_branchy
Unexecuted instantiation: vp9mvs.c:vpx_rac_get_prob_branchy
Unexecuted instantiation: vp9prob.c:vpx_rac_get_prob_branchy
Unexecuted instantiation: vp9recon.c:vpx_rac_get_prob_branchy
115
#endif
116
117
static av_always_inline int vpx_rac_get(VPXRangeCoder *c)
118
465M
{
119
465M
    unsigned int code_word = vpx_rac_renorm(c);
120
    /* equiprobable */
121
465M
    int low = (c->high + 1) >> 1;
122
465M
    unsigned int low_shift = low << 16;
123
465M
    int bit = code_word >= low_shift;
124
465M
    if (bit) {
125
453M
        c->high   -= low;
126
453M
        code_word -= low_shift;
127
453M
    } else {
128
12.3M
        c->high = low;
129
12.3M
    }
130
131
465M
    c->code_word = code_word;
132
465M
    return bit;
133
465M
}
Unexecuted instantiation: vp8.c:vpx_rac_get
Unexecuted instantiation: vpx_rac.c:vpx_rac_get
vp6.c:vpx_rac_get
Line
Count
Source
118
184M
{
119
184M
    unsigned int code_word = vpx_rac_renorm(c);
120
    /* equiprobable */
121
184M
    int low = (c->high + 1) >> 1;
122
184M
    unsigned int low_shift = low << 16;
123
184M
    int bit = code_word >= low_shift;
124
184M
    if (bit) {
125
175M
        c->high   -= low;
126
175M
        code_word -= low_shift;
127
175M
    } else {
128
8.69M
        c->high = low;
129
8.69M
    }
130
131
184M
    c->code_word = code_word;
132
184M
    return bit;
133
184M
}
vp56.c:vpx_rac_get
Line
Count
Source
118
45.0M
{
119
45.0M
    unsigned int code_word = vpx_rac_renorm(c);
120
    /* equiprobable */
121
45.0M
    int low = (c->high + 1) >> 1;
122
45.0M
    unsigned int low_shift = low << 16;
123
45.0M
    int bit = code_word >= low_shift;
124
45.0M
    if (bit) {
125
44.2M
        c->high   -= low;
126
44.2M
        code_word -= low_shift;
127
44.2M
    } else {
128
873k
        c->high = low;
129
873k
    }
130
131
45.0M
    c->code_word = code_word;
132
45.0M
    return bit;
133
45.0M
}
Unexecuted instantiation: vp56data.c:vpx_rac_get
vp5.c:vpx_rac_get
Line
Count
Source
118
236M
{
119
236M
    unsigned int code_word = vpx_rac_renorm(c);
120
    /* equiprobable */
121
236M
    int low = (c->high + 1) >> 1;
122
236M
    unsigned int low_shift = low << 16;
123
236M
    int bit = code_word >= low_shift;
124
236M
    if (bit) {
125
233M
        c->high   -= low;
126
233M
        code_word -= low_shift;
127
233M
    } else {
128
2.78M
        c->high = low;
129
2.78M
    }
130
131
236M
    c->code_word = code_word;
132
236M
    return bit;
133
236M
}
Unexecuted instantiation: webp.c:vpx_rac_get
Unexecuted instantiation: vp9.c:vpx_rac_get
Unexecuted instantiation: vp9block.c:vpx_rac_get
Unexecuted instantiation: vp9data.c:vpx_rac_get
Unexecuted instantiation: vp9lpf.c:vpx_rac_get
Unexecuted instantiation: vp9mvs.c:vpx_rac_get
Unexecuted instantiation: vp9prob.c:vpx_rac_get
Unexecuted instantiation: vp9recon.c:vpx_rac_get
134
135
#endif /* AVCODEC_VPX_RAC_H */