CMTime.h
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* akvirtualcamera, virtual camera for Mac and Windows.
* Copyright (C) 2024 Gonzalo Exequiel Pedone
*
* akvirtualcamera is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* akvirtualcamera 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with akvirtualcamera. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
#ifndef COREMEDIA_CMTIME_H
#define COREMEDIA_CMTIME_H
#include "../CoreFoundation/CFType.h"
#include "VCamUtils/src/utils.h"
using CMTimeValue = int64_t;
using CMTimeScale = int32_t;
enum CMTimeFlags
{
kCMTimeFlags_Valid = 0x1,
kCMTimeFlags_HasBeenRounded = 0x2,
kCMTimeFlags_PositiveInfinity = 0x4,
kCMTimeFlags_NegativeInfinity = 0x8,
kCMTimeFlags_Indefinite = 0x10,
kCMTimeFlags_ImpliedValueFlagsMask = kCMTimeFlags_PositiveInfinity
| kCMTimeFlags_NegativeInfinity
| kCMTimeFlags_Indefinite
};
using CMTimeEpoch = int64_t;
struct CMTime
{
CMTimeValue value = 0;
CMTimeScale timescale = 0;
CMTimeFlags flags = CMTimeFlags(0);
CMTimeEpoch epoch = 0;
CMTime(CMTimeValue value=0,
CMTimeScale timescale=0,
CMTimeFlags flags=CMTimeFlags(0),
CMTimeEpoch epoch=0):
value(value),
timescale(timescale),
flags(flags),
epoch(flags)
{
}
};
#define CMTIME_IS_VALID(time) ((time.flags & kCMTimeFlags_Valid) != 0)
#define CMTIME_IS_INVALID(time) ((time.flags & kCMTimeFlags_Valid) == 0)
inline CMTime CMTimeMake(int64_t value, int32_t timescale)
{
return {value, timescale, kCMTimeFlags_Valid, 0};
}
inline Float64 CMTimeGetSeconds(CMTime time)
{
return Float64(time.value) / time.timescale;
}
inline int32_t CMTimeCompare(CMTime time1, CMTime time2)
{
return int32_t(AkVCam::bound<CMTimeValue>(-1, time1.value * time2.timescale - time2.value * time1.timescale, 1));
}
inline CMTime CMTimeAdd(CMTime time1, CMTime time2)
{
return {(time1.value * time2.timescale + time2.value * time1.timescale)
/ AkVCam::gcd(time1.timescale, time2.timescale),
AkVCam::lcm(time1.timescale, time2.timescale),
kCMTimeFlags_Valid,
0};
}
inline CMTime CMTimeSubtract(CMTime time1, CMTime time2)
{
return {(time1.value * time2.timescale - time2.value * time1.timescale)
/ AkVCam::gcd(time1.timescale, time2.timescale),
AkVCam::lcm(time1.timescale, time2.timescale),
kCMTimeFlags_Valid,
0};
}
#endif // COREMEDIA_CMTIME_H