-
Notifications
You must be signed in to change notification settings - Fork 34
/
query.go
66 lines (50 loc) · 1.32 KB
/
query.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gst
/*
#cgo pkg-config: gstreamer-1.0
#include "gst.h"
*/
import "C"
import (
"errors"
"runtime"
"time"
"unsafe"
)
type FormatOptions int
const (
FormatUndefined FormatOptions = C.GST_FORMAT_UNDEFINED
FormatDefault FormatOptions = C.GST_FORMAT_DEFAULT
FormatBytes FormatOptions = C.GST_FORMAT_BYTES
FormatTime FormatOptions = C.GST_FORMAT_TIME
FormatBuffers FormatOptions = C.GST_FORMAT_BUFFERS
FormatPercent FormatOptions = C.GST_FORMAT_PERCENT
)
type Query struct {
C *C.GstQuery
}
func QueryNewSeeking(format FormatOptions) (q *Query, err error) {
gstQuery := C.gst_query_new_seeking(C.GstFormat(format))
if gstQuery == nil {
err = errors.New("could not create a Gstreamer query")
return
}
q = &Query{}
q.C = gstQuery
runtime.SetFinalizer(q, func(q *Query) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(q.C)))
})
return
}
func (q *Query) ParseSeeking(format *FormatOptions) (seekable bool, segmentStart, segmentEnd time.Duration) {
var Cformat C.GstFormat
var Cseekable C.gboolean
var CsegmentStart, CsegmentEnd C.gint64
if format != nil {
Cformat = C.GstFormat(*format)
}
C.gst_query_parse_seeking(q.C, &Cformat, &Cseekable, &CsegmentStart, &CsegmentEnd)
seekable = Cseekable == 1
segmentStart = time.Duration(CsegmentStart)
segmentEnd = time.Duration(CsegmentEnd)
return
}