FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/mastering_display_metadata.c
Date: 2026-08-26 01:27:24
Exec Total Coverage
Lines: 75 80 93.8%
Functions: 1 1 100.0%
Branches: 16 32 50.0%

Line Branch Exec Source
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"
23 #include "libavutil/mastering_display_metadata.h"
24 #include "libavutil/mem.h"
25
26 1 int main(void)
27 {
28 AVMasteringDisplayMetadata *mdm;
29 AVContentLightMetadata *clm;
30 AVFrame *frame;
31 size_t size;
32
33 /* av_mastering_display_metadata_alloc */
34 1 printf("Testing av_mastering_display_metadata_alloc()\n");
35 1 mdm = av_mastering_display_metadata_alloc();
36
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (mdm) {
37 /* verify defaults: all rationals should be {0, 1} */
38 1 printf("alloc: OK\n");
39 1 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 1 printf("defaults: min_lum=%d/%d, max_lum=%d/%d\n",
44 mdm->min_luminance.num, mdm->min_luminance.den,
45 mdm->max_luminance.num, mdm->max_luminance.den);
46 1 printf("defaults: has_primaries=%d, has_luminance=%d\n",
47 mdm->has_primaries, mdm->has_luminance);
48 1 av_free(mdm);
49 } else {
50 printf("alloc: FAIL\n");
51 }
52
53 /* av_mastering_display_metadata_alloc_size */
54 1 printf("\nTesting av_mastering_display_metadata_alloc_size()\n");
55 1 mdm = av_mastering_display_metadata_alloc_size(&size);
56
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (mdm) {
57
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("alloc_size: OK, size>0=%s\n", size > 0 ? "yes" : "no");
58 1 printf("defaults: primaries[0][0]=%d/%d\n",
59 mdm->display_primaries[0][0].num,
60 mdm->display_primaries[0][0].den);
61 1 av_free(mdm);
62 } else {
63 printf("alloc_size: FAIL\n");
64 }
65
66 /* write and read back */
67 1 printf("\nTesting write/read back\n");
68 1 mdm = av_mastering_display_metadata_alloc();
69
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (mdm) {
70 1 mdm->display_primaries[0][0] = (AVRational){ 34000, 50000 };
71 1 mdm->display_primaries[0][1] = (AVRational){ 16000, 50000 };
72 1 mdm->white_point[0] = (AVRational){ 15635, 50000 };
73 1 mdm->white_point[1] = (AVRational){ 16450, 50000 };
74 1 mdm->min_luminance = (AVRational){ 50, 10000 };
75 1 mdm->max_luminance = (AVRational){ 10000000, 10000 };
76 1 mdm->has_primaries = 1;
77 1 mdm->has_luminance = 1;
78 1 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 1 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 1 printf("luminance: min=%d/%d max=%d/%d\n",
87 mdm->min_luminance.num, mdm->min_luminance.den,
88 mdm->max_luminance.num, mdm->max_luminance.den);
89 1 av_free(mdm);
90 }
91
92 /* av_mastering_display_metadata_create_side_data */
93 1 printf("\nTesting av_mastering_display_metadata_create_side_data()\n");
94 1 frame = av_frame_alloc();
95
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
96 1 mdm = av_mastering_display_metadata_create_side_data(frame);
97
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (mdm) {
98 1 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 }
104 1 av_frame_free(&frame);
105 }
106
107 /* av_content_light_metadata_alloc */
108 1 printf("\nTesting av_content_light_metadata_alloc()\n");
109 1 clm = av_content_light_metadata_alloc(&size);
110
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (clm) {
111 1 printf("alloc: OK, size>0=%s, MaxCLL=%u, MaxFALL=%u\n",
112
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 size > 0 ? "yes" : "no", clm->MaxCLL, clm->MaxFALL);
113 1 clm->MaxCLL = 1000;
114 1 clm->MaxFALL = 400;
115 1 printf("write: MaxCLL=%u, MaxFALL=%u\n", clm->MaxCLL, clm->MaxFALL);
116 1 av_free(clm);
117 } else {
118 printf("alloc: FAIL\n");
119 }
120
121 /* av_content_light_metadata_create_side_data */
122 1 printf("\nTesting av_content_light_metadata_create_side_data()\n");
123 1 frame = av_frame_alloc();
124
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
125 1 clm = av_content_light_metadata_create_side_data(frame);
126
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (clm) {
127 1 printf("side_data: OK, MaxCLL=%u\n", clm->MaxCLL);
128 } else {
129 printf("side_data: FAIL\n");
130 }
131 1 av_frame_free(&frame);
132 }
133
134 /* OOM paths via av_max_alloc */
135 1 printf("\nTesting OOM paths\n");
136 1 av_max_alloc(1);
137 1 mdm = av_mastering_display_metadata_alloc();
138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("mastering alloc OOM: %s\n", mdm ? "FAIL" : "OK");
139 1 av_free(mdm);
140 1 mdm = av_mastering_display_metadata_alloc_size(&size);
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("mastering alloc_size OOM: %s\n", mdm ? "FAIL" : "OK");
142 1 av_free(mdm);
143 1 clm = av_content_light_metadata_alloc(&size);
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("content alloc OOM: %s\n", clm ? "FAIL" : "OK");
145 1 av_free(clm);
146 1 av_max_alloc(INT_MAX);
147
148 1 frame = av_frame_alloc();
149
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
150 1 av_max_alloc(1);
151 1 mdm = av_mastering_display_metadata_create_side_data(frame);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("mastering side_data OOM: %s\n", mdm ? "FAIL" : "OK");
153 1 clm = av_content_light_metadata_create_side_data(frame);
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("content side_data OOM: %s\n", clm ? "FAIL" : "OK");
155 1 av_max_alloc(INT_MAX);
156 1 av_frame_free(&frame);
157 }
158
159 1 return 0;
160 }
161