FFmpeg
Loading...
Searching...
No Matches
mastering_display_metadata.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 <stdio.h>
21
22#include "libavutil/frame.h"
24#include "libavutil/mem.h"
25
26int main(void)
27{
31 size_t size;
32
33 /* av_mastering_display_metadata_alloc */
34 printf("Testing av_mastering_display_metadata_alloc()\n");
36 if (mdm) {
37 /* verify defaults: all rationals should be {0, 1} */
38 printf("alloc: OK\n");
39 printf("defaults: primaries[0][0]=%d/%d, white_point[0]=%d/%d\n",
40 mdm->display_primaries[0][0].num,
41 mdm->display_primaries[0][0].den,
42 mdm->white_point[0].num, mdm->white_point[0].den);
43 printf("defaults: min_lum=%d/%d, max_lum=%d/%d\n",
46 printf("defaults: has_primaries=%d, has_luminance=%d\n",
47 mdm->has_primaries, mdm->has_luminance);
48 av_free(mdm);
49 } else {
50 printf("alloc: FAIL\n");
51 }
52
53 /* av_mastering_display_metadata_alloc_size */
54 printf("\nTesting av_mastering_display_metadata_alloc_size()\n");
56 if (mdm) {
57 printf("alloc_size: OK, size>0=%s\n", size > 0 ? "yes" : "no");
58 printf("defaults: primaries[0][0]=%d/%d\n",
59 mdm->display_primaries[0][0].num,
60 mdm->display_primaries[0][0].den);
61 av_free(mdm);
62 } else {
63 printf("alloc_size: FAIL\n");
64 }
65
66 /* write and read back */
67 printf("\nTesting write/read back\n");
69 if (mdm) {
70 mdm->display_primaries[0][0] = (AVRational){ 34000, 50000 };
71 mdm->display_primaries[0][1] = (AVRational){ 16000, 50000 };
72 mdm->white_point[0] = (AVRational){ 15635, 50000 };
73 mdm->white_point[1] = (AVRational){ 16450, 50000 };
74 mdm->min_luminance = (AVRational){ 50, 10000 };
75 mdm->max_luminance = (AVRational){ 10000000, 10000 };
76 mdm->has_primaries = 1;
77 mdm->has_luminance = 1;
78 printf("primaries[0]=(%d/%d, %d/%d)\n",
79 mdm->display_primaries[0][0].num,
80 mdm->display_primaries[0][0].den,
81 mdm->display_primaries[0][1].num,
82 mdm->display_primaries[0][1].den);
83 printf("white_point=(%d/%d, %d/%d)\n",
84 mdm->white_point[0].num, mdm->white_point[0].den,
85 mdm->white_point[1].num, mdm->white_point[1].den);
86 printf("luminance: min=%d/%d max=%d/%d\n",
89 av_free(mdm);
90 }
91
92 /* av_mastering_display_metadata_create_side_data */
93 printf("\nTesting av_mastering_display_metadata_create_side_data()\n");
95 if (frame) {
97 if (mdm) {
98 printf("side_data: OK, defaults: primaries[0][0]=%d/%d\n",
99 mdm->display_primaries[0][0].num,
100 mdm->display_primaries[0][0].den);
101 } else {
102 printf("side_data: FAIL\n");
103 }
105 }
106
107 /* av_content_light_metadata_alloc */
108 printf("\nTesting av_content_light_metadata_alloc()\n");
110 if (clm) {
111 printf("alloc: OK, size>0=%s, MaxCLL=%u, MaxFALL=%u\n",
112 size > 0 ? "yes" : "no", clm->MaxCLL, clm->MaxFALL);
113 clm->MaxCLL = 1000;
114 clm->MaxFALL = 400;
115 printf("write: MaxCLL=%u, MaxFALL=%u\n", clm->MaxCLL, clm->MaxFALL);
116 av_free(clm);
117 } else {
118 printf("alloc: FAIL\n");
119 }
120
121 /* av_content_light_metadata_create_side_data */
122 printf("\nTesting av_content_light_metadata_create_side_data()\n");
124 if (frame) {
126 if (clm) {
127 printf("side_data: OK, MaxCLL=%u\n", clm->MaxCLL);
128 } else {
129 printf("side_data: FAIL\n");
130 }
132 }
133
134 /* OOM paths via av_max_alloc */
135 printf("\nTesting OOM paths\n");
136 av_max_alloc(1);
138 printf("mastering alloc OOM: %s\n", mdm ? "FAIL" : "OK");
139 av_free(mdm);
141 printf("mastering alloc_size OOM: %s\n", mdm ? "FAIL" : "OK");
142 av_free(mdm);
144 printf("content alloc OOM: %s\n", clm ? "FAIL" : "OK");
145 av_free(clm);
146 av_max_alloc(INT_MAX);
147
149 if (frame) {
150 av_max_alloc(1);
152 printf("mastering side_data OOM: %s\n", mdm ? "FAIL" : "OK");
154 printf("content side_data OOM: %s\n", clm ? "FAIL" : "OK");
155 av_max_alloc(INT_MAX);
157 }
158
159 return 0;
160}
__device__ int printf(const char *,...)
static AVFrame * frame
reference-counted frame API
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition mem.c:76
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc(void)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Memory handling functions.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
#define av_free(p)
int main(void)
int size