FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc_sei.c
Date: 2022-01-22 23:30:28
Exec Total Coverage
Lines: 184 325 56.6%
Branches: 81 160 50.6%

Line Branch Exec Source
1 /*
2 * HEVC Supplementary Enhancement Information messages
3 *
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Gildas Cocherel
6 * Copyright (C) 2013 Vittorio Giovara
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "atsc_a53.h"
26 #include "dynamic_hdr10_plus.h"
27 #include "golomb.h"
28 #include "hevc_ps.h"
29 #include "hevc_sei.h"
30
31 6848 static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s, GetBitContext *gb)
32 {
33 int cIdx, i;
34 uint8_t hash_type;
35 //uint16_t picture_crc;
36 //uint32_t picture_checksum;
37 6848 hash_type = get_bits(gb, 8);
38
39
2/2
✓ Branch 0 taken 20544 times.
✓ Branch 1 taken 6848 times.
27392 for (cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++) {
40
2/2
✓ Branch 0 taken 19497 times.
✓ Branch 1 taken 1047 times.
20544 if (hash_type == 0) {
41 19497 s->is_md5 = 1;
42
2/2
✓ Branch 0 taken 311952 times.
✓ Branch 1 taken 19497 times.
331449 for (i = 0; i < 16; i++)
43 311952 s->md5[cIdx][i] = get_bits(gb, 8);
44
2/2
✓ Branch 0 taken 291 times.
✓ Branch 1 taken 756 times.
1047 } else if (hash_type == 1) {
45 // picture_crc = get_bits(gb, 16);
46 291 skip_bits(gb, 16);
47
1/2
✓ Branch 0 taken 756 times.
✗ Branch 1 not taken.
756 } else if (hash_type == 2) {
48 // picture_checksum = get_bits_long(gb, 32);
49 756 skip_bits(gb, 32);
50 }
51 }
52 6848 return 0;
53 }
54
55 3 static int decode_nal_sei_mastering_display_info(HEVCSEIMasteringDisplay *s, GetBitContext *gb, int size)
56 {
57 int i;
58
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (size < 24)
60 return AVERROR_INVALIDDATA;
61
62 // Mastering primaries
63
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 for (i = 0; i < 3; i++) {
64 9 s->display_primaries[i][0] = get_bits(gb, 16);
65 9 s->display_primaries[i][1] = get_bits(gb, 16);
66 }
67 // White point (x, y)
68 3 s->white_point[0] = get_bits(gb, 16);
69 3 s->white_point[1] = get_bits(gb, 16);
70
71 // Max and min luminance of mastering display
72 3 s->max_luminance = get_bits_long(gb, 32);
73 3 s->min_luminance = get_bits_long(gb, 32);
74 3 size -= 24;
75
76 // As this SEI message comes before the first frame that references it,
77 // initialize the flag to 2 and decrement on IRAP access unit so it
78 // persists for the coded video sequence (e.g., between two IRAPs)
79 3 s->present = 2;
80
81 3 skip_bits_long(gb, 8 * size);
82 3 return 0;
83 }
84
85 3 static int decode_nal_sei_content_light_info(HEVCSEIContentLight *s, GetBitContext *gb, int size)
86 {
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (size < 4)
88 return AVERROR_INVALIDDATA;
89
90 // Max and average light levels
91 3 s->max_content_light_level = get_bits(gb, 16);
92 3 s->max_pic_average_light_level = get_bits(gb, 16);
93 3 size -= 4;
94 // As this SEI message comes before the first frame that references it,
95 // initialize the flag to 2 and decrement on IRAP access unit so it
96 // persists for the coded video sequence (e.g., between two IRAPs)
97 3 s->present = 2;
98
99 3 skip_bits_long(gb, 8 * size);
100 3 return 0;
101 }
102
103 static int decode_nal_sei_frame_packing_arrangement(HEVCSEIFramePacking *s, GetBitContext *gb)
104 {
105 get_ue_golomb_long(gb); // frame_packing_arrangement_id
106 s->present = !get_bits1(gb);
107
108 if (s->present) {
109 s->arrangement_type = get_bits(gb, 7);
110 s->quincunx_subsampling = get_bits1(gb);
111 s->content_interpretation_type = get_bits(gb, 6);
112
113 // spatial_flipping_flag, frame0_flipped_flag, field_views_flag
114 skip_bits(gb, 3);
115 s->current_frame_is_frame0_flag = get_bits1(gb);
116 // frame0_self_contained_flag, frame1_self_contained_flag
117 skip_bits(gb, 2);
118
119 if (!s->quincunx_subsampling && s->arrangement_type != 5)
120 skip_bits(gb, 16); // frame[01]_grid_position_[xy]
121 skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
122 skip_bits1(gb); // frame_packing_arrangement_persistence_flag
123 }
124 skip_bits1(gb); // upsampled_aspect_ratio_flag
125 return 0;
126 }
127
128 static int decode_nal_sei_display_orientation(HEVCSEIDisplayOrientation *s, GetBitContext *gb)
129 {
130 s->present = !get_bits1(gb);
131
132 if (s->present) {
133 s->hflip = get_bits1(gb); // hor_flip
134 s->vflip = get_bits1(gb); // ver_flip
135
136 s->anticlockwise_rotation = get_bits(gb, 16);
137 skip_bits1(gb); // display_orientation_persistence_flag
138 }
139
140 return 0;
141 }
142
143 1204 static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCParamSets *ps,
144 void *logctx, int size)
145 {
146 1204 HEVCSEIPictureTiming *h = &s->picture_timing;
147 HEVCSPS *sps;
148
149
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 1160 times.
1204 if (!ps->sps_list[s->active_seq_parameter_set_id])
150 44 return(AVERROR(ENOMEM));
151 1160 sps = (HEVCSPS*)ps->sps_list[s->active_seq_parameter_set_id]->data;
152
153
2/2
✓ Branch 0 taken 677 times.
✓ Branch 1 taken 483 times.
1160 if (sps->vui.frame_field_info_present_flag) {
154 677 int pic_struct = get_bits(gb, 4);
155 677 h->picture_struct = AV_PICTURE_STRUCTURE_UNKNOWN;
156
4/6
✓ Branch 0 taken 677 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 667 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 667 times.
677 if (pic_struct == 2 || pic_struct == 10 || pic_struct == 12) {
157 10 av_log(logctx, AV_LOG_DEBUG, "BOTTOM Field\n");
158 10 h->picture_struct = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
159
4/6
✓ Branch 0 taken 667 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 667 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 656 times.
667 } else if (pic_struct == 1 || pic_struct == 9 || pic_struct == 11) {
160 11 av_log(logctx, AV_LOG_DEBUG, "TOP Field\n");
161 11 h->picture_struct = AV_PICTURE_STRUCTURE_TOP_FIELD;
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 656 times.
656 } else if (pic_struct == 7) {
163 av_log(logctx, AV_LOG_DEBUG, "Frame/Field Doubling\n");
164 h->picture_struct = HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING;
165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 656 times.
656 } else if (pic_struct == 8) {
166 av_log(logctx, AV_LOG_DEBUG, "Frame/Field Tripling\n");
167 h->picture_struct = HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING;
168 }
169 677 get_bits(gb, 2); // source_scan_type
170 677 get_bits(gb, 1); // duplicate_flag
171 677 skip_bits1(gb);
172 677 size--;
173 }
174 1160 skip_bits_long(gb, 8 * size);
175
176 1160 return 0;
177 }
178
179 static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetBitContext *gb,
180 int size)
181 {
182 int ret;
183
184 ret = ff_parse_a53_cc(&s->buf_ref, gb->buffer + get_bits_count(gb) / 8, size);
185
186 if (ret < 0)
187 return ret;
188
189 skip_bits_long(gb, size * 8);
190
191 return 0;
192 }
193
194 10 static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitContext *gb,
195 int size)
196 {
197 AVBufferRef *buf_ref, **tmp;
198
199
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if (size < 16 || size >= INT_MAX - 1)
200 return AVERROR_INVALIDDATA;
201
202 10 tmp = av_realloc_array(s->buf_ref, s->nb_buf_ref + 1, sizeof(*s->buf_ref));
203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!tmp)
204 return AVERROR(ENOMEM);
205 10 s->buf_ref = tmp;
206
207 10 buf_ref = av_buffer_alloc(size + 1);
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!buf_ref)
209 return AVERROR(ENOMEM);
210
211
2/2
✓ Branch 0 taken 12085 times.
✓ Branch 1 taken 10 times.
12095 for (int i = 0; i < size; i++)
212 12085 buf_ref->data[i] = get_bits(gb, 8);
213 10 buf_ref->data[size] = 0;
214 10 buf_ref->size = size;
215 10 s->buf_ref[s->nb_buf_ref++] = buf_ref;
216
217 10 return 0;
218 }
219
220 3 static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s,
221 GetBitContext *gb, int size)
222 {
223 size_t meta_size;
224 int err;
225 3 AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size);
226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!metadata)
227 return AVERROR(ENOMEM);
228
229 3 err = ff_parse_itu_t_t35_to_dynamic_hdr10_plus(metadata,
230 3 gb->buffer + get_bits_count(gb) / 8, size);
231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (err < 0) {
232 av_free(metadata);
233 return err;
234 }
235
236 3 av_buffer_unref(&s->info);
237 3 s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!s->info) {
239 av_free(metadata);
240 return AVERROR(ENOMEM);
241 }
242
243 3 skip_bits_long(gb, size * 8);
244
245 3 return 0;
246 }
247
248 67 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
249 void *logctx, int size)
250 {
251 int country_code, provider_code;
252
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (size < 3)
254 return AVERROR_INVALIDDATA;
255 67 size -= 3;
256
257 67 country_code = get_bits(gb, 8);
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (country_code == 0xFF) {
259 if (size < 1)
260 return AVERROR_INVALIDDATA;
261
262 skip_bits(gb, 8);
263 size--;
264 }
265
266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (country_code != 0xB5) { // usa_country_code
267 av_log(logctx, AV_LOG_VERBOSE,
268 "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)\n",
269 country_code);
270 goto end;
271 }
272
273 67 provider_code = get_bits(gb, 16);
274
275
2/3
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
67 switch (provider_code) {
276 3 case 0x3C: { // smpte_provider_code
277 // A/341 Amendment - 2094-40
278 3 const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
279 3 const uint8_t smpte2094_40_application_identifier = 0x04;
280 uint16_t provider_oriented_code;
281 uint8_t application_identifier;
282
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (size < 3)
284 return AVERROR_INVALIDDATA;
285 3 size -= 3;
286
287 3 provider_oriented_code = get_bits(gb, 16);
288 3 application_identifier = get_bits(gb, 8);
289
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
290 application_identifier == smpte2094_40_application_identifier) {
291 3 return decode_registered_user_data_dynamic_hdr_plus(&s->dynamic_hdr_plus, gb, size);
292 }
293 break;
294 }
295 64 case 0x31: { // atsc_provider_code
296 uint32_t user_identifier;
297
298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (size < 4)
299 return AVERROR_INVALIDDATA;
300 64 size -= 4;
301
302 64 user_identifier = get_bits_long(gb, 32);
303 switch (user_identifier) {
304 case MKBETAG('G', 'A', '9', '4'):
305 return decode_registered_user_data_closed_caption(&s->a53_caption, gb, size);
306 64 default:
307 64 av_log(logctx, AV_LOG_VERBOSE,
308 "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n",
309 user_identifier);
310 64 break;
311 }
312 64 break;
313 }
314 default:
315 av_log(logctx, AV_LOG_VERBOSE,
316 "Unsupported User Data Registered ITU-T T35 SEI message (provider_code = %d)\n",
317 provider_code);
318 break;
319 }
320
321 64 end:
322 64 skip_bits_long(gb, size * 8);
323 64 return 0;
324 }
325
326 30 static int decode_nal_sei_active_parameter_sets(HEVCSEI *s, GetBitContext *gb, void *logctx)
327 {
328 int num_sps_ids_minus1;
329 int i;
330 unsigned active_seq_parameter_set_id;
331
332 30 get_bits(gb, 4); // active_video_parameter_set_id
333 30 get_bits(gb, 1); // self_contained_cvs_flag
334 30 get_bits(gb, 1); // num_sps_ids_minus1
335 30 num_sps_ids_minus1 = get_ue_golomb_long(gb); // num_sps_ids_minus1
336
337
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (num_sps_ids_minus1 < 0 || num_sps_ids_minus1 > 15) {
338 av_log(logctx, AV_LOG_ERROR, "num_sps_ids_minus1 %d invalid\n", num_sps_ids_minus1);
339 return AVERROR_INVALIDDATA;
340 }
341
342 30 active_seq_parameter_set_id = get_ue_golomb_long(gb);
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (active_seq_parameter_set_id >= HEVC_MAX_SPS_COUNT) {
344 av_log(logctx, AV_LOG_ERROR, "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
345 return AVERROR_INVALIDDATA;
346 }
347 30 s->active_seq_parameter_set_id = active_seq_parameter_set_id;
348
349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 for (i = 1; i <= num_sps_ids_minus1; i++)
350 get_ue_golomb_long(gb); // active_seq_parameter_set_id[i]
351
352 30 return 0;
353 }
354
355 static int decode_nal_sei_alternative_transfer(HEVCSEIAlternativeTransfer *s, GetBitContext *gb, int size)
356 {
357 if (size < 1)
358 return AVERROR_INVALIDDATA;
359
360 s->present = 1;
361 s->preferred_transfer_characteristics = get_bits(gb, 8);
362 size--;
363
364 skip_bits_long(gb, 8 * size);
365 return 0;
366 }
367
368 64 static int decode_nal_sei_timecode(HEVCSEITimeCode *s, GetBitContext *gb)
369 {
370 64 s->num_clock_ts = get_bits(gb, 2);
371
372
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 64 times.
128 for (int i = 0; i < s->num_clock_ts; i++) {
373 64 s->clock_timestamp_flag[i] = get_bits(gb, 1);
374
375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (s->clock_timestamp_flag[i]) {
376 s->units_field_based_flag[i] = get_bits(gb, 1);
377 s->counting_type[i] = get_bits(gb, 5);
378 s->full_timestamp_flag[i] = get_bits(gb, 1);
379 s->discontinuity_flag[i] = get_bits(gb, 1);
380 s->cnt_dropped_flag[i] = get_bits(gb, 1);
381
382 s->n_frames[i] = get_bits(gb, 9);
383
384 if (s->full_timestamp_flag[i]) {
385 s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59);
386 s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59);
387 s->hours_value[i] = av_clip(get_bits(gb, 5), 0, 23);
388 } else {
389 s->seconds_flag[i] = get_bits(gb, 1);
390 if (s->seconds_flag[i]) {
391 s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59);
392 s->minutes_flag[i] = get_bits(gb, 1);
393 if (s->minutes_flag[i]) {
394 s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59);
395 s->hours_flag[i] = get_bits(gb, 1);
396 if (s->hours_flag[i]) {
397 s->hours_value[i] = av_clip(get_bits(gb, 5), 0, 23);
398 }
399 }
400 }
401 }
402
403 s->time_offset_length[i] = get_bits(gb, 5);
404 if (s->time_offset_length[i] > 0) {
405 s->time_offset_value[i] = get_bits_long(gb, s->time_offset_length[i]);
406 }
407 }
408 }
409
410 64 s->present = 1;
411 64 return 0;
412 }
413
414 static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
415 GetBitContext *gb)
416 {
417 h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
418
419 if (h->present) {
420 memset(h, 0, sizeof(*h));
421 h->model_id = get_bits(gb, 2);
422 h->separate_colour_description_present_flag = get_bits1(gb);
423 if (h->separate_colour_description_present_flag) {
424 h->bit_depth_luma = get_bits(gb, 3) + 8;
425 h->bit_depth_chroma = get_bits(gb, 3) + 8;
426 h->full_range = get_bits1(gb);
427 h->color_primaries = get_bits(gb, 8);
428 h->transfer_characteristics = get_bits(gb, 8);
429 h->matrix_coeffs = get_bits(gb, 8);
430 }
431 h->blending_mode_id = get_bits(gb, 2);
432 h->log2_scale_factor = get_bits(gb, 4);
433 for (int c = 0; c < 3; c++)
434 h->comp_model_present_flag[c] = get_bits1(gb);
435 for (int c = 0; c < 3; c++) {
436 if (h->comp_model_present_flag[c]) {
437 h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
438 h->num_model_values[c] = get_bits(gb, 3) + 1;
439 if (h->num_model_values[c] > 6)
440 return AVERROR_INVALIDDATA;
441 for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
442 h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
443 h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
444 for (int j = 0; j < h->num_model_values[c]; j++)
445 h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
446 }
447 }
448 }
449 h->persistence_flag = get_bits1(gb);
450
451 h->present = 1;
452 }
453
454 return 0;
455 }
456
457 1477 static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
458 const HEVCParamSets *ps, int type, int size)
459 {
460
8/13
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1204 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 30 times.
✓ Branch 7 taken 67 times.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 64 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 96 times.
1477 switch (type) {
461 case 256: // Mismatched value from HM 8.1
462 return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gb);
463 case SEI_TYPE_FRAME_PACKING_ARRANGEMENT:
464 return decode_nal_sei_frame_packing_arrangement(&s->frame_packing, gb);
465 case SEI_TYPE_DISPLAY_ORIENTATION:
466 return decode_nal_sei_display_orientation(&s->display_orientation, gb);
467 1204 case SEI_TYPE_PIC_TIMING:
468 1204 return decode_nal_sei_pic_timing(s, gb, ps, logctx, size);
469 3 case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
470 3 return decode_nal_sei_mastering_display_info(&s->mastering_display, gb, size);
471 3 case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
472 3 return decode_nal_sei_content_light_info(&s->content_light, gb, size);
473 30 case SEI_TYPE_ACTIVE_PARAMETER_SETS:
474 30 return decode_nal_sei_active_parameter_sets(s, gb, logctx);
475 67 case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
476 67 return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, logctx, size);
477 10 case SEI_TYPE_USER_DATA_UNREGISTERED:
478 10 return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, size);
479 case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
480 return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb, size);
481 64 case SEI_TYPE_TIME_CODE:
482 64 return decode_nal_sei_timecode(&s->timecode, gb);
483 case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
484 return decode_film_grain_characteristics(&s->film_grain_characteristics, gb);
485 96 default:
486 96 av_log(logctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
487 96 skip_bits_long(gb, 8 * size);
488 96 return 0;
489 }
490 }
491
492 6848 static int decode_nal_sei_suffix(GetBitContext *gb, void *logctx, HEVCSEI *s,
493 int type, int size)
494 {
495
1/2
✓ Branch 0 taken 6848 times.
✗ Branch 1 not taken.
6848 switch (type) {
496 6848 case SEI_TYPE_DECODED_PICTURE_HASH:
497 6848 return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gb);
498 default:
499 av_log(logctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", type);
500 skip_bits_long(gb, 8 * size);
501 return 0;
502 }
503 }
504
505 8389 static int decode_nal_sei_message(GetBitContext *gb, void *logctx, HEVCSEI *s,
506 const HEVCParamSets *ps, int nal_unit_type)
507 {
508 8389 int payload_type = 0;
509 8389 int payload_size = 0;
510 8389 int byte = 0xFF;
511 8389 av_log(logctx, AV_LOG_DEBUG, "Decoding SEI\n");
512
513
2/2
✓ Branch 0 taken 8389 times.
✓ Branch 1 taken 8325 times.
16714 while (byte == 0xFF) {
514
3/4
✓ Branch 1 taken 8325 times.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8325 times.
8389 if (get_bits_left(gb) < 16 || payload_type > INT_MAX - 255)
515 64 return AVERROR_INVALIDDATA;
516 8325 byte = get_bits(gb, 8);
517 8325 payload_type += byte;
518 }
519 8325 byte = 0xFF;
520
2/2
✓ Branch 0 taken 8368 times.
✓ Branch 1 taken 8325 times.
16693 while (byte == 0xFF) {
521
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8368 times.
8368 if (get_bits_left(gb) < 8 + 8LL*payload_size)
522 return AVERROR_INVALIDDATA;
523 8368 byte = get_bits(gb, 8);
524 8368 payload_size += byte;
525 }
526
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8325 times.
8325 if (get_bits_left(gb) < 8LL*payload_size)
527 return AVERROR_INVALIDDATA;
528
2/2
✓ Branch 0 taken 1477 times.
✓ Branch 1 taken 6848 times.
8325 if (nal_unit_type == HEVC_NAL_SEI_PREFIX) {
529 1477 return decode_nal_sei_prefix(gb, logctx, s, ps, payload_type, payload_size);
530 } else { /* nal_unit_type == NAL_SEI_SUFFIX */
531 6848 return decode_nal_sei_suffix(gb, logctx, s, payload_type, payload_size);
532 }
533 }
534
535 8281 static int more_rbsp_data(GetBitContext *gb)
536 {
537
3/4
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 8208 times.
✓ Branch 4 taken 73 times.
✗ Branch 5 not taken.
8281 return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
538 }
539
540 8389 int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s,
541 const HEVCParamSets *ps, int type)
542 {
543 int ret;
544
545 do {
546 8389 ret = decode_nal_sei_message(gb, logctx, s, ps, type);
547
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 8281 times.
8389 if (ret < 0)
548 108 return ret;
549
2/2
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 8208 times.
8281 } while (more_rbsp_data(gb));
550 8208 return 1;
551 }
552
553 12447 void ff_hevc_reset_sei(HEVCSEI *s)
554 {
555 12447 av_buffer_unref(&s->a53_caption.buf_ref);
556
557
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12447 times.
12450 for (int i = 0; i < s->unregistered.nb_buf_ref; i++)
558 3 av_buffer_unref(&s->unregistered.buf_ref[i]);
559 12447 s->unregistered.nb_buf_ref = 0;
560 12447 av_freep(&s->unregistered.buf_ref);
561 12447 av_buffer_unref(&s->dynamic_hdr_plus.info);
562 12447 }
563