diff options
author | Niklas Haas <git@haasn.dev> | 2024-03-23 13:14:04 +0100 |
---|---|---|
committer | Niklas Haas <git@haasn.dev> | 2024-04-03 16:16:25 +0200 |
commit | 4f55e16f2bc1b861ecc6ce29f151beac357f181c (patch) | |
tree | 22c81c719993c1169a266e0fb10ff7e1dce7b501 /libavutil | |
parent | 78076ede2960debdba4e12aca594897ab11e5417 (diff) | |
download | ffmpeg-4f55e16f2bc1b861ecc6ce29f151beac357f181c.tar.gz |
avutil/dovi_meta: add dolby vision extension blocks
As well as accessors plus a function for allocating this struct with
extension blocks,
Definitions generously taken from quietvoid/dovi_tool, which is
assembled as a collection of various patent fragments, as well as output
by the official Dolby Vision bitstream verifier tool.
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/dovi_meta.c | 22 | ||||
-rw-r--r-- | libavutil/dovi_meta.h | 146 | ||||
-rw-r--r-- | libavutil/version.h | 2 |
3 files changed, 166 insertions, 4 deletions
diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c index 9c50da561e..dfa4a438ed 100644 --- a/libavutil/dovi_meta.c +++ b/libavutil/dovi_meta.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <string.h> + #include "dovi_meta.h" #include "mem.h" @@ -39,6 +41,7 @@ typedef struct AVDOVIMetadataInternal { AVDOVIRpuDataHeader header; AVDOVIDataMapping mapping; AVDOVIColorMetadata color; + AVDOVIDmData ext_blocks[AV_DOVI_MAX_EXT_BLOCKS]; } AVDOVIMetadataInternal; AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size) @@ -51,10 +54,23 @@ AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size) *size = sizeof(*dovi); dovi->metadata = (struct AVDOVIMetadata) { - .header_offset = offsetof(AVDOVIMetadataInternal, header), - .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping), - .color_offset = offsetof(AVDOVIMetadataInternal, color), + .header_offset = offsetof(AVDOVIMetadataInternal, header), + .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping), + .color_offset = offsetof(AVDOVIMetadataInternal, color), + .ext_block_offset = offsetof(AVDOVIMetadataInternal, ext_blocks), + .ext_block_size = sizeof(AVDOVIDmData), }; return &dovi->metadata; } + +AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level) +{ + for (int i = 0; i < data->num_ext_blocks; i++) { + AVDOVIDmData *ext = av_dovi_get_ext(data, i); + if (ext->level == level) + return ext; + } + + return NULL; +} diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h index 46b13b3399..e10332f8d7 100644 --- a/libavutil/dovi_meta.h +++ b/libavutil/dovi_meta.h @@ -29,7 +29,9 @@ #include <stdint.h> #include <stddef.h> + #include "rational.h" +#include "csp.h" /* * DOVI configuration @@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata { uint16_t source_diagonal; } AVDOVIColorMetadata; +typedef struct AVDOVIDmLevel1 { + /* Per-frame brightness metadata */ + uint16_t min_pq; + uint16_t max_pq; + uint16_t avg_pq; +} AVDOVIDmLevel1; + +typedef struct AVDOVIDmLevel2 { + /* Usually derived from level 8 (at different levels) */ + uint16_t target_max_pq; + uint16_t trim_slope; + uint16_t trim_offset; + uint16_t trim_power; + uint16_t trim_chroma_weight; + uint16_t trim_saturation_gain; + int16_t ms_weight; +} AVDOVIDmLevel2; + +typedef struct AVDOVIDmLevel3 { + uint16_t min_pq_offset; + uint16_t max_pq_offset; + uint16_t avg_pq_offset; +} AVDOVIDmLevel3; + +typedef struct AVDOVIDmLevel4 { + uint16_t anchor_pq; + uint16_t anchor_power; +} AVDOVIDmLevel4; + +typedef struct AVDOVIDmLevel5 { + /* Active area definition */ + uint16_t left_offset; + uint16_t right_offset; + uint16_t top_offset; + uint16_t bottom_offset; +} AVDOVIDmLevel5; + +typedef struct AVDOVIDmLevel6 { + /* Static HDR10 metadata */ + uint16_t max_luminance; + uint16_t min_luminance; + uint16_t max_cll; + uint16_t max_fall; +} AVDOVIDmLevel6; + +typedef struct AVDOVIDmLevel8 { + /* Extended version of level 2 */ + uint8_t target_display_index; + uint16_t trim_slope; + uint16_t trim_offset; + uint16_t trim_power; + uint16_t trim_chroma_weight; + uint16_t trim_saturation_gain; + uint16_t ms_weight; + uint16_t target_mid_contrast; + uint16_t clip_trim; + uint8_t saturation_vector_field[6]; + uint8_t hue_vector_field[6]; +} AVDOVIDmLevel8; + +typedef struct AVDOVIDmLevel9 { + /* Source display characteristics */ + uint8_t source_primary_index; + AVColorPrimariesDesc source_display_primaries; +} AVDOVIDmLevel9; + +typedef struct AVDOVIDmLevel10 { + /* Target display characteristics */ + uint8_t target_display_index; + uint16_t target_max_pq; + uint16_t target_min_pq; + uint8_t target_primary_index; + AVColorPrimariesDesc target_display_primaries; +} AVDOVIDmLevel10; + +typedef struct AVDOVIDmLevel11 { + uint8_t content_type; + uint8_t whitepoint; + uint8_t reference_mode_flag; + uint8_t sharpness; + uint8_t noise_reduction; + uint8_t mpeg_noise_reduction; + uint8_t frame_rate_conversion; + uint8_t brightness; + uint8_t color; +} AVDOVIDmLevel11; + +typedef struct AVDOVIDmLevel254 { + /* DMv2 info block, always present in samples with DMv2 metadata */ + uint8_t dm_mode; + uint8_t dm_version_index; +} AVDOVIDmLevel254; + +typedef struct AVDOVIDmLevel255 { + /* Debug block, not really used in samples */ + uint8_t dm_run_mode; + uint8_t dm_run_version; + uint8_t dm_debug[4]; +} AVDOVIDmLevel255; + +/** + * Dolby Vision metadata extension block. + * + * @note sizeof(AVDOVIDmData) is not part of the public API. + */ +typedef struct AVDOVIDmData { + uint8_t level; /* [1, 255] */ + union { + AVDOVIDmLevel1 l1; + AVDOVIDmLevel2 l2; /* may appear multiple times */ + AVDOVIDmLevel3 l3; + AVDOVIDmLevel4 l4; + AVDOVIDmLevel5 l5; + AVDOVIDmLevel6 l6; + /* level 7 is currently unused */ + AVDOVIDmLevel8 l8; /* may appear multiple times */ + AVDOVIDmLevel9 l9; + AVDOVIDmLevel10 l10; /* may appear multiple times */ + AVDOVIDmLevel11 l11; + AVDOVIDmLevel254 l254; + AVDOVIDmLevel255 l255; + }; +} AVDOVIDmData; + /** * Combined struct representing a combination of header, mapping and color * metadata, for attaching to frames as side data. @@ -203,6 +329,13 @@ typedef struct AVDOVIMetadata { size_t header_offset; /* AVDOVIRpuDataHeader */ size_t mapping_offset; /* AVDOVIDataMapping */ size_t color_offset; /* AVDOVIColorMetadata */ + + size_t ext_block_offset; /* offset to start of ext blocks array */ + size_t ext_block_size; /* size per element */ + int num_ext_blocks; /* number of extension blocks */ + + /* static limit on num_ext_blocks, derived from bitstream limitations */ +#define AV_DOVI_MAX_EXT_BLOCKS 32 } AVDOVIMetadata; static av_always_inline AVDOVIRpuDataHeader * @@ -223,6 +356,19 @@ av_dovi_get_color(const AVDOVIMetadata *data) return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset); } +static av_always_inline AVDOVIDmData * +av_dovi_get_ext(const AVDOVIMetadata *data, int index) +{ + return (AVDOVIDmData *)((uint8_t *) data + data->ext_block_offset + + data->ext_block_size * index); +} + +/** + * Find an extension block with a given level, or NULL. In the case of + * multiple extension blocks, only the first is returned. + */ +AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level); + /** * Allocate an AVDOVIMetadata structure and initialize its * fields to default values. diff --git a/libavutil/version.h b/libavutil/version.h index d0cc34f43a..1ed4090e96 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 59 -#define LIBAVUTIL_VERSION_MINOR 11 +#define LIBAVUTIL_VERSION_MINOR 12 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |