forked from notedit/gst
/
main.go
65 lines (59 loc) · 1.55 KB
/
main.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
/*
This example embeds a gstream pipeline output into an X11 window.
Left-clicking the mouse in the window will start/pause the output video.
*/
package main
import (
"fmt"
"log"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"github.com/notedit/gst"
)
func main() {
pipeline, err := gst.ParseLaunch("videotestsrc ! xvimagesink sync=false name=output")
if err != nil {
log.Fatalf("ParseLaunch: %s", err)
}
e := pipeline.GetByName("output")
if e == nil {
log.Fatal("Output element not found")
}
X, err := xgb.NewConn()
if err != nil {
log.Fatalf("NewConn: %s", err)
}
setup := xproto.Setup(X)
screen := setup.DefaultScreen(X)
wid, _ := xproto.NewWindowId(X)
xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root,
0, 0, 500, 500, 0,
xproto.WindowClassInputOutput, screen.RootVisual, 0, []uint32{})
xproto.ChangeWindowAttributes(X, wid,
xproto.CwBackPixel|xproto.CwEventMask,
[]uint32{
0xffffffff,
xproto.EventMaskStructureNotify | xproto.EventMaskButtonPress})
err = xproto.MapWindowChecked(X, wid).Check()
if err != nil {
log.Fatalf("Checked Error for mapping window %d: %s\n", wid, err)
}
isPlaying := false
for {
ev, xerr := X.WaitForEvent()
if ev == nil && xerr == nil {
fmt.Println("Both event and error are nil. Exiting...")
return
}
if _, ok := ev.(xproto.ButtonPressEvent); ok {
if isPlaying {
isPlaying = false
pipeline.SetState(gst.StatePaused)
} else {
isPlaying = true
e.VideoOverlaySetWindowHandle(uintptr(wid))
pipeline.SetState(gst.StatePlaying)
}
}
}
}