forked from lijo-jose/gst
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathappsrc.go
88 lines (73 loc) · 2.06 KB
/
appsrc.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
package gst
import (
"fmt"
"unsafe"
)
/*
#cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0
#cgo LDFLAGS: -lgstapp-1.0
#include <stdlib.h>
#include <string.h>
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
*/
import "C"
type FlowReturn C.GstFlowReturn
const (
GST_FLOW_OK = FlowReturn(C.GST_FLOW_OK)
GST_FLOW_FLUSHING = FlowReturn(C.GST_FLOW_FLUSHING)
GST_FLOW_NOT_LINKED = FlowReturn(C.GST_FLOW_NOT_LINKED)
GST_FLOW_NOT_NEGOTIATED = FlowReturn(C.GST_FLOW_NOT_NEGOTIATED)
GST_FLOW_ERROR = FlowReturn(C.GST_FLOW_ERROR)
GST_FLOW_NOT_SUPPORTED = FlowReturn(C.GST_FLOW_NOT_SUPPORTED)
)
func (f FlowReturn) String() string {
switch f {
case GST_FLOW_OK:
return "GST_FLOW_OK"
case GST_FLOW_FLUSHING:
return "GST_FLOW_FLUSHING"
case GST_FLOW_NOT_LINKED:
return "GST_FLOW_NOT_LINKED"
case GST_FLOW_NOT_NEGOTIATED:
return "GST_FLOW_NOT_NEGOTIATED"
case GST_FLOW_ERROR:
return "GST_FLOW_ERROR"
case GST_FLOW_NOT_SUPPORTED:
return "GST_FLOW_NOT_SUPPORTED"
default:
return fmt.Sprintf("flow error: %d", f)
}
}
type AppSrc struct {
*Element
}
func NewAppSrc(name string) *AppSrc {
return &AppSrc{ElementFactoryMake("appsrc", name)}
}
func (a *AppSrc) g() *C.GstAppSrc {
return (*C.GstAppSrc)(a.GetPtr())
}
func (a *AppSrc) SetCaps(caps *Caps) {
p := unsafe.Pointer(caps) // HACK
C.gst_app_src_set_caps(a.g(), (*C.GstCaps)(p))
}
func (a *AppSrc) EOS() error {
ret := FlowReturn(C.gst_app_src_end_of_stream(a.g()))
if ret != GST_FLOW_OK {
return fmt.Errorf("appsrc eos: %v", ret)
}
return nil
}
func (b *AppSrc) PushBuffer(buffer *Buffer) int {
return (int)(C.gst_app_src_push_buffer((*C.GstAppSrc)(b.g()), (*C.GstBuffer)(buffer.GstBuffer)))
}
func (a *AppSrc) Write(d []byte) (int, error) {
buf := C.gst_buffer_new_allocate(nil, C.gsize(len(d)), nil)
n := C.gst_buffer_fill(buf, C.gsize(0), (C.gconstpointer)(C.CBytes(d)), C.gsize(len(d)))
ret := FlowReturn(C.gst_app_src_push_buffer((*C.GstAppSrc)(a.GetPtr()), buf))
if ret != GST_FLOW_OK {
return 0, fmt.Errorf("appsrc push buffer failed: %v", ret)
}
return int(n), nil
}