forked from tinyzimmer/go-gst
/
c_util.go
42 lines (33 loc) · 1.21 KB
/
c_util.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
package audio
/*
#include "gst.go.h"
GstClockTime
framesToClockTime (gint frames, gint rate) { return GST_FRAMES_TO_CLOCK_TIME(frames, rate); }
gint
clockTimeToFrames(GstClockTime ct, gint rate) { return GST_CLOCK_TIME_TO_FRAMES(ct, rate); }
GValue * audioUtilToGValue (guintptr p) { return (GValue*)(p); }
*/
import "C"
import "time"
// FramesToDuration calculates the Clocktime (which is usually referred to as a time.Duration in the bindings)
// from the given frames and rate.
func FramesToDuration(frames, rate int) time.Duration {
ct := C.framesToClockTime(C.gint(frames), C.gint(rate))
return time.Duration(ct)
}
// DurationToFrames calculates the number of frames from the given duration and sample rate.
func DurationToFrames(dur time.Duration, rate int) int {
return int(C.clockTimeToFrames(C.GstClockTime(dur.Nanoseconds()), C.gint(rate)))
}
// gboolean converts a go bool to a C.gboolean.
func gboolean(b bool) C.gboolean {
if b {
return C.gboolean(1)
}
return C.gboolean(0)
}
// gobool provides an easy type conversion between C.gboolean and a go bool.
func gobool(b C.gboolean) bool {
return int(b) > 0
}
func uintptrToGVal(p uintptr) *C.GValue { return (*C.GValue)(C.audioUtilToGValue(C.guintptr(p))) }