FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cbs_apv_syntax_template.c
Date: 2026-10-20 22:17:59
Exec Total Coverage
Lines: 185 307 60.3%
Functions: 22 37 59.5%
Branches: 83 272 30.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 u(24, frame_width, 1, MAX_UINT_BITS(24));
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 u(24, frame_height, 1, MAX_UINT_BITS(24));
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 uint32_t data_size, padding_size;
232 int err;
233
234
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 CHECK(FUNC(tile_header)(ctx, rw, &current->tile_header,
235 tile_idx, tile_size));
236
237 174 data_size = 0;
238
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 90 times.
560 for (int c = 0; c < priv->num_comp; c++) {
239 386 uint32_t comp_size = current->tile_header.tile_data_size[c];
240 #ifdef READ
241 338 int pos = get_bits_count(rw);
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
338 av_assert0(pos % 8 == 0);
243
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
338 if (get_bits_left(rw) < 8LL * comp_size)
244 ✗ return AVERROR_INVALIDDATA;
245 338 current->tile_data[c] = (uint8_t*)align_get_bits(rw);
246 338 skip_bits_long(rw, 8 * comp_size);
247 #else
248
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
48 if (put_bytes_left(rw, 0) < comp_size)
249 ✗ return AVERROR(ENOSPC);
250 48 ff_copy_bits(rw, current->tile_data[c], comp_size * 8);
251 #endif
252 386 data_size += comp_size;
253 }
254
255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
174 av_assert0(tile_size >=
256 current->tile_header.tile_header_size + data_size);
257 174 padding_size = tile_size -
258 174 (current->tile_header.tile_header_size + data_size);
259
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
174 if (padding_size > 0) {
261 #ifdef READ
262 ✗ current->tile_dummy_byte = (uint8_t*)align_get_bits(rw);
263 ✗ current->tile_dummy_byte_size = padding_size;
264 ✗ skip_bits_long(rw, 8 * padding_size);
265 #else
266 ✗ if (put_bytes_left(rw, 0) < padding_size)
267 ✗ return AVERROR(ENOSPC);
268 ✗ ff_copy_bits(rw, current->tile_dummy_byte, 8 * padding_size);
269 #endif
270 }
271
272 174 return 0;
273 }
274
275 87 static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw,
276 APVRawFrame *current)
277 {
278 87 CodedBitstreamAPVContext *priv = ctx->priv_data;
279 int err;
280
281 87 HEADER("Frame");
282
283 #ifdef WRITE
284 // Calculate tile sizes from header, components and padding
285 // before writing any of them. Must be done early because we might
286 // need to write them in the header.
287
288 12 cbs_apv_derive_tile_info(ctx, &current->frame_header);
289 12 priv->num_comp = cbs_apv_get_num_comp(&current->frame_header);
290
291
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
36 for (int t = 0; t < priv->num_tiles; t++) {
292 24 APVRawTile *tile = &current->tile[t];
293 24 uint32_t size = tile->tile_header.tile_header_size;
294
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
72 for (int c = 0; c < priv->num_comp; c++)
295 48 size += tile->tile_header.tile_data_size[c];
296 24 size += tile->tile_dummy_byte_size;
297
298 24 current->tile_size[t] = size;
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
24 if (current->frame_header.tile_info.tile_size_present_in_fh_flag)
300 ✗ current->frame_header.tile_info.tile_size_in_fh[t] = size;
301 }
302 #endif
303
304
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(pbu_header)(ctx, rw, &current->pbu_header));
305
306
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(frame_header)(ctx, rw, &current->frame_header));
307
308
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 45 times.
261 for (int t = 0; t < priv->num_tiles; t++) {
309 174 APVRawTile *tile = &current->tile[t];
310
311
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 us(32, tile_size[t], 10, MAX_INT_BITS(32), 1, t);
312
313
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
174 CHECK(FUNC(tile)(ctx, rw, tile, t, current->tile_size[t]));
314 }
315
316
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
87 CHECK(FUNC(filler)(ctx, rw, &current->filler));
317
318 87 return 0;
319 }
320
321 ✗ static int FUNC(au_info)(CodedBitstreamContext *ctx, RWContext *rw,
322 APVRawAUInfo *current)
323 {
324 int err;
325
326 ✗ HEADER("Access Unit Information");
327
328 ✗ u(16, num_frames, 1, CBS_APV_MAX_AU_FRAMES);
329
330 ✗ for (int i = 0; i < current->num_frames; i++) {
331 ✗ ubs(8, pbu_type[i], 1, i);
332 ✗ ubs(8, group_id[i], 1, i);
333
334 ✗ us(8, reserved_zero_8bits[i], 0, 0, 1, i);
335
336 ✗ CHECK(FUNC(frame_info)(ctx, rw, &current->frame_info[i]));
337 }
338
339 ✗ u(8, reserved_zero_8bits_2, 0, 0);
340
341 ✗ return 0;
342 }
343
344 ✗ static int FUNC(metadata_itu_t_t35)(CodedBitstreamContext *ctx,
345 RWContext *rw,
346 APVRawMetadataITUTT35 *current,
347 size_t payload_size)
348 {
349 int err;
350 ✗ size_t read_size = payload_size - 1;
351
352 ✗ HEADER("ITU-T T.35 Metadata");
353
354 ✗ ub(8, itu_t_t35_country_code);
355
356 ✗ if (payload_size < 1 + (current->itu_t_t35_country_code == 0xff))
357 ✗ return AVERROR_INVALIDDATA;
358
359 ✗ if (current->itu_t_t35_country_code == 0xff) {
360 ✗ ub(8, itu_t_t35_country_code_extension);
361 ✗ --read_size;
362 }
363
364 #ifdef READ
365 ✗ current->data_size = read_size;
366 ✗ current->data_ref = av_buffer_alloc(current->data_size);
367 ✗ if (!current->data_ref)
368 ✗ return AVERROR(ENOMEM);
369 ✗ current->data = current->data_ref->data;
370 #else
371 ✗ if (current->data_size != read_size) {
372 ✗ av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
373 "payload %zu but expecting %zu\n",
374 current->data_size, read_size);
375 ✗ return AVERROR(EINVAL);
376 }
377 #endif
378
379 ✗ for (size_t i = 0; i < current->data_size; i++) {
380 ✗ xu(8, itu_t_t35_payload[i],
381 current->data[i], 0x00, 0xff, 1, i);
382 }
383
384 ✗ return 0;
385 }
386
387 ✗ static int FUNC(metadata_mdcv)(CodedBitstreamContext *ctx,
388 RWContext *rw,
389 APVRawMetadataMDCV *current)
390 {
391 int err, i;
392
393 ✗ HEADER("MDCV Metadata");
394
395 ✗ for (i = 0; i < 3; i++) {
396 ✗ ubs(16, primary_chromaticity_x[i], 1, i);
397 ✗ ubs(16, primary_chromaticity_y[i], 1, i);
398 }
399
400 ✗ ub(16, white_point_chromaticity_x);
401 ✗ ub(16, white_point_chromaticity_y);
402
403 ✗ ub(32, max_mastering_luminance);
404 ✗ ub(32, min_mastering_luminance);
405
406 ✗ return 0;
407 }
408
409 ✗ static int FUNC(metadata_cll)(CodedBitstreamContext *ctx,
410 RWContext *rw,
411 APVRawMetadataCLL *current)
412 {
413 int err;
414
415 ✗ HEADER("CLL Metadata");
416
417 ✗ ub(16, max_cll);
418 ✗ ub(16, max_fall);
419
420 ✗ return 0;
421 }
422
423 ✗ static int FUNC(metadata_filler)(CodedBitstreamContext *ctx,
424 RWContext *rw,
425 APVRawMetadataFiller *current,
426 size_t payload_size)
427 {
428 int err;
429
430 ✗ HEADER("Filler Metadata");
431
432 ✗ for (size_t i = 0; i < payload_size; i++)
433 ✗ fixed(8, ff_byte, 0xff);
434
435 ✗ return 0;
436 }
437
438 120 static int FUNC(metadata_user_defined)(CodedBitstreamContext *ctx,
439 RWContext *rw,
440 APVRawMetadataUserDefined *current,
441 size_t payload_size)
442 {
443 int err;
444
445 120 HEADER("User-Defined Metadata");
446
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
120 if (payload_size < 16)
448 ✗ return AVERROR_INVALIDDATA;
449
450
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 60 times.
2040 for (int i = 0; i < 16; i++)
451
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 960 times.
1920 ubs(8, uuid[i], 1, i);
452
453 #ifdef READ
454 72 current->data_size = payload_size - 16;
455 72 current->data_ref = av_buffer_alloc(current->data_size);
456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
72 if (!current->data_ref)
457 ✗ return AVERROR(ENOMEM);
458 72 current->data = current->data_ref->data;
459 #else
460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
48 if (current->data_size != payload_size - 16) {
461 ✗ av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
462 "payload %zu but expecting %zu\n",
463 current->data_size, payload_size - 16);
464 ✗ return AVERROR(EINVAL);
465 }
466 #endif
467
468
2/2
✓ Branch 0 taken 1922 times.
✓ Branch 1 taken 60 times.
3964 for (size_t i = 0; i < current->data_size; i++) {
469
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1922 times.
3844 xu(8, user_defined_data_payload[i],
470 current->data[i], 0x00, 0xff, 1, i);
471 }
472
473 120 return 0;
474 }
475
476 ✗ static int FUNC(metadata_undefined)(CodedBitstreamContext *ctx,
477 RWContext *rw,
478 APVRawMetadataUndefined *current,
479 size_t payload_size)
480 {
481 int err;
482
483 ✗ HEADER("Undefined Metadata");
484
485 #ifdef READ
486 ✗ current->data_size = payload_size;
487 ✗ current->data_ref = av_buffer_alloc(current->data_size);
488 ✗ if (!current->data_ref)
489 ✗ return AVERROR(ENOMEM);
490 ✗ current->data = current->data_ref->data;
491 #else
492 ✗ if (current->data_size != payload_size) {
493 ✗ av_log(ctx->log_ctx, AV_LOG_ERROR, "Write size mismatch: "
494 "payload %zu but expecting %zu\n",
495 current->data_size, payload_size - 16);
496 ✗ return AVERROR(EINVAL);
497 }
498 #endif
499
500 ✗ for (size_t i = 0; i < current->data_size; i++) {
501 ✗ xu(8, undefined_metadata_payload_byte[i],
502 current->data[i], 0x00, 0xff, 1, i);
503 }
504
505 ✗ return 0;
506 }
507
508 120 static int FUNC(metadata_payload)(CodedBitstreamContext *ctx,
509 RWContext *rw,
510 APVRawMetadataPayload *current)
511 {
512 int err;
513
514
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) {
515 ✗ case APV_METADATA_ITU_T_T35:
516 ✗ CHECK(FUNC(metadata_itu_t_t35)(ctx, rw,
517 &current->itu_t_t35,
518 current->payload_size));
519 ✗ break;
520 ✗ case APV_METADATA_MDCV:
521 ✗ CHECK(FUNC(metadata_mdcv)(ctx, rw, &current->mdcv));
522 ✗ break;
523 ✗ case APV_METADATA_CLL:
524 ✗ CHECK(FUNC(metadata_cll)(ctx, rw, &current->cll));
525 ✗ break;
526 ✗ case APV_METADATA_FILLER:
527 ✗ CHECK(FUNC(metadata_filler)(ctx, rw,
528 &current->filler,
529 current->payload_size));
530 ✗ break;
531 120 case APV_METADATA_USER_DEFINED:
532
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
120 CHECK(FUNC(metadata_user_defined)(ctx, rw,
533 &current->user_defined,
534 current->payload_size));
535 120 break;
536 ✗ default:
537 ✗ CHECK(FUNC(metadata_undefined)(ctx, rw,
538 &current->undefined,
539 current->payload_size));
540 }
541
542 120 return 0;
543 }
544
545 24 static int FUNC(metadata)(CodedBitstreamContext *ctx, RWContext *rw,
546 APVRawMetadata *current)
547 {
548 int err;
549
550 #ifdef READ
551 uint32_t metadata_bytes_left;
552 #else
553 PutBitContext metadata_start_state;
554 uint32_t metadata_start_position;
555 int trace;
556 #endif
557
558 24 HEADER("Metadata");
559
560
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
24 CHECK(FUNC(pbu_header)(ctx, rw, &current->pbu_header));
561
562 #ifdef READ
563
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
18 ub(32, metadata_size);
564
565 18 metadata_bytes_left = current->metadata_size;
566
567
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 for (int p = 0; p < CBS_APV_MAX_METADATA_PAYLOADS; p++) {
568 36 APVRawMetadataPayload *pl = &current->payloads[p];
569 uint32_t tmp;
570
571 36 pl->payload_type = 0;
572
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 while (show_bits(rw, 8) == 0xff) {
573 ✗ fixed(8, ff_byte, 0xff);
574 ✗ pl->payload_type += 255;
575 ✗ --metadata_bytes_left;
576 }
577
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 xu(8, metadata_payload_type, tmp, 0, 254, 0);
578 36 pl->payload_type += tmp;
579 36 --metadata_bytes_left;
580
581 36 pl->payload_size = 0;
582
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 while (show_bits(rw, 8) == 0xff) {
583 ✗ fixed(8, ff_byte, 0xff);
584 ✗ pl->payload_size += 255;
585 ✗ --metadata_bytes_left;
586 }
587
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 xu(8, metadata_payload_size, tmp, 0, 254, 0);
588 36 pl->payload_size += tmp;
589 36 --metadata_bytes_left;
590
591
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 if (pl->payload_size > metadata_bytes_left) {
592 ✗ av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid metadata: "
593 "payload_size larger than remaining metadata size "
594 "(%"PRIu32" bytes).\n", pl->payload_size);
595 ✗ return AVERROR_INVALIDDATA;
596 }
597
598 36 current->metadata_count = p + 1;
599
600
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
36 CHECK(FUNC(metadata_payload)(ctx, rw, pl));
601
602 36 metadata_bytes_left -= pl->payload_size;
603
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
36 if (metadata_bytes_left == 0)
604 18 break;
605 }
606 #else
607 // Two passes: the first write finds the size (with tracing
608 // disabled), the second write does the real write.
609
610 6 metadata_start_state = *rw;
611 6 metadata_start_position = put_bits_count(rw);
612
613 6 trace = ctx->trace_enable;
614 6 ctx->trace_enable = 0;
615
616 18 for (int pass = 1; pass <= 2; pass++) {
617 12 *rw = metadata_start_state;
618
619 12 ub(32, metadata_size);
620
621 36 for (int p = 0; p < current->metadata_count; p++) {
622 24 APVRawMetadataPayload *pl = &current->payloads[p];
623 uint32_t payload_start_position;
624 uint32_t tmp;
625
626 24 tmp = pl->payload_type;
627 24 while (tmp >= 255) {
628 ✗ fixed(8, ff_byte, 0xff);
629 ✗ tmp -= 255;
630 }
631 24 xu(8, metadata_payload_type, tmp, 0, 254, 0);
632
633 24 tmp = pl->payload_size;
634 24 while (tmp >= 255) {
635 ✗ fixed(8, ff_byte, 0xff);
636 ✗ tmp -= 255;
637 }
638 24 xu(8, metadata_payload_size, tmp, 0, 254, 0);
639
640 24 payload_start_position = put_bits_count(rw);
641
642 24 err = FUNC(metadata_payload)(ctx, rw, pl);
643 24 ctx->trace_enable = trace;
644 24 if (err < 0)
645 ✗ return err;
646
647 24 if (pass == 1) {
648 12 pl->payload_size = (put_bits_count(rw) -
649 12 payload_start_position) / 8;
650 }
651 }
652
653 12 if (pass == 1) {
654 6 current->metadata_size = (put_bits_count(rw) -
655 6 metadata_start_position) / 8 - 4;
656 6 ctx->trace_enable = trace;
657 }
658 }
659 #endif
660
661
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
24 CHECK(FUNC(filler)(ctx, rw, &current->filler));
662
663 24 return 0;
664 }
665