-
Notifications
You must be signed in to change notification settings - Fork 34
/
bin.go
103 lines (75 loc) · 1.72 KB
/
bin.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
package gst
/*
#cgo pkg-config: gstreamer-1.0
#include "gst.h"
*/
import "C"
import (
"errors"
"runtime"
"unsafe"
)
type Bin struct {
Element
}
func ParseBinFromDescription(binStr string, ghostPads bool) (bin *Bin, err error) {
var gError *C.GError
pDesc := (*C.gchar)(unsafe.Pointer(C.CString(binStr)))
defer C.g_free(C.gpointer(unsafe.Pointer(pDesc)))
var ghost int
if ghostPads {
ghost = 1
} else {
ghost = 0
}
gstElt := C.gst_parse_bin_from_description(pDesc, C.int(ghost), &gError)
if gError != nil {
err = errors.New("create bin error")
return
}
bin = &Bin{}
bin.GstElement = gstElt
runtime.SetFinalizer(bin, func(bin *Bin) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(bin.GstElement)))
})
return
}
func BinNew(name string) (bin *Bin) {
pName := (*C.gchar)(unsafe.Pointer(C.CString(name)))
defer C.g_free(C.gpointer(unsafe.Pointer(pName)))
Celement := C.gst_bin_new(pName)
bin = &Bin{}
bin.GstElement = Celement
runtime.SetFinalizer(bin, func(bin *Bin) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(bin.GstElement)))
})
return
}
func (b *Bin) Add(child *Element) {
C.X_gst_bin_add(b.GstElement, child.GstElement)
return
}
func (b *Bin) Remove(child *Element) {
C.X_gst_bin_remove(b.GstElement, child.GstElement)
return
}
func (b *Bin) AddMany(elements ...*Element) {
for _, e := range elements {
if e != nil {
C.X_gst_bin_add(b.GstElement, e.GstElement)
}
}
return
}
func (b *Bin) GetByName(name string) (element *Element) {
n := (*C.gchar)(unsafe.Pointer(C.CString(name)))
defer C.g_free(C.gpointer(unsafe.Pointer(n)))
CElement := C.X_gst_bin_get_by_name(b.GstElement, n)
if CElement == nil {
return
}
element = &Element{
GstElement: CElement,
}
return
}