-
Notifications
You must be signed in to change notification settings - Fork 34
/
pipeline.go
129 lines (91 loc) · 2.37 KB
/
pipeline.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package gst
/*
#cgo pkg-config: gstreamer-1.0
#include "gst.h"
const char* ErrorMessage(GError *err) {
return err->message;
}
*/
import "C"
import (
"errors"
"fmt"
"runtime"
"unsafe"
)
type Pipeline struct {
Bin
}
func ParseLaunch(pipelineStr string) (p *Pipeline, err error) {
var gError *C.GError
pDesc := (*C.gchar)(unsafe.Pointer(C.CString(pipelineStr)))
defer C.g_free(C.gpointer(unsafe.Pointer(pDesc)))
gstElt := C.gst_parse_launch(pDesc, &gError)
if gError != nil {
err = errors.New(C.GoString(C.ErrorMessage(gError)))
return
}
p = &Pipeline{}
p.GstElement = gstElt
C.X_gst_pipeline_use_clock_real(p.GstElement)
runtime.SetFinalizer(p, func(p *Pipeline) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(p.GstElement)))
})
return
}
func PipelineNew(name string) (e *Pipeline, err error) {
var pName *C.gchar
if name == "" {
pName = nil
} else {
pName := (*C.gchar)(unsafe.Pointer(C.CString(name)))
defer C.g_free(C.gpointer(unsafe.Pointer(pName)))
}
gstElt := C.gst_pipeline_new(pName)
if gstElt == nil {
err = errors.New(fmt.Sprintf("could not create a Gstreamer pipeline name %s", name))
return
}
e = &Pipeline{}
e.GstElement = gstElt
C.X_gst_pipeline_use_clock_real(e.GstElement)
runtime.SetFinalizer(e, func(e *Pipeline) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(e.GstElement)))
})
return
}
func (p *Pipeline) SetState(state StateOptions) StateChangeReturn {
Cint := C.gst_element_set_state(p.GstElement, C.GstState(state))
return StateChangeReturn(Cint)
}
func (p *Pipeline) GetBus() (bus *Bus) {
CBus := C.X_gst_pipeline_get_bus(p.GstElement)
bus = &Bus{
C: CBus,
}
runtime.SetFinalizer(bus, func(bus *Bus) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(bus.C)))
})
return
}
func (p *Pipeline) GetClock() (clock *Clock) {
CElementClock := C.X_gst_pipeline_get_clock(p.GstElement)
clock = &Clock{
C: CElementClock,
}
runtime.SetFinalizer(clock, func(clock *Clock) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(clock.C)))
})
return
}
func (p *Pipeline) GetDelay() uint64 {
CClockTime := C.X_gst_pipeline_get_delay(p.GstElement)
return uint64(CClockTime)
}
func (p *Pipeline) GetLatency() uint64 {
CClockTime := C.X_gst_pipeline_get_latency(p.GstElement)
return uint64(CClockTime)
}
func (p *Pipeline) SetLatency(latency uint64) {
C.X_gst_pipeline_set_latency(p.GstElement, C.GstClockTime(latency))
}