FFmpeg
dovi_meta.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <limits.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 
23 #include "libavutil/dovi_meta.h"
24 #include "libavutil/mem.h"
25 
26 int main(void)
27 {
30  size_t size;
31 
32  /* av_dovi_alloc */
33  printf("Testing av_dovi_alloc()\n");
35  if (cfg) {
36  printf("alloc: OK, size>0=%s, dv_profile=%d\n",
37  size > 0 ? "yes" : "no", cfg->dv_profile);
38  av_free(cfg);
39  } else {
40  printf("alloc: FAIL\n");
41  }
42 
44  printf("alloc (no size): %s\n", cfg ? "OK" : "FAIL");
45  av_free(cfg);
46 
47  /* av_dovi_metadata_alloc */
48  printf("\nTesting av_dovi_metadata_alloc()\n");
50  if (md) {
52  AVDOVIDataMapping *mapping;
54 
55  printf("alloc: OK, size>0=%s\n", size > 0 ? "yes" : "no");
56  printf("num_ext_blocks=%d\n", md->num_ext_blocks);
57 
58  /* pointer consistency checks for inline accessors */
60  if ((uint8_t *)header != (uint8_t *)md + md->header_offset)
61  printf("header: pointer inconsistent with header_offset\n");
62  printf("header_offset>0=%s, rpu_type=%d\n",
63  md->header_offset > 0 ? "yes" : "no",
64  header->rpu_type);
65 
66  mapping = av_dovi_get_mapping(md);
67  if ((uint8_t *)mapping != (uint8_t *)md + md->mapping_offset)
68  printf("mapping: pointer inconsistent with mapping_offset\n");
69  printf("mapping_offset>0=%s, nlq_method_idc=%d\n",
70  md->mapping_offset > 0 ? "yes" : "no",
71  mapping->nlq_method_idc);
72 
74  if ((uint8_t *)color != (uint8_t *)md + md->color_offset)
75  printf("color: pointer inconsistent with color_offset\n");
76  printf("color_offset>0=%s, dm_metadata_id=%d\n",
77  md->color_offset > 0 ? "yes" : "no",
78  color->dm_metadata_id);
79 
80  printf("ext_block_size>0=%s\n",
81  md->ext_block_size > 0 ? "yes" : "no");
82 
83  av_free(md);
84  } else {
85  printf("alloc: FAIL\n");
86  }
87 
89  printf("alloc (no size): %s\n", md ? "OK" : "FAIL");
90  av_free(md);
91 
92  /* av_dovi_find_level */
93  printf("\nTesting av_dovi_find_level()\n");
95  if (md) {
96  AVDOVIDmData *ext, *found;
97 
98  /* set up 3 ext blocks with different levels */
99  md->num_ext_blocks = 3;
100  ext = av_dovi_get_ext(md, 0);
101  if ((uint8_t *)ext != (uint8_t *)md + md->ext_block_offset)
102  printf("ext[0]: pointer inconsistent with ext_block_offset\n");
103  ext->level = 1;
104  ext = av_dovi_get_ext(md, 1);
105  ext->level = 5;
106  ext = av_dovi_get_ext(md, 2);
107  ext->level = 1;
108 
109  found = av_dovi_find_level(md, 1);
110  printf("find level 1: %s\n", found && found->level == 1 ? "OK" : "FAIL");
111 
112  found = av_dovi_find_level(md, 5);
113  printf("find level 5: %s\n", found && found->level == 5 ? "OK" : "FAIL");
114 
115  /* first match -- should return ext[0], not ext[2] */
116  found = av_dovi_find_level(md, 1);
117  printf("find level 1 first match: %s\n",
118  found == av_dovi_get_ext(md, 0) ? "OK" : "FAIL");
119 
120  found = av_dovi_find_level(md, 99);
121  printf("find level 99 (missing): %s\n", found == NULL ? "OK" : "FAIL");
122 
123  av_free(md);
124  }
125 
126  /* OOM paths via av_max_alloc */
127  printf("\nTesting OOM paths\n");
128  av_max_alloc(1);
129  cfg = av_dovi_alloc(&size);
130  printf("av_dovi_alloc OOM: %s\n", cfg ? "FAIL" : "OK");
131  av_free(cfg);
133  printf("av_dovi_metadata_alloc OOM: %s\n", md ? "FAIL" : "OK");
134  av_free(md);
135  av_max_alloc(INT_MAX);
136 
137  return 0;
138 }
AVDOVIDataMapping::nlq_method_idc
enum AVDOVINLQMethod nlq_method_idc
Definition: dovi_meta.h:159
printf
__device__ int printf(const char *,...)
color
Definition: vf_paletteuse.c:513
md
#define md
Definition: vf_colormatrix.c:101
av_dovi_get_ext
static av_always_inline AVDOVIDmData * av_dovi_get_ext(const AVDOVIMetadata *data, int index)
Gets the specified Dolby Vision Display Management (DM) metadata.
Definition: dovi_meta.h:385
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:87
av_max_alloc
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition: mem.c:76
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:26
AVDOVIDmData
Dolby Vision metadata extension block.
Definition: dovi_meta.h:318
av_dovi_find_level
AVDOVIDmData * av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level)
Find an extension block with a given level, or NULL.
Definition: dovi_meta.c:66
AVDOVIMetadata
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition: dovi_meta.h:345
limits.h
av_dovi_get_header
static av_always_inline AVDOVIRpuDataHeader * av_dovi_get_header(const AVDOVIMetadata *data)
Definition: dovi_meta.h:363
main
int main(void)
Definition: dovi_meta.c:26
NULL
#define NULL
Definition: coverity.c:32
cfg
static CheckasmConfig cfg
Definition: checkasm.c:74
size
int size
Definition: twinvq_data.h:10344
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:98
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:45
header
static const uint8_t header[24]
Definition: sdr2.c:68
dovi_meta.h
av_dovi_get_color
static av_always_inline AVDOVIColorMetadata * av_dovi_get_color(const AVDOVIMetadata *data)
Definition: dovi_meta.h:375
AVDOVIColorMetadata
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:171
AVDOVIDmData::level
uint8_t level
Definition: dovi_meta.h:319
mem.h
av_dovi_get_mapping
static av_always_inline AVDOVIDataMapping * av_dovi_get_mapping(const AVDOVIMetadata *data)
Definition: dovi_meta.h:369
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDOVIDataMapping
Dolby Vision RPU data mapping parameters.
Definition: dovi_meta.h:152
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:55