FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cbs_sei_syntax_template.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 122 241 50.6%
Functions: 18 50 36.0%
Branches: 56 247 22.7%

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 SEI_FUNC(filler_payload, (CodedBitstreamContext *ctx, RWContext *rw,
20 SEIRawFillerPayload *current,
21 SEIMessageState *state))
22 {
23 int err, i;
24
25 HEADER("Filler Payload");
26
27 #ifdef READ
28 current->payload_size = state->payload_size;
29 #endif
30
31 for (i = 0; i < current->payload_size; i++)
32 fixed(8, ff_byte, 0xff);
33
34 return 0;
35 }
36
37 300 SEI_FUNC(user_data_registered, (CodedBitstreamContext *ctx, RWContext *rw,
38 SEIRawUserDataRegistered *current,
39 SEIMessageState *state))
40 {
41 int err, i, j;
42
43 150 HEADER("User Data Registered ITU-T T.35");
44
45
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
150 u(8, itu_t_t35_country_code, 0x00, 0xff);
46
1/2
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
150 if (current->itu_t_t35_country_code != 0xff)
47 150 i = 1;
48 else {
49 u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
50 i = 2;
51 }
52
53 #ifdef READ
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
50 if (state->payload_size < i) {
55 av_log(ctx->log_ctx, AV_LOG_ERROR,
56 "Invalid SEI user data registered payload.\n");
57 return AVERROR_INVALIDDATA;
58 }
59 50 current->data_length = state->payload_size - i;
60 #endif
61
62
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 25 times.
150 allocate(current->data, current->data_length);
63
2/2
✓ Branch 0 taken 729 times.
✓ Branch 1 taken 75 times.
1608 for (j = 0; j < current->data_length; j++)
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 729 times.
1458 xu(8, itu_t_t35_payload_byte[], current->data[j], 0x00, 0xff, 1, i + j);
65
66 150 return 0;
67 }
68
69 264 SEI_FUNC(user_data_unregistered, (CodedBitstreamContext *ctx, RWContext *rw,
70 SEIRawUserDataUnregistered *current,
71 SEIMessageState *state))
72 {
73 int err, i;
74
75 132 HEADER("User Data Unregistered");
76
77 #ifdef READ
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
44 if (state->payload_size < 16) {
79 av_log(ctx->log_ctx, AV_LOG_ERROR,
80 "Invalid SEI user data unregistered payload.\n");
81 return AVERROR_INVALIDDATA;
82 }
83 44 current->data_length = state->payload_size - 16;
84 #endif
85
86
2/2
✓ Branch 0 taken 1056 times.
✓ Branch 1 taken 66 times.
2244 for (i = 0; i < 16; i++)
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1056 times.
2112 us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
88
89
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 22 times.
132 allocate(current->data, current->data_length);
90
91
2/2
✓ Branch 0 taken 18363 times.
✓ Branch 1 taken 66 times.
36858 for (i = 0; i < current->data_length; i++)
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18363 times.
36726 xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
93
94 132 return 0;
95 }
96
97 SEI_FUNC(frame_packing_arrangement, (CodedBitstreamContext *ctx, RWContext *rw,
98 SEIRawFramePackingArrangement *current,
99 SEIMessageState *unused))
100 {
101 int err;
102
103 HEADER("Frame Packing Arrangement");
104
105 ue(fp_arrangement_id, 0, MAX_UINT_BITS(31));
106 flag(fp_arrangement_cancel_flag);
107 if (!current->fp_arrangement_cancel_flag) {
108 u(7, fp_arrangement_type, 3, 5);
109 flag(fp_quincunx_sampling_flag);
110 u(6, fp_content_interpretation_type, 0, 2);
111 flag(fp_spatial_flipping_flag);
112 flag(fp_frame0_flipped_flag);
113 flag(fp_field_views_flag);
114 flag(fp_current_frame_is_frame0_flag);
115 flag(fp_frame0_self_contained_flag);
116 flag(fp_frame1_self_contained_flag);
117 if (!current->fp_quincunx_sampling_flag && current->fp_arrangement_type != 5) {
118 ub(4, fp_frame0_grid_position_x);
119 ub(4, fp_frame0_grid_position_y);
120 ub(4, fp_frame1_grid_position_x);
121 ub(4, fp_frame1_grid_position_y);
122 }
123 fixed(8, fp_arrangement_reserved_byte, 0);
124 flag(fp_arrangement_persistence_flag);
125 }
126 flag(fp_upsampled_aspect_ratio_flag);
127
128 return 0;
129 }
130
131 29148 SEI_FUNC(decoded_picture_hash, (CodedBitstreamContext *ctx,
132 RWContext *rw,
133 SEIRawDecodedPictureHash *current,
134 SEIMessageState *unused))
135 {
136 int err, c_idx, i;
137
138 14574 HEADER("Decoded Picture Hash");
139
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7287 times.
14574 u(8, dph_sei_hash_type, 0, 2);
141
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7287 times.
14574 flag(dph_sei_single_component_flag);
142
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7287 times.
14574 ub(7, dph_sei_reserved_zero_7bits);
143
144
4/4
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 28116 times.
✓ Branch 2 taken 21345 times.
✓ Branch 3 taken 7287 times.
57264 for (c_idx = 0; c_idx < (current->dph_sei_single_component_flag ? 1 : 3);
145 42690 c_idx++) {
146
1/2
✓ Branch 0 taken 21345 times.
✗ Branch 1 not taken.
42690 if (current->dph_sei_hash_type == 0) {
147
2/2
✓ Branch 0 taken 341520 times.
✓ Branch 1 taken 21345 times.
725730 for (i = 0; i < 16; i++)
148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 341520 times.
683040 us(8, dph_sei_picture_md5[c_idx][i], 0x00, 0xff, 2, c_idx, i);
149 } else if (current->dph_sei_hash_type == 1) {
150 us(16, dph_sei_picture_crc[c_idx], 0x0000, 0xffff, 1, c_idx);
151 } else if (current->dph_sei_hash_type == 2) {
152 us(32, dph_sei_picture_checksum[c_idx], 0x00000000, 0xffffffff, 1,
153 c_idx);
154 }
155 }
156 14574 return 0;
157 }
158
159 12 SEI_FUNC(mastering_display_colour_volume,
160 (CodedBitstreamContext *ctx, RWContext *rw,
161 SEIRawMasteringDisplayColourVolume *current,
162 SEIMessageState *state))
163 {
164 int err, c;
165
166 6 HEADER("Mastering Display Colour Volume");
167
168
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
24 for (c = 0; c < 3; c++) {
169
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
18 ubs(16, display_primaries_x[c], 1, c);
170
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
18 ubs(16, display_primaries_y[c], 1, c);
171 }
172
173
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(16, white_point_x);
174
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(16, white_point_y);
175
176
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(32, max_display_mastering_luminance);
177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(32, min_display_mastering_luminance);
178
179 6 return 0;
180 }
181
182 SEI_FUNC(content_light_level_info, (CodedBitstreamContext *ctx, RWContext *rw,
183 SEIRawContentLightLevelInfo *current,
184 SEIMessageState *state))
185 {
186 int err;
187
188 HEADER("Content Light Level Information");
189
190 ub(16, max_content_light_level);
191 ub(16, max_pic_average_light_level);
192
193 return 0;
194 }
195
196 SEI_FUNC(alternative_transfer_characteristics,
197 (CodedBitstreamContext *ctx, RWContext *rw,
198 SEIRawAlternativeTransferCharacteristics *current,
199 SEIMessageState *state))
200 {
201 int err;
202
203 HEADER("Alternative Transfer Characteristics");
204
205 ub(8, preferred_transfer_characteristics);
206
207 return 0;
208 }
209
210 SEI_FUNC(ambient_viewing_environment,
211 (CodedBitstreamContext *ctx, RWContext *rw,
212 SEIRawAmbientViewingEnvironment *current,
213 SEIMessageState *state))
214 {
215 static const uint16_t max_ambient_light_value = 50000;
216 int err;
217
218 HEADER("Ambient Viewing Environment");
219
220 u(32, ambient_illuminance, 1, MAX_UINT_BITS(32));
221 u(16, ambient_light_x, 0, max_ambient_light_value);
222 u(16, ambient_light_y, 0, max_ambient_light_value);
223
224 return 0;
225 }
226
227 SEI_FUNC(film_grain_characteristics,
228 (CodedBitstreamContext *ctx, RWContext *rw,
229 SEIRawFilmGrainCharacteristics *current,
230 SEIMessageState *state))
231 {
232 int err, c, i, j;
233
234 HEADER("Film Grain Characteristics");
235
236 flag(fg_characteristics_cancel_flag);
237 if (!current->fg_characteristics_cancel_flag) {
238 int filmGrainBitDepth[3];
239
240 u(2, fg_model_id, 0, 1);
241 flag(fg_separate_colour_description_present_flag);
242 if (current->fg_separate_colour_description_present_flag) {
243 ub(3, fg_bit_depth_luma_minus8);
244 ub(3, fg_bit_depth_chroma_minus8);
245 flag(fg_full_range_flag);
246 ub(8, fg_colour_primaries);
247 ub(8, fg_transfer_characteristics);
248 ub(8, fg_matrix_coeffs);
249 }
250
251 filmGrainBitDepth[0] = current->fg_bit_depth_luma_minus8 + 8;
252 filmGrainBitDepth[1] =
253 filmGrainBitDepth[2] = current->fg_bit_depth_chroma_minus8 + 8;
254
255 u(2, fg_blending_mode_id, 0, 1);
256 ub(4, fg_log2_scale_factor);
257 for (c = 0; c < 3; c++)
258 flags(fg_comp_model_present_flag[c], 1, c);
259
260 for (c = 0; c < 3; c++) {
261 if (current->fg_comp_model_present_flag[c]) {
262 ubs(8, fg_num_intensity_intervals_minus1[c], 1, c);
263 us(3, fg_num_model_values_minus1[c], 0, 5, 1, c);
264 for (i = 0; i <= current->fg_num_intensity_intervals_minus1[c]; i++) {
265 ubs(8, fg_intensity_interval_lower_bound[c][i], 2, c, i);
266 ubs(8, fg_intensity_interval_upper_bound[c][i], 2, c, i);
267 for (j = 0; j <= current->fg_num_model_values_minus1[c]; j++)
268 ses(fg_comp_model_value[c][i][j], 0 - current->fg_model_id * (1 << (filmGrainBitDepth[c] - 1)),
269 ((1 << filmGrainBitDepth[c]) - 1) - current->fg_model_id * (1 << (filmGrainBitDepth[c] - 1)),
270 3, c, i, j);
271 }
272 }
273 }
274 flag(fg_characteristics_persistence_flag);
275 }
276
277 return 0;
278 }
279
280 SEI_FUNC(display_orientation, (CodedBitstreamContext *ctx, RWContext *rw,
281 SEIRawDisplayOrientation *current,
282 SEIMessageState *state))
283 {
284 int err;
285
286 HEADER("Display Orientation");
287
288 flag(display_orientation_cancel_flag);
289 if (!current->display_orientation_cancel_flag) {
290 flag(display_orientation_persistence_flag);
291 u(3, display_orientation_transform_type, 0, 7);
292 ub(3, display_orientation_reserved_zero_3bits);
293 }
294
295 return 0;
296 }
297
298 SEI_FUNC(frame_field_information, (CodedBitstreamContext *ctx, RWContext *rw,
299 SEIRawFrameFieldInformation *current,
300 SEIMessageState *state))
301 {
302 int err;
303
304 HEADER("Frame-field information");
305
306 flag(ffi_field_pic_flag);
307 if (current->ffi_field_pic_flag) {
308 flag(ffi_bottom_field_flag);
309 flag(ffi_pairing_indicated_flag);
310 if (current->ffi_pairing_indicated_flag)
311 flag(ffi_paired_with_next_field_flag);
312 } else {
313 flag(ffi_display_fields_from_frame_flag);
314 if (current->ffi_display_fields_from_frame_flag)
315 flag(ffi_top_field_first_flag);
316 u(8, ffi_display_elemental_periods_minus1, 0, 0xff);
317 }
318 u(2, ffi_source_scan_type, 0, 3);
319 flag(ffi_duplicate_flag);
320
321 return 0;
322 }
323
324 28762 static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
325 SEIRawMessage *current)
326 {
327 const SEIMessageTypeDescriptor *desc;
328 int err, i;
329
330 28762 desc = ff_cbs_sei_find_type(ctx, current->payload_type);
331
2/2
✓ Branch 0 taken 14112 times.
✓ Branch 1 taken 269 times.
28762 if (desc) {
332 28224 SEIMessageState state = {
333 28224 .payload_type = current->payload_type,
334 28224 .payload_size = current->payload_size,
335 28224 .extension_present = current->extension_bit_length > 0,
336 };
337 int start_position, current_position, bits_written;
338
339 #ifdef READ
340
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5688 times.
11376 CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
341 #endif
342
343 28224 start_position = bit_position(rw);
344
345
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14112 times.
28224 CHECK(desc->READWRITE(ctx, rw, current->payload, &state));
346
347 28224 current_position = bit_position(rw);
348 28224 bits_written = current_position - start_position;
349
350
3/4
✓ Branch 1 taken 11829 times.
✓ Branch 2 taken 2283 times.
✓ Branch 3 taken 11829 times.
✗ Branch 4 not taken.
28224 if (byte_alignment(rw) || state.extension_present ||
351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11829 times.
23658 bits_written < 8 * current->payload_size) {
352 size_t bits_left;
353
354 #ifdef READ
355 2066 GetBitContext tmp = *rw;
356 int trailing_bits, trailing_zero_bits;
357
358 2066 bits_left = 8 * current->payload_size - bits_written;
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1033 times.
2066 if (bits_left > 8)
360 skip_bits_long(&tmp, bits_left - 8);
361 2066 trailing_bits = get_bits(&tmp, FFMIN(bits_left, 8));
362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1033 times.
2066 if (trailing_bits == 0) {
363 // The trailing bits must contain a bit_equal_to_one, so
364 // they can't all be zero.
365 return AVERROR_INVALIDDATA;
366 }
367 2066 trailing_zero_bits = ff_ctz(trailing_bits);
368 2066 current->extension_bit_length =
369 2066 bits_left - 1 - trailing_zero_bits;
370 #endif
371
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2283 times.
4566 if (current->extension_bit_length > 0) {
373 allocate(current->extension_data,
374 (current->extension_bit_length + 7) / 8);
375
376 bits_left = current->extension_bit_length;
377 for (i = 0; bits_left > 0; i++) {
378 int length = FFMIN(bits_left, 8);
379 xu(length, reserved_payload_extension_data,
380 current->extension_data[i],
381 0, MAX_UINT_BITS(length), 0);
382 bits_left -= length;
383 }
384 }
385
386
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2283 times.
4566 fixed(1, bit_equal_to_one, 1);
387
2/2
✓ Branch 1 taken 3102 times.
✓ Branch 2 taken 2283 times.
10770 while (byte_alignment(rw))
388
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3102 times.
6204 fixed(1, bit_equal_to_zero, 0);
389 }
390
391 #ifdef WRITE
392 16848 current->payload_size = (put_bits_count(rw) - start_position) / 8;
393 #endif
394 } else {
395 uint8_t *data;
396
397 #ifdef READ
398
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 135 times.
270 allocate(current->payload_ref, current->payload_size);
399 270 current->payload = current->payload_ref;
400 #else
401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 134 times.
268 allocate(current->payload, current->payload_size);
402 #endif
403 538 data = current->payload;
404
405
2/2
✓ Branch 0 taken 6370 times.
✓ Branch 1 taken 269 times.
13278 for (i = 0; i < current->payload_size; i++)
406
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6370 times.
12740 xu(8, payload_byte[i], data[i], 0, 255, 1, i);
407 }
408
409 28762 return 0;
410 }
411
412 10062 static int FUNC(message_list)(CodedBitstreamContext *ctx, RWContext *rw,
413 SEIRawMessageList *current, int prefix)
414 {
415 SEIRawMessage *message;
416 int err, k;
417
418 #ifdef READ
419 5823 for (k = 0;; k++) {
420 5823 uint32_t payload_type = 0;
421 5823 uint32_t payload_size = 0;
422 uint32_t tmp;
423 GetBitContext payload_gbc;
424
425 5843 while (show_bits(rw, 8) == 0xff) {
426 20 fixed(8, ff_byte, 0xff);
427 20 payload_type += 255;
428 }
429 5823 xu(8, last_payload_type_byte, tmp, 0, 254, 0);
430 5823 payload_type += tmp;
431
432 5846 while (show_bits(rw, 8) == 0xff) {
433 23 fixed(8, ff_byte, 0xff);
434 23 payload_size += 255;
435 }
436 5823 xu(8, last_payload_size_byte, tmp, 0, 254, 0);
437 5823 payload_size += tmp;
438
439 // There must be space remaining for both the payload and
440 // the trailing bits on the SEI NAL unit.
441 5823 if (payload_size + 1 > get_bits_left(rw) / 8) {
442 av_log(ctx->log_ctx, AV_LOG_ERROR,
443 "Invalid SEI message: payload_size too large "
444 "(%"PRIu32" bytes).\n", payload_size);
445 return AVERROR_INVALIDDATA;
446 }
447 5823 CHECK(init_get_bits(&payload_gbc, rw->buffer,
448 get_bits_count(rw) + 8 * payload_size));
449 5823 skip_bits_long(&payload_gbc, get_bits_count(rw));
450
451 5823 CHECK(ff_cbs_sei_list_add(current));
452 5823 message = &current->messages[k];
453
454 5823 message->payload_type = payload_type;
455 5823 message->payload_size = payload_size;
456
457 5823 CHECK(FUNC(message)(ctx, &payload_gbc, message));
458
459 5823 skip_bits_long(rw, 8 * payload_size);
460
461 5823 if (!cbs_h2645_read_more_rbsp_data(rw))
462 5803 break;
463 }
464 #else
465 8538 for (k = 0; k < current->nb_messages; k++) {
466 PutBitContext start_state;
467 uint32_t tmp;
468 int trace, i;
469
470 4279 message = &current->messages[k];
471
472 // We write the payload twice in order to find the size. Trace
473 // output is switched off for the first write.
474 4279 trace = ctx->trace_enable;
475 4279 ctx->trace_enable = 0;
476
477 4279 start_state = *rw;
478 12837 for (i = 0; i < 2; i++) {
479 8558 *rw = start_state;
480
481 8558 tmp = message->payload_type;
482 8598 while (tmp >= 255) {
483 40 fixed(8, ff_byte, 0xff);
484 40 tmp -= 255;
485 }
486 8558 xu(8, last_payload_type_byte, tmp, 0, 254, 0);
487
488 8558 tmp = message->payload_size;
489 8604 while (tmp >= 255) {
490 46 fixed(8, ff_byte, 0xff);
491 46 tmp -= 255;
492 }
493 8558 xu(8, last_payload_size_byte, tmp, 0, 254, 0);
494
495 8558 err = FUNC(message)(ctx, rw, message);
496 8558 ctx->trace_enable = trace;
497 8558 if (err < 0)
498 return err;
499 }
500 }
501 #endif
502
503 10062 return 0;
504 }
505