FFmpeg
dovi_meta.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Vacing Fang <vacingfang@tencent.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * DOVI configuration
24  */
25 
26 
27 #ifndef AVUTIL_DOVI_META_H
28 #define AVUTIL_DOVI_META_H
29 
30 #include <stdint.h>
31 #include <stddef.h>
32 #include "rational.h"
33 
34 /*
35  * DOVI configuration
36  * ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2.1.2
37  dolby-vision-bitstreams-in-mpeg-2-transport-stream-multiplex-v1.2
38  * @code
39  * uint8_t dv_version_major, the major version number that the stream complies with
40  * uint8_t dv_version_minor, the minor version number that the stream complies with
41  * uint8_t dv_profile, the Dolby Vision profile
42  * uint8_t dv_level, the Dolby Vision level
43  * uint8_t rpu_present_flag
44  * uint8_t el_present_flag
45  * uint8_t bl_present_flag
46  * uint8_t dv_bl_signal_compatibility_id
47  * @endcode
48  *
49  * @note The struct must be allocated with av_dovi_alloc() and
50  * its size is not a part of the public ABI.
51  */
55  uint8_t dv_profile;
56  uint8_t dv_level;
58  uint8_t el_present_flag;
59  uint8_t bl_present_flag;
62 
63 /**
64  * Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its
65  * fields to default values.
66  *
67  * @return the newly allocated struct or NULL on failure
68  */
70 
71 /**
72  * Dolby Vision RPU data header.
73  *
74  * @note sizeof(AVDOVIRpuDataHeader) is not part of the public ABI.
75  */
76 typedef struct AVDOVIRpuDataHeader {
77  uint8_t rpu_type;
78  uint16_t rpu_format;
79  uint8_t vdr_rpu_profile;
80  uint8_t vdr_rpu_level;
82  uint8_t coef_data_type; /* informative, lavc always converts to fixed */
83  uint8_t coef_log2_denom;
86  uint8_t bl_bit_depth; /* [8, 16] */
87  uint8_t el_bit_depth; /* [8, 16] */
88  uint8_t vdr_bit_depth; /* [8, 16] */
93 
97 };
98 
99 /**
100  * Coefficients of a piece-wise function. The pieces of the function span the
101  * value ranges between two adjacent pivot values.
102  */
103 #define AV_DOVI_MAX_PIECES 8
104 typedef struct AVDOVIReshapingCurve {
105  uint8_t num_pivots; /* [2, 9] */
106  uint16_t pivots[AV_DOVI_MAX_PIECES + 1]; /* sorted ascending */
108  /* AV_DOVI_MAPPING_POLYNOMIAL */
109  uint8_t poly_order[AV_DOVI_MAX_PIECES]; /* [1, 2] */
110  int64_t poly_coef[AV_DOVI_MAX_PIECES][3]; /* x^0, x^1, x^2 */
111  /* AV_DOVI_MAPPING_MMR */
112  uint8_t mmr_order[AV_DOVI_MAX_PIECES]; /* [1, 3] */
114  int64_t mmr_coef[AV_DOVI_MAX_PIECES][3/* order - 1 */][7];
116 
120 };
121 
122 /**
123  * Coefficients of the non-linear inverse quantization. For the interpretation
124  * of these, see ETSI GS CCM 001.
125  */
126 typedef struct AVDOVINLQParams {
127  uint16_t nlq_offset;
128  uint64_t vdr_in_max;
129  /* AV_DOVI_NLQ_LINEAR_DZ */
133 
134 /**
135  * Dolby Vision RPU data mapping parameters.
136  *
137  * @note sizeof(AVDOVIDataMapping) is not part of the public ABI.
138  */
139 typedef struct AVDOVIDataMapping {
140  uint8_t vdr_rpu_id;
143  AVDOVIReshapingCurve curves[3]; /* per component */
144 
145  /* Non-linear inverse quantization */
149  AVDOVINLQParams nlq[3]; /* per component */
151 
152 /**
153  * Dolby Vision RPU colorspace metadata parameters.
154  *
155  * @note sizeof(AVDOVIColorMetadata) is not part of the public ABI.
156  */
157 typedef struct AVDOVIColorMetadata {
158  uint8_t dm_metadata_id;
160 
161  /**
162  * Coefficients of the custom Dolby Vision IPT-PQ matrices. These are to be
163  * used instead of the matrices indicated by the frame's colorspace tags.
164  * The output of rgb_to_lms_matrix is to be fed into a BT.2020 LMS->RGB
165  * matrix based on a Hunt-Pointer-Estevez transform, but without any
166  * crosstalk. (See the definition of the ICtCp colorspace for more
167  * information.)
168  */
169  AVRational ycc_to_rgb_matrix[9]; /* before PQ linearization */
170  AVRational ycc_to_rgb_offset[3]; /* input offset of neutral value */
171  AVRational rgb_to_lms_matrix[9]; /* after PQ linearization */
172 
173  /**
174  * Extra signal metadata (see Dolby patents for more info).
175  */
176  uint16_t signal_eotf;
183  uint8_t signal_full_range_flag; /* [0, 3] */
184  uint16_t source_min_pq;
185  uint16_t source_max_pq;
186  uint16_t source_diagonal;
188 
189 /**
190  * Combined struct representing a combination of header, mapping and color
191  * metadata, for attaching to frames as side data.
192  *
193  * @note The struct must be allocated with av_dovi_metadata_alloc() and
194  * its size is not a part of the public ABI.
195  */
196 
197 typedef struct AVDOVIMetadata {
198  /**
199  * Offset in bytes from the beginning of this structure at which the
200  * respective structs start.
201  */
202  size_t header_offset; /* AVDOVIRpuDataHeader */
203  size_t mapping_offset; /* AVDOVIDataMapping */
204  size_t color_offset; /* AVDOVIColorMetadata */
206 
209 {
210  return (AVDOVIRpuDataHeader *)((uint8_t *) data + data->header_offset);
211 }
212 
215 {
216  return (AVDOVIDataMapping *)((uint8_t *) data + data->mapping_offset);
217 }
218 
221 {
222  return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset);
223 }
224 
225 /**
226  * Allocate an AVDOVIMetadata structure and initialize its
227  * fields to default values.
228  *
229  * @param size If this parameter is non-NULL, the size in bytes of the
230  * allocated struct will be written here on success
231  *
232  * @return the newly allocated struct or NULL on failure
233  */
235 
236 #endif /* AVUTIL_DOVI_META_H */
av_dovi_metadata_alloc
AVDOVIMetadata * av_dovi_metadata_alloc(size_t *size)
Allocate an AVDOVIMetadata structure and initialize its fields to default values.
Definition: dovi_meta.c:44
AVDOVINLQMethod
AVDOVINLQMethod
Definition: dovi_meta.h:117
AVDOVIDataMapping::nlq_method_idc
enum AVDOVINLQMethod nlq_method_idc
Definition: dovi_meta.h:146
rational.h
AVDOVIReshapingCurve::mmr_coef
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
Definition: dovi_meta.h:114
AVDOVIMappingMethod
AVDOVIMappingMethod
Definition: dovi_meta.h:94
data
const char data[16]
Definition: mxf.c:146
AV_DOVI_NLQ_NONE
@ AV_DOVI_NLQ_NONE
Definition: dovi_meta.h:118
AVDOVIReshapingCurve::mapping_idc
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:107
AVDOVIRpuDataHeader::rpu_format
uint16_t rpu_format
Definition: dovi_meta.h:78
AVDOVIDataMapping::mapping_color_space
uint8_t mapping_color_space
Definition: dovi_meta.h:141
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:76
AVDOVIRpuDataHeader::coef_data_type
uint8_t coef_data_type
Definition: dovi_meta.h:82
AVDOVIRpuDataHeader::el_bit_depth
uint8_t el_bit_depth
Definition: dovi_meta.h:87
AVDOVIColorMetadata::signal_eotf_param0
uint16_t signal_eotf_param0
Definition: dovi_meta.h:177
AVDOVIColorMetadata::ycc_to_rgb_offset
AVRational ycc_to_rgb_offset[3]
Definition: dovi_meta.h:170
AVDOVIRpuDataHeader::vdr_rpu_normalized_idc
uint8_t vdr_rpu_normalized_idc
Definition: dovi_meta.h:84
AVDOVIRpuDataHeader::el_spatial_resampling_filter_flag
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:90
AVDOVIColorMetadata::dm_metadata_id
uint8_t dm_metadata_id
Definition: dovi_meta.h:158
AVDOVIRpuDataHeader::chroma_resampling_explicit_filter_flag
uint8_t chroma_resampling_explicit_filter_flag
Definition: dovi_meta.h:81
AVDOVIRpuDataHeader::vdr_bit_depth
uint8_t vdr_bit_depth
Definition: dovi_meta.h:88
AVDOVIRpuDataHeader::rpu_type
uint8_t rpu_type
Definition: dovi_meta.h:77
AVDOVIMetadata
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition: dovi_meta.h:197
AVDOVIReshapingCurve::mmr_order
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:112
AVDOVIRpuDataHeader::spatial_resampling_filter_flag
uint8_t spatial_resampling_filter_flag
Definition: dovi_meta.h:89
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:55
AV_DOVI_MAPPING_POLYNOMIAL
@ AV_DOVI_MAPPING_POLYNOMIAL
Definition: dovi_meta.h:95
AVDOVIDecoderConfigurationRecord::dv_version_major
uint8_t dv_version_major
Definition: dovi_meta.h:53
av_dovi_get_header
static av_always_inline AVDOVIRpuDataHeader * av_dovi_get_header(const AVDOVIMetadata *data)
Definition: dovi_meta.h:208
AVDOVIReshapingCurve::poly_order
uint8_t poly_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:109
AVDOVINLQParams::linear_deadzone_threshold
uint64_t linear_deadzone_threshold
Definition: dovi_meta.h:131
AVDOVIColorMetadata::signal_eotf_param2
uint32_t signal_eotf_param2
Definition: dovi_meta.h:179
AVDOVIDecoderConfigurationRecord::dv_level
uint8_t dv_level
Definition: dovi_meta.h:56
AVDOVIDecoderConfigurationRecord::dv_bl_signal_compatibility_id
uint8_t dv_bl_signal_compatibility_id
Definition: dovi_meta.h:60
AVDOVIColorMetadata::signal_bit_depth
uint8_t signal_bit_depth
Definition: dovi_meta.h:180
AV_DOVI_MAPPING_MMR
@ AV_DOVI_MAPPING_MMR
Definition: dovi_meta.h:96
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVDOVIColorMetadata::signal_eotf
uint16_t signal_eotf
Extra signal metadata (see Dolby patents for more info).
Definition: dovi_meta.h:176
AVDOVIMetadata::header_offset
size_t header_offset
Offset in bytes from the beginning of this structure at which the respective structs start.
Definition: dovi_meta.h:202
AVDOVIReshapingCurve::mmr_constant
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:113
AVDOVIColorMetadata::scene_refresh_flag
uint8_t scene_refresh_flag
Definition: dovi_meta.h:159
AV_DOVI_NLQ_LINEAR_DZ
@ AV_DOVI_NLQ_LINEAR_DZ
Definition: dovi_meta.h:119
AVDOVIRpuDataHeader::vdr_rpu_profile
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:79
size
int size
Definition: twinvq_data.h:10344
AVDOVIMetadata::mapping_offset
size_t mapping_offset
Definition: dovi_meta.h:203
AVDOVIRpuDataHeader::coef_log2_denom
uint8_t coef_log2_denom
Definition: dovi_meta.h:83
AVDOVIRpuDataHeader::bl_video_full_range_flag
uint8_t bl_video_full_range_flag
Definition: dovi_meta.h:85
AVDOVIReshapingCurve::poly_coef
int64_t poly_coef[AV_DOVI_MAX_PIECES][3]
Definition: dovi_meta.h:110
AVDOVIColorMetadata::source_min_pq
uint16_t source_min_pq
Definition: dovi_meta.h:184
av_dovi_alloc
AVDOVIDecoderConfigurationRecord * av_dovi_alloc(size_t *size)
Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its fields to default values.
Definition: dovi_meta.c:24
AVDOVIMetadata::color_offset
size_t color_offset
Definition: dovi_meta.h:204
AVDOVIDataMapping::num_y_partitions
uint32_t num_y_partitions
Definition: dovi_meta.h:148
av_always_inline
#define av_always_inline
Definition: attributes.h:49
AVDOVINLQParams
Coefficients of the non-linear inverse quantization.
Definition: dovi_meta.h:126
AVDOVIDataMapping::curves
AVDOVIReshapingCurve curves[3]
Definition: dovi_meta.h:143
AVDOVIColorMetadata::source_diagonal
uint16_t source_diagonal
Definition: dovi_meta.h:186
AVDOVINLQParams::linear_deadzone_slope
uint64_t linear_deadzone_slope
Definition: dovi_meta.h:130
AVDOVIReshapingCurve
Definition: dovi_meta.h:104
AVDOVIColorMetadata::signal_chroma_format
uint8_t signal_chroma_format
Definition: dovi_meta.h:182
AVDOVIColorMetadata::signal_eotf_param1
uint16_t signal_eotf_param1
Definition: dovi_meta.h:178
AVDOVINLQParams::vdr_in_max
uint64_t vdr_in_max
Definition: dovi_meta.h:128
AVDOVIColorMetadata::rgb_to_lms_matrix
AVRational rgb_to_lms_matrix[9]
Definition: dovi_meta.h:171
AVDOVIReshapingCurve::num_pivots
uint8_t num_pivots
Definition: dovi_meta.h:105
AVDOVIRpuDataHeader::vdr_rpu_level
uint8_t vdr_rpu_level
Definition: dovi_meta.h:80
av_dovi_get_color
static av_always_inline AVDOVIColorMetadata * av_dovi_get_color(const AVDOVIMetadata *data)
Definition: dovi_meta.h:220
AVDOVIDataMapping::mapping_chroma_format_idc
uint8_t mapping_chroma_format_idc
Definition: dovi_meta.h:142
AVDOVIDecoderConfigurationRecord::bl_present_flag
uint8_t bl_present_flag
Definition: dovi_meta.h:59
AVDOVIRpuDataHeader::bl_bit_depth
uint8_t bl_bit_depth
Definition: dovi_meta.h:86
AVDOVIColorMetadata
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:157
AVDOVIDecoderConfigurationRecord::rpu_present_flag
uint8_t rpu_present_flag
Definition: dovi_meta.h:57
AVDOVIDecoderConfigurationRecord::el_present_flag
uint8_t el_present_flag
Definition: dovi_meta.h:58
AVDOVIColorMetadata::source_max_pq
uint16_t source_max_pq
Definition: dovi_meta.h:185
AVDOVIDecoderConfigurationRecord::dv_version_minor
uint8_t dv_version_minor
Definition: dovi_meta.h:54
av_dovi_get_mapping
static av_always_inline AVDOVIDataMapping * av_dovi_get_mapping(const AVDOVIMetadata *data)
Definition: dovi_meta.h:214
AVDOVIReshapingCurve::pivots
uint16_t pivots[AV_DOVI_MAX_PIECES+1]
Definition: dovi_meta.h:106
AVDOVIColorMetadata::ycc_to_rgb_matrix
AVRational ycc_to_rgb_matrix[9]
Coefficients of the custom Dolby Vision IPT-PQ matrices.
Definition: dovi_meta.h:169
AVDOVINLQParams::nlq_offset
uint16_t nlq_offset
Definition: dovi_meta.h:127
AVDOVIDataMapping::vdr_rpu_id
uint8_t vdr_rpu_id
Definition: dovi_meta.h:140
AVDOVIRpuDataHeader::disable_residual_flag
uint8_t disable_residual_flag
Definition: dovi_meta.h:91
AVDOVIDataMapping::nlq
AVDOVINLQParams nlq[3]
Definition: dovi_meta.h:149
AVDOVIColorMetadata::signal_color_space
uint8_t signal_color_space
Definition: dovi_meta.h:181
AVDOVIDataMapping
Dolby Vision RPU data mapping parameters.
Definition: dovi_meta.h:139
AVDOVIColorMetadata::signal_full_range_flag
uint8_t signal_full_range_flag
Definition: dovi_meta.h:183
AV_DOVI_MAX_PIECES
#define AV_DOVI_MAX_PIECES
Coefficients of a piece-wise function.
Definition: dovi_meta.h:103
AVDOVIDataMapping::num_x_partitions
uint32_t num_x_partitions
Definition: dovi_meta.h:147
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:52