FreeRDP
Loading...
Searching...
No Matches
TestCameraAVFoundationFrameRate.c
1
18#include <stdio.h>
19#include "../frame_rate.h"
20
21WINPR_ATTR_NODISCARD
22int TestCameraAVFoundationFrameRate(int argc, char* argv[])
23{
24 WINPR_UNUSED(argc);
25 WINPR_UNUSED(argv);
26 const CMTime faceTime30 = CMTimeMake(1000000, 30000030);
27 const CMTime faceTime15 = CMTimeMake(1000000, 15000015);
28 const CMTime ntsc = CMTimeMake(1001, 30000);
29 const struct
30 {
31 const char* name;
32 UINT32 numerator;
33 UINT32 denominator;
34 CMTime minimum;
35 CMTime maximum;
36 BOOL accepted;
37 CMTime expected;
38 } tests[] = {
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,
46 CMTimeMake(1, 30) },
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 },
57 };
58 for (size_t i = 0; i < ARRAYSIZE(tests); i++)
59 {
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)))
65 {
66 fprintf(stderr, "Frame duration case failed: %s\n", tests[i].name);
67 return -1;
68 }
69 if (!accepted)
70 continue;
71
72 /* Advertised fractional rates must describe the same supported native duration. */
73 UINT32 numerator = 0;
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))
80 {
81 fprintf(stderr, "Frame rate round trip failed: %s\n", tests[i].name);
82 return -1;
83 }
84 }
85
86 UINT32 numerator = 0;
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))
92 {
93 fprintf(stderr, "Native frame rate serialization failed\n");
94 return -1;
95 }
96 return 0;
97}