FFmpeg
Loading...
Searching...
No Matches
h2645_sei.c
Go to the documentation of this file.
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
29#include "libavutil/buffer.h"
30#include "libavutil/display.h"
33#include "libavutil/mem.h"
34#include "libavutil/refstruct.h"
35#include "libavutil/stereo3d.h"
36
37#include "atsc_a53.h"
38#include "avcodec.h"
39#include "decode.h"
40#include "get_bits.h"
41#include "golomb.h"
42#include "h2645_sei.h"
43#include "itut35.h"
44
45#define IS_H264(codec_id) (CONFIG_H264_SEI && (CONFIG_HEVC_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
46#define IS_HEVC(codec_id) (CONFIG_HEVC_SEI && (CONFIG_H264_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
47#define IS_VVC(codec_id) (CONFIG_VVC_SEI && (CONFIG_H264_SEI || CONFIG_HEVC_SEI) ? codec_id == AV_CODEC_ID_VVC : CONFIG_VVC_SEI )
48
50 enum AVCodecID codec_id, void *logctx)
51{
52 FFITUTT35 itut_t35 = { 0 };
53 FFITUTT35Aux aux = { NULL };
54 int ret;
55
57 if (!ret)
58 av_log(logctx, AV_LOG_VERBOSE,
59 "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n",
60 itut_t35.country_code, itut_t35.provider_code);
61 if (ret <= 0)
62 return ret;
63
64 return ff_itut_t35_parse_payload_to_struct(&itut_t35, &aux, &h->itut_t35, 0);
65}
66
70{
71 uint8_t *user_data;
73 AVBufferRef *buf_ref, **tmp;
74
75 if (size < 16 || size >= INT_MAX - 1)
77
78 tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref));
79 if (!tmp)
80 return AVERROR(ENOMEM);
81 h->buf_ref = tmp;
82
83 buf_ref = av_buffer_alloc(size + 1);
84 if (!buf_ref)
85 return AVERROR(ENOMEM);
86 user_data = buf_ref->data;
87
89 user_data[size] = 0;
90 buf_ref->size = size;
91 h->buf_ref[h->nb_buf_ref++] = buf_ref;
92
93 if (IS_H264(codec_id)) {
94 int e, build;
95 e = sscanf(user_data + 16, "x264 - core %d", &build);
96 if (e == 1 && build > 0)
97 h->x264_build = build;
98 if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
99 h->x264_build = 67;
100 }
101
102 return 0;
103}
104
106 GetBitContext *gb)
107{
108 h->present = !get_bits1(gb); // display_orientation_cancel_flag
109
110 if (h->present) {
111 h->hflip = get_bits1(gb); // hor_flip
112 h->vflip = get_bits1(gb); // ver_flip
113
114 h->anticlockwise_rotation = get_bits(gb, 16);
115 // This is followed by display_orientation_repetition_period
116 // and display_orientation_extension_flag for H.264
117 // and by display_orientation_persistence_flag for HEVC.
118 }
119
120 return 0;
121}
122
124 GetBitContext *gb,
125 enum AVCodecID codec_id)
126{
127 h->arrangement_id = get_ue_golomb_long(gb);
128 h->arrangement_cancel_flag = get_bits1(gb);
129 h->present = !h->arrangement_cancel_flag;
130
131 if (h->present) {
132 h->arrangement_type = get_bits(gb, 7);
133 h->quincunx_sampling_flag = get_bits1(gb);
134 h->content_interpretation_type = get_bits(gb, 6);
135
136 // spatial_flipping_flag, frame0_flipped_flag, field_views_flag
137 skip_bits(gb, 3);
138 h->current_frame_is_frame0_flag = get_bits1(gb);
139 // frame0_self_contained_flag, frame1_self_contained_flag
140 skip_bits(gb, 2);
141
142 if (!h->quincunx_sampling_flag && h->arrangement_type != 5)
143 skip_bits(gb, 16); // frame[01]_grid_position_[xy]
144 skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
145 if (IS_H264(codec_id))
146 h->arrangement_repetition_period = get_ue_golomb_long(gb);
147 else
148 skip_bits1(gb); // frame_packing_arrangement_persistence_flag
149 }
150 // H.264: frame_packing_arrangement_extension_flag,
151 // HEVC: upsampled_aspect_ratio_flag
152 skip_bits1(gb);
153
154 return 0;
155}
156
158 GetByteContext *gb)
159{
160 if (bytestream2_get_bytes_left(gb) < 1)
161 return AVERROR_INVALIDDATA;
162
163 s->present = 1;
164 s->preferred_transfer_characteristics = bytestream2_get_byteu(gb);
165
166 return 0;
167}
168
170 GetByteContext *gb)
171{
172 static const uint16_t max_ambient_light_value = 50000;
173
174 if (bytestream2_get_bytes_left(gb) < 8)
175 return AVERROR_INVALIDDATA;
176
177 s->ambient_illuminance = bytestream2_get_be32u(gb);
178 if (!s->ambient_illuminance)
179 return AVERROR_INVALIDDATA;
180
181 s->ambient_light_x = bytestream2_get_be16u(gb);
182 if (s->ambient_light_x > max_ambient_light_value)
183 return AVERROR_INVALIDDATA;
184
185 s->ambient_light_y = bytestream2_get_be16u(gb);
186 if (s->ambient_light_y > max_ambient_light_value)
187 return AVERROR_INVALIDDATA;
188
189 s->present = 1;
190
191 return 0;
192}
193
196{
197 h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
198
199 if (h->present) {
200 memset(h, 0, sizeof(*h));
201 h->model_id = get_bits(gb, 2);
202 h->separate_colour_description_present_flag = get_bits1(gb);
203 if (h->separate_colour_description_present_flag) {
204 h->bit_depth_luma = get_bits(gb, 3) + 8;
205 h->bit_depth_chroma = get_bits(gb, 3) + 8;
206 h->full_range = get_bits1(gb);
207 h->color_primaries = get_bits(gb, 8);
208 h->transfer_characteristics = get_bits(gb, 8);
209 h->matrix_coeffs = get_bits(gb, 8);
210 }
211 h->blending_mode_id = get_bits(gb, 2);
212 h->log2_scale_factor = get_bits(gb, 4);
213 for (int c = 0; c < 3; c++)
214 h->comp_model_present_flag[c] = get_bits1(gb);
215 for (int c = 0; c < 3; c++) {
216 if (h->comp_model_present_flag[c]) {
217 h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
218 h->num_model_values[c] = get_bits(gb, 3) + 1;
219 if (h->num_model_values[c] > 6)
220 return AVERROR_INVALIDDATA;
221 for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
222 h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
223 h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
224 for (int j = 0; j < h->num_model_values[c]; j++)
225 h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
226 }
227 }
228 }
229 if (!IS_H264(codec_id))
230 h->persistence_flag = get_bits1(gb);
231 else
232 h->repetition_period = get_ue_golomb_long(gb);
233
234 h->present = 1;
235 }
236
237 return 0;
238}
239
241 GetByteContext *gb)
242{
243 int i;
244
245 if (bytestream2_get_bytes_left(gb) < 24)
246 return AVERROR_INVALIDDATA;
247
248 // Mastering primaries
249 for (i = 0; i < 3; i++) {
250 s->display_primaries[i][0] = bytestream2_get_be16u(gb);
251 s->display_primaries[i][1] = bytestream2_get_be16u(gb);
252 }
253 // White point (x, y)
254 s->white_point[0] = bytestream2_get_be16u(gb);
255 s->white_point[1] = bytestream2_get_be16u(gb);
256
257 // Max and min luminance of mastering display
258 s->max_luminance = bytestream2_get_be32u(gb);
259 s->min_luminance = bytestream2_get_be32u(gb);
260
261 // As this SEI message comes before the first frame that references it,
262 // initialize the flag to 2 and decrement on IRAP access unit so it
263 // persists for the coded video sequence (e.g., between two IRAPs)
264 s->present = 2;
265
266 return 0;
267}
268
270 GetByteContext *gb)
271{
272 if (bytestream2_get_bytes_left(gb) < 4)
273 return AVERROR_INVALIDDATA;
274
275 // Max and average light levels
276 s->max_content_light_level = bytestream2_get_be16u(gb);
277 s->max_pic_average_light_level = bytestream2_get_be16u(gb);
278 // As this SEI message comes before the first frame that references it,
279 // initialize the flag to 2 and decrement on IRAP access unit so it
280 // persists for the coded video sequence (e.g., between two IRAPs)
281 s->present = 2;
282
283 return 0;
284}
285
288 GetByteContext *gbyte, void *logctx)
289{
290 switch (type) {
292 return decode_registered_user_data(h, gbyte, codec_id, logctx);
294 return decode_unregistered_user_data(&h->unregistered, gbyte, codec_id);
296 return decode_display_orientation(&h->display_orientation, gb);
298 av_refstruct_unref(&h->film_grain_characteristics);
299 h->film_grain_characteristics = av_refstruct_allocz(sizeof(*h->film_grain_characteristics));
300 if (!h->film_grain_characteristics)
301 return AVERROR(ENOMEM);
302 return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb);
304 return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id);
306 return decode_alternative_transfer(&h->alternative_transfer, gbyte);
308 return decode_ambient_viewing_environment(&h->ambient_viewing_environment,
309 gbyte);
311 return decode_nal_sei_mastering_display_info(&h->mastering_display,
312 gbyte);
314 return decode_nal_sei_content_light_info(&h->content_light, gbyte);
315 default:
317 }
318}
319
321{
322 int ret = av_buffer_replace(&dst->itut_t35.a53_cc,
323 src->itut_t35.a53_cc);
324 if (ret < 0)
325 return ret;
326
327 for (unsigned i = 0; i < dst->unregistered.nb_buf_ref; i++)
328 av_buffer_unref(&dst->unregistered.buf_ref[i]);
329 dst->unregistered.nb_buf_ref = 0;
330
331 ret = av_buffer_replace(&dst->itut_t35.lcevc, src->itut_t35.lcevc);
332 if (ret < 0)
333 return ret;
334
335 if (src->unregistered.nb_buf_ref) {
336 ret = av_reallocp_array(&dst->unregistered.buf_ref,
337 src->unregistered.nb_buf_ref,
338 sizeof(*dst->unregistered.buf_ref));
339 if (ret < 0)
340 return ret;
341
342 for (unsigned i = 0; i < src->unregistered.nb_buf_ref; i++) {
343 dst->unregistered.buf_ref[i] = av_buffer_ref(src->unregistered.buf_ref[i]);
344 if (!dst->unregistered.buf_ref[i])
345 return AVERROR(ENOMEM);
346 dst->unregistered.nb_buf_ref++;
347 }
348 }
349
350 for (unsigned i = 0; i < FF_ARRAY_ELEMS(dst->itut_t35.aom_film_grain.sets); i++) {
351 ret = av_buffer_replace(&dst->itut_t35.aom_film_grain.sets[i],
352 src->itut_t35.aom_film_grain.sets[i]);
353 if (ret < 0)
354 return ret;
355 }
356 dst->itut_t35.aom_film_grain.enable = src->itut_t35.aom_film_grain.enable;
357
358 dst->ambient_viewing_environment = src->ambient_viewing_environment;
359 dst->mastering_display = src->mastering_display;
360 dst->content_light = src->content_light;
361
362 av_refstruct_replace(&dst->film_grain_characteristics,
363 src->film_grain_characteristics);
364
365 return 0;
366}
367
377
379 AVFrameSideData ***sd, int *nb_sd)
380{
381 int ret;
382
383 for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) {
384 H2645SEIUnregistered *unreg = &sei->unregistered;
385
386 if (unreg->buf_ref[i]) {
389 &unreg->buf_ref[i], 0);
390 if (!entry)
391 av_buffer_unref(&unreg->buf_ref[i]);
392 }
393 }
394 sei->unregistered.nb_buf_ref = 0;
395
396 if (sei->ambient_viewing_environment.present) {
397 H2645SEIAmbientViewingEnvironment *env = &sei->ambient_viewing_environment;
398 AVBufferRef *buf;
399 size_t size;
400
403 if (!dst_env)
404 return AVERROR(ENOMEM);
405
406 buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0);
407 if (!buf) {
408 av_free(dst_env);
409 return AVERROR(ENOMEM);
410 }
411
412 dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000);
413 dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000);
414 dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000);
415
416 ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd,
418
419 if (ret < 0)
420 return ret;
421 }
422
423 if (sei->mastering_display.present) {
424 // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
425 const int mapping[3] = {2, 0, 1};
426 const int chroma_den = 50000;
427 const int luma_den = 10000;
428 int i;
430
431 ret = ff_decode_mastering_display_new_ext(avctx, sd, nb_sd, &metadata);
432 if (ret < 0)
433 return ret;
434
435 if (metadata) {
436 metadata->has_luminance = 1;
437 metadata->has_primaries = 1;
438
439 for (i = 0; i < 3; i++) {
440 const int j = mapping[i];
441 metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
442 metadata->display_primaries[i][0].den = chroma_den;
443 metadata->has_primaries &= sei->mastering_display.display_primaries[j][0] >= 5 &&
444 sei->mastering_display.display_primaries[j][0] <= 37000;
445
446 metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1];
447 metadata->display_primaries[i][1].den = chroma_den;
448 metadata->has_primaries &= sei->mastering_display.display_primaries[j][1] >= 5 &&
449 sei->mastering_display.display_primaries[j][1] <= 42000;
450 }
451 metadata->white_point[0].num = sei->mastering_display.white_point[0];
452 metadata->white_point[0].den = chroma_den;
453 metadata->has_primaries &= sei->mastering_display.white_point[0] >= 5 &&
454 sei->mastering_display.white_point[0] <= 37000;
455
456 metadata->white_point[1].num = sei->mastering_display.white_point[1];
457 metadata->white_point[1].den = chroma_den;
458 metadata->has_primaries &= sei->mastering_display.white_point[1] >= 5 &&
459 sei->mastering_display.white_point[1] <= 42000;
460
461 metadata->max_luminance.num = sei->mastering_display.max_luminance;
462 metadata->max_luminance.den = luma_den;
463 metadata->has_luminance &= sei->mastering_display.max_luminance >= 50000 &&
464 sei->mastering_display.max_luminance <= 100000000;
465
466 metadata->min_luminance.num = sei->mastering_display.min_luminance;
467 metadata->min_luminance.den = luma_den;
468 metadata->has_luminance &= sei->mastering_display.min_luminance <= 50000 &&
469 sei->mastering_display.min_luminance <
470 sei->mastering_display.max_luminance;
471
472 /* Real (blu-ray) releases in the wild come with minimum luminance
473 * values of 0.000 cd/m2, so permit this edge case */
475 metadata->has_luminance &= sei->mastering_display.min_luminance >= 1;
476
477 if (metadata->has_luminance || metadata->has_primaries)
478 av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
479 if (metadata->has_primaries) {
480 av_log(avctx, AV_LOG_DEBUG,
481 "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
482 av_q2d(metadata->display_primaries[0][0]),
483 av_q2d(metadata->display_primaries[0][1]),
484 av_q2d(metadata->display_primaries[1][0]),
485 av_q2d(metadata->display_primaries[1][1]),
486 av_q2d(metadata->display_primaries[2][0]),
487 av_q2d(metadata->display_primaries[2][1]),
488 av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
489 }
490 if (metadata->has_luminance) {
491 av_log(avctx, AV_LOG_DEBUG,
492 "min_luminance=%f, max_luminance=%f\n",
493 av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
494 }
495 }
496 }
497
498 if (sei->content_light.present) {
500
501 ret = ff_decode_content_light_new_ext(avctx, sd, nb_sd, &metadata);
502 if (ret < 0)
503 return ret;
504
505 if (metadata) {
506 metadata->MaxCLL = sei->content_light.max_content_light_level;
507 metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
508
509 av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
510 av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
511 metadata->MaxCLL, metadata->MaxFALL);
512 }
513 }
514
515 return 0;
516}
517
519 enum AVCodecID codec_id,
520 AVCodecContext *avctx, const H2645VUI *vui,
521 unsigned bit_depth_luma, unsigned bit_depth_chroma,
522 int seed)
523{
524 H2645SEIFramePacking *fp = &sei->frame_packing;
525 FFITUTT35Meta *itut_t35 = &sei->itut_t35;
526 int ret;
527
528 if (fp->present &&
533
534 if (!stereo)
535 return AVERROR(ENOMEM);
536
537 switch (fp->arrangement_type) {
538#if CONFIG_H264_SEI
541 break;
543 stereo->type = AV_STEREO3D_COLUMNS;
544 break;
546 stereo->type = AV_STEREO3D_LINES;
547 break;
548#endif
552 else
554 break;
556 stereo->type = AV_STEREO3D_TOPBOTTOM;
557 break;
560 break;
561#if CONFIG_H264_SEI
563 stereo->type = AV_STEREO3D_2D;
564 break;
565#endif
566 }
567
568 if (fp->content_interpretation_type == 2)
570
573 stereo->view = AV_STEREO3D_VIEW_LEFT;
574 else
576 }
577 }
578
579 if (sei->display_orientation.present &&
580 (sei->display_orientation.anticlockwise_rotation ||
581 sei->display_orientation.hflip ||
582 sei->display_orientation.vflip)) {
583 H2645SEIDisplayOrientation *o = &sei->display_orientation;
584 double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16);
587 sizeof(int32_t) * 9);
588 if (!rotation)
589 return AVERROR(ENOMEM);
590
591 /* av_display_rotation_set() expects the angle in the clockwise
592 * direction, hence the first minus.
593 * The below code applies the flips after the rotation, yet
594 * the H.2645 specs require flipping to be applied first.
595 * Because of R O(phi) = O(-phi) R (where R is flipping around
596 * an arbitatry axis and O(phi) is the proper rotation by phi)
597 * we can create display matrices as desired by negating
598 * the degree once for every flip applied. */
599 angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip);
600 av_display_rotation_set((int32_t *)rotation->data, angle);
602 o->hflip, o->vflip);
603 }
604
605 if (itut_t35->a53_cc) {
607 if (!sd)
608 av_buffer_unref(&itut_t35->a53_cc);
609 itut_t35->a53_cc = NULL;
610 }
611
612 ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data);
613 if (ret < 0)
614 return ret;
615
616 if (itut_t35->afd) {
618 av_buffer_unref(&itut_t35->afd);
619 itut_t35->afd = NULL;
620 }
621
622 if (itut_t35->lcevc) {
624 &itut_t35->lcevc);
625 if (ret < 0)
626 return ret;
627 }
628
629 if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) {
630 H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics;
633
634 if (!fgp)
635 return AVERROR(ENOMEM);
636
638 h274 = &fgp->codec.h274;
639
640 fgp->seed = seed;
641 fgp->width = frame->width;
642 fgp->height = frame->height;
643
644 /* H.274 mandates film grain be applied to 4:4:4 frames */
645 fgp->subsampling_x = fgp->subsampling_y = 0;
646
647 h274->model_id = fgc->model_id;
649 fgp->bit_depth_luma = fgc->bit_depth_luma;
651 fgp->color_range = fgc->full_range + 1;
654 fgp->color_space = fgc->matrix_coeffs;
655 } else {
656 fgp->bit_depth_luma = bit_depth_luma;
657 fgp->bit_depth_chroma = bit_depth_chroma;
659 fgp->color_range = vui->video_full_range_flag + 1;
663 fgp->color_space = vui->matrix_coeffs;
664 }
665 }
668
670 sizeof(h274->component_model_present));
672 sizeof(h274->num_intensity_intervals));
673 memcpy(&h274->num_model_values, &fgc->num_model_values,
674 sizeof(h274->num_model_values));
676 sizeof(h274->intensity_interval_lower_bound));
678 sizeof(h274->intensity_interval_upper_bound));
679 memcpy(&h274->comp_model_value, &fgc->comp_model_value,
680 sizeof(h274->comp_model_value));
681
682 if (IS_H264(codec_id))
683 fgc->present = !!fgc->repetition_period;
684 else
685 fgc->present = fgc->persistence_flag;
686 }
687
688#if CONFIG_HEVC_SEI
690 if (ret < 0)
691 return ret;
692#endif
693
694 return 0;
695}
696
702
704{
705 for (unsigned i = 0; i < s->unregistered.nb_buf_ref; i++)
706 av_buffer_unref(&s->unregistered.buf_ref[i]);
707 s->unregistered.nb_buf_ref = 0;
708 av_freep(&s->unregistered.buf_ref);
709 ff_itut_t35_unref(&s->itut_t35);
710 s->ambient_viewing_environment.present = 0;
711 s->mastering_display.present = 0;
712 s->content_light.present = 0;
713
714 av_refstruct_unref(&s->film_grain_characteristics);
715}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
AVAmbientViewingEnvironment * av_ambient_viewing_environment_alloc(size_t *size)
Allocate an AVAmbientViewingEnvironment structure.
int ff_aom_attach_film_grain_sets(const AVFilmGrainAFGS1Params *s, AVFrame *frame)
#define entry
int32_t
Libavcodec external API header.
refcounted data buffer API
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition bytestream.h:277
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition decode.c:2222
int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf)
Same as ff_frame_new_side_data_from_buf, but taking a AVFrameSideData array directly instead of an AV...
Definition decode.c:2203
int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, struct AVMasteringDisplayMetadata **mdm)
Same as ff_decode_mastering_display_new, but taking a AVFrameSideData array directly instead of an AV...
Definition decode.c:2231
int ff_decode_content_light_new_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, AVContentLightMetadata **clm)
Same as ff_decode_content_light_new, but taking a AVFrameSideData array directly instead of an AVFram...
Definition decode.c:2276
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition defs.h:59
static AVFrame * frame
Display matrix.
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
bitstream reader API header.
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
exp golomb vlc stuff
static int get_se_golomb_long(GetBitContext *gb)
Definition golomb.h:294
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition golomb.h:104
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition buffer.c:233
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:103
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition buffer.c:77
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition buffer.c:55
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **buf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition side_data.c:229
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
Definition frame.c:647
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition frame.c:638
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition frame.h:236
@ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
Definition frame.h:220
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition frame.h:85
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition frame.h:59
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition frame.h:178
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition frame.h:90
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:217
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition mem.c:225
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure clockwise rotation by the specified angle (in de...
Definition display.c:51
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition display.c:66
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition stereo3d.h:194
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition stereo3d.c:54
@ AV_STEREO3D_COLUMNS
Views are packed per column.
Definition stereo3d.h:138
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
Definition stereo3d.h:126
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition stereo3d.h:52
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
Definition stereo3d.h:101
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
Definition stereo3d.h:76
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
Definition stereo3d.h:114
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition stereo3d.h:89
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition stereo3d.h:64
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
Definition stereo3d.h:163
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
Definition stereo3d.h:158
static int decode_unregistered_user_data(H2645SEIUnregistered *h, GetByteContext *gb, enum AVCodecID codec_id)
Definition h2645_sei.c:67
void ff_h2645_sei_reset(H2645SEI *s)
Definition h2645_sei.c:703
static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h, enum AVCodecID codec_id, GetBitContext *gb)
Definition h2645_sei.c:194
static int decode_frame_packing_arrangement(H2645SEIFramePacking *h, GetBitContext *gb, enum AVCodecID codec_id)
Definition h2645_sei.c:123
static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, AVFrameSideData ***sd, int *nb_sd)
Definition h2645_sei.c:378
static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s, GetByteContext *gb)
Definition h2645_sei.c:169
int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, enum AVCodecID codec_id, AVCodecContext *avctx, const H2645VUI *vui, unsigned bit_depth_luma, unsigned bit_depth_chroma, int seed)
Definition h2645_sei.c:518
int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
Definition h2645_sei.c:320
static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, enum AVCodecID codec_id, void *logctx)
Definition h2645_sei.c:49
int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, enum AVCodecID codec_id, GetBitContext *gb, GetByteContext *gbyte, void *logctx)
Decode a single SEI message.
Definition h2645_sei.c:286
static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, GetByteContext *gb)
Definition h2645_sei.c:240
int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei)
Definition h2645_sei.c:697
#define IS_H264(codec_id)
Definition h2645_sei.c:45
static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s, GetByteContext *gb)
Definition h2645_sei.c:157
static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, GetByteContext *gb)
Definition h2645_sei.c:269
static int decode_display_orientation(H2645SEIDisplayOrientation *h, GetBitContext *gb)
Definition h2645_sei.c:105
#define IS_VVC(codec_id)
Definition h2645_sei.c:47
static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id)
Definition h2645_sei.c:368
@ FF_H2645_SEI_MESSAGE_UNHANDLED
Definition h2645_sei.h:144
cl_device_type type
int ff_itut_t35_parse_payload_to_struct(FFITUTT35 *const itut_t35, FFITUTT35Aux *const aux, FFITUTT35Meta *metadata, int err_recognition)
Parse a pre-processed ITU-T T35 payload to fill the metadata struct.
Definition itut35.c:163
int ff_itut_t35_parse_buffer(FFITUTT35 *const itut_t35, const uint8_t *buf, size_t buf_size, int flags)
Parse a raw ITU-T T35 buffer to get the country code, provider code, and set them plus the pointer an...
Definition itut35.c:34
void ff_itut_t35_unref(FFITUTT35Meta *metadata)
Unref all references in metadata.
Definition itut35.c:393
Stereoscopic video.
Memory handling functions.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:120
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition refstruct.c:160
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
SEIFpaType
frame_packing_arrangement types.
Definition sei.h:147
@ SEI_FPA_TYPE_TOP_BOTTOM
Definition sei.h:152
@ SEI_FPA_H264_TYPE_CHECKERBOARD
Definition sei.h:148
@ SEI_FPA_H264_TYPE_2D
Definition sei.h:154
@ SEI_FPA_TYPE_INTERLEAVE_TEMPORAL
Definition sei.h:153
@ SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN
Definition sei.h:149
@ SEI_FPA_H264_TYPE_INTERLEAVE_ROW
Definition sei.h:150
@ SEI_FPA_TYPE_SIDE_BY_SIDE
Definition sei.h:151
SEIType
Definition sei.h:29
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition sei.h:34
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition sei.h:77
@ SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
Definition sei.h:106
@ SEI_TYPE_FRAME_PACKING_ARRANGEMENT
Definition sei.h:75
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition sei.h:35
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
Definition sei.h:49
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition sei.h:103
@ SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
Definition sei.h:107
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition sei.h:96
#define FF_ARRAY_ELEMS(a)
Ambient viewing environment metadata as defined by H.274.
AVRational ambient_illuminance
Environmental illuminance of the ambient viewing environment in lux.
AVRational ambient_light_x
Normalized x chromaticity coordinate of the environmental ambient light in the nominal viewing enviro...
AVRational ambient_light_y
Normalized y chromaticity coordinate of the environmental ambient light in the nominal viewing enviro...
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
size_t size
Size of data in bytes.
Definition buffer.h:94
main external API structure.
Definition avcodec.h:443
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition avcodec.h:1375
int nb_decoded_side_data
Definition avcodec.h:1930
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition avcodec.h:1929
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
This structure describes how to handle film grain synthesis for codecs using the ITU-T H....
uint8_t intensity_interval_upper_bound[3][256]
Specifies the upper bound of each intensity interval for which the set of model values applies for th...
int blending_mode_id
Specifies the blending mode used to blend the simulated film grain with the decoded images.
uint8_t intensity_interval_lower_bound[3][256]
Specifies the lower ounds of each intensity interval for whichthe set of model values applies for the...
int log2_scale_factor
Specifies a scale factor used in the film grain characterization equations.
int16_t comp_model_value[3][256][6]
Specifies the model values for the component for each intensity interval.
int model_id
Specifies the film grain simulation mode.
int component_model_present[3]
Indicates if the modelling of film grain for a given component is present.
uint16_t num_intensity_intervals[3]
Specifies the number of intensity intervals for which a specific set of model values has been estimat...
uint8_t num_model_values[3]
Specifies the number of model values present for each intensity interval in which the film grain has ...
This structure describes how to handle film grain synthesis in video for specific codecs.
enum AVColorPrimaries color_primaries
AVFilmGrainH274Params h274
enum AVColorRange color_range
Intended video signal characteristics.
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
int bit_depth_luma
Intended bit depth, or 0 for unknown/unspecified.
union AVFilmGrainParams::@177057277273004265167152242113040056044005264354 codec
Additional fields may be added both here and in any structure included.
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
int width
Intended display resolution.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
enum AVColorTransferCharacteristic color_trc
enum AVColorSpace color_space
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Mastering display metadata capable of representing the color volume of the display used to master the...
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition stereo3d.h:203
enum AVStereo3DType type
How views are packed within the video.
Definition stereo3d.h:207
int flags
Additional information about the frame packing.
Definition stereo3d.h:212
enum AVStereo3DView view
Determines which views are packed.
Definition stereo3d.h:217
AVBufferRef * lcevc
Definition itut35.h:63
AVBufferRef * a53_cc
Definition itut35.h:62
AVBufferRef * afd
Definition itut35.h:61
AVFilmGrainAFGS1Params aom_film_grain
Definition itut35.h:68
int country_code
Definition itut35.h:51
int provider_code
Definition itut35.h:53
const uint8_t * buffer
Definition bytestream.h:34
int16_t comp_model_value[3][256][6]
Definition h2645_sei.h:109
uint8_t intensity_interval_lower_bound[3][256]
Definition h2645_sei.h:107
uint8_t intensity_interval_upper_bound[3][256]
Definition h2645_sei.h:108
int current_frame_is_frame0_flag
Definition h2645_sei.h:71
int content_interpretation_type
Definition h2645_sei.h:69
SEIFpaType arrangement_type
Definition h2645_sei.h:67
AVBufferRef ** buf_ref
Definition h2645_sei.h:58
enum AVColorPrimaries colour_primaries
Definition h2645_vui.h:39
int video_signal_type_present_flag
Definition h2645_vui.h:35
enum AVColorTransferCharacteristic transfer_characteristics
Definition h2645_vui.h:40
int video_full_range_flag
Definition h2645_vui.h:37
enum AVColorSpace matrix_coeffs
Definition h2645_vui.h:41
int colour_description_present_flag
Definition h2645_vui.h:38
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
int size
enum AVCodecID codec_id
static unsigned int seed
Definition videogen.c:78
static double c[64]