Path: blob/master/dep/ffmpeg/include/libavutil/dovi_meta.h
4216 views
/*1* Copyright (c) 2020 Vacing Fang <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920/**21* @file22* DOVI configuration23*/242526#ifndef AVUTIL_DOVI_META_H27#define AVUTIL_DOVI_META_H2829#include <stdint.h>30#include <stddef.h>3132#include "rational.h"33#include "csp.h"3435/*36* DOVI configuration37* ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.238dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.239* @code40* uint8_t dv_version_major, the major version number that the stream complies with41* uint8_t dv_version_minor, the minor version number that the stream complies with42* uint8_t dv_profile, the Dolby Vision profile43* uint8_t dv_level, the Dolby Vision level44* uint8_t rpu_present_flag45* uint8_t el_present_flag46* uint8_t bl_present_flag47* uint8_t dv_bl_signal_compatibility_id48* uint8_t dv_md_compression, the compression method in use49* @endcode50*51* @note The struct must be allocated with av_dovi_alloc() and52* its size is not a part of the public ABI.53*/54typedef struct AVDOVIDecoderConfigurationRecord {55uint8_t dv_version_major;56uint8_t dv_version_minor;57uint8_t dv_profile;58uint8_t dv_level;59uint8_t rpu_present_flag;60uint8_t el_present_flag;61uint8_t bl_present_flag;62uint8_t dv_bl_signal_compatibility_id;63uint8_t dv_md_compression;64} AVDOVIDecoderConfigurationRecord;6566enum AVDOVICompression {67AV_DOVI_COMPRESSION_NONE = 0,68AV_DOVI_COMPRESSION_LIMITED = 1,69AV_DOVI_COMPRESSION_RESERVED = 2,70AV_DOVI_COMPRESSION_EXTENDED = 3,71};7273/**74* Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its75* fields to default values.76*77* @return the newly allocated struct or NULL on failure78*/79AVDOVIDecoderConfigurationRecord *av_dovi_alloc(size_t *size);8081/**82* Dolby Vision RPU data header.83*84* @note sizeof(AVDOVIRpuDataHeader) is not part of the public ABI.85*/86typedef struct AVDOVIRpuDataHeader {87uint8_t rpu_type;88uint16_t rpu_format;89uint8_t vdr_rpu_profile;90uint8_t vdr_rpu_level;91uint8_t chroma_resampling_explicit_filter_flag;92uint8_t coef_data_type; /* informative, lavc always converts to fixed */93uint8_t coef_log2_denom;94uint8_t vdr_rpu_normalized_idc;95uint8_t bl_video_full_range_flag;96uint8_t bl_bit_depth; /* [8, 16] */97uint8_t el_bit_depth; /* [8, 16] */98uint8_t vdr_bit_depth; /* [8, 16] */99uint8_t spatial_resampling_filter_flag;100uint8_t el_spatial_resampling_filter_flag;101uint8_t disable_residual_flag;102uint8_t ext_mapping_idc_0_4; /* extended base layer inverse mapping indicator */103uint8_t ext_mapping_idc_5_7; /* reserved */104} AVDOVIRpuDataHeader;105106enum AVDOVIMappingMethod {107AV_DOVI_MAPPING_POLYNOMIAL = 0,108AV_DOVI_MAPPING_MMR = 1,109};110111/**112* Coefficients of a piece-wise function. The pieces of the function span the113* value ranges between two adjacent pivot values.114*/115#define AV_DOVI_MAX_PIECES 8116typedef struct AVDOVIReshapingCurve {117uint8_t num_pivots; /* [2, 9] */118uint16_t pivots[AV_DOVI_MAX_PIECES + 1]; /* sorted ascending */119enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES];120/* AV_DOVI_MAPPING_POLYNOMIAL */121uint8_t poly_order[AV_DOVI_MAX_PIECES]; /* [1, 2] */122int64_t poly_coef[AV_DOVI_MAX_PIECES][3]; /* x^0, x^1, x^2 */123/* AV_DOVI_MAPPING_MMR */124uint8_t mmr_order[AV_DOVI_MAX_PIECES]; /* [1, 3] */125int64_t mmr_constant[AV_DOVI_MAX_PIECES];126int64_t mmr_coef[AV_DOVI_MAX_PIECES][3/* order - 1 */][7];127} AVDOVIReshapingCurve;128129enum AVDOVINLQMethod {130AV_DOVI_NLQ_NONE = -1,131AV_DOVI_NLQ_LINEAR_DZ = 0,132};133134/**135* Coefficients of the non-linear inverse quantization. For the interpretation136* of these, see ETSI GS CCM 001.137*/138typedef struct AVDOVINLQParams {139uint16_t nlq_offset;140uint64_t vdr_in_max;141/* AV_DOVI_NLQ_LINEAR_DZ */142uint64_t linear_deadzone_slope;143uint64_t linear_deadzone_threshold;144} AVDOVINLQParams;145146/**147* Dolby Vision RPU data mapping parameters.148*149* @note sizeof(AVDOVIDataMapping) is not part of the public ABI.150*/151typedef struct AVDOVIDataMapping {152uint8_t vdr_rpu_id;153uint8_t mapping_color_space;154uint8_t mapping_chroma_format_idc;155AVDOVIReshapingCurve curves[3]; /* per component */156157/* Non-linear inverse quantization */158enum AVDOVINLQMethod nlq_method_idc;159uint32_t num_x_partitions;160uint32_t num_y_partitions;161AVDOVINLQParams nlq[3]; /* per component */162uint16_t nlq_pivots[2];163} AVDOVIDataMapping;164165/**166* Dolby Vision RPU colorspace metadata parameters.167*168* @note sizeof(AVDOVIColorMetadata) is not part of the public ABI.169*/170typedef struct AVDOVIColorMetadata {171uint8_t dm_metadata_id;172uint8_t scene_refresh_flag;173174/**175* Coefficients of the custom Dolby Vision IPT-PQ matrices. These are to be176* used instead of the matrices indicated by the frame's colorspace tags.177* The output of rgb_to_lms_matrix is to be fed into a BT.2020 LMS->RGB178* matrix based on a Hunt-Pointer-Estevez transform, but without any179* crosstalk. (See the definition of the ICtCp colorspace for more180* information.)181*/182AVRational ycc_to_rgb_matrix[9]; /* before PQ linearization */183AVRational ycc_to_rgb_offset[3]; /* input offset of neutral value */184AVRational rgb_to_lms_matrix[9]; /* after PQ linearization */185186/**187* Extra signal metadata (see Dolby patents for more info).188*/189uint16_t signal_eotf;190uint16_t signal_eotf_param0;191uint16_t signal_eotf_param1;192uint32_t signal_eotf_param2;193uint8_t signal_bit_depth;194uint8_t signal_color_space;195uint8_t signal_chroma_format;196uint8_t signal_full_range_flag; /* [0, 3] */197uint16_t source_min_pq;198uint16_t source_max_pq;199uint16_t source_diagonal;200} AVDOVIColorMetadata;201202typedef struct AVDOVIDmLevel1 {203/* Per-frame brightness metadata */204uint16_t min_pq;205uint16_t max_pq;206uint16_t avg_pq;207} AVDOVIDmLevel1;208209typedef struct AVDOVIDmLevel2 {210/* Usually derived from level 8 (at different levels) */211uint16_t target_max_pq;212uint16_t trim_slope;213uint16_t trim_offset;214uint16_t trim_power;215uint16_t trim_chroma_weight;216uint16_t trim_saturation_gain;217int16_t ms_weight;218} AVDOVIDmLevel2;219220typedef struct AVDOVIDmLevel3 {221uint16_t min_pq_offset;222uint16_t max_pq_offset;223uint16_t avg_pq_offset;224} AVDOVIDmLevel3;225226typedef struct AVDOVIDmLevel4 {227uint16_t anchor_pq;228uint16_t anchor_power;229} AVDOVIDmLevel4;230231typedef struct AVDOVIDmLevel5 {232/* Active area definition */233uint16_t left_offset;234uint16_t right_offset;235uint16_t top_offset;236uint16_t bottom_offset;237} AVDOVIDmLevel5;238239typedef struct AVDOVIDmLevel6 {240/* Static HDR10 metadata */241uint16_t max_luminance;242uint16_t min_luminance;243uint16_t max_cll;244uint16_t max_fall;245} AVDOVIDmLevel6;246247typedef struct AVDOVIDmLevel8 {248/* Extended version of level 2 */249uint8_t target_display_index;250uint16_t trim_slope;251uint16_t trim_offset;252uint16_t trim_power;253uint16_t trim_chroma_weight;254uint16_t trim_saturation_gain;255uint16_t ms_weight;256uint16_t target_mid_contrast;257uint16_t clip_trim;258uint8_t saturation_vector_field[6];259uint8_t hue_vector_field[6];260} AVDOVIDmLevel8;261262typedef struct AVDOVIDmLevel9 {263/* Source display characteristics */264uint8_t source_primary_index;265AVColorPrimariesDesc source_display_primaries;266} AVDOVIDmLevel9;267268typedef struct AVDOVIDmLevel10 {269/* Target display characteristics */270uint8_t target_display_index;271uint16_t target_max_pq;272uint16_t target_min_pq;273uint8_t target_primary_index;274AVColorPrimariesDesc target_display_primaries;275} AVDOVIDmLevel10;276277typedef struct AVDOVIDmLevel11 {278uint8_t content_type;279uint8_t whitepoint;280uint8_t reference_mode_flag;281uint8_t sharpness;282uint8_t noise_reduction;283uint8_t mpeg_noise_reduction;284uint8_t frame_rate_conversion;285uint8_t brightness;286uint8_t color;287} AVDOVIDmLevel11;288289typedef struct AVDOVIDmLevel254 {290/* DMv2 info block, always present in samples with DMv2 metadata */291uint8_t dm_mode;292uint8_t dm_version_index;293} AVDOVIDmLevel254;294295typedef struct AVDOVIDmLevel255 {296/* Debug block, not really used in samples */297uint8_t dm_run_mode;298uint8_t dm_run_version;299uint8_t dm_debug[4];300} AVDOVIDmLevel255;301302/**303* Dolby Vision metadata extension block. Dynamic extension blocks may change304* from frame to frame, while static blocks are constant throughout the entire305* sequence.306*307* @note sizeof(AVDOVIDmData) is not part of the public API.308*/309typedef struct AVDOVIDmData {310uint8_t level; /* [1, 255] */311union {312AVDOVIDmLevel1 l1; /* dynamic */313AVDOVIDmLevel2 l2; /* dynamic, may appear multiple times */314AVDOVIDmLevel3 l3; /* dynamic */315AVDOVIDmLevel4 l4; /* dynamic */316AVDOVIDmLevel5 l5; /* dynamic */317AVDOVIDmLevel6 l6; /* static */318/* level 7 is currently unused */319AVDOVIDmLevel8 l8; /* dynamic, may appear multiple times */320AVDOVIDmLevel9 l9; /* dynamic */321AVDOVIDmLevel10 l10; /* static, may appear multiple times */322AVDOVIDmLevel11 l11; /* dynamic */323AVDOVIDmLevel254 l254; /* static */324AVDOVIDmLevel255 l255; /* static */325};326} AVDOVIDmData;327328/**329* Combined struct representing a combination of header, mapping and color330* metadata, for attaching to frames as side data.331*332* @note The struct must be allocated with av_dovi_metadata_alloc() and333* its size is not a part of the public ABI.334*/335336typedef struct AVDOVIMetadata {337/**338* Offset in bytes from the beginning of this structure at which the339* respective structs start.340*/341size_t header_offset; /* AVDOVIRpuDataHeader */342size_t mapping_offset; /* AVDOVIDataMapping */343size_t color_offset; /* AVDOVIColorMetadata */344345size_t ext_block_offset; /* offset to start of ext blocks array */346size_t ext_block_size; /* size per element */347int num_ext_blocks; /* number of extension blocks */348349/* static limit on num_ext_blocks, derived from bitstream limitations */350#define AV_DOVI_MAX_EXT_BLOCKS 32351} AVDOVIMetadata;352353static av_always_inline AVDOVIRpuDataHeader *354av_dovi_get_header(const AVDOVIMetadata *data)355{356return (AVDOVIRpuDataHeader *)((uint8_t *) data + data->header_offset);357}358359static av_always_inline AVDOVIDataMapping *360av_dovi_get_mapping(const AVDOVIMetadata *data)361{362return (AVDOVIDataMapping *)((uint8_t *) data + data->mapping_offset);363}364365static av_always_inline AVDOVIColorMetadata *366av_dovi_get_color(const AVDOVIMetadata *data)367{368return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset);369}370371static av_always_inline AVDOVIDmData *372av_dovi_get_ext(const AVDOVIMetadata *data, int index)373{374return (AVDOVIDmData *)((uint8_t *) data + data->ext_block_offset +375data->ext_block_size * index);376}377378/**379* Find an extension block with a given level, or NULL. In the case of380* multiple extension blocks, only the first is returned.381*/382AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level);383384/**385* Allocate an AVDOVIMetadata structure and initialize its386* fields to default values.387*388* @param size If this parameter is non-NULL, the size in bytes of the389* allocated struct will be written here on success390*391* @return the newly allocated struct or NULL on failure392*/393AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size);394395#endif /* AVUTIL_DOVI_META_H */396397398