forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gst.go
61 lines (50 loc) · 1.57 KB
/
gst.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
package gst
/*
#cgo pkg-config: gstreamer-1.0 gstreamer-app-1.0
#include "gst.h"
*/
import "C"
import (
"unsafe"
"github.com/pions/webrtc"
)
func init() {
go C.gstreamer_recieve_start_mainloop()
}
// Pipeline is a wrapper for a GStreamer Pipeline
type Pipeline struct {
Pipeline *C.GstElement
}
// CreatePipeline creates a GStreamer Pipeline
func CreatePipeline(codecName string) *Pipeline {
pipelineStr := "appsrc format=time is-live=true do-timestamp=true name=src ! application/x-rtp"
switch codecName {
case webrtc.VP8:
pipelineStr += ", encoding-name=VP8-DRAFT-IETF-01 ! rtpvp8depay ! decodebin ! autovideosink"
case webrtc.Opus:
pipelineStr += ", payload=96, encoding-name=OPUS ! rtpopusdepay ! decodebin ! autoaudiosink"
case webrtc.VP9:
pipelineStr += " ! rtpvp9depay ! decodebin ! autovideosink"
case webrtc.H264:
pipelineStr += " ! rtph264depay ! decodebin ! autovideosink"
default:
panic("Unhandled codec " + codecName)
}
pipelineStrUnsafe := C.CString(pipelineStr)
defer C.free(unsafe.Pointer(pipelineStrUnsafe))
return &Pipeline{Pipeline: C.gstreamer_recieve_create_pipeline(pipelineStrUnsafe)}
}
// Start starts the GStreamer Pipeline
func (p *Pipeline) Start() {
C.gstreamer_recieve_start_pipeline(p.Pipeline)
}
// Stop stops the GStreamer Pipeline
func (p *Pipeline) Stop() {
C.gstreamer_recieve_stop_pipeline(p.Pipeline)
}
// Push pushes a buffer on the appsrc of the GStreamer Pipeline
func (p *Pipeline) Push(buffer []byte) {
b := C.CBytes(buffer)
defer C.free(unsafe.Pointer(b))
C.gstreamer_recieve_push_buffer(p.Pipeline, b, C.int(len(buffer)))
}