Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Common H.264 and HEVC Supplementary Enhancement Information messages | ||
3 | * | ||
4 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * Copyright (C) 2012 - 2013 Guillaume Martres | ||
6 | * Copyright (C) 2012 - 2013 Gildas Cocherel | ||
7 | * Copyright (C) 2013 Vittorio Giovara | ||
8 | * | ||
9 | * This file is part of FFmpeg. | ||
10 | * | ||
11 | * FFmpeg is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU Lesser General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2.1 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * FFmpeg is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public | ||
22 | * License along with FFmpeg; if not, write to the Free Software | ||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
24 | */ | ||
25 | |||
26 | #include "config_components.h" | ||
27 | |||
28 | #include "libavutil/ambient_viewing_environment.h" | ||
29 | #include "libavutil/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/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 | 6 | static int decode_registered_user_data_dynamic_hdr_plus(HEVCSEIDynamicHDRPlus *s, | |
52 | GetByteContext *gb) | ||
53 | { | ||
54 | size_t meta_size; | ||
55 | int err; | ||
56 | 6 | AVDynamicHDRPlus *metadata = av_dynamic_hdr_plus_alloc(&meta_size); | |
57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!metadata) |
58 | ✗ | return AVERROR(ENOMEM); | |
59 | |||
60 | 6 | err = av_dynamic_hdr_plus_from_t35(metadata, gb->buffer, | |
61 | 6 | bytestream2_get_bytes_left(gb)); | |
62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (err < 0) { |
63 | ✗ | av_free(metadata); | |
64 | ✗ | return err; | |
65 | } | ||
66 | |||
67 | 6 | av_buffer_unref(&s->info); | |
68 | 6 | s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0); | |
69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!s->info) { |
70 | ✗ | av_free(metadata); | |
71 | ✗ | return AVERROR(ENOMEM); | |
72 | } | ||
73 | |||
74 | 6 | return 0; | |
75 | } | ||
76 | |||
77 | 3 | static int decode_registered_user_data_dynamic_hdr_vivid(HEVCSEIDynamicHDRVivid *s, | |
78 | GetByteContext *gb) | ||
79 | { | ||
80 | size_t meta_size; | ||
81 | int err; | ||
82 | 3 | AVDynamicHDRVivid *metadata = av_dynamic_hdr_vivid_alloc(&meta_size); | |
83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!metadata) |
84 | ✗ | return AVERROR(ENOMEM); | |
85 | |||
86 | 3 | err = ff_parse_itu_t_t35_to_dynamic_hdr_vivid(metadata, | |
87 | gb->buffer, bytestream2_get_bytes_left(gb)); | ||
88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (err < 0) { |
89 | ✗ | av_free(metadata); | |
90 | ✗ | return err; | |
91 | } | ||
92 | |||
93 | 3 | av_buffer_unref(&s->info); | |
94 | 3 | s->info = av_buffer_create((uint8_t *)metadata, meta_size, NULL, NULL, 0); | |
95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!s->info) { |
96 | ✗ | av_free(metadata); | |
97 | ✗ | return AVERROR(ENOMEM); | |
98 | } | ||
99 | |||
100 | 3 | return 0; | |
101 | } | ||
102 | #endif | ||
103 | |||
104 | ✗ | static int decode_registered_user_data_lcevc(HEVCSEILCEVC *s, | |
105 | GetByteContext *gb) | ||
106 | { | ||
107 | ✗ | int size = bytestream2_get_bytes_left(gb); | |
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 | |||
118 | 1169 | static int decode_registered_user_data_afd(H2645SEIAFD *h, GetByteContext *gb) | |
119 | { | ||
120 | int flag; | ||
121 | |||
122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1169 times.
|
1169 | if (bytestream2_get_bytes_left(gb) <= 0) |
123 | ✗ | return AVERROR_INVALIDDATA; | |
124 | |||
125 | 1169 | flag = !!(bytestream2_get_byteu(gb) & 0x40); // active_format_flag | |
126 | |||
127 |
1/2✓ Branch 0 taken 1169 times.
✗ Branch 1 not taken.
|
1169 | if (flag) { |
128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1169 times.
|
1169 | if (bytestream2_get_bytes_left(gb) <= 0) |
129 | ✗ | return AVERROR_INVALIDDATA; | |
130 | 1169 | h->active_format_description = bytestream2_get_byteu(gb) & 0xF; | |
131 | 1169 | h->present = 1; | |
132 | } | ||
133 | |||
134 | 1169 | return 0; | |
135 | } | ||
136 | |||
137 | 6 | static int decode_registered_user_data_closed_caption(H2645SEIA53Caption *h, | |
138 | GetByteContext *gb) | ||
139 | { | ||
140 | 6 | return ff_parse_a53_cc(&h->buf_ref, gb->buffer, | |
141 | bytestream2_get_bytes_left(gb)); | ||
142 | } | ||
143 | |||
144 | 1184 | static int decode_registered_user_data(H2645SEI *h, GetByteContext *gb, | |
145 | enum AVCodecID codec_id, void *logctx) | ||
146 | { | ||
147 | int country_code, provider_code; | ||
148 | |||
149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1184 times.
|
1184 | if (bytestream2_get_bytes_left(gb) < 3) |
150 | ✗ | return AVERROR_INVALIDDATA; | |
151 | |||
152 | 1184 | country_code = bytestream2_get_byteu(gb); // itu_t_t35_country_code | |
153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1184 times.
|
1184 | 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 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1181 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
1184 | if (country_code != ITU_T_T35_COUNTRY_CODE_US && |
161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | 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 | 1184 | provider_code = bytestream2_get_be16u(gb); | |
171 | |||
172 |
3/6✓ Branch 0 taken 1175 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1184 | switch (provider_code) { |
173 | 1175 | case ITU_T_T35_PROVIDER_CODE_ATSC: { | |
174 | uint32_t user_identifier; | ||
175 | |||
176 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1175 times.
|
1175 | if (bytestream2_get_bytes_left(gb) < 4) |
177 | ✗ | return AVERROR_INVALIDDATA; | |
178 | |||
179 | 1175 | user_identifier = bytestream2_get_be32u(gb); | |
180 |
2/3✓ Branch 0 taken 1169 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
1175 | switch (user_identifier) { |
181 | 1169 | case MKBETAG('D', 'T', 'G', '1'): // afd_data | |
182 | 1169 | return decode_registered_user_data_afd(&h->afd, gb); | |
183 | 6 | case MKBETAG('G', 'A', '9', '4'): // closed captions | |
184 | 6 | 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 | } | ||
193 | ✗ | case ITU_T_T35_PROVIDER_CODE_LCEVC: { | |
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 | ||
201 | 3 | case ITU_T_T35_PROVIDER_CODE_CUVA: { | |
202 | 3 | const uint16_t cuva_provider_oriented_code = 0x0005; | |
203 | uint16_t provider_oriented_code; | ||
204 | |||
205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!IS_HEVC(codec_id)) |
206 | ✗ | goto unsupported_provider_code; | |
207 | |||
208 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (bytestream2_get_bytes_left(gb) < 2) |
209 | ✗ | return AVERROR_INVALIDDATA; | |
210 | |||
211 | 3 | provider_oriented_code = bytestream2_get_be16u(gb); | |
212 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (provider_oriented_code == cuva_provider_oriented_code) { |
213 | 3 | return decode_registered_user_data_dynamic_hdr_vivid(&h->dynamic_hdr_vivid, gb); | |
214 | } | ||
215 | ✗ | break; | |
216 | } | ||
217 | 6 | case ITU_T_T35_PROVIDER_CODE_SMTPE: { | |
218 | // A/341 Amendment - 2094-40 | ||
219 | 6 | const uint16_t smpte2094_40_provider_oriented_code = 0x0001; | |
220 | 6 | const uint8_t smpte2094_40_application_identifier = 0x04; | |
221 | uint16_t provider_oriented_code; | ||
222 | uint8_t application_identifier; | ||
223 | |||
224 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!IS_HEVC(codec_id)) |
225 | ✗ | goto unsupported_provider_code; | |
226 | |||
227 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if (bytestream2_get_bytes_left(gb) < 3) |
228 | ✗ | return AVERROR_INVALIDDATA; | |
229 | |||
230 | 6 | provider_oriented_code = bytestream2_get_be16u(gb); | |
231 | 6 | application_identifier = bytestream2_get_byteu(gb); | |
232 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | if (provider_oriented_code == smpte2094_40_provider_oriented_code && |
233 | application_identifier == smpte2094_40_application_identifier) { | ||
234 | 6 | 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, | ||
252 | bytestream2_get_bytes_left(gb)); | ||
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 | |||
268 | 593 | static int decode_unregistered_user_data(H2645SEIUnregistered *h, | |
269 | GetByteContext *gb, | ||
270 | enum AVCodecID codec_id) | ||
271 | { | ||
272 | uint8_t *user_data; | ||
273 | 593 | int size = bytestream2_get_bytes_left(gb); | |
274 | AVBufferRef *buf_ref, **tmp; | ||
275 | |||
276 |
2/4✓ Branch 0 taken 593 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 593 times.
|
593 | if (size < 16 || size >= INT_MAX - 1) |
277 | ✗ | return AVERROR_INVALIDDATA; | |
278 | |||
279 | 593 | tmp = av_realloc_array(h->buf_ref, h->nb_buf_ref + 1, sizeof(*h->buf_ref)); | |
280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
|
593 | if (!tmp) |
281 | ✗ | return AVERROR(ENOMEM); | |
282 | 593 | h->buf_ref = tmp; | |
283 | |||
284 | 593 | buf_ref = av_buffer_alloc(size + 1); | |
285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 593 times.
|
593 | if (!buf_ref) |
286 | ✗ | return AVERROR(ENOMEM); | |
287 | 593 | user_data = buf_ref->data; | |
288 | |||
289 | 593 | bytestream2_get_bufferu(gb, user_data, size); | |
290 | 593 | user_data[size] = 0; | |
291 | 593 | buf_ref->size = size; | |
292 | 593 | h->buf_ref[h->nb_buf_ref++] = buf_ref; | |
293 | |||
294 |
2/2✓ Branch 0 taken 568 times.
✓ Branch 1 taken 25 times.
|
593 | if (IS_H264(codec_id)) { |
295 | int e, build; | ||
296 | 568 | e = sscanf(user_data + 16, "x264 - core %d", &build); | |
297 |
4/4✓ Branch 0 taken 143 times.
✓ Branch 1 taken 425 times.
✓ Branch 2 taken 140 times.
✓ Branch 3 taken 3 times.
|
568 | if (e == 1 && build > 0) |
298 | 140 | h->x264_build = build; | |
299 |
3/6✓ Branch 0 taken 143 times.
✓ Branch 1 taken 425 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 143 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
568 | if (e == 1 && build == 1 && !strncmp(user_data+16, "x264 - core 0000", 16)) |
300 | ✗ | h->x264_build = 67; | |
301 | } | ||
302 | |||
303 | 593 | return 0; | |
304 | } | ||
305 | |||
306 | 2 | static int decode_display_orientation(H2645SEIDisplayOrientation *h, | |
307 | GetBitContext *gb) | ||
308 | { | ||
309 | 2 | h->present = !get_bits1(gb); // display_orientation_cancel_flag | |
310 | |||
311 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (h->present) { |
312 | 2 | h->hflip = get_bits1(gb); // hor_flip | |
313 | 2 | h->vflip = get_bits1(gb); // ver_flip | |
314 | |||
315 | 2 | 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 | 2 | return 0; | |
322 | } | ||
323 | |||
324 | ✗ | static int decode_frame_packing_arrangement(H2645SEIFramePacking *h, | |
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 | |||
358 | ✗ | static int decode_alternative_transfer(H2645SEIAlternativeTransfer *s, | |
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 | |||
370 | 9 | static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s, | |
371 | GetByteContext *gb) | ||
372 | { | ||
373 | static const uint16_t max_ambient_light_value = 50000; | ||
374 | |||
375 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if (bytestream2_get_bytes_left(gb) < 8) |
376 | ✗ | return AVERROR_INVALIDDATA; | |
377 | |||
378 | 9 | s->ambient_illuminance = bytestream2_get_be32u(gb); | |
379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!s->ambient_illuminance) |
380 | ✗ | return AVERROR_INVALIDDATA; | |
381 | |||
382 | 9 | s->ambient_light_x = bytestream2_get_be16u(gb); | |
383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (s->ambient_light_x > max_ambient_light_value) |
384 | ✗ | return AVERROR_INVALIDDATA; | |
385 | |||
386 | 9 | s->ambient_light_y = bytestream2_get_be16u(gb); | |
387 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (s->ambient_light_y > max_ambient_light_value) |
388 | ✗ | return AVERROR_INVALIDDATA; | |
389 | |||
390 | 9 | s->present = 1; | |
391 | |||
392 | 9 | return 0; | |
393 | } | ||
394 | |||
395 | ✗ | static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics *h, | |
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 | |||
441 | 18 | static int decode_nal_sei_mastering_display_info(H2645SEIMasteringDisplay *s, | |
442 | GetByteContext *gb) | ||
443 | { | ||
444 | int i; | ||
445 | |||
446 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
|
18 | if (bytestream2_get_bytes_left(gb) < 24) |
447 | ✗ | return AVERROR_INVALIDDATA; | |
448 | |||
449 | // Mastering primaries | ||
450 |
2/2✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
|
72 | for (i = 0; i < 3; i++) { |
451 | 54 | s->display_primaries[i][0] = bytestream2_get_be16u(gb); | |
452 | 54 | s->display_primaries[i][1] = bytestream2_get_be16u(gb); | |
453 | } | ||
454 | // White point (x, y) | ||
455 | 18 | s->white_point[0] = bytestream2_get_be16u(gb); | |
456 | 18 | s->white_point[1] = bytestream2_get_be16u(gb); | |
457 | |||
458 | // Max and min luminance of mastering display | ||
459 | 18 | s->max_luminance = bytestream2_get_be32u(gb); | |
460 | 18 | 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 | 18 | s->present = 2; | |
466 | |||
467 | 18 | return 0; | |
468 | } | ||
469 | |||
470 | 9 | static int decode_nal_sei_content_light_info(H2645SEIContentLight *s, | |
471 | GetByteContext *gb) | ||
472 | { | ||
473 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if (bytestream2_get_bytes_left(gb) < 4) |
474 | ✗ | return AVERROR_INVALIDDATA; | |
475 | |||
476 | // Max and average light levels | ||
477 | 9 | s->max_content_light_level = bytestream2_get_be16u(gb); | |
478 | 9 | 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 | 9 | s->present = 2; | |
483 | |||
484 | 9 | return 0; | |
485 | } | ||
486 | |||
487 | 2248 | int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, | |
488 | enum AVCodecID codec_id, GetBitContext *gb, | ||
489 | GetByteContext *gbyte, void *logctx) | ||
490 | { | ||
491 |
7/10✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 593 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 433 times.
|
2248 | switch (type) { |
492 | 1184 | case SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: | |
493 | 1184 | return decode_registered_user_data(h, gbyte, codec_id, logctx); | |
494 | 593 | case SEI_TYPE_USER_DATA_UNREGISTERED: | |
495 | 593 | return decode_unregistered_user_data(&h->unregistered, gbyte, codec_id); | |
496 | 2 | case SEI_TYPE_DISPLAY_ORIENTATION: | |
497 | 2 | return decode_display_orientation(&h->display_orientation, gb); | |
498 | ✗ | case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS: | |
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); | |
504 | ✗ | case SEI_TYPE_FRAME_PACKING_ARRANGEMENT: | |
505 | ✗ | return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id); | |
506 | ✗ | case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: | |
507 | ✗ | return decode_alternative_transfer(&h->alternative_transfer, gbyte); | |
508 | 9 | case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT: | |
509 | 9 | return decode_ambient_viewing_environment(&h->ambient_viewing_environment, | |
510 | gbyte); | ||
511 | 18 | case SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME: | |
512 | 18 | return decode_nal_sei_mastering_display_info(&h->mastering_display, | |
513 | gbyte); | ||
514 | 9 | case SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO: | |
515 | 9 | return decode_nal_sei_content_light_info(&h->content_light, gbyte); | |
516 | 433 | default: | |
517 | 433 | return FF_H2645_SEI_MESSAGE_UNHANDLED; | |
518 | } | ||
519 | } | ||
520 | |||
521 | 90 | int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src) | |
522 | { | ||
523 | 90 | int ret = av_buffer_replace(&dst->a53_caption.buf_ref, | |
524 | 90 | src->a53_caption.buf_ref); | |
525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
|
90 | if (ret < 0) |
526 | ✗ | return ret; | |
527 | |||
528 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
|
90 | for (unsigned i = 0; i < dst->unregistered.nb_buf_ref; i++) |
529 | ✗ | av_buffer_unref(&dst->unregistered.buf_ref[i]); | |
530 | 90 | dst->unregistered.nb_buf_ref = 0; | |
531 | |||
532 | 90 | ret = av_buffer_replace(&dst->lcevc.info, src->lcevc.info); | |
533 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
|
90 | if (ret < 0) |
534 | ✗ | return ret; | |
535 | |||
536 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
|
90 | 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 |
2/2✓ Branch 0 taken 720 times.
✓ Branch 1 taken 90 times.
|
810 | for (unsigned i = 0; i < FF_ARRAY_ELEMS(dst->aom_film_grain.sets); i++) { |
552 | 720 | ret = av_buffer_replace(&dst->aom_film_grain.sets[i], | |
553 | 720 | src->aom_film_grain.sets[i]); | |
554 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 720 times.
|
720 | if (ret < 0) |
555 | ✗ | return ret; | |
556 | } | ||
557 | 90 | dst->aom_film_grain.enable = src->aom_film_grain.enable; | |
558 | |||
559 | 90 | dst->mastering_display = src->mastering_display; | |
560 | 90 | dst->content_light = src->content_light; | |
561 | |||
562 | 90 | ff_refstruct_replace(&dst->film_grain_characteristics, | |
563 | 90 | src->film_grain_characteristics); | |
564 | |||
565 | 90 | return 0; | |
566 | } | ||
567 | |||
568 | ✗ | static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id) | |
569 | { | ||
570 | ✗ | if (IS_H264(codec_id)) | |
571 | ✗ | return type <= SEI_FPA_H264_TYPE_2D && | |
572 | type >= SEI_FPA_H264_TYPE_CHECKERBOARD; | ||
573 | else | ||
574 | ✗ | return type <= SEI_FPA_TYPE_INTERLEAVE_TEMPORAL && | |
575 | type >= SEI_FPA_TYPE_SIDE_BY_SIDE; | ||
576 | } | ||
577 | |||
578 | 35350 | static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, | |
579 | AVFrameSideData ***sd, int *nb_sd) | ||
580 | { | ||
581 | int ret; | ||
582 | |||
583 |
2/2✓ Branch 0 taken 298 times.
✓ Branch 1 taken 35350 times.
|
35648 | for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) { |
584 | 298 | H2645SEIUnregistered *unreg = &sei->unregistered; | |
585 | |||
586 |
1/2✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
|
298 | if (unreg->buf_ref[i]) { |
587 | AVFrameSideData *entry = | ||
588 | 298 | av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, | |
589 | 298 | &unreg->buf_ref[i], 0); | |
590 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
|
298 | if (!entry) |
591 | ✗ | av_buffer_unref(&unreg->buf_ref[i]); | |
592 | } | ||
593 | } | ||
594 | 35350 | sei->unregistered.nb_buf_ref = 0; | |
595 | |||
596 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 35340 times.
|
35350 | if (sei->ambient_viewing_environment.present) { |
597 | 10 | H2645SEIAmbientViewingEnvironment *env = &sei->ambient_viewing_environment; | |
598 | AVBufferRef *buf; | ||
599 | size_t size; | ||
600 | |||
601 | AVAmbientViewingEnvironment *dst_env = | ||
602 | 10 | av_ambient_viewing_environment_alloc(&size); | |
603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!dst_env) |
604 | ✗ | return AVERROR(ENOMEM); | |
605 | |||
606 | 10 | buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0); | |
607 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!buf) { |
608 | ✗ | av_free(dst_env); | |
609 | ✗ | return AVERROR(ENOMEM); | |
610 | } | ||
611 | |||
612 | 10 | ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd, | |
613 | AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf); | ||
614 | |||
615 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) |
616 | ✗ | return ret; | |
617 | |||
618 | 10 | dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000); | |
619 | 10 | dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000); | |
620 | 10 | dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000); | |
621 | } | ||
622 | |||
623 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 35317 times.
|
35350 | if (sei->mastering_display.present) { |
624 | // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b | ||
625 | 33 | const int mapping[3] = {2, 0, 1}; | |
626 | 33 | const int chroma_den = 50000; | |
627 | 33 | const int luma_den = 10000; | |
628 | int i; | ||
629 | AVMasteringDisplayMetadata *metadata; | ||
630 | |||
631 | 33 | ret = ff_decode_mastering_display_new_ext(avctx, sd, nb_sd, &metadata); | |
632 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (ret < 0) |
633 | ✗ | return ret; | |
634 | |||
635 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 10 times.
|
33 | if (metadata) { |
636 | 23 | metadata->has_luminance = 1; | |
637 | 23 | metadata->has_primaries = 1; | |
638 | |||
639 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 23 times.
|
92 | for (i = 0; i < 3; i++) { |
640 | 69 | const int j = mapping[i]; | |
641 | 69 | metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; | |
642 | 69 | metadata->display_primaries[i][0].den = chroma_den; | |
643 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
138 | metadata->has_primaries &= sei->mastering_display.display_primaries[j][0] >= 5 && |
644 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | sei->mastering_display.display_primaries[j][0] <= 37000; |
645 | |||
646 | 69 | metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; | |
647 | 69 | metadata->display_primaries[i][1].den = chroma_den; | |
648 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
138 | metadata->has_primaries &= sei->mastering_display.display_primaries[j][1] >= 5 && |
649 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | sei->mastering_display.display_primaries[j][1] <= 42000; |
650 | } | ||
651 | 23 | metadata->white_point[0].num = sei->mastering_display.white_point[0]; | |
652 | 23 | metadata->white_point[0].den = chroma_den; | |
653 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
46 | metadata->has_primaries &= sei->mastering_display.white_point[0] >= 5 && |
654 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | sei->mastering_display.white_point[0] <= 37000; |
655 | |||
656 | 23 | metadata->white_point[1].num = sei->mastering_display.white_point[1]; | |
657 | 23 | metadata->white_point[1].den = chroma_den; | |
658 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
46 | metadata->has_primaries &= sei->mastering_display.white_point[1] >= 5 && |
659 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | sei->mastering_display.white_point[1] <= 42000; |
660 | |||
661 | 23 | metadata->max_luminance.num = sei->mastering_display.max_luminance; | |
662 | 23 | metadata->max_luminance.den = luma_den; | |
663 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
46 | metadata->has_luminance &= sei->mastering_display.max_luminance >= 50000 && |
664 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1 times.
|
23 | sei->mastering_display.max_luminance <= 100000000; |
665 | |||
666 | 23 | metadata->min_luminance.num = sei->mastering_display.min_luminance; | |
667 | 23 | metadata->min_luminance.den = luma_den; | |
668 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
46 | metadata->has_luminance &= sei->mastering_display.min_luminance <= 50000 && |
669 | 23 | sei->mastering_display.min_luminance < | |
670 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | 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 */ | ||
674 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) |
675 | ✗ | metadata->has_luminance &= sei->mastering_display.min_luminance >= 1; | |
676 | |||
677 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
23 | if (metadata->has_luminance || metadata->has_primaries) |
678 | 23 | av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); | |
679 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if (metadata->has_primaries) { |
680 | 23 | 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 | 23 | av_q2d(metadata->display_primaries[0][0]), | |
683 | 23 | av_q2d(metadata->display_primaries[0][1]), | |
684 | 23 | av_q2d(metadata->display_primaries[1][0]), | |
685 | 23 | av_q2d(metadata->display_primaries[1][1]), | |
686 | 23 | av_q2d(metadata->display_primaries[2][0]), | |
687 | 23 | av_q2d(metadata->display_primaries[2][1]), | |
688 | 23 | av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); | |
689 | } | ||
690 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1 times.
|
23 | if (metadata->has_luminance) { |
691 | 22 | av_log(avctx, AV_LOG_DEBUG, | |
692 | "min_luminance=%f, max_luminance=%f\n", | ||
693 | 22 | av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); | |
694 | } | ||
695 | } | ||
696 | } | ||
697 | |||
698 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 35344 times.
|
35350 | if (sei->content_light.present) { |
699 | AVContentLightMetadata *metadata; | ||
700 | |||
701 | 6 | ret = ff_decode_content_light_new_ext(avctx, sd, nb_sd, &metadata); | |
702 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (ret < 0) |
703 | ✗ | return ret; | |
704 | |||
705 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (metadata) { |
706 | 6 | metadata->MaxCLL = sei->content_light.max_content_light_level; | |
707 | 6 | metadata->MaxFALL = sei->content_light.max_pic_average_light_level; | |
708 | |||
709 | 6 | av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); | |
710 | 6 | av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", | |
711 | 6 | metadata->MaxCLL, metadata->MaxFALL); | |
712 | } | ||
713 | } | ||
714 | |||
715 | 35350 | return 0; | |
716 | } | ||
717 | |||
718 | 35102 | int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, | |
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 | 35102 | H2645SEIFramePacking *fp = &sei->frame_packing; | |
725 | int ret; | ||
726 | |||
727 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 35102 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
35102 | if (fp->present && |
728 | ✗ | is_frame_packing_type_valid(fp->arrangement_type, codec_id) && | |
729 | ✗ | fp->content_interpretation_type > 0 && | |
730 | ✗ | fp->content_interpretation_type < 3) { | |
731 | ✗ | AVStereo3D *stereo = av_stereo3d_create_side_data(frame); | |
732 | |||
733 | ✗ | if (!stereo) | |
734 | ✗ | return AVERROR(ENOMEM); | |
735 | |||
736 | ✗ | switch (fp->arrangement_type) { | |
737 | #if CONFIG_H264_SEI | ||
738 | ✗ | case SEI_FPA_H264_TYPE_CHECKERBOARD: | |
739 | ✗ | stereo->type = AV_STEREO3D_CHECKERBOARD; | |
740 | ✗ | break; | |
741 | ✗ | case SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN: | |
742 | ✗ | stereo->type = AV_STEREO3D_COLUMNS; | |
743 | ✗ | break; | |
744 | ✗ | case SEI_FPA_H264_TYPE_INTERLEAVE_ROW: | |
745 | ✗ | stereo->type = AV_STEREO3D_LINES; | |
746 | ✗ | break; | |
747 | #endif | ||
748 | ✗ | case SEI_FPA_TYPE_SIDE_BY_SIDE: | |
749 | ✗ | if (fp->quincunx_sampling_flag) | |
750 | ✗ | stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX; | |
751 | else | ||
752 | ✗ | stereo->type = AV_STEREO3D_SIDEBYSIDE; | |
753 | ✗ | break; | |
754 | ✗ | case SEI_FPA_TYPE_TOP_BOTTOM: | |
755 | ✗ | stereo->type = AV_STEREO3D_TOPBOTTOM; | |
756 | ✗ | break; | |
757 | ✗ | case SEI_FPA_TYPE_INTERLEAVE_TEMPORAL: | |
758 | ✗ | stereo->type = AV_STEREO3D_FRAMESEQUENCE; | |
759 | ✗ | break; | |
760 | #if CONFIG_H264_SEI | ||
761 | ✗ | case SEI_FPA_H264_TYPE_2D: | |
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 | |||
770 | ✗ | if (fp->arrangement_type == SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) { | |
771 | ✗ | if (fp->current_frame_is_frame0_flag) | |
772 | ✗ | stereo->view = AV_STEREO3D_VIEW_LEFT; | |
773 | else | ||
774 | ✗ | stereo->view = AV_STEREO3D_VIEW_RIGHT; | |
775 | } | ||
776 | } | ||
777 | |||
778 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35101 times.
|
35102 | if (sei->display_orientation.present && |
779 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | (sei->display_orientation.anticlockwise_rotation || |
780 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | sei->display_orientation.hflip || |
781 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | sei->display_orientation.vflip)) { |
782 | ✗ | H2645SEIDisplayOrientation *o = &sei->display_orientation; | |
783 | ✗ | double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16); | |
784 | ✗ | AVFrameSideData *rotation = av_frame_new_side_data(frame, | |
785 | AV_FRAME_DATA_DISPLAYMATRIX, | ||
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 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35101 times.
|
35102 | if (sei->a53_caption.buf_ref) { |
805 | 1 | H2645SEIA53Caption *a53 = &sei->a53_caption; | |
806 | 1 | AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, a53->buf_ref); | |
807 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!sd) |
808 | ✗ | av_buffer_unref(&a53->buf_ref); | |
809 | 1 | a53->buf_ref = NULL; | |
810 | 1 | avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; | |
811 | } | ||
812 | |||
813 | 35102 | ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data); | |
814 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35102 times.
|
35102 | if (ret < 0) |
815 | ✗ | return ret; | |
816 | |||
817 |
2/2✓ Branch 0 taken 324 times.
✓ Branch 1 taken 34778 times.
|
35102 | if (sei->afd.present) { |
818 | 324 | AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_AFD, | |
819 | sizeof(uint8_t)); | ||
820 | |||
821 |
1/2✓ Branch 0 taken 324 times.
✗ Branch 1 not taken.
|
324 | if (sd) { |
822 | 324 | *sd->data = sei->afd.active_format_description; | |
823 | 324 | sei->afd.present = 0; | |
824 | } | ||
825 | } | ||
826 | |||
827 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35102 times.
|
35102 | if (sei->lcevc.info) { |
828 | ✗ | HEVCSEILCEVC *lcevc = &sei->lcevc; | |
829 | ✗ | ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_LCEVC, &lcevc->info); | |
830 | ✗ | if (ret < 0) | |
831 | ✗ | return ret; | |
832 | } | ||
833 | |||
834 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 35102 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
35102 | if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) { |
835 | ✗ | H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics; | |
836 | ✗ | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); | |
837 | AVFilmGrainH274Params *h274; | ||
838 | |||
839 | ✗ | if (!fgp) | |
840 | ✗ | return AVERROR(ENOMEM); | |
841 | |||
842 | ✗ | fgp->type = AV_FILM_GRAIN_PARAMS_H274; | |
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; | |
853 | ✗ | if (fgc->separate_colour_description_present_flag) { | |
854 | ✗ | fgp->bit_depth_luma = fgc->bit_depth_luma; | |
855 | ✗ | fgp->bit_depth_chroma = fgc->bit_depth_chroma; | |
856 | ✗ | fgp->color_range = fgc->full_range + 1; | |
857 | ✗ | fgp->color_primaries = fgc->color_primaries; | |
858 | ✗ | fgp->color_trc = fgc->transfer_characteristics; | |
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; | |
863 | ✗ | if (vui->video_signal_type_present_flag) | |
864 | ✗ | fgp->color_range = vui->video_full_range_flag + 1; | |
865 | ✗ | if (vui->colour_description_present_flag) { | |
866 | ✗ | fgp->color_primaries = vui->colour_primaries; | |
867 | ✗ | fgp->color_trc = vui->transfer_characteristics; | |
868 | ✗ | fgp->color_space = vui->matrix_coeffs; | |
869 | } | ||
870 | } | ||
871 | ✗ | h274->blending_mode_id = fgc->blending_mode_id; | |
872 | ✗ | h274->log2_scale_factor = fgc->log2_scale_factor; | |
873 | |||
874 | #if FF_API_H274_FILM_GRAIN_VCS | ||
875 | FF_DISABLE_DEPRECATION_WARNINGS | ||
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; | |
882 | FF_ENABLE_DEPRECATION_WARNINGS | ||
883 | #endif | ||
884 | |||
885 | ✗ | memcpy(&h274->component_model_present, &fgc->comp_model_present_flag, | |
886 | sizeof(h274->component_model_present)); | ||
887 | ✗ | memcpy(&h274->num_intensity_intervals, &fgc->num_intensity_intervals, | |
888 | sizeof(h274->num_intensity_intervals)); | ||
889 | ✗ | memcpy(&h274->num_model_values, &fgc->num_model_values, | |
890 | sizeof(h274->num_model_values)); | ||
891 | ✗ | memcpy(&h274->intensity_interval_lower_bound, &fgc->intensity_interval_lower_bound, | |
892 | sizeof(h274->intensity_interval_lower_bound)); | ||
893 | ✗ | memcpy(&h274->intensity_interval_upper_bound, &fgc->intensity_interval_upper_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 | |||
903 | ✗ | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | |
904 | } | ||
905 | |||
906 | #if CONFIG_HEVC_SEI | ||
907 | 35102 | ret = ff_aom_attach_film_grain_sets(&sei->aom_film_grain, frame); | |
908 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35102 times.
|
35102 | if (ret < 0) |
909 | ✗ | return ret; | |
910 | #endif | ||
911 | |||
912 | 35102 | return 0; | |
913 | } | ||
914 | |||
915 | 248 | int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei) | |
916 | { | ||
917 | 248 | return h2645_sei_to_side_data(avctx, sei, &avctx->decoded_side_data, | |
918 | &avctx->nb_decoded_side_data); | ||
919 | } | ||
920 | |||
921 | 73911 | void ff_h2645_sei_reset(H2645SEI *s) | |
922 | { | ||
923 | 73911 | av_buffer_unref(&s->a53_caption.buf_ref); | |
924 | |||
925 |
2/2✓ Branch 0 taken 295 times.
✓ Branch 1 taken 73911 times.
|
74206 | for (unsigned i = 0; i < s->unregistered.nb_buf_ref; i++) |
926 | 295 | av_buffer_unref(&s->unregistered.buf_ref[i]); | |
927 | 73911 | s->unregistered.nb_buf_ref = 0; | |
928 | 73911 | av_freep(&s->unregistered.buf_ref); | |
929 | 73911 | av_buffer_unref(&s->dynamic_hdr_plus.info); | |
930 | 73911 | av_buffer_unref(&s->dynamic_hdr_vivid.info); | |
931 | 73911 | av_buffer_unref(&s->lcevc.info); | |
932 | |||
933 | 73911 | s->ambient_viewing_environment.present = 0; | |
934 | 73911 | s->mastering_display.present = 0; | |
935 | 73911 | s->content_light.present = 0; | |
936 | |||
937 | 73911 | ff_refstruct_unref(&s->film_grain_characteristics); | |
938 | 73911 | ff_aom_uninit_film_grain_params(&s->aom_film_grain); | |
939 | 73911 | } | |
940 |