| @@ -29,7 +29,9 @@ · 28 unmodified lines |
| 29 | | 29 | |
| 30 | #include <stdint.h> | 30 | #include <stdint.h> |
| 31 | #include <stddef.h> | 31 | #include <stddef.h> |
| | 32 | |
| 32 | #include "rational.h" | 33 | #include "rational.h" |
| | 34 | #include "csp.h" |
| 33 | | 35 | |
| 34 | /* | 36 | /* |
| 35 | * DOVI configuration | 37 | * DOVI configuration |
| @@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata { · 151 unmodified lines |
| 187 | uint16_t source_diagonal; | 189 | uint16_t source_diagonal; |
| 188 | } AVDOVIColorMetadata; | 190 | } AVDOVIColorMetadata; |
| 189 | | 191 | |
| | 192 | typedef struct AVDOVIDmLevel1 { |
| | 193 | /* Per-frame brightness metadata */ |
| | 194 | uint16_t min_pq; |
| | 195 | uint16_t max_pq; |
| | 196 | uint16_t avg_pq; |
| | 197 | } AVDOVIDmLevel1; |
| | 198 | |
| | 199 | typedef struct AVDOVIDmLevel2 { |
| | 200 | /* Usually derived from level 8 (at different levels) */ |
| | 201 | uint16_t target_max_pq; |
| | 202 | uint16_t trim_slope; |
| | 203 | uint16_t trim_offset; |
| | 204 | uint16_t trim_power; |
| | 205 | uint16_t trim_chroma_weight; |
| | 206 | uint16_t trim_saturation_gain; |
| | 207 | int16_t ms_weight; |
| | 208 | } AVDOVIDmLevel2; |
| | 209 | |
| | 210 | typedef struct AVDOVIDmLevel3 { |
| | 211 | uint16_t min_pq_offset; |
| | 212 | uint16_t max_pq_offset; |
| | 213 | uint16_t avg_pq_offset; |
| | 214 | } AVDOVIDmLevel3; |
| | 215 | |
| | 216 | typedef struct AVDOVIDmLevel4 { |
| | 217 | uint16_t anchor_pq; |
| | 218 | uint16_t anchor_power; |
| | 219 | } AVDOVIDmLevel4; |
| | 220 | |
| | 221 | typedef struct AVDOVIDmLevel5 { |
| | 222 | /* Active area definition */ |
| | 223 | uint16_t left_offset; |
| | 224 | uint16_t right_offset; |
| | 225 | uint16_t top_offset; |
| | 226 | uint16_t bottom_offset; |
| | 227 | } AVDOVIDmLevel5; |
| | 228 | |
| | 229 | typedef struct AVDOVIDmLevel6 { |
| | 230 | /* Static HDR10 metadata */ |
| | 231 | uint16_t max_luminance; |
| | 232 | uint16_t min_luminance; |
| | 233 | uint16_t max_cll; |
| | 234 | uint16_t max_fall; |
| | 235 | } AVDOVIDmLevel6; |
| | 236 | |
| | 237 | typedef struct AVDOVIDmLevel8 { |
| | 238 | /* Extended version of level 2 */ |
| | 239 | uint8_t target_display_index; |
| | 240 | uint16_t trim_slope; |
| | 241 | uint16_t trim_offset; |
| | 242 | uint16_t trim_power; |
| | 243 | uint16_t trim_chroma_weight; |
| | 244 | uint16_t trim_saturation_gain; |
| | 245 | uint16_t ms_weight; |
| | 246 | uint16_t target_mid_contrast; |
| | 247 | uint16_t clip_trim; |
| | 248 | uint8_t saturation_vector_field[6]; |
| | 249 | uint8_t hue_vector_field[6]; |
| | 250 | } AVDOVIDmLevel8; |
| | 251 | |
| | 252 | typedef struct AVDOVIDmLevel9 { |
| | 253 | /* Source display characteristics */ |
| | 254 | uint8_t source_primary_index; |
| | 255 | AVColorPrimariesDesc source_display_primaries; |
| | 256 | } AVDOVIDmLevel9; |
| | 257 | |
| | 258 | typedef struct AVDOVIDmLevel10 { |
| | 259 | /* Target display characteristics */ |
| | 260 | uint8_t target_display_index; |
| | 261 | uint16_t target_max_pq; |
| | 262 | uint16_t target_min_pq; |
| | 263 | uint8_t target_primary_index; |
| | 264 | AVColorPrimariesDesc target_display_primaries; |
| | 265 | } AVDOVIDmLevel10; |
| | 266 | |
| | 267 | typedef struct AVDOVIDmLevel11 { |
| | 268 | uint8_t content_type; |
| | 269 | uint8_t whitepoint; |
| | 270 | uint8_t reference_mode_flag; |
| | 271 | uint8_t sharpness; |
| | 272 | uint8_t noise_reduction; |
| | 273 | uint8_t mpeg_noise_reduction; |
| | 274 | uint8_t frame_rate_conversion; |
| | 275 | uint8_t brightness; |
| | 276 | uint8_t color; |
| | 277 | } AVDOVIDmLevel11; |
| | 278 | |
| | 279 | typedef struct AVDOVIDmLevel254 { |
| | 280 | /* DMv2 info block, always present in samples with DMv2 metadata */ |
| | 281 | uint8_t dm_mode; |
| | 282 | uint8_t dm_version_index; |
| | 283 | } AVDOVIDmLevel254; |
| | 284 | |
| | 285 | typedef struct AVDOVIDmLevel255 { |
| | 286 | /* Debug block, not really used in samples */ |
| | 287 | uint8_t dm_run_mode; |
| | 288 | uint8_t dm_run_version; |
| | 289 | uint8_t dm_debug[4]; |
| | 290 | } AVDOVIDmLevel255; |
| | 291 | |
| | 292 | /** |
| | 293 | * Dolby Vision metadata extension block. |
| | 294 | * |
| | 295 | * @note sizeof(AVDOVIDmData) is not part of the public API. |
| | 296 | */ |
| | 297 | typedef struct AVDOVIDmData { |
| | 298 | uint8_t level; /* [1, 255] */ |
| | 299 | union { |
| | 300 | AVDOVIDmLevel1 l1; |
| | 301 | AVDOVIDmLevel2 l2; /* may appear multiple times */ |
| | 302 | AVDOVIDmLevel3 l3; |
| | 303 | AVDOVIDmLevel4 l4; |
| | 304 | AVDOVIDmLevel5 l5; |
| | 305 | AVDOVIDmLevel6 l6; |
| | 306 | /* level 7 is currently unused */ |
| | 307 | AVDOVIDmLevel8 l8; /* may appear multiple times */ |
| | 308 | AVDOVIDmLevel9 l9; |
| | 309 | AVDOVIDmLevel10 l10; /* may appear multiple times */ |
| | 310 | AVDOVIDmLevel11 l11; |
| | 311 | AVDOVIDmLevel254 l254; |
| | 312 | AVDOVIDmLevel255 l255; |
| | 313 | }; |
| | 314 | } AVDOVIDmData; |
| | 315 | |
| 190 | /** | 316 | /** |
| 191 | * Combined struct representing a combination of header, mapping and color | 317 | * Combined struct representing a combination of header, mapping and color |
| 192 | * metadata, for attaching to frames as side data. | 318 | * metadata, for attaching to frames as side data. |
| @@ -203,6 +329,13 @@ typedef struct AVDOVIMetadata { · 10 unmodified lines |
| 203 | size_t header_offset; /* AVDOVIRpuDataHeader */ | 329 | size_t header_offset; /* AVDOVIRpuDataHeader */ |
| 204 | size_t mapping_offset; /* AVDOVIDataMapping */ | 330 | size_t mapping_offset; /* AVDOVIDataMapping */ |
| 205 | size_t color_offset; /* AVDOVIColorMetadata */ | 331 | size_t color_offset; /* AVDOVIColorMetadata */ |
| | 332 | |
| | 333 | size_t ext_block_offset; /* offset to start of ext blocks array */ |
| | 334 | size_t ext_block_size; /* size per element */ |
| | 335 | int num_ext_blocks; /* number of extension blocks */ |
| | 336 | |
| | 337 | /* static limit on num_ext_blocks, derived from bitstream limitations */ |
| | 338 | #define AV_DOVI_MAX_EXT_BLOCKS 32 |
| 206 | } AVDOVIMetadata; | 339 | } AVDOVIMetadata; |
| 207 | | 340 | |
| 208 | static av_always_inline AVDOVIRpuDataHeader * | 341 | static av_always_inline AVDOVIRpuDataHeader * |
| @@ -223,6 +356,19 @@ av_dovi_get_color(const AVDOVIMetadata *data) · 14 unmodified lines |
| 223 | return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset); | 356 | return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset); |
| 224 | } | 357 | } |
| 225 | | 358 | |
| | 359 | static av_always_inline AVDOVIDmData * |
| | 360 | av_dovi_get_ext(const AVDOVIMetadata *data, int index) |
| | 361 | { |
| | 362 | return (AVDOVIDmData *)((uint8_t *) data + data->ext_block_offset + |
| | 363 | data->ext_block_size * index); |
| | 364 | } |
| | 365 | |
| | 366 | /** |
| | 367 | * Find an extension block with a given level, or NULL. In the case of |
| | 368 | * multiple extension blocks, only the first is returned. |
| | 369 | */ |
| | 370 | AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level); |
| | 371 | |
| 226 | /** | 372 | /** |
| 227 | * Allocate an AVDOVIMetadata structure and initialize its | 373 | * Allocate an AVDOVIMetadata structure and initialize its |
| 228 | * fields to default values. | 374 | * fields to default values. |