Coverage Report

Created: 2025-08-28 07:12

/src/ffmpeg/libavcodec/cbs_h265_syntax_template.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * This file is part of FFmpeg.
3
 *
4
 * FFmpeg is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * FFmpeg is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with FFmpeg; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 */
18
19
static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
20
205k
{
21
205k
    int err;
22
23
205k
    fixed(1, rbsp_stop_one_bit, 1);
24
588k
    while (byte_alignment(rw) != 0)
25
410k
        fixed(1, rbsp_alignment_zero_bit, 0);
26
27
178k
    return 0;
28
184k
}
cbs_h2645.c:cbs_h265_read_rbsp_trailing_bits
Line
Count
Source
20
158k
{
21
158k
    int err;
22
23
158k
    fixed(1, rbsp_stop_one_bit, 1);
24
439k
    while (byte_alignment(rw) != 0)
25
308k
        fixed(1, rbsp_alignment_zero_bit, 0);
26
27
131k
    return 0;
28
136k
}
cbs_h2645.c:cbs_h265_write_rbsp_trailing_bits
Line
Count
Source
20
47.6k
{
21
47.6k
    int err;
22
23
47.6k
    fixed(1, rbsp_stop_one_bit, 1);
24
149k
    while (byte_alignment(rw) != 0)
25
101k
        fixed(1, rbsp_alignment_zero_bit, 0);
26
27
47.6k
    return 0;
28
47.6k
}
29
30
static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
31
                                 H265RawNALUnitHeader *current,
32
                                 int expected_nal_unit_type)
33
1.04M
{
34
1.04M
    int err;
35
36
1.04M
    fixed(1, forbidden_zero_bit, 0);
37
38
1.04M
    if (expected_nal_unit_type >= 0)
39
1.04M
        u(6, nal_unit_type, expected_nal_unit_type,
40
301k
                            expected_nal_unit_type);
41
301k
    else
42
301k
        ub(6, nal_unit_type);
43
44
1.04M
    u(6, nuh_layer_id,          0, 62);
45
1.04M
    u(3, nuh_temporal_id_plus1, 1,  7);
46
47
1.04M
    return 0;
48
1.04M
}
cbs_h2645.c:cbs_h265_read_nal_unit_header
Line
Count
Source
33
970k
{
34
970k
    int err;
35
36
970k
    fixed(1, forbidden_zero_bit, 0);
37
38
970k
    if (expected_nal_unit_type >= 0)
39
970k
        u(6, nal_unit_type, expected_nal_unit_type,
40
281k
                            expected_nal_unit_type);
41
281k
    else
42
281k
        ub(6, nal_unit_type);
43
44
970k
    u(6, nuh_layer_id,          0, 62);
45
970k
    u(3, nuh_temporal_id_plus1, 1,  7);
46
47
970k
    return 0;
48
970k
}
cbs_h2645.c:cbs_h265_write_nal_unit_header
Line
Count
Source
33
75.0k
{
34
75.0k
    int err;
35
36
75.0k
    fixed(1, forbidden_zero_bit, 0);
37
38
75.0k
    if (expected_nal_unit_type >= 0)
39
75.0k
        u(6, nal_unit_type, expected_nal_unit_type,
40
19.8k
                            expected_nal_unit_type);
41
19.8k
    else
42
19.8k
        ub(6, nal_unit_type);
43
44
75.0k
    u(6, nuh_layer_id,          0, 62);
45
75.0k
    u(3, nuh_temporal_id_plus1, 1,  7);
46
47
74.8k
    return 0;
48
75.0k
}
49
50
static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
51
80.2k
{
52
80.2k
    int err;
53
54
80.2k
    fixed(1, alignment_bit_equal_to_one, 1);
55
112k
    while (byte_alignment(rw) != 0)
56
76.7k
        fixed(1, alignment_bit_equal_to_zero, 0);
57
58
35.7k
    return 0;
59
54.0k
}
cbs_h2645.c:cbs_h265_read_byte_alignment
Line
Count
Source
51
72.4k
{
52
72.4k
    int err;
53
54
72.4k
    fixed(1, alignment_bit_equal_to_one, 1);
55
90.1k
    while (byte_alignment(rw) != 0)
56
62.2k
        fixed(1, alignment_bit_equal_to_zero, 0);
57
58
27.9k
    return 0;
59
46.2k
}
cbs_h2645.c:cbs_h265_write_byte_alignment
Line
Count
Source
51
7.75k
{
52
7.75k
    int err;
53
54
7.75k
    fixed(1, alignment_bit_equal_to_one, 1);
55
22.2k
    while (byte_alignment(rw) != 0)
56
14.4k
        fixed(1, alignment_bit_equal_to_zero, 0);
57
58
7.75k
    return 0;
59
7.75k
}
60
61
static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw,
62
                                H265RawExtensionData *current)
63
71.9k
{
64
71.9k
    int err;
65
71.9k
    size_t k;
66
#ifdef READ
67
    GetBitContext start;
68
    uint8_t bit;
69
    start = *rw;
70
19.5M
    for (k = 0; cbs_h2645_read_more_rbsp_data(rw); k++)
71
19.5M
        skip_bits(rw, 1);
72
    current->bit_length = k;
73
50.6k
    if (k > 0) {
74
48.8k
        *rw = start;
75
48.8k
        allocate(current->data, (current->bit_length + 7) / 8);
76
19.5M
        for (k = 0; k < current->bit_length; k++) {
77
19.5M
            xu(1, extension_data, bit, 0, 1, 0);
78
19.5M
            current->data[k / 8] |= bit << (7 - k % 8);
79
19.5M
        }
80
48.8k
    }
81
#else
82
11.5M
    for (k = 0; k < current->bit_length; k++)
83
11.5M
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
84
21.2k
#endif
85
71.9k
    return 0;
86
71.9k
}
cbs_h2645.c:cbs_h265_read_extension_data
Line
Count
Source
63
50.6k
{
64
50.6k
    int err;
65
50.6k
    size_t k;
66
50.6k
#ifdef READ
67
50.6k
    GetBitContext start;
68
50.6k
    uint8_t bit;
69
50.6k
    start = *rw;
70
19.5M
    for (k = 0; cbs_h2645_read_more_rbsp_data(rw); k++)
71
19.5M
        skip_bits(rw, 1);
72
50.6k
    current->bit_length = k;
73
50.6k
    if (k > 0) {
74
48.8k
        *rw = start;
75
48.8k
        allocate(current->data, (current->bit_length + 7) / 8);
76
19.5M
        for (k = 0; k < current->bit_length; k++) {
77
19.5M
            xu(1, extension_data, bit, 0, 1, 0);
78
19.5M
            current->data[k / 8] |= bit << (7 - k % 8);
79
19.5M
        }
80
48.8k
    }
81
#else
82
    for (k = 0; k < current->bit_length; k++)
83
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
84
#endif
85
50.6k
    return 0;
86
50.6k
}
cbs_h2645.c:cbs_h265_write_extension_data
Line
Count
Source
63
21.2k
{
64
21.2k
    int err;
65
21.2k
    size_t k;
66
#ifdef READ
67
    GetBitContext start;
68
    uint8_t bit;
69
    start = *rw;
70
    for (k = 0; cbs_h2645_read_more_rbsp_data(rw); k++)
71
        skip_bits(rw, 1);
72
    current->bit_length = k;
73
    if (k > 0) {
74
        *rw = start;
75
        allocate(current->data, (current->bit_length + 7) / 8);
76
        for (k = 0; k < current->bit_length; k++) {
77
            xu(1, extension_data, bit, 0, 1, 0);
78
            current->data[k / 8] |= bit << (7 - k % 8);
79
        }
80
    }
81
#else
82
11.5M
    for (k = 0; k < current->bit_length; k++)
83
11.5M
        xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
84
21.2k
#endif
85
21.2k
    return 0;
86
21.2k
}
87
88
static int FUNC(profile_tier_level)(CodedBitstreamContext *ctx, RWContext *rw,
89
                                    H265RawProfileTierLevel *current,
90
                                    int profile_present_flag,
91
                                    int max_num_sub_layers_minus1)
92
279k
{
93
279k
    int err, i, j;
94
95
279k
    if (profile_present_flag) {
96
279k
        u(2, general_profile_space, 0, 0);
97
275k
        flag(general_tier_flag);
98
275k
        ub(5, general_profile_idc);
99
100
9.05M
        for (j = 0; j < 32; j++)
101
8.77M
            flags(general_profile_compatibility_flag[j], 1, j);
102
103
273k
        flag(general_progressive_source_flag);
104
269k
        flag(general_interlaced_source_flag);
105
269k
        flag(general_non_packed_constraint_flag);
106
269k
        flag(general_frame_only_constraint_flag);
107
108
6.11M
#define profile_compatible(x) (current->general_profile_idc == (x) || \
109
6.11M
                               current->general_profile_compatibility_flag[x])
110
269k
        if (profile_compatible(4) || profile_compatible(5) ||
111
269k
            profile_compatible(6) || profile_compatible(7) ||
112
269k
            profile_compatible(8) || profile_compatible(9) ||
113
269k
            profile_compatible(10) || profile_compatible(11)) {
114
182k
            flag(general_max_12bit_constraint_flag);
115
182k
            flag(general_max_10bit_constraint_flag);
116
182k
            flag(general_max_8bit_constraint_flag);
117
182k
            flag(general_max_422chroma_constraint_flag);
118
182k
            flag(general_max_420chroma_constraint_flag);
119
181k
            flag(general_max_monochrome_constraint_flag);
120
181k
            flag(general_intra_constraint_flag);
121
181k
            flag(general_one_picture_only_constraint_flag);
122
181k
            flag(general_lower_bit_rate_constraint_flag);
123
124
181k
            if (profile_compatible(5) || profile_compatible(9) ||
125
181k
                profile_compatible(10) || profile_compatible(11)) {
126
52.9k
                flag(general_max_14bit_constraint_flag);
127
52.9k
                fixed(24, general_reserved_zero_33bits, 0);
128
42.0k
                fixed( 9, general_reserved_zero_33bits, 0);
129
128k
            } else {
130
128k
                fixed(24, general_reserved_zero_34bits, 0);
131
104k
                fixed(10, general_reserved_zero_34bits, 0);
132
104k
            }
133
181k
        } else if (profile_compatible(2)) {
134
81.2k
            fixed(7, general_reserved_zero_7bits, 0);
135
77.9k
            flag(general_one_picture_only_constraint_flag);
136
77.9k
            fixed(24, general_reserved_zero_35bits, 0);
137
67.9k
            fixed(11, general_reserved_zero_35bits, 0);
138
67.9k
        } else {
139
5.81k
            fixed(24, general_reserved_zero_43bits, 0);
140
4.46k
            fixed(19, general_reserved_zero_43bits, 0);
141
4.46k
        }
142
143
211k
        if (profile_compatible(1) || profile_compatible(2) ||
144
211k
            profile_compatible(3) || profile_compatible(4) ||
145
211k
            profile_compatible(5) || profile_compatible(9) ||
146
211k
            profile_compatible(11)) {
147
202k
            flag(general_inbld_flag);
148
202k
        } else {
149
8.89k
            fixed(1, general_reserved_zero_bit, 0);
150
8.89k
        }
151
211k
#undef profile_compatible
152
211k
    }
153
154
211k
    ub(8, general_level_idc);
155
156
384k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
157
173k
        flags(sub_layer_profile_present_flag[i], 1, i);
158
173k
        flags(sub_layer_level_present_flag[i],   1, i);
159
173k
    }
160
161
211k
    if (max_num_sub_layers_minus1 > 0) {
162
255k
        for (i = max_num_sub_layers_minus1; i < 8; i++)
163
210k
            fixed(2, reserved_zero_2bits, 0);
164
48.3k
    }
165
166
359k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
167
155k
        if (current->sub_layer_profile_present_flag[i]) {
168
20.5k
            us(2, sub_layer_profile_space[i], 0, 0, 1, i);
169
19.9k
            flags(sub_layer_tier_flag[i],           1, i);
170
19.9k
            ubs(5, sub_layer_profile_idc[i], 1, i);
171
172
657k
            for (j = 0; j < 32; j++)
173
637k
                flags(sub_layer_profile_compatibility_flag[i][j], 2, i, j);
174
175
19.9k
            flags(sub_layer_progressive_source_flag[i],    1, i);
176
19.8k
            flags(sub_layer_interlaced_source_flag[i],     1, i);
177
19.8k
            flags(sub_layer_non_packed_constraint_flag[i], 1, i);
178
19.8k
            flags(sub_layer_frame_only_constraint_flag[i], 1, i);
179
180
509k
#define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) ||   \
181
509k
                               current->sub_layer_profile_compatibility_flag[i][x])
182
19.8k
            if (profile_compatible(4) || profile_compatible(5) ||
183
19.8k
                profile_compatible(6) || profile_compatible(7) ||
184
19.8k
                profile_compatible(8) || profile_compatible(9) ||
185
19.8k
                profile_compatible(10) || profile_compatible(11)) {
186
17.5k
                flags(sub_layer_max_12bit_constraint_flag[i],        1, i);
187
17.5k
                flags(sub_layer_max_10bit_constraint_flag[i],        1, i);
188
17.5k
                flags(sub_layer_max_8bit_constraint_flag[i],         1, i);
189
17.5k
                flags(sub_layer_max_422chroma_constraint_flag[i],    1, i);
190
17.5k
                flags(sub_layer_max_420chroma_constraint_flag[i],    1, i);
191
17.4k
                flags(sub_layer_max_monochrome_constraint_flag[i],   1, i);
192
17.4k
                flags(sub_layer_intra_constraint_flag[i],            1, i);
193
17.4k
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
194
17.4k
                flags(sub_layer_lower_bit_rate_constraint_flag[i],   1, i);
195
196
17.4k
                if (profile_compatible(5) || profile_compatible(9) ||
197
17.4k
                    profile_compatible(10) || profile_compatible(11)) {
198
13.5k
                    flags(sub_layer_max_14bit_constraint_flag[i], 1, i);
199
13.5k
                    fixed(24, sub_layer_reserved_zero_33bits, 0);
200
11.2k
                    fixed( 9, sub_layer_reserved_zero_33bits, 0);
201
11.2k
                } else {
202
3.87k
                    fixed(24, sub_layer_reserved_zero_34bits, 0);
203
3.76k
                    fixed(10, sub_layer_reserved_zero_34bits, 0);
204
3.76k
                }
205
17.4k
            } else if (profile_compatible(2)) {
206
204
                fixed(7, sub_layer_reserved_zero_7bits, 0);
207
188
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
208
188
                fixed(24, sub_layer_reserved_zero_43bits, 0);
209
187
                fixed(11, sub_layer_reserved_zero_43bits, 0);
210
2.07k
            } else {
211
2.07k
                fixed(24, sub_layer_reserved_zero_43bits, 0);
212
1.80k
                fixed(19, sub_layer_reserved_zero_43bits, 0);
213
1.80k
            }
214
215
16.3k
            if (profile_compatible(1) || profile_compatible(2) ||
216
16.3k
                profile_compatible(3) || profile_compatible(4) ||
217
16.3k
                profile_compatible(5) || profile_compatible(9) ||
218
16.3k
                profile_compatible(11)) {
219
13.1k
                flags(sub_layer_inbld_flag[i], 1, i);
220
13.1k
            } else {
221
3.15k
                fixed(1, sub_layer_reserved_zero_bit, 0);
222
3.15k
            }
223
16.3k
#undef profile_compatible
224
16.3k
        }
225
151k
        if (current->sub_layer_level_present_flag[i])
226
151k
            ubs(8, sub_layer_level_idc[i], 1, i);
227
151k
    }
228
229
203k
    return 0;
230
208k
}
cbs_h2645.c:cbs_h265_read_profile_tier_level
Line
Count
Source
92
260k
{
93
260k
    int err, i, j;
94
95
260k
    if (profile_present_flag) {
96
260k
        u(2, general_profile_space, 0, 0);
97
257k
        flag(general_tier_flag);
98
257k
        ub(5, general_profile_idc);
99
100
8.44M
        for (j = 0; j < 32; j++)
101
8.18M
            flags(general_profile_compatibility_flag[j], 1, j);
102
103
254k
        flag(general_progressive_source_flag);
104
250k
        flag(general_interlaced_source_flag);
105
250k
        flag(general_non_packed_constraint_flag);
106
250k
        flag(general_frame_only_constraint_flag);
107
108
250k
#define profile_compatible(x) (current->general_profile_idc == (x) || \
109
250k
                               current->general_profile_compatibility_flag[x])
110
250k
        if (profile_compatible(4) || profile_compatible(5) ||
111
250k
            profile_compatible(6) || profile_compatible(7) ||
112
250k
            profile_compatible(8) || profile_compatible(9) ||
113
250k
            profile_compatible(10) || profile_compatible(11)) {
114
173k
            flag(general_max_12bit_constraint_flag);
115
173k
            flag(general_max_10bit_constraint_flag);
116
173k
            flag(general_max_8bit_constraint_flag);
117
173k
            flag(general_max_422chroma_constraint_flag);
118
173k
            flag(general_max_420chroma_constraint_flag);
119
172k
            flag(general_max_monochrome_constraint_flag);
120
172k
            flag(general_intra_constraint_flag);
121
172k
            flag(general_one_picture_only_constraint_flag);
122
172k
            flag(general_lower_bit_rate_constraint_flag);
123
124
172k
            if (profile_compatible(5) || profile_compatible(9) ||
125
172k
                profile_compatible(10) || profile_compatible(11)) {
126
47.2k
                flag(general_max_14bit_constraint_flag);
127
47.2k
                fixed(24, general_reserved_zero_33bits, 0);
128
36.3k
                fixed( 9, general_reserved_zero_33bits, 0);
129
125k
            } else {
130
125k
                fixed(24, general_reserved_zero_34bits, 0);
131
101k
                fixed(10, general_reserved_zero_34bits, 0);
132
101k
            }
133
172k
        } else if (profile_compatible(2)) {
134
72.3k
            fixed(7, general_reserved_zero_7bits, 0);
135
69.0k
            flag(general_one_picture_only_constraint_flag);
136
69.0k
            fixed(24, general_reserved_zero_35bits, 0);
137
59.1k
            fixed(11, general_reserved_zero_35bits, 0);
138
59.1k
        } else {
139
4.86k
            fixed(24, general_reserved_zero_43bits, 0);
140
3.51k
            fixed(19, general_reserved_zero_43bits, 0);
141
3.51k
        }
142
143
193k
        if (profile_compatible(1) || profile_compatible(2) ||
144
193k
            profile_compatible(3) || profile_compatible(4) ||
145
193k
            profile_compatible(5) || profile_compatible(9) ||
146
193k
            profile_compatible(11)) {
147
185k
            flag(general_inbld_flag);
148
185k
        } else {
149
7.88k
            fixed(1, general_reserved_zero_bit, 0);
150
7.88k
        }
151
193k
#undef profile_compatible
152
193k
    }
153
154
192k
    ub(8, general_level_idc);
155
156
346k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
157
153k
        flags(sub_layer_profile_present_flag[i], 1, i);
158
153k
        flags(sub_layer_level_present_flag[i],   1, i);
159
153k
    }
160
161
192k
    if (max_num_sub_layers_minus1 > 0) {
162
230k
        for (i = max_num_sub_layers_minus1; i < 8; i++)
163
189k
            fixed(2, reserved_zero_2bits, 0);
164
43.4k
    }
165
166
321k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
167
136k
        if (current->sub_layer_profile_present_flag[i]) {
168
17.8k
            us(2, sub_layer_profile_space[i], 0, 0, 1, i);
169
17.1k
            flags(sub_layer_tier_flag[i],           1, i);
170
17.1k
            ubs(5, sub_layer_profile_idc[i], 1, i);
171
172
566k
            for (j = 0; j < 32; j++)
173
549k
                flags(sub_layer_profile_compatibility_flag[i][j], 2, i, j);
174
175
17.1k
            flags(sub_layer_progressive_source_flag[i],    1, i);
176
17.0k
            flags(sub_layer_interlaced_source_flag[i],     1, i);
177
17.0k
            flags(sub_layer_non_packed_constraint_flag[i], 1, i);
178
17.0k
            flags(sub_layer_frame_only_constraint_flag[i], 1, i);
179
180
17.0k
#define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) ||   \
181
17.0k
                               current->sub_layer_profile_compatibility_flag[i][x])
182
17.0k
            if (profile_compatible(4) || profile_compatible(5) ||
183
17.0k
                profile_compatible(6) || profile_compatible(7) ||
184
17.0k
                profile_compatible(8) || profile_compatible(9) ||
185
17.0k
                profile_compatible(10) || profile_compatible(11)) {
186
15.0k
                flags(sub_layer_max_12bit_constraint_flag[i],        1, i);
187
15.0k
                flags(sub_layer_max_10bit_constraint_flag[i],        1, i);
188
15.0k
                flags(sub_layer_max_8bit_constraint_flag[i],         1, i);
189
15.0k
                flags(sub_layer_max_422chroma_constraint_flag[i],    1, i);
190
15.0k
                flags(sub_layer_max_420chroma_constraint_flag[i],    1, i);
191
14.8k
                flags(sub_layer_max_monochrome_constraint_flag[i],   1, i);
192
14.8k
                flags(sub_layer_intra_constraint_flag[i],            1, i);
193
14.8k
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
194
14.8k
                flags(sub_layer_lower_bit_rate_constraint_flag[i],   1, i);
195
196
14.8k
                if (profile_compatible(5) || profile_compatible(9) ||
197
14.8k
                    profile_compatible(10) || profile_compatible(11)) {
198
11.4k
                    flags(sub_layer_max_14bit_constraint_flag[i], 1, i);
199
11.4k
                    fixed(24, sub_layer_reserved_zero_33bits, 0);
200
9.09k
                    fixed( 9, sub_layer_reserved_zero_33bits, 0);
201
9.09k
                } else {
202
3.47k
                    fixed(24, sub_layer_reserved_zero_34bits, 0);
203
3.36k
                    fixed(10, sub_layer_reserved_zero_34bits, 0);
204
3.36k
                }
205
14.8k
            } else if (profile_compatible(2)) {
206
202
                fixed(7, sub_layer_reserved_zero_7bits, 0);
207
186
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
208
186
                fixed(24, sub_layer_reserved_zero_43bits, 0);
209
185
                fixed(11, sub_layer_reserved_zero_43bits, 0);
210
1.88k
            } else {
211
1.88k
                fixed(24, sub_layer_reserved_zero_43bits, 0);
212
1.61k
                fixed(19, sub_layer_reserved_zero_43bits, 0);
213
1.61k
            }
214
215
13.5k
            if (profile_compatible(1) || profile_compatible(2) ||
216
13.5k
                profile_compatible(3) || profile_compatible(4) ||
217
13.5k
                profile_compatible(5) || profile_compatible(9) ||
218
13.5k
                profile_compatible(11)) {
219
11.2k
                flags(sub_layer_inbld_flag[i], 1, i);
220
11.2k
            } else {
221
2.27k
                fixed(1, sub_layer_reserved_zero_bit, 0);
222
2.27k
            }
223
13.5k
#undef profile_compatible
224
13.5k
        }
225
132k
        if (current->sub_layer_level_present_flag[i])
226
132k
            ubs(8, sub_layer_level_idc[i], 1, i);
227
132k
    }
228
229
185k
    return 0;
230
189k
}
cbs_h2645.c:cbs_h265_write_profile_tier_level
Line
Count
Source
92
18.4k
{
93
18.4k
    int err, i, j;
94
95
18.4k
    if (profile_present_flag) {
96
18.4k
        u(2, general_profile_space, 0, 0);
97
18.4k
        flag(general_tier_flag);
98
18.4k
        ub(5, general_profile_idc);
99
100
608k
        for (j = 0; j < 32; j++)
101
589k
            flags(general_profile_compatibility_flag[j], 1, j);
102
103
18.4k
        flag(general_progressive_source_flag);
104
18.4k
        flag(general_interlaced_source_flag);
105
18.4k
        flag(general_non_packed_constraint_flag);
106
18.4k
        flag(general_frame_only_constraint_flag);
107
108
18.4k
#define profile_compatible(x) (current->general_profile_idc == (x) || \
109
18.4k
                               current->general_profile_compatibility_flag[x])
110
18.4k
        if (profile_compatible(4) || profile_compatible(5) ||
111
18.4k
            profile_compatible(6) || profile_compatible(7) ||
112
18.4k
            profile_compatible(8) || profile_compatible(9) ||
113
18.4k
            profile_compatible(10) || profile_compatible(11)) {
114
8.60k
            flag(general_max_12bit_constraint_flag);
115
8.60k
            flag(general_max_10bit_constraint_flag);
116
8.60k
            flag(general_max_8bit_constraint_flag);
117
8.60k
            flag(general_max_422chroma_constraint_flag);
118
8.60k
            flag(general_max_420chroma_constraint_flag);
119
8.60k
            flag(general_max_monochrome_constraint_flag);
120
8.60k
            flag(general_intra_constraint_flag);
121
8.60k
            flag(general_one_picture_only_constraint_flag);
122
8.60k
            flag(general_lower_bit_rate_constraint_flag);
123
124
8.60k
            if (profile_compatible(5) || profile_compatible(9) ||
125
8.60k
                profile_compatible(10) || profile_compatible(11)) {
126
5.72k
                flag(general_max_14bit_constraint_flag);
127
5.72k
                fixed(24, general_reserved_zero_33bits, 0);
128
5.72k
                fixed( 9, general_reserved_zero_33bits, 0);
129
5.72k
            } else {
130
2.87k
                fixed(24, general_reserved_zero_34bits, 0);
131
2.87k
                fixed(10, general_reserved_zero_34bits, 0);
132
2.87k
            }
133
9.82k
        } else if (profile_compatible(2)) {
134
8.88k
            fixed(7, general_reserved_zero_7bits, 0);
135
8.88k
            flag(general_one_picture_only_constraint_flag);
136
8.88k
            fixed(24, general_reserved_zero_35bits, 0);
137
8.88k
            fixed(11, general_reserved_zero_35bits, 0);
138
8.88k
        } else {
139
946
            fixed(24, general_reserved_zero_43bits, 0);
140
946
            fixed(19, general_reserved_zero_43bits, 0);
141
946
        }
142
143
18.4k
        if (profile_compatible(1) || profile_compatible(2) ||
144
18.4k
            profile_compatible(3) || profile_compatible(4) ||
145
18.4k
            profile_compatible(5) || profile_compatible(9) ||
146
18.4k
            profile_compatible(11)) {
147
17.4k
            flag(general_inbld_flag);
148
17.4k
        } else {
149
1.00k
            fixed(1, general_reserved_zero_bit, 0);
150
1.00k
        }
151
18.4k
#undef profile_compatible
152
18.4k
    }
153
154
18.4k
    ub(8, general_level_idc);
155
156
37.8k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
157
19.4k
        flags(sub_layer_profile_present_flag[i], 1, i);
158
19.4k
        flags(sub_layer_level_present_flag[i],   1, i);
159
19.4k
    }
160
161
18.4k
    if (max_num_sub_layers_minus1 > 0) {
162
25.2k
        for (i = max_num_sub_layers_minus1; i < 8; i++)
163
20.3k
            fixed(2, reserved_zero_2bits, 0);
164
4.96k
    }
165
166
37.8k
    for (i = 0; i < max_num_sub_layers_minus1; i++) {
167
19.4k
        if (current->sub_layer_profile_present_flag[i]) {
168
2.75k
            us(2, sub_layer_profile_space[i], 0, 0, 1, i);
169
2.75k
            flags(sub_layer_tier_flag[i],           1, i);
170
2.75k
            ubs(5, sub_layer_profile_idc[i], 1, i);
171
172
90.9k
            for (j = 0; j < 32; j++)
173
88.1k
                flags(sub_layer_profile_compatibility_flag[i][j], 2, i, j);
174
175
2.75k
            flags(sub_layer_progressive_source_flag[i],    1, i);
176
2.75k
            flags(sub_layer_interlaced_source_flag[i],     1, i);
177
2.75k
            flags(sub_layer_non_packed_constraint_flag[i], 1, i);
178
2.75k
            flags(sub_layer_frame_only_constraint_flag[i], 1, i);
179
180
2.75k
#define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) ||   \
181
2.75k
                               current->sub_layer_profile_compatibility_flag[i][x])
182
2.75k
            if (profile_compatible(4) || profile_compatible(5) ||
183
2.75k
                profile_compatible(6) || profile_compatible(7) ||
184
2.75k
                profile_compatible(8) || profile_compatible(9) ||
185
2.75k
                profile_compatible(10) || profile_compatible(11)) {
186
2.56k
                flags(sub_layer_max_12bit_constraint_flag[i],        1, i);
187
2.56k
                flags(sub_layer_max_10bit_constraint_flag[i],        1, i);
188
2.56k
                flags(sub_layer_max_8bit_constraint_flag[i],         1, i);
189
2.56k
                flags(sub_layer_max_422chroma_constraint_flag[i],    1, i);
190
2.56k
                flags(sub_layer_max_420chroma_constraint_flag[i],    1, i);
191
2.56k
                flags(sub_layer_max_monochrome_constraint_flag[i],   1, i);
192
2.56k
                flags(sub_layer_intra_constraint_flag[i],            1, i);
193
2.56k
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
194
2.56k
                flags(sub_layer_lower_bit_rate_constraint_flag[i],   1, i);
195
196
2.56k
                if (profile_compatible(5) || profile_compatible(9) ||
197
2.56k
                    profile_compatible(10) || profile_compatible(11)) {
198
2.15k
                    flags(sub_layer_max_14bit_constraint_flag[i], 1, i);
199
2.15k
                    fixed(24, sub_layer_reserved_zero_33bits, 0);
200
2.15k
                    fixed( 9, sub_layer_reserved_zero_33bits, 0);
201
2.15k
                } else {
202
401
                    fixed(24, sub_layer_reserved_zero_34bits, 0);
203
401
                    fixed(10, sub_layer_reserved_zero_34bits, 0);
204
401
                }
205
2.56k
            } else if (profile_compatible(2)) {
206
2
                fixed(7, sub_layer_reserved_zero_7bits, 0);
207
2
                flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
208
2
                fixed(24, sub_layer_reserved_zero_43bits, 0);
209
2
                fixed(11, sub_layer_reserved_zero_43bits, 0);
210
193
            } else {
211
193
                fixed(24, sub_layer_reserved_zero_43bits, 0);
212
193
                fixed(19, sub_layer_reserved_zero_43bits, 0);
213
193
            }
214
215
2.75k
            if (profile_compatible(1) || profile_compatible(2) ||
216
2.75k
                profile_compatible(3) || profile_compatible(4) ||
217
2.75k
                profile_compatible(5) || profile_compatible(9) ||
218
2.75k
                profile_compatible(11)) {
219
1.87k
                flags(sub_layer_inbld_flag[i], 1, i);
220
1.87k
            } else {
221
884
                fixed(1, sub_layer_reserved_zero_bit, 0);
222
884
            }
223
2.75k
#undef profile_compatible
224
2.75k
        }
225
19.4k
        if (current->sub_layer_level_present_flag[i])
226
19.4k
            ubs(8, sub_layer_level_idc[i], 1, i);
227
19.4k
    }
228
229
18.4k
    return 0;
230
18.4k
}
231
232
static int FUNC(sub_layer_hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
233
                                          H265RawHRDParameters *hrd,
234
                                          int nal, int sub_layer_id)
235
52.7k
{
236
52.7k
    H265RawSubLayerHRDParameters *current;
237
52.7k
    int err, i;
238
239
52.7k
    if (nal)
240
26.7k
        current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
241
25.9k
    else
242
25.9k
        current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
243
244
154k
    for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
245
105k
        ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
246
104k
        ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
247
103k
        if (hrd->sub_pic_hrd_params_present_flag) {
248
62.3k
            ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
249
61.0k
            ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
250
61.0k
        }
251
102k
        flags(cbr_flag[i], 1, i);
252
102k
    }
253
254
49.4k
    return 0;
255
52.7k
}
cbs_h2645.c:cbs_h265_read_sub_layer_hrd_parameters
Line
Count
Source
235
48.0k
{
236
48.0k
    H265RawSubLayerHRDParameters *current;
237
48.0k
    int err, i;
238
239
48.0k
    if (nal)
240
24.8k
        current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
241
23.2k
    else
242
23.2k
        current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
243
244
140k
    for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
245
95.5k
        ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
246
94.6k
        ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
247
93.9k
        if (hrd->sub_pic_hrd_params_present_flag) {
248
56.4k
            ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
249
55.2k
            ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
250
55.2k
        }
251
92.3k
        flags(cbr_flag[i], 1, i);
252
92.3k
    }
253
254
44.8k
    return 0;
255
48.0k
}
cbs_h2645.c:cbs_h265_write_sub_layer_hrd_parameters
Line
Count
Source
235
4.67k
{
236
4.67k
    H265RawSubLayerHRDParameters *current;
237
4.67k
    int err, i;
238
239
4.67k
    if (nal)
240
1.94k
        current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
241
2.72k
    else
242
2.72k
        current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
243
244
14.5k
    for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
245
9.87k
        ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
246
9.87k
        ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
247
9.87k
        if (hrd->sub_pic_hrd_params_present_flag) {
248
5.84k
            ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
249
5.84k
            ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
250
5.84k
        }
251
9.87k
        flags(cbr_flag[i], 1, i);
252
9.87k
    }
253
254
4.67k
    return 0;
255
4.67k
}
256
257
static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
258
                                H265RawHRDParameters *current, int common_inf_present_flag,
259
                                int max_num_sub_layers_minus1)
260
41.6k
{
261
41.6k
    int err, i;
262
263
41.6k
    if (common_inf_present_flag) {
264
40.1k
        flag(nal_hrd_parameters_present_flag);
265
40.0k
        flag(vcl_hrd_parameters_present_flag);
266
267
40.0k
        if (current->nal_hrd_parameters_present_flag ||
268
40.0k
            current->vcl_hrd_parameters_present_flag) {
269
34.4k
            flag(sub_pic_hrd_params_present_flag);
270
34.1k
            if (current->sub_pic_hrd_params_present_flag) {
271
22.8k
                ub(8, tick_divisor_minus2);
272
22.5k
                ub(5, du_cpb_removal_delay_increment_length_minus1);
273
22.2k
                flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
274
20.1k
                ub(5, dpb_output_delay_du_length_minus1);
275
20.1k
            }
276
277
29.3k
            ub(4, bit_rate_scale);
278
28.9k
            ub(4, cpb_size_scale);
279
28.2k
            if (current->sub_pic_hrd_params_present_flag)
280
17.2k
                ub(4, cpb_size_du_scale);
281
282
27.8k
            ub(5, initial_cpb_removal_delay_length_minus1);
283
27.6k
            ub(5, au_cpb_removal_delay_length_minus1);
284
27.6k
            ub(5, dpb_output_delay_length_minus1);
285
27.6k
        } else {
286
5.62k
            infer(sub_pic_hrd_params_present_flag, 0);
287
288
5.62k
            infer(initial_cpb_removal_delay_length_minus1, 23);
289
5.62k
            infer(au_cpb_removal_delay_length_minus1,      23);
290
5.62k
            infer(dpb_output_delay_length_minus1,          23);
291
46
        }
292
40.0k
    }
293
294
86.9k
    for (i = 0; i <= max_num_sub_layers_minus1; i++) {
295
62.8k
        flags(fixed_pic_rate_general_flag[i], 1, i);
296
297
58.4k
        if (!current->fixed_pic_rate_general_flag[i])
298
58.4k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
299
25.9k
        else
300
25.9k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
301
302
58.3k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
303
40.9k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
304
40.6k
            infer(low_delay_hrd_flag[i], 0);
305
40.6k
        } else
306
58.3k
            flags(low_delay_hrd_flag[i], 1, i);
307
308
57.8k
        if (!current->low_delay_hrd_flag[i])
309
57.8k
            ues(cpb_cnt_minus1[i], 0, 31, 1, i);
310
9.11k
        else
311
9.11k
            infer(cpb_cnt_minus1[i], 0);
312
313
56.1k
        if (current->nal_hrd_parameters_present_flag)
314
25.9k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 0, i));
315
55.1k
        if (current->vcl_hrd_parameters_present_flag)
316
26.7k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 1, i));
317
55.1k
    }
318
319
24.0k
    return 0;
320
34.1k
}
cbs_h2645.c:cbs_h265_read_hrd_parameters
Line
Count
Source
260
39.6k
{
261
39.6k
    int err, i;
262
263
39.6k
    if (common_inf_present_flag) {
264
38.1k
        flag(nal_hrd_parameters_present_flag);
265
38.1k
        flag(vcl_hrd_parameters_present_flag);
266
267
38.0k
        if (current->nal_hrd_parameters_present_flag ||
268
38.0k
            current->vcl_hrd_parameters_present_flag) {
269
32.4k
            flag(sub_pic_hrd_params_present_flag);
270
32.2k
            if (current->sub_pic_hrd_params_present_flag) {
271
21.8k
                ub(8, tick_divisor_minus2);
272
21.6k
                ub(5, du_cpb_removal_delay_increment_length_minus1);
273
21.2k
                flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
274
19.1k
                ub(5, dpb_output_delay_du_length_minus1);
275
19.1k
            }
276
277
27.4k
            ub(4, bit_rate_scale);
278
27.0k
            ub(4, cpb_size_scale);
279
26.3k
            if (current->sub_pic_hrd_params_present_flag)
280
16.3k
                ub(4, cpb_size_du_scale);
281
282
25.9k
            ub(5, initial_cpb_removal_delay_length_minus1);
283
25.7k
            ub(5, au_cpb_removal_delay_length_minus1);
284
25.6k
            ub(5, dpb_output_delay_length_minus1);
285
25.6k
        } else {
286
5.57k
            infer(sub_pic_hrd_params_present_flag, 0);
287
288
5.57k
            infer(initial_cpb_removal_delay_length_minus1, 23);
289
5.57k
            infer(au_cpb_removal_delay_length_minus1,      23);
290
5.57k
            infer(dpb_output_delay_length_minus1,          23);
291
5.57k
        }
292
38.0k
    }
293
294
81.7k
    for (i = 0; i <= max_num_sub_layers_minus1; i++) {
295
59.6k
        flags(fixed_pic_rate_general_flag[i], 1, i);
296
297
55.1k
        if (!current->fixed_pic_rate_general_flag[i])
298
55.1k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
299
24.4k
        else
300
24.4k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
301
302
55.1k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
303
38.0k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
304
37.7k
            infer(low_delay_hrd_flag[i], 0);
305
37.7k
        } else
306
55.1k
            flags(low_delay_hrd_flag[i], 1, i);
307
308
54.5k
        if (!current->low_delay_hrd_flag[i])
309
54.5k
            ues(cpb_cnt_minus1[i], 0, 31, 1, i);
310
8.97k
        else
311
8.97k
            infer(cpb_cnt_minus1[i], 0);
312
313
52.8k
        if (current->nal_hrd_parameters_present_flag)
314
23.2k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 0, i));
315
51.8k
        if (current->vcl_hrd_parameters_present_flag)
316
24.8k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 1, i));
317
51.8k
    }
318
319
22.1k
    return 0;
320
32.1k
}
cbs_h2645.c:cbs_h265_write_hrd_parameters
Line
Count
Source
260
1.96k
{
261
1.96k
    int err, i;
262
263
1.96k
    if (common_inf_present_flag) {
264
1.96k
        flag(nal_hrd_parameters_present_flag);
265
1.96k
        flag(vcl_hrd_parameters_present_flag);
266
267
1.96k
        if (current->nal_hrd_parameters_present_flag ||
268
1.96k
            current->vcl_hrd_parameters_present_flag) {
269
1.91k
            flag(sub_pic_hrd_params_present_flag);
270
1.91k
            if (current->sub_pic_hrd_params_present_flag) {
271
941
                ub(8, tick_divisor_minus2);
272
941
                ub(5, du_cpb_removal_delay_increment_length_minus1);
273
941
                flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
274
941
                ub(5, dpb_output_delay_du_length_minus1);
275
941
            }
276
277
1.91k
            ub(4, bit_rate_scale);
278
1.91k
            ub(4, cpb_size_scale);
279
1.91k
            if (current->sub_pic_hrd_params_present_flag)
280
941
                ub(4, cpb_size_du_scale);
281
282
1.91k
            ub(5, initial_cpb_removal_delay_length_minus1);
283
1.91k
            ub(5, au_cpb_removal_delay_length_minus1);
284
1.91k
            ub(5, dpb_output_delay_length_minus1);
285
1.91k
        } else {
286
46
            infer(sub_pic_hrd_params_present_flag, 0);
287
288
46
            infer(initial_cpb_removal_delay_length_minus1, 23);
289
46
            infer(au_cpb_removal_delay_length_minus1,      23);
290
46
            infer(dpb_output_delay_length_minus1,          23);
291
46
        }
292
1.96k
    }
293
294
5.22k
    for (i = 0; i <= max_num_sub_layers_minus1; i++) {
295
3.26k
        flags(fixed_pic_rate_general_flag[i], 1, i);
296
297
3.26k
        if (!current->fixed_pic_rate_general_flag[i])
298
3.26k
            flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
299
1.47k
        else
300
1.47k
            infer(fixed_pic_rate_within_cvs_flag[i], 1);
301
302
3.26k
        if (current->fixed_pic_rate_within_cvs_flag[i]) {
303
2.89k
            ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
304
2.89k
            infer(low_delay_hrd_flag[i], 0);
305
2.89k
        } else
306
3.26k
            flags(low_delay_hrd_flag[i], 1, i);
307
308
3.26k
        if (!current->low_delay_hrd_flag[i])
309
3.26k
            ues(cpb_cnt_minus1[i], 0, 31, 1, i);
310
145
        else
311
145
            infer(cpb_cnt_minus1[i], 0);
312
313
3.26k
        if (current->nal_hrd_parameters_present_flag)
314
2.72k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 0, i));
315
3.26k
        if (current->vcl_hrd_parameters_present_flag)
316
1.94k
            CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 1, i));
317
3.26k
    }
318
319
1.96k
    return 0;
320
1.96k
}
321
322
static int FUNC(vui_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
323
                                H265RawVUI *current, const H265RawSPS *sps)
324
73.9k
{
325
73.9k
    int err;
326
327
73.9k
    flag(aspect_ratio_info_present_flag);
328
73.8k
    if (current->aspect_ratio_info_present_flag) {
329
49.1k
        ub(8, aspect_ratio_idc);
330
48.7k
        if (current->aspect_ratio_idc == 255) {
331
10.0k
            ub(16, sar_width);
332
9.84k
            ub(16, sar_height);
333
9.84k
        }
334
48.7k
    } else {
335
24.6k
        infer(aspect_ratio_idc, 0);
336
24.6k
    }
337
338
73.1k
    flag(overscan_info_present_flag);
339
72.8k
    if (current->overscan_info_present_flag)
340
72.8k
        flag(overscan_appropriate_flag);
341
342
72.6k
    flag(video_signal_type_present_flag);
343
71.7k
    if (current->video_signal_type_present_flag) {
344
48.2k
        ub(3, video_format);
345
47.6k
        flag(video_full_range_flag);
346
46.0k
        flag(colour_description_present_flag);
347
45.5k
        if (current->colour_description_present_flag) {
348
25.6k
            ub(8, colour_primaries);
349
25.1k
            ub(8, transfer_characteristics);
350
25.0k
            ub(8, matrix_coefficients);
351
25.0k
        } else {
352
19.9k
            infer(colour_primaries,         2);
353
19.9k
            infer(transfer_characteristics, 2);
354
19.9k
            infer(matrix_coefficients,      2);
355
352
        }
356
45.5k
    } else {
357
23.5k
        infer(video_format,             5);
358
23.5k
        infer(video_full_range_flag,    0);
359
23.5k
        infer(colour_primaries,         2);
360
23.5k
        infer(transfer_characteristics, 2);
361
23.5k
        infer(matrix_coefficients,      2);
362
476
    }
363
364
68.4k
    flag(chroma_loc_info_present_flag);
365
68.0k
    if (current->chroma_loc_info_present_flag) {
366
39.6k
        ue(chroma_sample_loc_type_top_field,    0, 5);
367
38.4k
        ue(chroma_sample_loc_type_bottom_field, 0, 5);
368
38.4k
    } else {
369
28.4k
        infer(chroma_sample_loc_type_top_field,    0);
370
28.4k
        infer(chroma_sample_loc_type_bottom_field, 0);
371
847
    }
372
373
65.3k
    flag(neutral_chroma_indication_flag);
374
65.1k
    flag(field_seq_flag);
375
64.0k
    flag(frame_field_info_present_flag);
376
377
59.4k
    flag(default_display_window_flag);
378
59.4k
    if (current->default_display_window_flag) {
379
33.2k
        ue(def_disp_win_left_offset,   0, 16384);
380
33.0k
        ue(def_disp_win_right_offset,  0, 16384);
381
32.5k
        ue(def_disp_win_top_offset,    0, 16384);
382
32.3k
        ue(def_disp_win_bottom_offset, 0, 16384);
383
32.3k
    }
384
385
57.9k
    flag(vui_timing_info_present_flag);
386
57.7k
    if (current->vui_timing_info_present_flag) {
387
37.4k
        u(32, vui_num_units_in_tick, 1, UINT32_MAX);
388
36.0k
        u(32, vui_time_scale,        1, UINT32_MAX);
389
35.7k
        flag(vui_poc_proportional_to_timing_flag);
390
35.0k
        if (current->vui_poc_proportional_to_timing_flag)
391
35.0k
            ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
392
393
33.6k
        flag(vui_hrd_parameters_present_flag);
394
33.4k
        if (current->vui_hrd_parameters_present_flag) {
395
29.4k
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters,
396
29.4k
                                       1, sps->sps_max_sub_layers_minus1));
397
29.4k
        }
398
33.4k
    }
399
400
41.5k
    flag(bitstream_restriction_flag);
401
41.0k
    if (current->bitstream_restriction_flag) {
402
29.2k
        flag(tiles_fixed_structure_flag);
403
28.4k
        flag(motion_vectors_over_pic_boundaries_flag);
404
28.1k
        flag(restricted_ref_pic_lists_flag);
405
27.5k
        ue(min_spatial_segmentation_idc,  0, 4095);
406
27.1k
        ue(max_bytes_per_pic_denom,       0, 16);
407
26.4k
        ue(max_bits_per_min_cu_denom,     0, 16);
408
26.0k
        ue(log2_max_mv_length_horizontal, 0, 16);
409
25.6k
        ue(log2_max_mv_length_vertical,   0, 16);
410
25.6k
    } else {
411
11.7k
        infer(tiles_fixed_structure_flag,    0);
412
11.7k
        infer(motion_vectors_over_pic_boundaries_flag, 1);
413
11.7k
        infer(min_spatial_segmentation_idc,  0);
414
11.7k
        infer(max_bytes_per_pic_denom,       2);
415
11.7k
        infer(max_bits_per_min_cu_denom,     1);
416
11.7k
        infer(log2_max_mv_length_horizontal, 15);
417
11.7k
        infer(log2_max_mv_length_vertical,   15);
418
361
    }
419
420
37.0k
    return 0;
421
41.0k
}
cbs_h2645.c:cbs_h265_read_vui_parameters
Line
Count
Source
324
69.2k
{
325
69.2k
    int err;
326
327
69.2k
    flag(aspect_ratio_info_present_flag);
328
69.1k
    if (current->aspect_ratio_info_present_flag) {
329
45.2k
        ub(8, aspect_ratio_idc);
330
44.8k
        if (current->aspect_ratio_idc == 255) {
331
9.06k
            ub(16, sar_width);
332
8.81k
            ub(16, sar_height);
333
8.81k
        }
334
44.8k
    } else {
335
23.9k
        infer(aspect_ratio_idc, 0);
336
23.9k
    }
337
338
68.5k
    flag(overscan_info_present_flag);
339
68.1k
    if (current->overscan_info_present_flag)
340
68.1k
        flag(overscan_appropriate_flag);
341
342
67.9k
    flag(video_signal_type_present_flag);
343
67.1k
    if (current->video_signal_type_present_flag) {
344
44.0k
        ub(3, video_format);
345
43.4k
        flag(video_full_range_flag);
346
41.8k
        flag(colour_description_present_flag);
347
41.3k
        if (current->colour_description_present_flag) {
348
21.8k
            ub(8, colour_primaries);
349
21.3k
            ub(8, transfer_characteristics);
350
21.1k
            ub(8, matrix_coefficients);
351
21.1k
        } else {
352
19.5k
            infer(colour_primaries,         2);
353
19.5k
            infer(transfer_characteristics, 2);
354
19.5k
            infer(matrix_coefficients,      2);
355
19.5k
        }
356
41.3k
    } else {
357
23.0k
        infer(video_format,             5);
358
23.0k
        infer(video_full_range_flag,    0);
359
23.0k
        infer(colour_primaries,         2);
360
23.0k
        infer(transfer_characteristics, 2);
361
23.0k
        infer(matrix_coefficients,      2);
362
23.0k
    }
363
364
63.7k
    flag(chroma_loc_info_present_flag);
365
63.3k
    if (current->chroma_loc_info_present_flag) {
366
35.7k
        ue(chroma_sample_loc_type_top_field,    0, 5);
367
34.6k
        ue(chroma_sample_loc_type_bottom_field, 0, 5);
368
34.6k
    } else {
369
27.5k
        infer(chroma_sample_loc_type_top_field,    0);
370
27.5k
        infer(chroma_sample_loc_type_bottom_field, 0);
371
27.5k
    }
372
373
60.6k
    flag(neutral_chroma_indication_flag);
374
60.4k
    flag(field_seq_flag);
375
59.3k
    flag(frame_field_info_present_flag);
376
377
54.7k
    flag(default_display_window_flag);
378
54.7k
    if (current->default_display_window_flag) {
379
29.7k
        ue(def_disp_win_left_offset,   0, 16384);
380
29.5k
        ue(def_disp_win_right_offset,  0, 16384);
381
29.0k
        ue(def_disp_win_top_offset,    0, 16384);
382
28.8k
        ue(def_disp_win_bottom_offset, 0, 16384);
383
28.8k
    }
384
385
53.2k
    flag(vui_timing_info_present_flag);
386
53.0k
    if (current->vui_timing_info_present_flag) {
387
35.5k
        u(32, vui_num_units_in_tick, 1, UINT32_MAX);
388
34.1k
        u(32, vui_time_scale,        1, UINT32_MAX);
389
33.8k
        flag(vui_poc_proportional_to_timing_flag);
390
33.1k
        if (current->vui_poc_proportional_to_timing_flag)
391
33.1k
            ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
392
393
31.7k
        flag(vui_hrd_parameters_present_flag);
394
31.5k
        if (current->vui_hrd_parameters_present_flag) {
395
27.7k
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters,
396
27.7k
                                       1, sps->sps_max_sub_layers_minus1));
397
27.7k
        }
398
31.5k
    }
399
400
36.9k
    flag(bitstream_restriction_flag);
401
36.3k
    if (current->bitstream_restriction_flag) {
402
24.9k
        flag(tiles_fixed_structure_flag);
403
24.1k
        flag(motion_vectors_over_pic_boundaries_flag);
404
23.8k
        flag(restricted_ref_pic_lists_flag);
405
23.2k
        ue(min_spatial_segmentation_idc,  0, 4095);
406
22.8k
        ue(max_bytes_per_pic_denom,       0, 16);
407
22.1k
        ue(max_bits_per_min_cu_denom,     0, 16);
408
21.7k
        ue(log2_max_mv_length_horizontal, 0, 16);
409
21.2k
        ue(log2_max_mv_length_vertical,   0, 16);
410
21.2k
    } else {
411
11.4k
        infer(tiles_fixed_structure_flag,    0);
412
11.4k
        infer(motion_vectors_over_pic_boundaries_flag, 1);
413
11.4k
        infer(min_spatial_segmentation_idc,  0);
414
11.4k
        infer(max_bytes_per_pic_denom,       2);
415
11.4k
        infer(max_bits_per_min_cu_denom,     1);
416
11.4k
        infer(log2_max_mv_length_horizontal, 15);
417
11.4k
        infer(log2_max_mv_length_vertical,   15);
418
11.4k
    }
419
420
32.3k
    return 0;
421
36.3k
}
cbs_h2645.c:cbs_h265_write_vui_parameters
Line
Count
Source
324
4.67k
{
325
4.67k
    int err;
326
327
4.67k
    flag(aspect_ratio_info_present_flag);
328
4.67k
    if (current->aspect_ratio_info_present_flag) {
329
3.94k
        ub(8, aspect_ratio_idc);
330
3.94k
        if (current->aspect_ratio_idc == 255) {
331
1.02k
            ub(16, sar_width);
332
1.02k
            ub(16, sar_height);
333
1.02k
        }
334
3.94k
    } else {
335
732
        infer(aspect_ratio_idc, 0);
336
732
    }
337
338
4.67k
    flag(overscan_info_present_flag);
339
4.67k
    if (current->overscan_info_present_flag)
340
4.67k
        flag(overscan_appropriate_flag);
341
342
4.67k
    flag(video_signal_type_present_flag);
343
4.67k
    if (current->video_signal_type_present_flag) {
344
4.19k
        ub(3, video_format);
345
4.19k
        flag(video_full_range_flag);
346
4.19k
        flag(colour_description_present_flag);
347
4.19k
        if (current->colour_description_present_flag) {
348
3.84k
            ub(8, colour_primaries);
349
3.84k
            ub(8, transfer_characteristics);
350
3.84k
            ub(8, matrix_coefficients);
351
3.84k
        } else {
352
352
            infer(colour_primaries,         2);
353
352
            infer(transfer_characteristics, 2);
354
352
            infer(matrix_coefficients,      2);
355
352
        }
356
4.19k
    } else {
357
476
        infer(video_format,             5);
358
476
        infer(video_full_range_flag,    0);
359
476
        infer(colour_primaries,         2);
360
476
        infer(transfer_characteristics, 2);
361
476
        infer(matrix_coefficients,      2);
362
476
    }
363
364
4.67k
    flag(chroma_loc_info_present_flag);
365
4.67k
    if (current->chroma_loc_info_present_flag) {
366
3.82k
        ue(chroma_sample_loc_type_top_field,    0, 5);
367
3.82k
        ue(chroma_sample_loc_type_bottom_field, 0, 5);
368
3.82k
    } else {
369
847
        infer(chroma_sample_loc_type_top_field,    0);
370
847
        infer(chroma_sample_loc_type_bottom_field, 0);
371
847
    }
372
373
4.67k
    flag(neutral_chroma_indication_flag);
374
4.67k
    flag(field_seq_flag);
375
4.67k
    flag(frame_field_info_present_flag);
376
377
4.67k
    flag(default_display_window_flag);
378
4.67k
    if (current->default_display_window_flag) {
379
3.50k
        ue(def_disp_win_left_offset,   0, 16384);
380
3.50k
        ue(def_disp_win_right_offset,  0, 16384);
381
3.50k
        ue(def_disp_win_top_offset,    0, 16384);
382
3.50k
        ue(def_disp_win_bottom_offset, 0, 16384);
383
3.50k
    }
384
385
4.67k
    flag(vui_timing_info_present_flag);
386
4.67k
    if (current->vui_timing_info_present_flag) {
387
1.88k
        u(32, vui_num_units_in_tick, 1, UINT32_MAX);
388
1.88k
        u(32, vui_time_scale,        1, UINT32_MAX);
389
1.88k
        flag(vui_poc_proportional_to_timing_flag);
390
1.88k
        if (current->vui_poc_proportional_to_timing_flag)
391
1.88k
            ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
392
393
1.88k
        flag(vui_hrd_parameters_present_flag);
394
1.88k
        if (current->vui_hrd_parameters_present_flag) {
395
1.65k
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters,
396
1.65k
                                       1, sps->sps_max_sub_layers_minus1));
397
1.65k
        }
398
1.88k
    }
399
400
4.67k
    flag(bitstream_restriction_flag);
401
4.67k
    if (current->bitstream_restriction_flag) {
402
4.31k
        flag(tiles_fixed_structure_flag);
403
4.31k
        flag(motion_vectors_over_pic_boundaries_flag);
404
4.31k
        flag(restricted_ref_pic_lists_flag);
405
4.31k
        ue(min_spatial_segmentation_idc,  0, 4095);
406
4.31k
        ue(max_bytes_per_pic_denom,       0, 16);
407
4.31k
        ue(max_bits_per_min_cu_denom,     0, 16);
408
4.31k
        ue(log2_max_mv_length_horizontal, 0, 16);
409
4.31k
        ue(log2_max_mv_length_vertical,   0, 16);
410
4.31k
    } else {
411
361
        infer(tiles_fixed_structure_flag,    0);
412
361
        infer(motion_vectors_over_pic_boundaries_flag, 1);
413
361
        infer(min_spatial_segmentation_idc,  0);
414
361
        infer(max_bytes_per_pic_denom,       2);
415
361
        infer(max_bits_per_min_cu_denom,     1);
416
361
        infer(log2_max_mv_length_horizontal, 15);
417
361
        infer(log2_max_mv_length_vertical,   15);
418
361
    }
419
420
4.67k
    return 0;
421
4.67k
}
422
423
static int FUNC(vps)(CodedBitstreamContext *ctx, RWContext *rw,
424
                     H265RawVPS *current)
425
78.4k
{
426
78.4k
    int err, i, j;
427
428
78.4k
    HEADER("Video Parameter Set");
429
430
78.4k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_VPS));
431
432
78.4k
    ub(4, vps_video_parameter_set_id);
433
434
77.8k
    flag(vps_base_layer_internal_flag);
435
77.8k
    flag(vps_base_layer_available_flag);
436
77.8k
    u(6, vps_max_layers_minus1,     0, HEVC_MAX_LAYERS - 1);
437
74.8k
    u(3, vps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
438
71.1k
    flag(vps_temporal_id_nesting_flag);
439
440
71.1k
    if (current->vps_max_sub_layers_minus1 == 0 &&
441
71.1k
        current->vps_temporal_id_nesting_flag != 1) {
442
2.75k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
443
2.75k
               "vps_temporal_id_nesting_flag must be 1 if "
444
2.75k
               "vps_max_sub_layers_minus1 is 0.\n");
445
2.75k
        return AVERROR_INVALIDDATA;
446
2.75k
    }
447
448
68.3k
    fixed(16, vps_reserved_0xffff_16bits, 0xffff);
449
450
58.2k
    CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
451
58.2k
                                   1, current->vps_max_sub_layers_minus1));
452
453
44.5k
    flag(vps_sub_layer_ordering_info_present_flag);
454
44.1k
    for (i = (current->vps_sub_layer_ordering_info_present_flag ?
455
30.0k
              0 : current->vps_max_sub_layers_minus1);
456
168k
         i <= current->vps_max_sub_layers_minus1; i++) {
457
127k
        ues(vps_max_dec_pic_buffering_minus1[i],
458
124k
            0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
459
124k
        ues(vps_max_num_reorder_pics[i],
460
124k
            0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
461
124k
        ues(vps_max_latency_increase_plus1[i],
462
124k
            0, UINT32_MAX - 1,                               1, i);
463
124k
    }
464
40.7k
    if (!current->vps_sub_layer_ordering_info_present_flag) {
465
46.3k
        for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
466
35.1k
            infer(vps_max_dec_pic_buffering_minus1[i],
467
35.1k
                  current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
468
35.1k
            infer(vps_max_num_reorder_pics[i],
469
9.57k
                  current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
470
35.1k
            infer(vps_max_latency_increase_plus1[i],
471
9.57k
                  current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
472
9.57k
        }
473
11.1k
    }
474
475
40.7k
    u(6, vps_max_layer_id,        0, HEVC_MAX_LAYERS - 1);
476
40.6k
    ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
477
395k
    for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
478
2.38M
        for (j = 0; j <= current->vps_max_layer_id; j++)
479
2.03M
            flags(layer_id_included_flag[i][j], 2, i, j);
480
356k
    }
481
621k
    for (j = 0; j <= current->vps_max_layer_id; j++)
482
582k
        infer(layer_id_included_flag[0][j], j == 0);
483
484
39.1k
    flag(vps_timing_info_present_flag);
485
38.8k
    if (current->vps_timing_info_present_flag) {
486
22.0k
        u(32, vps_num_units_in_tick, 1, UINT32_MAX);
487
21.6k
        u(32, vps_time_scale,        1, UINT32_MAX);
488
21.1k
        flag(vps_poc_proportional_to_timing_flag);
489
21.0k
        if (current->vps_poc_proportional_to_timing_flag)
490
21.0k
            ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
491
20.7k
        ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
492
26.7k
        for (i = 0; i < current->vps_num_hrd_parameters; i++) {
493
13.6k
            ues(hrd_layer_set_idx[i],
494
12.2k
                current->vps_base_layer_internal_flag ? 0 : 1,
495
12.2k
                current->vps_num_layer_sets_minus1, 1, i);
496
12.2k
            if (i > 0)
497
12.2k
                flags(cprms_present_flag[i], 1, i);
498
8.83k
            else
499
8.83k
                infer(cprms_present_flag[0], 1);
500
501
12.2k
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters[i],
502
12.2k
                                       current->cprms_present_flag[i],
503
12.2k
                                       current->vps_max_sub_layers_minus1));
504
12.2k
        }
505
19.9k
    }
506
507
29.8k
    flag(vps_extension_flag);
508
28.9k
    if (current->vps_extension_flag)
509
14.8k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
510
511
28.9k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
512
513
27.2k
    return 0;
514
28.9k
}
cbs_h2645.c:cbs_h265_read_vps
Line
Count
Source
425
72.5k
{
426
72.5k
    int err, i, j;
427
428
72.5k
    HEADER("Video Parameter Set");
429
430
72.5k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_VPS));
431
432
72.5k
    ub(4, vps_video_parameter_set_id);
433
434
71.9k
    flag(vps_base_layer_internal_flag);
435
71.9k
    flag(vps_base_layer_available_flag);
436
71.9k
    u(6, vps_max_layers_minus1,     0, HEVC_MAX_LAYERS - 1);
437
68.9k
    u(3, vps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
438
65.2k
    flag(vps_temporal_id_nesting_flag);
439
440
65.2k
    if (current->vps_max_sub_layers_minus1 == 0 &&
441
65.2k
        current->vps_temporal_id_nesting_flag != 1) {
442
2.75k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
443
2.75k
               "vps_temporal_id_nesting_flag must be 1 if "
444
2.75k
               "vps_max_sub_layers_minus1 is 0.\n");
445
2.75k
        return AVERROR_INVALIDDATA;
446
2.75k
    }
447
448
62.4k
    fixed(16, vps_reserved_0xffff_16bits, 0xffff);
449
450
52.3k
    CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
451
52.3k
                                   1, current->vps_max_sub_layers_minus1));
452
453
38.5k
    flag(vps_sub_layer_ordering_info_present_flag);
454
38.1k
    for (i = (current->vps_sub_layer_ordering_info_present_flag ?
455
27.0k
              0 : current->vps_max_sub_layers_minus1);
456
146k
         i <= current->vps_max_sub_layers_minus1; i++) {
457
112k
        ues(vps_max_dec_pic_buffering_minus1[i],
458
109k
            0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
459
109k
        ues(vps_max_num_reorder_pics[i],
460
109k
            0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
461
109k
        ues(vps_max_latency_increase_plus1[i],
462
109k
            0, UINT32_MAX - 1,                               1, i);
463
109k
    }
464
34.8k
    if (!current->vps_sub_layer_ordering_info_present_flag) {
465
33.8k
        for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
466
25.5k
            infer(vps_max_dec_pic_buffering_minus1[i],
467
25.5k
                  current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
468
25.5k
            infer(vps_max_num_reorder_pics[i],
469
25.5k
                  current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
470
25.5k
            infer(vps_max_latency_increase_plus1[i],
471
25.5k
                  current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
472
25.5k
        }
473
8.28k
    }
474
475
34.8k
    u(6, vps_max_layer_id,        0, HEVC_MAX_LAYERS - 1);
476
34.7k
    ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
477
333k
    for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
478
2.22M
        for (j = 0; j <= current->vps_max_layer_id; j++)
479
1.92M
            flags(layer_id_included_flag[i][j], 2, i, j);
480
300k
    }
481
495k
    for (j = 0; j <= current->vps_max_layer_id; j++)
482
462k
        infer(layer_id_included_flag[0][j], j == 0);
483
484
33.2k
    flag(vps_timing_info_present_flag);
485
32.9k
    if (current->vps_timing_info_present_flag) {
486
19.3k
        u(32, vps_num_units_in_tick, 1, UINT32_MAX);
487
18.9k
        u(32, vps_time_scale,        1, UINT32_MAX);
488
18.4k
        flag(vps_poc_proportional_to_timing_flag);
489
18.3k
        if (current->vps_poc_proportional_to_timing_flag)
490
18.3k
            ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
491
18.0k
        ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
492
23.7k
        for (i = 0; i < current->vps_num_hrd_parameters; i++) {
493
13.3k
            ues(hrd_layer_set_idx[i],
494
11.9k
                current->vps_base_layer_internal_flag ? 0 : 1,
495
11.9k
                current->vps_num_layer_sets_minus1, 1, i);
496
11.9k
            if (i > 0)
497
11.9k
                flags(cprms_present_flag[i], 1, i);
498
8.53k
            else
499
8.53k
                infer(cprms_present_flag[0], 1);
500
501
11.9k
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters[i],
502
11.9k
                                       current->cprms_present_flag[i],
503
11.9k
                                       current->vps_max_sub_layers_minus1));
504
11.9k
        }
505
17.2k
    }
506
507
23.9k
    flag(vps_extension_flag);
508
23.0k
    if (current->vps_extension_flag)
509
11.4k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
510
511
23.0k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
512
513
21.3k
    return 0;
514
23.0k
}
cbs_h2645.c:cbs_h265_write_vps
Line
Count
Source
425
5.92k
{
426
5.92k
    int err, i, j;
427
428
5.92k
    HEADER("Video Parameter Set");
429
430
5.92k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_VPS));
431
432
5.92k
    ub(4, vps_video_parameter_set_id);
433
434
5.92k
    flag(vps_base_layer_internal_flag);
435
5.92k
    flag(vps_base_layer_available_flag);
436
5.92k
    u(6, vps_max_layers_minus1,     0, HEVC_MAX_LAYERS - 1);
437
5.92k
    u(3, vps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
438
5.92k
    flag(vps_temporal_id_nesting_flag);
439
440
5.92k
    if (current->vps_max_sub_layers_minus1 == 0 &&
441
5.92k
        current->vps_temporal_id_nesting_flag != 1) {
442
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
443
0
               "vps_temporal_id_nesting_flag must be 1 if "
444
0
               "vps_max_sub_layers_minus1 is 0.\n");
445
0
        return AVERROR_INVALIDDATA;
446
0
    }
447
448
5.92k
    fixed(16, vps_reserved_0xffff_16bits, 0xffff);
449
450
5.92k
    CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
451
5.92k
                                   1, current->vps_max_sub_layers_minus1));
452
453
5.92k
    flag(vps_sub_layer_ordering_info_present_flag);
454
5.92k
    for (i = (current->vps_sub_layer_ordering_info_present_flag ?
455
3.03k
              0 : current->vps_max_sub_layers_minus1);
456
21.0k
         i <= current->vps_max_sub_layers_minus1; i++) {
457
15.1k
        ues(vps_max_dec_pic_buffering_minus1[i],
458
15.1k
            0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
459
15.1k
        ues(vps_max_num_reorder_pics[i],
460
15.1k
            0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
461
15.1k
        ues(vps_max_latency_increase_plus1[i],
462
15.1k
            0, UINT32_MAX - 1,                               1, i);
463
15.1k
    }
464
5.92k
    if (!current->vps_sub_layer_ordering_info_present_flag) {
465
12.4k
        for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
466
9.57k
            infer(vps_max_dec_pic_buffering_minus1[i],
467
9.57k
                  current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
468
9.57k
            infer(vps_max_num_reorder_pics[i],
469
9.57k
                  current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
470
9.57k
            infer(vps_max_latency_increase_plus1[i],
471
9.57k
                  current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
472
9.57k
        }
473
2.88k
    }
474
475
5.92k
    u(6, vps_max_layer_id,        0, HEVC_MAX_LAYERS - 1);
476
5.92k
    ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
477
61.8k
    for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
478
165k
        for (j = 0; j <= current->vps_max_layer_id; j++)
479
109k
            flags(layer_id_included_flag[i][j], 2, i, j);
480
55.8k
    }
481
125k
    for (j = 0; j <= current->vps_max_layer_id; j++)
482
119k
        infer(layer_id_included_flag[0][j], j == 0);
483
484
5.92k
    flag(vps_timing_info_present_flag);
485
5.92k
    if (current->vps_timing_info_present_flag) {
486
2.69k
        u(32, vps_num_units_in_tick, 1, UINT32_MAX);
487
2.69k
        u(32, vps_time_scale,        1, UINT32_MAX);
488
2.69k
        flag(vps_poc_proportional_to_timing_flag);
489
2.69k
        if (current->vps_poc_proportional_to_timing_flag)
490
2.69k
            ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
491
2.69k
        ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
492
2.99k
        for (i = 0; i < current->vps_num_hrd_parameters; i++) {
493
302
            ues(hrd_layer_set_idx[i],
494
302
                current->vps_base_layer_internal_flag ? 0 : 1,
495
302
                current->vps_num_layer_sets_minus1, 1, i);
496
302
            if (i > 0)
497
302
                flags(cprms_present_flag[i], 1, i);
498
300
            else
499
300
                infer(cprms_present_flag[0], 1);
500
501
302
            CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters[i],
502
302
                                       current->cprms_present_flag[i],
503
302
                                       current->vps_max_sub_layers_minus1));
504
302
        }
505
2.69k
    }
506
507
5.92k
    flag(vps_extension_flag);
508
5.92k
    if (current->vps_extension_flag)
509
3.36k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
510
511
5.92k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
512
513
5.92k
    return 0;
514
5.92k
}
515
516
static int FUNC(st_ref_pic_set)(CodedBitstreamContext *ctx, RWContext *rw,
517
                                H265RawSTRefPicSet *current, int st_rps_idx,
518
                                const H265RawSPS *sps)
519
1.02M
{
520
1.02M
    int err, i, j;
521
522
1.02M
    if (st_rps_idx != 0)
523
1.02M
        flag(inter_ref_pic_set_prediction_flag);
524
125k
    else
525
125k
        infer(inter_ref_pic_set_prediction_flag, 0);
526
527
1.02M
    if (current->inter_ref_pic_set_prediction_flag) {
528
688k
        unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
529
688k
        const H265RawSTRefPicSet *ref;
530
688k
        int delta_rps, d_poc;
531
688k
        int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
532
688k
        int delta_poc_s0[HEVC_MAX_REFS], delta_poc_s1[HEVC_MAX_REFS];
533
688k
        uint8_t used_by_curr_pic_s0[HEVC_MAX_REFS],
534
688k
                used_by_curr_pic_s1[HEVC_MAX_REFS];
535
536
688k
        if (st_rps_idx == sps->num_short_term_ref_pic_sets)
537
688k
            ue(delta_idx_minus1, 0, st_rps_idx - 1);
538
648k
        else
539
648k
            infer(delta_idx_minus1, 0);
540
541
687k
        ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
542
687k
        ref = &sps->st_ref_pic_set[ref_rps_idx];
543
687k
        num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
544
687k
        av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
545
546
687k
        flag(delta_rps_sign);
547
687k
        ue(abs_delta_rps_minus1, 0, INT16_MAX);
548
686k
        delta_rps = (1 - 2 * current->delta_rps_sign) *
549
686k
            (current->abs_delta_rps_minus1 + 1);
550
551
686k
        num_ref_pics = 0;
552
3.81M
        for (j = 0; j <= num_delta_pocs; j++) {
553
3.12M
            flags(used_by_curr_pic_flag[j], 1, j);
554
3.12M
            if (!current->used_by_curr_pic_flag[j])
555
3.12M
                flags(use_delta_flag[j], 1, j);
556
2.43M
            else
557
2.43M
                infer(use_delta_flag[j], 1);
558
3.12M
            if (current->use_delta_flag[j])
559
2.64M
                ++num_ref_pics;
560
3.12M
        }
561
682k
        if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
562
141
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
563
141
                   "short-term ref pic set %d "
564
141
                   "contains too many pictures.\n", st_rps_idx);
565
141
            return AVERROR_INVALIDDATA;
566
141
        }
567
568
        // Since the stored form of an RPS here is actually the delta-step
569
        // form used when inter_ref_pic_set_prediction_flag is not set, we
570
        // need to reconstruct that here in order to be able to refer to
571
        // the RPS later (which is required for parsing, because we don't
572
        // even know what syntax elements appear without it).  Therefore,
573
        // this code takes the delta-step form of the reference set, turns
574
        // it into the delta-array form, applies the prediction process of
575
        // 7.4.8, converts the result back to the delta-step form, and
576
        // stores that as the current set for future use.  Note that the
577
        // inferences here mean that writers using prediction will need
578
        // to fill in the delta-step values correctly as well - since the
579
        // whole RPS prediction process is somewhat overly sophisticated,
580
        // this hopefully forms a useful check for them to ensure their
581
        // predicted form actually matches what was intended rather than
582
        // an onerous additional requirement.
583
584
682k
        d_poc = 0;
585
2.72M
        for (i = 0; i < ref->num_negative_pics; i++) {
586
2.04M
            d_poc -= ref->delta_poc_s0_minus1[i] + 1;
587
2.04M
            ref_delta_poc_s0[i] = d_poc;
588
2.04M
        }
589
682k
        d_poc = 0;
590
1.07M
        for (i = 0; i < ref->num_positive_pics; i++) {
591
392k
            d_poc += ref->delta_poc_s1_minus1[i] + 1;
592
392k
            ref_delta_poc_s1[i] = d_poc;
593
392k
        }
594
595
682k
        i = 0;
596
1.07M
        for (j = ref->num_positive_pics - 1; j >= 0; j--) {
597
392k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
598
392k
            if (d_poc < 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
599
39.8k
                delta_poc_s0[i] = d_poc;
600
39.8k
                used_by_curr_pic_s0[i++] =
601
39.8k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
602
39.8k
            }
603
392k
        }
604
682k
        if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
605
502k
            delta_poc_s0[i] = delta_rps;
606
502k
            used_by_curr_pic_s0[i++] =
607
502k
                current->used_by_curr_pic_flag[num_delta_pocs];
608
502k
        }
609
2.72M
        for (j = 0; j < ref->num_negative_pics; j++) {
610
2.04M
            d_poc = ref_delta_poc_s0[j] + delta_rps;
611
2.04M
            if (d_poc < 0 && current->use_delta_flag[j]) {
612
1.64M
                delta_poc_s0[i] = d_poc;
613
1.64M
                used_by_curr_pic_s0[i++] = current->used_by_curr_pic_flag[j];
614
1.64M
            }
615
2.04M
        }
616
617
682k
        infer(num_negative_pics, i);
618
2.86M
        for (i = 0; i < current->num_negative_pics; i++) {
619
2.18M
            infer(delta_poc_s0_minus1[i],
620
2.18M
                  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
621
2.18M
            infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
622
332k
        }
623
624
100k
        i = 0;
625
2.71M
        for (j = ref->num_negative_pics - 1; j >= 0; j--) {
626
2.03M
            d_poc = ref_delta_poc_s0[j] + delta_rps;
627
2.03M
            if (d_poc > 0 && current->use_delta_flag[j]) {
628
15.4k
                delta_poc_s1[i] = d_poc;
629
15.4k
                used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
630
15.4k
            }
631
2.03M
        }
632
681k
        if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
633
112k
            delta_poc_s1[i] = delta_rps;
634
112k
            used_by_curr_pic_s1[i++] =
635
112k
                current->used_by_curr_pic_flag[num_delta_pocs];
636
112k
        }
637
1.07M
        for (j = 0; j < ref->num_positive_pics; j++) {
638
391k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
639
391k
            if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
640
269k
                delta_poc_s1[i] = d_poc;
641
269k
                used_by_curr_pic_s1[i++] =
642
269k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
643
269k
            }
644
391k
        }
645
646
681k
        infer(num_positive_pics, i);
647
1.07M
        for (i = 0; i < current->num_positive_pics; i++) {
648
396k
            infer(delta_poc_s1_minus1[i],
649
396k
                  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
650
396k
            infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
651
31.5k
        }
652
653
339k
    } else {
654
339k
        ue(num_negative_pics, 0, 15);
655
329k
        ue(num_positive_pics, 0, 15 - current->num_negative_pics);
656
657
748k
        for (i = 0; i < current->num_negative_pics; i++) {
658
427k
            ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
659
426k
            flags(used_by_curr_pic_s0_flag[i],        1, i);
660
426k
        }
661
662
569k
        for (i = 0; i < current->num_positive_pics; i++) {
663
252k
            ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
664
249k
            flags(used_by_curr_pic_s1_flag[i],        1, i);
665
249k
        }
666
321k
    }
667
668
998k
    return 0;
669
1.02M
}
cbs_h2645.c:cbs_h265_read_st_ref_pic_set
Line
Count
Source
519
887k
{
520
887k
    int err, i, j;
521
522
887k
    if (st_rps_idx != 0)
523
887k
        flag(inter_ref_pic_set_prediction_flag);
524
113k
    else
525
113k
        infer(inter_ref_pic_set_prediction_flag, 0);
526
527
886k
    if (current->inter_ref_pic_set_prediction_flag) {
528
586k
        unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
529
586k
        const H265RawSTRefPicSet *ref;
530
586k
        int delta_rps, d_poc;
531
586k
        int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
532
586k
        int delta_poc_s0[HEVC_MAX_REFS], delta_poc_s1[HEVC_MAX_REFS];
533
586k
        uint8_t used_by_curr_pic_s0[HEVC_MAX_REFS],
534
586k
                used_by_curr_pic_s1[HEVC_MAX_REFS];
535
536
586k
        if (st_rps_idx == sps->num_short_term_ref_pic_sets)
537
586k
            ue(delta_idx_minus1, 0, st_rps_idx - 1);
538
548k
        else
539
548k
            infer(delta_idx_minus1, 0);
540
541
585k
        ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
542
585k
        ref = &sps->st_ref_pic_set[ref_rps_idx];
543
585k
        num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
544
585k
        av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
545
546
585k
        flag(delta_rps_sign);
547
585k
        ue(abs_delta_rps_minus1, 0, INT16_MAX);
548
584k
        delta_rps = (1 - 2 * current->delta_rps_sign) *
549
584k
            (current->abs_delta_rps_minus1 + 1);
550
551
584k
        num_ref_pics = 0;
552
3.26M
        for (j = 0; j <= num_delta_pocs; j++) {
553
2.68M
            flags(used_by_curr_pic_flag[j], 1, j);
554
2.68M
            if (!current->used_by_curr_pic_flag[j])
555
2.68M
                flags(use_delta_flag[j], 1, j);
556
2.08M
            else
557
2.08M
                infer(use_delta_flag[j], 1);
558
2.67M
            if (current->use_delta_flag[j])
559
2.27M
                ++num_ref_pics;
560
2.67M
        }
561
580k
        if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
562
141
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
563
141
                   "short-term ref pic set %d "
564
141
                   "contains too many pictures.\n", st_rps_idx);
565
141
            return AVERROR_INVALIDDATA;
566
141
        }
567
568
        // Since the stored form of an RPS here is actually the delta-step
569
        // form used when inter_ref_pic_set_prediction_flag is not set, we
570
        // need to reconstruct that here in order to be able to refer to
571
        // the RPS later (which is required for parsing, because we don't
572
        // even know what syntax elements appear without it).  Therefore,
573
        // this code takes the delta-step form of the reference set, turns
574
        // it into the delta-array form, applies the prediction process of
575
        // 7.4.8, converts the result back to the delta-step form, and
576
        // stores that as the current set for future use.  Note that the
577
        // inferences here mean that writers using prediction will need
578
        // to fill in the delta-step values correctly as well - since the
579
        // whole RPS prediction process is somewhat overly sophisticated,
580
        // this hopefully forms a useful check for them to ensure their
581
        // predicted form actually matches what was intended rather than
582
        // an onerous additional requirement.
583
584
580k
        d_poc = 0;
585
2.31M
        for (i = 0; i < ref->num_negative_pics; i++) {
586
1.73M
            d_poc -= ref->delta_poc_s0_minus1[i] + 1;
587
1.73M
            ref_delta_poc_s0[i] = d_poc;
588
1.73M
        }
589
580k
        d_poc = 0;
590
940k
        for (i = 0; i < ref->num_positive_pics; i++) {
591
360k
            d_poc += ref->delta_poc_s1_minus1[i] + 1;
592
360k
            ref_delta_poc_s1[i] = d_poc;
593
360k
        }
594
595
580k
        i = 0;
596
940k
        for (j = ref->num_positive_pics - 1; j >= 0; j--) {
597
360k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
598
360k
            if (d_poc < 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
599
33.5k
                delta_poc_s0[i] = d_poc;
600
33.5k
                used_by_curr_pic_s0[i++] =
601
33.5k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
602
33.5k
            }
603
360k
        }
604
580k
        if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
605
417k
            delta_poc_s0[i] = delta_rps;
606
417k
            used_by_curr_pic_s0[i++] =
607
417k
                current->used_by_curr_pic_flag[num_delta_pocs];
608
417k
        }
609
2.31M
        for (j = 0; j < ref->num_negative_pics; j++) {
610
1.73M
            d_poc = ref_delta_poc_s0[j] + delta_rps;
611
1.73M
            if (d_poc < 0 && current->use_delta_flag[j]) {
612
1.40M
                delta_poc_s0[i] = d_poc;
613
1.40M
                used_by_curr_pic_s0[i++] = current->used_by_curr_pic_flag[j];
614
1.40M
            }
615
1.73M
        }
616
617
580k
        infer(num_negative_pics, i);
618
2.43M
        for (i = 0; i < current->num_negative_pics; i++) {
619
1.85M
            infer(delta_poc_s0_minus1[i],
620
1.85M
                  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
621
1.85M
            infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
622
1.85M
        }
623
624
580k
        i = 0;
625
2.31M
        for (j = ref->num_negative_pics - 1; j >= 0; j--) {
626
1.73M
            d_poc = ref_delta_poc_s0[j] + delta_rps;
627
1.73M
            if (d_poc > 0 && current->use_delta_flag[j]) {
628
14.3k
                delta_poc_s1[i] = d_poc;
629
14.3k
                used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
630
14.3k
            }
631
1.73M
        }
632
580k
        if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
633
99.9k
            delta_poc_s1[i] = delta_rps;
634
99.9k
            used_by_curr_pic_s1[i++] =
635
99.9k
                current->used_by_curr_pic_flag[num_delta_pocs];
636
99.9k
        }
637
940k
        for (j = 0; j < ref->num_positive_pics; j++) {
638
360k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
639
360k
            if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
640
250k
                delta_poc_s1[i] = d_poc;
641
250k
                used_by_curr_pic_s1[i++] =
642
250k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
643
250k
            }
644
360k
        }
645
646
580k
        infer(num_positive_pics, i);
647
946k
        for (i = 0; i < current->num_positive_pics; i++) {
648
365k
            infer(delta_poc_s1_minus1[i],
649
365k
                  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
650
365k
            infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
651
365k
        }
652
653
580k
    } else {
654
299k
        ue(num_negative_pics, 0, 15);
655
289k
        ue(num_positive_pics, 0, 15 - current->num_negative_pics);
656
657
651k
        for (i = 0; i < current->num_negative_pics; i++) {
658
370k
            ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
659
369k
            flags(used_by_curr_pic_s0_flag[i],        1, i);
660
369k
        }
661
662
512k
        for (i = 0; i < current->num_positive_pics; i++) {
663
235k
            ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
664
232k
            flags(used_by_curr_pic_s1_flag[i],        1, i);
665
232k
        }
666
281k
    }
667
668
857k
    return 0;
669
886k
}
cbs_h2645.c:cbs_h265_write_st_ref_pic_set
Line
Count
Source
519
141k
{
520
141k
    int err, i, j;
521
522
141k
    if (st_rps_idx != 0)
523
141k
        flag(inter_ref_pic_set_prediction_flag);
524
11.5k
    else
525
11.5k
        infer(inter_ref_pic_set_prediction_flag, 0);
526
527
141k
    if (current->inter_ref_pic_set_prediction_flag) {
528
101k
        unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
529
101k
        const H265RawSTRefPicSet *ref;
530
101k
        int delta_rps, d_poc;
531
101k
        int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
532
101k
        int delta_poc_s0[HEVC_MAX_REFS], delta_poc_s1[HEVC_MAX_REFS];
533
101k
        uint8_t used_by_curr_pic_s0[HEVC_MAX_REFS],
534
101k
                used_by_curr_pic_s1[HEVC_MAX_REFS];
535
536
101k
        if (st_rps_idx == sps->num_short_term_ref_pic_sets)
537
101k
            ue(delta_idx_minus1, 0, st_rps_idx - 1);
538
99.5k
        else
539
99.5k
            infer(delta_idx_minus1, 0);
540
541
101k
        ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
542
101k
        ref = &sps->st_ref_pic_set[ref_rps_idx];
543
101k
        num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
544
101k
        av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
545
546
101k
        flag(delta_rps_sign);
547
101k
        ue(abs_delta_rps_minus1, 0, INT16_MAX);
548
101k
        delta_rps = (1 - 2 * current->delta_rps_sign) *
549
101k
            (current->abs_delta_rps_minus1 + 1);
550
551
101k
        num_ref_pics = 0;
552
546k
        for (j = 0; j <= num_delta_pocs; j++) {
553
444k
            flags(used_by_curr_pic_flag[j], 1, j);
554
444k
            if (!current->used_by_curr_pic_flag[j])
555
444k
                flags(use_delta_flag[j], 1, j);
556
349k
            else
557
349k
                infer(use_delta_flag[j], 1);
558
444k
            if (current->use_delta_flag[j])
559
372k
                ++num_ref_pics;
560
444k
        }
561
101k
        if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
562
0
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
563
0
                   "short-term ref pic set %d "
564
0
                   "contains too many pictures.\n", st_rps_idx);
565
0
            return AVERROR_INVALIDDATA;
566
0
        }
567
568
        // Since the stored form of an RPS here is actually the delta-step
569
        // form used when inter_ref_pic_set_prediction_flag is not set, we
570
        // need to reconstruct that here in order to be able to refer to
571
        // the RPS later (which is required for parsing, because we don't
572
        // even know what syntax elements appear without it).  Therefore,
573
        // this code takes the delta-step form of the reference set, turns
574
        // it into the delta-array form, applies the prediction process of
575
        // 7.4.8, converts the result back to the delta-step form, and
576
        // stores that as the current set for future use.  Note that the
577
        // inferences here mean that writers using prediction will need
578
        // to fill in the delta-step values correctly as well - since the
579
        // whole RPS prediction process is somewhat overly sophisticated,
580
        // this hopefully forms a useful check for them to ensure their
581
        // predicted form actually matches what was intended rather than
582
        // an onerous additional requirement.
583
584
101k
        d_poc = 0;
585
412k
        for (i = 0; i < ref->num_negative_pics; i++) {
586
310k
            d_poc -= ref->delta_poc_s0_minus1[i] + 1;
587
310k
            ref_delta_poc_s0[i] = d_poc;
588
310k
        }
589
101k
        d_poc = 0;
590
134k
        for (i = 0; i < ref->num_positive_pics; i++) {
591
32.2k
            d_poc += ref->delta_poc_s1_minus1[i] + 1;
592
32.2k
            ref_delta_poc_s1[i] = d_poc;
593
32.2k
        }
594
595
101k
        i = 0;
596
134k
        for (j = ref->num_positive_pics - 1; j >= 0; j--) {
597
32.2k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
598
32.2k
            if (d_poc < 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
599
6.38k
                delta_poc_s0[i] = d_poc;
600
6.38k
                used_by_curr_pic_s0[i++] =
601
6.38k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
602
6.38k
            }
603
32.2k
        }
604
101k
        if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
605
85.2k
            delta_poc_s0[i] = delta_rps;
606
85.2k
            used_by_curr_pic_s0[i++] =
607
85.2k
                current->used_by_curr_pic_flag[num_delta_pocs];
608
85.2k
        }
609
412k
        for (j = 0; j < ref->num_negative_pics; j++) {
610
310k
            d_poc = ref_delta_poc_s0[j] + delta_rps;
611
310k
            if (d_poc < 0 && current->use_delta_flag[j]) {
612
242k
                delta_poc_s0[i] = d_poc;
613
242k
                used_by_curr_pic_s0[i++] = current->used_by_curr_pic_flag[j];
614
242k
            }
615
310k
        }
616
617
101k
        infer(num_negative_pics, i);
618
434k
        for (i = 0; i < current->num_negative_pics; i++) {
619
333k
            infer(delta_poc_s0_minus1[i],
620
333k
                  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
621
332k
            infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
622
332k
        }
623
624
100k
        i = 0;
625
404k
        for (j = ref->num_negative_pics - 1; j >= 0; j--) {
626
304k
            d_poc = ref_delta_poc_s0[j] + delta_rps;
627
304k
            if (d_poc > 0 && current->use_delta_flag[j]) {
628
1.11k
                delta_poc_s1[i] = d_poc;
629
1.11k
                used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
630
1.11k
            }
631
304k
        }
632
100k
        if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
633
12.1k
            delta_poc_s1[i] = delta_rps;
634
12.1k
            used_by_curr_pic_s1[i++] =
635
12.1k
                current->used_by_curr_pic_flag[num_delta_pocs];
636
12.1k
        }
637
131k
        for (j = 0; j < ref->num_positive_pics; j++) {
638
31.1k
            d_poc = ref_delta_poc_s1[j] + delta_rps;
639
31.1k
            if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
640
18.7k
                delta_poc_s1[i] = d_poc;
641
18.7k
                used_by_curr_pic_s1[i++] =
642
18.7k
                    current->used_by_curr_pic_flag[ref->num_negative_pics + j];
643
18.7k
            }
644
31.1k
        }
645
646
100k
        infer(num_positive_pics, i);
647
131k
        for (i = 0; i < current->num_positive_pics; i++) {
648
31.5k
            infer(delta_poc_s1_minus1[i],
649
31.5k
                  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
650
31.5k
            infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
651
31.5k
        }
652
653
100k
    } else {
654
40.0k
        ue(num_negative_pics, 0, 15);
655
40.0k
        ue(num_positive_pics, 0, 15 - current->num_negative_pics);
656
657
96.7k
        for (i = 0; i < current->num_negative_pics; i++) {
658
56.7k
            ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
659
56.7k
            flags(used_by_curr_pic_s0_flag[i],        1, i);
660
56.7k
        }
661
662
57.0k
        for (i = 0; i < current->num_positive_pics; i++) {
663
17.0k
            ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
664
17.0k
            flags(used_by_curr_pic_s1_flag[i],        1, i);
665
17.0k
        }
666
40.0k
    }
667
668
140k
    return 0;
669
141k
}
670
671
static int FUNC(scaling_list_data)(CodedBitstreamContext *ctx, RWContext *rw,
672
                                   H265RawScalingList *current)
673
26.0k
{
674
26.0k
    int sizeId, matrixId;
675
26.0k
    int err, n, i;
676
677
66.4k
    for (sizeId = 0; sizeId < 4; sizeId++) {
678
292k
        for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
679
251k
            flags(scaling_list_pred_mode_flag[sizeId][matrixId],
680
248k
                  2, sizeId, matrixId);
681
248k
            if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
682
123k
                ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
683
123k
                    0, sizeId == 3 ? matrixId / 3 : matrixId,
684
123k
                    2, sizeId, matrixId);
685
125k
            } else {
686
125k
                n = FFMIN(64, 1 << (4 + (sizeId << 1)));
687
125k
                if (sizeId > 1) {
688
33.0k
                    ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
689
33.0k
                        2, sizeId - 2, matrixId);
690
33.0k
                }
691
5.03M
                for (i = 0; i < n; i++) {
692
4.91M
                    ses(scaling_list_delta_coeff[sizeId][matrixId][i],
693
4.91M
                        -128, +127, 3, sizeId, matrixId, i);
694
4.91M
                }
695
124k
            }
696
248k
        }
697
58.1k
    }
698
699
8.34k
    return 0;
700
26.0k
}
cbs_h2645.c:cbs_h265_read_scaling_list_data
Line
Count
Source
673
23.9k
{
674
23.9k
    int sizeId, matrixId;
675
23.9k
    int err, n, i;
676
677
56.2k
    for (sizeId = 0; sizeId < 4; sizeId++) {
678
243k
        for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
679
210k
            flags(scaling_list_pred_mode_flag[sizeId][matrixId],
680
207k
                  2, sizeId, matrixId);
681
207k
            if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
682
99.1k
                ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
683
99.1k
                    0, sizeId == 3 ? matrixId / 3 : matrixId,
684
99.1k
                    2, sizeId, matrixId);
685
108k
            } else {
686
108k
                n = FFMIN(64, 1 << (4 + (sizeId << 1)));
687
108k
                if (sizeId > 1) {
688
26.2k
                    ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
689
26.2k
                        2, sizeId - 2, matrixId);
690
26.2k
                }
691
4.25M
                for (i = 0; i < n; i++) {
692
4.15M
                    ses(scaling_list_delta_coeff[sizeId][matrixId][i],
693
4.15M
                        -128, +127, 3, sizeId, matrixId, i);
694
4.15M
                }
695
107k
            }
696
207k
        }
697
49.9k
    }
698
699
6.29k
    return 0;
700
23.9k
}
cbs_h2645.c:cbs_h265_write_scaling_list_data
Line
Count
Source
673
2.05k
{
674
2.05k
    int sizeId, matrixId;
675
2.05k
    int err, n, i;
676
677
10.2k
    for (sizeId = 0; sizeId < 4; sizeId++) {
678
49.2k
        for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
679
41.0k
            flags(scaling_list_pred_mode_flag[sizeId][matrixId],
680
41.0k
                  2, sizeId, matrixId);
681
41.0k
            if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
682
24.3k
                ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
683
24.3k
                    0, sizeId == 3 ? matrixId / 3 : matrixId,
684
24.3k
                    2, sizeId, matrixId);
685
24.3k
            } else {
686
16.6k
                n = FFMIN(64, 1 << (4 + (sizeId << 1)));
687
16.6k
                if (sizeId > 1) {
688
6.80k
                    ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
689
6.80k
                        2, sizeId - 2, matrixId);
690
6.80k
                }
691
784k
                for (i = 0; i < n; i++) {
692
767k
                    ses(scaling_list_delta_coeff[sizeId][matrixId][i],
693
767k
                        -128, +127, 3, sizeId, matrixId, i);
694
767k
                }
695
16.6k
            }
696
41.0k
        }
697
8.20k
    }
698
699
2.05k
    return 0;
700
2.05k
}
701
702
static int FUNC(sps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw,
703
                                     H265RawSPS *current)
704
20.8k
{
705
20.8k
    int err;
706
707
20.8k
    flag(transform_skip_rotation_enabled_flag);
708
20.8k
    flag(transform_skip_context_enabled_flag);
709
19.8k
    flag(implicit_rdpcm_enabled_flag);
710
19.6k
    flag(explicit_rdpcm_enabled_flag);
711
18.1k
    flag(extended_precision_processing_flag);
712
17.8k
    flag(intra_smoothing_disabled_flag);
713
17.5k
    flag(high_precision_offsets_enabled_flag);
714
17.1k
    flag(persistent_rice_adaptation_enabled_flag);
715
16.7k
    flag(cabac_bypass_alignment_enabled_flag);
716
717
16.5k
    return 0;
718
16.7k
}
cbs_h2645.c:cbs_h265_read_sps_range_extension
Line
Count
Source
704
19.5k
{
705
19.5k
    int err;
706
707
19.5k
    flag(transform_skip_rotation_enabled_flag);
708
19.5k
    flag(transform_skip_context_enabled_flag);
709
18.5k
    flag(implicit_rdpcm_enabled_flag);
710
18.3k
    flag(explicit_rdpcm_enabled_flag);
711
16.8k
    flag(extended_precision_processing_flag);
712
16.5k
    flag(intra_smoothing_disabled_flag);
713
16.3k
    flag(high_precision_offsets_enabled_flag);
714
15.8k
    flag(persistent_rice_adaptation_enabled_flag);
715
15.4k
    flag(cabac_bypass_alignment_enabled_flag);
716
717
15.2k
    return 0;
718
15.4k
}
cbs_h2645.c:cbs_h265_write_sps_range_extension
Line
Count
Source
704
1.29k
{
705
1.29k
    int err;
706
707
1.29k
    flag(transform_skip_rotation_enabled_flag);
708
1.29k
    flag(transform_skip_context_enabled_flag);
709
1.29k
    flag(implicit_rdpcm_enabled_flag);
710
1.29k
    flag(explicit_rdpcm_enabled_flag);
711
1.29k
    flag(extended_precision_processing_flag);
712
1.29k
    flag(intra_smoothing_disabled_flag);
713
1.29k
    flag(high_precision_offsets_enabled_flag);
714
1.29k
    flag(persistent_rice_adaptation_enabled_flag);
715
1.29k
    flag(cabac_bypass_alignment_enabled_flag);
716
717
1.29k
    return 0;
718
1.29k
}
719
720
static int FUNC(sps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw,
721
                                   H265RawSPS *current)
722
11.3k
{
723
11.3k
    int err, comp, i;
724
725
11.3k
    flag(sps_curr_pic_ref_enabled_flag);
726
727
10.2k
    flag(palette_mode_enabled_flag);
728
10.2k
    if (current->palette_mode_enabled_flag) {
729
3.89k
        ue(palette_max_size, 0, 64);
730
3.81k
        ue(delta_palette_max_predictor_size, 0, 128);
731
732
3.67k
        flag(sps_palette_predictor_initializer_present_flag);
733
3.47k
        if (current->sps_palette_predictor_initializer_present_flag) {
734
2.31k
            ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
735
5.97k
            for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
736
5.08k
                int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
737
5.08k
                                          : current->bit_depth_chroma_minus8 + 8;
738
48.5k
                for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
739
44.4k
                    ubs(bit_depth, sps_palette_predictor_initializers[comp][i], 2, comp, i);
740
5.08k
            }
741
1.95k
        }
742
3.47k
    }
743
744
8.42k
    u(2, motion_vector_resolution_control_idc, 0, 2);
745
6.81k
    flag(intra_boundary_filtering_disable_flag);
746
747
6.80k
    return 0;
748
6.81k
}
cbs_h2645.c:cbs_h265_read_sps_scc_extension
Line
Count
Source
722
10.3k
{
723
10.3k
    int err, comp, i;
724
725
10.3k
    flag(sps_curr_pic_ref_enabled_flag);
726
727
9.26k
    flag(palette_mode_enabled_flag);
728
9.23k
    if (current->palette_mode_enabled_flag) {
729
3.82k
        ue(palette_max_size, 0, 64);
730
3.73k
        ue(delta_palette_max_predictor_size, 0, 128);
731
732
3.60k
        flag(sps_palette_predictor_initializer_present_flag);
733
3.40k
        if (current->sps_palette_predictor_initializer_present_flag) {
734
2.27k
            ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
735
5.81k
            for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
736
4.97k
                int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
737
4.97k
                                          : current->bit_depth_chroma_minus8 + 8;
738
47.2k
                for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
739
43.3k
                    ubs(bit_depth, sps_palette_predictor_initializers[comp][i], 2, comp, i);
740
4.97k
            }
741
1.91k
        }
742
3.40k
    }
743
744
7.39k
    u(2, motion_vector_resolution_control_idc, 0, 2);
745
5.77k
    flag(intra_boundary_filtering_disable_flag);
746
747
5.77k
    return 0;
748
5.77k
}
cbs_h2645.c:cbs_h265_write_sps_scc_extension
Line
Count
Source
722
1.03k
{
723
1.03k
    int err, comp, i;
724
725
1.03k
    flag(sps_curr_pic_ref_enabled_flag);
726
727
1.03k
    flag(palette_mode_enabled_flag);
728
1.03k
    if (current->palette_mode_enabled_flag) {
729
72
        ue(palette_max_size, 0, 64);
730
72
        ue(delta_palette_max_predictor_size, 0, 128);
731
732
72
        flag(sps_palette_predictor_initializer_present_flag);
733
72
        if (current->sps_palette_predictor_initializer_present_flag) {
734
39
            ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
735
152
            for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
736
113
                int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
737
113
                                          : current->bit_depth_chroma_minus8 + 8;
738
1.23k
                for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
739
1.12k
                    ubs(bit_depth, sps_palette_predictor_initializers[comp][i], 2, comp, i);
740
113
            }
741
39
        }
742
72
    }
743
744
1.03k
    u(2, motion_vector_resolution_control_idc, 0, 2);
745
1.03k
    flag(intra_boundary_filtering_disable_flag);
746
747
1.03k
    return 0;
748
1.03k
}
749
750
static int FUNC(sps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw,
751
                                          H265RawSPS *current)
752
3.28k
{
753
3.28k
    int err;
754
755
3.28k
    flag(inter_view_mv_vert_constraint_flag);
756
757
3.24k
    return 0;
758
3.28k
}
cbs_h2645.c:cbs_h265_read_sps_multilayer_extension
Line
Count
Source
752
2.90k
{
753
2.90k
    int err;
754
755
2.90k
    flag(inter_view_mv_vert_constraint_flag);
756
757
2.87k
    return 0;
758
2.90k
}
cbs_h2645.c:cbs_h265_write_sps_multilayer_extension
Line
Count
Source
752
376
{
753
376
    int err;
754
755
376
    flag(inter_view_mv_vert_constraint_flag);
756
757
376
    return 0;
758
376
}
759
760
static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx,
761
                                        RWContext *rw, H265RawVUI *current,
762
                                        H265RawSPS *sps)
763
37.0k
{
764
37.0k
    infer(aspect_ratio_idc, 0);
765
766
37.0k
    infer(video_format,             5);
767
37.0k
    infer(video_full_range_flag,    0);
768
37.0k
    infer(colour_primaries,         2);
769
37.0k
    infer(transfer_characteristics, 2);
770
37.0k
    infer(matrix_coefficients,      2);
771
772
37.0k
    infer(chroma_sample_loc_type_top_field,    0);
773
37.0k
    infer(chroma_sample_loc_type_bottom_field, 0);
774
775
37.0k
    infer(tiles_fixed_structure_flag,    0);
776
37.0k
    infer(motion_vectors_over_pic_boundaries_flag, 1);
777
37.0k
    infer(min_spatial_segmentation_idc,  0);
778
37.0k
    infer(max_bytes_per_pic_denom,       2);
779
37.0k
    infer(max_bits_per_min_cu_denom,     1);
780
37.0k
    infer(log2_max_mv_length_horizontal, 15);
781
37.0k
    infer(log2_max_mv_length_vertical,   15);
782
783
7.81k
    return 0;
784
7.81k
}
cbs_h2645.c:cbs_h265_read_vui_parameters_default
Line
Count
Source
763
29.2k
{
764
29.2k
    infer(aspect_ratio_idc, 0);
765
766
29.2k
    infer(video_format,             5);
767
29.2k
    infer(video_full_range_flag,    0);
768
29.2k
    infer(colour_primaries,         2);
769
29.2k
    infer(transfer_characteristics, 2);
770
29.2k
    infer(matrix_coefficients,      2);
771
772
29.2k
    infer(chroma_sample_loc_type_top_field,    0);
773
29.2k
    infer(chroma_sample_loc_type_bottom_field, 0);
774
775
29.2k
    infer(tiles_fixed_structure_flag,    0);
776
29.2k
    infer(motion_vectors_over_pic_boundaries_flag, 1);
777
29.2k
    infer(min_spatial_segmentation_idc,  0);
778
29.2k
    infer(max_bytes_per_pic_denom,       2);
779
29.2k
    infer(max_bits_per_min_cu_denom,     1);
780
29.2k
    infer(log2_max_mv_length_horizontal, 15);
781
29.2k
    infer(log2_max_mv_length_vertical,   15);
782
783
29.2k
    return 0;
784
29.2k
}
cbs_h2645.c:cbs_h265_write_vui_parameters_default
Line
Count
Source
763
7.81k
{
764
7.81k
    infer(aspect_ratio_idc, 0);
765
766
7.81k
    infer(video_format,             5);
767
7.81k
    infer(video_full_range_flag,    0);
768
7.81k
    infer(colour_primaries,         2);
769
7.81k
    infer(transfer_characteristics, 2);
770
7.81k
    infer(matrix_coefficients,      2);
771
772
7.81k
    infer(chroma_sample_loc_type_top_field,    0);
773
7.81k
    infer(chroma_sample_loc_type_bottom_field, 0);
774
775
7.81k
    infer(tiles_fixed_structure_flag,    0);
776
7.81k
    infer(motion_vectors_over_pic_boundaries_flag, 1);
777
7.81k
    infer(min_spatial_segmentation_idc,  0);
778
7.81k
    infer(max_bytes_per_pic_denom,       2);
779
7.81k
    infer(max_bits_per_min_cu_denom,     1);
780
7.81k
    infer(log2_max_mv_length_horizontal, 15);
781
7.81k
    infer(log2_max_mv_length_vertical,   15);
782
783
7.81k
    return 0;
784
7.81k
}
785
786
static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
787
                     H265RawSPS *current)
788
288k
{
789
288k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
790
288k
    const H265RawVPS *vps;
791
288k
    int err, i;
792
288k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y,
793
288k
                 min_cb_size_y,   min_tb_log2_size_y;
794
288k
    unsigned int multi_layer_ext_sps_flag;
795
796
288k
    HEADER("Sequence Parameter Set");
797
798
288k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
799
800
288k
    ub(4, sps_video_parameter_set_id);
801
286k
    h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
802
286k
    if (!vps) {
803
51.9k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
804
51.9k
               current->sps_video_parameter_set_id);
805
51.9k
        return AVERROR_INVALIDDATA;
806
51.9k
    }
807
808
234k
    if (current->nal_unit_header.nuh_layer_id == 0)
809
234k
        u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1);
810
5.00k
    else {
811
5.00k
        u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS);
812
5.00k
        infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS
813
5.00k
                                         ? vps->vps_max_sub_layers_minus1
814
5.00k
                                         : current->sps_ext_or_max_sub_layers_minus1);
815
5.00k
    }
816
228k
    multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id &&
817
228k
                               current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS;
818
228k
    if (!multi_layer_ext_sps_flag) {
819
227k
        flag(sps_temporal_id_nesting_flag);
820
821
227k
        if (vps->vps_temporal_id_nesting_flag &&
822
227k
            !current->sps_temporal_id_nesting_flag) {
823
5.68k
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
824
5.68k
                   "sps_temporal_id_nesting_flag must be 1 if "
825
5.68k
                   "vps_temporal_id_nesting_flag is 1.\n");
826
5.68k
            return AVERROR_INVALIDDATA;
827
5.68k
        }
828
221k
        if (current->sps_max_sub_layers_minus1 == 0 &&
829
221k
            current->sps_temporal_id_nesting_flag != 1) {
830
567
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
831
567
                   "sps_temporal_id_nesting_flag must be 1 if "
832
567
                   "sps_max_sub_layers_minus1 is 0.\n");
833
567
            return AVERROR_INVALIDDATA;
834
567
        }
835
836
221k
        CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
837
221k
                                       1, current->sps_max_sub_layers_minus1));
838
221k
    } else {
839
1.32k
        if (current->sps_max_sub_layers_minus1 > 0)
840
877
            infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag);
841
444
        else
842
444
            infer(sps_temporal_id_nesting_flag, 1);
843
1.32k
    }
844
845
160k
    ue(sps_seq_parameter_set_id, 0, 15);
846
847
158k
    if (multi_layer_ext_sps_flag) {
848
1.27k
        flag(update_rep_format_flag);
849
1.27k
        if (current->update_rep_format_flag)
850
996
            ub(8, sps_rep_format_idx);
851
157k
    } else {
852
157k
        ue(chroma_format_idc, 0, 3);
853
157k
        if (current->chroma_format_idc == 3)
854
157k
            flag(separate_colour_plane_flag);
855
106k
        else
856
106k
            infer(separate_colour_plane_flag, 0);
857
858
156k
        ue(pic_width_in_luma_samples,  1, HEVC_MAX_WIDTH);
859
155k
        ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
860
861
153k
        flag(conformance_window_flag);
862
153k
        if (current->conformance_window_flag) {
863
148k
            ue(conf_win_left_offset,   0, current->pic_width_in_luma_samples);
864
147k
            ue(conf_win_right_offset,  0, current->pic_width_in_luma_samples);
865
146k
            ue(conf_win_top_offset,    0, current->pic_height_in_luma_samples);
866
146k
            ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
867
146k
        } else {
868
4.82k
            infer(conf_win_left_offset,   0);
869
4.82k
            infer(conf_win_right_offset,  0);
870
4.82k
            infer(conf_win_top_offset,    0);
871
4.82k
            infer(conf_win_bottom_offset, 0);
872
2
        }
873
874
150k
        ue(bit_depth_luma_minus8,   0, 8);
875
149k
        ue(bit_depth_chroma_minus8, 0, 8);
876
149k
    }
877
878
148k
    ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
879
880
148k
    if (!multi_layer_ext_sps_flag) {
881
146k
        flag(sps_sub_layer_ordering_info_present_flag);
882
146k
        for (i = (current->sps_sub_layer_ordering_info_present_flag ?
883
142k
                  0 : current->sps_max_sub_layers_minus1);
884
296k
             i <= current->sps_max_sub_layers_minus1; i++) {
885
154k
            ues(sps_max_dec_pic_buffering_minus1[i],
886
154k
                0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
887
154k
            ues(sps_max_num_reorder_pics[i],
888
150k
                0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
889
150k
            ues(sps_max_latency_increase_plus1[i],
890
150k
                0, UINT32_MAX - 1,                               1, i);
891
150k
        }
892
142k
        if (!current->sps_sub_layer_ordering_info_present_flag) {
893
1.25k
            for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
894
112
                infer(sps_max_dec_pic_buffering_minus1[i],
895
112
                      current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
896
112
                infer(sps_max_num_reorder_pics[i],
897
0
                      current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
898
112
                infer(sps_max_latency_increase_plus1[i],
899
0
                      current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
900
0
            }
901
1.14k
        }
902
142k
    }
903
904
143k
    ue(log2_min_luma_coding_block_size_minus3,   0, 3);
905
142k
    min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
906
907
142k
    ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
908
141k
    ctb_log2_size_y = min_cb_log2_size_y +
909
141k
        current->log2_diff_max_min_luma_coding_block_size;
910
911
141k
    min_cb_size_y = 1 << min_cb_log2_size_y;
912
141k
    if (current->pic_width_in_luma_samples  % min_cb_size_y ||
913
141k
        current->pic_height_in_luma_samples % min_cb_size_y) {
914
1.91k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
915
1.91k
               "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
916
1.91k
               current->pic_height_in_luma_samples, min_cb_size_y);
917
1.91k
        return AVERROR_INVALIDDATA;
918
1.91k
    }
919
920
140k
    ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
921
136k
    min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
922
923
136k
    ue(log2_diff_max_min_luma_transform_block_size,
924
135k
       0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
925
926
135k
    ue(max_transform_hierarchy_depth_inter,
927
135k
       0, ctb_log2_size_y - min_tb_log2_size_y);
928
135k
    ue(max_transform_hierarchy_depth_intra,
929
134k
       0, ctb_log2_size_y - min_tb_log2_size_y);
930
931
134k
    flag(scaling_list_enabled_flag);
932
133k
    if (current->scaling_list_enabled_flag) {
933
8.40k
        if (multi_layer_ext_sps_flag)
934
8.40k
            flag(sps_infer_scaling_list_flag);
935
7.70k
        else
936
7.70k
            infer(sps_infer_scaling_list_flag, 0);
937
8.40k
        if (current->sps_infer_scaling_list_flag)
938
690
            ub(6, sps_scaling_list_ref_layer_id);
939
7.71k
        else {
940
7.71k
            flag(sps_scaling_list_data_present_flag);
941
7.42k
            if (current->sps_scaling_list_data_present_flag)
942
3.37k
                CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
943
7.42k
        }
944
125k
    } else {
945
125k
        infer(sps_scaling_list_data_present_flag, 0);
946
125k
    }
947
948
130k
    flag(amp_enabled_flag);
949
127k
    flag(sample_adaptive_offset_enabled_flag);
950
951
127k
    flag(pcm_enabled_flag);
952
127k
    if (current->pcm_enabled_flag) {
953
28.6k
        u(4, pcm_sample_bit_depth_luma_minus1,
954
28.2k
          0, current->bit_depth_luma_minus8 + 8 - 1);
955
28.2k
        u(4, pcm_sample_bit_depth_chroma_minus1,
956
27.9k
          0, current->bit_depth_chroma_minus8 + 8 - 1);
957
958
27.9k
        ue(log2_min_pcm_luma_coding_block_size_minus3,
959
27.7k
           FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
960
27.7k
        ue(log2_diff_max_min_pcm_luma_coding_block_size,
961
27.1k
           0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
962
963
27.1k
        flag(pcm_loop_filter_disabled_flag);
964
27.1k
    }
965
966
125k
    ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
967
1.05M
    for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
968
940k
        CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
969
970
113k
    flag(long_term_ref_pics_present_flag);
971
112k
    if (current->long_term_ref_pics_present_flag) {
972
44.6k
        ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
973
85.4k
        for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
974
41.7k
            ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
975
41.2k
                lt_ref_pic_poc_lsb_sps[i], 1, i);
976
41.2k
            flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
977
41.2k
        }
978
44.5k
    }
979
980
111k
    flag(sps_temporal_mvp_enabled_flag);
981
111k
    flag(strong_intra_smoothing_enabled_flag);
982
983
111k
    flag(vui_parameters_present_flag);
984
110k
    if (current->vui_parameters_present_flag)
985
73.9k
        CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
986
37.0k
    else
987
37.0k
        CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
988
989
74.1k
    flag(sps_extension_present_flag);
990
74.0k
    if (current->sps_extension_present_flag) {
991
36.6k
        flag(sps_range_extension_flag);
992
36.5k
        flag(sps_multilayer_extension_flag);
993
36.4k
        flag(sps_3d_extension_flag);
994
36.2k
        flag(sps_scc_extension_flag);
995
36.0k
        ub(4, sps_extension_4bits);
996
36.0k
    }
997
998
73.2k
    if (current->sps_range_extension_flag)
999
20.8k
        CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1000
68.8k
    if (current->sps_multilayer_extension_flag)
1001
3.28k
        CHECK(FUNC(sps_multilayer_extension)(ctx, rw, current));
1002
68.8k
    if (current->sps_3d_extension_flag)
1003
2.91k
        return AVERROR_PATCHWELCOME;
1004
65.9k
    if (current->sps_scc_extension_flag)
1005
11.3k
        CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
1006
61.4k
    if (current->sps_extension_4bits)
1007
16.2k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1008
1009
61.4k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1010
1011
54.6k
    return 0;
1012
61.4k
}
cbs_h2645.c:cbs_h265_read_sps
Line
Count
Source
788
274k
{
789
274k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
790
274k
    const H265RawVPS *vps;
791
274k
    int err, i;
792
274k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y,
793
274k
                 min_cb_size_y,   min_tb_log2_size_y;
794
274k
    unsigned int multi_layer_ext_sps_flag;
795
796
274k
    HEADER("Sequence Parameter Set");
797
798
274k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
799
800
274k
    ub(4, sps_video_parameter_set_id);
801
272k
    h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
802
272k
    if (!vps) {
803
51.2k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
804
51.2k
               current->sps_video_parameter_set_id);
805
51.2k
        return AVERROR_INVALIDDATA;
806
51.2k
    }
807
808
221k
    if (current->nal_unit_header.nuh_layer_id == 0)
809
221k
        u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1);
810
4.72k
    else {
811
4.72k
        u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS);
812
4.72k
        infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS
813
4.72k
                                         ? vps->vps_max_sub_layers_minus1
814
4.72k
                                         : current->sps_ext_or_max_sub_layers_minus1);
815
4.72k
    }
816
215k
    multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id &&
817
215k
                               current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS;
818
215k
    if (!multi_layer_ext_sps_flag) {
819
214k
        flag(sps_temporal_id_nesting_flag);
820
821
214k
        if (vps->vps_temporal_id_nesting_flag &&
822
214k
            !current->sps_temporal_id_nesting_flag) {
823
5.62k
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
824
5.62k
                   "sps_temporal_id_nesting_flag must be 1 if "
825
5.62k
                   "vps_temporal_id_nesting_flag is 1.\n");
826
5.62k
            return AVERROR_INVALIDDATA;
827
5.62k
        }
828
209k
        if (current->sps_max_sub_layers_minus1 == 0 &&
829
209k
            current->sps_temporal_id_nesting_flag != 1) {
830
567
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
831
567
                   "sps_temporal_id_nesting_flag must be 1 if "
832
567
                   "sps_max_sub_layers_minus1 is 0.\n");
833
567
            return AVERROR_INVALIDDATA;
834
567
        }
835
836
208k
        CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
837
208k
                                       1, current->sps_max_sub_layers_minus1));
838
208k
    } else {
839
1.15k
        if (current->sps_max_sub_layers_minus1 > 0)
840
742
            infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag);
841
409
        else
842
409
            infer(sps_temporal_id_nesting_flag, 1);
843
1.15k
    }
844
845
147k
    ue(sps_seq_parameter_set_id, 0, 15);
846
847
146k
    if (multi_layer_ext_sps_flag) {
848
1.14k
        flag(update_rep_format_flag);
849
1.14k
        if (current->update_rep_format_flag)
850
958
            ub(8, sps_rep_format_idx);
851
145k
    } else {
852
145k
        ue(chroma_format_idc, 0, 3);
853
144k
        if (current->chroma_format_idc == 3)
854
144k
            flag(separate_colour_plane_flag);
855
94.4k
        else
856
94.4k
            infer(separate_colour_plane_flag, 0);
857
858
144k
        ue(pic_width_in_luma_samples,  1, HEVC_MAX_WIDTH);
859
142k
        ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
860
861
140k
        flag(conformance_window_flag);
862
140k
        if (current->conformance_window_flag) {
863
135k
            ue(conf_win_left_offset,   0, current->pic_width_in_luma_samples);
864
134k
            ue(conf_win_right_offset,  0, current->pic_width_in_luma_samples);
865
134k
            ue(conf_win_top_offset,    0, current->pic_height_in_luma_samples);
866
134k
            ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
867
134k
        } else {
868
4.82k
            infer(conf_win_left_offset,   0);
869
4.82k
            infer(conf_win_right_offset,  0);
870
4.82k
            infer(conf_win_top_offset,    0);
871
4.82k
            infer(conf_win_bottom_offset, 0);
872
4.82k
        }
873
874
138k
        ue(bit_depth_luma_minus8,   0, 8);
875
136k
        ue(bit_depth_chroma_minus8, 0, 8);
876
136k
    }
877
878
136k
    ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
879
880
135k
    if (!multi_layer_ext_sps_flag) {
881
134k
        flag(sps_sub_layer_ordering_info_present_flag);
882
134k
        for (i = (current->sps_sub_layer_ordering_info_present_flag ?
883
129k
                  0 : current->sps_max_sub_layers_minus1);
884
271k
             i <= current->sps_max_sub_layers_minus1; i++) {
885
141k
            ues(sps_max_dec_pic_buffering_minus1[i],
886
140k
                0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
887
140k
            ues(sps_max_num_reorder_pics[i],
888
137k
                0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
889
137k
            ues(sps_max_latency_increase_plus1[i],
890
137k
                0, UINT32_MAX - 1,                               1, i);
891
137k
        }
892
129k
        if (!current->sps_sub_layer_ordering_info_present_flag) {
893
1.24k
            for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
894
112
                infer(sps_max_dec_pic_buffering_minus1[i],
895
112
                      current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
896
112
                infer(sps_max_num_reorder_pics[i],
897
112
                      current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
898
112
                infer(sps_max_latency_increase_plus1[i],
899
112
                      current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
900
112
            }
901
1.13k
        }
902
129k
    }
903
904
130k
    ue(log2_min_luma_coding_block_size_minus3,   0, 3);
905
130k
    min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
906
907
130k
    ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
908
129k
    ctb_log2_size_y = min_cb_log2_size_y +
909
129k
        current->log2_diff_max_min_luma_coding_block_size;
910
911
129k
    min_cb_size_y = 1 << min_cb_log2_size_y;
912
129k
    if (current->pic_width_in_luma_samples  % min_cb_size_y ||
913
129k
        current->pic_height_in_luma_samples % min_cb_size_y) {
914
1.91k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
915
1.91k
               "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
916
1.91k
               current->pic_height_in_luma_samples, min_cb_size_y);
917
1.91k
        return AVERROR_INVALIDDATA;
918
1.91k
    }
919
920
127k
    ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
921
123k
    min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
922
923
123k
    ue(log2_diff_max_min_luma_transform_block_size,
924
123k
       0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
925
926
123k
    ue(max_transform_hierarchy_depth_inter,
927
122k
       0, ctb_log2_size_y - min_tb_log2_size_y);
928
122k
    ue(max_transform_hierarchy_depth_intra,
929
121k
       0, ctb_log2_size_y - min_tb_log2_size_y);
930
931
121k
    flag(scaling_list_enabled_flag);
932
120k
    if (current->scaling_list_enabled_flag) {
933
7.38k
        if (multi_layer_ext_sps_flag)
934
7.38k
            flag(sps_infer_scaling_list_flag);
935
6.72k
        else
936
6.72k
            infer(sps_infer_scaling_list_flag, 0);
937
7.38k
        if (current->sps_infer_scaling_list_flag)
938
652
            ub(6, sps_scaling_list_ref_layer_id);
939
6.72k
        else {
940
6.72k
            flag(sps_scaling_list_data_present_flag);
941
6.44k
            if (current->sps_scaling_list_data_present_flag)
942
3.30k
                CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
943
6.44k
        }
944
113k
    } else {
945
113k
        infer(sps_scaling_list_data_present_flag, 0);
946
113k
    }
947
948
117k
    flag(amp_enabled_flag);
949
115k
    flag(sample_adaptive_offset_enabled_flag);
950
951
114k
    flag(pcm_enabled_flag);
952
114k
    if (current->pcm_enabled_flag) {
953
28.2k
        u(4, pcm_sample_bit_depth_luma_minus1,
954
27.8k
          0, current->bit_depth_luma_minus8 + 8 - 1);
955
27.8k
        u(4, pcm_sample_bit_depth_chroma_minus1,
956
27.5k
          0, current->bit_depth_chroma_minus8 + 8 - 1);
957
958
27.5k
        ue(log2_min_pcm_luma_coding_block_size_minus3,
959
27.2k
           FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
960
27.2k
        ue(log2_diff_max_min_pcm_luma_coding_block_size,
961
26.7k
           0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
962
963
26.7k
        flag(pcm_loop_filter_disabled_flag);
964
26.7k
    }
965
966
112k
    ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
967
902k
    for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
968
802k
        CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
969
970
100k
    flag(long_term_ref_pics_present_flag);
971
100k
    if (current->long_term_ref_pics_present_flag) {
972
41.6k
        ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
973
79.8k
        for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
974
39.1k
            ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
975
38.6k
                lt_ref_pic_poc_lsb_sps[i], 1, i);
976
38.6k
            flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
977
38.6k
        }
978
41.5k
    }
979
980
99.5k
    flag(sps_temporal_mvp_enabled_flag);
981
99.4k
    flag(strong_intra_smoothing_enabled_flag);
982
983
99.2k
    flag(vui_parameters_present_flag);
984
98.4k
    if (current->vui_parameters_present_flag)
985
69.2k
        CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
986
29.2k
    else
987
29.2k
        CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
988
989
61.6k
    flag(sps_extension_present_flag);
990
61.5k
    if (current->sps_extension_present_flag) {
991
32.0k
        flag(sps_range_extension_flag);
992
31.9k
        flag(sps_multilayer_extension_flag);
993
31.8k
        flag(sps_3d_extension_flag);
994
31.6k
        flag(sps_scc_extension_flag);
995
31.4k
        ub(4, sps_extension_4bits);
996
31.4k
    }
997
998
60.7k
    if (current->sps_range_extension_flag)
999
19.5k
        CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1000
56.4k
    if (current->sps_multilayer_extension_flag)
1001
2.90k
        CHECK(FUNC(sps_multilayer_extension)(ctx, rw, current));
1002
56.3k
    if (current->sps_3d_extension_flag)
1003
2.91k
        return AVERROR_PATCHWELCOME;
1004
53.4k
    if (current->sps_scc_extension_flag)
1005
10.3k
        CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
1006
48.9k
    if (current->sps_extension_4bits)
1007
12.4k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1008
1009
48.9k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1010
1011
42.1k
    return 0;
1012
48.9k
}
cbs_h2645.c:cbs_h265_write_sps
Line
Count
Source
788
13.5k
{
789
13.5k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
790
13.5k
    const H265RawVPS *vps;
791
13.5k
    int err, i;
792
13.5k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y,
793
13.5k
                 min_cb_size_y,   min_tb_log2_size_y;
794
13.5k
    unsigned int multi_layer_ext_sps_flag;
795
796
13.5k
    HEADER("Sequence Parameter Set");
797
798
13.5k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
799
800
13.5k
    ub(4, sps_video_parameter_set_id);
801
13.5k
    h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
802
13.5k
    if (!vps) {
803
686
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
804
686
               current->sps_video_parameter_set_id);
805
686
        return AVERROR_INVALIDDATA;
806
686
    }
807
808
12.8k
    if (current->nal_unit_header.nuh_layer_id == 0)
809
12.8k
        u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1);
810
273
    else {
811
273
        u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS);
812
273
        infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS
813
273
                                         ? vps->vps_max_sub_layers_minus1
814
273
                                         : current->sps_ext_or_max_sub_layers_minus1);
815
273
    }
816
12.7k
    multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id &&
817
12.7k
                               current->sps_ext_or_max_sub_layers_minus1 == HEVC_MAX_SUB_LAYERS;
818
12.7k
    if (!multi_layer_ext_sps_flag) {
819
12.5k
        flag(sps_temporal_id_nesting_flag);
820
821
12.5k
        if (vps->vps_temporal_id_nesting_flag &&
822
12.5k
            !current->sps_temporal_id_nesting_flag) {
823
54
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
824
54
                   "sps_temporal_id_nesting_flag must be 1 if "
825
54
                   "vps_temporal_id_nesting_flag is 1.\n");
826
54
            return AVERROR_INVALIDDATA;
827
54
        }
828
12.5k
        if (current->sps_max_sub_layers_minus1 == 0 &&
829
12.5k
            current->sps_temporal_id_nesting_flag != 1) {
830
0
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
831
0
                   "sps_temporal_id_nesting_flag must be 1 if "
832
0
                   "sps_max_sub_layers_minus1 is 0.\n");
833
0
            return AVERROR_INVALIDDATA;
834
0
        }
835
836
12.5k
        CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
837
12.5k
                                       1, current->sps_max_sub_layers_minus1));
838
12.5k
    } else {
839
170
        if (current->sps_max_sub_layers_minus1 > 0)
840
135
            infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag);
841
35
        else
842
35
            infer(sps_temporal_id_nesting_flag, 1);
843
170
    }
844
845
12.6k
    ue(sps_seq_parameter_set_id, 0, 15);
846
847
12.6k
    if (multi_layer_ext_sps_flag) {
848
130
        flag(update_rep_format_flag);
849
130
        if (current->update_rep_format_flag)
850
38
            ub(8, sps_rep_format_idx);
851
12.5k
    } else {
852
12.5k
        ue(chroma_format_idc, 0, 3);
853
12.5k
        if (current->chroma_format_idc == 3)
854
12.5k
            flag(separate_colour_plane_flag);
855
12.1k
        else
856
12.1k
            infer(separate_colour_plane_flag, 0);
857
858
12.5k
        ue(pic_width_in_luma_samples,  1, HEVC_MAX_WIDTH);
859
12.5k
        ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
860
861
12.5k
        flag(conformance_window_flag);
862
12.5k
        if (current->conformance_window_flag) {
863
12.5k
            ue(conf_win_left_offset,   0, current->pic_width_in_luma_samples);
864
12.5k
            ue(conf_win_right_offset,  0, current->pic_width_in_luma_samples);
865
12.5k
            ue(conf_win_top_offset,    0, current->pic_height_in_luma_samples);
866
12.5k
            ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
867
12.5k
        } else {
868
2
            infer(conf_win_left_offset,   0);
869
2
            infer(conf_win_right_offset,  0);
870
2
            infer(conf_win_top_offset,    0);
871
2
            infer(conf_win_bottom_offset, 0);
872
2
        }
873
874
12.5k
        ue(bit_depth_luma_minus8,   0, 8);
875
12.5k
        ue(bit_depth_chroma_minus8, 0, 8);
876
12.5k
    }
877
878
12.6k
    ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
879
880
12.6k
    if (!multi_layer_ext_sps_flag) {
881
12.5k
        flag(sps_sub_layer_ordering_info_present_flag);
882
12.5k
        for (i = (current->sps_sub_layer_ordering_info_present_flag ?
883
12.4k
                  0 : current->sps_max_sub_layers_minus1);
884
25.6k
             i <= current->sps_max_sub_layers_minus1; i++) {
885
13.1k
            ues(sps_max_dec_pic_buffering_minus1[i],
886
13.1k
                0, HEVC_MAX_DPB_SIZE - 1,                        1, i);
887
13.1k
            ues(sps_max_num_reorder_pics[i],
888
13.1k
                0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
889
13.1k
            ues(sps_max_latency_increase_plus1[i],
890
13.1k
                0, UINT32_MAX - 1,                               1, i);
891
13.1k
        }
892
12.5k
        if (!current->sps_sub_layer_ordering_info_present_flag) {
893
9
            for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
894
0
                infer(sps_max_dec_pic_buffering_minus1[i],
895
0
                      current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
896
0
                infer(sps_max_num_reorder_pics[i],
897
0
                      current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
898
0
                infer(sps_max_latency_increase_plus1[i],
899
0
                      current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
900
0
            }
901
9
        }
902
12.5k
    }
903
904
12.6k
    ue(log2_min_luma_coding_block_size_minus3,   0, 3);
905
12.6k
    min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
906
907
12.6k
    ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
908
12.6k
    ctb_log2_size_y = min_cb_log2_size_y +
909
12.6k
        current->log2_diff_max_min_luma_coding_block_size;
910
911
12.6k
    min_cb_size_y = 1 << min_cb_log2_size_y;
912
12.6k
    if (current->pic_width_in_luma_samples  % min_cb_size_y ||
913
12.6k
        current->pic_height_in_luma_samples % min_cb_size_y) {
914
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
915
0
               "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
916
0
               current->pic_height_in_luma_samples, min_cb_size_y);
917
0
        return AVERROR_INVALIDDATA;
918
0
    }
919
920
12.6k
    ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
921
12.6k
    min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
922
923
12.6k
    ue(log2_diff_max_min_luma_transform_block_size,
924
12.6k
       0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
925
926
12.6k
    ue(max_transform_hierarchy_depth_inter,
927
12.6k
       0, ctb_log2_size_y - min_tb_log2_size_y);
928
12.6k
    ue(max_transform_hierarchy_depth_intra,
929
12.6k
       0, ctb_log2_size_y - min_tb_log2_size_y);
930
931
12.6k
    flag(scaling_list_enabled_flag);
932
12.6k
    if (current->scaling_list_enabled_flag) {
933
1.02k
        if (multi_layer_ext_sps_flag)
934
1.02k
            flag(sps_infer_scaling_list_flag);
935
983
        else
936
983
            infer(sps_infer_scaling_list_flag, 0);
937
1.02k
        if (current->sps_infer_scaling_list_flag)
938
38
            ub(6, sps_scaling_list_ref_layer_id);
939
983
        else {
940
983
            flag(sps_scaling_list_data_present_flag);
941
983
            if (current->sps_scaling_list_data_present_flag)
942
69
                CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
943
983
        }
944
11.6k
    } else {
945
11.6k
        infer(sps_scaling_list_data_present_flag, 0);
946
11.6k
    }
947
948
12.6k
    flag(amp_enabled_flag);
949
12.6k
    flag(sample_adaptive_offset_enabled_flag);
950
951
12.6k
    flag(pcm_enabled_flag);
952
12.6k
    if (current->pcm_enabled_flag) {
953
427
        u(4, pcm_sample_bit_depth_luma_minus1,
954
427
          0, current->bit_depth_luma_minus8 + 8 - 1);
955
427
        u(4, pcm_sample_bit_depth_chroma_minus1,
956
427
          0, current->bit_depth_chroma_minus8 + 8 - 1);
957
958
427
        ue(log2_min_pcm_luma_coding_block_size_minus3,
959
427
           FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
960
427
        ue(log2_diff_max_min_pcm_luma_coding_block_size,
961
427
           0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
962
963
427
        flag(pcm_loop_filter_disabled_flag);
964
427
    }
965
966
12.6k
    ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
967
151k
    for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
968
138k
        CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
969
970
12.4k
    flag(long_term_ref_pics_present_flag);
971
12.4k
    if (current->long_term_ref_pics_present_flag) {
972
3.04k
        ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
973
5.61k
        for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
974
2.57k
            ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
975
2.57k
                lt_ref_pic_poc_lsb_sps[i], 1, i);
976
2.57k
            flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
977
2.57k
        }
978
3.04k
    }
979
980
12.4k
    flag(sps_temporal_mvp_enabled_flag);
981
12.4k
    flag(strong_intra_smoothing_enabled_flag);
982
983
12.4k
    flag(vui_parameters_present_flag);
984
12.4k
    if (current->vui_parameters_present_flag)
985
4.67k
        CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
986
7.81k
    else
987
7.81k
        CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
988
989
12.4k
    flag(sps_extension_present_flag);
990
12.4k
    if (current->sps_extension_present_flag) {
991
4.60k
        flag(sps_range_extension_flag);
992
4.60k
        flag(sps_multilayer_extension_flag);
993
4.60k
        flag(sps_3d_extension_flag);
994
4.60k
        flag(sps_scc_extension_flag);
995
4.60k
        ub(4, sps_extension_4bits);
996
4.60k
    }
997
998
12.4k
    if (current->sps_range_extension_flag)
999
1.29k
        CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1000
12.4k
    if (current->sps_multilayer_extension_flag)
1001
376
        CHECK(FUNC(sps_multilayer_extension)(ctx, rw, current));
1002
12.4k
    if (current->sps_3d_extension_flag)
1003
0
        return AVERROR_PATCHWELCOME;
1004
12.4k
    if (current->sps_scc_extension_flag)
1005
1.03k
        CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
1006
12.4k
    if (current->sps_extension_4bits)
1007
3.77k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1008
1009
12.4k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1010
1011
12.4k
    return 0;
1012
12.4k
}
1013
1014
static int FUNC(pps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw,
1015
                                     H265RawPPS *current)
1016
38.3k
{
1017
38.3k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1018
38.3k
    const H265RawSPS *sps = h265->active_sps;
1019
38.3k
    int err, i;
1020
1021
38.3k
    if (current->transform_skip_enabled_flag)
1022
38.3k
        ue(log2_max_transform_skip_block_size_minus2, 0, 3);
1023
38.2k
    flag(cross_component_prediction_enabled_flag);
1024
1025
38.2k
    flag(chroma_qp_offset_list_enabled_flag);
1026
37.0k
    if (current->chroma_qp_offset_list_enabled_flag) {
1027
13.8k
        ue(diff_cu_chroma_qp_offset_depth,
1028
10.2k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1029
10.2k
        ue(chroma_qp_offset_list_len_minus1, 0, 5);
1030
26.3k
        for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
1031
19.1k
            ses(cb_qp_offset_list[i], -12, +12, 1, i);
1032
18.6k
            ses(cr_qp_offset_list[i], -12, +12, 1, i);
1033
18.6k
        }
1034
9.87k
    }
1035
1036
30.3k
    ue(log2_sao_offset_scale_luma,   0, FFMAX(0, sps->bit_depth_luma_minus8   - 2));
1037
29.3k
    ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
1038
1039
28.7k
    return 0;
1040
29.3k
}
cbs_h2645.c:cbs_h265_read_pps_range_extension
Line
Count
Source
1016
26.8k
{
1017
26.8k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1018
26.8k
    const H265RawSPS *sps = h265->active_sps;
1019
26.8k
    int err, i;
1020
1021
26.8k
    if (current->transform_skip_enabled_flag)
1022
26.8k
        ue(log2_max_transform_skip_block_size_minus2, 0, 3);
1023
26.7k
    flag(cross_component_prediction_enabled_flag);
1024
1025
26.7k
    flag(chroma_qp_offset_list_enabled_flag);
1026
25.5k
    if (current->chroma_qp_offset_list_enabled_flag) {
1027
12.1k
        ue(diff_cu_chroma_qp_offset_depth,
1028
8.50k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1029
8.50k
        ue(chroma_qp_offset_list_len_minus1, 0, 5);
1030
20.5k
        for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
1031
15.0k
            ses(cb_qp_offset_list[i], -12, +12, 1, i);
1032
14.5k
            ses(cr_qp_offset_list[i], -12, +12, 1, i);
1033
14.5k
        }
1034
8.17k
    }
1035
1036
18.8k
    ue(log2_sao_offset_scale_luma,   0, FFMAX(0, sps->bit_depth_luma_minus8   - 2));
1037
18.1k
    ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
1038
1039
17.5k
    return 0;
1040
18.1k
}
cbs_h2645.c:cbs_h265_write_pps_range_extension
Line
Count
Source
1016
11.4k
{
1017
11.4k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1018
11.4k
    const H265RawSPS *sps = h265->active_sps;
1019
11.4k
    int err, i;
1020
1021
11.4k
    if (current->transform_skip_enabled_flag)
1022
11.4k
        ue(log2_max_transform_skip_block_size_minus2, 0, 3);
1023
11.4k
    flag(cross_component_prediction_enabled_flag);
1024
1025
11.4k
    flag(chroma_qp_offset_list_enabled_flag);
1026
11.4k
    if (current->chroma_qp_offset_list_enabled_flag) {
1027
1.70k
        ue(diff_cu_chroma_qp_offset_depth,
1028
1.70k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1029
1.70k
        ue(chroma_qp_offset_list_len_minus1, 0, 5);
1030
5.75k
        for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
1031
4.05k
            ses(cb_qp_offset_list[i], -12, +12, 1, i);
1032
4.05k
            ses(cr_qp_offset_list[i], -12, +12, 1, i);
1033
4.05k
        }
1034
1.70k
    }
1035
1036
11.4k
    ue(log2_sao_offset_scale_luma,   0, FFMAX(0, sps->bit_depth_luma_minus8   - 2));
1037
11.2k
    ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
1038
1039
11.2k
    return 0;
1040
11.2k
}
1041
1042
static int FUNC(colour_mapping_octants)(CodedBitstreamContext *ctx, RWContext *rw,
1043
                                        H265RawPPS *current, unsigned int inp_depth,
1044
                                        unsigned int idx_y, unsigned int idx_cb,
1045
                                        unsigned int idx_cr, unsigned int inp_length)
1046
10.3k
{
1047
10.3k
    int part_num_y, cm_res_bits;
1048
10.3k
    int err;
1049
1050
10.3k
    part_num_y = 1 << current->cm_y_part_num_log2;
1051
1052
10.3k
    av_assert0(inp_depth <= 1);
1053
10.3k
    if (inp_depth < current->cm_octant_depth)
1054
10.3k
        flags(split_octant_flag[inp_depth], 1, inp_depth);
1055
8.40k
    else
1056
8.40k
        infer(split_octant_flag[inp_depth], 0);
1057
1058
10.2k
    if (current->split_octant_flag[inp_depth])
1059
3.52k
        for (int k = 0; k < 2; k++)
1060
6.31k
            for (int m = 0; m < 2; m++)
1061
11.9k
                for (int n = 0; n < 2; n++)
1062
8.29k
                    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, inp_depth + 1,
1063
10.2k
                                                       idx_y + part_num_y * k * inp_length / 2,
1064
10.2k
                                                       idx_cb + m * inp_length / 2,
1065
10.2k
                                                       idx_cr + n * inp_length / 2,
1066
10.2k
                                                       inp_length / 2));
1067
8.54k
    else
1068
22.9k
        for (int i = 0; i < part_num_y; i++) {
1069
15.3k
            int idx_shift_y = idx_y + (i << (current->cm_octant_depth - inp_depth));
1070
73.7k
            for (int j = 0; j < 4; j++) {
1071
59.4k
                flags(coded_res_flag[idx_shift_y][idx_cb][idx_cr][j],
1072
59.3k
                      4, idx_shift_y, idx_cb, idx_cr, j);
1073
59.3k
                if (current->coded_res_flag[idx_shift_y][idx_cb][idx_cr][j]) {
1074
92.6k
                    for (int c = 0; c < 3; c++) {
1075
69.9k
                        ues(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0, 3,
1076
69.6k
                            5, idx_shift_y, idx_cb, idx_cr, j, c);
1077
69.6k
                        cm_res_bits = FFMAX(0, 10 + (current->luma_bit_depth_cm_input_minus8 + 8) -
1078
69.6k
                                            (current->luma_bit_depth_cm_output_minus8 + 8) -
1079
69.6k
                                            current->cm_res_quant_bits - (current->cm_delta_flc_bits_minus1 + 1));
1080
69.6k
                        if (cm_res_bits)
1081
69.6k
                            ubs(cm_res_bits, res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c],
1082
38.8k
                                5, idx_shift_y, idx_cb, idx_cr, j, c);
1083
38.8k
                        else
1084
38.8k
                            infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1085
69.5k
                        if (current->res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c] ||
1086
69.5k
                            current->res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c])
1087
39.7k
                            ub(1, res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c]);
1088
29.7k
                        else
1089
29.7k
                            infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1090
69.5k
                    }
1091
35.7k
                } else {
1092
142k
                    for (int c = 0; c < 3; c++) {
1093
107k
                        infer(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1094
107k
                        infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1095
107k
                        infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1096
25.3k
                    }
1097
35.7k
                }
1098
59.3k
            }
1099
15.3k
        }
1100
1101
8.45k
    return 0;
1102
10.2k
}
cbs_h2645.c:cbs_h265_read_colour_mapping_octants
Line
Count
Source
1046
7.20k
{
1047
7.20k
    int part_num_y, cm_res_bits;
1048
7.20k
    int err;
1049
1050
7.20k
    part_num_y = 1 << current->cm_y_part_num_log2;
1051
1052
7.20k
    av_assert0(inp_depth <= 1);
1053
7.20k
    if (inp_depth < current->cm_octant_depth)
1054
7.20k
        flags(split_octant_flag[inp_depth], 1, inp_depth);
1055
5.58k
    else
1056
5.58k
        infer(split_octant_flag[inp_depth], 0);
1057
1058
7.04k
    if (current->split_octant_flag[inp_depth])
1059
2.46k
        for (int k = 0; k < 2; k++)
1060
4.20k
            for (int m = 0; m < 2; m++)
1061
7.76k
                for (int n = 0; n < 2; n++)
1062
5.47k
                    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, inp_depth + 1,
1063
7.04k
                                                       idx_y + part_num_y * k * inp_length / 2,
1064
7.04k
                                                       idx_cb + m * inp_length / 2,
1065
7.04k
                                                       idx_cr + n * inp_length / 2,
1066
7.04k
                                                       inp_length / 2));
1067
5.72k
    else
1068
16.5k
        for (int i = 0; i < part_num_y; i++) {
1069
11.7k
            int idx_shift_y = idx_y + (i << (current->cm_octant_depth - inp_depth));
1070
55.8k
            for (int j = 0; j < 4; j++) {
1071
45.0k
                flags(coded_res_flag[idx_shift_y][idx_cb][idx_cr][j],
1072
45.0k
                      4, idx_shift_y, idx_cb, idx_cr, j);
1073
45.0k
                if (current->coded_res_flag[idx_shift_y][idx_cb][idx_cr][j]) {
1074
69.0k
                    for (int c = 0; c < 3; c++) {
1075
52.2k
                        ues(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0, 3,
1076
51.9k
                            5, idx_shift_y, idx_cb, idx_cr, j, c);
1077
51.9k
                        cm_res_bits = FFMAX(0, 10 + (current->luma_bit_depth_cm_input_minus8 + 8) -
1078
51.9k
                                            (current->luma_bit_depth_cm_output_minus8 + 8) -
1079
51.9k
                                            current->cm_res_quant_bits - (current->cm_delta_flc_bits_minus1 + 1));
1080
51.9k
                        if (cm_res_bits)
1081
51.9k
                            ubs(cm_res_bits, res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c],
1082
21.4k
                                5, idx_shift_y, idx_cb, idx_cr, j, c);
1083
21.4k
                        else
1084
21.4k
                            infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1085
51.8k
                        if (current->res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c] ||
1086
51.8k
                            current->res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c])
1087
34.9k
                            ub(1, res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c]);
1088
16.8k
                        else
1089
16.8k
                            infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1090
51.8k
                    }
1091
27.2k
                } else {
1092
109k
                    for (int c = 0; c < 3; c++) {
1093
81.7k
                        infer(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1094
81.7k
                        infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1095
81.7k
                        infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1096
81.7k
                    }
1097
27.2k
                }
1098
45.0k
            }
1099
11.7k
        }
1100
1101
5.27k
    return 0;
1102
7.04k
}
cbs_h2645.c:cbs_h265_write_colour_mapping_octants
Line
Count
Source
1046
3.18k
{
1047
3.18k
    int part_num_y, cm_res_bits;
1048
3.18k
    int err;
1049
1050
3.18k
    part_num_y = 1 << current->cm_y_part_num_log2;
1051
1052
3.18k
    av_assert0(inp_depth <= 1);
1053
3.18k
    if (inp_depth < current->cm_octant_depth)
1054
3.18k
        flags(split_octant_flag[inp_depth], 1, inp_depth);
1055
2.81k
    else
1056
2.81k
        infer(split_octant_flag[inp_depth], 0);
1057
1058
3.18k
    if (current->split_octant_flag[inp_depth])
1059
1.05k
        for (int k = 0; k < 2; k++)
1060
2.11k
            for (int m = 0; m < 2; m++)
1061
4.22k
                for (int n = 0; n < 2; n++)
1062
2.81k
                    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, inp_depth + 1,
1063
3.18k
                                                       idx_y + part_num_y * k * inp_length / 2,
1064
3.18k
                                                       idx_cb + m * inp_length / 2,
1065
3.18k
                                                       idx_cr + n * inp_length / 2,
1066
3.18k
                                                       inp_length / 2));
1067
2.82k
    else
1068
6.41k
        for (int i = 0; i < part_num_y; i++) {
1069
3.58k
            int idx_shift_y = idx_y + (i << (current->cm_octant_depth - inp_depth));
1070
17.9k
            for (int j = 0; j < 4; j++) {
1071
14.3k
                flags(coded_res_flag[idx_shift_y][idx_cb][idx_cr][j],
1072
14.3k
                      4, idx_shift_y, idx_cb, idx_cr, j);
1073
14.3k
                if (current->coded_res_flag[idx_shift_y][idx_cb][idx_cr][j]) {
1074
23.6k
                    for (int c = 0; c < 3; c++) {
1075
17.7k
                        ues(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0, 3,
1076
17.7k
                            5, idx_shift_y, idx_cb, idx_cr, j, c);
1077
17.7k
                        cm_res_bits = FFMAX(0, 10 + (current->luma_bit_depth_cm_input_minus8 + 8) -
1078
17.7k
                                            (current->luma_bit_depth_cm_output_minus8 + 8) -
1079
17.7k
                                            current->cm_res_quant_bits - (current->cm_delta_flc_bits_minus1 + 1));
1080
17.7k
                        if (cm_res_bits)
1081
17.7k
                            ubs(cm_res_bits, res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c],
1082
17.3k
                                5, idx_shift_y, idx_cb, idx_cr, j, c);
1083
17.3k
                        else
1084
17.3k
                            infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1085
17.7k
                        if (current->res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c] ||
1086
17.7k
                            current->res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c])
1087
4.79k
                            ub(1, res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c]);
1088
12.9k
                        else
1089
12.9k
                            infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1090
17.7k
                    }
1091
8.44k
                } else {
1092
33.7k
                    for (int c = 0; c < 3; c++) {
1093
25.3k
                        infer(res_coeff_q[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1094
25.3k
                        infer(res_coeff_r[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1095
25.3k
                        infer(res_coeff_s[idx_shift_y][idx_cb][idx_cr][j][c], 0);
1096
25.3k
                    }
1097
8.44k
                }
1098
14.3k
            }
1099
3.58k
        }
1100
1101
3.18k
    return 0;
1102
3.18k
}
1103
1104
static int FUNC(colour_mapping_table)(CodedBitstreamContext *ctx, RWContext *rw,
1105
                                      H265RawPPS *current)
1106
3.97k
{
1107
3.97k
    int err;
1108
1109
3.97k
    ue(num_cm_ref_layers_minus1, 0, 61);
1110
13.0k
    for (int i = 0; i <= current->num_cm_ref_layers_minus1; i++)
1111
9.50k
        ubs(6, cm_ref_layer_id[i], 1, i);
1112
1113
3.53k
    u(2, cm_octant_depth, 0, 1);
1114
3.06k
    u(2, cm_y_part_num_log2, 0, 3 - current->cm_octant_depth);
1115
1116
3.06k
    ue(luma_bit_depth_cm_input_minus8, 0, 8);
1117
2.86k
    ue(chroma_bit_depth_cm_input_minus8, 0, 8);
1118
2.68k
    ue(luma_bit_depth_cm_output_minus8, 0, 8);
1119
2.68k
    ue(chroma_bit_depth_cm_output_minus8, 0, 8);
1120
1121
2.66k
    ub(2, cm_res_quant_bits);
1122
2.26k
    ub(2, cm_delta_flc_bits_minus1);
1123
1124
2.21k
    if (current->cm_octant_depth == 1) {
1125
2.10k
        se(cm_adapt_threshold_u_delta, -32768, 32767);
1126
2.07k
        se(cm_adapt_threshold_v_delta, -32768, 32767);
1127
2.07k
    } else {
1128
109
        infer(cm_adapt_threshold_u_delta, 0);
1129
109
        infer(cm_adapt_threshold_v_delta, 0);
1130
0
    }
1131
1132
2.08k
    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, 0, 0, 0, 0, 1 << current->cm_octant_depth));
1133
1134
931
    return 0;
1135
2.08k
}
cbs_h2645.c:cbs_h265_read_colour_mapping_table
Line
Count
Source
1106
3.61k
{
1107
3.61k
    int err;
1108
1109
3.61k
    ue(num_cm_ref_layers_minus1, 0, 61);
1110
10.9k
    for (int i = 0; i <= current->num_cm_ref_layers_minus1; i++)
1111
7.81k
        ubs(6, cm_ref_layer_id[i], 1, i);
1112
1113
3.16k
    u(2, cm_octant_depth, 0, 1);
1114
2.69k
    u(2, cm_y_part_num_log2, 0, 3 - current->cm_octant_depth);
1115
1116
2.69k
    ue(luma_bit_depth_cm_input_minus8, 0, 8);
1117
2.50k
    ue(chroma_bit_depth_cm_input_minus8, 0, 8);
1118
2.32k
    ue(luma_bit_depth_cm_output_minus8, 0, 8);
1119
2.32k
    ue(chroma_bit_depth_cm_output_minus8, 0, 8);
1120
1121
2.29k
    ub(2, cm_res_quant_bits);
1122
1.90k
    ub(2, cm_delta_flc_bits_minus1);
1123
1124
1.84k
    if (current->cm_octant_depth == 1) {
1125
1.73k
        se(cm_adapt_threshold_u_delta, -32768, 32767);
1126
1.70k
        se(cm_adapt_threshold_v_delta, -32768, 32767);
1127
1.70k
    } else {
1128
109
        infer(cm_adapt_threshold_u_delta, 0);
1129
109
        infer(cm_adapt_threshold_v_delta, 0);
1130
109
    }
1131
1132
1.72k
    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, 0, 0, 0, 0, 1 << current->cm_octant_depth));
1133
1134
566
    return 0;
1135
1.72k
}
cbs_h2645.c:cbs_h265_write_colour_mapping_table
Line
Count
Source
1106
365
{
1107
365
    int err;
1108
1109
365
    ue(num_cm_ref_layers_minus1, 0, 61);
1110
2.05k
    for (int i = 0; i <= current->num_cm_ref_layers_minus1; i++)
1111
1.68k
        ubs(6, cm_ref_layer_id[i], 1, i);
1112
1113
365
    u(2, cm_octant_depth, 0, 1);
1114
365
    u(2, cm_y_part_num_log2, 0, 3 - current->cm_octant_depth);
1115
1116
365
    ue(luma_bit_depth_cm_input_minus8, 0, 8);
1117
365
    ue(chroma_bit_depth_cm_input_minus8, 0, 8);
1118
365
    ue(luma_bit_depth_cm_output_minus8, 0, 8);
1119
365
    ue(chroma_bit_depth_cm_output_minus8, 0, 8);
1120
1121
365
    ub(2, cm_res_quant_bits);
1122
365
    ub(2, cm_delta_flc_bits_minus1);
1123
1124
365
    if (current->cm_octant_depth == 1) {
1125
365
        se(cm_adapt_threshold_u_delta, -32768, 32767);
1126
365
        se(cm_adapt_threshold_v_delta, -32768, 32767);
1127
365
    } else {
1128
0
        infer(cm_adapt_threshold_u_delta, 0);
1129
0
        infer(cm_adapt_threshold_v_delta, 0);
1130
0
    }
1131
1132
365
    CHECK(FUNC(colour_mapping_octants)(ctx, rw, current, 0, 0, 0, 0, 1 << current->cm_octant_depth));
1133
1134
365
    return 0;
1135
365
}
1136
1137
static int FUNC(pps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw,
1138
                                          H265RawPPS *current)
1139
9.97k
{
1140
9.97k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1141
9.97k
    const H265RawVPS *vps = h265->active_vps;
1142
9.97k
    int offset;
1143
9.97k
    int err, i;
1144
1145
9.97k
    flag(poc_reset_info_present_flag);
1146
9.92k
    flag(pps_infer_scaling_list_flag);
1147
9.89k
    if (current->pps_infer_scaling_list_flag)
1148
7.08k
        ub(6, pps_scaling_list_ref_layer_id);
1149
1150
9.89k
    if (!vps) {
1151
508
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS missing for PPS Multilayer Extension.\n");
1152
508
        return AVERROR_INVALIDDATA;
1153
508
    }
1154
1155
9.38k
    ue(num_ref_loc_offsets, 0, vps->vps_max_layers_minus1);
1156
29.6k
    for (i = 0; i < current->num_ref_loc_offsets; i++) {
1157
23.7k
        ubs(6, ref_loc_offset_layer_id[i], 1, i);
1158
23.5k
        offset = current->ref_loc_offset_layer_id[i];
1159
23.5k
        flags(scaled_ref_layer_offset_present_flag[i], 1, i);
1160
23.5k
        if (current->scaled_ref_layer_offset_present_flag[i]) {
1161
12.8k
            ses(scaled_ref_layer_left_offset[offset], -16384, 16383, 1, offset);
1162
12.8k
            ses(scaled_ref_layer_top_offset[offset], -16384, 16383, 1, offset);
1163
12.7k
            ses(scaled_ref_layer_right_offset[offset], -16384, 16383, 1, offset);
1164
12.6k
            ses(scaled_ref_layer_bottom_offset[offset], -16384, 16383, 1, offset);
1165
12.6k
        } else {
1166
10.7k
            infer(scaled_ref_layer_left_offset[offset], 0);
1167
10.7k
            infer(scaled_ref_layer_top_offset[offset], 0);
1168
10.4k
            infer(scaled_ref_layer_right_offset[offset], 0);
1169
10.3k
            infer(scaled_ref_layer_bottom_offset[offset], 0);
1170
1.69k
        }
1171
22.8k
        flags(ref_region_offset_present_flag[i], 1, i);
1172
22.8k
        if (current->ref_region_offset_present_flag[i]) {
1173
11.6k
            ses(ref_region_left_offset[offset], -16384, 16383, 1, offset);
1174
11.4k
            ses(ref_region_top_offset[offset], -16384, 16383, 1, offset);
1175
11.4k
            ses(ref_region_right_offset[offset], -16384, 16383, 1, offset);
1176
11.0k
            ses(ref_region_bottom_offset[offset], -16384, 16383, 1, offset);
1177
11.2k
        } else {
1178
11.2k
            infer(ref_region_left_offset[offset], 0);
1179
11.1k
            infer(ref_region_top_offset[offset], 0);
1180
11.1k
            infer(ref_region_right_offset[offset], 0);
1181
11.1k
            infer(ref_region_bottom_offset[offset], 0);
1182
1.30k
        }
1183
22.0k
        flags(resample_phase_set_present_flag[i], 1, i);
1184
22.0k
        if (current->resample_phase_set_present_flag[i]) {
1185
13.5k
            ues(phase_hor_luma[offset], 0, 31, 1, offset);
1186
13.5k
            ues(phase_ver_luma[offset], 0, 31, 1, offset);
1187
13.5k
            ues(phase_hor_chroma_plus8[offset], 0, 63, 1, offset);
1188
12.9k
            ues(phase_ver_chroma_plus8[offset], 0, 63, 1, offset);
1189
12.9k
        } else {
1190
8.49k
            infer(phase_hor_luma[offset], 0);
1191
8.36k
            infer(phase_ver_luma[offset], 0);
1192
8.36k
            infer(phase_hor_chroma_plus8[offset], 8);
1193
1.00k
        }
1194
22.0k
    }
1195
1196
5.96k
    flag(colour_mapping_enabled_flag);
1197
5.91k
    if (current->colour_mapping_enabled_flag)
1198
3.97k
        CHECK(FUNC(colour_mapping_table)(ctx, rw, current));
1199
1200
2.87k
    return 0;
1201
5.91k
}
cbs_h2645.c:cbs_h265_read_pps_multilayer_extension
Line
Count
Source
1139
8.34k
{
1140
8.34k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1141
8.34k
    const H265RawVPS *vps = h265->active_vps;
1142
8.34k
    int offset;
1143
8.34k
    int err, i;
1144
1145
8.34k
    flag(poc_reset_info_present_flag);
1146
8.29k
    flag(pps_infer_scaling_list_flag);
1147
8.26k
    if (current->pps_infer_scaling_list_flag)
1148
5.73k
        ub(6, pps_scaling_list_ref_layer_id);
1149
1150
8.26k
    if (!vps) {
1151
256
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS missing for PPS Multilayer Extension.\n");
1152
256
        return AVERROR_INVALIDDATA;
1153
256
    }
1154
1155
8.00k
    ue(num_ref_loc_offsets, 0, vps->vps_max_layers_minus1);
1156
26.2k
    for (i = 0; i < current->num_ref_loc_offsets; i++) {
1157
20.6k
        ubs(6, ref_loc_offset_layer_id[i], 1, i);
1158
20.5k
        offset = current->ref_loc_offset_layer_id[i];
1159
20.5k
        flags(scaled_ref_layer_offset_present_flag[i], 1, i);
1160
20.5k
        if (current->scaled_ref_layer_offset_present_flag[i]) {
1161
11.8k
            ses(scaled_ref_layer_left_offset[offset], -16384, 16383, 1, offset);
1162
11.8k
            ses(scaled_ref_layer_top_offset[offset], -16384, 16383, 1, offset);
1163
11.8k
            ses(scaled_ref_layer_right_offset[offset], -16384, 16383, 1, offset);
1164
11.7k
            ses(scaled_ref_layer_bottom_offset[offset], -16384, 16383, 1, offset);
1165
11.7k
        } else {
1166
8.64k
            infer(scaled_ref_layer_left_offset[offset], 0);
1167
8.64k
            infer(scaled_ref_layer_top_offset[offset], 0);
1168
8.64k
            infer(scaled_ref_layer_right_offset[offset], 0);
1169
8.64k
            infer(scaled_ref_layer_bottom_offset[offset], 0);
1170
8.64k
        }
1171
20.2k
        flags(ref_region_offset_present_flag[i], 1, i);
1172
20.2k
        if (current->ref_region_offset_present_flag[i]) {
1173
10.3k
            ses(ref_region_left_offset[offset], -16384, 16383, 1, offset);
1174
10.1k
            ses(ref_region_top_offset[offset], -16384, 16383, 1, offset);
1175
10.1k
            ses(ref_region_right_offset[offset], -16384, 16383, 1, offset);
1176
9.78k
            ses(ref_region_bottom_offset[offset], -16384, 16383, 1, offset);
1177
9.86k
        } else {
1178
9.86k
            infer(ref_region_left_offset[offset], 0);
1179
9.86k
            infer(ref_region_top_offset[offset], 0);
1180
9.86k
            infer(ref_region_right_offset[offset], 0);
1181
9.86k
            infer(ref_region_bottom_offset[offset], 0);
1182
9.86k
        }
1183
19.5k
        flags(resample_phase_set_present_flag[i], 1, i);
1184
19.4k
        if (current->resample_phase_set_present_flag[i]) {
1185
12.1k
            ues(phase_hor_luma[offset], 0, 31, 1, offset);
1186
12.1k
            ues(phase_ver_luma[offset], 0, 31, 1, offset);
1187
12.1k
            ues(phase_hor_chroma_plus8[offset], 0, 63, 1, offset);
1188
11.5k
            ues(phase_ver_chroma_plus8[offset], 0, 63, 1, offset);
1189
11.5k
        } else {
1190
7.36k
            infer(phase_hor_luma[offset], 0);
1191
7.36k
            infer(phase_ver_luma[offset], 0);
1192
7.36k
            infer(phase_hor_chroma_plus8[offset], 8);
1193
7.36k
        }
1194
19.4k
    }
1195
1196
5.56k
    flag(colour_mapping_enabled_flag);
1197
5.51k
    if (current->colour_mapping_enabled_flag)
1198
3.61k
        CHECK(FUNC(colour_mapping_table)(ctx, rw, current));
1199
1200
2.47k
    return 0;
1201
5.51k
}
cbs_h2645.c:cbs_h265_write_pps_multilayer_extension
Line
Count
Source
1139
1.62k
{
1140
1.62k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1141
1.62k
    const H265RawVPS *vps = h265->active_vps;
1142
1.62k
    int offset;
1143
1.62k
    int err, i;
1144
1145
1.62k
    flag(poc_reset_info_present_flag);
1146
1.62k
    flag(pps_infer_scaling_list_flag);
1147
1.62k
    if (current->pps_infer_scaling_list_flag)
1148
1.34k
        ub(6, pps_scaling_list_ref_layer_id);
1149
1150
1.62k
    if (!vps) {
1151
252
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS missing for PPS Multilayer Extension.\n");
1152
252
        return AVERROR_INVALIDDATA;
1153
252
    }
1154
1155
1.37k
    ue(num_ref_loc_offsets, 0, vps->vps_max_layers_minus1);
1156
3.46k
    for (i = 0; i < current->num_ref_loc_offsets; i++) {
1157
3.06k
        ubs(6, ref_loc_offset_layer_id[i], 1, i);
1158
3.06k
        offset = current->ref_loc_offset_layer_id[i];
1159
3.06k
        flags(scaled_ref_layer_offset_present_flag[i], 1, i);
1160
3.06k
        if (current->scaled_ref_layer_offset_present_flag[i]) {
1161
952
            ses(scaled_ref_layer_left_offset[offset], -16384, 16383, 1, offset);
1162
952
            ses(scaled_ref_layer_top_offset[offset], -16384, 16383, 1, offset);
1163
952
            ses(scaled_ref_layer_right_offset[offset], -16384, 16383, 1, offset);
1164
952
            ses(scaled_ref_layer_bottom_offset[offset], -16384, 16383, 1, offset);
1165
2.11k
        } else {
1166
2.11k
            infer(scaled_ref_layer_left_offset[offset], 0);
1167
2.11k
            infer(scaled_ref_layer_top_offset[offset], 0);
1168
1.85k
            infer(scaled_ref_layer_right_offset[offset], 0);
1169
1.69k
            infer(scaled_ref_layer_bottom_offset[offset], 0);
1170
1.69k
        }
1171
2.59k
        flags(ref_region_offset_present_flag[i], 1, i);
1172
2.59k
        if (current->ref_region_offset_present_flag[i]) {
1173
1.23k
            ses(ref_region_left_offset[offset], -16384, 16383, 1, offset);
1174
1.23k
            ses(ref_region_top_offset[offset], -16384, 16383, 1, offset);
1175
1.23k
            ses(ref_region_right_offset[offset], -16384, 16383, 1, offset);
1176
1.23k
            ses(ref_region_bottom_offset[offset], -16384, 16383, 1, offset);
1177
1.35k
        } else {
1178
1.35k
            infer(ref_region_left_offset[offset], 0);
1179
1.31k
            infer(ref_region_top_offset[offset], 0);
1180
1.30k
            infer(ref_region_right_offset[offset], 0);
1181
1.30k
            infer(ref_region_bottom_offset[offset], 0);
1182
1.30k
        }
1183
2.54k
        flags(resample_phase_set_present_flag[i], 1, i);
1184
2.54k
        if (current->resample_phase_set_present_flag[i]) {
1185
1.41k
            ues(phase_hor_luma[offset], 0, 31, 1, offset);
1186
1.41k
            ues(phase_ver_luma[offset], 0, 31, 1, offset);
1187
1.41k
            ues(phase_hor_chroma_plus8[offset], 0, 63, 1, offset);
1188
1.41k
            ues(phase_ver_chroma_plus8[offset], 0, 63, 1, offset);
1189
1.41k
        } else {
1190
1.13k
            infer(phase_hor_luma[offset], 0);
1191
1.00k
            infer(phase_ver_luma[offset], 0);
1192
1.00k
            infer(phase_hor_chroma_plus8[offset], 8);
1193
1.00k
        }
1194
2.54k
    }
1195
1196
399
    flag(colour_mapping_enabled_flag);
1197
399
    if (current->colour_mapping_enabled_flag)
1198
365
        CHECK(FUNC(colour_mapping_table)(ctx, rw, current));
1199
1200
399
    return 0;
1201
399
}
1202
1203
static int FUNC(pps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw,
1204
                                   H265RawPPS *current)
1205
21.0k
{
1206
21.0k
    int err, comp, i;
1207
1208
21.0k
    flag(pps_curr_pic_ref_enabled_flag);
1209
1210
20.8k
    flag(residual_adaptive_colour_transform_enabled_flag);
1211
20.7k
    if (current->residual_adaptive_colour_transform_enabled_flag) {
1212
11.7k
        flag(pps_slice_act_qp_offsets_present_flag);
1213
11.4k
        se(pps_act_y_qp_offset_plus5,  -7, +17);
1214
10.0k
        se(pps_act_cb_qp_offset_plus5, -7, +17);
1215
9.33k
        se(pps_act_cr_qp_offset_plus3, -9, +15);
1216
9.33k
    } else {
1217
8.99k
        infer(pps_slice_act_qp_offsets_present_flag, 0);
1218
8.99k
        infer(pps_act_y_qp_offset_plus5,  0);
1219
8.99k
        infer(pps_act_cb_qp_offset_plus5, 0);
1220
8.99k
        infer(pps_act_cr_qp_offset_plus3, 0);
1221
1.69k
    }
1222
1223
17.9k
    flag(pps_palette_predictor_initializer_present_flag);
1224
17.2k
    if (current->pps_palette_predictor_initializer_present_flag) {
1225
11.5k
        ue(pps_num_palette_predictor_initializer, 0, 128);
1226
10.7k
        if (current->pps_num_palette_predictor_initializer > 0) {
1227
7.90k
            flag(monochrome_palette_flag);
1228
6.88k
            ue(luma_bit_depth_entry_minus8, 0, 8);
1229
6.68k
            if (!current->monochrome_palette_flag)
1230
6.68k
                ue(chroma_bit_depth_entry_minus8, 0, 8);
1231
19.9k
            for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
1232
14.6k
                int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1233
14.6k
                                          : current->chroma_bit_depth_entry_minus8 + 8;
1234
68.9k
                for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
1235
54.8k
                    ubs(bit_depth, pps_palette_predictor_initializers[comp][i], 2, comp, i);
1236
14.6k
            }
1237
5.90k
        }
1238
10.7k
    }
1239
1240
13.8k
    return 0;
1241
17.2k
}
cbs_h2645.c:cbs_h265_read_pps_scc_extension
Line
Count
Source
1205
18.4k
{
1206
18.4k
    int err, comp, i;
1207
1208
18.4k
    flag(pps_curr_pic_ref_enabled_flag);
1209
1210
18.2k
    flag(residual_adaptive_colour_transform_enabled_flag);
1211
18.1k
    if (current->residual_adaptive_colour_transform_enabled_flag) {
1212
10.8k
        flag(pps_slice_act_qp_offsets_present_flag);
1213
10.5k
        se(pps_act_y_qp_offset_plus5,  -7, +17);
1214
9.10k
        se(pps_act_cb_qp_offset_plus5, -7, +17);
1215
8.38k
        se(pps_act_cr_qp_offset_plus3, -9, +15);
1216
8.38k
    } else {
1217
7.29k
        infer(pps_slice_act_qp_offsets_present_flag, 0);
1218
7.29k
        infer(pps_act_y_qp_offset_plus5,  0);
1219
7.29k
        infer(pps_act_cb_qp_offset_plus5, 0);
1220
7.29k
        infer(pps_act_cr_qp_offset_plus3, 0);
1221
7.29k
    }
1222
1223
15.2k
    flag(pps_palette_predictor_initializer_present_flag);
1224
14.6k
    if (current->pps_palette_predictor_initializer_present_flag) {
1225
9.43k
        ue(pps_num_palette_predictor_initializer, 0, 128);
1226
8.67k
        if (current->pps_num_palette_predictor_initializer > 0) {
1227
6.44k
            flag(monochrome_palette_flag);
1228
5.42k
            ue(luma_bit_depth_entry_minus8, 0, 8);
1229
5.22k
            if (!current->monochrome_palette_flag)
1230
5.22k
                ue(chroma_bit_depth_entry_minus8, 0, 8);
1231
14.3k
            for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
1232
10.6k
                int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1233
10.6k
                                          : current->chroma_bit_depth_entry_minus8 + 8;
1234
55.7k
                for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
1235
45.8k
                    ubs(bit_depth, pps_palette_predictor_initializers[comp][i], 2, comp, i);
1236
10.6k
            }
1237
4.44k
        }
1238
8.67k
    }
1239
1240
11.1k
    return 0;
1241
14.6k
}
cbs_h2645.c:cbs_h265_write_pps_scc_extension
Line
Count
Source
1205
2.65k
{
1206
2.65k
    int err, comp, i;
1207
1208
2.65k
    flag(pps_curr_pic_ref_enabled_flag);
1209
1210
2.65k
    flag(residual_adaptive_colour_transform_enabled_flag);
1211
2.65k
    if (current->residual_adaptive_colour_transform_enabled_flag) {
1212
954
        flag(pps_slice_act_qp_offsets_present_flag);
1213
954
        se(pps_act_y_qp_offset_plus5,  -7, +17);
1214
954
        se(pps_act_cb_qp_offset_plus5, -7, +17);
1215
954
        se(pps_act_cr_qp_offset_plus3, -9, +15);
1216
1.69k
    } else {
1217
1.69k
        infer(pps_slice_act_qp_offsets_present_flag, 0);
1218
1.69k
        infer(pps_act_y_qp_offset_plus5,  0);
1219
1.69k
        infer(pps_act_cb_qp_offset_plus5, 0);
1220
1.69k
        infer(pps_act_cr_qp_offset_plus3, 0);
1221
1.69k
    }
1222
1223
2.65k
    flag(pps_palette_predictor_initializer_present_flag);
1224
2.65k
    if (current->pps_palette_predictor_initializer_present_flag) {
1225
2.11k
        ue(pps_num_palette_predictor_initializer, 0, 128);
1226
2.11k
        if (current->pps_num_palette_predictor_initializer > 0) {
1227
1.46k
            flag(monochrome_palette_flag);
1228
1.46k
            ue(luma_bit_depth_entry_minus8, 0, 8);
1229
1.46k
            if (!current->monochrome_palette_flag)
1230
1.46k
                ue(chroma_bit_depth_entry_minus8, 0, 8);
1231
5.55k
            for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
1232
4.09k
                int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1233
4.09k
                                          : current->chroma_bit_depth_entry_minus8 + 8;
1234
13.1k
                for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
1235
9.08k
                    ubs(bit_depth, pps_palette_predictor_initializers[comp][i], 2, comp, i);
1236
4.09k
            }
1237
1.46k
        }
1238
2.11k
    }
1239
1240
2.65k
    return 0;
1241
2.65k
}
1242
1243
static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
1244
                     H265RawPPS *current)
1245
194k
{
1246
194k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1247
194k
    const H265RawSPS *sps;
1248
194k
    int err, i;
1249
1250
194k
    HEADER("Picture Parameter Set");
1251
1252
194k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
1253
1254
194k
    ue(pps_pic_parameter_set_id, 0, 63);
1255
190k
    ue(pps_seq_parameter_set_id, 0, 15);
1256
188k
    sps = h265->sps[current->pps_seq_parameter_set_id];
1257
188k
    if (!sps) {
1258
23.6k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1259
23.6k
               current->pps_seq_parameter_set_id);
1260
23.6k
        return AVERROR_INVALIDDATA;
1261
23.6k
    }
1262
164k
    h265->active_sps = sps;
1263
1264
164k
    flag(dependent_slice_segments_enabled_flag);
1265
164k
    flag(output_flag_present_flag);
1266
164k
    ub(3, num_extra_slice_header_bits);
1267
163k
    flag(sign_data_hiding_enabled_flag);
1268
163k
    flag(cabac_init_present_flag);
1269
1270
163k
    ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1271
158k
    ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1272
1273
157k
    se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
1274
1275
156k
    flag(constrained_intra_pred_flag);
1276
156k
    flag(transform_skip_enabled_flag);
1277
156k
    flag(cu_qp_delta_enabled_flag);
1278
155k
    if (current->cu_qp_delta_enabled_flag)
1279
155k
        ue(diff_cu_qp_delta_depth,
1280
113k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1281
113k
    else
1282
113k
        infer(diff_cu_qp_delta_depth, 0);
1283
1284
150k
    se(pps_cb_qp_offset, -12, +12);
1285
148k
    se(pps_cr_qp_offset, -12, +12);
1286
145k
    flag(pps_slice_chroma_qp_offsets_present_flag);
1287
1288
145k
    flag(weighted_pred_flag);
1289
144k
    flag(weighted_bipred_flag);
1290
1291
143k
    flag(transquant_bypass_enabled_flag);
1292
143k
    flag(tiles_enabled_flag);
1293
142k
    flag(entropy_coding_sync_enabled_flag);
1294
1295
141k
    if (current->tiles_enabled_flag) {
1296
52.1k
        ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
1297
51.8k
        ue(num_tile_rows_minus1,    0, HEVC_MAX_TILE_ROWS);
1298
50.0k
        flag(uniform_spacing_flag);
1299
49.4k
        if (!current->uniform_spacing_flag) {
1300
112k
            for (i = 0; i < current->num_tile_columns_minus1; i++)
1301
87.9k
                ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples,  1, i);
1302
77.3k
            for (i = 0; i < current->num_tile_rows_minus1; i++)
1303
53.2k
                ues(row_height_minus1[i],   0, sps->pic_height_in_luma_samples, 1, i);
1304
24.7k
        }
1305
46.7k
        flag(loop_filter_across_tiles_enabled_flag);
1306
89.7k
    } else {
1307
89.7k
        infer(num_tile_columns_minus1, 0);
1308
89.7k
        infer(num_tile_rows_minus1,    0);
1309
15.9k
    }
1310
1311
132k
    flag(pps_loop_filter_across_slices_enabled_flag);
1312
132k
    flag(deblocking_filter_control_present_flag);
1313
131k
    if (current->deblocking_filter_control_present_flag) {
1314
61.6k
        flag(deblocking_filter_override_enabled_flag);
1315
60.7k
        flag(pps_deblocking_filter_disabled_flag);
1316
60.5k
        if (!current->pps_deblocking_filter_disabled_flag) {
1317
21.1k
            se(pps_beta_offset_div2, -6, +6);
1318
20.1k
            se(pps_tc_offset_div2,   -6, +6);
1319
39.3k
        } else {
1320
39.3k
            infer(pps_beta_offset_div2, 0);
1321
39.3k
            infer(pps_tc_offset_div2,   0);
1322
11.4k
        }
1323
69.8k
    } else {
1324
69.8k
        infer(deblocking_filter_override_enabled_flag, 0);
1325
69.8k
        infer(pps_deblocking_filter_disabled_flag,     0);
1326
69.8k
        infer(pps_beta_offset_div2, 0);
1327
69.8k
        infer(pps_tc_offset_div2,   0);
1328
7.31k
    }
1329
1330
124k
    flag(pps_scaling_list_data_present_flag);
1331
121k
    if (current->pps_scaling_list_data_present_flag)
1332
22.6k
        CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1333
1334
107k
    flag(lists_modification_present_flag);
1335
1336
107k
    ue(log2_parallel_merge_level_minus2,
1337
104k
       0, (sps->log2_min_luma_coding_block_size_minus3 + 3 +
1338
104k
           sps->log2_diff_max_min_luma_coding_block_size - 2));
1339
1340
104k
    flag(slice_segment_header_extension_present_flag);
1341
1342
103k
    flag(pps_extension_present_flag);
1343
103k
    if (current->pps_extension_present_flag) {
1344
69.5k
        flag(pps_range_extension_flag);
1345
69.4k
        flag(pps_multilayer_extension_flag);
1346
68.7k
        flag(pps_3d_extension_flag);
1347
68.2k
        flag(pps_scc_extension_flag);
1348
67.9k
        ub(4, pps_extension_4bits);
1349
67.9k
    }
1350
101k
    if (current->pps_range_extension_flag)
1351
38.3k
        CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1352
91.5k
    if (current->pps_multilayer_extension_flag)
1353
9.97k
        CHECK(FUNC(pps_multilayer_extension)(ctx, rw, current));
1354
84.4k
    if (current->pps_3d_extension_flag)
1355
1.09k
        return AVERROR_PATCHWELCOME;
1356
83.3k
    if (current->pps_scc_extension_flag)
1357
21.0k
        CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1358
76.0k
    if (current->pps_extension_4bits)
1359
40.8k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1360
1361
76.0k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1362
1363
70.6k
    return 0;
1364
76.0k
}
cbs_h2645.c:cbs_h265_read_pps
Line
Count
Source
1245
172k
{
1246
172k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1247
172k
    const H265RawSPS *sps;
1248
172k
    int err, i;
1249
1250
172k
    HEADER("Picture Parameter Set");
1251
1252
172k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
1253
1254
172k
    ue(pps_pic_parameter_set_id, 0, 63);
1255
168k
    ue(pps_seq_parameter_set_id, 0, 15);
1256
167k
    sps = h265->sps[current->pps_seq_parameter_set_id];
1257
167k
    if (!sps) {
1258
23.4k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1259
23.4k
               current->pps_seq_parameter_set_id);
1260
23.4k
        return AVERROR_INVALIDDATA;
1261
23.4k
    }
1262
143k
    h265->active_sps = sps;
1263
1264
143k
    flag(dependent_slice_segments_enabled_flag);
1265
143k
    flag(output_flag_present_flag);
1266
143k
    ub(3, num_extra_slice_header_bits);
1267
142k
    flag(sign_data_hiding_enabled_flag);
1268
142k
    flag(cabac_init_present_flag);
1269
1270
142k
    ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1271
137k
    ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1272
1273
136k
    se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
1274
1275
135k
    flag(constrained_intra_pred_flag);
1276
135k
    flag(transform_skip_enabled_flag);
1277
135k
    flag(cu_qp_delta_enabled_flag);
1278
134k
    if (current->cu_qp_delta_enabled_flag)
1279
134k
        ue(diff_cu_qp_delta_depth,
1280
96.7k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1281
96.7k
    else
1282
96.7k
        infer(diff_cu_qp_delta_depth, 0);
1283
1284
129k
    se(pps_cb_qp_offset, -12, +12);
1285
127k
    se(pps_cr_qp_offset, -12, +12);
1286
124k
    flag(pps_slice_chroma_qp_offsets_present_flag);
1287
1288
124k
    flag(weighted_pred_flag);
1289
123k
    flag(weighted_bipred_flag);
1290
1291
122k
    flag(transquant_bypass_enabled_flag);
1292
122k
    flag(tiles_enabled_flag);
1293
121k
    flag(entropy_coding_sync_enabled_flag);
1294
1295
120k
    if (current->tiles_enabled_flag) {
1296
47.2k
        ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
1297
46.8k
        ue(num_tile_rows_minus1,    0, HEVC_MAX_TILE_ROWS);
1298
45.0k
        flag(uniform_spacing_flag);
1299
44.4k
        if (!current->uniform_spacing_flag) {
1300
99.4k
            for (i = 0; i < current->num_tile_columns_minus1; i++)
1301
78.1k
                ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples,  1, i);
1302
66.5k
            for (i = 0; i < current->num_tile_rows_minus1; i++)
1303
45.7k
                ues(row_height_minus1[i],   0, sps->pic_height_in_luma_samples, 1, i);
1304
21.2k
        }
1305
41.8k
        flag(loop_filter_across_tiles_enabled_flag);
1306
73.7k
    } else {
1307
73.7k
        infer(num_tile_columns_minus1, 0);
1308
73.7k
        infer(num_tile_rows_minus1,    0);
1309
73.7k
    }
1310
1311
111k
    flag(pps_loop_filter_across_slices_enabled_flag);
1312
111k
    flag(deblocking_filter_control_present_flag);
1313
110k
    if (current->deblocking_filter_control_present_flag) {
1314
48.1k
        flag(deblocking_filter_override_enabled_flag);
1315
47.1k
        flag(pps_deblocking_filter_disabled_flag);
1316
46.9k
        if (!current->pps_deblocking_filter_disabled_flag) {
1317
19.0k
            se(pps_beta_offset_div2, -6, +6);
1318
18.0k
            se(pps_tc_offset_div2,   -6, +6);
1319
27.8k
        } else {
1320
27.8k
            infer(pps_beta_offset_div2, 0);
1321
27.8k
            infer(pps_tc_offset_div2,   0);
1322
27.8k
        }
1323
62.5k
    } else {
1324
62.5k
        infer(deblocking_filter_override_enabled_flag, 0);
1325
62.5k
        infer(pps_deblocking_filter_disabled_flag,     0);
1326
62.5k
        infer(pps_beta_offset_div2, 0);
1327
62.5k
        infer(pps_tc_offset_div2,   0);
1328
62.5k
    }
1329
1330
103k
    flag(pps_scaling_list_data_present_flag);
1331
101k
    if (current->pps_scaling_list_data_present_flag)
1332
20.6k
        CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1333
1334
86.3k
    flag(lists_modification_present_flag);
1335
1336
86.3k
    ue(log2_parallel_merge_level_minus2,
1337
83.5k
       0, (sps->log2_min_luma_coding_block_size_minus3 + 3 +
1338
83.5k
           sps->log2_diff_max_min_luma_coding_block_size - 2));
1339
1340
83.5k
    flag(slice_segment_header_extension_present_flag);
1341
1342
82.8k
    flag(pps_extension_present_flag);
1343
82.5k
    if (current->pps_extension_present_flag) {
1344
53.4k
        flag(pps_range_extension_flag);
1345
53.3k
        flag(pps_multilayer_extension_flag);
1346
52.7k
        flag(pps_3d_extension_flag);
1347
52.2k
        flag(pps_scc_extension_flag);
1348
51.9k
        ub(4, pps_extension_4bits);
1349
51.9k
    }
1350
80.3k
    if (current->pps_range_extension_flag)
1351
26.8k
        CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1352
71.0k
    if (current->pps_multilayer_extension_flag)
1353
8.34k
        CHECK(FUNC(pps_multilayer_extension)(ctx, rw, current));
1354
65.1k
    if (current->pps_3d_extension_flag)
1355
1.09k
        return AVERROR_PATCHWELCOME;
1356
64.0k
    if (current->pps_scc_extension_flag)
1357
18.4k
        CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1358
56.8k
    if (current->pps_extension_4bits)
1359
26.7k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1360
1361
56.8k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1362
1363
51.3k
    return 0;
1364
56.8k
}
cbs_h2645.c:cbs_h265_write_pps
Line
Count
Source
1245
21.3k
{
1246
21.3k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1247
21.3k
    const H265RawSPS *sps;
1248
21.3k
    int err, i;
1249
1250
21.3k
    HEADER("Picture Parameter Set");
1251
1252
21.3k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
1253
1254
21.3k
    ue(pps_pic_parameter_set_id, 0, 63);
1255
21.3k
    ue(pps_seq_parameter_set_id, 0, 15);
1256
21.3k
    sps = h265->sps[current->pps_seq_parameter_set_id];
1257
21.3k
    if (!sps) {
1258
192
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1259
192
               current->pps_seq_parameter_set_id);
1260
192
        return AVERROR_INVALIDDATA;
1261
192
    }
1262
21.2k
    h265->active_sps = sps;
1263
1264
21.2k
    flag(dependent_slice_segments_enabled_flag);
1265
21.2k
    flag(output_flag_present_flag);
1266
21.2k
    ub(3, num_extra_slice_header_bits);
1267
21.2k
    flag(sign_data_hiding_enabled_flag);
1268
21.2k
    flag(cabac_init_present_flag);
1269
1270
21.2k
    ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1271
21.2k
    ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1272
1273
21.2k
    se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
1274
1275
21.0k
    flag(constrained_intra_pred_flag);
1276
21.0k
    flag(transform_skip_enabled_flag);
1277
21.0k
    flag(cu_qp_delta_enabled_flag);
1278
21.0k
    if (current->cu_qp_delta_enabled_flag)
1279
21.0k
        ue(diff_cu_qp_delta_depth,
1280
17.0k
           0, sps->log2_diff_max_min_luma_coding_block_size);
1281
17.0k
    else
1282
17.0k
        infer(diff_cu_qp_delta_depth, 0);
1283
1284
20.9k
    se(pps_cb_qp_offset, -12, +12);
1285
20.9k
    se(pps_cr_qp_offset, -12, +12);
1286
20.9k
    flag(pps_slice_chroma_qp_offsets_present_flag);
1287
1288
20.9k
    flag(weighted_pred_flag);
1289
20.9k
    flag(weighted_bipred_flag);
1290
1291
20.9k
    flag(transquant_bypass_enabled_flag);
1292
20.9k
    flag(tiles_enabled_flag);
1293
20.9k
    flag(entropy_coding_sync_enabled_flag);
1294
1295
20.9k
    if (current->tiles_enabled_flag) {
1296
4.97k
        ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
1297
4.97k
        ue(num_tile_rows_minus1,    0, HEVC_MAX_TILE_ROWS);
1298
4.97k
        flag(uniform_spacing_flag);
1299
4.97k
        if (!current->uniform_spacing_flag) {
1300
13.2k
            for (i = 0; i < current->num_tile_columns_minus1; i++)
1301
9.77k
                ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples,  1, i);
1302
10.8k
            for (i = 0; i < current->num_tile_rows_minus1; i++)
1303
7.41k
                ues(row_height_minus1[i],   0, sps->pic_height_in_luma_samples, 1, i);
1304
3.44k
        }
1305
4.90k
        flag(loop_filter_across_tiles_enabled_flag);
1306
15.9k
    } else {
1307
15.9k
        infer(num_tile_columns_minus1, 0);
1308
15.9k
        infer(num_tile_rows_minus1,    0);
1309
15.9k
    }
1310
1311
20.8k
    flag(pps_loop_filter_across_slices_enabled_flag);
1312
20.8k
    flag(deblocking_filter_control_present_flag);
1313
20.8k
    if (current->deblocking_filter_control_present_flag) {
1314
13.5k
        flag(deblocking_filter_override_enabled_flag);
1315
13.5k
        flag(pps_deblocking_filter_disabled_flag);
1316
13.5k
        if (!current->pps_deblocking_filter_disabled_flag) {
1317
2.09k
            se(pps_beta_offset_div2, -6, +6);
1318
2.09k
            se(pps_tc_offset_div2,   -6, +6);
1319
11.4k
        } else {
1320
11.4k
            infer(pps_beta_offset_div2, 0);
1321
11.4k
            infer(pps_tc_offset_div2,   0);
1322
11.4k
        }
1323
13.5k
    } else {
1324
7.31k
        infer(deblocking_filter_override_enabled_flag, 0);
1325
7.31k
        infer(pps_deblocking_filter_disabled_flag,     0);
1326
7.31k
        infer(pps_beta_offset_div2, 0);
1327
7.31k
        infer(pps_tc_offset_div2,   0);
1328
7.31k
    }
1329
1330
20.8k
    flag(pps_scaling_list_data_present_flag);
1331
20.8k
    if (current->pps_scaling_list_data_present_flag)
1332
1.98k
        CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1333
1334
20.8k
    flag(lists_modification_present_flag);
1335
1336
20.8k
    ue(log2_parallel_merge_level_minus2,
1337
20.7k
       0, (sps->log2_min_luma_coding_block_size_minus3 + 3 +
1338
20.7k
           sps->log2_diff_max_min_luma_coding_block_size - 2));
1339
1340
20.7k
    flag(slice_segment_header_extension_present_flag);
1341
1342
20.7k
    flag(pps_extension_present_flag);
1343
20.7k
    if (current->pps_extension_present_flag) {
1344
16.0k
        flag(pps_range_extension_flag);
1345
16.0k
        flag(pps_multilayer_extension_flag);
1346
16.0k
        flag(pps_3d_extension_flag);
1347
16.0k
        flag(pps_scc_extension_flag);
1348
16.0k
        ub(4, pps_extension_4bits);
1349
16.0k
    }
1350
20.7k
    if (current->pps_range_extension_flag)
1351
11.4k
        CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1352
20.4k
    if (current->pps_multilayer_extension_flag)
1353
1.62k
        CHECK(FUNC(pps_multilayer_extension)(ctx, rw, current));
1354
19.2k
    if (current->pps_3d_extension_flag)
1355
0
        return AVERROR_PATCHWELCOME;
1356
19.2k
    if (current->pps_scc_extension_flag)
1357
2.65k
        CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1358
19.2k
    if (current->pps_extension_4bits)
1359
14.1k
        CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1360
1361
19.2k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1362
1363
19.2k
    return 0;
1364
19.2k
}
1365
1366
static int FUNC(aud)(CodedBitstreamContext *ctx, RWContext *rw,
1367
                     H265RawAUD *current)
1368
22.8k
{
1369
22.8k
    int err;
1370
1371
22.8k
    HEADER("Access Unit Delimiter");
1372
1373
22.8k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1374
1375
22.7k
    u(3, pic_type, 0, 2);
1376
1377
22.1k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1378
1379
9.78k
    return 0;
1380
22.1k
}
cbs_h2645.c:cbs_h265_read_aud
Line
Count
Source
1368
16.9k
{
1369
16.9k
    int err;
1370
1371
16.9k
    HEADER("Access Unit Delimiter");
1372
1373
16.9k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1374
1375
16.9k
    u(3, pic_type, 0, 2);
1376
1377
16.4k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1378
1379
4.05k
    return 0;
1380
16.4k
}
cbs_h2645.c:cbs_h265_write_aud
Line
Count
Source
1368
5.90k
{
1369
5.90k
    int err;
1370
1371
5.90k
    HEADER("Access Unit Delimiter");
1372
1373
5.90k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1374
1375
5.73k
    u(3, pic_type, 0, 2);
1376
1377
5.73k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1378
1379
5.73k
    return 0;
1380
5.73k
}
1381
1382
static int FUNC(ref_pic_lists_modification)(CodedBitstreamContext *ctx, RWContext *rw,
1383
                                            H265RawSliceHeader *current,
1384
                                            unsigned int num_pic_total_curr)
1385
31.6k
{
1386
31.6k
    unsigned int entry_size;
1387
31.6k
    int err, i;
1388
1389
31.6k
    entry_size = av_log2(num_pic_total_curr - 1) + 1;
1390
1391
31.6k
    flag(ref_pic_list_modification_flag_l0);
1392
29.7k
    if (current->ref_pic_list_modification_flag_l0) {
1393
36.8k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1394
25.1k
            us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1395
13.0k
    }
1396
1397
28.4k
    if (current->slice_type == HEVC_SLICE_B) {
1398
25.1k
        flag(ref_pic_list_modification_flag_l1);
1399
24.6k
        if (current->ref_pic_list_modification_flag_l1) {
1400
37.0k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1401
28.3k
                us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1402
10.0k
        }
1403
24.6k
    }
1404
1405
26.6k
    return 0;
1406
28.4k
}
cbs_h2645.c:cbs_h265_read_ref_pic_lists_modification
Line
Count
Source
1385
27.5k
{
1386
27.5k
    unsigned int entry_size;
1387
27.5k
    int err, i;
1388
1389
27.5k
    entry_size = av_log2(num_pic_total_curr - 1) + 1;
1390
1391
27.5k
    flag(ref_pic_list_modification_flag_l0);
1392
25.6k
    if (current->ref_pic_list_modification_flag_l0) {
1393
33.7k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1394
23.2k
            us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1395
11.8k
    }
1396
1397
24.3k
    if (current->slice_type == HEVC_SLICE_B) {
1398
21.0k
        flag(ref_pic_list_modification_flag_l1);
1399
20.5k
        if (current->ref_pic_list_modification_flag_l1) {
1400
34.8k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1401
26.8k
                us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1402
8.99k
        }
1403
20.5k
    }
1404
1405
22.9k
    return 0;
1406
24.3k
}
cbs_h2645.c:cbs_h265_write_ref_pic_lists_modification
Line
Count
Source
1385
4.11k
{
1386
4.11k
    unsigned int entry_size;
1387
4.11k
    int err, i;
1388
1389
4.11k
    entry_size = av_log2(num_pic_total_curr - 1) + 1;
1390
1391
4.11k
    flag(ref_pic_list_modification_flag_l0);
1392
4.11k
    if (current->ref_pic_list_modification_flag_l0) {
1393
3.12k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1394
1.90k
            us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1395
1.21k
    }
1396
1397
4.11k
    if (current->slice_type == HEVC_SLICE_B) {
1398
4.08k
        flag(ref_pic_list_modification_flag_l1);
1399
4.08k
        if (current->ref_pic_list_modification_flag_l1) {
1400
2.20k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1401
1.56k
                us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1402
1.05k
        }
1403
4.08k
    }
1404
1405
3.69k
    return 0;
1406
4.11k
}
1407
1408
static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
1409
                                   H265RawSliceHeader *current)
1410
46.1k
{
1411
46.1k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1412
46.1k
    const H265RawSPS *sps = h265->active_sps;
1413
46.1k
    int err, i, j;
1414
46.1k
    int chroma = !sps->separate_colour_plane_flag &&
1415
46.1k
                  sps->chroma_format_idc != 0;
1416
1417
46.1k
    ue(luma_log2_weight_denom, 0, 7);
1418
41.0k
    if (chroma)
1419
41.0k
        se(delta_chroma_log2_weight_denom, -7, 7);
1420
3.99k
    else
1421
3.99k
        infer(delta_chroma_log2_weight_denom, 0);
1422
1423
148k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1424
109k
        if (1 /* is not same POC and same layer_id */)
1425
109k
            flags(luma_weight_l0_flag[i], 1, i);
1426
0
        else
1427
0
            infer(luma_weight_l0_flag[i], 0);
1428
109k
    }
1429
38.9k
    if (chroma) {
1430
133k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1431
99.3k
            if (1 /* is not same POC and same layer_id */)
1432
99.3k
                flags(chroma_weight_l0_flag[i], 1, i);
1433
0
            else
1434
0
                infer(chroma_weight_l0_flag[i], 0);
1435
99.3k
        }
1436
35.0k
    }
1437
1438
123k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1439
90.8k
        if (current->luma_weight_l0_flag[i]) {
1440
38.7k
            ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1441
37.4k
            ses(luma_offset_l0[i],
1442
37.4k
                -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1443
37.4k
                ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1444
52.0k
        } else {
1445
52.0k
            infer(delta_luma_weight_l0[i], 0);
1446
52.0k
            infer(luma_offset_l0[i],       0);
1447
8.44k
        }
1448
88.3k
        if (current->chroma_weight_l0_flag[i]) {
1449
115k
            for (j = 0; j < 2; j++) {
1450
78.7k
                ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1451
77.1k
                ses(chroma_offset_l0[i][j],
1452
77.1k
                    -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1453
77.1k
                    ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1454
77.1k
            }
1455
47.7k
        } else {
1456
143k
            for (j = 0; j < 2; j++) {
1457
95.4k
                infer(delta_chroma_weight_l0[i][j], 0);
1458
95.4k
                infer(chroma_offset_l0[i][j],       0);
1459
17.1k
            }
1460
47.7k
        }
1461
88.3k
    }
1462
1463
32.1k
    if (current->slice_type == HEVC_SLICE_B) {
1464
107k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1465
78.4k
            if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1466
78.4k
                flags(luma_weight_l1_flag[i], 1, i);
1467
0
            else
1468
0
                infer(luma_weight_l1_flag[i], 0);
1469
78.4k
        }
1470
28.8k
        if (chroma) {
1471
88.0k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1472
63.2k
                if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1473
63.2k
                    flags(chroma_weight_l1_flag[i], 1, i);
1474
0
                else
1475
0
                    infer(chroma_weight_l1_flag[i], 0);
1476
63.2k
            }
1477
25.5k
        }
1478
1479
87.6k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1480
62.9k
            if (current->luma_weight_l1_flag[i]) {
1481
27.3k
                ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1482
26.5k
                ses(luma_offset_l1[i],
1483
26.5k
                    -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1484
26.5k
                    ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1485
35.6k
            } else {
1486
35.6k
                infer(delta_luma_weight_l1[i], 0);
1487
35.6k
                infer(luma_offset_l1[i],       0);
1488
6.58k
            }
1489
61.9k
            if (current->chroma_weight_l1_flag[i]) {
1490
83.1k
                for (j = 0; j < 2; j++) {
1491
56.6k
                    ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1492
55.7k
                    ses(chroma_offset_l1[i][j],
1493
55.7k
                        -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1494
55.7k
                        ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1495
55.7k
                }
1496
33.0k
            } else {
1497
99.2k
                for (j = 0; j < 2; j++) {
1498
66.1k
                    infer(delta_chroma_weight_l1[i][j], 0);
1499
66.1k
                    infer(chroma_offset_l1[i][j],       0);
1500
13.1k
                }
1501
33.0k
            }
1502
61.9k
        }
1503
28.1k
    }
1504
1505
27.2k
    return 0;
1506
32.1k
}
cbs_h2645.c:cbs_h265_read_pred_weight_table
Line
Count
Source
1410
42.2k
{
1411
42.2k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1412
42.2k
    const H265RawSPS *sps = h265->active_sps;
1413
42.2k
    int err, i, j;
1414
42.2k
    int chroma = !sps->separate_colour_plane_flag &&
1415
42.2k
                  sps->chroma_format_idc != 0;
1416
1417
42.2k
    ue(luma_log2_weight_denom, 0, 7);
1418
37.0k
    if (chroma)
1419
37.0k
        se(delta_chroma_log2_weight_denom, -7, 7);
1420
3.74k
    else
1421
3.74k
        infer(delta_chroma_log2_weight_denom, 0);
1422
1423
134k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1424
99.8k
        if (1 /* is not same POC and same layer_id */)
1425
99.8k
            flags(luma_weight_l0_flag[i], 1, i);
1426
0
        else
1427
0
            infer(luma_weight_l0_flag[i], 0);
1428
99.8k
    }
1429
35.0k
    if (chroma) {
1430
120k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1431
89.7k
            if (1 /* is not same POC and same layer_id */)
1432
89.7k
                flags(chroma_weight_l0_flag[i], 1, i);
1433
0
            else
1434
0
                infer(chroma_weight_l0_flag[i], 0);
1435
89.7k
        }
1436
31.3k
    }
1437
1438
109k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1439
81.0k
        if (current->luma_weight_l0_flag[i]) {
1440
37.4k
            ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1441
36.1k
            ses(luma_offset_l0[i],
1442
36.1k
                -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1443
36.1k
                ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1444
43.6k
        } else {
1445
43.6k
            infer(delta_luma_weight_l0[i], 0);
1446
43.6k
            infer(luma_offset_l0[i],       0);
1447
43.6k
        }
1448
78.6k
        if (current->chroma_weight_l0_flag[i]) {
1449
112k
            for (j = 0; j < 2; j++) {
1450
76.4k
                ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1451
74.8k
                ses(chroma_offset_l0[i][j],
1452
74.8k
                    -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1453
74.8k
                    ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1454
74.8k
            }
1455
39.4k
        } else {
1456
117k
            for (j = 0; j < 2; j++) {
1457
78.3k
                infer(delta_chroma_weight_l0[i][j], 0);
1458
78.3k
                infer(chroma_offset_l0[i][j],       0);
1459
78.3k
            }
1460
39.1k
        }
1461
78.6k
    }
1462
1463
28.4k
    if (current->slice_type == HEVC_SLICE_B) {
1464
96.5k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1465
71.2k
            if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1466
71.2k
                flags(luma_weight_l1_flag[i], 1, i);
1467
0
            else
1468
0
                infer(luma_weight_l1_flag[i], 0);
1469
71.2k
        }
1470
25.2k
        if (chroma) {
1471
77.8k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1472
56.3k
                if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1473
56.3k
                    flags(chroma_weight_l1_flag[i], 1, i);
1474
0
                else
1475
0
                    infer(chroma_weight_l1_flag[i], 0);
1476
56.3k
            }
1477
22.2k
        }
1478
1479
76.9k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1480
55.8k
            if (current->luma_weight_l1_flag[i]) {
1481
26.7k
                ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1482
25.9k
                ses(luma_offset_l1[i],
1483
25.9k
                    -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1484
25.9k
                    ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1485
29.0k
            } else {
1486
29.0k
                infer(delta_luma_weight_l1[i], 0);
1487
29.0k
                infer(luma_offset_l1[i],       0);
1488
29.0k
            }
1489
54.7k
            if (current->chroma_weight_l1_flag[i]) {
1490
81.3k
                for (j = 0; j < 2; j++) {
1491
55.4k
                    ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1492
54.5k
                    ses(chroma_offset_l1[i][j],
1493
54.5k
                        -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1494
54.5k
                        ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1495
54.5k
                }
1496
28.1k
            } else {
1497
79.5k
                for (j = 0; j < 2; j++) {
1498
53.0k
                    infer(delta_chroma_weight_l1[i][j], 0);
1499
53.0k
                    infer(chroma_offset_l1[i][j],       0);
1500
53.0k
                }
1501
26.5k
            }
1502
54.7k
        }
1503
24.5k
    }
1504
1505
23.5k
    return 0;
1506
28.4k
}
cbs_h2645.c:cbs_h265_write_pred_weight_table
Line
Count
Source
1410
3.93k
{
1411
3.93k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1412
3.93k
    const H265RawSPS *sps = h265->active_sps;
1413
3.93k
    int err, i, j;
1414
3.93k
    int chroma = !sps->separate_colour_plane_flag &&
1415
3.93k
                  sps->chroma_format_idc != 0;
1416
1417
3.93k
    ue(luma_log2_weight_denom, 0, 7);
1418
3.93k
    if (chroma)
1419
3.93k
        se(delta_chroma_log2_weight_denom, -7, 7);
1420
253
    else
1421
253
        infer(delta_chroma_log2_weight_denom, 0);
1422
1423
13.8k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1424
9.92k
        if (1 /* is not same POC and same layer_id */)
1425
9.92k
            flags(luma_weight_l0_flag[i], 1, i);
1426
0
        else
1427
0
            infer(luma_weight_l0_flag[i], 0);
1428
9.92k
    }
1429
3.92k
    if (chroma) {
1430
13.3k
        for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1431
9.61k
            if (1 /* is not same POC and same layer_id */)
1432
9.61k
                flags(chroma_weight_l0_flag[i], 1, i);
1433
0
            else
1434
0
                infer(chroma_weight_l0_flag[i], 0);
1435
9.61k
        }
1436
3.68k
    }
1437
1438
13.4k
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1439
9.75k
        if (current->luma_weight_l0_flag[i]) {
1440
1.30k
            ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1441
1.30k
            ses(luma_offset_l0[i],
1442
1.30k
                -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1443
1.30k
                ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1444
8.44k
        } else {
1445
8.44k
            infer(delta_luma_weight_l0[i], 0);
1446
8.44k
            infer(luma_offset_l0[i],       0);
1447
8.44k
        }
1448
9.71k
        if (current->chroma_weight_l0_flag[i]) {
1449
3.29k
            for (j = 0; j < 2; j++) {
1450
2.31k
                ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1451
2.31k
                ses(chroma_offset_l0[i][j],
1452
2.31k
                    -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1453
2.31k
                    ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1454
2.31k
            }
1455
8.56k
        } else {
1456
25.6k
            for (j = 0; j < 2; j++) {
1457
17.1k
                infer(delta_chroma_weight_l0[i][j], 0);
1458
17.1k
                infer(chroma_offset_l0[i][j],       0);
1459
17.1k
            }
1460
8.56k
        }
1461
9.71k
    }
1462
1463
3.71k
    if (current->slice_type == HEVC_SLICE_B) {
1464
10.7k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1465
7.18k
            if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1466
7.18k
                flags(luma_weight_l1_flag[i], 1, i);
1467
0
            else
1468
0
                infer(luma_weight_l1_flag[i], 0);
1469
7.18k
        }
1470
3.59k
        if (chroma) {
1471
10.2k
            for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1472
6.89k
                if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1473
6.89k
                    flags(chroma_weight_l1_flag[i], 1, i);
1474
0
                else
1475
0
                    infer(chroma_weight_l1_flag[i], 0);
1476
6.89k
            }
1477
3.35k
        }
1478
1479
10.7k
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1480
7.18k
            if (current->luma_weight_l1_flag[i]) {
1481
594
                ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1482
594
                ses(luma_offset_l1[i],
1483
594
                    -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1484
594
                    ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1485
6.58k
            } else {
1486
6.58k
                infer(delta_luma_weight_l1[i], 0);
1487
6.58k
                infer(luma_offset_l1[i],       0);
1488
6.58k
            }
1489
7.18k
            if (current->chroma_weight_l1_flag[i]) {
1490
1.76k
                for (j = 0; j < 2; j++) {
1491
1.19k
                    ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1492
1.19k
                    ses(chroma_offset_l1[i][j],
1493
1.19k
                        -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1494
1.19k
                        ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1495
1.19k
                }
1496
6.56k
            } else {
1497
19.7k
                for (j = 0; j < 2; j++) {
1498
13.1k
                    infer(delta_chroma_weight_l1[i][j], 0);
1499
13.1k
                    infer(chroma_offset_l1[i][j],       0);
1500
13.1k
                }
1501
6.56k
            }
1502
7.18k
        }
1503
3.59k
    }
1504
1505
3.67k
    return 0;
1506
3.71k
}
1507
1508
static int FUNC(slice_segment_header)(CodedBitstreamContext *ctx, RWContext *rw,
1509
                                      H265RawSliceHeader *current)
1510
301k
{
1511
301k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1512
301k
    const H265RawSPS *sps;
1513
301k
    const H265RawPPS *pps;
1514
301k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1515
301k
    unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1516
301k
    unsigned int num_pic_total_curr = 0;
1517
301k
    int err, i;
1518
1519
301k
    HEADER("Slice Segment Header");
1520
1521
301k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1522
1523
301k
    flag(first_slice_segment_in_pic_flag);
1524
1525
299k
    if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1526
299k
        current->nal_unit_header.nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
1527
299k
        flag(no_output_of_prior_pics_flag);
1528
1529
299k
    ue(slice_pic_parameter_set_id, 0, 63);
1530
1531
286k
    pps = h265->pps[current->slice_pic_parameter_set_id];
1532
286k
    if (!pps) {
1533
65.8k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1534
65.8k
               current->slice_pic_parameter_set_id);
1535
65.8k
        return AVERROR_INVALIDDATA;
1536
65.8k
    }
1537
220k
    h265->active_pps = pps;
1538
1539
220k
    sps = h265->sps[pps->pps_seq_parameter_set_id];
1540
220k
    if (!sps) {
1541
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1542
0
               pps->pps_seq_parameter_set_id);
1543
0
        return AVERROR_INVALIDDATA;
1544
0
    }
1545
220k
    h265->active_sps = sps;
1546
1547
220k
    min_cb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3;
1548
220k
    ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size;
1549
220k
    ctb_size_y = 1 << ctb_log2_size_y;
1550
220k
    pic_width_in_ctbs_y =
1551
220k
        (sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1552
220k
    pic_height_in_ctbs_y =
1553
220k
        (sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1554
220k
    pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1555
1556
220k
    if (!current->first_slice_segment_in_pic_flag) {
1557
65.1k
        unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1558
65.1k
        if (pps->dependent_slice_segments_enabled_flag)
1559
65.1k
            flag(dependent_slice_segment_flag);
1560
53.0k
        else
1561
53.0k
            infer(dependent_slice_segment_flag, 0);
1562
65.1k
        u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1563
155k
    } else {
1564
155k
        infer(dependent_slice_segment_flag, 0);
1565
155k
    }
1566
1567
218k
    if (!current->dependent_slice_segment_flag) {
1568
606k
        for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1569
389k
            flags(slice_reserved_flag[i], 1, i);
1570
1571
217k
        ue(slice_type, 0, 2);
1572
1573
213k
        if (pps->output_flag_present_flag)
1574
213k
            flag(pic_output_flag);
1575
1576
212k
        if (sps->separate_colour_plane_flag)
1577
212k
            u(2, colour_plane_id, 0, 2);
1578
1579
209k
        if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1580
209k
            current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1581
200k
            const H265RawSTRefPicSet *rps;
1582
200k
            int dpb_slots_remaining;
1583
1584
200k
            ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1585
1586
195k
            flag(short_term_ref_pic_set_sps_flag);
1587
193k
            if (!current->short_term_ref_pic_set_sps_flag) {
1588
89.1k
                CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1589
89.1k
                                           sps->num_short_term_ref_pic_sets, sps));
1590
68.4k
                rps = &current->short_term_ref_pic_set;
1591
104k
            } else if (sps->num_short_term_ref_pic_sets > 1) {
1592
65.3k
                unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1593
65.3k
                u(idx_size, short_term_ref_pic_set_idx,
1594
61.7k
                  0, sps->num_short_term_ref_pic_sets - 1);
1595
61.7k
                rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1596
61.7k
            } else {
1597
39.2k
                infer(short_term_ref_pic_set_idx, 0);
1598
1.18k
                rps = &sps->st_ref_pic_set[0];
1599
1.18k
            }
1600
1601
168k
            dpb_slots_remaining = HEVC_MAX_DPB_SIZE - 1 -
1602
168k
                rps->num_negative_pics - rps->num_positive_pics;
1603
168k
            if (pps->pps_curr_pic_ref_enabled_flag &&
1604
168k
                (sps->sample_adaptive_offset_enabled_flag ||
1605
55.0k
                 !pps->pps_deblocking_filter_disabled_flag ||
1606
55.0k
                 pps->deblocking_filter_override_enabled_flag)) {
1607
                // This picture will occupy two DPB slots.
1608
52.6k
                if (dpb_slots_remaining == 0) {
1609
57
                    av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
1610
57
                           "short-term ref pic set contains too many pictures "
1611
57
                           "to use with current picture reference enabled.\n");
1612
57
                    return AVERROR_INVALIDDATA;
1613
57
                }
1614
52.6k
                --dpb_slots_remaining;
1615
52.6k
            }
1616
1617
168k
            num_pic_total_curr = 0;
1618
377k
            for (i = 0; i < rps->num_negative_pics; i++)
1619
209k
                if (rps->used_by_curr_pic_s0_flag[i])
1620
144k
                    ++num_pic_total_curr;
1621
285k
            for (i = 0; i < rps->num_positive_pics; i++)
1622
116k
                if (rps->used_by_curr_pic_s1_flag[i])
1623
38.2k
                    ++num_pic_total_curr;
1624
1625
168k
            if (sps->long_term_ref_pics_present_flag) {
1626
66.3k
                unsigned int idx_size;
1627
1628
66.3k
                if (sps->num_long_term_ref_pics_sps > 0) {
1629
22.2k
                    ue(num_long_term_sps, 0, FFMIN(sps->num_long_term_ref_pics_sps,
1630
19.8k
                                                   dpb_slots_remaining));
1631
19.8k
                    idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1632
19.8k
                    dpb_slots_remaining -= current->num_long_term_sps;
1633
44.1k
                } else {
1634
44.1k
                    infer(num_long_term_sps, 0);
1635
1.92k
                    idx_size = 0;
1636
1.92k
                }
1637
63.9k
                ue(num_long_term_pics, 0, dpb_slots_remaining);
1638
1639
133k
                for (i = 0; i < current->num_long_term_sps +
1640
133k
                                current->num_long_term_pics; i++) {
1641
80.3k
                    if (i < current->num_long_term_sps) {
1642
13.5k
                        if (sps->num_long_term_ref_pics_sps > 1)
1643
13.5k
                            us(idx_size, lt_idx_sps[i],
1644
10.9k
                               0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1645
10.9k
                        if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1646
9.41k
                            ++num_pic_total_curr;
1647
66.7k
                    } else {
1648
66.7k
                        ubs(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i], 1, i);
1649
62.7k
                        flags(used_by_curr_pic_lt_flag[i], 1, i);
1650
62.1k
                        if (current->used_by_curr_pic_lt_flag[i])
1651
35.7k
                            ++num_pic_total_curr;
1652
62.1k
                    }
1653
73.0k
                    flags(delta_poc_msb_present_flag[i], 1, i);
1654
72.9k
                    if (current->delta_poc_msb_present_flag[i])
1655
72.9k
                        ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1656
32.8k
                    else
1657
32.8k
                        infer(delta_poc_msb_cycle_lt[i], 0);
1658
72.9k
                }
1659
62.1k
            }
1660
1661
155k
            if (sps->sps_temporal_mvp_enabled_flag)
1662
155k
                flag(slice_temporal_mvp_enabled_flag);
1663
30.3k
            else
1664
30.3k
                infer(slice_temporal_mvp_enabled_flag, 0);
1665
1666
151k
            if (pps->pps_curr_pic_ref_enabled_flag)
1667
51.0k
                ++num_pic_total_curr;
1668
151k
        }
1669
1670
160k
        if (sps->sample_adaptive_offset_enabled_flag) {
1671
98.2k
            flag(slice_sao_luma_flag);
1672
97.7k
            if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1673
97.7k
                flag(slice_sao_chroma_flag);
1674
7.82k
            else
1675
7.82k
                infer(slice_sao_chroma_flag, 0);
1676
97.7k
        } else {
1677
62.5k
            infer(slice_sao_luma_flag,   0);
1678
62.5k
            infer(slice_sao_chroma_flag, 0);
1679
1.80k
        }
1680
1681
160k
        if (current->slice_type == HEVC_SLICE_P ||
1682
160k
            current->slice_type == HEVC_SLICE_B) {
1683
130k
            flag(num_ref_idx_active_override_flag);
1684
130k
            if (current->num_ref_idx_active_override_flag) {
1685
84.2k
                ue(num_ref_idx_l0_active_minus1, 0, 14);
1686
81.9k
                if (current->slice_type == HEVC_SLICE_B)
1687
81.9k
                    ue(num_ref_idx_l1_active_minus1, 0, 14);
1688
7.96k
                else
1689
7.96k
                    infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1690
81.9k
            } else {
1691
45.7k
                infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1692
45.5k
                infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1693
2.62k
            }
1694
1695
125k
            if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1696
31.6k
                CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1697
125k
                                                       num_pic_total_curr));
1698
1699
120k
            if (current->slice_type == HEVC_SLICE_B)
1700
120k
                flag(mvd_l1_zero_flag);
1701
120k
            if (pps->cabac_init_present_flag)
1702
120k
                flag(cabac_init_flag);
1703
13.9k
            else
1704
13.9k
                infer(cabac_init_flag, 0);
1705
119k
            if (current->slice_temporal_mvp_enabled_flag) {
1706
31.7k
                if (current->slice_type == HEVC_SLICE_B)
1707
31.7k
                    flag(collocated_from_l0_flag);
1708
5.60k
                else
1709
5.60k
                    infer(collocated_from_l0_flag, 1);
1710
31.5k
                if (current->collocated_from_l0_flag) {
1711
17.5k
                    if (current->num_ref_idx_l0_active_minus1 > 0)
1712
17.5k
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1713
6.75k
                    else
1714
6.75k
                        infer(collocated_ref_idx, 0);
1715
17.5k
                } else {
1716
14.0k
                    if (current->num_ref_idx_l1_active_minus1 > 0)
1717
14.0k
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1718
5.26k
                    else
1719
5.26k
                        infer(collocated_ref_idx, 0);
1720
14.0k
                }
1721
31.5k
            }
1722
1723
115k
            if ((pps->weighted_pred_flag   && current->slice_type == HEVC_SLICE_P) ||
1724
115k
                (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1725
46.1k
                CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1726
1727
96.8k
            ue(five_minus_max_num_merge_cand, 0, 4);
1728
87.0k
            if (sps->motion_vector_resolution_control_idc == 2)
1729
87.0k
                flag(use_integer_mv_flag);
1730
76.6k
            else
1731
76.6k
                infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1732
87.0k
        }
1733
1734
116k
        se(slice_qp_delta,
1735
109k
           - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1736
109k
           + 51 - (pps->init_qp_minus26 + 26));
1737
109k
        if (pps->pps_slice_chroma_qp_offsets_present_flag) {
1738
51.1k
            se(slice_cb_qp_offset, -12, +12);
1739
47.5k
            se(slice_cr_qp_offset, -12, +12);
1740
57.9k
        } else {
1741
57.9k
            infer(slice_cb_qp_offset, 0);
1742
57.7k
            infer(slice_cr_qp_offset, 0);
1743
4.96k
        }
1744
103k
        if (pps->pps_slice_act_qp_offsets_present_flag) {
1745
19.5k
            se(slice_act_y_qp_offset,
1746
18.4k
               -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1747
18.4k
               +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1748
18.4k
            se(slice_act_cb_qp_offset,
1749
16.9k
               -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1750
16.9k
               +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1751
16.9k
            se(slice_act_cr_qp_offset,
1752
16.9k
               -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1753
16.9k
               +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1754
84.0k
        } else {
1755
84.0k
            infer(slice_act_y_qp_offset,  0);
1756
82.7k
            infer(slice_act_cb_qp_offset, 0);
1757
82.1k
            infer(slice_act_cr_qp_offset, 0);
1758
7.38k
        }
1759
98.1k
        if (pps->chroma_qp_offset_list_enabled_flag)
1760
98.1k
            flag(cu_chroma_qp_offset_enabled_flag);
1761
84.9k
        else
1762
84.9k
            infer(cu_chroma_qp_offset_enabled_flag, 0);
1763
1764
97.5k
        if (pps->deblocking_filter_override_enabled_flag)
1765
97.5k
            flag(deblocking_filter_override_flag);
1766
55.5k
        else
1767
55.5k
            infer(deblocking_filter_override_flag, 0);
1768
96.7k
        if (current->deblocking_filter_override_flag) {
1769
17.7k
            flag(slice_deblocking_filter_disabled_flag);
1770
17.4k
            if (!current->slice_deblocking_filter_disabled_flag) {
1771
10.4k
                se(slice_beta_offset_div2, -6, +6);
1772
9.78k
                se(slice_tc_offset_div2,   -6, +6);
1773
9.78k
            } else {
1774
7.07k
                infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1775
7.06k
                infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1776
564
            }
1777
79.0k
        } else {
1778
79.0k
            infer(slice_deblocking_filter_disabled_flag,
1779
79.0k
                  pps->pps_deblocking_filter_disabled_flag);
1780
79.0k
            infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1781
78.9k
            infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1782
5.59k
        }
1783
94.9k
        if (pps->pps_loop_filter_across_slices_enabled_flag &&
1784
94.9k
            (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1785
56.3k
             !current->slice_deblocking_filter_disabled_flag))
1786
94.9k
            flag(slice_loop_filter_across_slices_enabled_flag);
1787
45.7k
        else
1788
45.7k
            infer(slice_loop_filter_across_slices_enabled_flag,
1789
94.9k
                  pps->pps_loop_filter_across_slices_enabled_flag);
1790
94.9k
    }
1791
1792
95.2k
    if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1793
51.4k
        unsigned int num_entry_point_offsets_limit;
1794
51.4k
        if (!pps->tiles_enabled_flag && pps->entropy_coding_sync_enabled_flag)
1795
27.7k
            num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1796
23.7k
        else if (pps->tiles_enabled_flag && !pps->entropy_coding_sync_enabled_flag)
1797
10.4k
            num_entry_point_offsets_limit =
1798
10.4k
                (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1799
13.3k
        else
1800
13.3k
            num_entry_point_offsets_limit =
1801
13.3k
                (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1802
51.4k
        ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1803
1804
46.0k
        if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1805
2
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1806
2
                   "%"PRIu16".\n", current->num_entry_point_offsets);
1807
2
            return AVERROR_PATCHWELCOME;
1808
2
        }
1809
1810
46.0k
        if (current->num_entry_point_offsets > 0) {
1811
14.0k
            ue(offset_len_minus1, 0, 31);
1812
29.8k
            for (i = 0; i < current->num_entry_point_offsets; i++)
1813
21.1k
                ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[i], 1, i);
1814
9.37k
        }
1815
46.0k
    }
1816
1817
84.4k
    if (pps->slice_segment_header_extension_present_flag) {
1818
33.5k
        ue(slice_segment_header_extension_length, 0, 256);
1819
96.3k
        for (i = 0; i < current->slice_segment_header_extension_length; i++)
1820
67.0k
            us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1821
32.6k
    }
1822
1823
80.2k
    CHECK(FUNC(byte_alignment)(ctx, rw));
1824
1825
35.7k
    return 0;
1826
80.2k
}
cbs_h2645.c:cbs_h265_read_slice_segment_header
Line
Count
Source
1510
281k
{
1511
281k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1512
281k
    const H265RawSPS *sps;
1513
281k
    const H265RawPPS *pps;
1514
281k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1515
281k
    unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1516
281k
    unsigned int num_pic_total_curr = 0;
1517
281k
    int err, i;
1518
1519
281k
    HEADER("Slice Segment Header");
1520
1521
281k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1522
1523
281k
    flag(first_slice_segment_in_pic_flag);
1524
1525
279k
    if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1526
279k
        current->nal_unit_header.nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
1527
279k
        flag(no_output_of_prior_pics_flag);
1528
1529
279k
    ue(slice_pic_parameter_set_id, 0, 63);
1530
1531
266k
    pps = h265->pps[current->slice_pic_parameter_set_id];
1532
266k
    if (!pps) {
1533
62.4k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1534
62.4k
               current->slice_pic_parameter_set_id);
1535
62.4k
        return AVERROR_INVALIDDATA;
1536
62.4k
    }
1537
204k
    h265->active_pps = pps;
1538
1539
204k
    sps = h265->sps[pps->pps_seq_parameter_set_id];
1540
204k
    if (!sps) {
1541
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1542
0
               pps->pps_seq_parameter_set_id);
1543
0
        return AVERROR_INVALIDDATA;
1544
0
    }
1545
204k
    h265->active_sps = sps;
1546
1547
204k
    min_cb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3;
1548
204k
    ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size;
1549
204k
    ctb_size_y = 1 << ctb_log2_size_y;
1550
204k
    pic_width_in_ctbs_y =
1551
204k
        (sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1552
204k
    pic_height_in_ctbs_y =
1553
204k
        (sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1554
204k
    pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1555
1556
204k
    if (!current->first_slice_segment_in_pic_flag) {
1557
63.4k
        unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1558
63.4k
        if (pps->dependent_slice_segments_enabled_flag)
1559
63.4k
            flag(dependent_slice_segment_flag);
1560
51.7k
        else
1561
51.7k
            infer(dependent_slice_segment_flag, 0);
1562
63.4k
        u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1563
140k
    } else {
1564
140k
        infer(dependent_slice_segment_flag, 0);
1565
140k
    }
1566
1567
202k
    if (!current->dependent_slice_segment_flag) {
1568
574k
        for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1569
372k
            flags(slice_reserved_flag[i], 1, i);
1570
1571
201k
        ue(slice_type, 0, 2);
1572
1573
198k
        if (pps->output_flag_present_flag)
1574
198k
            flag(pic_output_flag);
1575
1576
196k
        if (sps->separate_colour_plane_flag)
1577
196k
            u(2, colour_plane_id, 0, 2);
1578
1579
193k
        if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1580
193k
            current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1581
185k
            const H265RawSTRefPicSet *rps;
1582
185k
            int dpb_slots_remaining;
1583
1584
185k
            ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1585
1586
181k
            flag(short_term_ref_pic_set_sps_flag);
1587
179k
            if (!current->short_term_ref_pic_set_sps_flag) {
1588
85.9k
                CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1589
85.9k
                                           sps->num_short_term_ref_pic_sets, sps));
1590
66.6k
                rps = &current->short_term_ref_pic_set;
1591
93.4k
            } else if (sps->num_short_term_ref_pic_sets > 1) {
1592
56.2k
                unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1593
56.2k
                u(idx_size, short_term_ref_pic_set_idx,
1594
52.9k
                  0, sps->num_short_term_ref_pic_sets - 1);
1595
52.9k
                rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1596
52.9k
            } else {
1597
37.2k
                infer(short_term_ref_pic_set_idx, 0);
1598
37.2k
                rps = &sps->st_ref_pic_set[0];
1599
37.2k
            }
1600
1601
156k
            dpb_slots_remaining = HEVC_MAX_DPB_SIZE - 1 -
1602
156k
                rps->num_negative_pics - rps->num_positive_pics;
1603
156k
            if (pps->pps_curr_pic_ref_enabled_flag &&
1604
156k
                (sps->sample_adaptive_offset_enabled_flag ||
1605
50.1k
                 !pps->pps_deblocking_filter_disabled_flag ||
1606
50.1k
                 pps->deblocking_filter_override_enabled_flag)) {
1607
                // This picture will occupy two DPB slots.
1608
47.8k
                if (dpb_slots_remaining == 0) {
1609
47
                    av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
1610
47
                           "short-term ref pic set contains too many pictures "
1611
47
                           "to use with current picture reference enabled.\n");
1612
47
                    return AVERROR_INVALIDDATA;
1613
47
                }
1614
47.7k
                --dpb_slots_remaining;
1615
47.7k
            }
1616
1617
156k
            num_pic_total_curr = 0;
1618
349k
            for (i = 0; i < rps->num_negative_pics; i++)
1619
192k
                if (rps->used_by_curr_pic_s0_flag[i])
1620
129k
                    ++num_pic_total_curr;
1621
267k
            for (i = 0; i < rps->num_positive_pics; i++)
1622
111k
                if (rps->used_by_curr_pic_s1_flag[i])
1623
35.9k
                    ++num_pic_total_curr;
1624
1625
156k
            if (sps->long_term_ref_pics_present_flag) {
1626
60.9k
                unsigned int idx_size;
1627
1628
60.9k
                if (sps->num_long_term_ref_pics_sps > 0) {
1629
18.7k
                    ue(num_long_term_sps, 0, FFMIN(sps->num_long_term_ref_pics_sps,
1630
16.3k
                                                   dpb_slots_remaining));
1631
16.3k
                    idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1632
16.3k
                    dpb_slots_remaining -= current->num_long_term_sps;
1633
42.1k
                } else {
1634
42.1k
                    infer(num_long_term_sps, 0);
1635
42.1k
                    idx_size = 0;
1636
42.1k
                }
1637
58.5k
                ue(num_long_term_pics, 0, dpb_slots_remaining);
1638
1639
126k
                for (i = 0; i < current->num_long_term_sps +
1640
126k
                                current->num_long_term_pics; i++) {
1641
77.9k
                    if (i < current->num_long_term_sps) {
1642
13.1k
                        if (sps->num_long_term_ref_pics_sps > 1)
1643
13.1k
                            us(idx_size, lt_idx_sps[i],
1644
10.4k
                               0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1645
10.4k
                        if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1646
8.95k
                            ++num_pic_total_curr;
1647
64.7k
                    } else {
1648
64.7k
                        ubs(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i], 1, i);
1649
60.8k
                        flags(used_by_curr_pic_lt_flag[i], 1, i);
1650
60.2k
                        if (current->used_by_curr_pic_lt_flag[i])
1651
34.1k
                            ++num_pic_total_curr;
1652
60.2k
                    }
1653
70.6k
                    flags(delta_poc_msb_present_flag[i], 1, i);
1654
70.5k
                    if (current->delta_poc_msb_present_flag[i])
1655
70.5k
                        ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1656
31.9k
                    else
1657
31.9k
                        infer(delta_poc_msb_cycle_lt[i], 0);
1658
70.5k
                }
1659
56.6k
            }
1660
1661
143k
            if (sps->sps_temporal_mvp_enabled_flag)
1662
143k
                flag(slice_temporal_mvp_enabled_flag);
1663
25.5k
            else
1664
25.5k
                infer(slice_temporal_mvp_enabled_flag, 0);
1665
1666
140k
            if (pps->pps_curr_pic_ref_enabled_flag)
1667
46.3k
                ++num_pic_total_curr;
1668
140k
        }
1669
1670
149k
        if (sps->sample_adaptive_offset_enabled_flag) {
1671
88.5k
            flag(slice_sao_luma_flag);
1672
87.9k
            if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1673
87.9k
                flag(slice_sao_chroma_flag);
1674
7.08k
            else
1675
7.08k
                infer(slice_sao_chroma_flag, 0);
1676
87.9k
        } else {
1677
60.7k
            infer(slice_sao_luma_flag,   0);
1678
60.7k
            infer(slice_sao_chroma_flag, 0);
1679
60.7k
        }
1680
1681
148k
        if (current->slice_type == HEVC_SLICE_P ||
1682
148k
            current->slice_type == HEVC_SLICE_B) {
1683
119k
            flag(num_ref_idx_active_override_flag);
1684
119k
            if (current->num_ref_idx_active_override_flag) {
1685
76.1k
                ue(num_ref_idx_l0_active_minus1, 0, 14);
1686
73.8k
                if (current->slice_type == HEVC_SLICE_B)
1687
73.8k
                    ue(num_ref_idx_l1_active_minus1, 0, 14);
1688
7.58k
                else
1689
7.58k
                    infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1690
73.8k
            } else {
1691
42.9k
                infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1692
42.9k
                infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1693
42.9k
            }
1694
1695
115k
            if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1696
27.5k
                CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1697
115k
                                                       num_pic_total_curr));
1698
1699
110k
            if (current->slice_type == HEVC_SLICE_B)
1700
110k
                flag(mvd_l1_zero_flag);
1701
109k
            if (pps->cabac_init_present_flag)
1702
109k
                flag(cabac_init_flag);
1703
13.7k
            else
1704
13.7k
                infer(cabac_init_flag, 0);
1705
109k
            if (current->slice_temporal_mvp_enabled_flag) {
1706
29.9k
                if (current->slice_type == HEVC_SLICE_B)
1707
29.9k
                    flag(collocated_from_l0_flag);
1708
5.29k
                else
1709
5.29k
                    infer(collocated_from_l0_flag, 1);
1710
29.8k
                if (current->collocated_from_l0_flag) {
1711
15.9k
                    if (current->num_ref_idx_l0_active_minus1 > 0)
1712
15.9k
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1713
6.20k
                    else
1714
6.20k
                        infer(collocated_ref_idx, 0);
1715
15.9k
                } else {
1716
13.9k
                    if (current->num_ref_idx_l1_active_minus1 > 0)
1717
13.9k
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1718
5.17k
                    else
1719
5.17k
                        infer(collocated_ref_idx, 0);
1720
13.9k
                }
1721
29.8k
            }
1722
1723
105k
            if ((pps->weighted_pred_flag   && current->slice_type == HEVC_SLICE_P) ||
1724
105k
                (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1725
42.2k
                CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1726
1727
86.8k
            ue(five_minus_max_num_merge_cand, 0, 4);
1728
77.0k
            if (sps->motion_vector_resolution_control_idc == 2)
1729
77.0k
                flag(use_integer_mv_flag);
1730
67.0k
            else
1731
67.0k
                infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1732
77.0k
        }
1733
1734
105k
        se(slice_qp_delta,
1735
98.5k
           - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1736
98.5k
           + 51 - (pps->init_qp_minus26 + 26));
1737
98.5k
        if (pps->pps_slice_chroma_qp_offsets_present_flag) {
1738
45.7k
            se(slice_cb_qp_offset, -12, +12);
1739
42.1k
            se(slice_cr_qp_offset, -12, +12);
1740
52.7k
        } else {
1741
52.7k
            infer(slice_cb_qp_offset, 0);
1742
52.7k
            infer(slice_cr_qp_offset, 0);
1743
52.7k
        }
1744
93.2k
        if (pps->pps_slice_act_qp_offsets_present_flag) {
1745
18.4k
            se(slice_act_y_qp_offset,
1746
17.4k
               -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1747
17.4k
               +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1748
17.4k
            se(slice_act_cb_qp_offset,
1749
16.2k
               -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1750
16.2k
               +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1751
16.2k
            se(slice_act_cr_qp_offset,
1752
16.2k
               -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1753
16.2k
               +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1754
74.7k
        } else {
1755
74.7k
            infer(slice_act_y_qp_offset,  0);
1756
74.7k
            infer(slice_act_cb_qp_offset, 0);
1757
74.7k
            infer(slice_act_cr_qp_offset, 0);
1758
74.7k
        }
1759
90.1k
        if (pps->chroma_qp_offset_list_enabled_flag)
1760
90.1k
            flag(cu_chroma_qp_offset_enabled_flag);
1761
79.8k
        else
1762
79.8k
            infer(cu_chroma_qp_offset_enabled_flag, 0);
1763
1764
89.5k
        if (pps->deblocking_filter_override_enabled_flag)
1765
89.5k
            flag(deblocking_filter_override_flag);
1766
50.8k
        else
1767
50.8k
            infer(deblocking_filter_override_flag, 0);
1768
89.0k
        if (current->deblocking_filter_override_flag) {
1769
15.7k
            flag(slice_deblocking_filter_disabled_flag);
1770
15.4k
            if (!current->slice_deblocking_filter_disabled_flag) {
1771
8.93k
                se(slice_beta_offset_div2, -6, +6);
1772
8.32k
                se(slice_tc_offset_div2,   -6, +6);
1773
8.32k
            } else {
1774
6.50k
                infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1775
6.50k
                infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1776
6.50k
            }
1777
73.3k
        } else {
1778
73.3k
            infer(slice_deblocking_filter_disabled_flag,
1779
73.3k
                  pps->pps_deblocking_filter_disabled_flag);
1780
73.3k
            infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1781
73.3k
            infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1782
73.3k
        }
1783
87.3k
        if (pps->pps_loop_filter_across_slices_enabled_flag &&
1784
87.3k
            (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1785
50.5k
             !current->slice_deblocking_filter_disabled_flag))
1786
87.3k
            flag(slice_loop_filter_across_slices_enabled_flag);
1787
43.7k
        else
1788
43.7k
            infer(slice_loop_filter_across_slices_enabled_flag,
1789
87.3k
                  pps->pps_loop_filter_across_slices_enabled_flag);
1790
87.3k
    }
1791
1792
87.3k
    if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1793
48.4k
        unsigned int num_entry_point_offsets_limit;
1794
48.4k
        if (!pps->tiles_enabled_flag && pps->entropy_coding_sync_enabled_flag)
1795
26.7k
            num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1796
21.6k
        else if (pps->tiles_enabled_flag && !pps->entropy_coding_sync_enabled_flag)
1797
10.1k
            num_entry_point_offsets_limit =
1798
10.1k
                (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1799
11.5k
        else
1800
11.5k
            num_entry_point_offsets_limit =
1801
11.5k
                (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1802
48.4k
        ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1803
1804
43.1k
        if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1805
2
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1806
2
                   "%"PRIu16".\n", current->num_entry_point_offsets);
1807
2
            return AVERROR_PATCHWELCOME;
1808
2
        }
1809
1810
43.1k
        if (current->num_entry_point_offsets > 0) {
1811
13.7k
            ue(offset_len_minus1, 0, 31);
1812
28.3k
            for (i = 0; i < current->num_entry_point_offsets; i++)
1813
19.9k
                ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[i], 1, i);
1814
9.11k
        }
1815
43.1k
    }
1816
1817
76.6k
    if (pps->slice_segment_header_extension_present_flag) {
1818
31.1k
        ue(slice_segment_header_extension_length, 0, 256);
1819
91.0k
        for (i = 0; i < current->slice_segment_header_extension_length; i++)
1820
64.1k
            us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1821
30.2k
    }
1822
1823
72.4k
    CHECK(FUNC(byte_alignment)(ctx, rw));
1824
1825
27.9k
    return 0;
1826
72.4k
}
cbs_h2645.c:cbs_h265_write_slice_segment_header
Line
Count
Source
1510
19.8k
{
1511
19.8k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1512
19.8k
    const H265RawSPS *sps;
1513
19.8k
    const H265RawPPS *pps;
1514
19.8k
    unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1515
19.8k
    unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1516
19.8k
    unsigned int num_pic_total_curr = 0;
1517
19.8k
    int err, i;
1518
1519
19.8k
    HEADER("Slice Segment Header");
1520
1521
19.8k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1522
1523
19.8k
    flag(first_slice_segment_in_pic_flag);
1524
1525
19.8k
    if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1526
19.8k
        current->nal_unit_header.nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
1527
19.8k
        flag(no_output_of_prior_pics_flag);
1528
1529
19.8k
    ue(slice_pic_parameter_set_id, 0, 63);
1530
1531
19.8k
    pps = h265->pps[current->slice_pic_parameter_set_id];
1532
19.8k
    if (!pps) {
1533
3.42k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1534
3.42k
               current->slice_pic_parameter_set_id);
1535
3.42k
        return AVERROR_INVALIDDATA;
1536
3.42k
    }
1537
16.4k
    h265->active_pps = pps;
1538
1539
16.4k
    sps = h265->sps[pps->pps_seq_parameter_set_id];
1540
16.4k
    if (!sps) {
1541
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1542
0
               pps->pps_seq_parameter_set_id);
1543
0
        return AVERROR_INVALIDDATA;
1544
0
    }
1545
16.4k
    h265->active_sps = sps;
1546
1547
16.4k
    min_cb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3;
1548
16.4k
    ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size;
1549
16.4k
    ctb_size_y = 1 << ctb_log2_size_y;
1550
16.4k
    pic_width_in_ctbs_y =
1551
16.4k
        (sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1552
16.4k
    pic_height_in_ctbs_y =
1553
16.4k
        (sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1554
16.4k
    pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1555
1556
16.4k
    if (!current->first_slice_segment_in_pic_flag) {
1557
1.74k
        unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1558
1.74k
        if (pps->dependent_slice_segments_enabled_flag)
1559
1.74k
            flag(dependent_slice_segment_flag);
1560
1.27k
        else
1561
1.27k
            infer(dependent_slice_segment_flag, 0);
1562
1.72k
        u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1563
14.7k
    } else {
1564
14.7k
        infer(dependent_slice_segment_flag, 0);
1565
14.7k
    }
1566
1567
15.9k
    if (!current->dependent_slice_segment_flag) {
1568
32.3k
        for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1569
16.7k
            flags(slice_reserved_flag[i], 1, i);
1570
1571
15.5k
        ue(slice_type, 0, 2);
1572
1573
15.5k
        if (pps->output_flag_present_flag)
1574
15.5k
            flag(pic_output_flag);
1575
1576
15.5k
        if (sps->separate_colour_plane_flag)
1577
15.5k
            u(2, colour_plane_id, 0, 2);
1578
1579
15.5k
        if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1580
15.5k
            current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1581
15.2k
            const H265RawSTRefPicSet *rps;
1582
15.2k
            int dpb_slots_remaining;
1583
1584
15.2k
            ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1585
1586
14.4k
            flag(short_term_ref_pic_set_sps_flag);
1587
14.4k
            if (!current->short_term_ref_pic_set_sps_flag) {
1588
3.28k
                CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1589
3.28k
                                           sps->num_short_term_ref_pic_sets, sps));
1590
1.84k
                rps = &current->short_term_ref_pic_set;
1591
11.1k
            } else if (sps->num_short_term_ref_pic_sets > 1) {
1592
9.03k
                unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1593
9.03k
                u(idx_size, short_term_ref_pic_set_idx,
1594
8.82k
                  0, sps->num_short_term_ref_pic_sets - 1);
1595
8.82k
                rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1596
8.82k
            } else {
1597
2.08k
                infer(short_term_ref_pic_set_idx, 0);
1598
1.18k
                rps = &sps->st_ref_pic_set[0];
1599
1.18k
            }
1600
1601
11.8k
            dpb_slots_remaining = HEVC_MAX_DPB_SIZE - 1 -
1602
11.8k
                rps->num_negative_pics - rps->num_positive_pics;
1603
11.8k
            if (pps->pps_curr_pic_ref_enabled_flag &&
1604
11.8k
                (sps->sample_adaptive_offset_enabled_flag ||
1605
4.87k
                 !pps->pps_deblocking_filter_disabled_flag ||
1606
4.87k
                 pps->deblocking_filter_override_enabled_flag)) {
1607
                // This picture will occupy two DPB slots.
1608
4.87k
                if (dpb_slots_remaining == 0) {
1609
10
                    av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
1610
10
                           "short-term ref pic set contains too many pictures "
1611
10
                           "to use with current picture reference enabled.\n");
1612
10
                    return AVERROR_INVALIDDATA;
1613
10
                }
1614
4.86k
                --dpb_slots_remaining;
1615
4.86k
            }
1616
1617
11.8k
            num_pic_total_curr = 0;
1618
28.4k
            for (i = 0; i < rps->num_negative_pics; i++)
1619
16.6k
                if (rps->used_by_curr_pic_s0_flag[i])
1620
15.7k
                    ++num_pic_total_curr;
1621
17.6k
            for (i = 0; i < rps->num_positive_pics; i++)
1622
5.76k
                if (rps->used_by_curr_pic_s1_flag[i])
1623
2.34k
                    ++num_pic_total_curr;
1624
1625
11.8k
            if (sps->long_term_ref_pics_present_flag) {
1626
5.47k
                unsigned int idx_size;
1627
1628
5.47k
                if (sps->num_long_term_ref_pics_sps > 0) {
1629
3.53k
                    ue(num_long_term_sps, 0, FFMIN(sps->num_long_term_ref_pics_sps,
1630
3.53k
                                                   dpb_slots_remaining));
1631
3.53k
                    idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1632
3.53k
                    dpb_slots_remaining -= current->num_long_term_sps;
1633
3.53k
                } else {
1634
1.94k
                    infer(num_long_term_sps, 0);
1635
1.92k
                    idx_size = 0;
1636
1.92k
                }
1637
5.46k
                ue(num_long_term_pics, 0, dpb_slots_remaining);
1638
1639
7.85k
                for (i = 0; i < current->num_long_term_sps +
1640
7.85k
                                current->num_long_term_pics; i++) {
1641
2.42k
                    if (i < current->num_long_term_sps) {
1642
463
                        if (sps->num_long_term_ref_pics_sps > 1)
1643
463
                            us(idx_size, lt_idx_sps[i],
1644
463
                               0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1645
463
                        if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1646
458
                            ++num_pic_total_curr;
1647
1.95k
                    } else {
1648
1.95k
                        ubs(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i], 1, i);
1649
1.93k
                        flags(used_by_curr_pic_lt_flag[i], 1, i);
1650
1.93k
                        if (current->used_by_curr_pic_lt_flag[i])
1651
1.60k
                            ++num_pic_total_curr;
1652
1.93k
                    }
1653
2.39k
                    flags(delta_poc_msb_present_flag[i], 1, i);
1654
2.39k
                    if (current->delta_poc_msb_present_flag[i])
1655
2.39k
                        ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1656
884
                    else
1657
884
                        infer(delta_poc_msb_cycle_lt[i], 0);
1658
2.39k
                }
1659
5.45k
            }
1660
1661
11.7k
            if (sps->sps_temporal_mvp_enabled_flag)
1662
11.7k
                flag(slice_temporal_mvp_enabled_flag);
1663
4.77k
            else
1664
4.77k
                infer(slice_temporal_mvp_enabled_flag, 0);
1665
1666
11.3k
            if (pps->pps_curr_pic_ref_enabled_flag)
1667
4.73k
                ++num_pic_total_curr;
1668
11.3k
        }
1669
1670
11.5k
        if (sps->sample_adaptive_offset_enabled_flag) {
1671
9.76k
            flag(slice_sao_luma_flag);
1672
9.76k
            if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1673
9.76k
                flag(slice_sao_chroma_flag);
1674
741
            else
1675
741
                infer(slice_sao_chroma_flag, 0);
1676
9.76k
        } else {
1677
1.80k
            infer(slice_sao_luma_flag,   0);
1678
1.80k
            infer(slice_sao_chroma_flag, 0);
1679
1.80k
        }
1680
1681
11.5k
        if (current->slice_type == HEVC_SLICE_P ||
1682
11.5k
            current->slice_type == HEVC_SLICE_B) {
1683
11.0k
            flag(num_ref_idx_active_override_flag);
1684
11.0k
            if (current->num_ref_idx_active_override_flag) {
1685
8.16k
                ue(num_ref_idx_l0_active_minus1, 0, 14);
1686
8.16k
                if (current->slice_type == HEVC_SLICE_B)
1687
8.16k
                    ue(num_ref_idx_l1_active_minus1, 0, 14);
1688
380
                else
1689
380
                    infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1690
8.16k
            } else {
1691
2.84k
                infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1692
2.62k
                infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1693
2.62k
            }
1694
1695
10.6k
            if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1696
4.11k
                CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1697
10.6k
                                                       num_pic_total_curr));
1698
1699
10.2k
            if (current->slice_type == HEVC_SLICE_B)
1700
10.2k
                flag(mvd_l1_zero_flag);
1701
10.2k
            if (pps->cabac_init_present_flag)
1702
10.2k
                flag(cabac_init_flag);
1703
187
            else
1704
187
                infer(cabac_init_flag, 0);
1705
10.2k
            if (current->slice_temporal_mvp_enabled_flag) {
1706
1.73k
                if (current->slice_type == HEVC_SLICE_B)
1707
1.73k
                    flag(collocated_from_l0_flag);
1708
311
                else
1709
311
                    infer(collocated_from_l0_flag, 1);
1710
1.73k
                if (current->collocated_from_l0_flag) {
1711
1.62k
                    if (current->num_ref_idx_l0_active_minus1 > 0)
1712
1.62k
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1713
548
                    else
1714
548
                        infer(collocated_ref_idx, 0);
1715
1.62k
                } else {
1716
109
                    if (current->num_ref_idx_l1_active_minus1 > 0)
1717
109
                        ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1718
87
                    else
1719
87
                        infer(collocated_ref_idx, 0);
1720
109
                }
1721
1.73k
            }
1722
1723
10.2k
            if ((pps->weighted_pred_flag   && current->slice_type == HEVC_SLICE_P) ||
1724
10.2k
                (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1725
3.93k
                CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1726
1727
10.0k
            ue(five_minus_max_num_merge_cand, 0, 4);
1728
10.0k
            if (sps->motion_vector_resolution_control_idc == 2)
1729
10.0k
                flag(use_integer_mv_flag);
1730
9.56k
            else
1731
9.56k
                infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1732
10.0k
        }
1733
1734
10.5k
        se(slice_qp_delta,
1735
10.5k
           - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1736
10.5k
           + 51 - (pps->init_qp_minus26 + 26));
1737
10.5k
        if (pps->pps_slice_chroma_qp_offsets_present_flag) {
1738
5.34k
            se(slice_cb_qp_offset, -12, +12);
1739
5.34k
            se(slice_cr_qp_offset, -12, +12);
1740
5.34k
        } else {
1741
5.19k
            infer(slice_cb_qp_offset, 0);
1742
4.96k
            infer(slice_cr_qp_offset, 0);
1743
4.96k
        }
1744
10.3k
        if (pps->pps_slice_act_qp_offsets_present_flag) {
1745
1.04k
            se(slice_act_y_qp_offset,
1746
1.03k
               -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1747
1.03k
               +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1748
1.03k
            se(slice_act_cb_qp_offset,
1749
708
               -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1750
708
               +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1751
708
            se(slice_act_cr_qp_offset,
1752
708
               -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1753
708
               +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1754
9.27k
        } else {
1755
9.27k
            infer(slice_act_y_qp_offset,  0);
1756
7.94k
            infer(slice_act_cb_qp_offset, 0);
1757
7.38k
            infer(slice_act_cr_qp_offset, 0);
1758
7.38k
        }
1759
8.01k
        if (pps->chroma_qp_offset_list_enabled_flag)
1760
8.01k
            flag(cu_chroma_qp_offset_enabled_flag);
1761
5.15k
        else
1762
5.15k
            infer(cu_chroma_qp_offset_enabled_flag, 0);
1763
1764
7.95k
        if (pps->deblocking_filter_override_enabled_flag)
1765
7.95k
            flag(deblocking_filter_override_flag);
1766
4.69k
        else
1767
4.69k
            infer(deblocking_filter_override_flag, 0);
1768
7.71k
        if (current->deblocking_filter_override_flag) {
1769
2.03k
            flag(slice_deblocking_filter_disabled_flag);
1770
2.03k
            if (!current->slice_deblocking_filter_disabled_flag) {
1771
1.46k
                se(slice_beta_offset_div2, -6, +6);
1772
1.46k
                se(slice_tc_offset_div2,   -6, +6);
1773
1.46k
            } else {
1774
574
                infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1775
564
                infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1776
564
            }
1777
5.67k
        } else {
1778
5.67k
            infer(slice_deblocking_filter_disabled_flag,
1779
5.67k
                  pps->pps_deblocking_filter_disabled_flag);
1780
5.67k
            infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1781
5.59k
            infer(slice_tc_offset_div2,   pps->pps_tc_offset_div2);
1782
5.59k
        }
1783
7.61k
        if (pps->pps_loop_filter_across_slices_enabled_flag &&
1784
7.61k
            (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1785
5.87k
             !current->slice_deblocking_filter_disabled_flag))
1786
7.61k
            flag(slice_loop_filter_across_slices_enabled_flag);
1787
2.05k
        else
1788
2.05k
            infer(slice_loop_filter_across_slices_enabled_flag,
1789
7.61k
                  pps->pps_loop_filter_across_slices_enabled_flag);
1790
7.61k
    }
1791
1792
7.93k
    if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1793
3.04k
        unsigned int num_entry_point_offsets_limit;
1794
3.04k
        if (!pps->tiles_enabled_flag && pps->entropy_coding_sync_enabled_flag)
1795
972
            num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1796
2.07k
        else if (pps->tiles_enabled_flag && !pps->entropy_coding_sync_enabled_flag)
1797
255
            num_entry_point_offsets_limit =
1798
255
                (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1799
1.82k
        else
1800
1.82k
            num_entry_point_offsets_limit =
1801
1.82k
                (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1802
3.04k
        ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1803
1804
2.87k
        if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1805
0
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1806
0
                   "%"PRIu16".\n", current->num_entry_point_offsets);
1807
0
            return AVERROR_PATCHWELCOME;
1808
0
        }
1809
1810
2.87k
        if (current->num_entry_point_offsets > 0) {
1811
267
            ue(offset_len_minus1, 0, 31);
1812
1.49k
            for (i = 0; i < current->num_entry_point_offsets; i++)
1813
1.22k
                ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[i], 1, i);
1814
267
        }
1815
2.87k
    }
1816
1817
7.75k
    if (pps->slice_segment_header_extension_present_flag) {
1818
2.40k
        ue(slice_segment_header_extension_length, 0, 256);
1819
5.30k
        for (i = 0; i < current->slice_segment_header_extension_length; i++)
1820
2.90k
            us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1821
2.40k
    }
1822
1823
7.75k
    CHECK(FUNC(byte_alignment)(ctx, rw));
1824
1825
7.75k
    return 0;
1826
7.75k
}
1827
1828
SEI_FUNC(sei_buffering_period, (CodedBitstreamContext *ctx, RWContext *rw,
1829
                                H265RawSEIBufferingPeriod *current,
1830
                                SEIMessageState *sei))
1831
25.7k
{
1832
25.7k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1833
25.7k
    const H265RawSPS *sps;
1834
25.7k
    const H265RawHRDParameters *hrd;
1835
25.7k
    int err, i, length;
1836
1837
#ifdef READ
1838
    int start_pos, end_pos;
1839
    start_pos = get_bits_count(rw);
1840
#endif
1841
1842
25.7k
    HEADER("Buffering Period");
1843
1844
25.7k
    ue(bp_seq_parameter_set_id, 0, HEVC_MAX_SPS_COUNT - 1);
1845
1846
21.0k
    sps = h265->sps[current->bp_seq_parameter_set_id];
1847
21.0k
    if (!sps) {
1848
3.42k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1849
3.42k
               current->bp_seq_parameter_set_id);
1850
3.42k
        return AVERROR_INVALIDDATA;
1851
3.42k
    }
1852
17.6k
    h265->active_sps = sps;
1853
1854
17.6k
    if (!sps->vui_parameters_present_flag ||
1855
17.6k
        !sps->vui.vui_hrd_parameters_present_flag) {
1856
4.30k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1857
4.30k
               "HRD parameters to be present in SPS.\n");
1858
4.30k
        return AVERROR_INVALIDDATA;
1859
4.30k
    }
1860
13.3k
    hrd = &sps->vui.hrd_parameters;
1861
13.3k
    if (!hrd->nal_hrd_parameters_present_flag &&
1862
13.3k
        !hrd->vcl_hrd_parameters_present_flag) {
1863
683
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1864
683
               "NAL or VCL HRD parameters to be present.\n");
1865
683
        return AVERROR_INVALIDDATA;
1866
683
    }
1867
1868
12.6k
    if (!hrd->sub_pic_hrd_params_present_flag)
1869
12.6k
        flag(irap_cpb_params_present_flag);
1870
3.64k
    else
1871
3.64k
        infer(irap_cpb_params_present_flag, 0);
1872
12.6k
    if (current->irap_cpb_params_present_flag) {
1873
2.79k
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1874
2.79k
        ub(length, cpb_delay_offset);
1875
2.51k
        length = hrd->dpb_output_delay_length_minus1 + 1;
1876
2.51k
        ub(length, dpb_delay_offset);
1877
9.87k
    } else {
1878
9.87k
        infer(cpb_delay_offset, 0);
1879
9.87k
        infer(dpb_delay_offset, 0);
1880
3.63k
    }
1881
1882
11.9k
    flag(concatenation_flag);
1883
1884
11.8k
    length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1885
11.8k
    ub(length, au_cpb_removal_delay_delta_minus1);
1886
1887
11.1k
    if (hrd->nal_hrd_parameters_present_flag) {
1888
42.5k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1889
33.7k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1890
1891
33.7k
            ubs(length, nal_initial_cpb_removal_delay[i], 1, i);
1892
33.0k
            ubs(length, nal_initial_cpb_removal_offset[i], 1, i);
1893
1894
32.9k
            if (hrd->sub_pic_hrd_params_present_flag ||
1895
32.9k
                current->irap_cpb_params_present_flag) {
1896
8.46k
                ubs(length, nal_initial_alt_cpb_removal_delay[i], 1, i);
1897
8.09k
                ubs(length, nal_initial_alt_cpb_removal_offset[i], 1, i);
1898
8.09k
            }
1899
32.9k
        }
1900
10.0k
    }
1901
9.84k
    if (hrd->vcl_hrd_parameters_present_flag) {
1902
13.7k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1903
12.4k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1904
1905
12.4k
            ubs(length, vcl_initial_cpb_removal_delay[i], 1, i);
1906
12.3k
            ubs(length, vcl_initial_cpb_removal_offset[i], 1, i);
1907
1908
12.2k
            if (hrd->sub_pic_hrd_params_present_flag ||
1909
12.2k
                current->irap_cpb_params_present_flag) {
1910
10.8k
                ubs(length, vcl_initial_alt_cpb_removal_delay[i], 1, i);
1911
10.0k
                ubs(length, vcl_initial_alt_cpb_removal_offset[i], 1, i);
1912
10.0k
            }
1913
12.2k
        }
1914
2.72k
    }
1915
1916
#ifdef READ
1917
4.72k
    end_pos = get_bits_count(rw);
1918
4.72k
    if (cbs_h265_payload_extension_present(rw, sei->payload_size,
1919
4.72k
                                           end_pos - start_pos))
1920
4.72k
        flag(use_alt_cpb_params_flag);
1921
221
    else
1922
221
        infer(use_alt_cpb_params_flag, 0);
1923
#else
1924
    // If unknown extension data exists, then use_alt_cpb_params_flag is
1925
    // coded in the bitstream and must be written even if it's 0.
1926
3.72k
    if (current->use_alt_cpb_params_flag || sei->extension_present) {
1927
3.72k
        flag(use_alt_cpb_params_flag);
1928
        // Ensure this bit is not the last in the payload by making the
1929
        // more_data_in_payload() check evaluate to true, so it may not
1930
        // be mistaken as something else by decoders.
1931
3.72k
        sei->extension_present = 1;
1932
3.72k
    }
1933
3.72k
#endif
1934
1935
8.44k
    return 0;
1936
3.72k
}
cbs_h2645.c:cbs_h265_read_sei_buffering_period
Line
Count
Source
1831
21.2k
{
1832
21.2k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1833
21.2k
    const H265RawSPS *sps;
1834
21.2k
    const H265RawHRDParameters *hrd;
1835
21.2k
    int err, i, length;
1836
1837
21.2k
#ifdef READ
1838
21.2k
    int start_pos, end_pos;
1839
21.2k
    start_pos = get_bits_count(rw);
1840
21.2k
#endif
1841
1842
21.2k
    HEADER("Buffering Period");
1843
1844
21.2k
    ue(bp_seq_parameter_set_id, 0, HEVC_MAX_SPS_COUNT - 1);
1845
1846
16.6k
    sps = h265->sps[current->bp_seq_parameter_set_id];
1847
16.6k
    if (!sps) {
1848
3.37k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1849
3.37k
               current->bp_seq_parameter_set_id);
1850
3.37k
        return AVERROR_INVALIDDATA;
1851
3.37k
    }
1852
13.2k
    h265->active_sps = sps;
1853
1854
13.2k
    if (!sps->vui_parameters_present_flag ||
1855
13.2k
        !sps->vui.vui_hrd_parameters_present_flag) {
1856
4.22k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1857
4.22k
               "HRD parameters to be present in SPS.\n");
1858
4.22k
        return AVERROR_INVALIDDATA;
1859
4.22k
    }
1860
9.00k
    hrd = &sps->vui.hrd_parameters;
1861
9.00k
    if (!hrd->nal_hrd_parameters_present_flag &&
1862
9.00k
        !hrd->vcl_hrd_parameters_present_flag) {
1863
683
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1864
683
               "NAL or VCL HRD parameters to be present.\n");
1865
683
        return AVERROR_INVALIDDATA;
1866
683
    }
1867
1868
8.32k
    if (!hrd->sub_pic_hrd_params_present_flag)
1869
8.32k
        flag(irap_cpb_params_present_flag);
1870
3.08k
    else
1871
3.08k
        infer(irap_cpb_params_present_flag, 0);
1872
8.32k
    if (current->irap_cpb_params_present_flag) {
1873
2.08k
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1874
2.08k
        ub(length, cpb_delay_offset);
1875
1.94k
        length = hrd->dpb_output_delay_length_minus1 + 1;
1876
1.94k
        ub(length, dpb_delay_offset);
1877
6.23k
    } else {
1878
6.23k
        infer(cpb_delay_offset, 0);
1879
6.23k
        infer(dpb_delay_offset, 0);
1880
6.23k
    }
1881
1882
7.89k
    flag(concatenation_flag);
1883
1884
7.86k
    length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1885
7.86k
    ub(length, au_cpb_removal_delay_delta_minus1);
1886
1887
7.14k
    if (hrd->nal_hrd_parameters_present_flag) {
1888
26.0k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1889
20.6k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1890
1891
20.6k
            ubs(length, nal_initial_cpb_removal_delay[i], 1, i);
1892
19.9k
            ubs(length, nal_initial_cpb_removal_offset[i], 1, i);
1893
1894
19.8k
            if (hrd->sub_pic_hrd_params_present_flag ||
1895
19.8k
                current->irap_cpb_params_present_flag) {
1896
7.59k
                ubs(length, nal_initial_alt_cpb_removal_delay[i], 1, i);
1897
7.29k
                ubs(length, nal_initial_alt_cpb_removal_offset[i], 1, i);
1898
7.29k
            }
1899
19.8k
        }
1900
6.55k
    }
1901
5.97k
    if (hrd->vcl_hrd_parameters_present_flag) {
1902
8.55k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1903
7.57k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1904
1905
7.57k
            ubs(length, vcl_initial_cpb_removal_delay[i], 1, i);
1906
7.45k
            ubs(length, vcl_initial_cpb_removal_offset[i], 1, i);
1907
1908
7.36k
            if (hrd->sub_pic_hrd_params_present_flag ||
1909
7.36k
                current->irap_cpb_params_present_flag) {
1910
6.03k
                ubs(length, vcl_initial_alt_cpb_removal_delay[i], 1, i);
1911
5.24k
                ubs(length, vcl_initial_alt_cpb_removal_offset[i], 1, i);
1912
5.24k
            }
1913
7.36k
        }
1914
2.22k
    }
1915
1916
4.72k
#ifdef READ
1917
4.72k
    end_pos = get_bits_count(rw);
1918
4.72k
    if (cbs_h265_payload_extension_present(rw, sei->payload_size,
1919
4.72k
                                           end_pos - start_pos))
1920
4.72k
        flag(use_alt_cpb_params_flag);
1921
221
    else
1922
221
        infer(use_alt_cpb_params_flag, 0);
1923
#else
1924
    // If unknown extension data exists, then use_alt_cpb_params_flag is
1925
    // coded in the bitstream and must be written even if it's 0.
1926
    if (current->use_alt_cpb_params_flag || sei->extension_present) {
1927
        flag(use_alt_cpb_params_flag);
1928
        // Ensure this bit is not the last in the payload by making the
1929
        // more_data_in_payload() check evaluate to true, so it may not
1930
        // be mistaken as something else by decoders.
1931
        sei->extension_present = 1;
1932
    }
1933
#endif
1934
1935
4.72k
    return 0;
1936
4.72k
}
cbs_h2645.c:cbs_h265_write_sei_buffering_period
Line
Count
Source
1831
4.47k
{
1832
4.47k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1833
4.47k
    const H265RawSPS *sps;
1834
4.47k
    const H265RawHRDParameters *hrd;
1835
4.47k
    int err, i, length;
1836
1837
#ifdef READ
1838
    int start_pos, end_pos;
1839
    start_pos = get_bits_count(rw);
1840
#endif
1841
1842
4.47k
    HEADER("Buffering Period");
1843
1844
4.47k
    ue(bp_seq_parameter_set_id, 0, HEVC_MAX_SPS_COUNT - 1);
1845
1846
4.47k
    sps = h265->sps[current->bp_seq_parameter_set_id];
1847
4.47k
    if (!sps) {
1848
43
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1849
43
               current->bp_seq_parameter_set_id);
1850
43
        return AVERROR_INVALIDDATA;
1851
43
    }
1852
4.43k
    h265->active_sps = sps;
1853
1854
4.43k
    if (!sps->vui_parameters_present_flag ||
1855
4.43k
        !sps->vui.vui_hrd_parameters_present_flag) {
1856
82
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1857
82
               "HRD parameters to be present in SPS.\n");
1858
82
        return AVERROR_INVALIDDATA;
1859
82
    }
1860
4.35k
    hrd = &sps->vui.hrd_parameters;
1861
4.35k
    if (!hrd->nal_hrd_parameters_present_flag &&
1862
4.35k
        !hrd->vcl_hrd_parameters_present_flag) {
1863
0
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1864
0
               "NAL or VCL HRD parameters to be present.\n");
1865
0
        return AVERROR_INVALIDDATA;
1866
0
    }
1867
1868
4.35k
    if (!hrd->sub_pic_hrd_params_present_flag)
1869
4.35k
        flag(irap_cpb_params_present_flag);
1870
561
    else
1871
561
        infer(irap_cpb_params_present_flag, 0);
1872
4.34k
    if (current->irap_cpb_params_present_flag) {
1873
707
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1874
707
        ub(length, cpb_delay_offset);
1875
571
        length = hrd->dpb_output_delay_length_minus1 + 1;
1876
571
        ub(length, dpb_delay_offset);
1877
3.63k
    } else {
1878
3.63k
        infer(cpb_delay_offset, 0);
1879
3.63k
        infer(dpb_delay_offset, 0);
1880
3.63k
    }
1881
1882
4.02k
    flag(concatenation_flag);
1883
1884
4.02k
    length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1885
4.02k
    ub(length, au_cpb_removal_delay_delta_minus1);
1886
1887
4.02k
    if (hrd->nal_hrd_parameters_present_flag) {
1888
16.4k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1889
13.1k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1890
1891
13.1k
            ubs(length, nal_initial_cpb_removal_delay[i], 1, i);
1892
13.0k
            ubs(length, nal_initial_cpb_removal_offset[i], 1, i);
1893
1894
13.0k
            if (hrd->sub_pic_hrd_params_present_flag ||
1895
13.0k
                current->irap_cpb_params_present_flag) {
1896
865
                ubs(length, nal_initial_alt_cpb_removal_delay[i], 1, i);
1897
802
                ubs(length, nal_initial_alt_cpb_removal_offset[i], 1, i);
1898
802
            }
1899
13.0k
        }
1900
3.54k
    }
1901
3.86k
    if (hrd->vcl_hrd_parameters_present_flag) {
1902
5.19k
        for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1903
4.85k
            length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1904
1905
4.85k
            ubs(length, vcl_initial_cpb_removal_delay[i], 1, i);
1906
4.84k
            ubs(length, vcl_initial_cpb_removal_offset[i], 1, i);
1907
1908
4.84k
            if (hrd->sub_pic_hrd_params_present_flag ||
1909
4.84k
                current->irap_cpb_params_present_flag) {
1910
4.84k
                ubs(length, vcl_initial_alt_cpb_removal_delay[i], 1, i);
1911
4.78k
                ubs(length, vcl_initial_alt_cpb_removal_offset[i], 1, i);
1912
4.78k
            }
1913
4.84k
        }
1914
497
    }
1915
1916
#ifdef READ
1917
    end_pos = get_bits_count(rw);
1918
    if (cbs_h265_payload_extension_present(rw, sei->payload_size,
1919
                                           end_pos - start_pos))
1920
        flag(use_alt_cpb_params_flag);
1921
    else
1922
        infer(use_alt_cpb_params_flag, 0);
1923
#else
1924
    // If unknown extension data exists, then use_alt_cpb_params_flag is
1925
    // coded in the bitstream and must be written even if it's 0.
1926
3.72k
    if (current->use_alt_cpb_params_flag || sei->extension_present) {
1927
3.72k
        flag(use_alt_cpb_params_flag);
1928
        // Ensure this bit is not the last in the payload by making the
1929
        // more_data_in_payload() check evaluate to true, so it may not
1930
        // be mistaken as something else by decoders.
1931
3.72k
        sei->extension_present = 1;
1932
3.72k
    }
1933
3.72k
#endif
1934
1935
3.72k
    return 0;
1936
3.72k
}
1937
1938
SEI_FUNC(sei_pic_timing, (CodedBitstreamContext *ctx, RWContext *rw,
1939
                          H265RawSEIPicTiming *current, SEIMessageState *sei))
1940
48.3k
{
1941
48.3k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1942
48.3k
    const H265RawSPS *sps;
1943
48.3k
    const H265RawHRDParameters *hrd;
1944
48.3k
    int err, expected_source_scan_type, i, length;
1945
1946
48.3k
    HEADER("Picture Timing");
1947
1948
48.3k
    sps = h265->active_sps;
1949
48.3k
    if (!sps) {
1950
3.04k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1951
3.04k
               "No active SPS for pic_timing.\n");
1952
3.04k
        return AVERROR_INVALIDDATA;
1953
3.04k
    }
1954
1955
45.2k
    expected_source_scan_type = 2 -
1956
45.2k
        2 * sps->profile_tier_level.general_interlaced_source_flag -
1957
45.2k
        sps->profile_tier_level.general_progressive_source_flag;
1958
1959
45.2k
    if (sps->vui.frame_field_info_present_flag) {
1960
4.64k
        u(4, pic_struct, 0, 12);
1961
3.08k
        u(2, source_scan_type,
1962
2.28k
          expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1963
2.28k
          expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1964
2.28k
        flag(duplicate_flag);
1965
40.6k
    } else {
1966
40.6k
        infer(pic_struct, 0);
1967
40.4k
        infer(source_scan_type,
1968
5.95k
              expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1969
40.4k
        infer(duplicate_flag, 0);
1970
5.94k
    }
1971
1972
42.5k
    if (sps->vui_parameters_present_flag &&
1973
42.5k
        sps->vui.vui_hrd_parameters_present_flag)
1974
9.62k
        hrd = &sps->vui.hrd_parameters;
1975
32.9k
    else
1976
32.9k
        hrd = NULL;
1977
42.5k
    if (hrd && (hrd->nal_hrd_parameters_present_flag ||
1978
9.62k
                hrd->vcl_hrd_parameters_present_flag)) {
1979
9.22k
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1980
9.22k
        ub(length, au_cpb_removal_delay_minus1);
1981
1982
8.98k
        length = hrd->dpb_output_delay_length_minus1 + 1;
1983
8.98k
        ub(length, pic_dpb_output_delay);
1984
1985
8.26k
        if (hrd->sub_pic_hrd_params_present_flag) {
1986
7.33k
            length = hrd->dpb_output_delay_du_length_minus1 + 1;
1987
7.33k
            ub(length, pic_dpb_output_du_delay);
1988
7.33k
        }
1989
1990
8.19k
        if (hrd->sub_pic_hrd_params_present_flag &&
1991
8.19k
            hrd->sub_pic_cpb_params_in_pic_timing_sei_flag) {
1992
            // Each decoding unit must contain at least one slice segment.
1993
6.12k
            ue(num_decoding_units_minus1, 0, HEVC_MAX_SLICE_SEGMENTS);
1994
5.53k
            flag(du_common_cpb_removal_delay_flag);
1995
1996
5.51k
            length = hrd->du_cpb_removal_delay_increment_length_minus1 + 1;
1997
5.51k
            if (current->du_common_cpb_removal_delay_flag)
1998
3.85k
                ub(length, du_common_cpb_removal_delay_increment_minus1);
1999
2000
4.61k
            for (i = 0; i <= current->num_decoding_units_minus1; i++) {
2001
2.61k
                ues(num_nalus_in_du_minus1[i],
2002
2.45k
                    0, HEVC_MAX_SLICE_SEGMENTS, 1, i);
2003
2.45k
                if (!current->du_common_cpb_removal_delay_flag &&
2004
2.45k
                    i < current->num_decoding_units_minus1)
2005
2.45k
                    ubs(length, du_cpb_removal_delay_increment_minus1[i], 1, i);
2006
2.45k
            }
2007
2.21k
        }
2008
8.19k
    }
2009
2010
37.4k
    return 0;
2011
42.5k
}
cbs_h2645.c:cbs_h265_read_sei_pic_timing
Line
Count
Source
1940
41.6k
{
1941
41.6k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1942
41.6k
    const H265RawSPS *sps;
1943
41.6k
    const H265RawHRDParameters *hrd;
1944
41.6k
    int err, expected_source_scan_type, i, length;
1945
1946
41.6k
    HEADER("Picture Timing");
1947
1948
41.6k
    sps = h265->active_sps;
1949
41.6k
    if (!sps) {
1950
2.97k
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1951
2.97k
               "No active SPS for pic_timing.\n");
1952
2.97k
        return AVERROR_INVALIDDATA;
1953
2.97k
    }
1954
1955
38.6k
    expected_source_scan_type = 2 -
1956
38.6k
        2 * sps->profile_tier_level.general_interlaced_source_flag -
1957
38.6k
        sps->profile_tier_level.general_progressive_source_flag;
1958
1959
38.6k
    if (sps->vui.frame_field_info_present_flag) {
1960
4.13k
        u(4, pic_struct, 0, 12);
1961
2.58k
        u(2, source_scan_type,
1962
1.90k
          expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1963
1.90k
          expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1964
1.90k
        flag(duplicate_flag);
1965
34.5k
    } else {
1966
34.5k
        infer(pic_struct, 0);
1967
34.5k
        infer(source_scan_type,
1968
34.5k
              expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1969
34.5k
        infer(duplicate_flag, 0);
1970
34.5k
    }
1971
1972
36.4k
    if (sps->vui_parameters_present_flag &&
1973
36.4k
        sps->vui.vui_hrd_parameters_present_flag)
1974
9.30k
        hrd = &sps->vui.hrd_parameters;
1975
27.1k
    else
1976
27.1k
        hrd = NULL;
1977
36.4k
    if (hrd && (hrd->nal_hrd_parameters_present_flag ||
1978
9.30k
                hrd->vcl_hrd_parameters_present_flag)) {
1979
8.89k
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1980
8.89k
        ub(length, au_cpb_removal_delay_minus1);
1981
1982
8.66k
        length = hrd->dpb_output_delay_length_minus1 + 1;
1983
8.66k
        ub(length, pic_dpb_output_delay);
1984
1985
8.07k
        if (hrd->sub_pic_hrd_params_present_flag) {
1986
7.14k
            length = hrd->dpb_output_delay_du_length_minus1 + 1;
1987
7.14k
            ub(length, pic_dpb_output_du_delay);
1988
7.14k
        }
1989
1990
8.02k
        if (hrd->sub_pic_hrd_params_present_flag &&
1991
8.02k
            hrd->sub_pic_cpb_params_in_pic_timing_sei_flag) {
1992
            // Each decoding unit must contain at least one slice segment.
1993
6.04k
            ue(num_decoding_units_minus1, 0, HEVC_MAX_SLICE_SEGMENTS);
1994
5.45k
            flag(du_common_cpb_removal_delay_flag);
1995
1996
5.44k
            length = hrd->du_cpb_removal_delay_increment_length_minus1 + 1;
1997
5.44k
            if (current->du_common_cpb_removal_delay_flag)
1998
3.78k
                ub(length, du_common_cpb_removal_delay_increment_minus1);
1999
2000
4.58k
            for (i = 0; i <= current->num_decoding_units_minus1; i++) {
2001
2.59k
                ues(num_nalus_in_du_minus1[i],
2002
2.43k
                    0, HEVC_MAX_SLICE_SEGMENTS, 1, i);
2003
2.43k
                if (!current->du_common_cpb_removal_delay_flag &&
2004
2.43k
                    i < current->num_decoding_units_minus1)
2005
2.43k
                    ubs(length, du_cpb_removal_delay_increment_minus1[i], 1, i);
2006
2.43k
            }
2007
2.20k
        }
2008
8.02k
    }
2009
2010
31.5k
    return 0;
2011
36.4k
}
cbs_h2645.c:cbs_h265_write_sei_pic_timing
Line
Count
Source
1940
6.68k
{
1941
6.68k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
1942
6.68k
    const H265RawSPS *sps;
1943
6.68k
    const H265RawHRDParameters *hrd;
1944
6.68k
    int err, expected_source_scan_type, i, length;
1945
1946
6.68k
    HEADER("Picture Timing");
1947
1948
6.68k
    sps = h265->active_sps;
1949
6.68k
    if (!sps) {
1950
77
        av_log(ctx->log_ctx, AV_LOG_ERROR,
1951
77
               "No active SPS for pic_timing.\n");
1952
77
        return AVERROR_INVALIDDATA;
1953
77
    }
1954
1955
6.60k
    expected_source_scan_type = 2 -
1956
6.60k
        2 * sps->profile_tier_level.general_interlaced_source_flag -
1957
6.60k
        sps->profile_tier_level.general_progressive_source_flag;
1958
1959
6.60k
    if (sps->vui.frame_field_info_present_flag) {
1960
506
        u(4, pic_struct, 0, 12);
1961
506
        u(2, source_scan_type,
1962
373
          expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1963
373
          expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1964
373
        flag(duplicate_flag);
1965
6.09k
    } else {
1966
6.09k
        infer(pic_struct, 0);
1967
5.95k
        infer(source_scan_type,
1968
5.95k
              expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1969
5.94k
        infer(duplicate_flag, 0);
1970
5.94k
    }
1971
1972
6.13k
    if (sps->vui_parameters_present_flag &&
1973
6.13k
        sps->vui.vui_hrd_parameters_present_flag)
1974
324
        hrd = &sps->vui.hrd_parameters;
1975
5.81k
    else
1976
5.81k
        hrd = NULL;
1977
6.13k
    if (hrd && (hrd->nal_hrd_parameters_present_flag ||
1978
324
                hrd->vcl_hrd_parameters_present_flag)) {
1979
324
        length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1980
324
        ub(length, au_cpb_removal_delay_minus1);
1981
1982
320
        length = hrd->dpb_output_delay_length_minus1 + 1;
1983
320
        ub(length, pic_dpb_output_delay);
1984
1985
189
        if (hrd->sub_pic_hrd_params_present_flag) {
1986
189
            length = hrd->dpb_output_delay_du_length_minus1 + 1;
1987
189
            ub(length, pic_dpb_output_du_delay);
1988
189
        }
1989
1990
169
        if (hrd->sub_pic_hrd_params_present_flag &&
1991
169
            hrd->sub_pic_cpb_params_in_pic_timing_sei_flag) {
1992
            // Each decoding unit must contain at least one slice segment.
1993
77
            ue(num_decoding_units_minus1, 0, HEVC_MAX_SLICE_SEGMENTS);
1994
77
            flag(du_common_cpb_removal_delay_flag);
1995
1996
77
            length = hrd->du_cpb_removal_delay_increment_length_minus1 + 1;
1997
77
            if (current->du_common_cpb_removal_delay_flag)
1998
69
                ub(length, du_common_cpb_removal_delay_increment_minus1);
1999
2000
34
            for (i = 0; i <= current->num_decoding_units_minus1; i++) {
2001
20
                ues(num_nalus_in_du_minus1[i],
2002
20
                    0, HEVC_MAX_SLICE_SEGMENTS, 1, i);
2003
20
                if (!current->du_common_cpb_removal_delay_flag &&
2004
20
                    i < current->num_decoding_units_minus1)
2005
20
                    ubs(length, du_cpb_removal_delay_increment_minus1[i], 1, i);
2006
20
            }
2007
14
        }
2008
169
    }
2009
2010
5.92k
    return 0;
2011
6.13k
}
2012
2013
SEI_FUNC(sei_pan_scan_rect, (CodedBitstreamContext *ctx, RWContext *rw,
2014
                             H265RawSEIPanScanRect *current,
2015
                             SEIMessageState *sei))
2016
228k
{
2017
228k
    int err, i;
2018
2019
228k
    HEADER("Pan-Scan Rectangle");
2020
2021
228k
    ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
2022
226k
    flag(pan_scan_rect_cancel_flag);
2023
2024
226k
    if (!current->pan_scan_rect_cancel_flag) {
2025
10.0k
        ue(pan_scan_cnt_minus1, 0, 2);
2026
2027
23.9k
        for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
2028
16.6k
            ses(pan_scan_rect_left_offset[i],   INT32_MIN + 1, INT32_MAX, 1, i);
2029
16.2k
            ses(pan_scan_rect_right_offset[i],  INT32_MIN + 1, INT32_MAX, 1, i);
2030
16.1k
            ses(pan_scan_rect_top_offset[i],    INT32_MIN + 1, INT32_MAX, 1, i);
2031
15.1k
            ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
2032
15.1k
        }
2033
2034
7.31k
        flag(pan_scan_rect_persistence_flag);
2035
7.31k
    }
2036
2037
223k
    return 0;
2038
226k
}
cbs_h2645.c:cbs_h265_read_sei_pan_scan_rect
Line
Count
Source
2016
90.8k
{
2017
90.8k
    int err, i;
2018
2019
90.8k
    HEADER("Pan-Scan Rectangle");
2020
2021
90.8k
    ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
2022
88.6k
    flag(pan_scan_rect_cancel_flag);
2023
2024
88.6k
    if (!current->pan_scan_rect_cancel_flag) {
2025
6.20k
        ue(pan_scan_cnt_minus1, 0, 2);
2026
2027
12.2k
        for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
2028
8.79k
            ses(pan_scan_rect_left_offset[i],   INT32_MIN + 1, INT32_MAX, 1, i);
2029
8.37k
            ses(pan_scan_rect_right_offset[i],  INT32_MIN + 1, INT32_MAX, 1, i);
2030
8.29k
            ses(pan_scan_rect_top_offset[i],    INT32_MIN + 1, INT32_MAX, 1, i);
2031
7.35k
            ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
2032
7.35k
        }
2033
2034
3.43k
        flag(pan_scan_rect_persistence_flag);
2035
3.43k
    }
2036
2037
85.8k
    return 0;
2038
88.6k
}
cbs_h2645.c:cbs_h265_write_sei_pan_scan_rect
Line
Count
Source
2016
137k
{
2017
137k
    int err, i;
2018
2019
137k
    HEADER("Pan-Scan Rectangle");
2020
2021
137k
    ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
2022
137k
    flag(pan_scan_rect_cancel_flag);
2023
2024
137k
    if (!current->pan_scan_rect_cancel_flag) {
2025
3.88k
        ue(pan_scan_cnt_minus1, 0, 2);
2026
2027
11.7k
        for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
2028
7.83k
            ses(pan_scan_rect_left_offset[i],   INT32_MIN + 1, INT32_MAX, 1, i);
2029
7.83k
            ses(pan_scan_rect_right_offset[i],  INT32_MIN + 1, INT32_MAX, 1, i);
2030
7.83k
            ses(pan_scan_rect_top_offset[i],    INT32_MIN + 1, INT32_MAX, 1, i);
2031
7.83k
            ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
2032
7.83k
        }
2033
2034
3.88k
        flag(pan_scan_rect_persistence_flag);
2035
3.88k
    }
2036
2037
137k
    return 0;
2038
137k
}
2039
2040
SEI_FUNC(sei_recovery_point, (CodedBitstreamContext *ctx, RWContext *rw,
2041
                              H265RawSEIRecoveryPoint *current,
2042
                              SEIMessageState *sei))
2043
59.4k
{
2044
59.4k
    int err;
2045
2046
59.4k
    HEADER("Recovery Point");
2047
2048
59.4k
    se(recovery_poc_cnt, -32768, 32767);
2049
2050
54.7k
    flag(exact_match_flag);
2051
54.7k
    flag(broken_link_flag);
2052
2053
54.7k
    return 0;
2054
54.7k
}
cbs_h2645.c:cbs_h265_read_sei_recovery_point
Line
Count
Source
2043
35.8k
{
2044
35.8k
    int err;
2045
2046
35.8k
    HEADER("Recovery Point");
2047
2048
35.8k
    se(recovery_poc_cnt, -32768, 32767);
2049
2050
31.1k
    flag(exact_match_flag);
2051
31.1k
    flag(broken_link_flag);
2052
2053
31.1k
    return 0;
2054
31.1k
}
cbs_h2645.c:cbs_h265_write_sei_recovery_point
Line
Count
Source
2043
23.6k
{
2044
23.6k
    int err;
2045
2046
23.6k
    HEADER("Recovery Point");
2047
2048
23.6k
    se(recovery_poc_cnt, -32768, 32767);
2049
2050
23.6k
    flag(exact_match_flag);
2051
23.6k
    flag(broken_link_flag);
2052
2053
23.6k
    return 0;
2054
23.6k
}
2055
2056
SEI_FUNC(film_grain_characteristics, (CodedBitstreamContext *ctx, RWContext *rw,
2057
                                      H265RawFilmGrainCharacteristics *current,
2058
                                      SEIMessageState *state))
2059
16.3k
{
2060
16.3k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2061
16.3k
    const H265RawSPS *sps = h265->active_sps;
2062
16.3k
    int err, c, i, j;
2063
2064
16.3k
    HEADER("Film Grain Characteristics");
2065
2066
16.3k
    flag(film_grain_characteristics_cancel_flag);
2067
14.8k
    if (!current->film_grain_characteristics_cancel_flag) {
2068
14.5k
        int filmGrainBitDepth[3];
2069
2070
14.5k
        u(2, film_grain_model_id, 0, 1);
2071
14.3k
        flag(separate_colour_description_present_flag);
2072
14.3k
        if (current->separate_colour_description_present_flag) {
2073
3.15k
            ub(3, film_grain_bit_depth_luma_minus8);
2074
3.15k
            ub(3, film_grain_bit_depth_chroma_minus8);
2075
3.13k
            flag(film_grain_full_range_flag);
2076
3.13k
            ub(8, film_grain_colour_primaries);
2077
3.10k
            ub(8, film_grain_transfer_characteristics);
2078
2.62k
            ub(8, film_grain_matrix_coeffs);
2079
11.2k
        } else {
2080
11.2k
            if (!sps) {
2081
1.11k
                av_log(ctx->log_ctx, AV_LOG_ERROR,
2082
1.11k
                       "No active SPS for film_grain_characteristics.\n");
2083
1.11k
                return AVERROR_INVALIDDATA;
2084
1.11k
            }
2085
10.0k
            infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8);
2086
8.64k
            infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8);
2087
8.47k
            infer(film_grain_full_range_flag, sps->vui.video_full_range_flag);
2088
8.32k
            infer(film_grain_colour_primaries, sps->vui.colour_primaries);
2089
8.17k
            infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics);
2090
8.17k
            infer(film_grain_matrix_coeffs, sps->vui.matrix_coefficients);
2091
1.50k
        }
2092
2093
10.6k
        filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8;
2094
10.6k
        filmGrainBitDepth[1] =
2095
10.6k
        filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8;
2096
2097
10.6k
        u(2, blending_mode_id, 0, 1);
2098
10.0k
        ub(4, log2_scale_factor);
2099
36.8k
        for (c = 0; c < 3; c++)
2100
27.6k
            flags(comp_model_present_flag[c], 1, c);
2101
31.7k
        for (c = 0; c < 3; c++) {
2102
24.7k
            if (current->comp_model_present_flag[c]) {
2103
2.72k
                ubs(8, num_intensity_intervals_minus1[c], 1, c);
2104
2.46k
                us(3, num_model_values_minus1[c], 0, 5, 1, c);
2105
5.18k
                for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) {
2106
4.64k
                    ubs(8, intensity_interval_lower_bound[c][i], 2, c, i);
2107
4.50k
                    ubs(8, intensity_interval_upper_bound[c][i], 2, c, i);
2108
14.4k
                    for (j = 0; j <= current->num_model_values_minus1[c]; j++)
2109
10.8k
                        ses(comp_model_value[c][i][j],      0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2110
4.48k
                            ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2111
4.48k
                            3, c, i, j);
2112
4.48k
                }
2113
1.55k
            }
2114
24.7k
        }
2115
7.02k
        flag(film_grain_characteristics_persistence_flag);
2116
7.02k
    }
2117
2118
7.30k
    return 0;
2119
14.8k
}
cbs_h2645.c:cbs_h265_read_film_grain_characteristics
Line
Count
Source
2059
12.3k
{
2060
12.3k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2061
12.3k
    const H265RawSPS *sps = h265->active_sps;
2062
12.3k
    int err, c, i, j;
2063
2064
12.3k
    HEADER("Film Grain Characteristics");
2065
2066
12.3k
    flag(film_grain_characteristics_cancel_flag);
2067
10.8k
    if (!current->film_grain_characteristics_cancel_flag) {
2068
10.5k
        int filmGrainBitDepth[3];
2069
2070
10.5k
        u(2, film_grain_model_id, 0, 1);
2071
10.4k
        flag(separate_colour_description_present_flag);
2072
10.4k
        if (current->separate_colour_description_present_flag) {
2073
3.07k
            ub(3, film_grain_bit_depth_luma_minus8);
2074
3.07k
            ub(3, film_grain_bit_depth_chroma_minus8);
2075
3.05k
            flag(film_grain_full_range_flag);
2076
3.05k
            ub(8, film_grain_colour_primaries);
2077
3.01k
            ub(8, film_grain_transfer_characteristics);
2078
2.53k
            ub(8, film_grain_matrix_coeffs);
2079
7.34k
        } else {
2080
7.34k
            if (!sps) {
2081
674
                av_log(ctx->log_ctx, AV_LOG_ERROR,
2082
674
                       "No active SPS for film_grain_characteristics.\n");
2083
674
                return AVERROR_INVALIDDATA;
2084
674
            }
2085
6.66k
            infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8);
2086
6.66k
            infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8);
2087
6.66k
            infer(film_grain_full_range_flag, sps->vui.video_full_range_flag);
2088
6.66k
            infer(film_grain_colour_primaries, sps->vui.colour_primaries);
2089
6.66k
            infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics);
2090
6.66k
            infer(film_grain_matrix_coeffs, sps->vui.matrix_coefficients);
2091
6.66k
        }
2092
2093
9.20k
        filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8;
2094
9.20k
        filmGrainBitDepth[1] =
2095
9.20k
        filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8;
2096
2097
9.20k
        u(2, blending_mode_id, 0, 1);
2098
8.57k
        ub(4, log2_scale_factor);
2099
31.0k
        for (c = 0; c < 3; c++)
2100
23.3k
            flags(comp_model_present_flag[c], 1, c);
2101
26.0k
        for (c = 0; c < 3; c++) {
2102
20.4k
            if (current->comp_model_present_flag[c]) {
2103
2.63k
                ubs(8, num_intensity_intervals_minus1[c], 1, c);
2104
2.37k
                us(3, num_model_values_minus1[c], 0, 5, 1, c);
2105
5.00k
                for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) {
2106
4.55k
                    ubs(8, intensity_interval_lower_bound[c][i], 2, c, i);
2107
4.41k
                    ubs(8, intensity_interval_upper_bound[c][i], 2, c, i);
2108
14.0k
                    for (j = 0; j <= current->num_model_values_minus1[c]; j++)
2109
10.5k
                        ses(comp_model_value[c][i][j],      0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2110
4.39k
                            ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2111
4.39k
                            3, c, i, j);
2112
4.39k
                }
2113
1.46k
            }
2114
20.4k
        }
2115
5.58k
        flag(film_grain_characteristics_persistence_flag);
2116
5.58k
    }
2117
2118
5.85k
    return 0;
2119
10.8k
}
cbs_h2645.c:cbs_h265_write_film_grain_characteristics
Line
Count
Source
2059
3.98k
{
2060
3.98k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2061
3.98k
    const H265RawSPS *sps = h265->active_sps;
2062
3.98k
    int err, c, i, j;
2063
2064
3.98k
    HEADER("Film Grain Characteristics");
2065
2066
3.98k
    flag(film_grain_characteristics_cancel_flag);
2067
3.98k
    if (!current->film_grain_characteristics_cancel_flag) {
2068
3.95k
        int filmGrainBitDepth[3];
2069
2070
3.95k
        u(2, film_grain_model_id, 0, 1);
2071
3.95k
        flag(separate_colour_description_present_flag);
2072
3.95k
        if (current->separate_colour_description_present_flag) {
2073
88
            ub(3, film_grain_bit_depth_luma_minus8);
2074
88
            ub(3, film_grain_bit_depth_chroma_minus8);
2075
88
            flag(film_grain_full_range_flag);
2076
88
            ub(8, film_grain_colour_primaries);
2077
88
            ub(8, film_grain_transfer_characteristics);
2078
88
            ub(8, film_grain_matrix_coeffs);
2079
3.87k
        } else {
2080
3.87k
            if (!sps) {
2081
444
                av_log(ctx->log_ctx, AV_LOG_ERROR,
2082
444
                       "No active SPS for film_grain_characteristics.\n");
2083
444
                return AVERROR_INVALIDDATA;
2084
444
            }
2085
3.42k
            infer(film_grain_bit_depth_luma_minus8, sps->bit_depth_luma_minus8);
2086
1.97k
            infer(film_grain_bit_depth_chroma_minus8, sps->bit_depth_chroma_minus8);
2087
1.81k
            infer(film_grain_full_range_flag, sps->vui.video_full_range_flag);
2088
1.66k
            infer(film_grain_colour_primaries, sps->vui.colour_primaries);
2089
1.50k
            infer(film_grain_transfer_characteristics, sps->vui.transfer_characteristics);
2090
1.50k
            infer(film_grain_matrix_coeffs, sps->vui.matrix_coefficients);
2091
1.50k
        }
2092
2093
1.43k
        filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8;
2094
1.43k
        filmGrainBitDepth[1] =
2095
1.43k
        filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8;
2096
2097
1.43k
        u(2, blending_mode_id, 0, 1);
2098
1.43k
        ub(4, log2_scale_factor);
2099
5.73k
        for (c = 0; c < 3; c++)
2100
4.30k
            flags(comp_model_present_flag[c], 1, c);
2101
5.73k
        for (c = 0; c < 3; c++) {
2102
4.30k
            if (current->comp_model_present_flag[c]) {
2103
88
                ubs(8, num_intensity_intervals_minus1[c], 1, c);
2104
88
                us(3, num_model_values_minus1[c], 0, 5, 1, c);
2105
176
                for (i = 0; i <= current->num_intensity_intervals_minus1[c]; i++) {
2106
88
                    ubs(8, intensity_interval_lower_bound[c][i], 2, c, i);
2107
88
                    ubs(8, intensity_interval_upper_bound[c][i], 2, c, i);
2108
440
                    for (j = 0; j <= current->num_model_values_minus1[c]; j++)
2109
352
                        ses(comp_model_value[c][i][j],      0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2110
88
                            ((1 << filmGrainBitDepth[c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[c] - 1)),
2111
88
                            3, c, i, j);
2112
88
                }
2113
88
            }
2114
4.30k
        }
2115
1.43k
        flag(film_grain_characteristics_persistence_flag);
2116
1.43k
    }
2117
2118
1.45k
    return 0;
2119
3.98k
}
2120
2121
SEI_FUNC(sei_display_orientation, (CodedBitstreamContext *ctx, RWContext *rw,
2122
                                   H265RawSEIDisplayOrientation *current,
2123
                                   SEIMessageState *sei))
2124
9.74k
{
2125
9.74k
    int err;
2126
2127
9.74k
    HEADER("Display Orientation");
2128
2129
9.74k
    flag(display_orientation_cancel_flag);
2130
9.07k
    if (!current->display_orientation_cancel_flag) {
2131
8.40k
        flag(hor_flip);
2132
8.40k
        flag(ver_flip);
2133
8.40k
        ub(16, anticlockwise_rotation);
2134
3.22k
        flag(display_orientation_persistence_flag);
2135
3.22k
    }
2136
2137
3.90k
    return 0;
2138
9.07k
}
cbs_h2645.c:cbs_h265_read_sei_display_orientation
Line
Count
Source
2124
8.58k
{
2125
8.58k
    int err;
2126
2127
8.58k
    HEADER("Display Orientation");
2128
2129
8.58k
    flag(display_orientation_cancel_flag);
2130
7.91k
    if (!current->display_orientation_cancel_flag) {
2131
7.24k
        flag(hor_flip);
2132
7.24k
        flag(ver_flip);
2133
7.24k
        ub(16, anticlockwise_rotation);
2134
2.07k
        flag(display_orientation_persistence_flag);
2135
2.07k
    }
2136
2137
2.74k
    return 0;
2138
7.91k
}
cbs_h2645.c:cbs_h265_write_sei_display_orientation
Line
Count
Source
2124
1.15k
{
2125
1.15k
    int err;
2126
2127
1.15k
    HEADER("Display Orientation");
2128
2129
1.15k
    flag(display_orientation_cancel_flag);
2130
1.15k
    if (!current->display_orientation_cancel_flag) {
2131
1.15k
        flag(hor_flip);
2132
1.15k
        flag(ver_flip);
2133
1.15k
        ub(16, anticlockwise_rotation);
2134
1.15k
        flag(display_orientation_persistence_flag);
2135
1.15k
    }
2136
2137
1.15k
    return 0;
2138
1.15k
}
2139
2140
SEI_FUNC(sei_active_parameter_sets, (CodedBitstreamContext *ctx, RWContext *rw,
2141
                                     H265RawSEIActiveParameterSets *current,
2142
                                     SEIMessageState *sei))
2143
18.7k
{
2144
18.7k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2145
18.7k
    const H265RawVPS *vps;
2146
18.7k
    int err, i;
2147
2148
18.7k
    HEADER("Active Parameter Sets");
2149
2150
18.7k
    u(4, active_video_parameter_set_id, 0, HEVC_MAX_VPS_COUNT);
2151
17.5k
    vps = h265->vps[current->active_video_parameter_set_id];
2152
17.5k
    if (!vps) {
2153
1.82k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available for active "
2154
1.82k
               "parameter sets.\n", current->active_video_parameter_set_id);
2155
1.82k
        return AVERROR_INVALIDDATA;
2156
1.82k
    }
2157
15.7k
    h265->active_vps = vps;
2158
2159
15.7k
    flag(self_contained_cvs_flag);
2160
15.7k
    flag(no_parameter_set_update_flag);
2161
2162
15.7k
    ue(num_sps_ids_minus1, 0, HEVC_MAX_SPS_COUNT - 1);
2163
202k
    for (i = 0; i <= current->num_sps_ids_minus1; i++)
2164
189k
        ues(active_seq_parameter_set_id[i], 0, HEVC_MAX_SPS_COUNT - 1, 1, i);
2165
2166
13.2k
    for (i = vps->vps_base_layer_internal_flag;
2167
343k
         i <= FFMIN(62, vps->vps_max_layers_minus1); i++) {
2168
330k
        ues(layer_sps_idx[i], 0, current->num_sps_ids_minus1, 1, i);
2169
2170
330k
        if (i == 0)
2171
124
            h265->active_sps = h265->sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
2172
330k
    }
2173
2174
13.0k
    return 0;
2175
13.2k
}
cbs_h2645.c:cbs_h265_read_sei_active_parameter_sets
Line
Count
Source
2143
12.2k
{
2144
12.2k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2145
12.2k
    const H265RawVPS *vps;
2146
12.2k
    int err, i;
2147
2148
12.2k
    HEADER("Active Parameter Sets");
2149
2150
12.2k
    u(4, active_video_parameter_set_id, 0, HEVC_MAX_VPS_COUNT);
2151
11.0k
    vps = h265->vps[current->active_video_parameter_set_id];
2152
11.0k
    if (!vps) {
2153
1.81k
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available for active "
2154
1.81k
               "parameter sets.\n", current->active_video_parameter_set_id);
2155
1.81k
        return AVERROR_INVALIDDATA;
2156
1.81k
    }
2157
9.22k
    h265->active_vps = vps;
2158
2159
9.22k
    flag(self_contained_cvs_flag);
2160
9.22k
    flag(no_parameter_set_update_flag);
2161
2162
9.22k
    ue(num_sps_ids_minus1, 0, HEVC_MAX_SPS_COUNT - 1);
2163
96.8k
    for (i = 0; i <= current->num_sps_ids_minus1; i++)
2164
90.1k
        ues(active_seq_parameter_set_id[i], 0, HEVC_MAX_SPS_COUNT - 1, 1, i);
2165
2166
6.75k
    for (i = vps->vps_base_layer_internal_flag;
2167
118k
         i <= FFMIN(62, vps->vps_max_layers_minus1); i++) {
2168
111k
        ues(layer_sps_idx[i], 0, current->num_sps_ids_minus1, 1, i);
2169
2170
111k
        if (i == 0)
2171
112
            h265->active_sps = h265->sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
2172
111k
    }
2173
2174
6.53k
    return 0;
2175
6.75k
}
cbs_h2645.c:cbs_h265_write_sei_active_parameter_sets
Line
Count
Source
2143
6.48k
{
2144
6.48k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2145
6.48k
    const H265RawVPS *vps;
2146
6.48k
    int err, i;
2147
2148
6.48k
    HEADER("Active Parameter Sets");
2149
2150
6.48k
    u(4, active_video_parameter_set_id, 0, HEVC_MAX_VPS_COUNT);
2151
6.48k
    vps = h265->vps[current->active_video_parameter_set_id];
2152
6.48k
    if (!vps) {
2153
4
        av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available for active "
2154
4
               "parameter sets.\n", current->active_video_parameter_set_id);
2155
4
        return AVERROR_INVALIDDATA;
2156
4
    }
2157
6.48k
    h265->active_vps = vps;
2158
2159
6.48k
    flag(self_contained_cvs_flag);
2160
6.48k
    flag(no_parameter_set_update_flag);
2161
2162
6.48k
    ue(num_sps_ids_minus1, 0, HEVC_MAX_SPS_COUNT - 1);
2163
105k
    for (i = 0; i <= current->num_sps_ids_minus1; i++)
2164
99.2k
        ues(active_seq_parameter_set_id[i], 0, HEVC_MAX_SPS_COUNT - 1, 1, i);
2165
2166
6.48k
    for (i = vps->vps_base_layer_internal_flag;
2167
225k
         i <= FFMIN(62, vps->vps_max_layers_minus1); i++) {
2168
219k
        ues(layer_sps_idx[i], 0, current->num_sps_ids_minus1, 1, i);
2169
2170
219k
        if (i == 0)
2171
12
            h265->active_sps = h265->sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
2172
219k
    }
2173
2174
6.48k
    return 0;
2175
6.48k
}
2176
2177
SEI_FUNC(sei_decoded_picture_hash, (CodedBitstreamContext *ctx, RWContext *rw,
2178
                                    H265RawSEIDecodedPictureHash *current,
2179
                                    SEIMessageState *sei))
2180
5.29k
{
2181
5.29k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2182
5.29k
    const H265RawSPS *sps = h265->active_sps;
2183
5.29k
    int err, c, i;
2184
2185
5.29k
    HEADER("Decoded Picture Hash");
2186
2187
5.29k
    if (!sps) {
2188
830
        av_log(ctx->log_ctx, AV_LOG_ERROR,
2189
830
               "No active SPS for decoded picture hash.\n");
2190
830
        return AVERROR_INVALIDDATA;
2191
830
    }
2192
2193
4.46k
    u(8, hash_type, 0, 2);
2194
2195
12.8k
    for (c = 0; c < (sps->chroma_format_idc == 0 ? 1 : 3); c++) {
2196
9.79k
        if (current->hash_type == 0) {
2197
28.7k
            for (i = 0; i < 16; i++)
2198
27.0k
                us(8, picture_md5[c][i], 0x00, 0xff, 2, c, i);
2199
8.08k
        } else if (current->hash_type == 1) {
2200
621
            us(16, picture_crc[c], 0x0000, 0xffff, 1, c);
2201
7.46k
        } else if (current->hash_type == 2) {
2202
7.46k
            us(32, picture_checksum[c], 0x00000000, 0xffffffff, 1, c);
2203
7.46k
        }
2204
9.79k
    }
2205
2206
3.03k
    return 0;
2207
3.54k
}
cbs_h2645.c:cbs_h265_read_sei_decoded_picture_hash
Line
Count
Source
2180
4.30k
{
2181
4.30k
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2182
4.30k
    const H265RawSPS *sps = h265->active_sps;
2183
4.30k
    int err, c, i;
2184
2185
4.30k
    HEADER("Decoded Picture Hash");
2186
2187
4.30k
    if (!sps) {
2188
827
        av_log(ctx->log_ctx, AV_LOG_ERROR,
2189
827
               "No active SPS for decoded picture hash.\n");
2190
827
        return AVERROR_INVALIDDATA;
2191
827
    }
2192
2193
3.47k
    u(8, hash_type, 0, 2);
2194
2195
8.90k
    for (c = 0; c < (sps->chroma_format_idc == 0 ? 1 : 3); c++) {
2196
6.85k
        if (current->hash_type == 0) {
2197
14.1k
            for (i = 0; i < 16; i++)
2198
13.3k
                us(8, picture_md5[c][i], 0x00, 0xff, 2, c, i);
2199
5.99k
        } else if (current->hash_type == 1) {
2200
489
            us(16, picture_crc[c], 0x0000, 0xffff, 1, c);
2201
5.50k
        } else if (current->hash_type == 2) {
2202
5.50k
            us(32, picture_checksum[c], 0x00000000, 0xffffffff, 1, c);
2203
5.50k
        }
2204
6.85k
    }
2205
2206
2.05k
    return 0;
2207
2.55k
}
cbs_h2645.c:cbs_h265_write_sei_decoded_picture_hash
Line
Count
Source
2180
987
{
2181
987
    CodedBitstreamH265Context *h265 = ctx->priv_data;
2182
987
    const H265RawSPS *sps = h265->active_sps;
2183
987
    int err, c, i;
2184
2185
987
    HEADER("Decoded Picture Hash");
2186
2187
987
    if (!sps) {
2188
3
        av_log(ctx->log_ctx, AV_LOG_ERROR,
2189
3
               "No active SPS for decoded picture hash.\n");
2190
3
        return AVERROR_INVALIDDATA;
2191
3
    }
2192
2193
984
    u(8, hash_type, 0, 2);
2194
2195
3.92k
    for (c = 0; c < (sps->chroma_format_idc == 0 ? 1 : 3); c++) {
2196
2.94k
        if (current->hash_type == 0) {
2197
14.5k
            for (i = 0; i < 16; i++)
2198
13.6k
                us(8, picture_md5[c][i], 0x00, 0xff, 2, c, i);
2199
2.08k
        } else if (current->hash_type == 1) {
2200
132
            us(16, picture_crc[c], 0x0000, 0xffff, 1, c);
2201
1.95k
        } else if (current->hash_type == 2) {
2202
1.95k
            us(32, picture_checksum[c], 0x00000000, 0xffffffff, 1, c);
2203
1.95k
        }
2204
2.94k
    }
2205
2206
984
    return 0;
2207
984
}
2208
2209
SEI_FUNC(sei_time_code, (CodedBitstreamContext *ctx, RWContext *rw,
2210
                         H265RawSEITimeCode *current, SEIMessageState *sei))
2211
38.0k
{
2212
38.0k
    int err, i;
2213
2214
38.0k
    HEADER("Time Code");
2215
2216
38.0k
    u(2, num_clock_ts, 1, 3);
2217
2218
80.2k
    for (i = 0; i < current->num_clock_ts; i++) {
2219
66.3k
        flags(clock_timestamp_flag[i],   1, i);
2220
2221
65.2k
        if (current->clock_timestamp_flag[i]) {
2222
42.5k
            flags(units_field_based_flag[i], 1, i);
2223
42.0k
            us(5, counting_type[i], 0, 6,    1, i);
2224
38.4k
            flags(full_timestamp_flag[i],    1, i);
2225
37.2k
            flags(discontinuity_flag[i],     1, i);
2226
36.7k
            flags(cnt_dropped_flag[i],       1, i);
2227
2228
36.4k
            ubs(9, n_frames[i], 1, i);
2229
2230
36.0k
            if (current->full_timestamp_flag[i]) {
2231
12.8k
                us(6, seconds_value[i], 0, 59, 1, i);
2232
12.6k
                us(6, minutes_value[i], 0, 59, 1, i);
2233
12.4k
                us(5, hours_value[i],   0, 23, 1, i);
2234
23.2k
            } else {
2235
23.2k
                flags(seconds_flag[i], 1, i);
2236
22.5k
                if (current->seconds_flag[i]) {
2237
14.8k
                    us(6, seconds_value[i], 0, 59, 1, i);
2238
14.4k
                    flags(minutes_flag[i], 1, i);
2239
13.2k
                    if (current->minutes_flag[i]) {
2240
6.43k
                        us(6, minutes_value[i], 0, 59, 1, i);
2241
6.34k
                        flags(hours_flag[i], 1, i);
2242
5.39k
                        if (current->hours_flag[i])
2243
5.39k
                            us(5, hours_value[i], 0, 23, 1, i);
2244
5.39k
                    }
2245
13.2k
                }
2246
22.5k
            }
2247
2248
28.8k
            ubs(5, time_offset_length[i], 1, i);
2249
26.7k
            if (current->time_offset_length[i] > 0)
2250
26.7k
                ibs(current->time_offset_length[i], time_offset_value[i], 1, i);
2251
3.14k
            else
2252
3.14k
                infer(time_offset_value[i], 0);
2253
26.7k
        }
2254
65.2k
    }
2255
2256
13.8k
    return 0;
2257
37.0k
}
cbs_h2645.c:cbs_h265_read_sei_time_code
Line
Count
Source
2211
37.1k
{
2212
37.1k
    int err, i;
2213
2214
37.1k
    HEADER("Time Code");
2215
2216
37.1k
    u(2, num_clock_ts, 1, 3);
2217
2218
76.5k
    for (i = 0; i < current->num_clock_ts; i++) {
2219
63.6k
        flags(clock_timestamp_flag[i],   1, i);
2220
2221
62.5k
        if (current->clock_timestamp_flag[i]) {
2222
39.9k
            flags(units_field_based_flag[i], 1, i);
2223
39.4k
            us(5, counting_type[i], 0, 6,    1, i);
2224
35.8k
            flags(full_timestamp_flag[i],    1, i);
2225
34.6k
            flags(discontinuity_flag[i],     1, i);
2226
34.1k
            flags(cnt_dropped_flag[i],       1, i);
2227
2228
33.8k
            ubs(9, n_frames[i], 1, i);
2229
2230
33.4k
            if (current->full_timestamp_flag[i]) {
2231
11.0k
                us(6, seconds_value[i], 0, 59, 1, i);
2232
10.8k
                us(6, minutes_value[i], 0, 59, 1, i);
2233
10.7k
                us(5, hours_value[i],   0, 23, 1, i);
2234
22.4k
            } else {
2235
22.4k
                flags(seconds_flag[i], 1, i);
2236
21.6k
                if (current->seconds_flag[i]) {
2237
13.9k
                    us(6, seconds_value[i], 0, 59, 1, i);
2238
13.5k
                    flags(minutes_flag[i], 1, i);
2239
12.4k
                    if (current->minutes_flag[i]) {
2240
5.60k
                        us(6, minutes_value[i], 0, 59, 1, i);
2241
5.50k
                        flags(hours_flag[i], 1, i);
2242
4.55k
                        if (current->hours_flag[i])
2243
4.55k
                            us(5, hours_value[i], 0, 23, 1, i);
2244
4.55k
                    }
2245
12.4k
                }
2246
21.6k
            }
2247
2248
26.2k
            ubs(5, time_offset_length[i], 1, i);
2249
24.1k
            if (current->time_offset_length[i] > 0)
2250
24.1k
                ibs(current->time_offset_length[i], time_offset_value[i], 1, i);
2251
3.04k
            else
2252
3.04k
                infer(time_offset_value[i], 0);
2253
24.1k
        }
2254
62.5k
    }
2255
2256
12.9k
    return 0;
2257
36.1k
}
cbs_h2645.c:cbs_h265_write_sei_time_code
Line
Count
Source
2211
932
{
2212
932
    int err, i;
2213
2214
932
    HEADER("Time Code");
2215
2216
932
    u(2, num_clock_ts, 1, 3);
2217
2218
3.64k
    for (i = 0; i < current->num_clock_ts; i++) {
2219
2.70k
        flags(clock_timestamp_flag[i],   1, i);
2220
2221
2.70k
        if (current->clock_timestamp_flag[i]) {
2222
2.59k
            flags(units_field_based_flag[i], 1, i);
2223
2.59k
            us(5, counting_type[i], 0, 6,    1, i);
2224
2.59k
            flags(full_timestamp_flag[i],    1, i);
2225
2.59k
            flags(discontinuity_flag[i],     1, i);
2226
2.59k
            flags(cnt_dropped_flag[i],       1, i);
2227
2228
2.59k
            ubs(9, n_frames[i], 1, i);
2229
2230
2.59k
            if (current->full_timestamp_flag[i]) {
2231
1.75k
                us(6, seconds_value[i], 0, 59, 1, i);
2232
1.75k
                us(6, minutes_value[i], 0, 59, 1, i);
2233
1.75k
                us(5, hours_value[i],   0, 23, 1, i);
2234
1.75k
            } else {
2235
844
                flags(seconds_flag[i], 1, i);
2236
844
                if (current->seconds_flag[i]) {
2237
838
                    us(6, seconds_value[i], 0, 59, 1, i);
2238
838
                    flags(minutes_flag[i], 1, i);
2239
838
                    if (current->minutes_flag[i]) {
2240
836
                        us(6, minutes_value[i], 0, 59, 1, i);
2241
836
                        flags(hours_flag[i], 1, i);
2242
836
                        if (current->hours_flag[i])
2243
836
                            us(5, hours_value[i], 0, 23, 1, i);
2244
836
                    }
2245
838
                }
2246
844
            }
2247
2248
2.59k
            ubs(5, time_offset_length[i], 1, i);
2249
2.59k
            if (current->time_offset_length[i] > 0)
2250
2.59k
                ibs(current->time_offset_length[i], time_offset_value[i], 1, i);
2251
98
            else
2252
98
                infer(time_offset_value[i], 0);
2253
2.59k
        }
2254
2.70k
    }
2255
2256
932
    return 0;
2257
932
}
2258
2259
SEI_FUNC(sei_alpha_channel_info, (CodedBitstreamContext *ctx, RWContext *rw,
2260
                                  H265RawSEIAlphaChannelInfo *current,
2261
                                  SEIMessageState *sei))
2262
6.44k
{
2263
6.44k
    int err, length;
2264
2265
6.44k
    HEADER("Alpha Channel Information");
2266
2267
6.44k
    flag(alpha_channel_cancel_flag);
2268
4.00k
    if (!current->alpha_channel_cancel_flag) {
2269
1.36k
        ub(3, alpha_channel_use_idc);
2270
1.36k
        ub(3, alpha_channel_bit_depth_minus8);
2271
1.36k
        length = current->alpha_channel_bit_depth_minus8 + 9;
2272
1.36k
        ub(length, alpha_transparent_value);
2273
1.33k
        ub(length, alpha_opaque_value);
2274
422
        flag(alpha_channel_incr_flag);
2275
422
        flag(alpha_channel_clip_flag);
2276
292
        if (current->alpha_channel_clip_flag)
2277
292
            flag(alpha_channel_clip_type_flag);
2278
2.64k
    } else {
2279
2.64k
       infer(alpha_channel_use_idc,   2);
2280
2.64k
       infer(alpha_channel_incr_flag, 0);
2281
2.64k
       infer(alpha_channel_clip_flag, 0);
2282
462
    }
2283
2284
2.93k
    return 0;
2285
4.00k
}
cbs_h2645.c:cbs_h265_read_sei_alpha_channel_info
Line
Count
Source
2262
5.97k
{
2263
5.97k
    int err, length;
2264
2265
5.97k
    HEADER("Alpha Channel Information");
2266
2267
5.97k
    flag(alpha_channel_cancel_flag);
2268
3.54k
    if (!current->alpha_channel_cancel_flag) {
2269
1.36k
        ub(3, alpha_channel_use_idc);
2270
1.36k
        ub(3, alpha_channel_bit_depth_minus8);
2271
1.36k
        length = current->alpha_channel_bit_depth_minus8 + 9;
2272
1.36k
        ub(length, alpha_transparent_value);
2273
1.33k
        ub(length, alpha_opaque_value);
2274
422
        flag(alpha_channel_incr_flag);
2275
422
        flag(alpha_channel_clip_flag);
2276
292
        if (current->alpha_channel_clip_flag)
2277
292
            flag(alpha_channel_clip_type_flag);
2278
2.17k
    } else {
2279
2.17k
       infer(alpha_channel_use_idc,   2);
2280
2.17k
       infer(alpha_channel_incr_flag, 0);
2281
2.17k
       infer(alpha_channel_clip_flag, 0);
2282
2.17k
    }
2283
2284
2.47k
    return 0;
2285
3.54k
}
cbs_h2645.c:cbs_h265_write_sei_alpha_channel_info
Line
Count
Source
2262
462
{
2263
462
    int err, length;
2264
2265
462
    HEADER("Alpha Channel Information");
2266
2267
462
    flag(alpha_channel_cancel_flag);
2268
462
    if (!current->alpha_channel_cancel_flag) {
2269
0
        ub(3, alpha_channel_use_idc);
2270
0
        ub(3, alpha_channel_bit_depth_minus8);
2271
0
        length = current->alpha_channel_bit_depth_minus8 + 9;
2272
0
        ub(length, alpha_transparent_value);
2273
0
        ub(length, alpha_opaque_value);
2274
0
        flag(alpha_channel_incr_flag);
2275
0
        flag(alpha_channel_clip_flag);
2276
0
        if (current->alpha_channel_clip_flag)
2277
0
            flag(alpha_channel_clip_type_flag);
2278
462
    } else {
2279
462
       infer(alpha_channel_use_idc,   2);
2280
462
       infer(alpha_channel_incr_flag, 0);
2281
462
       infer(alpha_channel_clip_flag, 0);
2282
462
    }
2283
2284
462
    return 0;
2285
462
}
2286
2287
SEI_FUNC(sei_3d_reference_displays_info, (CodedBitstreamContext *ctx, RWContext *rw,
2288
                                          H265RawSEI3DReferenceDisplaysInfo *current,
2289
                                          SEIMessageState *sei))
2290
1.88k
{
2291
1.88k
    int length;
2292
1.88k
    int err, i;
2293
2294
1.88k
    HEADER("Three Dimensional Reference Displays Information");
2295
2296
1.88k
    ue(prec_ref_display_width, 0, 31);
2297
1.87k
    flag(ref_viewing_distance_flag);
2298
1.87k
    if (current->ref_viewing_distance_flag)
2299
1.87k
        ue(prec_ref_viewing_dist, 0, 31);
2300
1.87k
    ue(num_ref_displays_minus1, 0, 31);
2301
7.06k
    for (i = 0; i <= current->num_ref_displays_minus1; i++) {
2302
6.56k
        ues(left_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2303
6.36k
        ues(right_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2304
5.88k
        us(6, exponent_ref_display_width[i], 0, 62, 1, i);
2305
5.70k
        if (!current->exponent_ref_display_width[i])
2306
353
            length = FFMAX(0, (int)current->prec_ref_display_width - 30);
2307
5.35k
        else
2308
5.35k
            length = FFMAX(0, (int)current->exponent_ref_display_width[i] +
2309
5.70k
                              (int)current->prec_ref_display_width - 31);
2310
2311
5.70k
        if (length > 32) {
2312
6
            av_log(ctx->log_ctx, AV_LOG_ERROR, "refDispWidthBits > 32 is not supported\n");
2313
6
            return AVERROR_PATCHWELCOME;
2314
6
        }
2315
2316
5.70k
        if (length)
2317
5.70k
            ubs(length, mantissa_ref_display_width[i], 1, i);
2318
1.75k
        else
2319
1.75k
            infer(mantissa_ref_display_width[i], 0);
2320
5.52k
        if (current->ref_viewing_distance_flag) {
2321
3.06k
            us(6, exponent_ref_viewing_distance[i], 0, 62, 1, i);
2322
2.93k
            if (!current->exponent_ref_viewing_distance[i])
2323
516
                length = FFMAX(0, (int)current->prec_ref_viewing_dist - 30);
2324
2.42k
            else
2325
2.42k
                length = FFMAX(0, (int)current->exponent_ref_viewing_distance[i] +
2326
2.93k
                                  (int)current->prec_ref_viewing_dist - 31);
2327
2328
2.93k
            if (length > 32) {
2329
57
                av_log(ctx->log_ctx, AV_LOG_ERROR, "refViewDistBits > 32 is not supported\n");
2330
57
                return AVERROR_PATCHWELCOME;
2331
57
            }
2332
2333
2.88k
            if (length)
2334
2.88k
                ubs(length, mantissa_ref_viewing_distance[i], 1, i);
2335
1.11k
            else
2336
1.11k
                infer(mantissa_ref_viewing_distance[i], 0);
2337
2.88k
        }
2338
5.33k
        flags(additional_shift_present_flag[i], 1, i);
2339
5.33k
        if (current->additional_shift_present_flag[i])
2340
5.33k
            us(10, num_sample_shift_plus512[i], 0, 1023, 1, i);
2341
5.33k
    }
2342
495
    flag(three_dimensional_reference_displays_extension_flag);
2343
2344
494
    return 0;
2345
495
}
cbs_h2645.c:cbs_h265_read_sei_3d_reference_displays_info
Line
Count
Source
2290
1.79k
{
2291
1.79k
    int length;
2292
1.79k
    int err, i;
2293
2294
1.79k
    HEADER("Three Dimensional Reference Displays Information");
2295
2296
1.79k
    ue(prec_ref_display_width, 0, 31);
2297
1.78k
    flag(ref_viewing_distance_flag);
2298
1.78k
    if (current->ref_viewing_distance_flag)
2299
1.78k
        ue(prec_ref_viewing_dist, 0, 31);
2300
1.78k
    ue(num_ref_displays_minus1, 0, 31);
2301
6.81k
    for (i = 0; i <= current->num_ref_displays_minus1; i++) {
2302
6.40k
        ues(left_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2303
6.20k
        ues(right_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2304
5.72k
        us(6, exponent_ref_display_width[i], 0, 62, 1, i);
2305
5.54k
        if (!current->exponent_ref_display_width[i])
2306
201
            length = FFMAX(0, (int)current->prec_ref_display_width - 30);
2307
5.34k
        else
2308
5.34k
            length = FFMAX(0, (int)current->exponent_ref_display_width[i] +
2309
5.54k
                              (int)current->prec_ref_display_width - 31);
2310
2311
5.54k
        if (length > 32) {
2312
6
            av_log(ctx->log_ctx, AV_LOG_ERROR, "refDispWidthBits > 32 is not supported\n");
2313
6
            return AVERROR_PATCHWELCOME;
2314
6
        }
2315
2316
5.54k
        if (length)
2317
5.54k
            ubs(length, mantissa_ref_display_width[i], 1, i);
2318
1.74k
        else
2319
1.74k
            infer(mantissa_ref_display_width[i], 0);
2320
5.36k
        if (current->ref_viewing_distance_flag) {
2321
3.06k
            us(6, exponent_ref_viewing_distance[i], 0, 62, 1, i);
2322
2.93k
            if (!current->exponent_ref_viewing_distance[i])
2323
516
                length = FFMAX(0, (int)current->prec_ref_viewing_dist - 30);
2324
2.42k
            else
2325
2.42k
                length = FFMAX(0, (int)current->exponent_ref_viewing_distance[i] +
2326
2.93k
                                  (int)current->prec_ref_viewing_dist - 31);
2327
2328
2.93k
            if (length > 32) {
2329
57
                av_log(ctx->log_ctx, AV_LOG_ERROR, "refViewDistBits > 32 is not supported\n");
2330
57
                return AVERROR_PATCHWELCOME;
2331
57
            }
2332
2333
2.88k
            if (length)
2334
2.88k
                ubs(length, mantissa_ref_viewing_distance[i], 1, i);
2335
1.11k
            else
2336
1.11k
                infer(mantissa_ref_viewing_distance[i], 0);
2337
2.88k
        }
2338
5.17k
        flags(additional_shift_present_flag[i], 1, i);
2339
5.17k
        if (current->additional_shift_present_flag[i])
2340
5.17k
            us(10, num_sample_shift_plus512[i], 0, 1023, 1, i);
2341
5.17k
    }
2342
411
    flag(three_dimensional_reference_displays_extension_flag);
2343
2344
410
    return 0;
2345
411
}
cbs_h2645.c:cbs_h265_write_sei_3d_reference_displays_info
Line
Count
Source
2290
84
{
2291
84
    int length;
2292
84
    int err, i;
2293
2294
84
    HEADER("Three Dimensional Reference Displays Information");
2295
2296
84
    ue(prec_ref_display_width, 0, 31);
2297
84
    flag(ref_viewing_distance_flag);
2298
84
    if (current->ref_viewing_distance_flag)
2299
84
        ue(prec_ref_viewing_dist, 0, 31);
2300
84
    ue(num_ref_displays_minus1, 0, 31);
2301
244
    for (i = 0; i <= current->num_ref_displays_minus1; i++) {
2302
160
        ues(left_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2303
160
        ues(right_view_id[i], 0, MAX_UINT_BITS(15), 1, i);
2304
160
        us(6, exponent_ref_display_width[i], 0, 62, 1, i);
2305
160
        if (!current->exponent_ref_display_width[i])
2306
152
            length = FFMAX(0, (int)current->prec_ref_display_width - 30);
2307
8
        else
2308
8
            length = FFMAX(0, (int)current->exponent_ref_display_width[i] +
2309
160
                              (int)current->prec_ref_display_width - 31);
2310
2311
160
        if (length > 32) {
2312
0
            av_log(ctx->log_ctx, AV_LOG_ERROR, "refDispWidthBits > 32 is not supported\n");
2313
0
            return AVERROR_PATCHWELCOME;
2314
0
        }
2315
2316
160
        if (length)
2317
160
            ubs(length, mantissa_ref_display_width[i], 1, i);
2318
8
        else
2319
8
            infer(mantissa_ref_display_width[i], 0);
2320
160
        if (current->ref_viewing_distance_flag) {
2321
0
            us(6, exponent_ref_viewing_distance[i], 0, 62, 1, i);
2322
0
            if (!current->exponent_ref_viewing_distance[i])
2323
0
                length = FFMAX(0, (int)current->prec_ref_viewing_dist - 30);
2324
0
            else
2325
0
                length = FFMAX(0, (int)current->exponent_ref_viewing_distance[i] +
2326
0
                                  (int)current->prec_ref_viewing_dist - 31);
2327
2328
0
            if (length > 32) {
2329
0
                av_log(ctx->log_ctx, AV_LOG_ERROR, "refViewDistBits > 32 is not supported\n");
2330
0
                return AVERROR_PATCHWELCOME;
2331
0
            }
2332
2333
0
            if (length)
2334
0
                ubs(length, mantissa_ref_viewing_distance[i], 1, i);
2335
0
            else
2336
0
                infer(mantissa_ref_viewing_distance[i], 0);
2337
0
        }
2338
160
        flags(additional_shift_present_flag[i], 1, i);
2339
160
        if (current->additional_shift_present_flag[i])
2340
160
            us(10, num_sample_shift_plus512[i], 0, 1023, 1, i);
2341
160
    }
2342
84
    flag(three_dimensional_reference_displays_extension_flag);
2343
2344
84
    return 0;
2345
84
}
2346
2347
static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
2348
                     H265RawSEI *current, int prefix)
2349
159k
{
2350
159k
    int err;
2351
2352
159k
    if (prefix)
2353
121k
        HEADER("Prefix Supplemental Enhancement Information");
2354
38.2k
    else
2355
38.2k
        HEADER("Suffix Supplemental Enhancement Information");
2356
2357
159k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2358
159k
                                prefix ? HEVC_NAL_SEI_PREFIX
2359
159k
                                       : HEVC_NAL_SEI_SUFFIX));
2360
2361
159k
    CHECK(FUNC_SEI(message_list)(ctx, rw, &current->message_list, prefix));
2362
2363
16.4k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2364
2365
16.4k
    return 0;
2366
16.4k
}
cbs_h2645.c:cbs_h265_read_sei
Line
Count
Source
2349
151k
{
2350
151k
    int err;
2351
2352
151k
    if (prefix)
2353
113k
        HEADER("Prefix Supplemental Enhancement Information");
2354
37.9k
    else
2355
37.9k
        HEADER("Suffix Supplemental Enhancement Information");
2356
2357
151k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2358
151k
                                prefix ? HEVC_NAL_SEI_PREFIX
2359
151k
                                       : HEVC_NAL_SEI_SUFFIX));
2360
2361
151k
    CHECK(FUNC_SEI(message_list)(ctx, rw, &current->message_list, prefix));
2362
2363
12.2k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2364
2365
12.2k
    return 0;
2366
12.2k
}
cbs_h2645.c:cbs_h265_write_sei
Line
Count
Source
2349
8.30k
{
2350
8.30k
    int err;
2351
2352
8.30k
    if (prefix)
2353
7.96k
        HEADER("Prefix Supplemental Enhancement Information");
2354
342
    else
2355
342
        HEADER("Suffix Supplemental Enhancement Information");
2356
2357
8.30k
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2358
8.30k
                                prefix ? HEVC_NAL_SEI_PREFIX
2359
8.30k
                                       : HEVC_NAL_SEI_SUFFIX));
2360
2361
8.30k
    CHECK(FUNC_SEI(message_list)(ctx, rw, &current->message_list, prefix));
2362
2363
4.25k
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2364
2365
4.25k
    return 0;
2366
4.25k
}
2367
2368
2369
static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
2370
                        H265RawFiller *current)
2371
810
{
2372
810
    int err;
2373
2374
810
    HEADER("Filler Data");
2375
2376
810
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2377
810
                                HEVC_NAL_FD_NUT));
2378
2379
#ifdef READ
2380
826
    while (show_bits(rw, 8) == 0xff) {
2381
56
        fixed(8, ff_byte, 0xff);
2382
56
        ++current->filler_size;
2383
56
    }
2384
#else
2385
40
    {
2386
40
        uint32_t i;
2387
40
        for (i = 0; i < current->filler_size; i++)
2388
0
            fixed(8, ff_byte, 0xff);
2389
40
    }
2390
40
#endif
2391
2392
810
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2393
2394
85
    return 0;
2395
810
}
cbs_h2645.c:cbs_h265_read_filler
Line
Count
Source
2371
770
{
2372
770
    int err;
2373
2374
770
    HEADER("Filler Data");
2375
2376
770
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2377
770
                                HEVC_NAL_FD_NUT));
2378
2379
770
#ifdef READ
2380
826
    while (show_bits(rw, 8) == 0xff) {
2381
56
        fixed(8, ff_byte, 0xff);
2382
56
        ++current->filler_size;
2383
56
    }
2384
#else
2385
    {
2386
        uint32_t i;
2387
        for (i = 0; i < current->filler_size; i++)
2388
            fixed(8, ff_byte, 0xff);
2389
    }
2390
#endif
2391
2392
770
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2393
2394
45
    return 0;
2395
770
}
cbs_h2645.c:cbs_h265_write_filler
Line
Count
Source
2371
40
{
2372
40
    int err;
2373
2374
40
    HEADER("Filler Data");
2375
2376
40
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2377
40
                                HEVC_NAL_FD_NUT));
2378
2379
#ifdef READ
2380
    while (show_bits(rw, 8) == 0xff) {
2381
        fixed(8, ff_byte, 0xff);
2382
        ++current->filler_size;
2383
    }
2384
#else
2385
40
    {
2386
40
        uint32_t i;
2387
40
        for (i = 0; i < current->filler_size; i++)
2388
0
            fixed(8, ff_byte, 0xff);
2389
40
    }
2390
40
#endif
2391
2392
40
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
2393
2394
40
    return 0;
2395
40
}