-
Notifications
You must be signed in to change notification settings - Fork 14
/
gstreamer_test.go
103 lines (70 loc) · 1.87 KB
/
gstreamer_test.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 gstreamer
import (
"fmt"
"testing"
"time"
)
func TestPipeline(t *testing.T) {
pipeline, err := New("videotestsrc ! capsfilter name=filter ! autovideosink")
if err != nil {
t.Error("pipeline create error", err)
t.FailNow()
}
filter := pipeline.FindElement("filter")
if filter == nil {
t.Error("pipeline find element error ")
}
filter.SetCap("video/x-raw,width=1280,height=720")
pipeline.Start()
select {}
}
func TestAppsrc(t *testing.T) {
pipeline, err := New("appsrc name=mysource format=time is-live=true do-timestamp=true ! videoconvert ! autovideosink")
if err != nil {
t.Error("pipeline create error", err)
t.FailNow()
}
appsrc := pipeline.FindElement("mysource")
appsrc.SetCap("video/x-raw,format=RGB,width=320,height=240,bpp=24,depth=24")
pipeline.Start()
for {
time.Sleep(1 * time.Second)
appsrc.Push(make([]byte, 320*240*3))
}
}
func TestAppsink(t *testing.T) {
pipeline, err := New("videotestsrc num-buffers=15 ! appsink name=sink")
if err != nil {
t.Error("pipeline create error", err)
t.FailNow()
}
appsink := pipeline.FindElement("sink")
pipeline.Start()
out := appsink.Poll()
for {
buffer := <-out
fmt.Println(len(buffer))
}
}
func TestAppsink2(t *testing.T) {
pipeline, err := New("videotestsrc ! video/x-raw,format=I420,framerate=15/1 ! x264enc bframes=0 speed-preset=veryfast key-int-max=60 ! video/x-h264,stream-format=byte-stream ! appsink name=sink")
if err != nil {
t.Error("pipeline create error", err)
t.FailNow()
}
appsink := pipeline.FindElement("sink")
pipeline.Start()
out := appsink.Poll()
for {
buffer := <-out
fmt.Println("push ", len(buffer))
}
}
func TestCheckPlugins(t *testing.T) {
plugins := []string{"videotestsrc", "audiotestsrc", "rtp", "curl","x264", "rtmp"}
err := CheckPlugins(plugins)
if err != nil {
t.Error("pipeline create error", err)
t.FailNow()
}
}