FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cbs_apv_syntax_template.c
Date: 2026-08-29 16:27:19
Exec Total Coverage
Lines: 167 279 59.9%
Functions: 22 37 59.5%
Branches: 75 254 29.5%

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 285 static int FUNC(pbu_header)(CodedBitstreamContext *ctx, RWContext *rw,
20 APVRawPBUHeader *current)
21 {
22 int err;
23
24
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 147 times.
285 ub(8, pbu_type);
25
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 147 times.
285 ub(16, group_id);
26
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 147 times.
285 u(8, reserved_zero_8bits, 0, 0);
27
28 285 return 0;
29 }
30
31 87 static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw)
32 {
33 int err;
34
35
2/2
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 45 times.
435 while (byte_alignment(rw) != 0)
36
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
348 fixed(1, alignment_bit_equal_to_zero, 0);
37
38 87 return 0;
39 }
40
41 135 static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
42 APVRawFiller *current)
43 {
44 int err;
45
46 #ifdef READ
47 111 current->filler_size = 0;
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
111 while (show_bits(rw, 8) == 0xff) {
49 fixed(8, ff_byte, 0xff);
50 ++current->filler_size;
51 }
52 #else
53 {
54 uint32_t i;
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
24 for (i = 0; i < current->filler_size; i++)
56 fixed(8, ff_byte, 0xff);
57 }
58 #endif
59
60 135 return 0;
61 }
62
63 87 static int FUNC(frame_info)(CodedBitstreamContext *ctx, RWContext *rw,
64 APVRawFrameInfo *current)
65 {
66 int err;
67
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, profile_idc);
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, level_idc);
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(3, band_idc);
71
72
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(5, reserved_zero_5bits, 0, 0);
73
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(24, frame_width);
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(24, frame_height);
76
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(4, chroma_format_idc, 0, 4);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
87 if (current->chroma_format_idc == 1) {
79 av_log(ctx->log_ctx, AV_LOG_ERROR,
80 "chroma_format_idc 1 for 4:2:0 is not allowed in APV.\n");
81 return AVERROR_INVALIDDATA;
82 }
83
84
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(4, bit_depth_minus8, 2, 8);
85
86
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, capture_time_distance);
87
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(8, reserved_zero_8bits, 0, 0);
89
90 87 return 0;
91 }
92
93 static int FUNC(quantization_matrix)(CodedBitstreamContext *ctx,
94 RWContext *rw,
95 APVRawQuantizationMatrix *current)
96 {
97 const CodedBitstreamAPVContext *priv = ctx->priv_data;
98 int err;
99
100 for (int c = 0; c < priv->num_comp; c++) {
101 for (int y = 0; y < 8; y++) {
102 for (int x = 0; x < 8 ; x++) {
103 us(8, q_matrix[c][x][y], 1, 255, 3, c, x, y);
104 }
105 }
106 }
107
108 return 0;
109 }
110
111 87 static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw,
112 APVRawTileInfo *current,
113 const APVRawFrameHeader *fh)
114 {
115 87 CodedBitstreamAPVContext *priv = ctx->priv_data;
116 87 int frame_width_in_mbs = (fh->frame_info.frame_width + 15) / 16;
117 87 int frame_height_in_mbs = (fh->frame_info.frame_height + 15) / 16;
118 /* The spec also demands tile_width >= APV_MIN_TILE_WIDTH_IN_MBS (16)
119 * and tile_height >= APV_MIN_TILE_HEIGHT_IN_MBS (8); we deliberately
120 * accept smaller tiles (down to the 20x20 grid cap, which the fixed
121 * arrays rely on) so sub-minimum experimental streams keep working. */
122 87 uint32_t min_tile_width = (frame_width_in_mbs + APV_MAX_TILE_COLS - 1) /
123 APV_MAX_TILE_COLS;
124 87 uint32_t min_tile_height = (frame_height_in_mbs + APV_MAX_TILE_ROWS - 1) /
125 APV_MAX_TILE_ROWS;
126 int err;
127
128
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(20, tile_width_in_mbs, min_tile_width, MAX_UINT_BITS(20));
129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(20, tile_height_in_mbs, min_tile_height, MAX_UINT_BITS(20));
130
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(1, tile_size_present_in_fh_flag);
132
133 87 cbs_apv_derive_tile_info(ctx, fh);
134
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
87 if (current->tile_size_present_in_fh_flag) {
136 for (int t = 0; t < priv->num_tiles; t++) {
137 us(32, tile_size_in_fh[t], 10, MAX_UINT_BITS(32), 1, t);
138 }
139 }
140
141 87 return 0;
142 }
143
144 87 static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw,
145 APVRawFrameHeader *current)
146 {
147 87 CodedBitstreamAPVContext *priv = ctx->priv_data;
148 int err;
149
150
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(frame_info)(ctx, rw, &current->frame_info));
151
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(8, reserved_zero_8bits, 0, 0);
153
154
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(1, color_description_present_flag);
155
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
87 if (current->color_description_present_flag) {
156
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, color_primaries);
157
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, transfer_characteristics);
158
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(8, matrix_coefficients);
159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(1, full_range_flag);
160 } else {
161 infer(color_primaries, 2);
162 infer(transfer_characteristics, 2);
163 infer(matrix_coefficients, 2);
164 infer(full_range_flag, 0);
165 }
166
167 87 priv->bit_depth = current->frame_info.bit_depth_minus8 + 8;
168 87 priv->num_comp = cbs_apv_get_num_comp(current);
169
170
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 ub(1, use_q_matrix);
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
87 if (current->use_q_matrix) {
172 CHECK(FUNC(quantization_matrix)(ctx, rw,
173 &current->quantization_matrix));
174 } else {
175
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 45 times.
280 for (int c = 0; c < priv->num_comp; c++) {
176
2/2
✓ Branch 0 taken 808 times.
✓ Branch 1 taken 101 times.
1737 for (int y = 0; y < 8; y++) {
177
2/2
✓ Branch 0 taken 6464 times.
✓ Branch 1 taken 808 times.
13896 for (int x = 0; x < 8 ; x++) {
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 768 times.
12352 infer(quantization_matrix.q_matrix[c][y][x], 16);
179 }
180 }
181 }
182 }
183
184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(tile_info)(ctx, rw, &current->tile_info, current));
185
186
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(8, reserved_zero_8bits_2, 0, 0);
187
188
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(byte_alignment)(ctx, rw));
189
190 87 return 0;
191 }
192
193 174 static int FUNC(tile_header)(CodedBitstreamContext *ctx, RWContext *rw,
194 APVRawTileHeader *current,
195 int tile_idx, uint32_t tile_size)
196 {
197 174 const CodedBitstreamAPVContext *priv = ctx->priv_data;
198 uint16_t expected_tile_header_size;
199 uint32_t tile_size_remaining;
200 uint8_t max_qp;
201 int err;
202
203 174 expected_tile_header_size = 4 + priv->num_comp * (4 + 1) + 1;
204
205
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 u(16, tile_header_size,
206 expected_tile_header_size, expected_tile_header_size);
207
208
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 u(16, tile_index, tile_idx, tile_idx);
209
210 174 tile_size_remaining = tile_size - current->tile_header_size;
211
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 90 times.
560 for (int c = 0; c < priv->num_comp; c++) {
212
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
386 us(32, tile_data_size[c], 1, tile_size_remaining, 1, c);
213 386 tile_size_remaining -= current->tile_data_size[c];
214 }
215
216 174 max_qp = 3 + priv->bit_depth * 6;
217
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 90 times.
560 for (int c = 0; c < priv->num_comp; c++) {
218
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
386 us(8, tile_qp[c], 0, max_qp, 1, c);
219 }
220
221
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 u(8, reserved_zero_8bits, 0, 0);
222
223 174 return 0;
224 }
225
226 174 static int FUNC(tile)(CodedBitstreamContext *ctx, RWContext *rw,
227 APVRawTile *current,
228 int tile_idx, uint32_t tile_size)
229 {
230 174 const CodedBitstreamAPVContext *priv = ctx->priv_data;
231 int err;
232
233
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 CHECK(FUNC(tile_header)(ctx, rw, &current->tile_header,
234 tile_idx, tile_size));
235
236
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 90 times.
560 for (int c = 0; c < priv->num_comp; c++) {
237 386 uint32_t comp_size = current->tile_header.tile_data_size[c];
238 #ifdef READ
239 338 int pos = get_bits_count(rw);
240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
338 av_assert0(pos % 8 == 0);
241
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
338 if (get_bits_left(rw) < 8LL * comp_size)
242 return AVERROR_INVALIDDATA;
243 338 current->tile_data[c] = (uint8_t*)align_get_bits(rw);
244 338 skip_bits_long(rw, 8 * comp_size);
245 #else
246
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
48 if (put_bytes_left(rw, 0) < comp_size)
247 return AVERROR(ENOSPC);
248 48 ff_copy_bits(rw, current->tile_data[c], comp_size * 8);
249 #endif
250 }
251
252 174 return 0;
253 }
254
255 87 static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw,
256 APVRawFrame *current)
257 {
258 87 const CodedBitstreamAPVContext *priv = ctx->priv_data;
259 int err;
260
261 87 HEADER("Frame");
262
263
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(pbu_header)(ctx, rw, &current->pbu_header));
264
265
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(frame_header)(ctx, rw, &current->frame_header));
266
267
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 45 times.
261 for (int t = 0; t < priv->num_tiles; t++) {
268
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 us(32, tile_size[t], 10, MAX_INT_BITS(32), 1, t);
269
270
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 CHECK(FUNC(tile)(ctx, rw, &current->tile[t],
271 t, current->tile_size[t]));
272 }
273
274
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(filler)(ctx, rw, &current->filler));
275
276 87 return 0;
277 }
278
279 static int FUNC(au_info)(CodedBitstreamContext *ctx, RWContext *rw,
280 APVRawAUInfo *current)
281 {
282 int err;
283
284 HEADER("Access Unit Information");
285
286 u(16, num_frames, 1, CBS_APV_MAX_AU_FRAMES);
287
288 for (int i = 0; i < current->num_frames; i++) {
289 ubs(8, pbu_type[i], 1, i);
290 ubs(8, group_id[i], 1, i);
291
292 us(8, reserved_zero_8bits[i], 0, 0, 1, i);
293
294 CHECK(FUNC(frame_info)(ctx, rw, &current->frame_info[i]));
295 }
296
297 u(8, reserved_zero_8bits_2, 0, 0);
298
299 return 0;
300 }
301
302 static int FUNC(metadata_itu_t_t35)(CodedBitstreamContext *ctx,
303 RWContext *rw,
304 APVRawMetadataITUTT35 *current,
305 size_t payload_size)
306 {
307 int err;
308 size_t read_size = payload_size - 1;
309
310 HEADER("ITU-T T.35 Metadata");
311
312 ub(8, itu_t_t35_country_code);
313
314 if (current->itu_t_t35_country_code == 0xff) {
315 ub(8, itu_t_t35_country_code_extension);
316 --read_size;
317 }
318
319 #ifdef READ
320 current->data_size = read_size;
321 current->data_ref = av_buffer_alloc(current->data_size);
322 if (!current->data_ref)
323 return AVERROR(ENOMEM);
324 current->data = current->data_ref->data;
325 #else
326 if (current->data_size != read_size) {
327 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
328 "payload %zu but expecting %zu\n",
329 current->data_size, read_size);
330 return AVERROR(EINVAL);
331 }
332 #endif
333
334 for (size_t i = 0; i < current->data_size; i++) {
335 xu(8, itu_t_t35_payload[i],
336 current->data[i], 0x00, 0xff, 1, i);
337 }
338
339 return 0;
340 }
341
342 static int FUNC(metadata_mdcv)(CodedBitstreamContext *ctx,
343 RWContext *rw,
344 APVRawMetadataMDCV *current)
345 {
346 int err, i;
347
348 HEADER("MDCV Metadata");
349
350 for (i = 0; i < 3; i++) {
351 ubs(16, primary_chromaticity_x[i], 1, i);
352 ubs(16, primary_chromaticity_y[i], 1, i);
353 }
354
355 ub(16, white_point_chromaticity_x);
356 ub(16, white_point_chromaticity_y);
357
358 ub(32, max_mastering_luminance);
359 ub(32, min_mastering_luminance);
360
361 return 0;
362 }
363
364 static int FUNC(metadata_cll)(CodedBitstreamContext *ctx,
365 RWContext *rw,
366 APVRawMetadataCLL *current)
367 {
368 int err;
369
370 HEADER("CLL Metadata");
371
372 ub(16, max_cll);
373 ub(16, max_fall);
374
375 return 0;
376 }
377
378 static int FUNC(metadata_filler)(CodedBitstreamContext *ctx,
379 RWContext *rw,
380 APVRawMetadataFiller *current,
381 size_t payload_size)
382 {
383 int err;
384
385 HEADER("Filler Metadata");
386
387 for (size_t i = 0; i < payload_size; i++)
388 fixed(8, ff_byte, 0xff);
389
390 return 0;
391 }
392
393 120 static int FUNC(metadata_user_defined)(CodedBitstreamContext *ctx,
394 RWContext *rw,
395 APVRawMetadataUserDefined *current,
396 size_t payload_size)
397 {
398 int err;
399
400 120 HEADER("User-Defined Metadata");
401
402
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 60 times.
2040 for (int i = 0; i < 16; i++)
403
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 960 times.
1920 ubs(8, uuid[i], 1, i);
404
405 #ifdef READ
406 72 current->data_size = payload_size - 16;
407 72 current->data_ref = av_buffer_alloc(current->data_size);
408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
72 if (!current->data_ref)
409 return AVERROR(ENOMEM);
410 72 current->data = current->data_ref->data;
411 #else
412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
48 if (current->data_size != payload_size - 16) {
413 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
414 "payload %zu but expecting %zu\n",
415 current->data_size, payload_size - 16);
416 return AVERROR(EINVAL);
417 }
418 #endif
419
420
2/2
✓ Branch 0 taken 1922 times.
✓ Branch 1 taken 60 times.
3964 for (size_t i = 0; i < current->data_size; i++) {
421
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1922 times.
3844 xu(8, user_defined_data_payload[i],
422 current->data[i], 0x00, 0xff, 1, i);
423 }
424
425 120 return 0;
426 }
427
428 static int FUNC(metadata_undefined)(CodedBitstreamContext *ctx,
429 RWContext *rw,
430 APVRawMetadataUndefined *current,
431 size_t payload_size)
432 {
433 int err;
434
435 HEADER("Undefined Metadata");
436
437 #ifdef READ
438 current->data_size = payload_size;
439 current->data_ref = av_buffer_alloc(current->data_size);
440 if (!current->data_ref)
441 return AVERROR(ENOMEM);
442 current->data = current->data_ref->data;
443 #else
444 if (current->data_size != payload_size) {
445 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
446 "payload %zu but expecting %zu\n",
447 current->data_size, payload_size - 16);
448 return AVERROR(EINVAL);
449 }
450 #endif
451
452 for (size_t i = 0; i < current->data_size; i++) {
453 xu(8, undefined_metadata_payload_byte[i],
454 current->data[i], 0x00, 0xff, 1, i);
455 }
456
457 return 0;
458 }
459
460 120 static int FUNC(metadata_payload)(CodedBitstreamContext *ctx,
461 RWContext *rw,
462 APVRawMetadataPayload *current)
463 {
464 int err;
465
466
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
120 switch (current->payload_type) {
467 case APV_METADATA_ITU_T_T35:
468 CHECK(FUNC(metadata_itu_t_t35)(ctx, rw,
469 &current->itu_t_t35,
470 current->payload_size));
471 break;
472 case APV_METADATA_MDCV:
473 CHECK(FUNC(metadata_mdcv)(ctx, rw, &current->mdcv));
474 break;
475 case APV_METADATA_CLL:
476 CHECK(FUNC(metadata_cll)(ctx, rw, &current->cll));
477 break;
478 case APV_METADATA_FILLER:
479 CHECK(FUNC(metadata_filler)(ctx, rw,
480 &current->filler,
481 current->payload_size));
482 break;
483 120 case APV_METADATA_USER_DEFINED:
484
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
120 CHECK(FUNC(metadata_user_defined)(ctx, rw,
485 &current->user_defined,
486 current->payload_size));
487 120 break;
488 default:
489 CHECK(FUNC(metadata_undefined)(ctx, rw,
490 &current->undefined,
491 current->payload_size));
492 }
493
494 120 return 0;
495 }
496
497 24 static int FUNC(metadata)(CodedBitstreamContext *ctx, RWContext *rw,
498 APVRawMetadata *current)
499 {
500 int err;
501
502 #ifdef READ
503 uint32_t metadata_bytes_left;
504 #else
505 PutBitContext metadata_start_state;
506 uint32_t metadata_start_position;
507 int trace;
508 #endif
509
510 24 HEADER("Metadata");
511
512
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
24 CHECK(FUNC(pbu_header)(ctx, rw, &current->pbu_header));
513
514 #ifdef READ
515
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
18 ub(32, metadata_size);
516
517 18 metadata_bytes_left = current->metadata_size;
518
519
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 for (int p = 0; p < CBS_APV_MAX_METADATA_PAYLOADS; p++) {
520 36 APVRawMetadataPayload *pl = &current->payloads[p];
521 uint32_t tmp;
522
523 36 pl->payload_type = 0;
524
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 while (show_bits(rw, 8) == 0xff) {
525 fixed(8, ff_byte, 0xff);
526 pl->payload_type += 255;
527 --metadata_bytes_left;
528 }
529
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 xu(8, metadata_payload_type, tmp, 0, 254, 0);
530 36 pl->payload_type += tmp;
531 36 --metadata_bytes_left;
532
533 36 pl->payload_size = 0;
534
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 while (show_bits(rw, 8) == 0xff) {
535 fixed(8, ff_byte, 0xff);
536 pl->payload_size += 255;
537 --metadata_bytes_left;
538 }
539
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 xu(8, metadata_payload_size, tmp, 0, 254, 0);
540 36 pl->payload_size += tmp;
541 36 --metadata_bytes_left;
542
543
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 if (pl->payload_size > metadata_bytes_left) {
544 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid metadata: "
545 "payload_size larger than remaining metadata size "
546 "(%"PRIu32" bytes).\n", pl->payload_size);
547 return AVERROR_INVALIDDATA;
548 }
549
550 36 current->metadata_count = p + 1;
551
552
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 CHECK(FUNC(metadata_payload)(ctx, rw, pl));
553
554 36 metadata_bytes_left -= pl->payload_size;
555
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 if (metadata_bytes_left == 0)
556 18 break;
557 }
558 #else
559 // Two passes: the first write finds the size (with tracing
560 // disabled), the second write does the real write.
561
562 6 metadata_start_state = *rw;
563 6 metadata_start_position = put_bits_count(rw);
564
565 6 trace = ctx->trace_enable;
566 6 ctx->trace_enable = 0;
567
568 18 for (int pass = 1; pass <= 2; pass++) {
569 12 *rw = metadata_start_state;
570
571 12 ub(32, metadata_size);
572
573 36 for (int p = 0; p < current->metadata_count; p++) {
574 24 APVRawMetadataPayload *pl = &current->payloads[p];
575 uint32_t payload_start_position;
576 uint32_t tmp;
577
578 24 tmp = pl->payload_type;
579 24 while (tmp >= 255) {
580 fixed(8, ff_byte, 0xff);
581 tmp -= 255;
582 }
583 24 xu(8, metadata_payload_type, tmp, 0, 254, 0);
584
585 24 tmp = pl->payload_size;
586 24 while (tmp >= 255) {
587 fixed(8, ff_byte, 0xff);
588 tmp -= 255;
589 }
590 24 xu(8, metadata_payload_size, tmp, 0, 254, 0);
591
592 24 payload_start_position = put_bits_count(rw);
593
594 24 err = FUNC(metadata_payload)(ctx, rw, pl);
595 24 ctx->trace_enable = trace;
596 24 if (err < 0)
597 return err;
598
599 24 if (pass == 1) {
600 12 pl->payload_size = (put_bits_count(rw) -
601 12 payload_start_position) / 8;
602 }
603 }
604
605 12 if (pass == 1) {
606 6 current->metadata_size = (put_bits_count(rw) -
607 6 metadata_start_position) / 8 - 4;
608 6 ctx->trace_enable = trace;
609 }
610 }
611 #endif
612
613
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
24 CHECK(FUNC(filler)(ctx, rw, &current->filler));
614
615 24 return 0;
616 }
617