/src/ffmpeg/libavcodec/h2645_sei.c
Line | Count | Source |
1 | | /* |
2 | | * Common H.264 and HEVC Supplementary Enhancement Information messages |
3 | | * |
4 | | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
5 | | * Copyright (C) 2012 - 2013 Guillaume Martres |
6 | | * Copyright (C) 2012 - 2013 Gildas Cocherel |
7 | | * Copyright (C) 2013 Vittorio Giovara |
8 | | * |
9 | | * This file is part of FFmpeg. |
10 | | * |
11 | | * FFmpeg is free software; you can redistribute it and/or |
12 | | * modify it under the terms of the GNU Lesser General Public |
13 | | * License as published by the Free Software Foundation; either |
14 | | * version 2.1 of the License, or (at your option) any later version. |
15 | | * |
16 | | * FFmpeg is distributed in the hope that it will be useful, |
17 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | | * Lesser General Public License for more details. |
20 | | * |
21 | | * You should have received a copy of the GNU Lesser General Public |
22 | | * License along with FFmpeg; if not, write to the Free Software |
23 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | | */ |
25 | | |
26 | | #include "config_components.h" |
27 | | |
28 | | #include "libavutil/ambient_viewing_environment.h" |
29 | | #include "libavutil/buffer.h" |
30 | | #include "libavutil/display.h" |
31 | | #include "libavutil/hdr_dynamic_metadata.h" |
32 | | #include "libavutil/film_grain_params.h" |
33 | | #include "libavutil/mastering_display_metadata.h" |
34 | | #include "libavutil/mem.h" |
35 | | #include "libavutil/refstruct.h" |
36 | | #include "libavutil/stereo3d.h" |
37 | | |
38 | | #include "atsc_a53.h" |
39 | | #include "avcodec.h" |
40 | | #include "decode.h" |
41 | | #include "dynamic_hdr_vivid.h" |
42 | | #include "get_bits.h" |
43 | | #include "golomb.h" |
44 | | #include "h2645_sei.h" |
45 | | #include "itut35.h" |
46 | | |
47 | 455k | #define IS_H264(codec_id) (CONFIG_H264_SEI && (CONFIG_HEVC_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI) |
48 | 210k | #define IS_HEVC(codec_id) (CONFIG_HEVC_SEI && (CONFIG_H264_SEI || CONFIG_VVC_SEI ) ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI) |
49 | 23.6k | #define IS_VVC(codec_id) (CONFIG_VVC_SEI && (CONFIG_H264_SEI || CONFIG_HEVC_SEI) ? codec_id == AV_CODEC_ID_VVC : CONFIG_VVC_SEI ) |
50 | | |
51 | | #if CONFIG_HEVC_SEI |
52 | | static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s, |
53 | | GetByteContext *gb) |
54 | 113k | { |
55 | 113k | size_t meta_size; |
56 | 113k | int err; |
57 | 113k | AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size); |
58 | 113k | if (!metadata) |
59 | 0 | return AVERROR(ENOMEM); |
60 | | |
61 | 113k | err = av_dynamic_hdr_plus_from_t35(metadata, gb->buffer, |
62 | 113k | bytestream2_get_bytes_left(gb)); |
63 | 113k | if (err < 0) { |
64 | 83.2k | av_free(metadata); |
65 | 83.2k | return err; |
66 | 83.2k | } |
67 | | |
68 | 30.7k | av_buffer_unref(&s->info); |
69 | 30.7k | s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0); |
70 | 30.7k | if (!s->info) { |
71 | 0 | av_free(metadata); |
72 | 0 | return AVERROR(ENOMEM); |
73 | 0 | } |
74 | | |
75 | 30.7k | return 0; |
76 | 30.7k | } |
77 | | |
78 | | static int decode_registered_user_data_dynamic_hdr_vivid(HEVCSEIDynamicHDRVivid *s, |
79 | | GetByteContext *gb) |
80 | 44.7k | { |
81 | 44.7k | size_t meta_size; |
82 | 44.7k | int err; |
83 | 44.7k | AVDynamicHDRVivid *metadata = av_dynamic_hdr_vivid_alloc(&meta_size); |
84 | 44.7k | if (!metadata) |
85 | 0 | return AVERROR(ENOMEM); |
86 | | |
87 | 44.7k | err = ff_parse_itu_t_t35_to_dynamic_hdr_vivid(metadata, |
88 | 44.7k | gb->buffer, bytestream2_get_bytes_left(gb)); |
89 | 44.7k | if (err < 0) { |
90 | 23.3k | av_free(metadata); |
91 | 23.3k | return err; |
92 | 23.3k | } |
93 | | |
94 | 21.4k | av_buffer_unref(&s->info); |
95 | 21.4k | s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0); |
96 | 21.4k | if (!s->info) { |
97 | 0 | av_free(metadata); |
98 | 0 | return AVERROR(ENOMEM); |
99 | 0 | } |
100 | | |
101 | 21.4k | return 0; |
102 | 21.4k | } |
103 | | #endif |
104 | | |
105 | | static int decode_registered_user_data_lcevc(HEVCSEILCEVC *s, |
106 | | GetByteContext *gb) |
107 | 3.22k | { |
108 | 3.22k | int size = bytestream2_get_bytes_left(gb); |
109 | | |
110 | 3.22k | av_buffer_unref(&s->info); |
111 | 3.22k | s->info = av_buffer_alloc(size); |
112 | 3.22k | if (!s->info) |
113 | 0 | return AVERROR(ENOMEM); |
114 | | |
115 | 3.22k | bytestream2_get_bufferu(gb, s->info->data, size); |
116 | 3.22k | return 0; |
117 | 3.22k | } |
118 | | |
119 | | static int decode_registered_user_data_afd(H2645SEIAFD *h, GetByteContext *gb) |
120 | 4.07k | { |
121 | 4.07k | int flag; |
122 | | |
123 | 4.07k | if (bytestream2_get_bytes_left(gb) <= 0) |
124 | 205 | return AVERROR_INVALIDDATA; |
125 | | |
126 | 3.86k | flag = !!(bytestream2_get_byteu(gb) & 0x40); // active_format_flag |
127 | | |
128 | 3.86k | if (flag) { |
129 | 3.55k | if (bytestream2_get_bytes_left(gb) <= 0) |
130 | 182 | return AVERROR_INVALIDDATA; |
131 | 3.36k | h->active_format_description = bytestream2_get_byteu(gb) & 0xF; |
132 | 3.36k | h->present = 1; |
133 | 3.36k | } |
134 | | |
135 | 3.68k | return 0; |
136 | 3.86k | } |
137 | | |
138 | | static int decode_registered_user_data_closed_caption(H2645SEIA53Caption *h, |
139 | | GetByteContext *gb) |
140 | 21.7k | { |
141 | 21.7k | return ff_parse_a53_cc(&h->buf_ref, gb->buffer, |
142 | 21.7k | bytestream2_get_bytes_left(gb)); |
143 | 21.7k | } |
144 | | |
145 | | static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, |
146 | | enum AVCodecID codec_id, void *logctx) |
147 | 490k | { |
148 | 490k | int country_code, provider_code; |
149 | | |
150 | 490k | if (bytestream2_get_bytes_left(gb) < 3) |
151 | 19.8k | return AVERROR_INVALIDDATA; |
152 | | |
153 | 470k | country_code = bytestream2_get_byteu(gb); // itu_t_t35_country_code |
154 | 470k | if (country_code == 0xFF) { |
155 | 15.2k | if (bytestream2_get_bytes_left(gb) < 3) |
156 | 3.22k | return AVERROR_INVALIDDATA; |
157 | | |
158 | 12.0k | bytestream2_skipu(gb, 1); // itu_t_t35_country_code_extension_byte |
159 | 12.0k | } |
160 | | |
161 | | /* itu_t_t35_payload_byte follows */ |
162 | 467k | provider_code = bytestream2_get_be16u(gb); |
163 | | |
164 | 467k | if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_ATSC) { |
165 | 34.9k | uint32_t user_identifier; |
166 | | |
167 | 34.9k | if (bytestream2_get_bytes_left(gb) < 4) |
168 | 3.61k | return AVERROR_INVALIDDATA; |
169 | | |
170 | 31.3k | user_identifier = bytestream2_get_be32u(gb); |
171 | 31.3k | switch (user_identifier) { |
172 | 4.07k | case MKBETAG('D', 'T', 'G', '1'): // afd_data |
173 | 4.07k | return decode_registered_user_data_afd(&h->afd, gb); |
174 | 21.7k | case MKBETAG('G', 'A', '9', '4'): // closed captions |
175 | 21.7k | return decode_registered_user_data_closed_caption(&h->a53_caption, gb); |
176 | 5.47k | default: |
177 | 5.47k | av_log(logctx, AV_LOG_VERBOSE, |
178 | 5.47k | "Unsupported User Data Registered ITU-T T35 SEI message (atsc user_identifier = 0x%04x)\n", |
179 | 5.47k | user_identifier); |
180 | 5.47k | break; |
181 | 31.3k | } |
182 | 432k | } else if (country_code == ITU_T_T35_COUNTRY_CODE_UK && provider_code == ITU_T_T35_PROVIDER_CODE_VNOVA) { |
183 | 5.43k | if (bytestream2_get_bytes_left(gb) < 2) |
184 | 2.21k | return AVERROR_INVALIDDATA; |
185 | | |
186 | 3.22k | bytestream2_skipu(gb, 1); // user_data_type_code |
187 | 3.22k | return decode_registered_user_data_lcevc(&h->lcevc, gb); |
188 | 5.43k | } |
189 | 426k | #if CONFIG_HEVC_SEI |
190 | 426k | else if (country_code == ITU_T_T35_COUNTRY_CODE_CN && provider_code == ITU_T_T35_PROVIDER_CODE_HDR_VIVID) { |
191 | 55.4k | const uint16_t cuva_provider_oriented_code = 0x0005; |
192 | 55.4k | uint16_t provider_oriented_code; |
193 | | |
194 | 55.4k | if (!IS_HEVC(codec_id)) |
195 | 7.72k | goto unsupported_provider_code; |
196 | | |
197 | 47.7k | if (bytestream2_get_bytes_left(gb) < 2) |
198 | 481 | return AVERROR_INVALIDDATA; |
199 | | |
200 | 47.2k | provider_oriented_code = bytestream2_get_be16u(gb); |
201 | 47.2k | if (provider_oriented_code == cuva_provider_oriented_code) { |
202 | 44.7k | return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); |
203 | 44.7k | } |
204 | 371k | } else if(country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_SAMSUNG) { |
205 | | // A/341 Amendment - 2094-40 |
206 | 123k | const uint16_t smpte2094_40_provider_oriented_code = 0x0001; |
207 | 123k | const uint8_t smpte2094_40_application_identifier = 0x04; |
208 | 123k | uint16_t provider_oriented_code; |
209 | 123k | uint8_t application_identifier; |
210 | | |
211 | 123k | if (!IS_HEVC(codec_id)) |
212 | 2.35k | goto unsupported_provider_code; |
213 | | |
214 | 121k | if (bytestream2_get_bytes_left(gb) < 3) |
215 | 710 | return AVERROR_INVALIDDATA; |
216 | | |
217 | 120k | provider_oriented_code = bytestream2_get_be16u(gb); |
218 | 120k | application_identifier = bytestream2_get_byteu(gb); |
219 | 120k | if (provider_oriented_code == smpte2094_40_provider_oriented_code && |
220 | 117k | application_identifier == smpte2094_40_application_identifier) { |
221 | 113k | return decode_registered_user_data_dynamic_hdr_plus(&h->dynamic_hdr_plus, gb); |
222 | 113k | } |
223 | 247k | } else if (country_code == ITU_T_T35_COUNTRY_CODE_US && provider_code == ITU_T_T35_PROVIDER_CODE_AOM) { |
224 | 31.4k | const uint16_t aom_grain_provider_oriented_code = 0x0001; |
225 | 31.4k | uint16_t provider_oriented_code; |
226 | | |
227 | 31.4k | if (!IS_HEVC(codec_id)) |
228 | 417 | goto unsupported_provider_code; |
229 | | |
230 | 31.0k | if (bytestream2_get_bytes_left(gb) < 2) |
231 | 2.15k | return AVERROR_INVALIDDATA; |
232 | | |
233 | 28.8k | provider_oriented_code = bytestream2_get_byteu(gb); |
234 | 28.8k | if (provider_oriented_code == aom_grain_provider_oriented_code) { |
235 | 27.9k | return ff_aom_parse_film_grain_sets(&h->aom_film_grain, |
236 | 27.9k | gb->buffer, |
237 | 27.9k | bytestream2_get_bytes_left(gb)); |
238 | 27.9k | } |
239 | 28.8k | } |
240 | 215k | #endif |
241 | 215k | else { |
242 | 226k | unsupported_provider_code: |
243 | 226k | av_log(logctx, AV_LOG_VERBOSE, |
244 | 226k | "Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d, provider_code = %d)\n", |
245 | 226k | country_code, provider_code); |
246 | 226k | } |
247 | | |
248 | 242k | return 0; |
249 | 467k | } |
250 | | |
251 | | static int decode_unregistered_user_data(H2645SEIUnregistered *h, |
252 | | GetByteContext *gb, |
253 | | enum AVCodecID codec_id) |
254 | 86.0k | { |
255 | 86.0k | uint8_t *user_data; |
256 | 86.0k | int size = bytestream2_get_bytes_left(gb); |
257 | 86.0k | AVBufferRef *buf_ref, **tmp; |
258 | | |
259 | 86.0k | if (size < 16 || size >= INT_MAX - 1) |
260 | 11.8k | return AVERROR_INVALIDDATA; |
261 | | |
262 | 74.1k | tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref)); |
263 | 74.1k | if (!tmp) |
264 | 0 | return AVERROR(ENOMEM); |
265 | 74.1k | h->buf_ref = tmp; |
266 | | |
267 | 74.1k | buf_ref = av_buffer_alloc(size + 1); |
268 | 74.1k | if (!buf_ref) |
269 | 0 | return AVERROR(ENOMEM); |
270 | 74.1k | user_data = buf_ref->data; |
271 | | |
272 | 74.1k | bytestream2_get_bufferu(gb, user_data, size); |
273 | 74.1k | user_data[size] = 0; |
274 | 74.1k | buf_ref->size = size; |
275 | 74.1k | h->buf_ref[h->nb_buf_ref++] = buf_ref; |
276 | | |
277 | 74.1k | if (IS_H264(codec_id)) { |
278 | 61.5k | int e, build; |
279 | 61.5k | e = sscanf(user_data + 16, "x264 - core %d", &build); |
280 | 61.5k | if (e == 1 && build > 0) |
281 | 11.6k | h->x264_build = build; |
282 | 61.5k | if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16)) |
283 | 519 | h->x264_build = 67; |
284 | 61.5k | } |
285 | | |
286 | 74.1k | return 0; |
287 | 74.1k | } |
288 | | |
289 | | static int decode_display_orientation(H2645SEIDisplayOrientation *h, |
290 | | GetBitContext *gb) |
291 | 48.1k | { |
292 | 48.1k | h->present = !get_bits1(gb); // display_orientation_cancel_flag |
293 | | |
294 | 48.1k | if (h->present) { |
295 | 37.3k | h->hflip = get_bits1(gb); // hor_flip |
296 | 37.3k | h->vflip = get_bits1(gb); // ver_flip |
297 | | |
298 | 37.3k | h->anticlockwise_rotation = get_bits(gb, 16); |
299 | | // This is followed by display_orientation_repetition_period |
300 | | // and display_orientation_extension_flag for H.264 |
301 | | // and by display_orientation_persistence_flag for HEVC. |
302 | 37.3k | } |
303 | | |
304 | 48.1k | return 0; |
305 | 48.1k | } |
306 | | |
307 | | static int decode_frame_packing_arrangement(H2645SEIFramePacking *h, |
308 | | GetBitContext *gb, |
309 | | enum AVCodecID codec_id) |
310 | 201k | { |
311 | 201k | h->arrangement_id = get_ue_golomb_long(gb); |
312 | 201k | h->arrangement_cancel_flag = get_bits1(gb); |
313 | 201k | h->present = !h->arrangement_cancel_flag; |
314 | | |
315 | 201k | if (h->present) { |
316 | 113k | h->arrangement_type = get_bits(gb, 7); |
317 | 113k | h->quincunx_sampling_flag = get_bits1(gb); |
318 | 113k | h->content_interpretation_type = get_bits(gb, 6); |
319 | | |
320 | | // spatial_flipping_flag, frame0_flipped_flag, field_views_flag |
321 | 113k | skip_bits(gb, 3); |
322 | 113k | h->current_frame_is_frame0_flag = get_bits1(gb); |
323 | | // frame0_self_contained_flag, frame1_self_contained_flag |
324 | 113k | skip_bits(gb, 2); |
325 | | |
326 | 113k | if (!h->quincunx_sampling_flag && h->arrangement_type != 5) |
327 | 60.7k | skip_bits(gb, 16); // frame[01]_grid_position_[xy] |
328 | 113k | skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte |
329 | 113k | if (IS_H264(codec_id)) |
330 | 92.8k | h->arrangement_repetition_period = get_ue_golomb_long(gb); |
331 | 20.7k | else |
332 | 20.7k | skip_bits1(gb); // frame_packing_arrangement_persistence_flag |
333 | 113k | } |
334 | | // H.264: frame_packing_arrangement_extension_flag, |
335 | | // HEVC: upsampled_aspect_ratio_flag |
336 | 201k | skip_bits1(gb); |
337 | | |
338 | 201k | return 0; |
339 | 201k | } |
340 | | |
341 | | static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s, |
342 | | GetByteContext *gb) |
343 | 24.2k | { |
344 | 24.2k | if (bytestream2_get_bytes_left(gb) < 1) |
345 | 15.9k | return AVERROR_INVALIDDATA; |
346 | | |
347 | 8.32k | s->present = 1; |
348 | 8.32k | s->preferred_transfer_characteristics = bytestream2_get_byteu(gb); |
349 | | |
350 | 8.32k | return 0; |
351 | 24.2k | } |
352 | | |
353 | | static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s, |
354 | | GetByteContext *gb) |
355 | 39.5k | { |
356 | 39.5k | static const uint16_t max_ambient_light_value = 50000; |
357 | | |
358 | 39.5k | if (bytestream2_get_bytes_left(gb) < 8) |
359 | 6.05k | return AVERROR_INVALIDDATA; |
360 | | |
361 | 33.5k | s->ambient_illuminance = bytestream2_get_be32u(gb); |
362 | 33.5k | if (!s->ambient_illuminance) |
363 | 5.13k | return AVERROR_INVALIDDATA; |
364 | | |
365 | 28.3k | s->ambient_light_x = bytestream2_get_be16u(gb); |
366 | 28.3k | if (s->ambient_light_x > max_ambient_light_value) |
367 | 6.50k | return AVERROR_INVALIDDATA; |
368 | | |
369 | 21.8k | s->ambient_light_y = bytestream2_get_be16u(gb); |
370 | 21.8k | if (s->ambient_light_y > max_ambient_light_value) |
371 | 5.29k | return AVERROR_INVALIDDATA; |
372 | | |
373 | 16.5k | s->present = 1; |
374 | | |
375 | 16.5k | return 0; |
376 | 21.8k | } |
377 | | |
378 | | static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h, |
379 | | enum AVCodecID codec_id, GetBitContext *gb) |
380 | 238k | { |
381 | 238k | h->present = !get_bits1(gb); // film_grain_characteristics_cancel_flag |
382 | | |
383 | 238k | if (h->present) { |
384 | 229k | memset(h, 0, sizeof(*h)); |
385 | 229k | h->model_id = get_bits(gb, 2); |
386 | 229k | h->separate_colour_description_present_flag = get_bits1(gb); |
387 | 229k | if (h->separate_colour_description_present_flag) { |
388 | 177k | h->bit_depth_luma = get_bits(gb, 3) + 8; |
389 | 177k | h->bit_depth_chroma = get_bits(gb, 3) + 8; |
390 | 177k | h->full_range = get_bits1(gb); |
391 | 177k | h->color_primaries = get_bits(gb, 8); |
392 | 177k | h->transfer_characteristics = get_bits(gb, 8); |
393 | 177k | h->matrix_coeffs = get_bits(gb, 8); |
394 | 177k | } |
395 | 229k | h->blending_mode_id = get_bits(gb, 2); |
396 | 229k | h->log2_scale_factor = get_bits(gb, 4); |
397 | 917k | for (int c = 0; c < 3; c++) |
398 | 687k | h->comp_model_present_flag[c] = get_bits1(gb); |
399 | 891k | for (int c = 0; c < 3; c++) { |
400 | 673k | if (h->comp_model_present_flag[c]) { |
401 | 213k | h->num_intensity_intervals[c] = get_bits(gb, 8) + 1; |
402 | 213k | h->num_model_values[c] = get_bits(gb, 3) + 1; |
403 | 213k | if (h->num_model_values[c] > 6) |
404 | 11.3k | return AVERROR_INVALIDDATA; |
405 | 13.5M | for (int i = 0; i < h->num_intensity_intervals[c]; i++) { |
406 | 13.3M | h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8); |
407 | 13.3M | h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8); |
408 | 54.3M | for (int j = 0; j < h->num_model_values[c]; j++) |
409 | 40.9M | h->comp_model_value[c][i][j] = get_se_golomb_long(gb); |
410 | 13.3M | } |
411 | 201k | } |
412 | 673k | } |
413 | 217k | if (!IS_H264(codec_id)) |
414 | 104k | h->persistence_flag = get_bits1(gb); |
415 | 113k | else |
416 | 113k | h->repetition_period = get_ue_golomb_long(gb); |
417 | | |
418 | 217k | h->present = 1; |
419 | 217k | } |
420 | | |
421 | 227k | return 0; |
422 | 238k | } |
423 | | |
424 | | static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, |
425 | | GetByteContext *gb) |
426 | 50.5k | { |
427 | 50.5k | int i; |
428 | | |
429 | 50.5k | if (bytestream2_get_bytes_left(gb) < 24) |
430 | 10.4k | return AVERROR_INVALIDDATA; |
431 | | |
432 | | // Mastering primaries |
433 | 160k | for (i = 0; i < 3; i++) { |
434 | 120k | s->display_primaries[i][0] = bytestream2_get_be16u(gb); |
435 | 120k | s->display_primaries[i][1] = bytestream2_get_be16u(gb); |
436 | 120k | } |
437 | | // White point (x, y) |
438 | 40.0k | s->white_point[0] = bytestream2_get_be16u(gb); |
439 | 40.0k | s->white_point[1] = bytestream2_get_be16u(gb); |
440 | | |
441 | | // Max and min luminance of mastering display |
442 | 40.0k | s->max_luminance = bytestream2_get_be32u(gb); |
443 | 40.0k | s->min_luminance = bytestream2_get_be32u(gb); |
444 | | |
445 | | // As this SEI message comes before the first frame that references it, |
446 | | // initialize the flag to 2 and decrement on IRAP access unit so it |
447 | | // persists for the coded video sequence (e.g., between two IRAPs) |
448 | 40.0k | s->present = 2; |
449 | | |
450 | 40.0k | return 0; |
451 | 50.5k | } |
452 | | |
453 | | static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, |
454 | | GetByteContext *gb) |
455 | 31.3k | { |
456 | 31.3k | if (bytestream2_get_bytes_left(gb) < 4) |
457 | 7.46k | return AVERROR_INVALIDDATA; |
458 | | |
459 | | // Max and average light levels |
460 | 23.8k | s->max_content_light_level = bytestream2_get_be16u(gb); |
461 | 23.8k | s->max_pic_average_light_level = bytestream2_get_be16u(gb); |
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 | 23.8k | s->present = 2; |
466 | | |
467 | 23.8k | return 0; |
468 | 31.3k | } |
469 | | |
470 | | int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, |
471 | | enum AVCodecID codec_id, GetBitContext *gb, |
472 | | GetByteContext *gbyte, void *logctx) |
473 | 5.15M | { |
474 | 5.15M | switch (type) { |
475 | 490k | case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: |
476 | 490k | return decode_registered_user_data(h, gbyte, codec_id, logctx); |
477 | 86.0k | case SEI_TYPE_USER_DATA_UNREGISTERED: |
478 | 86.0k | return decode_unregistered_user_data(&h->unregistered, gbyte, codec_id); |
479 | 48.1k | case SEI_TYPE_DISPLAY_ORIENTATION: |
480 | 48.1k | return decode_display_orientation(&h->display_orientation, gb); |
481 | 238k | case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS: |
482 | 238k | av_refstruct_unref(&h->film_grain_characteristics); |
483 | 238k | h->film_grain_characteristics = av_refstruct_allocz(sizeof(*h->film_grain_characteristics)); |
484 | 238k | if (!h->film_grain_characteristics) |
485 | 0 | return AVERROR(ENOMEM); |
486 | 238k | return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb); |
487 | 201k | case SEI_TYPE_FRAME_PACKING_ARRANGEMENT: |
488 | 201k | return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id); |
489 | 24.2k | case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: |
490 | 24.2k | return decode_alternative_transfer(&h->alternative_transfer, gbyte); |
491 | 39.5k | case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT: |
492 | 39.5k | return decode_ambient_viewing_environment(&h->ambient_viewing_environment, |
493 | 39.5k | gbyte); |
494 | 50.5k | case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: |
495 | 50.5k | return decode_nal_sei_mastering_display_info(&h->mastering_display, |
496 | 50.5k | gbyte); |
497 | 31.3k | case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: |
498 | 31.3k | return decode_nal_sei_content_light_info(&h->content_light, gbyte); |
499 | 3.94M | default: |
500 | 3.94M | return FF_H2645_SEI_MESSAGE_UNHANDLED; |
501 | 5.15M | } |
502 | 5.15M | } |
503 | | |
504 | | int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src) |
505 | 2.34M | { |
506 | 2.34M | int ret = av_buffer_replace(&dst->a53_caption.buf_ref, |
507 | 2.34M | src->a53_caption.buf_ref); |
508 | 2.34M | if (ret < 0) |
509 | 0 | return ret; |
510 | | |
511 | 2.34M | for (unsigned i = 0; i < dst->unregistered.nb_buf_ref; i++) |
512 | 0 | av_buffer_unref(&dst->unregistered.buf_ref[i]); |
513 | 2.34M | dst->unregistered.nb_buf_ref = 0; |
514 | | |
515 | 2.34M | ret = av_buffer_replace(&dst->lcevc.info, src->lcevc.info); |
516 | 2.34M | if (ret < 0) |
517 | 0 | return ret; |
518 | | |
519 | 2.34M | if (src->unregistered.nb_buf_ref) { |
520 | 0 | ret = av_reallocp_array(&dst->unregistered.buf_ref, |
521 | 0 | src->unregistered.nb_buf_ref, |
522 | 0 | sizeof(*dst->unregistered.buf_ref)); |
523 | 0 | if (ret < 0) |
524 | 0 | return ret; |
525 | | |
526 | 0 | for (unsigned i = 0; i < src->unregistered.nb_buf_ref; i++) { |
527 | 0 | dst->unregistered.buf_ref[i] = av_buffer_ref(src->unregistered.buf_ref[i]); |
528 | 0 | if (!dst->unregistered.buf_ref[i]) |
529 | 0 | return AVERROR(ENOMEM); |
530 | 0 | dst->unregistered.nb_buf_ref++; |
531 | 0 | } |
532 | 0 | } |
533 | | |
534 | 21.0M | for (unsigned i = 0; i < FF_ARRAY_ELEMS(dst->aom_film_grain.sets); i++) { |
535 | 18.7M | ret = av_buffer_replace(&dst->aom_film_grain.sets[i], |
536 | 18.7M | src->aom_film_grain.sets[i]); |
537 | 18.7M | if (ret < 0) |
538 | 0 | return ret; |
539 | 18.7M | } |
540 | 2.34M | dst->aom_film_grain.enable = src->aom_film_grain.enable; |
541 | | |
542 | 2.34M | dst->ambient_viewing_environment = src->ambient_viewing_environment; |
543 | 2.34M | dst->mastering_display = src->mastering_display; |
544 | 2.34M | dst->content_light = src->content_light; |
545 | | |
546 | 2.34M | av_refstruct_replace(&dst->film_grain_characteristics, |
547 | 2.34M | src->film_grain_characteristics); |
548 | | |
549 | 2.34M | return 0; |
550 | 2.34M | } |
551 | | |
552 | | static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id) |
553 | 38.4k | { |
554 | 38.4k | if (IS_H264(codec_id)) |
555 | 34.1k | return type <= SEI_FPA_H264_TYPE_2D && |
556 | 32.9k | type >= SEI_FPA_H264_TYPE_CHECKERBOARD; |
557 | 4.29k | else |
558 | 4.29k | return type <= SEI_FPA_TYPE_INTERLEAVE_TEMPORAL && |
559 | 2.46k | type >= SEI_FPA_TYPE_SIDE_BY_SIDE; |
560 | 38.4k | } |
561 | | |
562 | | static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, |
563 | | AVFrameSideData ***sd, int *nb_sd) |
564 | 3.69M | { |
565 | 3.69M | int ret; |
566 | | |
567 | 3.70M | for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) { |
568 | 9.89k | H2645SEIUnregistered *unreg = &sei->unregistered; |
569 | | |
570 | 9.89k | if (unreg->buf_ref[i]) { |
571 | 9.89k | AVFrameSideData *entry = |
572 | 9.89k | av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, |
573 | 9.89k | &unreg->buf_ref[i], 0); |
574 | 9.89k | if (!entry) |
575 | 0 | av_buffer_unref(&unreg->buf_ref[i]); |
576 | 9.89k | } |
577 | 9.89k | } |
578 | 3.69M | sei->unregistered.nb_buf_ref = 0; |
579 | | |
580 | 3.69M | if (sei->ambient_viewing_environment.present) { |
581 | 998 | H2645SEIAmbientViewingEnvironment *env = &sei->ambient_viewing_environment; |
582 | 998 | AVBufferRef *buf; |
583 | 998 | size_t size; |
584 | | |
585 | 998 | AVAmbientViewingEnvironment *dst_env = |
586 | 998 | av_ambient_viewing_environment_alloc(&size); |
587 | 998 | if (!dst_env) |
588 | 0 | return AVERROR(ENOMEM); |
589 | | |
590 | 998 | buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0); |
591 | 998 | if (!buf) { |
592 | 0 | av_free(dst_env); |
593 | 0 | return AVERROR(ENOMEM); |
594 | 0 | } |
595 | | |
596 | 998 | ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd, |
597 | 998 | AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf); |
598 | | |
599 | 998 | if (ret < 0) |
600 | 0 | return ret; |
601 | | |
602 | 998 | dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000); |
603 | 998 | dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000); |
604 | 998 | dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000); |
605 | 998 | } |
606 | | |
607 | 3.69M | if (sei->mastering_display.present) { |
608 | | // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b |
609 | 11.2k | const int mapping[3] = {2, 0, 1}; |
610 | 11.2k | const int chroma_den = 50000; |
611 | 11.2k | const int luma_den = 10000; |
612 | 11.2k | int i; |
613 | 11.2k | AVMasteringDisplayMetadata *metadata; |
614 | | |
615 | 11.2k | ret = ff_decode_mastering_display_new_ext(avctx, sd, nb_sd, &metadata); |
616 | 11.2k | if (ret < 0) |
617 | 0 | return ret; |
618 | | |
619 | 11.2k | if (metadata) { |
620 | 11.2k | metadata->has_luminance = 1; |
621 | 11.2k | metadata->has_primaries = 1; |
622 | | |
623 | 45.0k | for (i = 0; i < 3; i++) { |
624 | 33.8k | const int j = mapping[i]; |
625 | 33.8k | metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; |
626 | 33.8k | metadata->display_primaries[i][0].den = chroma_den; |
627 | 33.8k | metadata->has_primaries &= sei->mastering_display.display_primaries[j][0] >= 5 && |
628 | 33.5k | sei->mastering_display.display_primaries[j][0] <= 37000; |
629 | | |
630 | 33.8k | metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; |
631 | 33.8k | metadata->display_primaries[i][1].den = chroma_den; |
632 | 33.8k | metadata->has_primaries &= sei->mastering_display.display_primaries[j][1] >= 5 && |
633 | 30.3k | sei->mastering_display.display_primaries[j][1] <= 42000; |
634 | 33.8k | } |
635 | 11.2k | metadata->white_point[0].num = sei->mastering_display.white_point[0]; |
636 | 11.2k | metadata->white_point[0].den = chroma_den; |
637 | 11.2k | metadata->has_primaries &= sei->mastering_display.white_point[0] >= 5 && |
638 | 10.1k | sei->mastering_display.white_point[0] <= 37000; |
639 | | |
640 | 11.2k | metadata->white_point[1].num = sei->mastering_display.white_point[1]; |
641 | 11.2k | metadata->white_point[1].den = chroma_den; |
642 | 11.2k | metadata->has_primaries &= sei->mastering_display.white_point[1] >= 5 && |
643 | 7.77k | sei->mastering_display.white_point[1] <= 42000; |
644 | | |
645 | 11.2k | metadata->max_luminance.num = sei->mastering_display.max_luminance; |
646 | 11.2k | metadata->max_luminance.den = luma_den; |
647 | 11.2k | metadata->has_luminance &= sei->mastering_display.max_luminance >= 50000 && |
648 | 10.4k | sei->mastering_display.max_luminance <= 100000000; |
649 | | |
650 | 11.2k | metadata->min_luminance.num = sei->mastering_display.min_luminance; |
651 | 11.2k | metadata->min_luminance.den = luma_den; |
652 | 11.2k | metadata->has_luminance &= sei->mastering_display.min_luminance <= 50000 && |
653 | 6.06k | sei->mastering_display.min_luminance < |
654 | 6.06k | sei->mastering_display.max_luminance; |
655 | | |
656 | | /* Real (blu-ray) releases in the wild come with minimum luminance |
657 | | * values of 0.000 cd/m2, so permit this edge case */ |
658 | 11.2k | if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) |
659 | 0 | metadata->has_luminance &= sei->mastering_display.min_luminance >= 1; |
660 | | |
661 | 11.2k | if (metadata->has_luminance || metadata->has_primaries) |
662 | 6.24k | av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); |
663 | 11.2k | if (metadata->has_primaries) { |
664 | 6.24k | av_log(avctx, AV_LOG_DEBUG, |
665 | 6.24k | "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", |
666 | 6.24k | av_q2d(metadata->display_primaries[0][0]), |
667 | 6.24k | av_q2d(metadata->display_primaries[0][1]), |
668 | 6.24k | av_q2d(metadata->display_primaries[1][0]), |
669 | 6.24k | av_q2d(metadata->display_primaries[1][1]), |
670 | 6.24k | av_q2d(metadata->display_primaries[2][0]), |
671 | 6.24k | av_q2d(metadata->display_primaries[2][1]), |
672 | 6.24k | av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); |
673 | 6.24k | } |
674 | 11.2k | if (metadata->has_luminance) { |
675 | 344 | av_log(avctx, AV_LOG_DEBUG, |
676 | 344 | "min_luminance=%f, max_luminance=%f\n", |
677 | 344 | av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); |
678 | 344 | } |
679 | 11.2k | } |
680 | 11.2k | } |
681 | | |
682 | 3.69M | if (sei->content_light.present) { |
683 | 1.27k | AVContentLightMetadata *metadata; |
684 | | |
685 | 1.27k | ret = ff_decode_content_light_new_ext(avctx, sd, nb_sd, &metadata); |
686 | 1.27k | if (ret < 0) |
687 | 0 | return ret; |
688 | | |
689 | 1.27k | if (metadata) { |
690 | 1.27k | metadata->MaxCLL = sei->content_light.max_content_light_level; |
691 | 1.27k | metadata->MaxFALL = sei->content_light.max_pic_average_light_level; |
692 | | |
693 | 1.27k | av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); |
694 | 1.27k | av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", |
695 | 1.27k | metadata->MaxCLL, metadata->MaxFALL); |
696 | 1.27k | } |
697 | 1.27k | } |
698 | | |
699 | 3.69M | return 0; |
700 | 3.69M | } |
701 | | |
702 | | int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, |
703 | | enum AVCodecID codec_id, |
704 | | AVCodecContext *avctx, const H2645VUI *vui, |
705 | | unsigned bit_depth_luma, unsigned bit_depth_chroma, |
706 | | int seed) |
707 | 3.69M | { |
708 | 3.69M | H2645SEIFramePacking *fp = &sei->frame_packing; |
709 | 3.69M | int ret; |
710 | | |
711 | 3.69M | if (fp->present && |
712 | 38.4k | is_frame_packing_type_valid(fp->arrangement_type, codec_id) && |
713 | 34.9k | fp->content_interpretation_type > 0 && |
714 | 14.9k | fp->content_interpretation_type < 3) { |
715 | 13.5k | AVStereo3D *stereo = av_stereo3d_create_side_data(frame); |
716 | | |
717 | 13.5k | if (!stereo) |
718 | 0 | return AVERROR(ENOMEM); |
719 | | |
720 | 13.5k | switch (fp->arrangement_type) { |
721 | 0 | #if CONFIG_H264_SEI |
722 | 6.43k | case SEI_FPA_H264_TYPE_CHECKERBOARD: |
723 | 6.43k | stereo->type = AV_STEREO3D_CHECKERBOARD; |
724 | 6.43k | break; |
725 | 574 | case SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN: |
726 | 574 | stereo->type = AV_STEREO3D_COLUMNS; |
727 | 574 | break; |
728 | 622 | case SEI_FPA_H264_TYPE_INTERLEAVE_ROW: |
729 | 622 | stereo->type = AV_STEREO3D_LINES; |
730 | 622 | break; |
731 | 0 | #endif |
732 | 1.88k | case SEI_FPA_TYPE_SIDE_BY_SIDE: |
733 | 1.88k | if (fp->quincunx_sampling_flag) |
734 | 349 | stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX; |
735 | 1.53k | else |
736 | 1.53k | stereo->type = AV_STEREO3D_SIDEBYSIDE; |
737 | 1.88k | break; |
738 | 1.23k | case SEI_FPA_TYPE_TOP_BOTTOM: |
739 | 1.23k | stereo->type = AV_STEREO3D_TOPBOTTOM; |
740 | 1.23k | break; |
741 | 2.42k | case SEI_FPA_TYPE_INTERLEAVE_TEMPORAL: |
742 | 2.42k | stereo->type = AV_STEREO3D_FRAMESEQUENCE; |
743 | 2.42k | break; |
744 | 0 | #if CONFIG_H264_SEI |
745 | 363 | case SEI_FPA_H264_TYPE_2D: |
746 | 363 | stereo->type = AV_STEREO3D_2D; |
747 | 363 | break; |
748 | 13.5k | #endif |
749 | 13.5k | } |
750 | | |
751 | 13.5k | if (fp->content_interpretation_type == 2) |
752 | 11.5k | stereo->flags = AV_STEREO3D_FLAG_INVERT; |
753 | | |
754 | 13.5k | if (fp->arrangement_type == SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) { |
755 | 2.42k | if (fp->current_frame_is_frame0_flag) |
756 | 1.40k | stereo->view = AV_STEREO3D_VIEW_LEFT; |
757 | 1.01k | else |
758 | 1.01k | stereo->view = AV_STEREO3D_VIEW_RIGHT; |
759 | 2.42k | } |
760 | 13.5k | } |
761 | | |
762 | 3.69M | if (sei->display_orientation.present && |
763 | 35.2k | (sei->display_orientation.anticlockwise_rotation || |
764 | 27.5k | sei->display_orientation.hflip || |
765 | 23.9k | sei->display_orientation.vflip)) { |
766 | 23.9k | H2645SEIDisplayOrientation *o = &sei->display_orientation; |
767 | 23.9k | double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16); |
768 | 23.9k | AVFrameSideData *rotation = av_frame_new_side_data(frame, |
769 | 23.9k | AV_FRAME_DATA_DISPLAYMATRIX, |
770 | 23.9k | sizeof(int32_t) * 9); |
771 | 23.9k | if (!rotation) |
772 | 0 | return AVERROR(ENOMEM); |
773 | | |
774 | | /* av_display_rotation_set() expects the angle in the clockwise |
775 | | * direction, hence the first minus. |
776 | | * The below code applies the flips after the rotation, yet |
777 | | * the H.2645 specs require flipping to be applied first. |
778 | | * Because of R O(phi) = O(-phi) R (where R is flipping around |
779 | | * an arbitatry axis and O(phi) is the proper rotation by phi) |
780 | | * we can create display matrices as desired by negating |
781 | | * the degree once for every flip applied. */ |
782 | 23.9k | angle = -angle * (1 - 2 * !!o->hflip) * (1 - 2 * !!o->vflip); |
783 | 23.9k | av_display_rotation_set((int32_t *)rotation->data, angle); |
784 | 23.9k | av_display_matrix_flip((int32_t *)rotation->data, |
785 | 23.9k | o->hflip, o->vflip); |
786 | 23.9k | } |
787 | | |
788 | 3.69M | if (sei->a53_caption.buf_ref) { |
789 | 499 | H2645SEIA53Caption *a53 = &sei->a53_caption; |
790 | 499 | AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, a53->buf_ref); |
791 | 499 | if (!sd) |
792 | 0 | av_buffer_unref(&a53->buf_ref); |
793 | 499 | a53->buf_ref = NULL; |
794 | 499 | #if FF_API_CODEC_PROPS |
795 | 499 | FF_DISABLE_DEPRECATION_WARNINGS |
796 | 499 | avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; |
797 | 499 | FF_ENABLE_DEPRECATION_WARNINGS |
798 | 499 | #endif |
799 | 499 | } |
800 | | |
801 | 3.69M | ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data); |
802 | 3.69M | if (ret < 0) |
803 | 0 | return ret; |
804 | | |
805 | 3.69M | if (sei->afd.present) { |
806 | 181 | AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_AFD, |
807 | 181 | sizeof(uint8_t)); |
808 | | |
809 | 181 | if (sd) { |
810 | 181 | *sd->data = sei->afd.active_format_description; |
811 | 181 | sei->afd.present = 0; |
812 | 181 | } |
813 | 181 | } |
814 | | |
815 | 3.69M | if (sei->lcevc.info) { |
816 | 0 | HEVCSEILCEVC *lcevc = &sei->lcevc; |
817 | 0 | ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_LCEVC, &lcevc->info); |
818 | 0 | if (ret < 0) |
819 | 0 | return ret; |
820 | 0 | } |
821 | | |
822 | 3.69M | if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) { |
823 | 11.8k | H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics; |
824 | 11.8k | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); |
825 | 11.8k | AVFilmGrainH274Params *h274; |
826 | | |
827 | 11.8k | if (!fgp) |
828 | 0 | return AVERROR(ENOMEM); |
829 | | |
830 | 11.8k | fgp->type = AV_FILM_GRAIN_PARAMS_H274; |
831 | 11.8k | h274 = &fgp->codec.h274; |
832 | | |
833 | 11.8k | fgp->seed = seed; |
834 | 11.8k | fgp->width = frame->width; |
835 | 11.8k | fgp->height = frame->height; |
836 | | |
837 | | /* H.274 mandates film grain be applied to 4:4:4 frames */ |
838 | 11.8k | fgp->subsampling_x = fgp->subsampling_y = 0; |
839 | | |
840 | 11.8k | h274->model_id = fgc->model_id; |
841 | 11.8k | if (IS_VVC(codec_id) || fgc->separate_colour_description_present_flag) { |
842 | 2.41k | fgp->bit_depth_luma = fgc->bit_depth_luma; |
843 | 2.41k | fgp->bit_depth_chroma = fgc->bit_depth_chroma; |
844 | 2.41k | fgp->color_range = fgc->full_range + 1; |
845 | 2.41k | fgp->color_primaries = fgc->color_primaries; |
846 | 2.41k | fgp->color_trc = fgc->transfer_characteristics; |
847 | 2.41k | fgp->color_space = fgc->matrix_coeffs; |
848 | 9.40k | } else { |
849 | 9.40k | fgp->bit_depth_luma = bit_depth_luma; |
850 | 9.40k | fgp->bit_depth_chroma = bit_depth_chroma; |
851 | 9.40k | if (vui->video_signal_type_present_flag) |
852 | 733 | fgp->color_range = vui->video_full_range_flag + 1; |
853 | 9.40k | if (vui->colour_description_present_flag) { |
854 | 593 | fgp->color_primaries = vui->colour_primaries; |
855 | 593 | fgp->color_trc = vui->transfer_characteristics; |
856 | 593 | fgp->color_space = vui->matrix_coeffs; |
857 | 593 | } |
858 | 9.40k | } |
859 | 11.8k | h274->blending_mode_id = fgc->blending_mode_id; |
860 | 11.8k | h274->log2_scale_factor = fgc->log2_scale_factor; |
861 | | |
862 | 11.8k | memcpy(&h274->component_model_present, &fgc->comp_model_present_flag, |
863 | 11.8k | sizeof(h274->component_model_present)); |
864 | 11.8k | memcpy(&h274->num_intensity_intervals, &fgc->num_intensity_intervals, |
865 | 11.8k | sizeof(h274->num_intensity_intervals)); |
866 | 11.8k | memcpy(&h274->num_model_values, &fgc->num_model_values, |
867 | 11.8k | sizeof(h274->num_model_values)); |
868 | 11.8k | memcpy(&h274->intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound, |
869 | 11.8k | sizeof(h274->intensity_interval_lower_bound)); |
870 | 11.8k | memcpy(&h274->intensity_interval_upper_bound, &fgc->intensity_interval_upper_bound, |
871 | 11.8k | sizeof(h274->intensity_interval_upper_bound)); |
872 | 11.8k | memcpy(&h274->comp_model_value, &fgc->comp_model_value, |
873 | 11.8k | sizeof(h274->comp_model_value)); |
874 | | |
875 | 11.8k | if (IS_H264(codec_id)) |
876 | 10.2k | fgc->present = !!fgc->repetition_period; |
877 | 1.58k | else |
878 | 1.58k | fgc->present = fgc->persistence_flag; |
879 | | |
880 | 11.8k | #if FF_API_CODEC_PROPS |
881 | 11.8k | FF_DISABLE_DEPRECATION_WARNINGS |
882 | 11.8k | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; |
883 | 11.8k | FF_ENABLE_DEPRECATION_WARNINGS |
884 | 11.8k | #endif |
885 | 11.8k | } |
886 | | |
887 | 3.69M | #if CONFIG_HEVC_SEI |
888 | 3.69M | ret = ff_aom_attach_film_grain_sets(&sei->aom_film_grain, frame); |
889 | 3.69M | if (ret < 0) |
890 | 0 | return ret; |
891 | 3.69M | #endif |
892 | | |
893 | 3.69M | return 0; |
894 | 3.69M | } |
895 | | |
896 | | int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei) |
897 | 348 | { |
898 | 348 | return h2645_sei_to_side_data(avctx, sei, &avctx->decoded_side_data, |
899 | 348 | &avctx->nb_decoded_side_data); |
900 | 348 | } |
901 | | |
902 | | void ff_h2645_sei_reset(H2645SEI *s) |
903 | 14.1M | { |
904 | 14.1M | av_buffer_unref(&s->a53_caption.buf_ref); |
905 | | |
906 | 14.2M | for (unsigned i = 0; i < s->unregistered.nb_buf_ref; i++) |
907 | 64.2k | av_buffer_unref(&s->unregistered.buf_ref[i]); |
908 | 14.1M | s->unregistered.nb_buf_ref = 0; |
909 | 14.1M | av_freep(&s->unregistered.buf_ref); |
910 | 14.1M | av_buffer_unref(&s->dynamic_hdr_plus.info); |
911 | 14.1M | av_buffer_unref(&s->dynamic_hdr_vivid.info); |
912 | 14.1M | av_buffer_unref(&s->lcevc.info); |
913 | | |
914 | 14.1M | s->ambient_viewing_environment.present = 0; |
915 | 14.1M | s->mastering_display.present = 0; |
916 | 14.1M | s->content_light.present = 0; |
917 | | |
918 | 14.1M | av_refstruct_unref(&s->film_grain_characteristics); |
919 | 14.1M | ff_aom_uninit_film_grain_params(&s->aom_film_grain); |
920 | 14.1M | } |