forked from notedit/gst
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.go
127 lines (90 loc) · 2.35 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
package gst
/*
#cgo pkg-config: gstreamer-1.0
#include "gst.h"
char* getErrorMsg(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)
defer C.g_clear_error(&gError)
if gError != nil {
err = errors.New("create pipeline error: " + C.GoString(C.getErrorMsg(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 {
return e, fmt.Errorf("could not create a Gstreamer pipeline name %s", name)
}
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 e, err
}
func (p *Pipeline) SetState(state StateOptions) {
C.gst_element_set_state(p.GstElement, C.GstState(state))
}
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))
}