FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h2645_sei.c
Date: 2023-01-27 00:32:08
Exec Total Coverage
Lines: 160 368 43.5%
Functions: 12 16 75.0%
Branches: 74 208 35.6%

Line Branch Exec Source
1 /*
2 * Common H.264 and HEVC Supplementary Enhancement Information messages
3 *
4 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5 * Copyright (C) 2012 - 2013 Guillaume Martres
6 * Copyright (C) 2012 - 2013 Gildas Cocherel
7 * Copyright (C) 2013 Vittorio Giovara
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include "config_components.h"
27
28 #include "libavutil/ambient_viewing_environment.h"
29 #include "libavutil/display.h"
30 #include "libavutil/film_grain_params.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/stereo3d.h"
33
34 #include "atsc_a53.h"
35 #include "avcodec.h"
36 #include "dynamic_hdr10_plus.h"
37 #include "dynamic_hdr_vivid.h"
38 #include "get_bits.h"
39 #include "golomb.h"
40 #include "h2645_sei.h"
41
42 #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
43 #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
44
45 #if CONFIG_HEVC_SEI
46 3 static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s,
47 GetByteContext *gb)
48 {
49 size_t meta_size;
50 int err;
51 3 AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size);
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!metadata)
53 return AVERROR(ENOMEM);
54
55 3 err = ff_parse_itu_t_t35_to_dynamic_hdr10_plus(metadata, gb->buffer,
56 bytestream2_get_bytes_left(gb));
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (err < 0) {
58 av_free(metadata);
59 return err;
60 }
61
62 3 av_buffer_unref(&s->info);
63 3 s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!s->info) {
65 av_free(metadata);
66 return AVERROR(ENOMEM);
67 }
68
69 3 return 0;
70 }
71
72 3 static int decode_registered_user_data_dynamic_hdr_vivid(HEVCSEIDynamicHDRVivid *s,
73 GetByteContext *gb)
74 {
75 size_t meta_size;
76 int err;
77 3 AVDynamicHDRVivid *metadata = av_dynamic_hdr_vivid_alloc(&meta_size);
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!metadata)
79 return AVERROR(ENOMEM);
80
81 3 err = ff_parse_itu_t_t35_to_dynamic_hdr_vivid(metadata,
82 gb->buffer, bytestream2_get_bytes_left(gb));
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (err < 0) {
84 av_free(metadata);
85 return err;
86 }
87
88 3 av_buffer_unref(&s->info);
89 3 s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!s->info) {
91 av_free(metadata);
92 return AVERROR(ENOMEM);
93 }
94
95 3 return 0;
96 }
97 #endif
98
99 1169 static int decode_registered_user_data_afd(H2645SEIAFD *h, GetByteContext *gb)
100 {
101 int flag;
102
103
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1169 times.
1169 if (bytestream2_get_bytes_left(gb) <= 0)
104 return AVERROR_INVALIDDATA;
105
106 1169 flag = !!(bytestream2_get_byteu(gb) & 0x40); // active_format_flag
107
108
1/2
✓ Branch 0 taken 1169 times.
✗ Branch 1 not taken.
1169 if (flag) {
109
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1169 times.
1169 if (bytestream2_get_bytes_left(gb) <= 0)
110 return AVERROR_INVALIDDATA;
111 1169 h->active_format_description = bytestream2_get_byteu(gb) & 0xF;
112 1169 h->present = 1;
113 }
114
115 1169 return 0;
116 }
117
118 6 static int decode_registered_user_data_closed_caption(H2645SEIA53Caption *h,
119 GetByteContext *gb)
120 {
121 6 return ff_parse_a53_cc(&h->buf_ref, gb->buffer,
122 bytestream2_get_bytes_left(gb));
123 }
124
125 1181 static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb,
126 enum AVCodecID codec_id, void *logctx)
127 {
128 int country_code, provider_code;
129
130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1181 times.
1181 if (bytestream2_get_bytes_left(gb) < 3)
131 return AVERROR_INVALIDDATA;
132
133 1181 country_code = bytestream2_get_byteu(gb); // itu_t_t35_country_code
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1181 times.
1181 if (country_code == 0xFF) {
135 if (bytestream2_get_bytes_left(gb) < 3)
136 return AVERROR_INVALIDDATA;
137
138 bytestream2_skipu(gb, 1); // itu_t_t35_country_code_extension_byte
139 }
140
141
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1178 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
1181 if (country_code != 0xB5 && country_code != 0x26) { // usa_country_code and cn_country_code
142 av_log(logctx, AV_LOG_VERBOSE,
143 "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)\n",
144 country_code);
145 return 0;
146 }
147
148 /* itu_t_t35_payload_byte follows */
149 1181 provider_code = bytestream2_get_be16u(gb);
150
151
3/4
✓ Branch 0 taken 1175 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
1181 switch (provider_code) {
152 1175 case 0x31: { // atsc_provider_code
153 uint32_t user_identifier;
154
155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1175 times.
1175 if (bytestream2_get_bytes_left(gb) < 4)
156 return AVERROR_INVALIDDATA;
157
158 1175 user_identifier = bytestream2_get_be32u(gb);
159 switch (user_identifier) {
160 1169 case MKBETAG('D', 'T', 'G', '1'): // afd_data
161 1169 return decode_registered_user_data_afd(&h->afd, gb);
162 6 case MKBETAG('G', 'A', '9', '4'): // closed captions
163 6 return decode_registered_user_data_closed_caption(&h->a53_caption, gb);
164 default:
165 av_log(logctx, AV_LOG_VERBOSE,
166 "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n",
167 user_identifier);
168 break;
169 }
170 break;
171 }
172 #if CONFIG_HEVC_SEI
173 3 case 0x04: { // cuva_provider_code
174 3 const uint16_t cuva_provider_oriented_code = 0x0005;
175 uint16_t provider_oriented_code;
176
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!IS_HEVC(codec_id))
178 goto unsupported_provider_code;
179
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (bytestream2_get_bytes_left(gb) < 2)
181 return AVERROR_INVALIDDATA;
182
183 3 provider_oriented_code = bytestream2_get_be16u(gb);
184
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (provider_oriented_code == cuva_provider_oriented_code) {
185 3 return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb);
186 }
187 break;
188 }
189 3 case 0x3C: { // smpte_provider_code
190 // A/341 Amendment - 2094-40
191 3 const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
192 3 const uint8_t smpte2094_40_application_identifier = 0x04;
193 uint16_t provider_oriented_code;
194 uint8_t application_identifier;
195
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!IS_HEVC(codec_id))
197 goto unsupported_provider_code;
198
199
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (bytestream2_get_bytes_left(gb) < 3)
200 return AVERROR_INVALIDDATA;
201
202 3 provider_oriented_code = bytestream2_get_be16u(gb);
203 3 application_identifier = bytestream2_get_byteu(gb);
204
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 &&
205 application_identifier == smpte2094_40_application_identifier) {
206 3 return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb);
207 }
208 break;
209 }
210 unsupported_provider_code:
211 #endif
212 default:
213 av_log(logctx, AV_LOG_VERBOSE,
214 "Unsupported User Data Registered ITU-T T35 SEI message (provider_code = %d)\n",
215 provider_code);
216 break;
217 }
218
219 return 0;
220 }
221
222 423 static int decode_unregistered_user_data(H2645SEIUnregistered *h,
223 GetByteContext *gb,
224 enum AVCodecID codec_id)
225 {
226 uint8_t *user_data;
227 423 int size = bytestream2_get_bytes_left(gb);
228 AVBufferRef *buf_ref, **tmp;
229
230
2/4
✓ Branch 0 taken 423 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 423 times.
423 if (size < 16 || size >= INT_MAX - 1)
231 return AVERROR_INVALIDDATA;
232
233 423 tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref));
234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 423 times.
423 if (!tmp)
235 return AVERROR(ENOMEM);
236 423 h->buf_ref = tmp;
237
238 423 buf_ref = av_buffer_alloc(size + 1);
239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 423 times.
423 if (!buf_ref)
240 return AVERROR(ENOMEM);
241 423 user_data = buf_ref->data;
242
243 423 bytestream2_get_bufferu(gb, user_data, size);
244 423 user_data[size] = 0;
245 423 buf_ref->size = size;
246 423 h->buf_ref[h->nb_buf_ref++] = buf_ref;
247
248
2/2
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 13 times.
423 if (IS_H264(codec_id)) {
249 int e, build;
250 410 e = sscanf(user_data + 16, "x264 - core %d", &build);
251
4/4
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 293 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 3 times.
410 if (e == 1 && build > 0)
252 114 h->x264_build = build;
253
3/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 293 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
410 if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
254 h->x264_build = 67;
255 }
256
257 423 return 0;
258 }
259
260 2 static int decode_display_orientation(H2645SEIDisplayOrientation *h,
261 GetBitContext *gb)
262 {
263 2 h->present = !get_bits1(gb); // display_orientation_cancel_flag
264
265
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (h->present) {
266 2 h->hflip = get_bits1(gb); // hor_flip
267 2 h->vflip = get_bits1(gb); // ver_flip
268
269 2 h->anticlockwise_rotation = get_bits(gb, 16);
270 // This is followed by display_orientation_repetition_period
271 // and display_orientation_extension_flag for H.264
272 // and by display_orientation_persistence_flag for HEVC.
273 }
274
275 2 return 0;
276 }
277
278 static int decode_frame_packing_arrangement(H2645SEIFramePacking *h,
279 GetBitContext *gb,
280 enum AVCodecID codec_id)
281 {
282 h->arrangement_id = get_ue_golomb_long(gb);
283 h->arrangement_cancel_flag = get_bits1(gb);
284 h->present = !h->arrangement_cancel_flag;
285
286 if (h->present) {
287 h->arrangement_type = get_bits(gb, 7);
288 h->quincunx_sampling_flag = get_bits1(gb);
289 h->content_interpretation_type = get_bits(gb, 6);
290
291 // spatial_flipping_flag, frame0_flipped_flag, field_views_flag
292 skip_bits(gb, 3);
293 h->current_frame_is_frame0_flag = get_bits1(gb);
294 // frame0_self_contained_flag, frame1_self_contained_flag
295 skip_bits(gb, 2);
296
297 if (!h->quincunx_sampling_flag && h->arrangement_type != 5)
298 skip_bits(gb, 16); // frame[01]_grid_position_[xy]
299 skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
300 if (IS_H264(codec_id))
301 h->arrangement_repetition_period = get_ue_golomb_long(gb);
302 else
303 skip_bits1(gb); // frame_packing_arrangement_persistence_flag
304 }
305 // H.264: frame_packing_arrangement_extension_flag,
306 // HEVC: upsampled_aspect_ratio_flag
307 skip_bits1(gb);
308
309 return 0;
310 }
311
312 static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s,
313 GetByteContext *gb)
314 {
315 if (bytestream2_get_bytes_left(gb) < 1)
316 return AVERROR_INVALIDDATA;
317
318 s->present = 1;
319 s->preferred_transfer_characteristics = bytestream2_get_byteu(gb);
320
321 return 0;
322 }
323
324 6 static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s,
325 GetByteContext *gb)
326 {
327 static const uint16_t max_ambient_light_value = 50000;
328
329
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (bytestream2_get_bytes_left(gb) < 8)
330 return AVERROR_INVALIDDATA;
331
332 6 s->ambient_illuminance = bytestream2_get_be32u(gb);
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!s->ambient_illuminance)
334 return AVERROR_INVALIDDATA;
335
336 6 s->ambient_light_x = bytestream2_get_be16u(gb);
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s->ambient_light_x > max_ambient_light_value)
338 return AVERROR_INVALIDDATA;
339
340 6 s->ambient_light_y = bytestream2_get_be16u(gb);
341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s->ambient_light_y > max_ambient_light_value)
342 return AVERROR_INVALIDDATA;
343
344 6 s->present = 1;
345
346 6 return 0;
347 }
348
349 static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h,
350 enum AVCodecID codec_id, GetBitContext *gb)
351 {
352 h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
353
354 if (h->present) {
355 memset(h, 0, sizeof(*h));
356 h->model_id = get_bits(gb, 2);
357 h->separate_colour_description_present_flag = get_bits1(gb);
358 if (h->separate_colour_description_present_flag) {
359 h->bit_depth_luma = get_bits(gb, 3) + 8;
360 h->bit_depth_chroma = get_bits(gb, 3) + 8;
361 h->full_range = get_bits1(gb);
362 h->color_primaries = get_bits(gb, 8);
363 h->transfer_characteristics = get_bits(gb, 8);
364 h->matrix_coeffs = get_bits(gb, 8);
365 }
366 h->blending_mode_id = get_bits(gb, 2);
367 h->log2_scale_factor = get_bits(gb, 4);
368 for (int c = 0; c < 3; c++)
369 h->comp_model_present_flag[c] = get_bits1(gb);
370 for (int c = 0; c < 3; c++) {
371 if (h->comp_model_present_flag[c]) {
372 h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
373 h->num_model_values[c] = get_bits(gb, 3) + 1;
374 if (h->num_model_values[c] > 6)
375 return AVERROR_INVALIDDATA;
376 for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
377 h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
378 h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
379 for (int j = 0; j < h->num_model_values[c]; j++)
380 h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
381 }
382 }
383 }
384 if (IS_HEVC(codec_id))
385 h->persistence_flag = get_bits1(gb);
386 else
387 h->repetition_period = get_ue_golomb_long(gb);
388
389 h->present = 1;
390 }
391
392 return 0;
393 }
394
395 2036 int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type,
396 enum AVCodecID codec_id, GetBitContext *gb,
397 GetByteContext *gbyte, void *logctx)
398 {
399
5/8
✓ Branch 0 taken 1181 times.
✓ Branch 1 taken 423 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 424 times.
2036 switch (type) {
400 1181 case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
401 1181 return decode_registered_user_data(h, gbyte, codec_id, logctx);
402 423 case SEI_TYPE_USER_DATA_UNREGISTERED:
403 423 return decode_unregistered_user_data(&h->unregistered, gbyte, codec_id);
404 2 case SEI_TYPE_DISPLAY_ORIENTATION:
405 2 return decode_display_orientation(&h->display_orientation, gb);
406 case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
407 return decode_film_grain_characteristics(&h->film_grain_characteristics, codec_id, gb);
408 case SEI_TYPE_FRAME_PACKING_ARRANGEMENT:
409 return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id);
410 case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
411 return decode_alternative_transfer(&h->alternative_transfer, gbyte);
412 6 case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT:
413 6 return decode_ambient_viewing_environment(&h->ambient_viewing_environment,
414 gbyte);
415 424 default:
416 424 return FF_H2645_SEI_MESSAGE_UNHANDLED;
417 }
418 }
419
420 94 int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
421 {
422 94 int ret = av_buffer_replace(&dst->a53_caption.buf_ref,
423 94 src->a53_caption.buf_ref);
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if (ret < 0)
425 return ret;
426
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 for (unsigned i = 0; i < dst->unregistered.nb_buf_ref; i++)
428 av_buffer_unref(&dst->unregistered.buf_ref[i]);
429 94 dst->unregistered.nb_buf_ref = 0;
430
431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if (src->unregistered.nb_buf_ref) {
432 ret = av_reallocp_array(&dst->unregistered.buf_ref,
433 src->unregistered.nb_buf_ref,
434 sizeof(*dst->unregistered.buf_ref));
435 if (ret < 0)
436 return ret;
437
438 for (unsigned i = 0; i < src->unregistered.nb_buf_ref; i++) {
439 dst->unregistered.buf_ref[i] = av_buffer_ref(src->unregistered.buf_ref[i]);
440 if (!dst->unregistered.buf_ref[i])
441 return AVERROR(ENOMEM);
442 dst->unregistered.nb_buf_ref++;
443 }
444 }
445
446 94 return 0;
447 }
448
449 static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id)
450 {
451 if (IS_H264(codec_id))
452 return type <= SEI_FPA_H264_TYPE_2D &&
453 type >= SEI_FPA_H264_TYPE_CHECKERBOARD;
454 else
455 return type <= SEI_FPA_TYPE_INTERLEAVE_TEMPORAL &&
456 type >= SEI_FPA_TYPE_SIDE_BY_SIDE;
457 }
458
459 33000 int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
460 enum AVCodecID codec_id,
461 AVCodecContext *avctx, const H2645VUI *vui,
462 unsigned bit_depth_luma, unsigned bit_depth_chroma,
463 int seed)
464 {
465 33000 H2645SEIFramePacking *fp = &sei->frame_packing;
466
467
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 33000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
33000 if (fp->present &&
468 is_frame_packing_type_valid(fp->arrangement_type, codec_id) &&
469 fp->content_interpretation_type > 0 &&
470 fp->content_interpretation_type < 3) {
471 AVStereo3D *stereo = av_stereo3d_create_side_data(frame);
472
473 if (!stereo)
474 return AVERROR(ENOMEM);
475
476 switch (fp->arrangement_type) {
477 #if CONFIG_H264_SEI
478 case SEI_FPA_H264_TYPE_CHECKERBOARD:
479 stereo->type = AV_STEREO3D_CHECKERBOARD;
480 break;
481 case SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN:
482 stereo->type = AV_STEREO3D_COLUMNS;
483 break;
484 case SEI_FPA_H264_TYPE_INTERLEAVE_ROW:
485 stereo->type = AV_STEREO3D_LINES;
486 break;
487 #endif
488 case SEI_FPA_TYPE_SIDE_BY_SIDE:
489 if (fp->quincunx_sampling_flag)
490 stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
491 else
492 stereo->type = AV_STEREO3D_SIDEBYSIDE;
493 break;
494 case SEI_FPA_TYPE_TOP_BOTTOM:
495 stereo->type = AV_STEREO3D_TOPBOTTOM;
496 break;
497 case SEI_FPA_TYPE_INTERLEAVE_TEMPORAL:
498 stereo->type = AV_STEREO3D_FRAMESEQUENCE;
499 break;
500 #if CONFIG_H264_SEI
501 case SEI_FPA_H264_TYPE_2D:
502 stereo->type = AV_STEREO3D_2D;
503 break;
504 #endif
505 }
506
507 if (fp->content_interpretation_type == 2)
508 stereo->flags = AV_STEREO3D_FLAG_INVERT;
509
510 if (fp->arrangement_type == SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) {
511 if (fp->current_frame_is_frame0_flag)
512 stereo->view = AV_STEREO3D_VIEW_LEFT;
513 else
514 stereo->view = AV_STEREO3D_VIEW_RIGHT;
515 }
516 }
517
518
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32999 times.
33000 if (sei->display_orientation.present &&
519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 (sei->display_orientation.anticlockwise_rotation ||
520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sei->display_orientation.hflip ||
521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 sei->display_orientation.vflip)) {
522 H2645SEIDisplayOrientation *o = &sei->display_orientation;
523 double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16);
524 AVFrameSideData *rotation = av_frame_new_side_data(frame,
525 AV_FRAME_DATA_DISPLAYMATRIX,
526 sizeof(int32_t) * 9);
527 if (!rotation)
528 return AVERROR(ENOMEM);
529
530 /* av_display_rotation_set() expects the angle in the clockwise
531 * direction, hence the first minus.
532 * The below code applies the flips after the rotation, yet
533 * the H.2645 specs require flipping to be applied first.
534 * Because of R O(phi) = O(-phi) R (where R is flipping around
535 * an arbitatry axis and O(phi) is the proper rotation by phi)
536 * we can create display matrices as desired by negating
537 * the degree once for every flip applied. */
538 angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip);
539 av_display_rotation_set((int32_t *)rotation->data, angle);
540 av_display_matrix_flip((int32_t *)rotation->data,
541 o->hflip, o->vflip);
542 }
543
544
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32999 times.
33000 if (sei->a53_caption.buf_ref) {
545 1 H2645SEIA53Caption *a53 = &sei->a53_caption;
546 1 AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, a53->buf_ref);
547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!sd)
548 av_buffer_unref(&a53->buf_ref);
549 1 a53->buf_ref = NULL;
550
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (avctx)
551 1 avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
552 }
553
554
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 33000 times.
33210 for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) {
555 210 H2645SEIUnregistered *unreg = &sei->unregistered;
556
557
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (unreg->buf_ref[i]) {
558 210 AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame,
559 AV_FRAME_DATA_SEI_UNREGISTERED,
560 210 unreg->buf_ref[i]);
561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
210 if (!sd)
562 av_buffer_unref(&unreg->buf_ref[i]);
563 210 unreg->buf_ref[i] = NULL;
564 }
565 }
566 33000 sei->unregistered.nb_buf_ref = 0;
567
568
2/2
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 32679 times.
33000 if (sei->afd.present) {
569 321 AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_AFD,
570 sizeof(uint8_t));
571
572
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 if (sd) {
573 321 *sd->data = sei->afd.active_format_description;
574 321 sei->afd.present = 0;
575 }
576 }
577
578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33000 times.
33000 if (sei->film_grain_characteristics.present) {
579 H2645SEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics;
580 AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame);
581 AVFilmGrainH274Params *h274;
582
583 if (!fgp)
584 return AVERROR(ENOMEM);
585
586 fgp->type = AV_FILM_GRAIN_PARAMS_H274;
587 h274 = &fgp->codec.h274;
588
589 fgp->seed = seed;
590
591 h274->model_id = fgc->model_id;
592 if (fgc->separate_colour_description_present_flag) {
593 h274->bit_depth_luma = fgc->bit_depth_luma;
594 h274->bit_depth_chroma = fgc->bit_depth_chroma;
595 h274->color_range = fgc->full_range + 1;
596 h274->color_primaries = fgc->color_primaries;
597 h274->color_trc = fgc->transfer_characteristics;
598 h274->color_space = fgc->matrix_coeffs;
599 } else {
600 h274->bit_depth_luma = bit_depth_luma;
601 h274->bit_depth_chroma = bit_depth_chroma;
602 if (vui->video_signal_type_present_flag)
603 h274->color_range = vui->video_full_range_flag + 1;
604 else
605 h274->color_range = AVCOL_RANGE_UNSPECIFIED;
606 if (vui->colour_description_present_flag) {
607 h274->color_primaries = vui->colour_primaries;
608 h274->color_trc = vui->transfer_characteristics;
609 h274->color_space = vui->matrix_coeffs;
610 } else {
611 h274->color_primaries = AVCOL_PRI_UNSPECIFIED;
612 h274->color_trc = AVCOL_TRC_UNSPECIFIED;
613 h274->color_space = AVCOL_SPC_UNSPECIFIED;
614 }
615 }
616 h274->blending_mode_id = fgc->blending_mode_id;
617 h274->log2_scale_factor = fgc->log2_scale_factor;
618
619 memcpy(&h274->component_model_present, &fgc->comp_model_present_flag,
620 sizeof(h274->component_model_present));
621 memcpy(&h274->num_intensity_intervals, &fgc->num_intensity_intervals,
622 sizeof(h274->num_intensity_intervals));
623 memcpy(&h274->num_model_values, &fgc->num_model_values,
624 sizeof(h274->num_model_values));
625 memcpy(&h274->intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound,
626 sizeof(h274->intensity_interval_lower_bound));
627 memcpy(&h274->intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound,
628 sizeof(h274->intensity_interval_upper_bound));
629 memcpy(&h274->comp_model_value, &fgc->comp_model_value,
630 sizeof(h274->comp_model_value));
631
632 if (IS_H264(codec_id))
633 fgc->present = !!fgc->repetition_period;
634 else
635 fgc->present = fgc->persistence_flag;
636
637 if (avctx)
638 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
639 }
640
641
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 32998 times.
33000 if (sei->ambient_viewing_environment.present) {
642 2 H2645SEIAmbientViewingEnvironment *env =
643 &sei->ambient_viewing_environment;
644
645 AVAmbientViewingEnvironment *dst_env =
646 2 av_ambient_viewing_environment_create_side_data(frame);
647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!dst_env)
648 return AVERROR(ENOMEM);
649
650 2 dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000);
651 2 dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000);
652 2 dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000);
653 }
654
655 33000 return 0;
656 }
657
658 69449 void ff_h2645_sei_reset(H2645SEI *s)
659 {
660 69449 av_buffer_unref(&s->a53_caption.buf_ref);
661
662
2/2
✓ Branch 0 taken 213 times.
✓ Branch 1 taken 69449 times.
69662 for (unsigned i = 0; i < s->unregistered.nb_buf_ref; i++)
663 213 av_buffer_unref(&s->unregistered.buf_ref[i]);
664 69449 s->unregistered.nb_buf_ref = 0;
665 69449 av_freep(&s->unregistered.buf_ref);
666 69449 av_buffer_unref(&s->dynamic_hdr_plus.info);
667 69449 av_buffer_unref(&s->dynamic_hdr_vivid.info);
668
669 69449 s->ambient_viewing_environment.present = 0;
670 69449 }
671