FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cbs_av1_syntax_template.c
Date: 2026-08-11 17:55:23
Exec Total Coverage
Lines: 863 1186 72.8%
Functions: 70 82 85.4%
Branches: 725 1604 45.2%

Line Branch Exec Source
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 13794 static int FUNC(obu_header)(CodedBitstreamContext *ctx, RWContext *rw,
20 AV1RawOBUHeader *current)
21 {
22 13794 CodedBitstreamAV1Context *priv = ctx->priv_data;
23 int err;
24
25 13794 HEADER("OBU header");
26
27
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6897 times.
13794 fc(1, obu_forbidden_bit, 0, 0);
28
29
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6897 times.
13794 fc(4, obu_type, 0, AV1_OBU_PADDING);
30
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6897 times.
13794 flag(obu_extension_flag);
31
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6897 times.
13794 flag(obu_has_size_field);
32
33
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6897 times.
13794 fc(1, obu_reserved_1bit, 0, 0);
34
35
2/2
✓ Branch 0 taken 412 times.
✓ Branch 1 taken 6485 times.
13794 if (current->obu_extension_flag) {
36
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
824 fb(3, temporal_id);
37
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
824 fb(2, spatial_id);
38
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
824 fc(3, extension_header_reserved_3bits, 0, 0);
39 } else {
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 937 times.
12970 infer(temporal_id, 0);
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 937 times.
12970 infer(spatial_id, 0);
42 }
43
44 13794 priv->temporal_id = current->temporal_id;
45 13794 priv->spatial_id = current->spatial_id;
46
47 13794 return 0;
48 }
49
50 1974 static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
51 {
52 int err;
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 987 times.
1974 av_assert0(nb_bits > 0);
55
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 987 times.
1974 fixed(1, trailing_one_bit, 1);
57 1974 --nb_bits;
58
59
2/2
✓ Branch 0 taken 4407 times.
✓ Branch 1 taken 987 times.
10788 while (nb_bits > 0) {
60
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4407 times.
8814 fixed(1, trailing_zero_bit, 0);
61 8814 --nb_bits;
62 }
63
64 1974 return 0;
65 }
66
67 6010 static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
68 {
69 int err;
70
71
2/2
✓ Branch 1 taken 7015 times.
✓ Branch 2 taken 3005 times.
20040 while (byte_alignment(rw) != 0)
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7015 times.
14030 fixed(1, zero_bit, 0);
73
74 6010 return 0;
75 }
76
77 1248 static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw,
78 AV1RawColorConfig *current, int seq_profile)
79 {
80 1248 CodedBitstreamAV1Context *priv = ctx->priv_data;
81 int err;
82
83
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(high_bitdepth);
84
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (seq_profile == AV_PROFILE_AV1_PROFESSIONAL &&
86 current->high_bitdepth) {
87 flag(twelve_bit);
88 priv->bit_depth = current->twelve_bit ? 12 : 10;
89 } else {
90
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 617 times.
1248 priv->bit_depth = current->high_bitdepth ? 10 : 8;
91 }
92
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (seq_profile == AV_PROFILE_AV1_HIGH)
94 infer(mono_chrome, 0);
95 else
96
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(mono_chrome);
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 priv->num_planes = current->mono_chrome ? 1 : 3;
98
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(color_description_present_flag);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->color_description_present_flag) {
101 fb(8, color_primaries);
102 fb(8, transfer_characteristics);
103 fb(8, matrix_coefficients);
104 } else {
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(color_primaries, AVCOL_PRI_UNSPECIFIED);
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(transfer_characteristics, AVCOL_TRC_UNSPECIFIED);
107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED);
108 }
109
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->mono_chrome) {
111 flag(color_range);
112
113 infer(subsampling_x, 1);
114 infer(subsampling_y, 1);
115 infer(chroma_sample_position, AV1_CSP_UNKNOWN);
116 infer(separate_uv_delta_q, 0);
117
118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 } else if (current->color_primaries == AVCOL_PRI_BT709 &&
119 current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 &&
120 current->matrix_coefficients == AVCOL_SPC_RGB) {
121 infer(color_range, 1);
122 infer(subsampling_x, 0);
123 infer(subsampling_y, 0);
124 flag(separate_uv_delta_q);
125
126 } else {
127
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(color_range);
128
129
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (seq_profile == AV_PROFILE_AV1_MAIN) {
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(subsampling_x, 1);
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(subsampling_y, 1);
132 } else if (seq_profile == AV_PROFILE_AV1_HIGH) {
133 infer(subsampling_x, 0);
134 infer(subsampling_y, 0);
135 } else {
136 if (priv->bit_depth == 12) {
137 fb(1, subsampling_x);
138 if (current->subsampling_x)
139 fb(1, subsampling_y);
140 else
141 infer(subsampling_y, 0);
142 } else {
143 infer(subsampling_x, 1);
144 infer(subsampling_y, 0);
145 }
146 }
147
2/4
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
✗ Branch 3 not taken.
1248 if (current->subsampling_x && current->subsampling_y) {
148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fc(2, chroma_sample_position, AV1_CSP_UNKNOWN,
149 AV1_CSP_COLOCATED);
150 }
151
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(separate_uv_delta_q);
153 }
154
155 1248 return 0;
156 }
157
158 746 static int FUNC(timing_info)(CodedBitstreamContext *ctx, RWContext *rw,
159 AV1RawTimingInfo *current)
160 {
161 int err;
162
163
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32));
164
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fc(32, time_scale, 1, MAX_UINT_BITS(32));
165
166
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 flag(equal_picture_interval);
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373 times.
746 if (current->equal_picture_interval)
168 uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1);
169
170 746 return 0;
171 }
172
173 746 static int FUNC(decoder_model_info)(CodedBitstreamContext *ctx, RWContext *rw,
174 AV1RawDecoderModelInfo *current)
175 {
176 int err;
177
178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fb(5, buffer_delay_length_minus_1);
179
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fc(32, num_units_in_decoding_tick, 1, MAX_UINT_BITS(32));
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fb(5, buffer_removal_time_length_minus_1);
181
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fb(5, frame_presentation_time_length_minus_1);
182
183 746 return 0;
184 }
185
186 1248 static int FUNC(sequence_header_obu)(CodedBitstreamContext *ctx, RWContext *rw,
187 AV1RawSequenceHeader *current)
188 {
189 1248 CodedBitstreamAV1Context *priv = ctx->priv_data;
190 int i, err;
191
192 1248 HEADER("Sequence Header");
193
194 1248 priv->seen_frame_header = 0;
195
196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fc(3, seq_profile, AV_PROFILE_AV1_MAIN,
197 AV_PROFILE_AV1_PROFESSIONAL);
198
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(still_picture);
199
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(reduced_still_picture_header);
200
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->reduced_still_picture_header) {
202 infer(timing_info_present_flag, 0);
203 infer(decoder_model_info_present_flag, 0);
204 infer(initial_display_delay_present_flag, 0);
205 infer(operating_points_cnt_minus_1, 0);
206 infer(operating_point_idc[0], 0);
207
208 fb(5, seq_level_idx[0]);
209
210 infer(seq_tier[0], 0);
211 infer(decoder_model_present_for_this_op[0], 0);
212 infer(initial_display_delay_present_for_this_op[0], 0);
213
214 } else {
215
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(timing_info_present_flag);
216
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 251 times.
1248 if (current->timing_info_present_flag) {
217
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 CHECK(FUNC(timing_info)(ctx, rw, &current->timing_info));
218
219
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 flag(decoder_model_info_present_flag);
220
1/2
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
746 if (current->decoder_model_info_present_flag) {
221
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 CHECK(FUNC(decoder_model_info)
222 (ctx, rw, &current->decoder_model_info));
223 }
224 } else {
225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
502 infer(decoder_model_info_present_flag, 0);
226 }
227
228
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(initial_display_delay_present_flag);
229
230
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(5, operating_points_cnt_minus_1);
231
2/2
✓ Branch 0 taken 659 times.
✓ Branch 1 taken 624 times.
2566 for (i = 0; i <= current->operating_points_cnt_minus_1; i++) {
232
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
1318 fbs(12, operating_point_idc[i], 1, i);
233
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 659 times.
1318 fbs(5, seq_level_idx[i], 1, i);
234
235
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 649 times.
1318 if (current->seq_level_idx[i] > 7)
236
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
20 flags(seq_tier[i], 1, i);
237 else
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
1298 infer(seq_tier[i], 0);
239
240
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 286 times.
1318 if (current->decoder_model_info_present_flag) {
241
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 flags(decoder_model_present_for_this_op[i], 1, i);
242
1/2
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
746 if (current->decoder_model_present_for_this_op[i]) {
243 746 int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1;
244
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fbs(n, decoder_buffer_delay[i], 1, i);
245
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fbs(n, encoder_buffer_delay[i], 1, i);
246
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 flags(low_delay_mode_flag[i], 1, i);
247 }
248 } else {
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
572 infer(decoder_model_present_for_this_op[i], 0);
250 }
251
252
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 286 times.
1318 if (current->initial_display_delay_present_flag) {
253
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 flags(initial_display_delay_present_for_this_op[i], 1, i);
254
1/2
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
746 if (current->initial_display_delay_present_for_this_op[i])
255
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
746 fbs(4, initial_display_delay_minus_1[i], 1, i);
256 }
257 }
258 }
259
260
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(4, frame_width_bits_minus_1);
261
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(4, frame_height_bits_minus_1);
262
263
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1);
264
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1);
265
266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->reduced_still_picture_header)
267 infer(frame_id_numbers_present_flag, 0);
268 else
269
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(frame_id_numbers_present_flag);
270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->frame_id_numbers_present_flag) {
271 fb(4, delta_frame_id_length_minus_2);
272 fb(3, additional_frame_id_length_minus_1);
273 }
274
275
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(use_128x128_superblock);
276
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_filter_intra);
277
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_intra_edge_filter);
278
279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 624 times.
1248 if (current->reduced_still_picture_header) {
280 infer(enable_interintra_compound, 0);
281 infer(enable_masked_compound, 0);
282 infer(enable_warped_motion, 0);
283 infer(enable_dual_filter, 0);
284 infer(enable_order_hint, 0);
285 infer(enable_jnt_comp, 0);
286 infer(enable_ref_frame_mvs, 0);
287
288 infer(seq_force_screen_content_tools,
289 AV1_SELECT_SCREEN_CONTENT_TOOLS);
290 infer(seq_force_integer_mv,
291 AV1_SELECT_INTEGER_MV);
292 } else {
293
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_interintra_compound);
294
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_masked_compound);
295
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_warped_motion);
296
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_dual_filter);
297
298
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_order_hint);
299
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (current->enable_order_hint) {
300
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_jnt_comp);
301
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_ref_frame_mvs);
302 } else {
303 infer(enable_jnt_comp, 0);
304 infer(enable_ref_frame_mvs, 0);
305 }
306
307
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(seq_choose_screen_content_tools);
308
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (current->seq_choose_screen_content_tools)
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(seq_force_screen_content_tools,
310 AV1_SELECT_SCREEN_CONTENT_TOOLS);
311 else
312 fb(1, seq_force_screen_content_tools);
313
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (current->seq_force_screen_content_tools > 0) {
314
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(seq_choose_integer_mv);
315
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (current->seq_choose_integer_mv)
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
1248 infer(seq_force_integer_mv,
317 AV1_SELECT_INTEGER_MV);
318 else
319 fb(1, seq_force_integer_mv);
320 } else {
321 infer(seq_force_integer_mv, AV1_SELECT_INTEGER_MV);
322 }
323
324
1/2
✓ Branch 0 taken 624 times.
✗ Branch 1 not taken.
1248 if (current->enable_order_hint)
325
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 fb(3, order_hint_bits_minus_1);
326 }
327
328
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_superres);
329
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_cdef);
330
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(enable_restoration);
331
332
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 CHECK(FUNC(color_config)(ctx, rw, &current->color_config,
333 current->seq_profile));
334
335
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 624 times.
1248 flag(film_grain_params_present);
336
337 1248 return 0;
338 }
339
340 2598 static int FUNC(temporal_delimiter_obu)(CodedBitstreamContext *ctx, RWContext *rw)
341 {
342 2598 CodedBitstreamAV1Context *priv = ctx->priv_data;
343
344 2598 HEADER("Temporal Delimiter");
345
346 2598 priv->seen_frame_header = 0;
347
348 2598 return 0;
349 }
350
351 84 static int FUNC(set_frame_refs)(CodedBitstreamContext *ctx, RWContext *rw,
352 AV1RawFrameHeader *current)
353 {
354 84 CodedBitstreamAV1Context *priv = ctx->priv_data;
355 84 const AV1RawSequenceHeader *seq = priv->sequence_header;
356 static const uint8_t ref_frame_list[AV1_NUM_REF_FRAMES - 2] = {
357 AV1_REF_FRAME_LAST2, AV1_REF_FRAME_LAST3, AV1_REF_FRAME_BWDREF,
358 AV1_REF_FRAME_ALTREF2, AV1_REF_FRAME_ALTREF
359 };
360 int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES];
361 int16_t shifted_order_hints[AV1_NUM_REF_FRAMES];
362 int cur_frame_hint, latest_order_hint, earliest_order_hint, ref;
363 int i, j;
364
365
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 42 times.
672 for (i = 0; i < AV1_REFS_PER_FRAME; i++)
366 588 ref_frame_idx[i] = AV1_REF_FRAME_NONE;
367 84 ref_frame_idx[AV1_REF_FRAME_LAST - AV1_REF_FRAME_LAST] = current->last_frame_idx;
368 84 ref_frame_idx[AV1_REF_FRAME_GOLDEN - AV1_REF_FRAME_LAST] = current->golden_frame_idx;
369
370
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++)
371 672 used_frame[i] = 0;
372 84 used_frame[current->last_frame_idx] = 1;
373 84 used_frame[current->golden_frame_idx] = 1;
374
375 84 cur_frame_hint = 1 << (seq->order_hint_bits_minus_1);
376
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++)
377 672 shifted_order_hints[i] = cur_frame_hint +
378 672 cbs_av1_get_relative_dist(seq, priv->ref[i].order_hint,
379 672 priv->order_hint);
380
381 84 latest_order_hint = shifted_order_hints[current->last_frame_idx];
382 84 earliest_order_hint = shifted_order_hints[current->golden_frame_idx];
383
384 84 ref = AV1_REF_FRAME_NONE;
385
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
386 672 int hint = shifted_order_hints[i];
387
6/6
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 126 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 84 times.
✓ Branch 5 taken 42 times.
672 if (!used_frame[i] && hint >= cur_frame_hint &&
388
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 39 times.
168 (ref < 0 || hint >= latest_order_hint)) {
389 174 ref = i;
390 174 latest_order_hint = hint;
391 }
392 }
393
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 if (ref >= 0) {
394 84 ref_frame_idx[AV1_REF_FRAME_ALTREF - AV1_REF_FRAME_LAST] = ref;
395 84 used_frame[ref] = 1;
396 }
397
398 84 ref = AV1_REF_FRAME_NONE;
399
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
400 672 int hint = shifted_order_hints[i];
401
6/6
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 42 times.
✓ Branch 5 taken 42 times.
672 if (!used_frame[i] && hint >= cur_frame_hint &&
402
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 39 times.
84 (ref < 0 || hint < earliest_order_hint)) {
403 90 ref = i;
404 90 earliest_order_hint = hint;
405 }
406 }
407
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
84 if (ref >= 0) {
408 84 ref_frame_idx[AV1_REF_FRAME_BWDREF - AV1_REF_FRAME_LAST] = ref;
409 84 used_frame[ref] = 1;
410 }
411
412 84 ref = AV1_REF_FRAME_NONE;
413
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
414 672 int hint = shifted_order_hints[i];
415
6/6
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 126 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 36 times.
672 if (!used_frame[i] && hint >= cur_frame_hint &&
416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
12 (ref < 0 || hint < earliest_order_hint)) {
417 72 ref = i;
418 72 earliest_order_hint = hint;
419 }
420 }
421
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 6 times.
84 if (ref >= 0) {
422 72 ref_frame_idx[AV1_REF_FRAME_ALTREF2 - AV1_REF_FRAME_LAST] = ref;
423 72 used_frame[ref] = 1;
424 }
425
426
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 42 times.
504 for (i = 0; i < AV1_REFS_PER_FRAME - 2; i++) {
427 420 int ref_frame = ref_frame_list[i];
428
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 120 times.
420 if (ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] < 0 ) {
429 180 ref = AV1_REF_FRAME_NONE;
430
2/2
✓ Branch 0 taken 720 times.
✓ Branch 1 taken 90 times.
1620 for (j = 0; j < AV1_NUM_REF_FRAMES; j++) {
431 1440 int hint = shifted_order_hints[j];
432
6/6
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 486 times.
✓ Branch 2 taken 222 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 90 times.
1440 if (!used_frame[j] && hint < cur_frame_hint &&
433
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 54 times.
264 (ref < 0 || hint >= latest_order_hint)) {
434 336 ref = j;
435 336 latest_order_hint = hint;
436 }
437 }
438
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
180 if (ref >= 0) {
439 180 ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] = ref;
440 180 used_frame[ref] = 1;
441 }
442 }
443 }
444
445 84 ref = AV1_REF_FRAME_NONE;
446
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 42 times.
756 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
447 672 int hint = shifted_order_hints[i];
448
4/4
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 42 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 261 times.
672 if (ref < 0 || hint < earliest_order_hint) {
449 150 ref = i;
450 150 earliest_order_hint = hint;
451 }
452 }
453
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 42 times.
672 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 294 times.
588 if (ref_frame_idx[i] < 0)
455 ref_frame_idx[i] = ref;
456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
588 infer(ref_frame_idx[i], ref_frame_idx[i]);
457 }
458
459 84 return 0;
460 }
461
462 2930 static int FUNC(superres_params)(CodedBitstreamContext *ctx, RWContext *rw,
463 AV1RawFrameHeader *current)
464 {
465 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
466 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
467 int denom, err;
468
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (seq->enable_superres)
470 flag(use_superres);
471 else
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
2930 infer(use_superres, 0);
473
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (current->use_superres) {
475 fb(3, coded_denom);
476 denom = current->coded_denom + AV1_SUPERRES_DENOM_MIN;
477 } else {
478 2930 denom = AV1_SUPERRES_NUM;
479 }
480
481 2930 priv->upscaled_width = priv->frame_width;
482 2930 priv->frame_width = (priv->upscaled_width * AV1_SUPERRES_NUM +
483 2930 denom / 2) / denom;
484
485 2930 return 0;
486 }
487
488 2840 static int FUNC(frame_size)(CodedBitstreamContext *ctx, RWContext *rw,
489 AV1RawFrameHeader *current)
490 {
491 2840 CodedBitstreamAV1Context *priv = ctx->priv_data;
492 2840 const AV1RawSequenceHeader *seq = priv->sequence_header;
493 int err;
494
495
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1409 times.
2840 if (current->frame_size_override_flag) {
496
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
22 fb(seq->frame_width_bits_minus_1 + 1, frame_width_minus_1);
497
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
22 fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1);
498 } else {
499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 356 times.
2818 infer(frame_width_minus_1, seq->max_frame_width_minus_1);
500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 356 times.
2818 infer(frame_height_minus_1, seq->max_frame_height_minus_1);
501 }
502
503 2840 priv->frame_width = current->frame_width_minus_1 + 1;
504 2840 priv->frame_height = current->frame_height_minus_1 + 1;
505
506
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1420 times.
2840 CHECK(FUNC(superres_params)(ctx, rw, current));
507
508 2840 return 0;
509 }
510
511 2840 static int FUNC(render_size)(CodedBitstreamContext *ctx, RWContext *rw,
512 AV1RawFrameHeader *current)
513 {
514 2840 CodedBitstreamAV1Context *priv = ctx->priv_data;
515 int err;
516
517
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1420 times.
2840 flag(render_and_frame_size_different);
518
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1420 times.
2840 if (current->render_and_frame_size_different) {
520 fb(16, render_width_minus_1);
521 fb(16, render_height_minus_1);
522 } else {
523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
2840 infer(render_width_minus_1, current->frame_width_minus_1);
524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
2840 infer(render_height_minus_1, current->frame_height_minus_1);
525 }
526
527 2840 priv->render_width = current->render_width_minus_1 + 1;
528 2840 priv->render_height = current->render_height_minus_1 + 1;
529
530 2840 return 0;
531 }
532
533 90 static int FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw,
534 AV1RawFrameHeader *current)
535 {
536 90 CodedBitstreamAV1Context *priv = ctx->priv_data;
537 int i, err;
538
539
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
90 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
540
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
90 flags(found_ref[i], 1, i);
541
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
90 if (current->found_ref[i]) {
542 90 AV1ReferenceFrameState *ref =
543 90 &priv->ref[current->ref_frame_idx[i]];
544
545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
90 if (!ref->valid) {
546 av_log(ctx->log_ctx, AV_LOG_ERROR,
547 "Missing reference frame needed for frame size "
548 "(ref = %d, ref_frame_idx = %d).\n",
549 i, current->ref_frame_idx[i]);
550 return AVERROR_INVALIDDATA;
551 }
552
553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
90 infer(frame_width_minus_1, ref->upscaled_width - 1);
554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
90 infer(frame_height_minus_1, ref->frame_height - 1);
555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
90 infer(render_width_minus_1, ref->render_width - 1);
556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
90 infer(render_height_minus_1, ref->render_height - 1);
557
558 90 priv->upscaled_width = ref->upscaled_width;
559 90 priv->frame_width = priv->upscaled_width;
560 90 priv->frame_height = ref->frame_height;
561 90 priv->render_width = ref->render_width;
562 90 priv->render_height = ref->render_height;
563 90 break;
564 }
565 }
566
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
90 if (i >= AV1_REFS_PER_FRAME) {
568 CHECK(FUNC(frame_size)(ctx, rw, current));
569 CHECK(FUNC(render_size)(ctx, rw, current));
570 } else {
571
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
90 CHECK(FUNC(superres_params)(ctx, rw, current));
572 }
573
574 90 return 0;
575 }
576
577 2510 static int FUNC(interpolation_filter)(CodedBitstreamContext *ctx, RWContext *rw,
578 AV1RawFrameHeader *current)
579 {
580 int err;
581
582
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 flag(is_filter_switchable);
583
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 231 times.
2510 if (current->is_filter_switchable)
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
2048 infer(interpolation_filter,
585 AV1_INTERPOLATION_FILTER_SWITCHABLE);
586 else
587
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 231 times.
462 fb(2, interpolation_filter);
588
589 2510 return 0;
590 }
591
592 2930 static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw,
593 AV1RawFrameHeader *current)
594 {
595 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
596 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
597 int mi_cols, mi_rows, sb_cols, sb_rows, sb_shift, sb_size;
598 int max_tile_width_sb, max_tile_height_sb, max_tile_area_sb;
599 int min_log2_tile_cols, max_log2_tile_cols, max_log2_tile_rows;
600 int min_log2_tiles, min_log2_tile_rows;
601 int err;
602
603 2930 mi_cols = 2 * ((priv->frame_width + 7) >> 3);
604 2930 mi_rows = 2 * ((priv->frame_height + 7) >> 3);
605
606 7100 sb_cols = seq->use_128x128_superblock ? ((mi_cols + 31) >> 5)
607
2/2
✓ Branch 0 taken 620 times.
✓ Branch 1 taken 845 times.
2930 : ((mi_cols + 15) >> 4);
608 7100 sb_rows = seq->use_128x128_superblock ? ((mi_rows + 31) >> 5)
609
2/2
✓ Branch 0 taken 620 times.
✓ Branch 1 taken 845 times.
2930 : ((mi_rows + 15) >> 4);
610
611
2/2
✓ Branch 0 taken 620 times.
✓ Branch 1 taken 845 times.
2930 sb_shift = seq->use_128x128_superblock ? 5 : 4;
612 2930 sb_size = sb_shift + 2;
613
614 2930 max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size;
615 2930 max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size);
616
617 2930 min_log2_tile_cols = cbs_av1_tile_log2(max_tile_width_sb, sb_cols);
618 2930 max_log2_tile_cols = cbs_av1_tile_log2(1, FFMIN(sb_cols, AV1_MAX_TILE_COLS));
619 2930 max_log2_tile_rows = cbs_av1_tile_log2(1, FFMIN(sb_rows, AV1_MAX_TILE_ROWS));
620
1/2
✓ Branch 1 taken 1465 times.
✗ Branch 2 not taken.
2930 min_log2_tiles = FFMAX(min_log2_tile_cols,
621 cbs_av1_tile_log2(max_tile_area_sb, sb_rows * sb_cols));
622
623
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(uniform_tile_spacing_flag);
624
625
2/2
✓ Branch 0 taken 1386 times.
✓ Branch 1 taken 79 times.
2930 if (current->uniform_tile_spacing_flag) {
626 int tile_width_sb, tile_height_sb;
627
628
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1386 times.
2772 increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
629
630 2772 tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >>
631 2772 current->tile_cols_log2;
632
633
2/2
✓ Branch 0 taken 1756 times.
✓ Branch 1 taken 1386 times.
6284 for (int off = 0, j = 0; off < sb_cols; off += tile_width_sb)
634 3512 current->tile_start_col_sb[j++] = off;
635
636 2772 current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb;
637
638 2772 min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0);
639
640
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1386 times.
2772 increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows);
641
642 2772 tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >>
643 2772 current->tile_rows_log2;
644
645
2/2
✓ Branch 0 taken 1456 times.
✓ Branch 1 taken 1386 times.
5684 for (int off = 0, j = 0; off < sb_rows; off += tile_height_sb)
646 2912 current->tile_start_row_sb[j++] = off;
647
648 2772 current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb;
649
650 int i;
651
2/2
✓ Branch 0 taken 370 times.
✓ Branch 1 taken 1386 times.
3512 for (i = 0; i < current->tile_cols - 1; i++)
652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 118 times.
740 infer(width_in_sbs_minus_1[i], tile_width_sb - 1);
653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
2772 infer(width_in_sbs_minus_1[i],
654 sb_cols - (current->tile_cols - 1) * tile_width_sb - 1);
655
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 1386 times.
2912 for (i = 0; i < current->tile_rows - 1; i++)
656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
140 infer(height_in_sbs_minus_1[i], tile_height_sb - 1);
657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 348 times.
2772 infer(height_in_sbs_minus_1[i],
658 sb_rows - (current->tile_rows - 1) * tile_height_sb - 1);
659
660 } else {
661 int widest_tile_sb, start_sb, size_sb, max_width, max_height, i;
662
663 158 widest_tile_sb = 0;
664
665 158 start_sb = 0;
666
3/4
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
316 for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) {
667 158 current->tile_start_col_sb[i] = start_sb;
668 158 max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb);
669
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
158 ns(max_width, width_in_sbs_minus_1[i], 1, i);
670 158 size_sb = current->width_in_sbs_minus_1[i] + 1;
671 158 widest_tile_sb = FFMAX(size_sb, widest_tile_sb);
672 158 start_sb += size_sb;
673 }
674 158 current->tile_cols_log2 = cbs_av1_tile_log2(1, i);
675 158 current->tile_cols = i;
676
677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
158 if (min_log2_tiles > 0)
678 max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1);
679 else
680 158 max_tile_area_sb = sb_rows * sb_cols;
681 158 max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1);
682
683 158 start_sb = 0;
684
3/4
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 316 times.
✗ Branch 3 not taken.
790 for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) {
685 632 current->tile_start_row_sb[i] = start_sb;
686 632 max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb);
687
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 316 times.
632 ns(max_height, height_in_sbs_minus_1[i], 1, i);
688 632 size_sb = current->height_in_sbs_minus_1[i] + 1;
689 632 start_sb += size_sb;
690 }
691 158 current->tile_rows_log2 = cbs_av1_tile_log2(1, i);
692 158 current->tile_rows = i;
693 }
694
695
2/2
✓ Branch 0 taken 1305 times.
✓ Branch 1 taken 160 times.
2930 if (current->tile_cols_log2 > 0 ||
696
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 1226 times.
2610 current->tile_rows_log2 > 0) {
697
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
478 fb(current->tile_cols_log2 + current->tile_rows_log2,
698 context_update_tile_id);
699
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
478 fb(2, tile_size_bytes_minus1);
700 } else {
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
2452 infer(context_update_tile_id, 0);
702 }
703
704 2930 priv->tile_cols = current->tile_cols;
705 2930 priv->tile_rows = current->tile_rows;
706
707 2930 return 0;
708 }
709
710 2930 static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw,
711 AV1RawFrameHeader *current)
712 {
713 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
714 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
715 int err;
716
717
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(8, base_q_idx);
718
719
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1465 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2930 delta_q(delta_q_y_dc);
720
721
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (priv->num_planes > 1) {
722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (seq->color_config.separate_uv_delta_q)
723 flag(diff_uv_delta);
724 else
725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
2930 infer(diff_uv_delta, 0);
726
727
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1465 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2930 delta_q(delta_q_u_dc);
728
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1465 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2930 delta_q(delta_q_u_ac);
729
730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (current->diff_uv_delta) {
731 delta_q(delta_q_v_dc);
732 delta_q(delta_q_v_ac);
733 } else {
734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
2930 infer(delta_q_v_dc, current->delta_q_u_dc);
735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
2930 infer(delta_q_v_ac, current->delta_q_u_ac);
736 }
737 } else {
738 infer(delta_q_u_dc, 0);
739 infer(delta_q_u_ac, 0);
740 infer(delta_q_v_dc, 0);
741 infer(delta_q_v_ac, 0);
742 }
743
744
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(using_qmatrix);
745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (current->using_qmatrix) {
746 fb(4, qm_y);
747 fb(4, qm_u);
748 if (seq->color_config.separate_uv_delta_q)
749 fb(4, qm_v);
750 else
751 infer(qm_v, current->qm_u);
752 }
753
754 2930 return 0;
755 }
756
757 2930 static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw,
758 AV1RawFrameHeader *current)
759 {
760 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
761 static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 };
762 static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 };
763 static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 };
764 static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 };
765 int i, j, err;
766
767
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(segmentation_enabled);
768
769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (current->segmentation_enabled) {
770 if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
771 infer(segmentation_update_map, 1);
772 infer(segmentation_temporal_update, 0);
773 infer(segmentation_update_data, 1);
774 } else {
775 flag(segmentation_update_map);
776 if (current->segmentation_update_map)
777 flag(segmentation_temporal_update);
778 else
779 infer(segmentation_temporal_update, 0);
780 flag(segmentation_update_data);
781 }
782
783 for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
784 const uint8_t *ref_feature_enabled;
785 const int16_t *ref_feature_value;
786
787 if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
788 ref_feature_enabled = default_feature_enabled;
789 ref_feature_value = default_feature_value;
790 } else {
791 ref_feature_enabled =
792 priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i];
793 ref_feature_value =
794 priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i];
795 }
796
797 for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
798 if (current->segmentation_update_data) {
799 flags(feature_enabled[i][j], 2, i, j);
800
801 if (current->feature_enabled[i][j] && bits[j] > 0) {
802 if (sign[j])
803 sus(1 + bits[j], feature_value[i][j], 2, i, j);
804 else
805 fbs(bits[j], feature_value[i][j], 2, i, j);
806 } else {
807 infer(feature_value[i][j], 0);
808 }
809 } else {
810 infer(feature_enabled[i][j], ref_feature_enabled[j]);
811 infer(feature_value[i][j], ref_feature_value[j]);
812 }
813 }
814 }
815 } else {
816
2/2
✓ Branch 0 taken 11720 times.
✓ Branch 1 taken 1465 times.
26370 for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
817
2/2
✓ Branch 0 taken 93760 times.
✓ Branch 1 taken 11720 times.
210960 for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23936 times.
187520 infer(feature_enabled[i][j], 0);
819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23936 times.
187520 infer(feature_value[i][j], 0);
820 }
821 }
822 }
823
824 2930 return 0;
825 }
826
827 2930 static int FUNC(delta_q_params)(CodedBitstreamContext *ctx, RWContext *rw,
828 AV1RawFrameHeader *current)
829 {
830 int err;
831
832
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (current->base_q_idx > 0)
833
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(delta_q_present);
834 else
835 infer(delta_q_present, 0);
836
837
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1433 times.
2930 if (current->delta_q_present)
838
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
64 fb(2, delta_q_res);
839
840 2930 return 0;
841 }
842
843 2930 static int FUNC(delta_lf_params)(CodedBitstreamContext *ctx, RWContext *rw,
844 AV1RawFrameHeader *current)
845 {
846 int err;
847
848
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1433 times.
2930 if (current->delta_q_present) {
849
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
64 if (!current->allow_intrabc)
850
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
64 flag(delta_lf_present);
851 else
852 infer(delta_lf_present, 0);
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
64 if (current->delta_lf_present) {
854 fb(2, delta_lf_res);
855 flag(delta_lf_multi);
856 } else {
857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
64 infer(delta_lf_res, 0);
858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
64 infer(delta_lf_multi, 0);
859 }
860 } else {
861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
2866 infer(delta_lf_present, 0);
862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
2866 infer(delta_lf_res, 0);
863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
2866 infer(delta_lf_multi, 0);
864 }
865
866 2930 return 0;
867 }
868
869 2930 static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw,
870 AV1RawFrameHeader *current)
871 {
872 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
873 static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] =
874 { 1, 0, 0, 0, -1, 0, -1, -1 };
875 static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 };
876 int i, err;
877
878
2/4
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1465 times.
2930 if (priv->coded_lossless || current->allow_intrabc) {
879 infer(loop_filter_level[0], 0);
880 infer(loop_filter_level[1], 0);
881 infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1);
882 infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0);
883 infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0);
884 infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0);
885 infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0);
886 infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1);
887 infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1);
888 infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1);
889 for (i = 0; i < 2; i++)
890 infer(loop_filter_mode_deltas[i], 0);
891 return 0;
892 }
893
894
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(6, loop_filter_level[0]);
895
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(6, loop_filter_level[1]);
896
897
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (priv->num_planes > 1) {
898
2/2
✓ Branch 0 taken 741 times.
✓ Branch 1 taken 724 times.
2930 if (current->loop_filter_level[0] ||
899
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 725 times.
1482 current->loop_filter_level[1]) {
900
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 740 times.
1480 fb(6, loop_filter_level[2]);
901
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 740 times.
1480 fb(6, loop_filter_level[3]);
902 }
903 }
904
905
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(3, loop_filter_sharpness);
906
907
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(loop_filter_delta_enabled);
908
2/2
✓ Branch 0 taken 1357 times.
✓ Branch 1 taken 108 times.
2930 if (current->loop_filter_delta_enabled) {
909 const int8_t *ref_loop_filter_ref_deltas, *ref_loop_filter_mode_deltas;
910
911
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 996 times.
2714 if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
912 722 ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas;
913 722 ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas;
914 } else {
915 1992 ref_loop_filter_ref_deltas =
916 1992 priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas;
917 1992 ref_loop_filter_mode_deltas =
918 1992 priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas;
919 }
920
921
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1357 times.
2714 flag(loop_filter_delta_update);
922
2/2
✓ Branch 0 taken 10856 times.
✓ Branch 1 taken 1357 times.
24426 for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
923
2/2
✓ Branch 0 taken 2888 times.
✓ Branch 1 taken 7968 times.
21712 if (current->loop_filter_delta_update)
924
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2888 times.
5776 flags(update_ref_delta[i], 1, i);
925 else
926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2176 times.
15936 infer(update_ref_delta[i], 0);
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10856 times.
21712 if (current->update_ref_delta[i])
928 sus(1 + 6, loop_filter_ref_deltas[i], 1, i);
929 else
930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2992 times.
21712 infer(loop_filter_ref_deltas[i], ref_loop_filter_ref_deltas[i]);
931 }
932
2/2
✓ Branch 0 taken 2714 times.
✓ Branch 1 taken 1357 times.
8142 for (i = 0; i < 2; i++) {
933
2/2
✓ Branch 0 taken 722 times.
✓ Branch 1 taken 1992 times.
5428 if (current->loop_filter_delta_update)
934
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 722 times.
1444 flags(update_mode_delta[i], 1, i);
935 else
936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 544 times.
3984 infer(update_mode_delta[i], 0);
937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2714 times.
5428 if (current->update_mode_delta[i])
938 sus(1 + 6, loop_filter_mode_deltas[i], 1, i);
939 else
940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748 times.
5428 infer(loop_filter_mode_deltas[i], ref_loop_filter_mode_deltas[i]);
941 }
942 } else {
943
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 108 times.
1944 for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++)
944
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1728 infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]);
945
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 108 times.
648 for (i = 0; i < 2; i++)
946
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
432 infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]);
947 }
948
949 2930 return 0;
950 }
951
952 2930 static int FUNC(cdef_params)(CodedBitstreamContext *ctx, RWContext *rw,
953 AV1RawFrameHeader *current)
954 {
955 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
956 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
957 int i, err;
958
959
2/4
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
✗ Branch 3 not taken.
2930 if (priv->coded_lossless || current->allow_intrabc ||
960
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 1333 times.
2930 !seq->enable_cdef) {
961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_damping_minus_3, 0);
962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_bits, 0);
963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_y_pri_strength[0], 0);
964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_y_sec_strength[0], 0);
965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_uv_pri_strength[0], 0);
966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
264 infer(cdef_uv_sec_strength[0], 0);
967
968 264 return 0;
969 }
970
971
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1333 times.
2666 fb(2, cdef_damping_minus_3);
972
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1333 times.
2666 fb(2, cdef_bits);
973
974
2/2
✓ Branch 0 taken 4822 times.
✓ Branch 1 taken 1333 times.
12310 for (i = 0; i < (1 << current->cdef_bits); i++) {
975
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4822 times.
9644 fbs(4, cdef_y_pri_strength[i], 1, i);
976
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4822 times.
9644 fbs(2, cdef_y_sec_strength[i], 1, i);
977
978
1/2
✓ Branch 0 taken 4822 times.
✗ Branch 1 not taken.
9644 if (priv->num_planes > 1) {
979
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4822 times.
9644 fbs(4, cdef_uv_pri_strength[i], 1, i);
980
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4822 times.
9644 fbs(2, cdef_uv_sec_strength[i], 1, i);
981 }
982 }
983
984 2666 return 0;
985 }
986
987 2930 static int FUNC(lr_params)(CodedBitstreamContext *ctx, RWContext *rw,
988 AV1RawFrameHeader *current)
989 {
990 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
991 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
992 int uses_lr, uses_chroma_lr;
993 int i, err;
994
995
2/4
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
✗ Branch 3 not taken.
2930 if (priv->all_lossless || current->allow_intrabc ||
996
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 1260 times.
2930 !seq->enable_restoration) {
997 410 return 0;
998 }
999
1000 2520 uses_lr = uses_chroma_lr = 0;
1001
2/2
✓ Branch 0 taken 3780 times.
✓ Branch 1 taken 1260 times.
10080 for (i = 0; i < priv->num_planes; i++) {
1002
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3780 times.
7560 fbs(2, lr_type[i], 1, i);
1003
1004
2/2
✓ Branch 0 taken 958 times.
✓ Branch 1 taken 2822 times.
7560 if (current->lr_type[i] != AV1_RESTORE_NONE) {
1005 1916 uses_lr = 1;
1006
2/2
✓ Branch 0 taken 356 times.
✓ Branch 1 taken 602 times.
1916 if (i > 0)
1007 712 uses_chroma_lr = 1;
1008 }
1009 }
1010
1011
2/2
✓ Branch 0 taken 666 times.
✓ Branch 1 taken 594 times.
2520 if (uses_lr) {
1012
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 282 times.
1332 if (seq->use_128x128_superblock)
1013
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 384 times.
768 increment(lr_unit_shift, 1, 2);
1014 else
1015
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 282 times.
564 increment(lr_unit_shift, 0, 2);
1016
1017
1/2
✓ Branch 0 taken 666 times.
✗ Branch 1 not taken.
1332 if(seq->color_config.subsampling_x &&
1018
3/4
✓ Branch 0 taken 666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
✓ Branch 3 taken 437 times.
1332 seq->color_config.subsampling_y && uses_chroma_lr) {
1019
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
458 fb(1, lr_uv_shift);
1020 } else {
1021
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
874 infer(lr_uv_shift, 0);
1022 }
1023 }
1024
1025 2520 return 0;
1026 }
1027
1028 2930 static int FUNC(read_tx_mode)(CodedBitstreamContext *ctx, RWContext *rw,
1029 AV1RawFrameHeader *current)
1030 {
1031 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
1032 int err;
1033
1034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (priv->coded_lossless)
1035 infer(tx_mode, AV1_ONLY_4X4);
1036 else
1037
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT);
1038
1039 2930 return 0;
1040 }
1041
1042 2930 static int FUNC(frame_reference_mode)(CodedBitstreamContext *ctx, RWContext *rw,
1043 AV1RawFrameHeader *current)
1044 {
1045 int err;
1046
1047
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (current->frame_type == AV1_FRAME_INTRA_ONLY ||
1048
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1255 times.
2930 current->frame_type == AV1_FRAME_KEY)
1049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
420 infer(reference_select, 0);
1050 else
1051
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 flag(reference_select);
1052
1053 2930 return 0;
1054 }
1055
1056 2930 static int FUNC(skip_mode_params)(CodedBitstreamContext *ctx, RWContext *rw,
1057 AV1RawFrameHeader *current)
1058 {
1059 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
1060 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
1061 int skip_mode_allowed;
1062 int err;
1063
1064
2/2
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 210 times.
2930 if (current->frame_type == AV1_FRAME_KEY ||
1065
1/2
✓ Branch 0 taken 1255 times.
✗ Branch 1 not taken.
2510 current->frame_type == AV1_FRAME_INTRA_ONLY ||
1066
3/4
✓ Branch 0 taken 789 times.
✓ Branch 1 taken 466 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 789 times.
2510 !current->reference_select || !seq->enable_order_hint) {
1067 1352 skip_mode_allowed = 0;
1068 } else {
1069 int forward_idx, backward_idx;
1070 int forward_hint, backward_hint;
1071 int ref_hint, dist, i;
1072
1073 1578 forward_idx = -1;
1074 1578 backward_idx = -1;
1075
2/2
✓ Branch 0 taken 5523 times.
✓ Branch 1 taken 789 times.
12624 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1076 11046 ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1077 11046 dist = cbs_av1_get_relative_dist(seq, ref_hint,
1078 11046 priv->order_hint);
1079
2/2
✓ Branch 0 taken 4603 times.
✓ Branch 1 taken 920 times.
11046 if (dist < 0) {
1080
4/4
✓ Branch 0 taken 3814 times.
✓ Branch 1 taken 789 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 3718 times.
16834 if (forward_idx < 0 ||
1081 7628 cbs_av1_get_relative_dist(seq, ref_hint,
1082 forward_hint) > 0) {
1083 1770 forward_idx = i;
1084 1770 forward_hint = ref_hint;
1085 }
1086
2/2
✓ Branch 0 taken 887 times.
✓ Branch 1 taken 33 times.
1840 } else if (dist > 0) {
1087
3/4
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 438 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 449 times.
2672 if (backward_idx < 0 ||
1088 898 cbs_av1_get_relative_dist(seq, ref_hint,
1089 backward_hint) < 0) {
1090 876 backward_idx = i;
1091 876 backward_hint = ref_hint;
1092 }
1093 }
1094 }
1095
1096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 789 times.
1578 if (forward_idx < 0) {
1097 skip_mode_allowed = 0;
1098
2/2
✓ Branch 0 taken 438 times.
✓ Branch 1 taken 351 times.
1578 } else if (backward_idx >= 0) {
1099 876 skip_mode_allowed = 1;
1100 // Frames for skip mode are forward_idx and backward_idx.
1101 } else {
1102 int second_forward_idx;
1103 int second_forward_hint;
1104
1105 702 second_forward_idx = -1;
1106
2/2
✓ Branch 0 taken 2457 times.
✓ Branch 1 taken 351 times.
5616 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1107 4914 ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1108
2/2
✓ Branch 1 taken 1935 times.
✓ Branch 2 taken 522 times.
4914 if (cbs_av1_get_relative_dist(seq, ref_hint,
1109 forward_hint) < 0) {
1110
4/4
✓ Branch 0 taken 1600 times.
✓ Branch 1 taken 335 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 1577 times.
7070 if (second_forward_idx < 0 ||
1111 3200 cbs_av1_get_relative_dist(seq, ref_hint,
1112 second_forward_hint) > 0) {
1113 716 second_forward_idx = i;
1114 716 second_forward_hint = ref_hint;
1115 }
1116 }
1117 }
1118
1119
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 335 times.
702 if (second_forward_idx < 0) {
1120 32 skip_mode_allowed = 0;
1121 } else {
1122 670 skip_mode_allowed = 1;
1123 // Frames for skip mode are forward_idx and second_forward_idx.
1124 }
1125 }
1126 }
1127
1128
2/2
✓ Branch 0 taken 773 times.
✓ Branch 1 taken 692 times.
2930 if (skip_mode_allowed)
1129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 773 times.
1546 flag(skip_mode_present);
1130 else
1131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 204 times.
1384 infer(skip_mode_present, 0);
1132
1133 2930 return 0;
1134 }
1135
1136 488 static int FUNC(global_motion_param)(CodedBitstreamContext *ctx, RWContext *rw,
1137 AV1RawFrameHeader *current,
1138 int type, int ref, int idx)
1139 {
1140 uint32_t abs_bits, prec_bits, num_syms;
1141 int err;
1142
1143
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 122 times.
488 if (idx < 2) {
1144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
244 if (type == AV1_WARP_MODEL_TRANSLATION) {
1145 abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv;
1146 prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv;
1147 } else {
1148 244 abs_bits = AV1_GM_ABS_TRANS_BITS;
1149 244 prec_bits = AV1_GM_TRANS_PREC_BITS;
1150 }
1151 } else {
1152 244 abs_bits = AV1_GM_ABS_ALPHA_BITS;
1153 244 prec_bits = AV1_GM_ALPHA_PREC_BITS;
1154 }
1155
1156 488 num_syms = 2 * (1 << abs_bits) + 1;
1157
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 244 times.
488 subexp(gm_params[ref][idx], num_syms, 2, ref, idx);
1158
1159 // Actual gm_params value is not reconstructed here.
1160 (void)prec_bits;
1161
1162 488 return 0;
1163 }
1164
1165 2930 static int FUNC(global_motion_params)(CodedBitstreamContext *ctx, RWContext *rw,
1166 AV1RawFrameHeader *current)
1167 {
1168 int ref, type;
1169 int err;
1170
1171
2/2
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 210 times.
2930 if (current->frame_type == AV1_FRAME_KEY ||
1172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1255 times.
2510 current->frame_type == AV1_FRAME_INTRA_ONLY)
1173 420 return 0;
1174
1175
2/2
✓ Branch 0 taken 8785 times.
✓ Branch 1 taken 1255 times.
20080 for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
1176
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8785 times.
17570 flags(is_global[ref], 1, ref);
1177
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 8724 times.
17570 if (current->is_global[ref]) {
1178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
122 flags(is_rot_zoom[ref], 1, ref);
1179
1/2
✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
122 if (current->is_rot_zoom[ref]) {
1180 122 type = AV1_WARP_MODEL_ROTZOOM;
1181 } else {
1182 flags(is_translation[ref], 1, ref);
1183 type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
1184 : AV1_WARP_MODEL_AFFINE;
1185 }
1186 } else {
1187 17448 type = AV1_WARP_MODEL_IDENTITY;
1188 }
1189
1190
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 8724 times.
17570 if (type >= AV1_WARP_MODEL_ROTZOOM) {
1191
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
122 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2));
1192
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
122 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3));
1193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
122 if (type == AV1_WARP_MODEL_AFFINE) {
1194 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4));
1195 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5));
1196 } else {
1197 // gm_params[ref][4] = -gm_params[ref][3]
1198 // gm_params[ref][5] = gm_params[ref][2]
1199 }
1200 }
1201
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 8724 times.
17570 if (type >= AV1_WARP_MODEL_TRANSLATION) {
1202
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
122 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0));
1203
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
122 CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1));
1204 }
1205 }
1206
1207 2510 return 0;
1208 }
1209
1210 2930 static int FUNC(film_grain_params)(CodedBitstreamContext *ctx, RWContext *rw,
1211 AV1RawFilmGrainParams *current,
1212 AV1RawFrameHeader *frame_header)
1213 {
1214 2930 CodedBitstreamAV1Context *priv = ctx->priv_data;
1215 2930 const AV1RawSequenceHeader *seq = priv->sequence_header;
1216 int num_pos_luma, num_pos_chroma;
1217 int i, err;
1218
1219
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 1397 times.
2930 if (!seq->film_grain_params_present ||
1220
4/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 18 times.
136 (!frame_header->show_frame && !frame_header->showable_frame))
1221 2806 return 0;
1222
1223
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 flag(apply_grain);
1224
1225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
124 if (!current->apply_grain)
1226 return 0;
1227
1228
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(16, grain_seed);
1229
1230
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 8 times.
124 if (frame_header->frame_type == AV1_FRAME_INTER)
1231
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
108 flag(update_grain);
1232 else
1233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
16 infer(update_grain, 1);
1234
1235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
124 if (!current->update_grain) {
1236 fb(3, film_grain_params_ref_idx);
1237 return 0;
1238 }
1239
1240
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fc(4, num_y_points, 0, 14);
1241
2/2
✓ Branch 0 taken 428 times.
✓ Branch 1 taken 62 times.
980 for (i = 0; i < current->num_y_points; i++) {
1242
3/4
✓ Branch 0 taken 366 times.
✓ Branch 1 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 428 times.
856 fcs(8, point_y_value[i],
1243 i ? current->point_y_value[i - 1] + 1 : 0,
1244 MAX_UINT_BITS(8) - (current->num_y_points - i - 1),
1245 1, i);
1246
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 428 times.
856 fbs(8, point_y_scaling[i], 1, i);
1247 }
1248
1249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
124 if (seq->color_config.mono_chrome)
1250 infer(chroma_scaling_from_luma, 0);
1251 else
1252
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 flag(chroma_scaling_from_luma);
1253
1254
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 if (seq->color_config.mono_chrome ||
1255
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 current->chroma_scaling_from_luma ||
1256
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 (seq->color_config.subsampling_x == 1 &&
1257
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 seq->color_config.subsampling_y == 1 &&
1258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
124 current->num_y_points == 0)) {
1259 infer(num_cb_points, 0);
1260 infer(num_cr_points, 0);
1261 } else {
1262
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fc(4, num_cb_points, 0, 10);
1263
2/2
✓ Branch 0 taken 242 times.
✓ Branch 1 taken 62 times.
608 for (i = 0; i < current->num_cb_points; i++) {
1264
3/4
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 242 times.
484 fcs(8, point_cb_value[i],
1265 i ? current->point_cb_value[i - 1] + 1 : 0,
1266 MAX_UINT_BITS(8) - (current->num_cb_points - i - 1),
1267 1, i);
1268
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 242 times.
484 fbs(8, point_cb_scaling[i], 1, i);
1269 }
1270
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fc(4, num_cr_points, 0, 10);
1271
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 62 times.
620 for (i = 0; i < current->num_cr_points; i++) {
1272
3/4
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 248 times.
496 fcs(8, point_cr_value[i],
1273 i ? current->point_cr_value[i - 1] + 1 : 0,
1274 MAX_UINT_BITS(8) - (current->num_cr_points - i - 1),
1275 1, i);
1276
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
496 fbs(8, point_cr_scaling[i], 1, i);
1277 }
1278 }
1279
1280
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(2, grain_scaling_minus_8);
1281
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(2, ar_coeff_lag);
1282 124 num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1);
1283
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 if (current->num_y_points) {
1284 124 num_pos_chroma = num_pos_luma + 1;
1285
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 62 times.
3100 for (i = 0; i < num_pos_luma; i++)
1286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1488 times.
2976 fbs(8, ar_coeffs_y_plus_128[i], 1, i);
1287 } else {
1288 num_pos_chroma = num_pos_luma;
1289 }
1290
2/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
124 if (current->chroma_scaling_from_luma || current->num_cb_points) {
1291
2/2
✓ Branch 0 taken 1550 times.
✓ Branch 1 taken 62 times.
3224 for (i = 0; i < num_pos_chroma; i++)
1292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1550 times.
3100 fbs(8, ar_coeffs_cb_plus_128[i], 1, i);
1293 }
1294
2/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
124 if (current->chroma_scaling_from_luma || current->num_cr_points) {
1295
2/2
✓ Branch 0 taken 1550 times.
✓ Branch 1 taken 62 times.
3224 for (i = 0; i < num_pos_chroma; i++)
1296
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1550 times.
3100 fbs(8, ar_coeffs_cr_plus_128[i], 1, i);
1297 }
1298
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(2, ar_coeff_shift_minus_6);
1299
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(2, grain_scale_shift);
1300
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 if (current->num_cb_points) {
1301
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(8, cb_mult);
1302
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(8, cb_luma_mult);
1303
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(9, cb_offset);
1304 }
1305
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 if (current->num_cr_points) {
1306
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(8, cr_mult);
1307
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(8, cr_luma_mult);
1308
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 fb(9, cr_offset);
1309 }
1310
1311
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 flag(overlap_flag);
1312
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
124 flag(clip_to_restricted_range);
1313
1314 124 return 0;
1315 }
1316
1317 3350 static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
1318 AV1RawFrameHeader *current)
1319 {
1320 3350 CodedBitstreamAV1Context *priv = ctx->priv_data;
1321 const AV1RawSequenceHeader *seq;
1322 int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits;
1323 int i, err;
1324
1325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1675 times.
3350 if (!priv->sequence_header) {
1326 av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1327 "unable to decode frame header.\n");
1328 return AVERROR_INVALIDDATA;
1329 }
1330 3350 seq = priv->sequence_header;
1331
1332 3350 id_len = seq->additional_frame_id_length_minus_1 +
1333 3350 seq->delta_frame_id_length_minus_2 + 3;
1334 3350 all_frames = (1 << AV1_NUM_REF_FRAMES) - 1;
1335
1336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1675 times.
3350 if (seq->reduced_still_picture_header) {
1337 infer(show_existing_frame, 0);
1338 infer(frame_type, AV1_FRAME_KEY);
1339 infer(show_frame, 1);
1340 infer(showable_frame, 0);
1341 frame_is_intra = 1;
1342
1343 } else {
1344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1675 times.
3350 flag(show_existing_frame);
1345
1346
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1465 times.
3350 if (current->show_existing_frame) {
1347 AV1ReferenceFrameState *ref;
1348
1349
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
420 fb(3, frame_to_show_map_idx);
1350 420 ref = &priv->ref[current->frame_to_show_map_idx];
1351
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
420 if (!ref->valid) {
1353 av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame needed for "
1354 "show_existing_frame (frame_to_show_map_idx = %d).\n",
1355 current->frame_to_show_map_idx);
1356 return AVERROR_INVALIDDATA;
1357 }
1358
1359
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 175 times.
420 if (seq->decoder_model_info_present_flag &&
1360
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
70 !seq->timing_info.equal_picture_interval) {
1361
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
70 fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1,
1362 frame_presentation_time);
1363 }
1364
1365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
420 if (seq->frame_id_numbers_present_flag)
1366 fb(id_len, display_frame_id);
1367
1368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(frame_type, ref->frame_type);
1369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
420 if (current->frame_type == AV1_FRAME_KEY) {
1370 infer(refresh_frame_flags, all_frames);
1371
1372 // Section 7.21
1373 infer(current_frame_id, ref->frame_id);
1374 priv->upscaled_width = ref->upscaled_width;
1375 priv->frame_width = ref->frame_width;
1376 priv->frame_height = ref->frame_height;
1377 priv->render_width = ref->render_width;
1378 priv->render_height = ref->render_height;
1379 priv->bit_depth = ref->bit_depth;
1380 priv->order_hint = ref->order_hint;
1381
1382 memcpy(priv->loop_filter_ref_deltas, ref->loop_filter_ref_deltas,
1383 sizeof(ref->loop_filter_ref_deltas));
1384 memcpy(priv->loop_filter_mode_deltas, ref->loop_filter_mode_deltas,
1385 sizeof(ref->loop_filter_mode_deltas));
1386 memcpy(priv->feature_enabled, ref->feature_enabled,
1387 sizeof(ref->feature_enabled));
1388 memcpy(priv->feature_value, ref->feature_value,
1389 sizeof(ref->feature_value));
1390 } else
1391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(refresh_frame_flags, 0);
1392
1393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(frame_width_minus_1, ref->upscaled_width - 1);
1394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(frame_height_minus_1, ref->frame_height - 1);
1395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(render_width_minus_1, ref->render_width - 1);
1396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
420 infer(render_height_minus_1, ref->render_height - 1);
1397
1398 // Section 7.20
1399 420 goto update_refs;
1400 }
1401
1402
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(2, frame_type);
1403
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
5860 frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY ||
1404
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1255 times.
2930 current->frame_type == AV1_FRAME_KEY);
1405
1406
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(show_frame);
1407
2/2
✓ Branch 0 taken 1174 times.
✓ Branch 1 taken 291 times.
2930 if (current->show_frame &&
1408
2/2
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 766 times.
2348 seq->decoder_model_info_present_flag &&
1409
1/2
✓ Branch 0 taken 408 times.
✗ Branch 1 not taken.
816 !seq->timing_info.equal_picture_interval) {
1410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 408 times.
816 fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1,
1411 frame_presentation_time);
1412 }
1413
2/2
✓ Branch 0 taken 1174 times.
✓ Branch 1 taken 291 times.
2930 if (current->show_frame)
1414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
2348 infer(showable_frame, current->frame_type != AV1_FRAME_KEY);
1415 else
1416
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 291 times.
582 flag(showable_frame);
1417
1418
2/2
✓ Branch 0 taken 1462 times.
✓ Branch 1 taken 3 times.
2930 if (current->frame_type == AV1_FRAME_SWITCH ||
1419
3/4
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1252 times.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
2924 (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
426 infer(error_resilient_mode, 1);
1421 else
1422
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1252 times.
2504 flag(error_resilient_mode);
1423 }
1424
1425
3/4
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1255 times.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
2930 if (current->frame_type == AV1_FRAME_KEY && current->show_frame) {
1426
2/2
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 210 times.
3780 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1427 3360 priv->ref[i].valid = 0;
1428 3360 priv->ref[i].order_hint = 0;
1429 }
1430
2/2
✓ Branch 0 taken 1470 times.
✓ Branch 1 taken 210 times.
3360 for (i = 0; i < AV1_REFS_PER_FRAME; i++)
1431 2940 priv->order_hints[i + AV1_REF_FRAME_LAST] = 0;
1432 }
1433
1434
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(disable_cdf_update);
1435
1436
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (seq->seq_force_screen_content_tools ==
1437 AV1_SELECT_SCREEN_CONTENT_TOOLS) {
1438
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(allow_screen_content_tools);
1439 } else {
1440 infer(allow_screen_content_tools,
1441 seq->seq_force_screen_content_tools);
1442 }
1443
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1430 times.
2930 if (current->allow_screen_content_tools) {
1444
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
70 if (seq->seq_force_integer_mv == AV1_SELECT_INTEGER_MV)
1445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
70 flag(force_integer_mv);
1446 else
1447 infer(force_integer_mv, seq->seq_force_integer_mv);
1448 } else {
1449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 363 times.
2860 infer(force_integer_mv, 0);
1450 }
1451
1452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 if (seq->frame_id_numbers_present_flag) {
1453 fb(id_len, current_frame_id);
1454
1455 diff_len = seq->delta_frame_id_length_minus_2 + 2;
1456 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1457 if (current->current_frame_id > (1 << diff_len)) {
1458 if (priv->ref[i].frame_id > current->current_frame_id ||
1459 priv->ref[i].frame_id < (current->current_frame_id -
1460 (1 << diff_len)))
1461 priv->ref[i].valid = 0;
1462 } else {
1463 if (priv->ref[i].frame_id > current->current_frame_id &&
1464 priv->ref[i].frame_id < ((1 << id_len) +
1465 current->current_frame_id -
1466 (1 << diff_len)))
1467 priv->ref[i].valid = 0;
1468 }
1469 }
1470 } else {
1471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
2930 infer(current_frame_id, 0);
1472 }
1473
1474
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1462 times.
2930 if (current->frame_type == AV1_FRAME_SWITCH)
1475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
6 infer(frame_size_override_flag, 1);
1476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1462 times.
2924 else if(seq->reduced_still_picture_header)
1477 infer(frame_size_override_flag, 0);
1478 else
1479
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1462 times.
2924 flag(frame_size_override_flag);
1480
1481 2930 order_hint_bits =
1482
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
1483
1/2
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
2930 if (order_hint_bits > 0)
1484
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 fb(order_hint_bits, order_hint);
1485 else
1486 infer(order_hint, 0);
1487 2930 priv->order_hint = current->order_hint;
1488
1489
4/4
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 210 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1252 times.
2930 if (frame_is_intra || current->error_resilient_mode)
1490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
426 infer(primary_ref_frame, AV1_PRIMARY_REF_NONE);
1491 else
1492
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1252 times.
2504 fb(3, primary_ref_frame);
1493
1494
2/2
✓ Branch 0 taken 488 times.
✓ Branch 1 taken 977 times.
2930 if (seq->decoder_model_info_present_flag) {
1495
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 488 times.
976 flag(buffer_removal_time_present_flag);
1496
1/2
✓ Branch 0 taken 488 times.
✗ Branch 1 not taken.
976 if (current->buffer_removal_time_present_flag) {
1497
2/2
✓ Branch 0 taken 488 times.
✓ Branch 1 taken 488 times.
1952 for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) {
1498
1/2
✓ Branch 0 taken 488 times.
✗ Branch 1 not taken.
976 if (seq->decoder_model_present_for_this_op[i]) {
1499 976 int op_pt_idc = seq->operating_point_idc[i];
1500 976 int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1;
1501 976 int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1;
1502
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 488 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
976 if (seq->operating_point_idc[i] == 0 ||
1503 (in_temporal_layer && in_spatial_layer)) {
1504
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 488 times.
976 fbs(seq->decoder_model_info.buffer_removal_time_length_minus_1 + 1,
1505 buffer_removal_time[i], 1, i);
1506 }
1507 }
1508 }
1509 }
1510 }
1511
1512
2/2
✓ Branch 0 taken 1462 times.
✓ Branch 1 taken 3 times.
2930 if (current->frame_type == AV1_FRAME_SWITCH ||
1513
3/4
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1252 times.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
2924 (current->frame_type == AV1_FRAME_KEY && current->show_frame))
1514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
426 infer(refresh_frame_flags, all_frames);
1515 else
1516
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1252 times.
2504 fb(8, refresh_frame_flags);
1517
1518
3/4
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1255 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 210 times.
2930 if (!frame_is_intra || current->refresh_frame_flags != all_frames) {
1519
1/2
✓ Branch 0 taken 1255 times.
✗ Branch 1 not taken.
2510 if (seq->enable_order_hint) {
1520
2/2
✓ Branch 0 taken 10040 times.
✓ Branch 1 taken 1255 times.
22590 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1521
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 10016 times.
20080 if (current->error_resilient_mode)
1522
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
48 fbs(order_hint_bits, ref_order_hint[i], 1, i);
1523 else
1524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2520 times.
20032 infer(ref_order_hint[i], priv->ref[i].order_hint);
1525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10040 times.
20080 if (current->ref_order_hint[i] != priv->ref[i].order_hint)
1526 priv->ref[i].valid = 0;
1527 }
1528 }
1529 }
1530
1531
2/2
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 210 times.
2930 if (current->frame_type == AV1_FRAME_KEY ||
1532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1255 times.
2510 current->frame_type == AV1_FRAME_INTRA_ONLY) {
1533
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
420 CHECK(FUNC(frame_size)(ctx, rw, current));
1534
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
420 CHECK(FUNC(render_size)(ctx, rw, current));
1535
1536
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 205 times.
420 if (current->allow_screen_content_tools &&
1537
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
10 priv->upscaled_width == priv->frame_width)
1538
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
10 flag(allow_intrabc);
1539 else
1540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
410 infer(allow_intrabc, 0);
1541
1542 } else {
1543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1255 times.
2510 if (!seq->enable_order_hint) {
1544 infer(frame_refs_short_signaling, 0);
1545 } else {
1546
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 flag(frame_refs_short_signaling);
1547
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1213 times.
2510 if (current->frame_refs_short_signaling) {
1548
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
84 fb(3, last_frame_idx);
1549
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
84 fb(3, golden_frame_idx);
1550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
84 CHECK(FUNC(set_frame_refs)(ctx, rw, current));
1551 }
1552 }
1553
1554
2/2
✓ Branch 0 taken 8785 times.
✓ Branch 1 taken 1255 times.
20080 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1555
2/2
✓ Branch 0 taken 8491 times.
✓ Branch 1 taken 294 times.
17570 if (!current->frame_refs_short_signaling)
1556
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8491 times.
16982 fbs(3, ref_frame_idx[i], 1, i);
1557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8785 times.
17570 if (seq->frame_id_numbers_present_flag) {
1558 fbs(seq->delta_frame_id_length_minus_2 + 2,
1559 delta_frame_id_minus1[i], 1, i);
1560 }
1561 }
1562
1563
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1207 times.
2510 if (current->frame_size_override_flag &&
1564
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 3 times.
96 !current->error_resilient_mode) {
1565
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
90 CHECK(FUNC(frame_size_with_refs)(ctx, rw, current));
1566 } else {
1567
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1210 times.
2420 CHECK(FUNC(frame_size)(ctx, rw, current));
1568
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1210 times.
2420 CHECK(FUNC(render_size)(ctx, rw, current));
1569 }
1570
1571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1255 times.
2510 if (current->force_integer_mv)
1572 infer(allow_high_precision_mv, 0);
1573 else
1574
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 flag(allow_high_precision_mv);
1575
1576
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 CHECK(FUNC(interpolation_filter)(ctx, rw, current));
1577
1578
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1255 times.
2510 flag(is_motion_mode_switchable);
1579
1580
2/2
✓ Branch 0 taken 1252 times.
✓ Branch 1 taken 3 times.
2510 if (current->error_resilient_mode ||
1581
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 1162 times.
2504 !seq->enable_ref_frame_mvs)
1582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
186 infer(use_ref_frame_mvs, 0);
1583 else
1584
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1162 times.
2324 flag(use_ref_frame_mvs);
1585
1586
2/2
✓ Branch 0 taken 8785 times.
✓ Branch 1 taken 1255 times.
20080 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
1587 17570 int ref_frame = AV1_REF_FRAME_LAST + i;
1588 17570 int hint = priv->ref[current->ref_frame_idx[i]].order_hint;
1589 17570 priv->order_hints[ref_frame] = hint;
1590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8785 times.
17570 if (!seq->enable_order_hint) {
1591 priv->ref_frame_sign_bias[ref_frame] = 0;
1592 } else {
1593 17570 priv->ref_frame_sign_bias[ref_frame] =
1594 17570 cbs_av1_get_relative_dist(seq, hint,
1595 17570 current->order_hint) > 0;
1596 }
1597 }
1598
1599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 316 times.
2510 infer(allow_intrabc, 0);
1600 }
1601
1602
2/4
✓ Branch 0 taken 1465 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1465 times.
2930 if (seq->reduced_still_picture_header || current->disable_cdf_update)
1603 infer(disable_frame_end_update_cdf, 1);
1604 else
1605
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(disable_frame_end_update_cdf);
1606
1607 2930 if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
1608 // Init non-coeff CDFs.
1609 // Setup past independence.
1610 } else {
1611 // Load CDF tables from previous frame.
1612 // Load params from previous frame.
1613 }
1614
1615 2930 if (current->use_ref_frame_mvs) {
1616 // Perform motion field estimation process.
1617 }
1618
1619
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(tile_info)(ctx, rw, current));
1620
1621
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(quantization_params)(ctx, rw, current));
1622
1623
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(segmentation_params)(ctx, rw, current));
1624
1625
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(delta_q_params)(ctx, rw, current));
1626
1627
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(delta_lf_params)(ctx, rw, current));
1628
1629 // Init coeff CDFs / load previous segments.
1630
1631 2930 priv->coded_lossless = 1;
1632
2/2
✓ Branch 0 taken 11720 times.
✓ Branch 1 taken 1465 times.
26370 for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
1633 int qindex;
1634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11720 times.
23440 if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
1635 qindex = (current->base_q_idx +
1636 current->feature_value[i][AV1_SEG_LVL_ALT_Q]);
1637 } else {
1638 23440 qindex = current->base_q_idx;
1639 }
1640 23440 qindex = av_clip_uintp2(qindex, 8);
1641
1642
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11720 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
23440 if (qindex || current->delta_q_y_dc ||
1643 current->delta_q_u_ac || current->delta_q_u_dc ||
1644 current->delta_q_v_ac || current->delta_q_v_dc) {
1645 23440 priv->coded_lossless = 0;
1646 }
1647 }
1648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1465 times.
2930 priv->all_lossless = priv->coded_lossless &&
1649 priv->frame_width == priv->upscaled_width;
1650
1651
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(loop_filter_params)(ctx, rw, current));
1652
1653
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(cdef_params)(ctx, rw, current));
1654
1655
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(lr_params)(ctx, rw, current));
1656
1657
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(read_tx_mode)(ctx, rw, current));
1658
1659
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(frame_reference_mode)(ctx, rw, current));
1660
1661
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(skip_mode_params)(ctx, rw, current));
1662
1663
4/4
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 210 times.
✓ Branch 2 taken 1252 times.
✓ Branch 3 taken 3 times.
2930 if (frame_is_intra || current->error_resilient_mode ||
1664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1252 times.
2504 !seq->enable_warped_motion)
1665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
426 infer(allow_warped_motion, 0);
1666 else
1667
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1252 times.
2504 flag(allow_warped_motion);
1668
1669
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 flag(reduced_tx_set);
1670
1671
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(global_motion_params)(ctx, rw, current));
1672
1673
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1465 times.
2930 CHECK(FUNC(film_grain_params)(ctx, rw, &current->film_grain, current));
1674
1675 2930 av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d "
1676 "upscaled %d render %dx%d subsample %dx%d "
1677 "bitdepth %d tiles %dx%d.\n", priv->order_hint,
1678 priv->frame_width, priv->frame_height, priv->upscaled_width,
1679 priv->render_width, priv->render_height,
1680 2930 seq->color_config.subsampling_x + 1,
1681 2930 seq->color_config.subsampling_y + 1, priv->bit_depth,
1682 priv->tile_rows, priv->tile_cols);
1683
1684 3350 update_refs:
1685
2/2
✓ Branch 0 taken 13400 times.
✓ Branch 1 taken 1675 times.
30150 for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1686
2/2
✓ Branch 0 taken 2867 times.
✓ Branch 1 taken 10533 times.
26800 if (current->refresh_frame_flags & (1 << i)) {
1687 5734 priv->ref[i] = (AV1ReferenceFrameState) {
1688 .valid = 1,
1689 5734 .frame_id = current->current_frame_id,
1690 5734 .upscaled_width = priv->upscaled_width,
1691 5734 .frame_width = priv->frame_width,
1692 5734 .frame_height = priv->frame_height,
1693 5734 .render_width = priv->render_width,
1694 5734 .render_height = priv->render_height,
1695 5734 .frame_type = current->frame_type,
1696 5734 .subsampling_x = seq->color_config.subsampling_x,
1697 5734 .subsampling_y = seq->color_config.subsampling_y,
1698 5734 .bit_depth = priv->bit_depth,
1699 5734 .order_hint = priv->order_hint,
1700 };
1701
1702
2/2
✓ Branch 0 taken 20069 times.
✓ Branch 1 taken 2867 times.
45872 for (int j = 0; j < AV1_REFS_PER_FRAME; j++) {
1703 40138 priv->ref[i].saved_order_hints[j + AV1_REF_FRAME_LAST] =
1704 40138 priv->order_hints[j + AV1_REF_FRAME_LAST];
1705 }
1706
1707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2867 times.
5734 if (current->show_existing_frame) {
1708 memcpy(priv->ref[i].loop_filter_ref_deltas, priv->loop_filter_ref_deltas,
1709 sizeof(priv->loop_filter_ref_deltas));
1710 memcpy(priv->ref[i].loop_filter_mode_deltas, priv->loop_filter_mode_deltas,
1711 sizeof(priv->loop_filter_mode_deltas));
1712 memcpy(priv->ref[i].feature_enabled, priv->feature_enabled,
1713 sizeof(priv->feature_enabled));
1714 memcpy(priv->ref[i].feature_value, priv->feature_value,
1715 sizeof(priv->feature_value));
1716 } else {
1717 5734 memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas,
1718 sizeof(current->loop_filter_ref_deltas));
1719 5734 memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas,
1720 sizeof(current->loop_filter_mode_deltas));
1721 5734 memcpy(priv->ref[i].feature_enabled, current->feature_enabled,
1722 sizeof(current->feature_enabled));
1723 5734 memcpy(priv->ref[i].feature_value, current->feature_value,
1724 sizeof(current->feature_value));
1725 }
1726 }
1727 }
1728
1729 3350 return 0;
1730 }
1731
1732 3350 static int FUNC(frame_header_obu)(CodedBitstreamContext *ctx, RWContext *rw,
1733 AV1RawFrameHeader *current, int redundant,
1734 AVBufferRef *rw_buffer_ref)
1735 {
1736 3350 CodedBitstreamAV1Context *priv = ctx->priv_data;
1737 int start_pos, fh_bits, fh_bytes, err;
1738 uint8_t *fh_start;
1739
1740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1675 times.
3350 if (priv->seen_frame_header) {
1741 if (!redundant) {
1742 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated "
1743 "frame header OBU.\n");
1744 return AVERROR_INVALIDDATA;
1745 } else {
1746 GetBitContext fh;
1747 size_t i, b;
1748 uint32_t val;
1749
1750 HEADER("Redundant Frame Header");
1751
1752 av_assert0(priv->frame_header_ref && priv->frame_header);
1753
1754 init_get_bits(&fh, priv->frame_header,
1755 priv->frame_header_size);
1756 for (i = 0; i < priv->frame_header_size; i += 8) {
1757 b = FFMIN(priv->frame_header_size - i, 8);
1758 val = get_bits(&fh, b);
1759 xf(b, frame_header_copy[i],
1760 val, val, val, 1, i / 8);
1761 }
1762 }
1763 } else {
1764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1675 times.
3350 if (redundant)
1765 #ifdef READ
1766 HEADER("Redundant Frame Header (used as Frame Header)");
1767 #else
1768 {
1769 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid redundant "
1770 "frame header OBU.\n");
1771 return AVERROR_INVALIDDATA;
1772 }
1773 #endif
1774 else
1775 3350 HEADER("Frame Header");
1776
1777 #ifdef READ
1778 2508 start_pos = get_bits_count(rw);
1779 #else
1780 842 start_pos = put_bits_count(rw);
1781 #endif
1782
1783
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1675 times.
3350 CHECK(FUNC(uncompressed_header)(ctx, rw, current));
1784
1785 3350 priv->tile_num = 0;
1786
1787
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 1465 times.
3350 if (current->show_existing_frame) {
1788 420 priv->seen_frame_header = 0;
1789 } else {
1790 2930 priv->seen_frame_header = 1;
1791
1792 2930 av_buffer_unref(&priv->frame_header_ref);
1793
1794 #ifdef READ
1795 2182 fh_bits = get_bits_count(rw) - start_pos;
1796 2182 fh_start = (uint8_t*)rw->buffer + start_pos / 8;
1797 #else
1798 // Need to flush the bitwriter so that we can copy its output,
1799 // but use a copy so we don't affect the caller's structure.
1800 {
1801 748 PutBitContext tmp = *rw;
1802 748 flush_put_bits(&tmp);
1803 }
1804
1805 748 fh_bits = put_bits_count(rw) - start_pos;
1806 748 fh_start = rw->buf + start_pos / 8;
1807 #endif
1808 2930 fh_bytes = (fh_bits + 7) / 8;
1809
1810 2930 priv->frame_header_size = fh_bits;
1811
1812
2/2
✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 374 times.
2930 if (rw_buffer_ref) {
1813 2182 priv->frame_header_ref = av_buffer_ref(rw_buffer_ref);
1814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1091 times.
2182 if (!priv->frame_header_ref)
1815 return AVERROR(ENOMEM);
1816 2182 priv->frame_header = fh_start;
1817 } else {
1818 748 priv->frame_header_ref =
1819 748 av_buffer_alloc(fh_bytes + AV_INPUT_BUFFER_PADDING_SIZE);
1820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374 times.
748 if (!priv->frame_header_ref)
1821 return AVERROR(ENOMEM);
1822 748 priv->frame_header = priv->frame_header_ref->data;
1823 748 memcpy(priv->frame_header, fh_start, fh_bytes);
1824 }
1825 }
1826 }
1827
1828 3350 return 0;
1829 }
1830
1831 3330 static int FUNC(tile_group_obu)(CodedBitstreamContext *ctx, RWContext *rw,
1832 AV1RawTileGroup *current)
1833 {
1834 3330 CodedBitstreamAV1Context *priv = ctx->priv_data;
1835 int num_tiles, tile_bits;
1836 int err;
1837
1838 3330 HEADER("Tile Group");
1839
1840 3330 num_tiles = priv->tile_cols * priv->tile_rows;
1841
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 1226 times.
3330 if (num_tiles > 1)
1842
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 439 times.
878 flag(tile_start_and_end_present_flag);
1843 else
1844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
2452 infer(tile_start_and_end_present_flag, 0);
1845
1846
4/4
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 1226 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 325 times.
3330 if (num_tiles == 1 || !current->tile_start_and_end_present_flag) {
1847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334 times.
2680 infer(tg_start, 0);
1848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334 times.
2680 infer(tg_end, num_tiles - 1);
1849 } else {
1850 650 tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) +
1851 650 cbs_av1_tile_log2(1, priv->tile_rows);
1852
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 325 times.
650 fc(tile_bits, tg_start, priv->tile_num, num_tiles - 1);
1853
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 325 times.
650 fc(tile_bits, tg_end, current->tg_start, num_tiles - 1);
1854 }
1855
1856 3330 priv->tile_num = current->tg_end + 1;
1857
1858
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1665 times.
3330 CHECK(FUNC(byte_alignment)(ctx, rw));
1859
1860 // Reset header for next frame.
1861
2/2
✓ Branch 0 taken 1465 times.
✓ Branch 1 taken 200 times.
3330 if (current->tg_end == num_tiles - 1)
1862 2930 priv->seen_frame_header = 0;
1863
1864 // Tile data follows.
1865
1866 3330 return 0;
1867 }
1868
1869 2680 static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw,
1870 AV1RawFrame *current,
1871 AVBufferRef *rw_buffer_ref)
1872 {
1873 int err;
1874
1875
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1340 times.
2680 CHECK(FUNC(frame_header_obu)(ctx, rw, &current->header,
1876 0, rw_buffer_ref));
1877
1878
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1340 times.
2680 CHECK(FUNC(byte_alignment)(ctx, rw));
1879
1880 2680 return 0;
1881 }
1882
1883 #if CBS_AV1_OBU_TILE_LIST
1884 static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw,
1885 AV1RawTileList *current)
1886 {
1887 int err;
1888
1889 fb(8, output_frame_width_in_tiles_minus_1);
1890 fb(8, output_frame_height_in_tiles_minus_1);
1891
1892 fb(16, tile_count_minus_1);
1893
1894 // Tile data follows.
1895
1896 return 0;
1897 }
1898 #endif
1899
1900 #if CBS_AV1_OBU_METADATA
1901 28 static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw,
1902 AV1RawMetadataHDRCLL *current)
1903 {
1904 int err;
1905
1906 28 HEADER("HDR CLL Metadata");
1907
1908
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(16, max_cll);
1909
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(16, max_fall);
1910
1911 28 return 0;
1912 }
1913
1914 28 static int FUNC(metadata_hdr_mdcv)(CodedBitstreamContext *ctx, RWContext *rw,
1915 AV1RawMetadataHDRMDCV *current)
1916 {
1917 int err, i;
1918
1919 28 HEADER("HDR MDCV Metadata");
1920
1921
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 14 times.
112 for (i = 0; i < 3; i++) {
1922
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
84 fbs(16, primary_chromaticity_x[i], 1, i);
1923
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
84 fbs(16, primary_chromaticity_y[i], 1, i);
1924 }
1925
1926
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(16, white_point_chromaticity_x);
1927
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(16, white_point_chromaticity_y);
1928
1929
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(32, luminance_max);
1930
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 fb(32, luminance_min);
1931
1932 28 return 0;
1933 }
1934
1935 static int FUNC(scalability_structure)(CodedBitstreamContext *ctx, RWContext *rw,
1936 AV1RawMetadataScalability *current)
1937 {
1938 CodedBitstreamAV1Context *priv = ctx->priv_data;
1939 const AV1RawSequenceHeader *seq;
1940 int err, i, j;
1941
1942 if (!priv->sequence_header) {
1943 av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: "
1944 "unable to parse scalability metadata.\n");
1945 return AVERROR_INVALIDDATA;
1946 }
1947 seq = priv->sequence_header;
1948
1949 fb(2, spatial_layers_cnt_minus_1);
1950 flag(spatial_layer_dimensions_present_flag);
1951 flag(spatial_layer_description_present_flag);
1952 flag(temporal_group_description_present_flag);
1953 fc(3, scalability_structure_reserved_3bits, 0, 0);
1954 if (current->spatial_layer_dimensions_present_flag) {
1955 for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) {
1956 fcs(16, spatial_layer_max_width[i],
1957 0, seq->max_frame_width_minus_1 + 1, 1, i);
1958 fcs(16, spatial_layer_max_height[i],
1959 0, seq->max_frame_height_minus_1 + 1, 1, i);
1960 }
1961 }
1962 if (current->spatial_layer_description_present_flag) {
1963 for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++)
1964 fbs(8, spatial_layer_ref_id[i], 1, i);
1965 }
1966 if (current->temporal_group_description_present_flag) {
1967 fb(8, temporal_group_size);
1968 for (i = 0; i < current->temporal_group_size; i++) {
1969 fbs(3, temporal_group_temporal_id[i], 1, i);
1970 flags(temporal_group_temporal_switching_up_point_flag[i], 1, i);
1971 flags(temporal_group_spatial_switching_up_point_flag[i], 1, i);
1972 fbs(3, temporal_group_ref_cnt[i], 1, i);
1973 for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) {
1974 fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j);
1975 }
1976 }
1977 }
1978
1979 return 0;
1980 }
1981
1982 static int FUNC(metadata_scalability)(CodedBitstreamContext *ctx, RWContext *rw,
1983 AV1RawMetadataScalability *current)
1984 {
1985 int err;
1986
1987 HEADER("Scalability Metadata");
1988
1989 fb(8, scalability_mode_idc);
1990
1991 if (current->scalability_mode_idc == AV1_SCALABILITY_SS)
1992 CHECK(FUNC(scalability_structure)(ctx, rw, current));
1993
1994 return 0;
1995 }
1996
1997 static int FUNC(metadata_itut_t35)(CodedBitstreamContext *ctx, RWContext *rw,
1998 AV1RawMetadataITUTT35 *current)
1999 {
2000 int err;
2001 size_t i;
2002
2003 HEADER("ITU-T T.35 Metadata");
2004
2005 fb(8, itu_t_t35_country_code);
2006 if (current->itu_t_t35_country_code == 0xff)
2007 fb(8, itu_t_t35_country_code_extension_byte);
2008
2009 #ifdef READ
2010 // The payload runs up to the start of the trailing bits, but there might
2011 // be arbitrarily many trailing zeroes so we need to read through twice.
2012 current->payload_size = cbs_av1_get_payload_bytes_left(rw);
2013
2014 current->payload_ref = av_buffer_alloc(current->payload_size +
2015 AV_INPUT_BUFFER_PADDING_SIZE);
2016 if (!current->payload_ref)
2017 return AVERROR(ENOMEM);
2018 current->payload = current->payload_ref->data;
2019 memset(current->payload + current->payload_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2020 #endif
2021
2022 for (i = 0; i < current->payload_size; i++)
2023 xf(8, itu_t_t35_payload_bytes[i], current->payload[i],
2024 0x00, 0xff, 1, i);
2025
2026 return 0;
2027 }
2028
2029 static int FUNC(metadata_timecode)(CodedBitstreamContext *ctx, RWContext *rw,
2030 AV1RawMetadataTimecode *current)
2031 {
2032 int err;
2033
2034 HEADER("Timecode Metadata");
2035
2036 fb(5, counting_type);
2037 flag(full_timestamp_flag);
2038 flag(discontinuity_flag);
2039 flag(cnt_dropped_flag);
2040 fb(9, n_frames);
2041
2042 if (current->full_timestamp_flag) {
2043 fc(6, seconds_value, 0, 59);
2044 fc(6, minutes_value, 0, 59);
2045 fc(5, hours_value, 0, 23);
2046 } else {
2047 flag(seconds_flag);
2048 if (current->seconds_flag) {
2049 fc(6, seconds_value, 0, 59);
2050 flag(minutes_flag);
2051 if (current->minutes_flag) {
2052 fc(6, minutes_value, 0, 59);
2053 flag(hours_flag);
2054 if (current->hours_flag)
2055 fc(5, hours_value, 0, 23);
2056 }
2057 }
2058 }
2059
2060 fb(5, time_offset_length);
2061 if (current->time_offset_length > 0)
2062 fb(current->time_offset_length, time_offset_value);
2063 else
2064 infer(time_offset_length, 0);
2065
2066 return 0;
2067 }
2068
2069 static int FUNC(metadata_unknown)(CodedBitstreamContext *ctx, RWContext *rw,
2070 AV1RawMetadataUnknown *current)
2071 {
2072 int err;
2073 size_t i;
2074
2075 HEADER("Unknown Metadata");
2076
2077 #ifdef READ
2078 current->payload_size = cbs_av1_get_payload_bytes_left(rw);
2079
2080 current->payload_ref = av_buffer_alloc(current->payload_size);
2081 if (!current->payload_ref)
2082 return AVERROR(ENOMEM);
2083 current->payload = current->payload_ref->data;
2084 #endif
2085
2086 for (i = 0; i < current->payload_size; i++)
2087 fbs(8, payload[i], 1, i);
2088
2089 return 0;
2090 }
2091
2092 56 static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
2093 AV1RawMetadata *current)
2094 {
2095 int err;
2096
2097
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
56 leb128(metadata_type);
2098
2099
2/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
56 switch (current->metadata_type) {
2100 28 case AV1_METADATA_TYPE_HDR_CLL:
2101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 CHECK(FUNC(metadata_hdr_cll)(ctx, rw, &current->metadata.hdr_cll));
2102 28 break;
2103 28 case AV1_METADATA_TYPE_HDR_MDCV:
2104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
28 CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, &current->metadata.hdr_mdcv));
2105 28 break;
2106 case AV1_METADATA_TYPE_SCALABILITY:
2107 CHECK(FUNC(metadata_scalability)(ctx, rw, &current->metadata.scalability));
2108 break;
2109 case AV1_METADATA_TYPE_ITUT_T35:
2110 CHECK(FUNC(metadata_itut_t35)(ctx, rw, &current->metadata.itut_t35));
2111 break;
2112 case AV1_METADATA_TYPE_TIMECODE:
2113 CHECK(FUNC(metadata_timecode)(ctx, rw, &current->metadata.timecode));
2114 break;
2115 default:
2116 CHECK(FUNC(metadata_unknown)(ctx, rw, &current->metadata.unknown));
2117 }
2118
2119 56 return 0;
2120 }
2121 #endif
2122
2123 #if CBS_AV1_OBU_PADDING
2124 static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw,
2125 AV1RawPadding *current)
2126 {
2127 int i, err;
2128
2129 HEADER("Padding");
2130
2131 #ifdef READ
2132 // The payload runs up to the start of the trailing bits, but there might
2133 // be arbitrarily many trailing zeroes so we need to read through twice.
2134 current->payload_size = cbs_av1_get_payload_bytes_left(rw);
2135
2136 current->payload_ref = av_buffer_alloc(current->payload_size);
2137 if (!current->payload_ref)
2138 return AVERROR(ENOMEM);
2139 current->payload = current->payload_ref->data;
2140 #endif
2141
2142 for (i = 0; i < current->payload_size; i++)
2143 xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
2144
2145 return 0;
2146 }
2147 #endif
2148