mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-11 10:50:19 +08:00
examples compiling again
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type workflow struct {
|
||||
*gst.Pipeline
|
||||
gst.Pipeline
|
||||
}
|
||||
|
||||
func (w *workflow) newSrc() {
|
||||
@@ -27,26 +28,26 @@ func (w *workflow) newSrc() {
|
||||
src.Link(caps)
|
||||
|
||||
// Get a sink pad on compositor
|
||||
mixer := w.ByName("mixer")
|
||||
mixer := w.GetByName("mixer")
|
||||
|
||||
pad := mixer.GetRequestPad("sink_%u")
|
||||
pad.SetObjectProperty("xpos", 640)
|
||||
pad.SetObjectProperty("ypos", 0)
|
||||
|
||||
caps.StaticPad("src").Link(pad)
|
||||
caps.GetStaticPad("src").Link(pad)
|
||||
caps.SyncStateWithParent()
|
||||
src.SyncStateWithParent()
|
||||
|
||||
}
|
||||
func (w *workflow) delSrc() {
|
||||
|
||||
mixer := w.ByName("mixer")
|
||||
mixer := w.GetByName("mixer")
|
||||
|
||||
src := w.ByName("src2")
|
||||
src := w.GetByName("src2")
|
||||
|
||||
caps := w.ByName("caps2")
|
||||
caps := w.GetByName("caps2")
|
||||
|
||||
pad := mixer.StaticPad("sink_1")
|
||||
pad := mixer.GetStaticPad("sink_1")
|
||||
if pad == nil {
|
||||
fmt.Printf("pad is null\n")
|
||||
return
|
||||
@@ -60,7 +61,7 @@ func (w *workflow) delSrc() {
|
||||
mixer.ReleaseRequestPad(pad)
|
||||
}
|
||||
|
||||
func createPipeline() (*gst.Pipeline, error) {
|
||||
func createPipeline() (gst.Pipeline, error) {
|
||||
gst.Init()
|
||||
ret, err := gst.ParseLaunch("videotestsrc ! video/x-raw , capsfilter caps=width=640,height=360 name=caps1 ! compositor name=mixer ! autovideosink")
|
||||
|
||||
@@ -70,7 +71,7 @@ func createPipeline() (*gst.Pipeline, error) {
|
||||
|
||||
var w workflow
|
||||
|
||||
w.Pipeline = ret.(*gst.Pipeline)
|
||||
w.Pipeline = ret.(gst.Pipeline)
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
@@ -83,12 +84,12 @@ func createPipeline() (*gst.Pipeline, error) {
|
||||
return w.Pipeline, nil
|
||||
}
|
||||
|
||||
func runPipeline(loop *glib.MainLoop, pipeline *gst.Pipeline) error {
|
||||
func runPipeline(pipeline gst.Pipeline) error {
|
||||
// Start the pipeline
|
||||
pipeline.SetState(gst.StatePlaying)
|
||||
|
||||
// Add a message watch to the bus to quit on any error
|
||||
pipeline.Bus().AddWatch(0, func(bus *gst.Bus, msg *gst.Message) bool {
|
||||
for msg := range pipeline.GetBus().Messages(context.Background()) {
|
||||
var err error
|
||||
|
||||
// If the stream has ended or any element posts an error to the
|
||||
@@ -99,7 +100,7 @@ func runPipeline(loop *glib.MainLoop, pipeline *gst.Pipeline) error {
|
||||
case gst.MessageError:
|
||||
// The parsed error implements the error interface, but also
|
||||
// contains additional debug information.
|
||||
gerr, debug := msg.ParseError()
|
||||
debug, gerr := msg.ParseError()
|
||||
fmt.Println("go-gst-debug:", debug)
|
||||
err = gerr
|
||||
}
|
||||
@@ -107,24 +108,18 @@ func runPipeline(loop *glib.MainLoop, pipeline *gst.Pipeline) error {
|
||||
// If either condition triggered an error, log and quit
|
||||
if err != nil {
|
||||
fmt.Println("ERROR:", err.Error())
|
||||
loop.Quit()
|
||||
return false
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
// Block on the main loop
|
||||
return loop.RunError()
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func main() {
|
||||
loop := glib.NewMainLoop(glib.MainContextDefault(), false)
|
||||
|
||||
pipeline, err := createPipeline()
|
||||
if err != nil {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
runPipeline(loop, pipeline)
|
||||
runPipeline(pipeline)
|
||||
}
|
||||
|
Reference in New Issue
Block a user