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
22
33 API changes, most recent first:
44
5+2024-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+
510 2024-04-xx - xxxxxxxxxx - lavu 59.11.100 - dovi_meta.h
611 Add AVDOVIDataMapping.nlq_pivots.
712
libavutil/dovi_meta.c+19−3
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919 */
2020
21+#include <string.h>
22+
2123 #include "dovi_meta.h"
2224 #include "mem.h"
2325
@@ -39,6 +41,7 @@ typedef struct AVDOVIMetadataInternal { · 15 unmodified lines
3941 AVDOVIRpuDataHeader header;
4042 AVDOVIDataMapping mapping;
4143 AVDOVIColorMetadata color;
44+ AVDOVIDmData ext_blocks[AV_DOVI_MAX_EXT_BLOCKS];
4245 } AVDOVIMetadataInternal;
4346
4447 AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
@@ -51,10 +54,23 @@ AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size) · 6 unmodified lines
5154 *size = sizeof(*dovi);
5255
5356 dovi->metadata = (struct AVDOVIMetadata) {
54− .header_offset = offsetof(AVDOVIMetadataInternal, header),
55− .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
56− .color_offset = offsetof(AVDOVIMetadataInternal, color),
57+ .header_offset = offsetof(AVDOVIMetadataInternal, header),
58+ .mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
59+ .color_offset = offsetof(AVDOVIMetadataInternal, color),
60+ .ext_block_offset = offsetof(AVDOVIMetadataInternal, ext_blocks),
61+ .ext_block_size = sizeof(AVDOVIDmData),
5762 };
5863
5964 return &dovi->metadata;
6065 }
66+
67+AVDOVIDmData *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
2929
3030 #include <stdint.h>
3131 #include <stddef.h>
32+
3233 #include "rational.h"
34+#include "csp.h"
3335
3436 /*
3537 * DOVI configuration
@@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata { · 151 unmodified lines
187189 uint16_t source_diagonal;
188190 } AVDOVIColorMetadata;
189191
192+typedef 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+
199+typedef 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+
210+typedef struct AVDOVIDmLevel3 {
211+ uint16_t min_pq_offset;
212+ uint16_t max_pq_offset;
213+ uint16_t avg_pq_offset;
214+} AVDOVIDmLevel3;
215+
216+typedef struct AVDOVIDmLevel4 {
217+ uint16_t anchor_pq;
218+ uint16_t anchor_power;
219+} AVDOVIDmLevel4;
220+
221+typedef 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+
229+typedef 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+
237+typedef 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+
252+typedef struct AVDOVIDmLevel9 {
253+ /* Source display characteristics */
254+ uint8_t source_primary_index;
255+ AVColorPrimariesDesc source_display_primaries;
256+} AVDOVIDmLevel9;
257+
258+typedef 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+
267+typedef 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+
279+typedef 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+
285+typedef 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+ */
297+typedef 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+
190316 /**
191317 * Combined struct representing a combination of header, mapping and color
192318 * metadata, for attaching to frames as side data.
@@ -203,6 +329,13 @@ typedef struct AVDOVIMetadata { · 10 unmodified lines
203329 size_t header_offset; /* AVDOVIRpuDataHeader */
204330 size_t mapping_offset; /* AVDOVIDataMapping */
205331 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
206339 } AVDOVIMetadata;
207340
208341 static av_always_inline AVDOVIRpuDataHeader *
@@ -223,6 +356,19 @@ av_dovi_get_color(const AVDOVIMetadata *data) · 14 unmodified lines
223356 return (AVDOVIColorMetadata *)((uint8_t *) data + data->color_offset);
224357 }
225358
359+static av_always_inline AVDOVIDmData *
360+av_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+ */
370+AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level);
371+
226372 /**
227373 * Allocate an AVDOVIMetadata structure and initialize its
228374 * fields to default values.
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 59
82−#define LIBAVUTIL_VERSION_MINOR 11
82+#define LIBAVUTIL_VERSION_MINOR 12
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #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