mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-08-09 09:32:43 +00:00
tests/fate/libavutil: add FATE test for mastering_display_metadata
Test all 5 public functions: av_mastering_display_metadata_alloc,
av_mastering_display_metadata_alloc_size, the create_side_data
variant, av_content_light_metadata_alloc, and its create_side_data
variant. Verifies the {0,1} rational defaults set by get_defaults(),
write/read-back of HDR metadata fields, frame side data attachment
for both mastering display and content light metadata, and OOM
paths via av_max_alloc.
Coverage for libavutil/mastering_display_metadata.c: 86.49% -> 100.00%
This commit is contained in:
@@ -237,6 +237,7 @@ libavutil/tests/buffer.* @MarcosAsh
|
||||
libavutil/tests/csp.* @MarcosAsh
|
||||
libavutil/tests/dovi_meta.* @MarcosAsh
|
||||
libavutil/tests/hdr_dynamic_vivid_metadata.* @MarcosAsh
|
||||
libavutil/tests/mastering_display_metadata.* @MarcosAsh
|
||||
libavutil/tests/tdrdi.* @MarcosAsh
|
||||
libavutil/tests/timestamp.* @MarcosAsh
|
||||
tests/ref/.*drawvg.* @ayosec
|
||||
@@ -245,6 +246,7 @@ tests/ref/fate/buffer @MarcosAsh
|
||||
tests/ref/fate/csp @MarcosAsh
|
||||
tests/ref/fate/dovi_meta @MarcosAsh
|
||||
tests/ref/fate/hdr_dynamic_vivid_metadata @MarcosAsh
|
||||
tests/ref/fate/mastering_display_metadata @MarcosAsh
|
||||
tests/ref/fate/sub-mcc.* @programmerjake
|
||||
tests/ref/fate/tdrdi @MarcosAsh
|
||||
tests/ref/fate/timestamp @MarcosAsh
|
||||
|
||||
@@ -294,6 +294,7 @@ TESTPROGS = adler32 \
|
||||
lfg \
|
||||
lls \
|
||||
log \
|
||||
mastering_display_metadata \
|
||||
mathematics \
|
||||
md5 \
|
||||
murmur3 \
|
||||
|
||||
1
libavutil/tests/.gitignore
vendored
1
libavutil/tests/.gitignore
vendored
@@ -38,6 +38,7 @@
|
||||
/lls
|
||||
/log
|
||||
/lzo
|
||||
/mastering_display_metadata
|
||||
/mathematics
|
||||
/md5
|
||||
/murmur3
|
||||
|
||||
160
libavutil/tests/mastering_display_metadata.c
Normal file
160
libavutil/tests/mastering_display_metadata.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/frame.h"
|
||||
#include "libavutil/mastering_display_metadata.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVMasteringDisplayMetadata *mdm;
|
||||
AVContentLightMetadata *clm;
|
||||
AVFrame *frame;
|
||||
size_t size;
|
||||
|
||||
/* av_mastering_display_metadata_alloc */
|
||||
printf("Testing av_mastering_display_metadata_alloc()\n");
|
||||
mdm = av_mastering_display_metadata_alloc();
|
||||
if (mdm) {
|
||||
/* verify defaults: all rationals should be {0, 1} */
|
||||
printf("alloc: OK\n");
|
||||
printf("defaults: primaries[0][0]=%d/%d, white_point[0]=%d/%d\n",
|
||||
mdm->display_primaries[0][0].num,
|
||||
mdm->display_primaries[0][0].den,
|
||||
mdm->white_point[0].num, mdm->white_point[0].den);
|
||||
printf("defaults: min_lum=%d/%d, max_lum=%d/%d\n",
|
||||
mdm->min_luminance.num, mdm->min_luminance.den,
|
||||
mdm->max_luminance.num, mdm->max_luminance.den);
|
||||
printf("defaults: has_primaries=%d, has_luminance=%d\n",
|
||||
mdm->has_primaries, mdm->has_luminance);
|
||||
av_free(mdm);
|
||||
} else {
|
||||
printf("alloc: FAIL\n");
|
||||
}
|
||||
|
||||
/* av_mastering_display_metadata_alloc_size */
|
||||
printf("\nTesting av_mastering_display_metadata_alloc_size()\n");
|
||||
mdm = av_mastering_display_metadata_alloc_size(&size);
|
||||
if (mdm) {
|
||||
printf("alloc_size: OK, size>0=%s\n", size > 0 ? "yes" : "no");
|
||||
printf("defaults: primaries[0][0]=%d/%d\n",
|
||||
mdm->display_primaries[0][0].num,
|
||||
mdm->display_primaries[0][0].den);
|
||||
av_free(mdm);
|
||||
} else {
|
||||
printf("alloc_size: FAIL\n");
|
||||
}
|
||||
|
||||
/* write and read back */
|
||||
printf("\nTesting write/read back\n");
|
||||
mdm = av_mastering_display_metadata_alloc();
|
||||
if (mdm) {
|
||||
mdm->display_primaries[0][0] = (AVRational){ 34000, 50000 };
|
||||
mdm->display_primaries[0][1] = (AVRational){ 16000, 50000 };
|
||||
mdm->white_point[0] = (AVRational){ 15635, 50000 };
|
||||
mdm->white_point[1] = (AVRational){ 16450, 50000 };
|
||||
mdm->min_luminance = (AVRational){ 50, 10000 };
|
||||
mdm->max_luminance = (AVRational){ 10000000, 10000 };
|
||||
mdm->has_primaries = 1;
|
||||
mdm->has_luminance = 1;
|
||||
printf("primaries[0]=(%d/%d, %d/%d)\n",
|
||||
mdm->display_primaries[0][0].num,
|
||||
mdm->display_primaries[0][0].den,
|
||||
mdm->display_primaries[0][1].num,
|
||||
mdm->display_primaries[0][1].den);
|
||||
printf("white_point=(%d/%d, %d/%d)\n",
|
||||
mdm->white_point[0].num, mdm->white_point[0].den,
|
||||
mdm->white_point[1].num, mdm->white_point[1].den);
|
||||
printf("luminance: min=%d/%d max=%d/%d\n",
|
||||
mdm->min_luminance.num, mdm->min_luminance.den,
|
||||
mdm->max_luminance.num, mdm->max_luminance.den);
|
||||
av_free(mdm);
|
||||
}
|
||||
|
||||
/* av_mastering_display_metadata_create_side_data */
|
||||
printf("\nTesting av_mastering_display_metadata_create_side_data()\n");
|
||||
frame = av_frame_alloc();
|
||||
if (frame) {
|
||||
mdm = av_mastering_display_metadata_create_side_data(frame);
|
||||
if (mdm) {
|
||||
printf("side_data: OK, defaults: primaries[0][0]=%d/%d\n",
|
||||
mdm->display_primaries[0][0].num,
|
||||
mdm->display_primaries[0][0].den);
|
||||
} else {
|
||||
printf("side_data: FAIL\n");
|
||||
}
|
||||
av_frame_free(&frame);
|
||||
}
|
||||
|
||||
/* av_content_light_metadata_alloc */
|
||||
printf("\nTesting av_content_light_metadata_alloc()\n");
|
||||
clm = av_content_light_metadata_alloc(&size);
|
||||
if (clm) {
|
||||
printf("alloc: OK, size>0=%s, MaxCLL=%u, MaxFALL=%u\n",
|
||||
size > 0 ? "yes" : "no", clm->MaxCLL, clm->MaxFALL);
|
||||
clm->MaxCLL = 1000;
|
||||
clm->MaxFALL = 400;
|
||||
printf("write: MaxCLL=%u, MaxFALL=%u\n", clm->MaxCLL, clm->MaxFALL);
|
||||
av_free(clm);
|
||||
} else {
|
||||
printf("alloc: FAIL\n");
|
||||
}
|
||||
|
||||
/* av_content_light_metadata_create_side_data */
|
||||
printf("\nTesting av_content_light_metadata_create_side_data()\n");
|
||||
frame = av_frame_alloc();
|
||||
if (frame) {
|
||||
clm = av_content_light_metadata_create_side_data(frame);
|
||||
if (clm) {
|
||||
printf("side_data: OK, MaxCLL=%u\n", clm->MaxCLL);
|
||||
} else {
|
||||
printf("side_data: FAIL\n");
|
||||
}
|
||||
av_frame_free(&frame);
|
||||
}
|
||||
|
||||
/* OOM paths via av_max_alloc */
|
||||
printf("\nTesting OOM paths\n");
|
||||
av_max_alloc(1);
|
||||
mdm = av_mastering_display_metadata_alloc();
|
||||
printf("mastering alloc OOM: %s\n", mdm ? "FAIL" : "OK");
|
||||
av_free(mdm);
|
||||
mdm = av_mastering_display_metadata_alloc_size(&size);
|
||||
printf("mastering alloc_size OOM: %s\n", mdm ? "FAIL" : "OK");
|
||||
av_free(mdm);
|
||||
clm = av_content_light_metadata_alloc(&size);
|
||||
printf("content alloc OOM: %s\n", clm ? "FAIL" : "OK");
|
||||
av_free(clm);
|
||||
av_max_alloc(INT_MAX);
|
||||
|
||||
frame = av_frame_alloc();
|
||||
if (frame) {
|
||||
av_max_alloc(1);
|
||||
mdm = av_mastering_display_metadata_create_side_data(frame);
|
||||
printf("mastering side_data OOM: %s\n", mdm ? "FAIL" : "OK");
|
||||
clm = av_content_light_metadata_create_side_data(frame);
|
||||
printf("content side_data OOM: %s\n", clm ? "FAIL" : "OK");
|
||||
av_max_alloc(INT_MAX);
|
||||
av_frame_free(&frame);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -136,6 +136,10 @@ FATE_LIBAVUTIL += fate-lfg
|
||||
fate-lfg: libavutil/tests/lfg$(EXESUF)
|
||||
fate-lfg: CMD = run libavutil/tests/lfg$(EXESUF)
|
||||
|
||||
FATE_LIBAVUTIL += fate-mastering_display_metadata
|
||||
fate-mastering_display_metadata: libavutil/tests/mastering_display_metadata$(EXESUF)
|
||||
fate-mastering_display_metadata: CMD = run libavutil/tests/mastering_display_metadata$(EXESUF)
|
||||
|
||||
FATE_LIBAVUTIL += fate-mathematics
|
||||
fate-mathematics: libavutil/tests/mathematics$(EXESUF)
|
||||
fate-mathematics: CMD = run libavutil/tests/mathematics$(EXESUF)
|
||||
|
||||
31
tests/ref/fate/mastering_display_metadata
Normal file
31
tests/ref/fate/mastering_display_metadata
Normal file
@@ -0,0 +1,31 @@
|
||||
Testing av_mastering_display_metadata_alloc()
|
||||
alloc: OK
|
||||
defaults: primaries[0][0]=0/1, white_point[0]=0/1
|
||||
defaults: min_lum=0/1, max_lum=0/1
|
||||
defaults: has_primaries=0, has_luminance=0
|
||||
|
||||
Testing av_mastering_display_metadata_alloc_size()
|
||||
alloc_size: OK, size>0=yes
|
||||
defaults: primaries[0][0]=0/1
|
||||
|
||||
Testing write/read back
|
||||
primaries[0]=(34000/50000, 16000/50000)
|
||||
white_point=(15635/50000, 16450/50000)
|
||||
luminance: min=50/10000 max=10000000/10000
|
||||
|
||||
Testing av_mastering_display_metadata_create_side_data()
|
||||
side_data: OK, defaults: primaries[0][0]=0/1
|
||||
|
||||
Testing av_content_light_metadata_alloc()
|
||||
alloc: OK, size>0=yes, MaxCLL=0, MaxFALL=0
|
||||
write: MaxCLL=1000, MaxFALL=400
|
||||
|
||||
Testing av_content_light_metadata_create_side_data()
|
||||
side_data: OK, MaxCLL=0
|
||||
|
||||
Testing OOM paths
|
||||
mastering alloc OOM: OK
|
||||
mastering alloc_size OOM: OK
|
||||
content alloc OOM: OK
|
||||
mastering side_data OOM: OK
|
||||
content side_data OOM: OK
|
||||
Reference in New Issue
Block a user