-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtime.go
45 lines (38 loc) · 1.33 KB
/
time.go
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
package astiav
//#include <libavutil/avutil.h>
//#include <libavutil/time.h>
import "C"
const (
// https://ffmpeg.org/doxygen/7.0/group__lavu__time.html#ga2eaefe702f95f619ea6f2d08afa01be1
NoPtsValue = int64(C.AV_NOPTS_VALUE)
// https://ffmpeg.org/doxygen/7.0/group__lavu__time.html#gaa11ed202b70e1f52bac809811a910e2a
TimeBase = int(C.AV_TIME_BASE)
)
var (
// https://ffmpeg.org/doxygen/7.0/group__lavu__time.html#gafd07a13a4ddaa6015275cad6022d9ee3
TimeBaseQ = newRationalFromC(C.AV_TIME_BASE_Q)
)
// https://ffmpeg.org/doxygen/7.0/time_8c.html#adf0e36df54426fa167e3cc5a3406f3b7
func RelativeTime() int64 {
return int64(C.av_gettime_relative())
}
type CompareTimestampsResult uint8
const (
CompareTimestampsResultUndefined CompareTimestampsResult = iota
CompareTimestampsResultAEqualB
CompareTimestampsResultABeforeB
CompareTimestampsResultAAfterB
)
// https://ffmpeg.org/doxygen/7.0/group__lavu__math.html#ga151744358fff630942b926e67e67c415
func CompareTimestamps(a, b int64, timeBaseA, timeBaseB Rational) CompareTimestampsResult {
switch C.av_compare_ts(C.int64_t(a), timeBaseA.c, C.int64_t(b), timeBaseB.c) {
case C.int(-1):
return CompareTimestampsResultABeforeB
case C.int(0):
return CompareTimestampsResultAEqualB
case C.int(1):
return CompareTimestampsResultAAfterB
default:
return CompareTimestampsResultUndefined
}
}