FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/hevc_sei.c
Date: 2021-09-23 20:34:37
Exec Total Coverage
Lines: 184 327 56.3%
Branches: 81 162 50.0%

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 if (size < 3)
185 return AVERROR_INVALIDDATA;
186
187 ret = ff_parse_a53_cc(&s->buf_ref, gb->buffer + get_bits_count(gb) / 8, size);
188
189 if (ret < 0)
190 return ret;
191
192 skip_bits_long(gb, size * 8);
193
194 return 0;
195 }
196
197 9 static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitContext *gb,
198 int size)
199 {
200 AVBufferRef *buf_ref, **tmp;
201
202
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (size < 16 || size >= INT_MAX - 1)
203 return AVERROR_INVALIDDATA;
204
205 9 tmp = av_realloc_array(s->buf_ref, s->nb_buf_ref + 1, sizeof(*s->buf_ref));
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!tmp)
207 return AVERROR(ENOMEM);
208 9 s->buf_ref = tmp;
209
210 9 buf_ref = av_buffer_alloc(size + 1);
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (!buf_ref)
212 return AVERROR(ENOMEM);
213
214
2/2
✓ Branch 0 taken 12050 times.
✓ Branch 1 taken 9 times.
12059 for (int i = 0; i < size; i++)
215 12050 buf_ref->data[i] = get_bits(gb, 8);
216 9 buf_ref->data[size] = 0;
217 9 buf_ref->size = size;
218 9 s->buf_ref[s->nb_buf_ref++] = buf_ref;
219
220 9 return 0;
221 }
222
223 3 static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s,
224 GetBitContext *gb, int size)
225 {
226 size_t meta_size;
227 int err;
228 3 AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size);
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!metadata)
230 return AVERROR(ENOMEM);
231
232 3 err = ff_parse_itu_t_t35_to_dynamic_hdr10_plus(metadata,
233 3 gb->buffer + get_bits_count(gb) / 8, size);
234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (err < 0) {
235 av_free(metadata);
236 return err;
237 }
238
239 3 av_buffer_unref(&s->info);
240 3 s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!s->info) {
242 av_free(metadata);
243 return AVERROR(ENOMEM);
244 }
245
246 3 skip_bits_long(gb, size * 8);
247
248 3 return 0;
249 }
250
251 67 static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb,
252 void *logctx, int size)
253 {
254 int country_code, provider_code;
255
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (size < 3)
257 return AVERROR_INVALIDDATA;
258 67 size -= 3;
259
260 67 country_code = get_bits(gb, 8);
261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (country_code == 0xFF) {
262 if (size < 1)
263 return AVERROR_INVALIDDATA;
264
265 skip_bits(gb, 8);
266 size--;
267 }
268
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (country_code != 0xB5) { // usa_country_code
270 av_log(logctx, AV_LOG_VERBOSE,
271 "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)\n",
272 country_code);
273 goto end;
274 }
275
276 67 provider_code = get_bits(gb, 16);
277
278
2/3
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
67 switch (provider_code) {
279 3 case 0x3C: { // smpte_provider_code
280 // A/341 Amendment - 2094-40
281 3 const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
282 3 const uint8_t smpte2094_40_application_identifier = 0x04;
283 uint16_t provider_oriented_code;
284 uint8_t application_identifier;
285
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (size < 3)
287 return AVERROR_INVALIDDATA;
288 3 size -= 3;
289
290 3 provider_oriented_code = get_bits(gb, 16);
291 3 application_identifier = get_bits(gb, 8);
292
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 &&
293 application_identifier == smpte2094_40_application_identifier) {
294 3 return decode_registered_user_data_dynamic_hdr_plus(&s->dynamic_hdr_plus, gb, size);
295 }
296 break;
297 }
298 64 case 0x31: { // atsc_provider_code
299 uint32_t user_identifier;
300
301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (size < 4)
302 return AVERROR_INVALIDDATA;
303 64 size -= 4;
304
305 64 user_identifier = get_bits_long(gb, 32);
306 switch (user_identifier) {
307 case MKBETAG('G', 'A', '9', '4'):
308 return decode_registered_user_data_closed_caption(&s->a53_caption, gb, size);
309 64 default:
310 64 av_log(logctx, AV_LOG_VERBOSE,
311 "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n",
312 user_identifier);
313 64 break;
314 }
315 64 break;
316 }
317 default:
318 av_log(logctx, AV_LOG_VERBOSE,
319 "Unsupported User Data Registered ITU-T T35 SEI message (provider_code = %d)\n",
320 provider_code);
321 break;
322 }
323
324 64 end:
325 64 skip_bits_long(gb, size * 8);
326 64 return 0;
327 }
328
329 30 static int decode_nal_sei_active_parameter_sets(HEVCSEI *s, GetBitContext *gb, void *logctx)
330 {
331 int num_sps_ids_minus1;
332 int i;
333 unsigned active_seq_parameter_set_id;
334
335 30 get_bits(gb, 4); // active_video_parameter_set_id
336 30 get_bits(gb, 1); // self_contained_cvs_flag
337 30 get_bits(gb, 1); // num_sps_ids_minus1
338 30 num_sps_ids_minus1 = get_ue_golomb_long(gb); // num_sps_ids_minus1
339
340
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) {
341 av_log(logctx, AV_LOG_ERROR, "num_sps_ids_minus1 %d invalid\n", num_sps_ids_minus1);
342 return AVERROR_INVALIDDATA;
343 }
344
345 30 active_seq_parameter_set_id = get_ue_golomb_long(gb);
346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (active_seq_parameter_set_id >= HEVC_MAX_SPS_COUNT) {
347 av_log(logctx, AV_LOG_ERROR, "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
348 return AVERROR_INVALIDDATA;
349 }
350 30 s->active_seq_parameter_set_id = active_seq_parameter_set_id;
351
352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 for (i = 1; i <= num_sps_ids_minus1; i++)
353 get_ue_golomb_long(gb); // active_seq_parameter_set_id[i]
354
355 30 return 0;
356 }
357
358 static int decode_nal_sei_alternative_transfer(HEVCSEIAlternativeTransfer *s, GetBitContext *gb, int size)
359 {
360 if (size < 1)
361 return AVERROR_INVALIDDATA;
362
363 s->present = 1;
364 s->preferred_transfer_characteristics = get_bits(gb, 8);
365 size--;
366
367 skip_bits_long(gb, 8 * size);
368 return 0;
369 }
370
371 64 static int decode_nal_sei_timecode(HEVCSEITimeCode *s, GetBitContext *gb)
372 {
373 64 s->num_clock_ts = get_bits(gb, 2);
374
375
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 64 times.
128 for (int i = 0; i < s->num_clock_ts; i++) {
376 64 s->clock_timestamp_flag[i] = get_bits(gb, 1);
377
378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (s->clock_timestamp_flag[i]) {
379 s->units_field_based_flag[i] = get_bits(gb, 1);
380 s->counting_type[i] = get_bits(gb, 5);
381 s->full_timestamp_flag[i] = get_bits(gb, 1);
382 s->discontinuity_flag[i] = get_bits(gb, 1);
383 s->cnt_dropped_flag[i] = get_bits(gb, 1);
384
385 s->n_frames[i] = get_bits(gb, 9);
386
387 if (s->full_timestamp_flag[i]) {
388 s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59);
389 s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59);
390 s->hours_value[i] = av_clip(get_bits(gb, 5), 0, 23);
391 } else {
392 s->seconds_flag[i] = get_bits(gb, 1);
393 if (s->seconds_flag[i]) {
394 s->seconds_value[i] = av_clip(get_bits(gb, 6), 0, 59);
395 s->minutes_flag[i] = get_bits(gb, 1);
396 if (s->minutes_flag[i]) {
397 s->minutes_value[i] = av_clip(get_bits(gb, 6), 0, 59);
398 s->hours_flag[i] = get_bits(gb, 1);
399 if (s->hours_flag[i]) {
400 s->hours_value[i] = av_clip(get_bits(gb, 5), 0, 23);
401 }
402 }
403 }
404 }
405
406 s->time_offset_length[i] = get_bits(gb, 5);
407 if (s->time_offset_length[i] > 0) {
408 s->time_offset_value[i] = get_bits_long(gb, s->time_offset_length[i]);
409 }
410 }
411 }
412
413 64 s->present = 1;
414 64 return 0;
415 }
416
417 static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
418 GetBitContext *gb)
419 {
420 h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
421
422 if (h->present) {
423 memset(h, 0, sizeof(*h));
424 h->model_id = get_bits(gb, 2);
425 h->separate_colour_description_present_flag = get_bits1(gb);
426 if (h->separate_colour_description_present_flag) {
427 h->bit_depth_luma = get_bits(gb, 3) + 8;
428 h->bit_depth_chroma = get_bits(gb, 3) + 8;
429 h->full_range = get_bits1(gb);
430 h->color_primaries = get_bits(gb, 8);
431 h->transfer_characteristics = get_bits(gb, 8);
432 h->matrix_coeffs = get_bits(gb, 8);
433 }
434 h->blending_mode_id = get_bits(gb, 2);
435 h->log2_scale_factor = get_bits(gb, 4);
436 for (int c = 0; c < 3; c++)
437 h->comp_model_present_flag[c] = get_bits1(gb);
438 for (int c = 0; c < 3; c++) {
439 if (h->comp_model_present_flag[c]) {
440 h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
441 h->num_model_values[c] = get_bits(gb, 3) + 1;
442 if (h->num_model_values[c] > 6)
443 return AVERROR_INVALIDDATA;
444 for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
445 h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
446 h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
447 for (int j = 0; j < h->num_model_values[c]; j++)
448 h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
449 }
450 }
451 }
452 h->persistence_flag = get_bits1(gb);
453
454 h->present = 1;
455 }
456
457 return 0;
458 }
459
460 1470 static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
461 const HEVCParamSets *ps, int type, int size)
462 {
463
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 9 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 64 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 90 times.
1470 switch (type) {
464 case 256: // Mismatched value from HM 8.1
465 return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gb);
466 case SEI_TYPE_FRAME_PACKING_ARRANGEMENT:
467 return decode_nal_sei_frame_packing_arrangement(&s->frame_packing, gb);
468 case SEI_TYPE_DISPLAY_ORIENTATION:
469 return decode_nal_sei_display_orientation(&s->display_orientation, gb);
470 1204 case SEI_TYPE_PIC_TIMING:
471 1204 return decode_nal_sei_pic_timing(s, gb, ps, logctx, size);
472 3 case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME:
473 3 return decode_nal_sei_mastering_display_info(&s->mastering_display, gb, size);
474 3 case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
475 3 return decode_nal_sei_content_light_info(&s->content_light, gb, size);
476 30 case SEI_TYPE_ACTIVE_PARAMETER_SETS:
477 30 return decode_nal_sei_active_parameter_sets(s, gb, logctx);
478 67 case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
479 67 return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, logctx, size);
480 9 case SEI_TYPE_USER_DATA_UNREGISTERED:
481 9 return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, size);
482 case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
483 return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb, size);
484 64 case SEI_TYPE_TIME_CODE:
485 64 return decode_nal_sei_timecode(&s->timecode, gb);
486 case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
487 return decode_film_grain_characteristics(&s->film_grain_characteristics, gb);
488 90 default:
489 90 av_log(logctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
490 90 skip_bits_long(gb, 8 * size);
491 90 return 0;
492 }
493 }
494
495 6848 static int decode_nal_sei_suffix(GetBitContext *gb, void *logctx, HEVCSEI *s,
496 int type, int size)
497 {
498
1/2
✓ Branch 0 taken 6848 times.
✗ Branch 1 not taken.
6848 switch (type) {
499 6848 case SEI_TYPE_DECODED_PICTURE_HASH:
500 6848 return decode_nal_sei_decoded_picture_hash(&s->picture_hash, gb);
501 default:
502 av_log(logctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", type);
503 skip_bits_long(gb, 8 * size);
504 return 0;
505 }
506 }
507
508 8382 static int decode_nal_sei_message(GetBitContext *gb, void *logctx, HEVCSEI *s,
509 const HEVCParamSets *ps, int nal_unit_type)
510 {
511 8382 int payload_type = 0;
512 8382 int payload_size = 0;
513 8382 int byte = 0xFF;
514 8382 av_log(logctx, AV_LOG_DEBUG, "Decoding SEI\n");
515
516
2/2
✓ Branch 0 taken 8382 times.
✓ Branch 1 taken 8318 times.
16700 while (byte == 0xFF) {
517
3/4
✓ Branch 1 taken 8318 times.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8318 times.
8382 if (get_bits_left(gb) < 16 || payload_type > INT_MAX - 255)
518 64 return AVERROR_INVALIDDATA;
519 8318 byte = get_bits(gb, 8);
520 8318 payload_type += byte;
521 }
522 8318 byte = 0xFF;
523
2/2
✓ Branch 0 taken 8361 times.
✓ Branch 1 taken 8318 times.
16679 while (byte == 0xFF) {
524
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8361 times.
8361 if (get_bits_left(gb) < 8 + 8LL*payload_size)
525 return AVERROR_INVALIDDATA;
526 8361 byte = get_bits(gb, 8);
527 8361 payload_size += byte;
528 }
529
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8318 times.
8318 if (get_bits_left(gb) < 8LL*payload_size)
530 return AVERROR_INVALIDDATA;
531
2/2
✓ Branch 0 taken 1470 times.
✓ Branch 1 taken 6848 times.
8318 if (nal_unit_type == HEVC_NAL_SEI_PREFIX) {
532 1470 return decode_nal_sei_prefix(gb, logctx, s, ps, payload_type, payload_size);
533 } else { /* nal_unit_type == NAL_SEI_SUFFIX */
534 6848 return decode_nal_sei_suffix(gb, logctx, s, payload_type, payload_size);
535 }
536 }
537
538 8274 static int more_rbsp_data(GetBitContext *gb)
539 {
540
3/4
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 8201 times.
✓ Branch 4 taken 73 times.
✗ Branch 5 not taken.
8274 return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
541 }
542
543 8382 int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s,
544 const HEVCParamSets *ps, int type)
545 {
546 int ret;
547
548 do {
549 8382 ret = decode_nal_sei_message(gb, logctx, s, ps, type);
550
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 8274 times.
8382 if (ret < 0)
551 108 return ret;
552
2/2
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 8201 times.
8274 } while (more_rbsp_data(gb));
553 8201 return 1;
554 }
555
556 12409 void ff_hevc_reset_sei(HEVCSEI *s)
557 {
558 12409 av_buffer_unref(&s->a53_caption.buf_ref);
559
560
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12409 times.
12412 for (int i = 0; i < s->unregistered.nb_buf_ref; i++)
561 3 av_buffer_unref(&s->unregistered.buf_ref[i]);
562 12409 s->unregistered.nb_buf_ref = 0;
563 12409 av_freep(&s->unregistered.buf_ref);
564 12409 av_buffer_unref(&s->dynamic_hdr_plus.info);
565 12409 }
566