19#include "../frame_rate.h"
22int TestCameraAVFoundationFrameRate(
int argc,
char* argv[])
26 const CMTime faceTime30 = CMTimeMake(1000000, 30000030);
27 const CMTime faceTime15 = CMTimeMake(1000000, 15000015);
28 const CMTime ntsc = CMTimeMake(1001, 30000);
39 {
"FaceTime 30 fps", 30, 1, faceTime30, faceTime30, TRUE, faceTime30 },
40 {
"FaceTime 15 fps", 15, 1, faceTime15, faceTime15, TRUE, faceTime15 },
41 {
"nanosecond camera clock", 30, 1, CMTimeMake(33333333, 1000000000),
42 CMTimeMake(33333333, 1000000000), TRUE, CMTimeMake(33333333, 1000000000) },
43 {
"rounded lower rate", 30, 1, CMTimeMake(1000000, 29999970), CMTimeMake(1000000, 29999970),
44 TRUE, CMTimeMake(1000000, 29999970) },
45 {
"continuous range", 30, 1, CMTimeMake(1, 60), CMTimeMake(1, 15), TRUE,
47 {
"fractional rate", 30000, 1001, CMTimeMake(1, 60), CMTimeMake(1, 15), TRUE, ntsc },
48 {
"distinct NTSC rate", 30, 1, ntsc, ntsc, FALSE, kCMTimeInvalid },
49 {
"unsupported rate", 60, 1, faceTime30, faceTime30, FALSE, kCMTimeInvalid },
50 {
"zero numerator", 0, 1, faceTime30, faceTime30, FALSE, kCMTimeInvalid },
51 {
"zero denominator", 30, 0, faceTime30, faceTime30, FALSE, kCMTimeInvalid },
52 {
"overflowing timescale", UINT32_MAX, 1, faceTime30, faceTime30, FALSE, kCMTimeInvalid },
53 {
"invalid range", 30, 1, kCMTimeInvalid, faceTime30, FALSE, kCMTimeInvalid },
54 {
"infinite range", 30, 1, faceTime30, kCMTimePositiveInfinity, FALSE, kCMTimeInvalid },
55 {
"zero duration", 30, 1, kCMTimeZero, faceTime30, FALSE, kCMTimeInvalid },
56 {
"reversed range", 30, 1, CMTimeMake(1, 15), CMTimeMake(1, 60), FALSE, kCMTimeInvalid },
58 for (
size_t i = 0; i < ARRAYSIZE(tests); i++)
60 CMTime actual = kCMTimeInvalid;
61 const BOOL accepted = cam_avfoundation_frame_duration(
62 tests[i].numerator, tests[i].denominator, tests[i].minimum, tests[i].maximum, &actual);
63 if ((accepted != tests[i].accepted) ||
64 (accepted && (CMTimeCompare(actual, tests[i].expected) != 0)))
66 fprintf(stderr,
"Frame duration case failed: %s\n", tests[i].name);
74 UINT32 denominator = 0;
75 CMTime selected = kCMTimeInvalid;
76 if (!cam_avfoundation_frame_rate(actual, &numerator, &denominator) ||
77 !cam_avfoundation_frame_duration(numerator, denominator, tests[i].minimum,
78 tests[i].maximum, &selected) ||
79 (CMTimeCompare(selected, actual) != 0))
81 fprintf(stderr,
"Frame rate round trip failed: %s\n", tests[i].name);
87 UINT32 denominator = 0;
88 if (!cam_avfoundation_frame_rate(faceTime30, &numerator, &denominator) ||
89 (numerator != 3000003) || (denominator != 100000) ||
90 cam_avfoundation_frame_rate(kCMTimeInvalid, &numerator, &denominator) ||
91 cam_avfoundation_frame_rate(CMTimeMake(INT64_MAX, 1), &numerator, &denominator))
93 fprintf(stderr,
"Native frame rate serialization failed\n");