FFmpeg 5.1.6
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;
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 */
76typedef struct AVDOVIRpuDataHeader {
77 uint8_t rpu_type;
78 uint16_t rpu_format;
82 uint8_t coef_data_type; /* informative, lavc always converts to fixed */
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
104typedef 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 */
126typedef 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 */
139typedef 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 */
157typedef struct AVDOVIColorMetadata {
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] */
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
197typedef 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 */
#define av_always_inline
Definition: attributes.h:45
static av_always_inline AVDOVIColorMetadata * av_dovi_get_color(const AVDOVIMetadata *data)
Definition: dovi_meta.h:220
AVDOVIDecoderConfigurationRecord * av_dovi_alloc(size_t *size)
Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its fields to default values.
static av_always_inline AVDOVIRpuDataHeader * av_dovi_get_header(const AVDOVIMetadata *data)
Definition: dovi_meta.h:208
AVDOVIMappingMethod
Definition: dovi_meta.h:94
@ AV_DOVI_MAPPING_MMR
Definition: dovi_meta.h:96
@ AV_DOVI_MAPPING_POLYNOMIAL
Definition: dovi_meta.h:95
AVDOVINLQMethod
Definition: dovi_meta.h:117
@ AV_DOVI_NLQ_NONE
Definition: dovi_meta.h:118
@ AV_DOVI_NLQ_LINEAR_DZ
Definition: dovi_meta.h:119
AVDOVIMetadata * av_dovi_metadata_alloc(size_t *size)
Allocate an AVDOVIMetadata structure and initialize its fields to default values.
static av_always_inline AVDOVIDataMapping * av_dovi_get_mapping(const AVDOVIMetadata *data)
Definition: dovi_meta.h:214
#define AV_DOVI_MAX_PIECES
Coefficients of a piece-wise function.
Definition: dovi_meta.h:103
Utilties for rational number calculation.
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:157
uint16_t signal_eotf
Extra signal metadata (see Dolby patents for more info).
Definition: dovi_meta.h:176
AVRational rgb_to_lms_matrix[9]
Definition: dovi_meta.h:171
uint8_t signal_bit_depth
Definition: dovi_meta.h:180
AVRational ycc_to_rgb_matrix[9]
Coefficients of the custom Dolby Vision IPT-PQ matrices.
Definition: dovi_meta.h:169
uint16_t signal_eotf_param0
Definition: dovi_meta.h:177
uint16_t signal_eotf_param1
Definition: dovi_meta.h:178
uint8_t scene_refresh_flag
Definition: dovi_meta.h:159
uint16_t source_min_pq
Definition: dovi_meta.h:184
uint8_t signal_chroma_format
Definition: dovi_meta.h:182
uint16_t source_diagonal
Definition: dovi_meta.h:186
uint8_t dm_metadata_id
Definition: dovi_meta.h:158
uint16_t source_max_pq
Definition: dovi_meta.h:185
uint32_t signal_eotf_param2
Definition: dovi_meta.h:179
uint8_t signal_color_space
Definition: dovi_meta.h:181
uint8_t signal_full_range_flag
Definition: dovi_meta.h:183
AVRational ycc_to_rgb_offset[3]
Definition: dovi_meta.h:170
Dolby Vision RPU data mapping parameters.
Definition: dovi_meta.h:139
uint32_t num_x_partitions
Definition: dovi_meta.h:147
uint8_t vdr_rpu_id
Definition: dovi_meta.h:140
AVDOVINLQParams nlq[3]
Definition: dovi_meta.h:149
uint8_t mapping_color_space
Definition: dovi_meta.h:141
uint8_t mapping_chroma_format_idc
Definition: dovi_meta.h:142
AVDOVIReshapingCurve curves[3]
Definition: dovi_meta.h:143
enum AVDOVINLQMethod nlq_method_idc
Definition: dovi_meta.h:146
uint32_t num_y_partitions
Definition: dovi_meta.h:148
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition: dovi_meta.h:197
size_t mapping_offset
Definition: dovi_meta.h:203
size_t color_offset
Definition: dovi_meta.h:204
size_t header_offset
Offset in bytes from the beginning of this structure at which the respective structs start.
Definition: dovi_meta.h:202
Coefficients of the non-linear inverse quantization.
Definition: dovi_meta.h:126
uint64_t linear_deadzone_slope
Definition: dovi_meta.h:130
uint64_t linear_deadzone_threshold
Definition: dovi_meta.h:131
uint16_t nlq_offset
Definition: dovi_meta.h:127
uint64_t vdr_in_max
Definition: dovi_meta.h:128
uint8_t poly_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:109
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:107
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:113
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
Definition: dovi_meta.h:114
int64_t poly_coef[AV_DOVI_MAX_PIECES][3]
Definition: dovi_meta.h:110
uint16_t pivots[AV_DOVI_MAX_PIECES+1]
Definition: dovi_meta.h:106
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:112
Dolby Vision RPU data header.
Definition: dovi_meta.h:76
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:79
uint8_t bl_bit_depth
Definition: dovi_meta.h:86
uint8_t spatial_resampling_filter_flag
Definition: dovi_meta.h:89
uint8_t vdr_bit_depth
Definition: dovi_meta.h:88
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:90
uint8_t bl_video_full_range_flag
Definition: dovi_meta.h:85
uint16_t rpu_format
Definition: dovi_meta.h:78
uint8_t disable_residual_flag
Definition: dovi_meta.h:91
uint8_t vdr_rpu_normalized_idc
Definition: dovi_meta.h:84
uint8_t coef_log2_denom
Definition: dovi_meta.h:83
uint8_t chroma_resampling_explicit_filter_flag
Definition: dovi_meta.h:81
uint8_t el_bit_depth
Definition: dovi_meta.h:87
uint8_t coef_data_type
Definition: dovi_meta.h:82
uint8_t vdr_rpu_level
Definition: dovi_meta.h:80
Rational number (pair of numerator and denominator).
Definition: rational.h:58