FFmpeg
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"
34 #include "libavutil/mem.h"
35 #include "libavutil/stereo3d.h"
36 
37 #include "atsc_a53.h"
38 #include "avcodec.h"
39 #include "decode.h"
40 #include "dynamic_hdr_vivid.h"
41 #include "get_bits.h"
42 #include "golomb.h"
43 #include "h2645_sei.h"
44 #include "itut35.h"
45 #include "refstruct.h"
46 
47 #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
48 #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
49 
50 #if CONFIG_HEVC_SEI
51 static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s,
52  GetByteContext *gb)
53 {
54  size_t meta_size;
55  int err;
56  AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size);
57  if (!metadata)
58  return AVERROR(ENOMEM);
59 
60  err = av_dynamic_hdr_plus_from_t35(metadata, gb->buffer,
62  if (err < 0) {
63  av_free(metadata);
64  return err;
65  }
66 
67  av_buffer_unref(&s->info);
68  s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
69  if (!s->info) {
70  av_free(metadata);
71  return AVERROR(ENOMEM);
72  }
73 
74  return 0;
75 }
76 
77 static int decode_registered_user_data_dynamic_hdr_vivid(HEVCSEIDynamicHDRVivid *s,
78  GetByteContext *gb)
79 {
80  size_t meta_size;
81  int err;
82  AVDynamicHDRVivid *metadata = av_dynamic_hdr_vivid_alloc(&meta_size);
83  if (!metadata)
84  return AVERROR(ENOMEM);
85 
88  if (err < 0) {
89  av_free(metadata);
90  return err;
91  }
92 
93  av_buffer_unref(&s->info);
94  s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0);
95  if (!s->info) {
96  av_free(metadata);
97  return AVERROR(ENOMEM);
98  }
99 
100  return 0;
101 }
102 #endif
103 
105  GetByteContext *gb)
106 {
108 
109  av_buffer_unref(&s->info);
110  s->info = av_buffer_alloc(size);
111  if (!s->info)
112  return AVERROR(ENOMEM);
113 
114  bytestream2_get_bufferu(gb, s->info->data, size);
115  return 0;
116 }
117 
119 {
120  int flag;
121 
122  if (bytestream2_get_bytes_left(gb) <= 0)
123  return AVERROR_INVALIDDATA;
124 
125  flag = !!(bytestream2_get_byteu(gb) & 0x40); // active_format_flag
126 
127  if (flag) {
128  if (bytestream2_get_bytes_left(gb) <= 0)
129  return AVERROR_INVALIDDATA;
130  h->active_format_description = bytestream2_get_byteu(gb) & 0xF;
131  h->present = 1;
132  }
133 
134  return 0;
135 }
136 
138  GetByteContext *gb)
139 {
140  return ff_parse_a53_cc(&h->buf_ref, gb->buffer,
142 }
143 
145  enum AVCodecID codec_id, void *logctx)
146 {
147  int country_code, provider_code;
148 
149  if (bytestream2_get_bytes_left(gb) < 3)
150  return AVERROR_INVALIDDATA;
151 
152  country_code = bytestream2_get_byteu(gb); // itu_t_t35_country_code
153  if (country_code == 0xFF) {
154  if (bytestream2_get_bytes_left(gb) < 3)
155  return AVERROR_INVALIDDATA;
156 
157  bytestream2_skipu(gb, 1); // itu_t_t35_country_code_extension_byte
158  }
159 
160  if (country_code != ITU_T_T35_COUNTRY_CODE_US &&
161  country_code != ITU_T_T35_COUNTRY_CODE_UK &&
162  country_code != ITU_T_T35_COUNTRY_CODE_CN) {
163  av_log(logctx, AV_LOG_VERBOSE,
164  "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)\n",
165  country_code);
166  return 0;
167  }
168 
169  /* itu_t_t35_payload_byte follows */
170  provider_code = bytestream2_get_be16u(gb);
171 
172  switch (provider_code) {
174  uint32_t user_identifier;
175 
176  if (bytestream2_get_bytes_left(gb) < 4)
177  return AVERROR_INVALIDDATA;
178 
179  user_identifier = bytestream2_get_be32u(gb);
180  switch (user_identifier) {
181  case MKBETAG('D', 'T', 'G', '1'): // afd_data
182  return decode_registered_user_data_afd(&h->afd, gb);
183  case MKBETAG('G', 'A', '9', '4'): // closed captions
184  return decode_registered_user_data_closed_caption(&h->a53_caption, gb);
185  default:
186  av_log(logctx, AV_LOG_VERBOSE,
187  "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n",
188  user_identifier);
189  break;
190  }
191  break;
192  }
194  if (bytestream2_get_bytes_left(gb) < 2)
195  return AVERROR_INVALIDDATA;
196 
197  bytestream2_skipu(gb, 1); // user_data_type_code
198  return decode_registered_user_data_lcevc(&h->lcevc, gb);
199  }
200 #if CONFIG_HEVC_SEI
202  const uint16_t cuva_provider_oriented_code = 0x0005;
203  uint16_t provider_oriented_code;
204 
205  if (!IS_HEVC(codec_id))
206  goto unsupported_provider_code;
207 
208  if (bytestream2_get_bytes_left(gb) < 2)
209  return AVERROR_INVALIDDATA;
210 
211  provider_oriented_code = bytestream2_get_be16u(gb);
212  if (provider_oriented_code == cuva_provider_oriented_code) {
213  return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb);
214  }
215  break;
216  }
218  // A/341 Amendment - 2094-40
219  const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
220  const uint8_t smpte2094_40_application_identifier = 0x04;
221  uint16_t provider_oriented_code;
222  uint8_t application_identifier;
223 
224  if (!IS_HEVC(codec_id))
225  goto unsupported_provider_code;
226 
227  if (bytestream2_get_bytes_left(gb) < 3)
228  return AVERROR_INVALIDDATA;
229 
230  provider_oriented_code = bytestream2_get_be16u(gb);
231  application_identifier = bytestream2_get_byteu(gb);
232  if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
233  application_identifier == smpte2094_40_application_identifier) {
234  return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb);
235  }
236  break;
237  }
238  case 0x5890: { // aom_provider_code
239  const uint16_t aom_grain_provider_oriented_code = 0x0001;
240  uint16_t provider_oriented_code;
241 
242  if (!IS_HEVC(codec_id))
243  goto unsupported_provider_code;
244 
245  if (bytestream2_get_bytes_left(gb) < 2)
246  return AVERROR_INVALIDDATA;
247 
248  provider_oriented_code = bytestream2_get_byteu(gb);
249  if (provider_oriented_code == aom_grain_provider_oriented_code) {
250  return ff_aom_parse_film_grain_sets(&h->aom_film_grain,
251  gb->buffer,
253  }
254  break;
255  }
256  unsupported_provider_code:
257 #endif
258  default:
259  av_log(logctx, AV_LOG_VERBOSE,
260  "Unsupported User Data Registered ITU-T T35 SEI message (provider_code = %d)\n",
261  provider_code);
262  break;
263  }
264 
265  return 0;
266 }
267 
269  GetByteContext *gb,
270  enum AVCodecID codec_id)
271 {
272  uint8_t *user_data;
274  AVBufferRef *buf_ref, **tmp;
275 
276  if (size < 16 || size >= INT_MAX - 1)
277  return AVERROR_INVALIDDATA;
278 
279  tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref));
280  if (!tmp)
281  return AVERROR(ENOMEM);
282  h->buf_ref = tmp;
283 
284  buf_ref = av_buffer_alloc(size + 1);
285  if (!buf_ref)
286  return AVERROR(ENOMEM);
287  user_data = buf_ref->data;
288 
290  user_data[size] = 0;
291  buf_ref->size = size;
292  h->buf_ref[h->nb_buf_ref++] = buf_ref;
293 
294  if (IS_H264(codec_id)) {
295  int e, build;
296  e = sscanf(user_data + 16, "x264 - core %d", &build);
297  if (e == 1 && build > 0)
298  h->x264_build = build;
299  if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16))
300  h->x264_build = 67;
301  }
302 
303  return 0;
304 }
305 
307  GetBitContext *gb)
308 {
309  h->present = !get_bits1(gb); // display_orientation_cancel_flag
310 
311  if (h->present) {
312  h->hflip = get_bits1(gb); // hor_flip
313  h->vflip = get_bits1(gb); // ver_flip
314 
315  h->anticlockwise_rotation = get_bits(gb, 16);
316  // This is followed by display_orientation_repetition_period
317  // and display_orientation_extension_flag for H.264
318  // and by display_orientation_persistence_flag for HEVC.
319  }
320 
321  return 0;
322 }
323 
325  GetBitContext *gb,
326  enum AVCodecID codec_id)
327 {
328  h->arrangement_id = get_ue_golomb_long(gb);
329  h->arrangement_cancel_flag = get_bits1(gb);
330  h->present = !h->arrangement_cancel_flag;
331 
332  if (h->present) {
333  h->arrangement_type = get_bits(gb, 7);
334  h->quincunx_sampling_flag = get_bits1(gb);
335  h->content_interpretation_type = get_bits(gb, 6);
336 
337  // spatial_flipping_flag, frame0_flipped_flag, field_views_flag
338  skip_bits(gb, 3);
339  h->current_frame_is_frame0_flag = get_bits1(gb);
340  // frame0_self_contained_flag, frame1_self_contained_flag
341  skip_bits(gb, 2);
342 
343  if (!h->quincunx_sampling_flag && h->arrangement_type != 5)
344  skip_bits(gb, 16); // frame[01]_grid_position_[xy]
345  skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
346  if (IS_H264(codec_id))
347  h->arrangement_repetition_period = get_ue_golomb_long(gb);
348  else
349  skip_bits1(gb); // frame_packing_arrangement_persistence_flag
350  }
351  // H.264: frame_packing_arrangement_extension_flag,
352  // HEVC: upsampled_aspect_ratio_flag
353  skip_bits1(gb);
354 
355  return 0;
356 }
357 
359  GetByteContext *gb)
360 {
361  if (bytestream2_get_bytes_left(gb) < 1)
362  return AVERROR_INVALIDDATA;
363 
364  s->present = 1;
365  s->preferred_transfer_characteristics = bytestream2_get_byteu(gb);
366 
367  return 0;
368 }
369 
371  GetByteContext *gb)
372 {
373  static const uint16_t max_ambient_light_value = 50000;
374 
375  if (bytestream2_get_bytes_left(gb) < 8)
376  return AVERROR_INVALIDDATA;
377 
378  s->ambient_illuminance = bytestream2_get_be32u(gb);
379  if (!s->ambient_illuminance)
380  return AVERROR_INVALIDDATA;
381 
382  s->ambient_light_x = bytestream2_get_be16u(gb);
383  if (s->ambient_light_x > max_ambient_light_value)
384  return AVERROR_INVALIDDATA;
385 
386  s->ambient_light_y = bytestream2_get_be16u(gb);
387  if (s->ambient_light_y > max_ambient_light_value)
388  return AVERROR_INVALIDDATA;
389 
390  s->present = 1;
391 
392  return 0;
393 }
394 
396  enum AVCodecID codec_id, GetBitContext *gb)
397 {
398  h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag
399 
400  if (h->present) {
401  memset(h, 0, sizeof(*h));
402  h->model_id = get_bits(gb, 2);
403  h->separate_colour_description_present_flag = get_bits1(gb);
404  if (h->separate_colour_description_present_flag) {
405  h->bit_depth_luma = get_bits(gb, 3) + 8;
406  h->bit_depth_chroma = get_bits(gb, 3) + 8;
407  h->full_range = get_bits1(gb);
408  h->color_primaries = get_bits(gb, 8);
409  h->transfer_characteristics = get_bits(gb, 8);
410  h->matrix_coeffs = get_bits(gb, 8);
411  }
412  h->blending_mode_id = get_bits(gb, 2);
413  h->log2_scale_factor = get_bits(gb, 4);
414  for (int c = 0; c < 3; c++)
415  h->comp_model_present_flag[c] = get_bits1(gb);
416  for (int c = 0; c < 3; c++) {
417  if (h->comp_model_present_flag[c]) {
418  h->num_intensity_intervals[c] = get_bits(gb, 8) + 1;
419  h->num_model_values[c] = get_bits(gb, 3) + 1;
420  if (h->num_model_values[c] > 6)
421  return AVERROR_INVALIDDATA;
422  for (int i = 0; i < h->num_intensity_intervals[c]; i++) {
423  h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8);
424  h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8);
425  for (int j = 0; j < h->num_model_values[c]; j++)
426  h->comp_model_value[c][i][j] = get_se_golomb_long(gb);
427  }
428  }
429  }
430  if (IS_HEVC(codec_id))
431  h->persistence_flag = get_bits1(gb);
432  else
433  h->repetition_period = get_ue_golomb_long(gb);
434 
435  h->present = 1;
436  }
437 
438  return 0;
439 }
440 
442  GetByteContext *gb)
443 {
444  int i;
445 
446  if (bytestream2_get_bytes_left(gb) < 24)
447  return AVERROR_INVALIDDATA;
448 
449  // Mastering primaries
450  for (i = 0; i < 3; i++) {
451  s->display_primaries[i][0] = bytestream2_get_be16u(gb);
452  s->display_primaries[i][1] = bytestream2_get_be16u(gb);
453  }
454  // White point (x, y)
455  s->white_point[0] = bytestream2_get_be16u(gb);
456  s->white_point[1] = bytestream2_get_be16u(gb);
457 
458  // Max and min luminance of mastering display
459  s->max_luminance = bytestream2_get_be32u(gb);
460  s->min_luminance = bytestream2_get_be32u(gb);
461 
462  // As this SEI message comes before the first frame that references it,
463  // initialize the flag to 2 and decrement on IRAP access unit so it
464  // persists for the coded video sequence (e.g., between two IRAPs)
465  s->present = 2;
466 
467  return 0;
468 }
469 
471  GetByteContext *gb)
472 {
473  if (bytestream2_get_bytes_left(gb) < 4)
474  return AVERROR_INVALIDDATA;
475 
476  // Max and average light levels
477  s->max_content_light_level = bytestream2_get_be16u(gb);
478  s->max_pic_average_light_level = bytestream2_get_be16u(gb);
479  // As this SEI message comes before the first frame that references it,
480  // initialize the flag to 2 and decrement on IRAP access unit so it
481  // persists for the coded video sequence (e.g., between two IRAPs)
482  s->present = 2;
483 
484  return 0;
485 }
486 
488  enum AVCodecID codec_id, GetBitContext *gb,
489  GetByteContext *gbyte, void *logctx)
490 {
491  switch (type) {
493  return decode_registered_user_data(h, gbyte, codec_id, logctx);
495  return decode_unregistered_user_data(&h->unregistered, gbyte, codec_id);
497  return decode_display_orientation(&h->display_orientation, gb);
499  ff_refstruct_unref(&h->film_grain_characteristics);
500  h->film_grain_characteristics = ff_refstruct_allocz(sizeof(*h->film_grain_characteristics));
501  if (!h->film_grain_characteristics)
502  return AVERROR(ENOMEM);
503  return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb);
505  return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id);
507  return decode_alternative_transfer(&h->alternative_transfer, gbyte);
509  return decode_ambient_viewing_environment(&h->ambient_viewing_environment,
510  gbyte);
512  return decode_nal_sei_mastering_display_info(&h->mastering_display,
513  gbyte);
515  return decode_nal_sei_content_light_info(&h->content_light, gbyte);
516  default:
518  }
519 }
520 
522 {
523  int ret = av_buffer_replace(&dst->a53_caption.buf_ref,
524  src->a53_caption.buf_ref);
525  if (ret < 0)
526  return ret;
527 
528  for (unsigned i = 0; i < dst->unregistered.nb_buf_ref; i++)
529  av_buffer_unref(&dst->unregistered.buf_ref[i]);
530  dst->unregistered.nb_buf_ref = 0;
531 
532  ret = av_buffer_replace(&dst->lcevc.info, src->lcevc.info);
533  if (ret < 0)
534  return ret;
535 
536  if (src->unregistered.nb_buf_ref) {
537  ret = av_reallocp_array(&dst->unregistered.buf_ref,
538  src->unregistered.nb_buf_ref,
539  sizeof(*dst->unregistered.buf_ref));
540  if (ret < 0)
541  return ret;
542 
543  for (unsigned i = 0; i < src->unregistered.nb_buf_ref; i++) {
544  dst->unregistered.buf_ref[i] = av_buffer_ref(src->unregistered.buf_ref[i]);
545  if (!dst->unregistered.buf_ref[i])
546  return AVERROR(ENOMEM);
547  dst->unregistered.nb_buf_ref++;
548  }
549  }
550 
551  for (unsigned i = 0; i < FF_ARRAY_ELEMS(dst->aom_film_grain.sets); i++) {
552  ret = av_buffer_replace(&dst->aom_film_grain.sets[i],
553  src->aom_film_grain.sets[i]);
554  if (ret < 0)
555  return ret;
556  }
557  dst->aom_film_grain.enable = src->aom_film_grain.enable;
558 
559  dst->mastering_display = src->mastering_display;
560  dst->content_light = src->content_light;
561 
562  ff_refstruct_replace(&dst->film_grain_characteristics,
563  src->film_grain_characteristics);
564 
565  return 0;
566 }
567 
569 {
570  if (IS_H264(codec_id))
571  return type <= SEI_FPA_H264_TYPE_2D &&
573  else
576 }
577 
579  AVFrameSideData ***sd, int *nb_sd)
580 {
581  int ret;
582 
583  for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) {
584  H2645SEIUnregistered *unreg = &sei->unregistered;
585 
586  if (unreg->buf_ref[i]) {
589  &unreg->buf_ref[i], 0);
590  if (!entry)
591  av_buffer_unref(&unreg->buf_ref[i]);
592  }
593  }
594  sei->unregistered.nb_buf_ref = 0;
595 
596  if (sei->ambient_viewing_environment.present) {
597  H2645SEIAmbientViewingEnvironment *env = &sei->ambient_viewing_environment;
598  AVBufferRef *buf;
599  size_t size;
600 
601  AVAmbientViewingEnvironment *dst_env =
603  if (!dst_env)
604  return AVERROR(ENOMEM);
605 
606  buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0);
607  if (!buf) {
608  av_free(dst_env);
609  return AVERROR(ENOMEM);
610  }
611 
612  ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd,
614 
615  if (ret < 0)
616  return ret;
617 
618  dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000);
619  dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000);
620  dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000);
621  }
622 
623  if (sei->mastering_display.present) {
624  // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
625  const int mapping[3] = {2, 0, 1};
626  const int chroma_den = 50000;
627  const int luma_den = 10000;
628  int i;
629  AVMasteringDisplayMetadata *metadata;
630 
631  ret = ff_decode_mastering_display_new_ext(avctx, sd, nb_sd, &metadata);
632  if (ret < 0)
633  return ret;
634 
635  if (metadata) {
636  metadata->has_luminance = 1;
637  metadata->has_primaries = 1;
638 
639  for (i = 0; i < 3; i++) {
640  const int j = mapping[i];
641  metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
642  metadata->display_primaries[i][0].den = chroma_den;
643  metadata->has_primaries &= sei->mastering_display.display_primaries[j][0] >= 5 &&
644  sei->mastering_display.display_primaries[j][0] <= 37000;
645 
646  metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1];
647  metadata->display_primaries[i][1].den = chroma_den;
648  metadata->has_primaries &= sei->mastering_display.display_primaries[j][1] >= 5 &&
649  sei->mastering_display.display_primaries[j][1] <= 42000;
650  }
651  metadata->white_point[0].num = sei->mastering_display.white_point[0];
652  metadata->white_point[0].den = chroma_den;
653  metadata->has_primaries &= sei->mastering_display.white_point[0] >= 5 &&
654  sei->mastering_display.white_point[0] <= 37000;
655 
656  metadata->white_point[1].num = sei->mastering_display.white_point[1];
657  metadata->white_point[1].den = chroma_den;
658  metadata->has_primaries &= sei->mastering_display.white_point[1] >= 5 &&
659  sei->mastering_display.white_point[1] <= 42000;
660 
661  metadata->max_luminance.num = sei->mastering_display.max_luminance;
662  metadata->max_luminance.den = luma_den;
663  metadata->has_luminance &= sei->mastering_display.max_luminance >= 50000 &&
664  sei->mastering_display.max_luminance <= 100000000;
665 
666  metadata->min_luminance.num = sei->mastering_display.min_luminance;
667  metadata->min_luminance.den = luma_den;
668  metadata->has_luminance &= sei->mastering_display.min_luminance <= 50000 &&
669  sei->mastering_display.min_luminance <
670  sei->mastering_display.max_luminance;
671 
672  /* Real (blu-ray) releases in the wild come with minimum luminance
673  * values of 0.000 cd/m2, so permit this edge case */
675  metadata->has_luminance &= sei->mastering_display.min_luminance >= 1;
676 
677  if (metadata->has_luminance || metadata->has_primaries)
678  av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
679  if (metadata->has_primaries) {
680  av_log(avctx, AV_LOG_DEBUG,
681  "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
682  av_q2d(metadata->display_primaries[0][0]),
683  av_q2d(metadata->display_primaries[0][1]),
684  av_q2d(metadata->display_primaries[1][0]),
685  av_q2d(metadata->display_primaries[1][1]),
686  av_q2d(metadata->display_primaries[2][0]),
687  av_q2d(metadata->display_primaries[2][1]),
688  av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
689  }
690  if (metadata->has_luminance) {
691  av_log(avctx, AV_LOG_DEBUG,
692  "min_luminance=%f, max_luminance=%f\n",
693  av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
694  }
695  }
696  }
697 
698  if (sei->content_light.present) {
699  AVContentLightMetadata *metadata;
700 
701  ret = ff_decode_content_light_new_ext(avctx, sd, nb_sd, &metadata);
702  if (ret < 0)
703  return ret;
704 
705  if (metadata) {
706  metadata->MaxCLL = sei->content_light.max_content_light_level;
707  metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
708 
709  av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
710  av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
711  metadata->MaxCLL, metadata->MaxFALL);
712  }
713  }
714 
715  return 0;
716 }
717 
719  enum AVCodecID codec_id,
720  AVCodecContext *avctx, const H2645VUI *vui,
721  unsigned bit_depth_luma, unsigned bit_depth_chroma,
722  int seed)
723 {
724  H2645SEIFramePacking *fp = &sei->frame_packing;
725  int ret;
726 
727  if (fp->present &&
729  fp->content_interpretation_type > 0 &&
730  fp->content_interpretation_type < 3) {
732 
733  if (!stereo)
734  return AVERROR(ENOMEM);
735 
736  switch (fp->arrangement_type) {
737 #if CONFIG_H264_SEI
739  stereo->type = AV_STEREO3D_CHECKERBOARD;
740  break;
742  stereo->type = AV_STEREO3D_COLUMNS;
743  break;
745  stereo->type = AV_STEREO3D_LINES;
746  break;
747 #endif
749  if (fp->quincunx_sampling_flag)
751  else
752  stereo->type = AV_STEREO3D_SIDEBYSIDE;
753  break;
755  stereo->type = AV_STEREO3D_TOPBOTTOM;
756  break;
759  break;
760 #if CONFIG_H264_SEI
762  stereo->type = AV_STEREO3D_2D;
763  break;
764 #endif
765  }
766 
767  if (fp->content_interpretation_type == 2)
768  stereo->flags = AV_STEREO3D_FLAG_INVERT;
769 
772  stereo->view = AV_STEREO3D_VIEW_LEFT;
773  else
774  stereo->view = AV_STEREO3D_VIEW_RIGHT;
775  }
776  }
777 
778  if (sei->display_orientation.present &&
779  (sei->display_orientation.anticlockwise_rotation ||
780  sei->display_orientation.hflip ||
781  sei->display_orientation.vflip)) {
782  H2645SEIDisplayOrientation *o = &sei->display_orientation;
783  double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16);
786  sizeof(int32_t) * 9);
787  if (!rotation)
788  return AVERROR(ENOMEM);
789 
790  /* av_display_rotation_set() expects the angle in the clockwise
791  * direction, hence the first minus.
792  * The below code applies the flips after the rotation, yet
793  * the H.2645 specs require flipping to be applied first.
794  * Because of R O(phi) = O(-phi) R (where R is flipping around
795  * an arbitatry axis and O(phi) is the proper rotation by phi)
796  * we can create display matrices as desired by negating
797  * the degree once for every flip applied. */
798  angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip);
799  av_display_rotation_set((int32_t *)rotation->data, angle);
800  av_display_matrix_flip((int32_t *)rotation->data,
801  o->hflip, o->vflip);
802  }
803 
804  if (sei->a53_caption.buf_ref) {
805  H2645SEIA53Caption *a53 = &sei->a53_caption;
807  if (!sd)
808  av_buffer_unref(&a53->buf_ref);
809  a53->buf_ref = NULL;
811  }
812 
813  ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data);
814  if (ret < 0)
815  return ret;
816 
817  if (sei->afd.present) {
819  sizeof(uint8_t));
820 
821  if (sd) {
822  *sd->data = sei->afd.active_format_description;
823  sei->afd.present = 0;
824  }
825  }
826 
827  if (sei->lcevc.info) {
828  HEVCSEILCEVC *lcevc = &sei->lcevc;
830  if (ret < 0)
831  return ret;
832  }
833 
834  if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) {
835  H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics;
837  AVFilmGrainH274Params *h274;
838 
839  if (!fgp)
840  return AVERROR(ENOMEM);
841 
843  h274 = &fgp->codec.h274;
844 
845  fgp->seed = seed;
846  fgp->width = frame->width;
847  fgp->height = frame->height;
848 
849  /* H.274 mandates film grain be applied to 4:4:4 frames */
850  fgp->subsampling_x = fgp->subsampling_y = 0;
851 
852  h274->model_id = fgc->model_id;
854  fgp->bit_depth_luma = fgc->bit_depth_luma;
856  fgp->color_range = fgc->full_range + 1;
857  fgp->color_primaries = fgc->color_primaries;
859  fgp->color_space = fgc->matrix_coeffs;
860  } else {
861  fgp->bit_depth_luma = bit_depth_luma;
862  fgp->bit_depth_chroma = bit_depth_chroma;
864  fgp->color_range = vui->video_full_range_flag + 1;
866  fgp->color_primaries = vui->colour_primaries;
868  fgp->color_space = vui->matrix_coeffs;
869  }
870  }
871  h274->blending_mode_id = fgc->blending_mode_id;
873 
874 #if FF_API_H274_FILM_GRAIN_VCS
876  h274->bit_depth_luma = fgp->bit_depth_luma;
877  h274->bit_depth_chroma = fgp->bit_depth_chroma;
878  h274->color_range = fgp->color_range;
879  h274->color_primaries = fgp->color_primaries;
880  h274->color_trc = fgp->color_trc;
881  h274->color_space = fgp->color_space;
883 #endif
884 
886  sizeof(h274->component_model_present));
888  sizeof(h274->num_intensity_intervals));
889  memcpy(&h274->num_model_values, &fgc->num_model_values,
890  sizeof(h274->num_model_values));
892  sizeof(h274->intensity_interval_lower_bound));
894  sizeof(h274->intensity_interval_upper_bound));
895  memcpy(&h274->comp_model_value, &fgc->comp_model_value,
896  sizeof(h274->comp_model_value));
897 
898  if (IS_H264(codec_id))
899  fgc->present = !!fgc->repetition_period;
900  else
901  fgc->present = fgc->persistence_flag;
902 
904  }
905 
906 #if CONFIG_HEVC_SEI
907  ret = ff_aom_attach_film_grain_sets(&sei->aom_film_grain, frame);
908  if (ret < 0)
909  return ret;
910 #endif
911 
912  return 0;
913 }
914 
916 {
917  return h2645_sei_to_side_data(avctx, sei, &avctx->decoded_side_data,
918  &avctx->nb_decoded_side_data);
919 }
920 
922 {
923  av_buffer_unref(&s->a53_caption.buf_ref);
924 
925  for (unsigned i = 0; i < s->unregistered.nb_buf_ref; i++)
926  av_buffer_unref(&s->unregistered.buf_ref[i]);
927  s->unregistered.nb_buf_ref = 0;
928  av_freep(&s->unregistered.buf_ref);
929  av_buffer_unref(&s->dynamic_hdr_plus.info);
930  av_buffer_unref(&s->dynamic_hdr_vivid.info);
931  av_buffer_unref(&s->lcevc.info);
932 
933  s->ambient_viewing_environment.present = 0;
934  s->mastering_display.present = 0;
935  s->content_light.present = 0;
936 
937  ff_refstruct_unref(&s->film_grain_characteristics);
938  ff_aom_uninit_film_grain_params(&s->aom_film_grain);
939 }
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
h2645_sei_to_side_data
static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, AVFrameSideData ***sd, int *nb_sd)
Definition: h2645_sei.c:578
decode_film_grain_characteristics
static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h, enum AVCodecID codec_id, GetBitContext *gb)
Definition: h2645_sei.c:395
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
entry
#define entry
Definition: aom_film_grain_template.c:66
AV_STEREO3D_VIEW_LEFT
@ AV_STEREO3D_VIEW_LEFT
Frame contains only the left view.
Definition: stereo3d.h:158
H2645SEIFilmGrainCharacteristics::persistence_flag
int persistence_flag
Definition: h2645_sei.h:111
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_STEREO3D_SIDEBYSIDE_QUINCUNX
@ AV_STEREO3D_SIDEBYSIDE_QUINCUNX
Views are next to each other, but when upscaling apply a checkerboard pattern.
Definition: stereo3d.h:114
SEI_FPA_H264_TYPE_CHECKERBOARD
@ SEI_FPA_H264_TYPE_CHECKERBOARD
Definition: sei.h:148
SEI_FPA_TYPE_INTERLEAVE_TEMPORAL
@ SEI_FPA_TYPE_INTERLEAVE_TEMPORAL
Definition: sei.h:153
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:2087
H2645SEIFramePacking::arrangement_type
SEIFpaType arrangement_type
Definition: h2645_sei.h:67
H2645SEIAmbientViewingEnvironment::ambient_light_x
uint16_t ambient_light_x
Definition: h2645_sei.h:88
AVFilmGrainParams::bit_depth_luma
int bit_depth_luma
Intended bit depth, or 0 for unknown/unspecified.
Definition: film_grain_params.h:287
H2645SEIFramePacking
Definition: h2645_sei.h:63
av_frame_new_side_data
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:799
GetByteContext
Definition: bytestream.h:33
H2645SEIAFD
Definition: h2645_sei.h:40
AVFilmGrainH274Params::color_range
attribute_deprecated enum AVColorRange color_range
Specifies the video signal characteristics.
Definition: film_grain_params.h:167
AVAmbientViewingEnvironment
Ambient viewing environment metadata as defined by H.274.
Definition: ambient_viewing_environment.h:36
get_se_golomb_long
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:294
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
H2645SEIFilmGrainCharacteristics::bit_depth_chroma
int bit_depth_chroma
Definition: h2645_sei.h:97
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
ff_h2645_sei_to_frame
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:718
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
H2645VUI::matrix_coeffs
enum AVColorSpace matrix_coeffs
Definition: h2645_vui.h:41
AVFilmGrainH274Params::blending_mode_id
int blending_mode_id
Specifies the blending mode used to blend the simulated film grain with the decoded images.
Definition: film_grain_params.h:182
HEVCSEILCEVC::info
AVBufferRef * info
Definition: h2645_sei.h:54
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
H2645SEIA53Caption::buf_ref
AVBufferRef * buf_ref
Definition: h2645_sei.h:37
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
IS_H264
#define IS_H264(codec_id)
Definition: h2645_sei.c:47
H2645SEIA53Caption
Definition: h2645_sei.h:36
av_display_matrix_flip
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
H2645SEIMasteringDisplay
Definition: h2645_sei.h:114
FF_COMPLIANCE_STRICT
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: defs.h:59
AVFilmGrainParams::color_space
enum AVColorSpace color_space
Definition: film_grain_params.h:282
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
av_display_rotation_set
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
AV_FRAME_DATA_DISPLAYMATRIX
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:85
SEI_FPA_TYPE_TOP_BOTTOM
@ SEI_FPA_TYPE_TOP_BOTTOM
Definition: sei.h:152
H2645VUI::colour_primaries
enum AVColorPrimaries colour_primaries
Definition: h2645_vui.h:39
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AV_STEREO3D_VIEW_RIGHT
@ AV_STEREO3D_VIEW_RIGHT
Frame contains only the right view.
Definition: stereo3d.h:163
HEVCSEILCEVC
Definition: h2645_sei.h:53
AVFilmGrainParams::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: film_grain_params.h:281
H2645VUI::video_full_range_flag
int video_full_range_flag
Definition: h2645_vui.h:37
AVFilmGrainParams::seed
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
Definition: film_grain_params.h:250
H2645SEIDisplayOrientation
Definition: h2645_sei.h:74
H2645VUI::video_signal_type_present_flag
int video_signal_type_present_flag
Definition: h2645_vui.h:35
ff_h2645_sei_message_decode
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:487
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
golomb.h
exp golomb vlc stuff
AV_STEREO3D_SIDEBYSIDE
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition: stereo3d.h:64
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN
@ SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN
Definition: sei.h:149
ITU_T_T35_COUNTRY_CODE_CN
#define ITU_T_T35_COUNTRY_CODE_CN
Definition: itut35.h:22
H2645SEIFramePacking::present
int present
Definition: h2645_sei.h:64
AV_STEREO3D_2D
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:52
H2645SEIFilmGrainCharacteristics::intensity_interval_upper_bound
uint8_t intensity_interval_upper_bound[3][256]
Definition: h2645_sei.h:108
GetBitContext
Definition: get_bits.h:108
AVFilmGrainH274Params::bit_depth_chroma
attribute_deprecated int bit_depth_chroma
Specifies the bit depth used for the chroma components.
Definition: film_grain_params.h:159
av_dynamic_hdr_vivid_alloc
AVDynamicHDRVivid * av_dynamic_hdr_vivid_alloc(size_t *size)
Copyright (c) 2021 Limin Wang <lance.lmwang at gmail.com>
Definition: hdr_dynamic_vivid_metadata.c:24
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
@ SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
Definition: sei.h:107
AVRational::num
int num
Numerator.
Definition: rational.h:59
refstruct.h
ITU_T_T35_PROVIDER_CODE_ATSC
#define ITU_T_T35_PROVIDER_CODE_ATSC
Definition: itut35.h:26
ff_frame_new_side_data_from_buf
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:2137
AVFilmGrainH274Params::intensity_interval_upper_bound
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...
Definition: film_grain_params.h:216
av_ambient_viewing_environment_alloc
AVAmbientViewingEnvironment * av_ambient_viewing_environment_alloc(size_t *size)
Allocate an AVAmbientViewingEnvironment structure.
Definition: ambient_viewing_environment.c:31
is_frame_packing_type_valid
static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id)
Definition: h2645_sei.c:568
ff_decode_content_light_new_ext
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:2191
AVFilmGrainParams::bit_depth_chroma
int bit_depth_chroma
Definition: film_grain_params.h:288
AV_STEREO3D_FRAMESEQUENCE
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition: stereo3d.h:89
film_grain_params.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
H2645SEIFilmGrainCharacteristics::intensity_interval_lower_bound
uint8_t intensity_interval_lower_bound[3][256]
Definition: h2645_sei.h:107
H2645SEIFramePacking::current_frame_is_frame0_flag
int current_frame_is_frame0_flag
Definition: h2645_sei.h:71
AVFilmGrainParams::width
int width
Intended display resolution.
Definition: film_grain_params.h:269
H2645SEIFilmGrainCharacteristics::matrix_coeffs
int matrix_coeffs
Definition: h2645_sei.h:101
H2645SEIDisplayOrientation::anticlockwise_rotation
int anticlockwise_rotation
Definition: h2645_sei.h:76
AV_STEREO3D_LINES
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
Definition: stereo3d.h:126
stereo3d.h
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
s
#define s(width, name)
Definition: cbs_vp9.c:198
SEI_TYPE_FRAME_PACKING_ARRANGEMENT
@ SEI_TYPE_FRAME_PACKING_ARRANGEMENT
Definition: sei.h:75
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
SEI_FPA_H264_TYPE_INTERLEAVE_ROW
@ SEI_FPA_H264_TYPE_INTERLEAVE_ROW
Definition: sei.h:150
decode_registered_user_data_closed_caption
static int decode_registered_user_data_closed_caption(H2645SEIA53Caption *h, GetByteContext *gb)
Definition: h2645_sei.c:137
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:2088
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
decode_nal_sei_content_light_info
static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, GetByteContext *gb)
Definition: h2645_sei.c:470
av_film_grain_params_create_side_data
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
Definition: film_grain_params.c:33
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
H2645SEIAmbientViewingEnvironment
Definition: h2645_sei.h:85
H2645SEIFilmGrainCharacteristics::log2_scale_factor
int log2_scale_factor
Definition: h2645_sei.h:103
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
SEIType
SEIType
Definition: sei.h:29
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
decode.h
get_bits.h
ff_aom_uninit_film_grain_params
void ff_aom_uninit_film_grain_params(AVFilmGrainAFGS1Params *s)
Definition: aom_film_grain.c:381
decode_unregistered_user_data
static int decode_unregistered_user_data(H2645SEIUnregistered *h, GetByteContext *gb, enum AVCodecID codec_id)
Definition: h2645_sei.c:268
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AVFilmGrainH274Params::comp_model_value
int16_t comp_model_value[3][256][6]
Specifies the model values for the component for each intensity interval.
Definition: film_grain_params.h:227
FF_CODEC_PROPERTY_FILM_GRAIN
#define FF_CODEC_PROPERTY_FILM_GRAIN
Definition: avcodec.h:1809
AVStereo3D::flags
int flags
Additional information about the frame packing.
Definition: stereo3d.h:212
H2645SEIDisplayOrientation::hflip
int hflip
Definition: h2645_sei.h:77
AVFilmGrainH274Params::model_id
int model_id
Specifies the film grain simulation mode.
Definition: film_grain_params.h:137
ff_parse_a53_cc
int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size)
Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef.
Definition: atsc_a53.c:69
decode_registered_user_data
static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, enum AVCodecID codec_id, void *logctx)
Definition: h2645_sei.c:144
NULL
#define NULL
Definition: coverity.c:32
H2645SEIFilmGrainCharacteristics::color_primaries
int color_primaries
Definition: h2645_sei.h:99
H2645VUI::colour_description_present_flag
int colour_description_present_flag
Definition: h2645_vui.h:38
av_buffer_unref
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
decode_frame_packing_arrangement
static int decode_frame_packing_arrangement(H2645SEIFramePacking *h, GetBitContext *gb, enum AVCodecID codec_id)
Definition: h2645_sei.c:324
H2645SEIFilmGrainCharacteristics::repetition_period
int repetition_period
Definition: h2645_sei.h:110
H2645SEIFilmGrainCharacteristics::model_id
int model_id
Definition: h2645_sei.h:94
ff_h2645_sei_to_context
int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei)
Definition: h2645_sei.c:915
H2645SEIFilmGrainCharacteristics::comp_model_present_flag
int comp_model_present_flag[3]
Definition: h2645_sei.h:104
AVFilmGrainH274Params::color_trc
attribute_deprecated enum AVColorTransferCharacteristic color_trc
Definition: film_grain_params.h:171
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
H2645SEI
Definition: h2645_sei.h:128
AVDynamicHDRVivid
This struct represents dynamic metadata for color volume transform - CUVA 005.1:2021 standard.
Definition: hdr_dynamic_vivid_metadata.h:310
H2645VUI
Definition: h2645_vui.h:27
ff_refstruct_allocz
static void * ff_refstruct_allocz(size_t size)
Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
double
double
Definition: af_crystalizer.c:132
av_frame_new_side_data_from_buf
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:790
H2645SEIFilmGrainCharacteristics::num_intensity_intervals
uint16_t num_intensity_intervals[3]
Definition: h2645_sei.h:105
AVFilmGrainParams::subsampling_x
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
Definition: film_grain_params.h:274
seed
static unsigned int seed
Definition: videogen.c:78
AV_FRAME_DATA_AFD
@ 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
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:858
IS_HEVC
#define IS_HEVC(codec_id)
Definition: h2645_sei.c:48
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_aom_attach_film_grain_sets
int ff_aom_attach_film_grain_sets(const AVFilmGrainAFGS1Params *s, AVFrame *frame)
Definition: aom_film_grain.c:359
AV_FRAME_DATA_SEI_UNREGISTERED
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition: frame.h:178
decode_alternative_transfer
static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s, GetByteContext *gb)
Definition: h2645_sei.c:358
av_buffer_create
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
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
H2645SEIFilmGrainCharacteristics::bit_depth_luma
int bit_depth_luma
Definition: h2645_sei.h:96
H2645SEIFilmGrainCharacteristics::num_model_values
uint8_t num_model_values[3]
Definition: h2645_sei.h:106
AV_STEREO3D_CHECKERBOARD
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:101
H2645SEIDisplayOrientation::vflip
int vflip
Definition: h2645_sei.h:77
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
@ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
Definition: frame.h:220
H2645VUI::transfer_characteristics
enum AVColorTransferCharacteristic transfer_characteristics
Definition: h2645_vui.h:40
AVFilmGrainH274Params::color_primaries
attribute_deprecated enum AVColorPrimaries color_primaries
Definition: film_grain_params.h:169
AVFilmGrainH274Params::component_model_present
int component_model_present[3]
Indicates if the modelling of film grain for a given component is present.
Definition: film_grain_params.h:192
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
h2645_sei.h
AV_FRAME_DATA_LCEVC
@ AV_FRAME_DATA_LCEVC
Raw LCEVC payload data, as a uint8_t array, with NAL emulation bytes intact.
Definition: frame.h:236
size
int size
Definition: twinvq_data.h:10344
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
ff_frame_new_side_data_from_buf_ext
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:2118
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:238
user_data
static int FUNC() user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
Definition: cbs_mpeg2_syntax_template.c:59
H2645SEIFilmGrainCharacteristics::blending_mode_id
int blending_mode_id
Definition: h2645_sei.h:102
buffer.h
decode_nal_sei_mastering_display_info
static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, GetByteContext *gb)
Definition: h2645_sei.c:441
av_reallocp_array
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
SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition: sei.h:96
SEI_FPA_TYPE_SIDE_BY_SIDE
@ SEI_FPA_TYPE_SIDE_BY_SIDE
Definition: sei.h:151
ff_h2645_sei_reset
void ff_h2645_sei_reset(H2645SEI *s)
Definition: h2645_sei.c:921
SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
@ SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
Definition: sei.h:106
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
AVFilmGrainParams::h274
AVFilmGrainH274Params h274
Definition: film_grain_params.h:261
decode_registered_user_data_afd
static int decode_registered_user_data_afd(H2645SEIAFD *h, GetByteContext *gb)
Definition: h2645_sei.c:118
ff_aom_parse_film_grain_sets
int ff_aom_parse_film_grain_sets(AVFilmGrainAFGS1Params *s, const uint8_t *payload, int payload_size)
Definition: aom_film_grain.c:124
AV_STEREO3D_FLAG_INVERT
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:194
ff_parse_itu_t_t35_to_dynamic_hdr_vivid
int ff_parse_itu_t_t35_to_dynamic_hdr_vivid(AVDynamicHDRVivid *s, const uint8_t *data, int size)
Parse the user data registered ITU-T T.35 to AVbuffer (AVDynamicHDRVivid).
Definition: dynamic_hdr_vivid.c:32
AVBufferRef::size
size_t size
Size of data in bytes.
Definition: buffer.h:94
flag
#define flag(name)
Definition: cbs_av1.c:474
SEI_FPA_H264_TYPE_2D
@ SEI_FPA_H264_TYPE_2D
Definition: sei.h:154
ITU_T_T35_PROVIDER_CODE_LCEVC
#define ITU_T_T35_PROVIDER_CODE_LCEVC
Definition: itut35.h:29
H2645SEIFilmGrainCharacteristics::transfer_characteristics
int transfer_characteristics
Definition: h2645_sei.h:100
AVFilmGrainParams::color_primaries
enum AVColorPrimaries color_primaries
Definition: film_grain_params.h:280
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVCodecContext::properties
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:1806
HEVCSEIDynamicHDRPlus
Definition: h2645_sei.h:45
AVFilmGrainH274Params
This structure describes how to handle film grain synthesis for codecs using the ITU-T H....
Definition: film_grain_params.h:132
AVFilmGrainH274Params::num_intensity_intervals
uint16_t num_intensity_intervals[3]
Specifies the number of intensity intervals for which a specific set of model values has been estimat...
Definition: film_grain_params.h:198
display.h
AV_STEREO3D_TOPBOTTOM
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
Definition: stereo3d.h:76
AVFilmGrainParams::subsampling_y
int subsampling_y
Definition: film_grain_params.h:274
SEI_TYPE_DISPLAY_ORIENTATION
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition: sei.h:77
H2645SEIFilmGrainCharacteristics::present
int present
Definition: h2645_sei.h:93
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
ambient_viewing_environment.h
AVFilmGrainH274Params::intensity_interval_lower_bound
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...
Definition: film_grain_params.h:210
H2645SEIFilmGrainCharacteristics::separate_colour_description_present_flag
int separate_colour_description_present_flag
Definition: h2645_sei.h:95
AVDynamicHDRPlus
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
Definition: hdr_dynamic_metadata.h:243
avcodec.h
AVFilmGrainParams::height
int height
Definition: film_grain_params.h:269
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
H2645SEIFramePacking::content_interpretation_type
int content_interpretation_type
Definition: h2645_sei.h:69
H2645SEIUnregistered
Definition: h2645_sei.h:57
AV_STEREO3D_COLUMNS
@ AV_STEREO3D_COLUMNS
Views are packed per column.
Definition: stereo3d.h:138
atsc_a53.h
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1389
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:207
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
SEIFpaType
SEIFpaType
frame_packing_arrangement types.
Definition: sei.h:147
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVFilmGrainH274Params::color_space
attribute_deprecated enum AVColorSpace color_space
Definition: film_grain_params.h:173
itut35.h
AV_FILM_GRAIN_PARAMS_H274
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
Definition: film_grain_params.h:35
SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: sei.h:35
AVRational::den
int den
Denominator.
Definition: rational.h:60
decode_ambient_viewing_environment
static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s, GetByteContext *gb)
Definition: h2645_sei.c:370
AVFilmGrainH274Params::log2_scale_factor
int log2_scale_factor
Specifies a scale factor used in the film grain characterization equations.
Definition: film_grain_params.h:187
hdr_dynamic_metadata.h
HEVCSEIDynamicHDRVivid
Definition: h2645_sei.h:49
AVFilmGrainH274Params::bit_depth_luma
attribute_deprecated int bit_depth_luma
TODO: On this ABI bump, please also re-order the fields in AVFilmGrainParams (see below)
Definition: film_grain_params.h:151
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
FF_CODEC_PROPERTY_CLOSED_CAPTIONS
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:1808
ITU_T_T35_COUNTRY_CODE_UK
#define ITU_T_T35_COUNTRY_CODE_UK
Definition: itut35.h:23
H2645SEIAmbientViewingEnvironment::ambient_illuminance
uint32_t ambient_illuminance
Definition: h2645_sei.h:87
FF_H2645_SEI_MESSAGE_UNHANDLED
@ FF_H2645_SEI_MESSAGE_UNHANDLED
Definition: h2645_sei.h:149
AVFilmGrainH274Params::num_model_values
uint8_t num_model_values[3]
Specifies the number of model values present for each intensity interval in which the film grain has ...
Definition: film_grain_params.h:204
AVFilmGrainParams::color_range
enum AVColorRange color_range
Intended video signal characteristics.
Definition: film_grain_params.h:279
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
H2645SEIAmbientViewingEnvironment::ambient_light_y
uint16_t ambient_light_y
Definition: h2645_sei.h:89
ff_decode_mastering_display_new_ext
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:2146
H2645SEIFramePacking::quincunx_sampling_flag
int quincunx_sampling_flag
Definition: h2645_sei.h:70
ITU_T_T35_PROVIDER_CODE_CUVA
#define ITU_T_T35_PROVIDER_CODE_CUVA
Definition: itut35.h:27
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
bytestream2_get_bufferu
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:277
AVFilmGrainParams::codec
union AVFilmGrainParams::@434 codec
Additional fields may be added both here and in any structure included.
mastering_display_metadata.h
get_ue_golomb_long
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
ITU_T_T35_COUNTRY_CODE_US
#define ITU_T_T35_COUNTRY_CODE_US
Definition: itut35.h:24
ff_h2645_sei_ctx_replace
int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
Definition: h2645_sei.c:521
av_stereo3d_create_side_data
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:54
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
av_dynamic_hdr_plus_alloc
AVDynamicHDRPlus * av_dynamic_hdr_plus_alloc(size_t *size)
Allocate an AVDynamicHDRPlus structure and set its fields to default values.
Definition: hdr_dynamic_metadata.c:36
dynamic_hdr_vivid.h
AVStereo3D::view
enum AVStereo3DView view
Determines which views are packed.
Definition: stereo3d.h:217
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ITU_T_T35_PROVIDER_CODE_SMTPE
#define ITU_T_T35_PROVIDER_CODE_SMTPE
Definition: itut35.h:30
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dynamic_hdr_plus_from_t35
int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data, size_t size)
Parse the user data registered ITU-T T.35 to AVbuffer (AVDynamicHDRPlus).
Definition: hdr_dynamic_metadata.c:61
H2645SEIFilmGrainCharacteristics::full_range
int full_range
Definition: h2645_sei.h:98
int32_t
int32_t
Definition: audioconvert.c:56
H2645SEIContentLight
Definition: h2645_sei.h:122
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
h
h
Definition: vp9dsp_template.c:2070
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:203
H2645SEIFilmGrainCharacteristics::comp_model_value
int16_t comp_model_value[3][256][6]
Definition: h2645_sei.h:109
H2645SEIUnregistered::buf_ref
AVBufferRef ** buf_ref
Definition: h2645_sei.h:58
SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
Definition: sei.h:49
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:242
decode_registered_user_data_lcevc
static int decode_registered_user_data_lcevc(HEVCSEILCEVC *s, GetByteContext *gb)
Definition: h2645_sei.c:104
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
av_frame_side_data_add
AVFrameSideData * av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef **pbuf, unsigned int flags)
Add a new side data entry to an array from an existing AVBufferRef.
Definition: frame.c:850
src
#define src
Definition: vp8dsp.c:248
H2645SEIAlternativeTransfer
Definition: h2645_sei.h:80
decode_display_orientation
static int decode_display_orientation(H2645SEIDisplayOrientation *h, GetBitContext *gb)
Definition: h2645_sei.c:306
H2645SEIFilmGrainCharacteristics
Definition: h2645_sei.h:92