This commit is contained in:
notedit
2020-08-30 13:16:17 +08:00
parent 72f1f3bbad
commit d7cba48f95
3 changed files with 0 additions and 69 deletions

View File

@@ -1,65 +0,0 @@
/*
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)
}
}
}
}

2
go.mod
View File

@@ -1,5 +1,3 @@
module github.com/notedit/gst
go 1.12
require github.com/BurntSushi/xgb v0.0.0-20200324125942-20f126ea2843 // indirect

2
go.sum
View File

@@ -1,2 +0,0 @@
github.com/BurntSushi/xgb v0.0.0-20200324125942-20f126ea2843 h1:3iF31c7rp7nGZVDv7YQ+VxOgpipVfPKotLXykjZmwM8=
github.com/BurntSushi/xgb v0.0.0-20200324125942-20f126ea2843/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=