FFmpeg
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 
26 int main(void)
27 {
30  AVFrame *frame;
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",
45  mdm->max_luminance.num, mdm->max_luminance.den);
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",
88  mdm->max_luminance.num, mdm->max_luminance.den);
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");
123  frame = av_frame_alloc();
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 
148  frame = av_frame_alloc();
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 }
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
printf
__device__ int printf(const char *,...)
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
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
AVRational::num
int num
Numerator.
Definition: rational.h:59
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
av_mastering_display_metadata_alloc
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc(void)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:39
main
int main(void)
Definition: mastering_display_metadata.c:26
limits.h
av_content_light_metadata_alloc
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:73
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
size
int size
Definition: twinvq_data.h:10344
frame.h
av_content_light_metadata_create_side_data
AVContentLightMetadata * av_content_light_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVContentLightMetadata and add it to the frame.
Definition: mastering_display_metadata.c:83
av_mastering_display_metadata_alloc_size
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:44
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
av_mastering_display_metadata_create_side_data
AVMasteringDisplayMetadata * av_mastering_display_metadata_create_side_data(AVFrame *frame)
Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
Definition: mastering_display_metadata.c:59
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
mem.h
mastering_display_metadata.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116