FFmpeg coverage


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