History

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.

Niklas Haas committed 2 years ago

Commit 4f55e161 parent 78076ed4 files · +171 −4Browse files

Unified · Split

4 files
  1. doc/APIchanges +5 −0
  2. libavutil/dovi_meta.c +19 −3
  3. libavutil/dovi_meta.h +146 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+5−0
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07 · 1 unmodified line
2 2
3API changes, most recent first:3API changes, most recent first:
4 4
52024-04-xx - xxxxxxxxxx - lavu 59.12.100 - dovi_meta.h
6 Add AVDOVIMetadata.ext_block_{offset,size}, AVDOVIMetadata.num_ext_blocks,
7 AVDOVIDmData and AVDOVIDmLevel{1..6,8..11,254..255}, av_dovi_get_ext()
8 and av_dovi_find_level().
9
52024-04-xx - xxxxxxxxxx - lavu 59.11.100 - dovi_meta.h102024-04-xx - xxxxxxxxxx - lavu 59.11.100 - dovi_meta.h
6 Add AVDOVIDataMapping.nlq_pivots.11 Add AVDOVIDataMapping.nlq_pivots.
7 12
libavutil/dovi_meta.c+19−3
@@ -18,6 +18,8 @@ · 17 unmodified lines
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */19 */
20 20
21#include <string.h>
22
21#include "dovi_meta.h"23#include "dovi_meta.h"
22#include "mem.h"24#include "mem.h"
23 25
@@ -39,6 +41,7 @@ typedef struct AVDOVIMetadataInternal { · 15 unmodified lines
39 AVDOVIRpuDataHeader header;41 AVDOVIRpuDataHeader header;
40 AVDOVIDataMapping mapping;42 AVDOVIDataMapping mapping;
41 AVDOVIColorMetadata color;43 AVDOVIColorMetadata color;
44 AVDOVIDmData ext_blocks[AV_DOVI_MAX_EXT_BLOCKS];
42} AVDOVIMetadataInternal;45} AVDOVIMetadataInternal;
43 46
44AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)47AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
@@ -51,10 +54,23 @@ AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size) · 6 unmodified lines
51 *size = sizeof(*dovi);54 *size = sizeof(*dovi);
52 55
53 dovi->metadata = (struct AVDOVIMetadata) {56 dovi->metadata = (struct AVDOVIMetadata) {
54 .header_offset = offsetof(AVDOVIMetadataInternal, header),57 .header_offset = offsetof(AVDOVIMetadataInternal, header),
55 .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),58 .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
56 .color_offset = offsetof(AVDOVIMetadataInternal, color),59 .color_offset = offsetof(AVDOVIMetadataInternal, color),
60 .ext_block_offset = offsetof(AVDOVIMetadataInternal, ext_blocks),
61 .ext_block_size = sizeof(AVDOVIDmData),
57 };62 };
58 63
59 return &dovi->metadata;64 return &dovi->metadata;
60}65}
66
67AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level)
68{
69 for (int i = 0; i < data->num_ext_blocks; i++) {
70 AVDOVIDmData *ext = av_dovi_get_ext(data, i);
71 if (ext->level == level)
72 return ext;
73 }
74
75 return NULL;
76}
libavutil/dovi_meta.h+146−0
@@ -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 configuration37 * 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
192typedef 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
199typedef 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
210typedef struct AVDOVIDmLevel3 {
211 uint16_t min_pq_offset;
212 uint16_t max_pq_offset;
213 uint16_t avg_pq_offset;
214} AVDOVIDmLevel3;
215
216typedef struct AVDOVIDmLevel4 {
217 uint16_t anchor_pq;
218 uint16_t anchor_power;
219} AVDOVIDmLevel4;
220
221typedef 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
229typedef 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
237typedef 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
252typedef struct AVDOVIDmLevel9 {
253 /* Source display characteristics */
254 uint8_t source_primary_index;
255 AVColorPrimariesDesc source_display_primaries;
256} AVDOVIDmLevel9;
257
258typedef 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
267typedef 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
279typedef 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
285typedef 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 */
297typedef 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 color317 * 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
208static av_always_inline AVDOVIRpuDataHeader *341static 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
359static av_always_inline AVDOVIDmData *
360av_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 */
370AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level);
371
226/**372/**
227 * Allocate an AVDOVIMetadata structure and initialize its373 * Allocate an AVDOVIMetadata structure and initialize its
228 * fields to default values.374 * fields to default values.
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5981#define LIBAVUTIL_VERSION_MAJOR 59
82#define LIBAVUTIL_VERSION_MINOR 1182#define LIBAVUTIL_VERSION_MINOR 12
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t