-
Notifications
You must be signed in to change notification settings - Fork 48
/
element.go
165 lines (142 loc) · 3.81 KB
/
element.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package gst
/*
#include <stdlib.h>
#include <gst/gst.h>
*/
import "C"
import (
"github.com/ziutek/glib"
"unsafe"
)
type State C.GstState
const (
STATE_VOID_PENDING = State(C.GST_STATE_VOID_PENDING)
STATE_NULL = State(C.GST_STATE_NULL)
STATE_READY = State(C.GST_STATE_READY)
STATE_PAUSED = State(C.GST_STATE_PAUSED)
STATE_PLAYING = State(C.GST_STATE_PLAYING)
)
func (s *State) g() *C.GstState {
return (*C.GstState)(s)
}
func (s State) String() string {
switch s {
case STATE_VOID_PENDING:
return "STATE_VOID_PENDING"
case STATE_NULL:
return "STATE_NULL"
case STATE_READY:
return "STATE_READY"
case STATE_PAUSED:
return "STATE_PAUSED"
case STATE_PLAYING:
return "STATE_PLAYING"
}
panic("Unknown state")
}
type StateChangeReturn C.GstStateChangeReturn
const (
STATE_CHANGE_FAILURE = StateChangeReturn(C.GST_STATE_CHANGE_FAILURE)
STATE_CHANGE_SUCCESS = StateChangeReturn(C.GST_STATE_CHANGE_SUCCESS)
STATE_CHANGE_ASYNC = StateChangeReturn(C.GST_STATE_CHANGE_ASYNC)
STATE_CHANGE_NO_PREROLL = StateChangeReturn(C.GST_STATE_CHANGE_NO_PREROLL)
)
type Element struct {
GstObj
}
func (e *Element) g() *C.GstElement {
return (*C.GstElement)(e.GetPtr())
}
func (e *Element) AsElement() *Element {
return e
}
func (e *Element) Link(next ...*Element) bool {
for _, dst := range next {
if C.gst_element_link(e.g(), dst.g()) == 0 {
return false
}
e = dst
}
return true
}
func (e *Element) Unlink(next ...*Element) {
for _, dst := range next {
C.gst_element_unlink(e.g(), dst.g())
e = dst
}
}
func (e *Element) LinkFiltered(dst *Element, filter *Caps) bool {
return C.gst_element_link_filtered(e.g(), dst.g(), filter.g()) != 0
}
func (e *Element) LinkPads(pad_name string, dst *Element, dst_pad_name string) bool {
src_pname := (*C.gchar)(C.CString(pad_name))
defer C.free(unsafe.Pointer(src_pname))
dst_pname := (*C.gchar)(C.CString(dst_pad_name))
defer C.free(unsafe.Pointer(dst_pname))
return C.gst_element_link_pads(e.g(), src_pname, dst.g(), dst_pname) != 0
}
func (e *Element) UnlinkPads(pad_name string, dst *Element, dst_pad_name string) {
src_pname := (*C.gchar)(C.CString(pad_name))
defer C.free(unsafe.Pointer(src_pname))
dst_pname := (*C.gchar)(C.CString(dst_pad_name))
defer C.free(unsafe.Pointer(dst_pname))
C.gst_element_unlink_pads(e.g(), src_pname, dst.g(), dst_pname)
}
func (e *Element) SetState(state State) StateChangeReturn {
return StateChangeReturn(C.gst_element_set_state(e.g(), C.GstState(state)))
}
func (e *Element) GetState(timeout_ns int64) (state, pending State,
ret StateChangeReturn) {
ret = StateChangeReturn(C.gst_element_get_state(
e.g(), state.g(), pending.g(), C.GstClockTime(timeout_ns),
))
return
}
func (e *Element) AddPad(p *Pad) bool {
return C.gst_element_add_pad(e.g(), p.g()) != 0
}
func (e *Element) GetRequestPad(name string) *Pad {
s := (*C.gchar)(C.CString(name))
defer C.free(unsafe.Pointer(s))
cp := C.gst_element_get_request_pad(e.g(), s)
if cp == nil {
return nil
}
p := new(Pad)
p.SetPtr(glib.Pointer(cp))
return p
}
func (e *Element) GetStaticPad(name string) *Pad {
s := (*C.gchar)(C.CString(name))
defer C.free(unsafe.Pointer(s))
cp := C.gst_element_get_static_pad(e.g(), s)
if cp == nil {
return nil
}
p := new(Pad)
p.SetPtr(glib.Pointer(cp))
return p
}
func (e *Element) GetBus() *Bus {
bus := C.gst_element_get_bus(e.g())
if bus == nil {
return nil
}
b := new(Bus)
b.SetPtr(glib.Pointer(bus))
return b
}
// TODO: Move ElementFactoryMake to element_factory.go
func ElementFactoryMake(factory_name, name string) *Element {
fn := (*C.gchar)(C.CString(factory_name))
defer C.free(unsafe.Pointer(fn))
n := (*C.gchar)(C.CString(name))
defer C.free(unsafe.Pointer(n))
ge := C.gst_element_factory_make(fn, n)
if ge == nil {
return nil
}
e := new(Element)
e.SetPtr(glib.Pointer(ge))
return e
}