mirror of
https://github.com/go-gst/go-gst.git
synced 2025-09-26 20:11:18 +08:00
Merge pull request #152 from go-gst/custom_elements_mem_leak
add example which registers and uses go custom elements
This commit is contained in:
2
examples/plugins/registered_elements/.gitignore
vendored
Normal file
2
examples/plugins/registered_elements/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.dot
|
||||
__debug*
|
8
examples/plugins/registered_elements/README.md
Normal file
8
examples/plugins/registered_elements/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Registered Elements example
|
||||
|
||||
This example shows how you can define custom gstreamer elements in go, register them in the element factory and use them in the same application in a pipeline.
|
||||
|
||||
We define two elements:
|
||||
|
||||
* `gocustombin` a custom GstBin that uses an audiomixer to aggregate the input of two `gocustomsrc`
|
||||
* `gocustomsrc` a custom GstBin that uses an audiotestsrc and a volume element.
|
@@ -0,0 +1,11 @@
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
|
||||
var FinalizersCalled int = 0
|
||||
|
||||
func AssertFinalizersCalled(x int) {
|
||||
if FinalizersCalled != x {
|
||||
panic(fmt.Sprintf("finalizers did not run correctly, memory leak, wanted: %d, got: %d", x, FinalizersCalled))
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package common
|
||||
|
||||
func Must[T any](v T, err error) T {
|
||||
if err != nil {
|
||||
panic("got error:" + err.Error())
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
package custombin
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gst/go-glib/glib"
|
||||
"github.com/go-gst/go-gst/examples/plugins/registered_elements/internal/common"
|
||||
"github.com/go-gst/go-gst/gst"
|
||||
)
|
||||
|
||||
type customBin struct {
|
||||
// self *gst.Bin
|
||||
source1 *gst.Element
|
||||
source2 *gst.Element
|
||||
mixer *gst.Element
|
||||
}
|
||||
|
||||
// ClassInit is the place where you define pads and properties
|
||||
func (*customBin) ClassInit(klass *glib.ObjectClass) {
|
||||
class := gst.ToElementClass(klass)
|
||||
class.SetMetadata(
|
||||
"custom test source",
|
||||
"Src/Test",
|
||||
"Demo source bin with volume",
|
||||
"Wilhelm Bartel <bartel.wilhelm@gmail.com>",
|
||||
)
|
||||
class.AddPadTemplate(gst.NewPadTemplate(
|
||||
"src",
|
||||
gst.PadDirectionSource,
|
||||
gst.PadPresenceAlways,
|
||||
gst.NewCapsFromString("audio/x-raw,channels=2,rate=48000"),
|
||||
))
|
||||
}
|
||||
|
||||
// SetProperty gets called for every property. The id is the index in the slice defined above.
|
||||
func (s *customBin) SetProperty(self *glib.Object, id uint, value *glib.Value) {}
|
||||
|
||||
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
||||
// slice provided at ClassInit.
|
||||
func (o *customBin) GetProperty(self *glib.Object, id uint) *glib.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// New is called by the bindings to create a new instance of your go element. Use this to initialize channels, maps, etc.
|
||||
//
|
||||
// Think of New like the constructor of your struct
|
||||
func (*customBin) New() glib.GoObjectSubclass {
|
||||
return &customBin{}
|
||||
}
|
||||
|
||||
// InstanceInit should initialize the element. Keep in mind that the properties are not yet present. When this is called.
|
||||
func (s *customBin) InstanceInit(instance *glib.Object) {
|
||||
self := gst.ToGstBin(instance)
|
||||
|
||||
s.source1 = common.Must(gst.NewElementWithProperties("gocustomsrc", map[string]interface{}{
|
||||
"duration": int64(5 * time.Second),
|
||||
}))
|
||||
s.source2 = common.Must(gst.NewElementWithProperties("gocustomsrc", map[string]interface{}{
|
||||
"duration": int64(10 * time.Second),
|
||||
}))
|
||||
|
||||
s.mixer = common.Must(gst.NewElement("audiomixer"))
|
||||
|
||||
klass := instance.Class()
|
||||
class := gst.ToElementClass(klass)
|
||||
|
||||
self.AddMany(
|
||||
s.source1,
|
||||
s.source2,
|
||||
s.mixer,
|
||||
)
|
||||
|
||||
srcpad := s.mixer.GetStaticPad("src")
|
||||
|
||||
ghostpad := gst.NewGhostPadFromTemplate("src", srcpad, class.GetPadTemplate("src"))
|
||||
|
||||
s.source1.Link(s.mixer)
|
||||
s.source2.Link(s.mixer)
|
||||
|
||||
self.AddPad(ghostpad.Pad)
|
||||
}
|
||||
|
||||
func (s *customBin) Constructed(o *glib.Object) {}
|
||||
|
||||
func (s *customBin) Finalize(o *glib.Object) {
|
||||
common.FinalizersCalled++
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package custombin
|
||||
|
||||
import (
|
||||
"github.com/go-gst/go-gst/gst"
|
||||
)
|
||||
|
||||
// Register needs to be called after gst.Init() to make the gocustombin available in the standard
|
||||
// gst element registry. After this call the element can be used like any other gstreamer element
|
||||
func Register() bool {
|
||||
return gst.RegisterElement(
|
||||
// no plugin:
|
||||
nil,
|
||||
// The name of the element
|
||||
"gocustombin",
|
||||
// The rank of the element
|
||||
gst.RankNone,
|
||||
// The GoElement implementation for the element
|
||||
&customBin{},
|
||||
// The base subclass this element extends
|
||||
gst.ExtendsBin,
|
||||
)
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
package customsrc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/go-gst/go-glib/glib"
|
||||
"github.com/go-gst/go-gst/examples/plugins/registered_elements/internal/common"
|
||||
"github.com/go-gst/go-gst/gst"
|
||||
)
|
||||
|
||||
// default: 1024, this value makes it easier to calculate num buffers with the sample rate
|
||||
const samplesperbuffer = 4800
|
||||
|
||||
const samplerate = 48000
|
||||
|
||||
var properties = []*glib.ParamSpec{
|
||||
glib.NewInt64Param(
|
||||
"duration",
|
||||
"duration",
|
||||
"duration the source",
|
||||
0,
|
||||
math.MaxInt64,
|
||||
0,
|
||||
glib.ParameterReadWrite,
|
||||
),
|
||||
}
|
||||
|
||||
type customSrc struct {
|
||||
// self *gst.Bin
|
||||
source *gst.Element
|
||||
volume *gst.Element
|
||||
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
// ClassInit is the place where you define pads and properties
|
||||
func (*customSrc) ClassInit(klass *glib.ObjectClass) {
|
||||
class := gst.ToElementClass(klass)
|
||||
class.SetMetadata(
|
||||
"custom test source",
|
||||
"Src/Test",
|
||||
"Demo source bin with volume",
|
||||
"Wilhelm Bartel <bartel.wilhelm@gmail.com>",
|
||||
)
|
||||
class.AddPadTemplate(gst.NewPadTemplate(
|
||||
"src",
|
||||
gst.PadDirectionSource,
|
||||
gst.PadPresenceAlways,
|
||||
gst.NewCapsFromString(fmt.Sprintf("audio/x-raw,channels=2,rate=%d", samplerate)),
|
||||
))
|
||||
class.InstallProperties(properties)
|
||||
}
|
||||
|
||||
// SetProperty gets called for every property. The id is the index in the slice defined above.
|
||||
func (s *customSrc) SetProperty(self *glib.Object, id uint, value *glib.Value) {
|
||||
param := properties[id]
|
||||
|
||||
bin := gst.ToGstBin(self)
|
||||
|
||||
switch param.Name() {
|
||||
case "duration":
|
||||
state := bin.GetCurrentState()
|
||||
if !(state == gst.StateNull || state != gst.StateReady) {
|
||||
return
|
||||
}
|
||||
|
||||
gv, _ := value.GoValue()
|
||||
|
||||
durI, _ := gv.(int64)
|
||||
|
||||
s.duration = time.Duration(durI)
|
||||
|
||||
s.updateSource()
|
||||
}
|
||||
}
|
||||
|
||||
// GetProperty is called to retrieve the value of the property at index `id` in the properties
|
||||
// slice provided at ClassInit.
|
||||
func (o *customSrc) GetProperty(self *glib.Object, id uint) *glib.Value {
|
||||
param := properties[id]
|
||||
|
||||
switch param.Name() {
|
||||
case "duration":
|
||||
v, _ := glib.GValue(int64(o.duration))
|
||||
return v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*customSrc) New() glib.GoObjectSubclass {
|
||||
return &customSrc{}
|
||||
}
|
||||
|
||||
// InstanceInit should initialize the element. Keep in mind that the properties are not yet present. When this is called.
|
||||
func (s *customSrc) InstanceInit(instance *glib.Object) {
|
||||
self := gst.ToGstBin(instance)
|
||||
|
||||
s.source = common.Must(gst.NewElement("audiotestsrc"))
|
||||
s.volume = common.Must(gst.NewElement("volume"))
|
||||
|
||||
klass := instance.Class()
|
||||
class := gst.ToElementClass(klass)
|
||||
|
||||
self.AddMany(
|
||||
s.source,
|
||||
s.volume,
|
||||
)
|
||||
|
||||
srcpad := s.volume.GetStaticPad("src")
|
||||
|
||||
ghostpad := gst.NewGhostPadFromTemplate("src", srcpad, class.GetPadTemplate("src"))
|
||||
|
||||
gst.ElementLinkMany(
|
||||
s.source,
|
||||
s.volume,
|
||||
)
|
||||
|
||||
self.AddPad(ghostpad.Pad)
|
||||
|
||||
s.updateSource()
|
||||
}
|
||||
|
||||
func (s *customSrc) Constructed(o *glib.Object) {}
|
||||
|
||||
func (s *customSrc) Finalize(o *glib.Object) {
|
||||
common.FinalizersCalled++
|
||||
}
|
||||
|
||||
// updateSource will get called to update the audiotestsrc when a property changes
|
||||
func (s *customSrc) updateSource() {
|
||||
if s.source != nil {
|
||||
numBuffers := (float64(s.duration / time.Second)) / (float64(samplesperbuffer) / float64(samplerate))
|
||||
|
||||
s.source.SetProperty("num-buffers", int(math.Ceil(numBuffers)))
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package customsrc
|
||||
|
||||
import (
|
||||
"github.com/go-gst/go-gst/gst"
|
||||
)
|
||||
|
||||
// Register needs to be called after gst.Init() to make the gocustomsrc available in the standard
|
||||
// gst element registry. After this call the element can be used like any other gstreamer element
|
||||
func Register() bool {
|
||||
return gst.RegisterElement(
|
||||
// no plugin:
|
||||
nil,
|
||||
// The name of the element
|
||||
"gocustomsrc",
|
||||
// The rank of the element
|
||||
gst.RankNone,
|
||||
// The GoElement implementation for the element
|
||||
&customSrc{},
|
||||
// The base subclass this element extends
|
||||
gst.ExtendsBin,
|
||||
)
|
||||
}
|
120
examples/plugins/registered_elements/main.go
Normal file
120
examples/plugins/registered_elements/main.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/go-gst/go-glib/glib"
|
||||
"github.com/go-gst/go-gst/examples/plugins/registered_elements/internal/common"
|
||||
"github.com/go-gst/go-gst/examples/plugins/registered_elements/internal/custombin"
|
||||
"github.com/go-gst/go-gst/examples/plugins/registered_elements/internal/customsrc"
|
||||
"github.com/go-gst/go-gst/gst"
|
||||
)
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gst.Init(nil)
|
||||
|
||||
customsrc.Register()
|
||||
custombin.Register()
|
||||
|
||||
systemclock := gst.ObtainSystemClock()
|
||||
|
||||
pipeline, err := gst.NewPipelineFromString("gocustombin ! fakesink sync=true")
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipeline.ForceClock(systemclock.Clock)
|
||||
|
||||
bus := pipeline.GetBus()
|
||||
|
||||
mainloop := glib.NewMainLoop(glib.MainContextDefault(), false)
|
||||
|
||||
pipeline.SetState(gst.StatePlaying)
|
||||
|
||||
bus.AddWatch(func(msg *gst.Message) bool {
|
||||
switch msg.Type() {
|
||||
case gst.MessageStateChanged:
|
||||
old, new := msg.ParseStateChanged()
|
||||
dot := pipeline.DebugBinToDotData(gst.DebugGraphShowVerbose)
|
||||
|
||||
f, err := os.OpenFile(filepath.Join(wd, fmt.Sprintf("pipeline-%s-to-%s.dot", old, new)), os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0600)
|
||||
|
||||
if err != nil {
|
||||
cancel()
|
||||
return false
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.Write([]byte(dot))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
cancel()
|
||||
return false
|
||||
}
|
||||
|
||||
case gst.MessageEOS:
|
||||
fmt.Println(msg.String())
|
||||
cancel()
|
||||
return false
|
||||
}
|
||||
|
||||
// the String method is expensive and should not be used in prodution:
|
||||
fmt.Println(msg.String())
|
||||
return true
|
||||
})
|
||||
|
||||
go mainloop.Run()
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
|
||||
mainloop.Quit()
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
pipeline.BlockSetState(gst.StateNull)
|
||||
|
||||
gst.Deinit()
|
||||
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
err := run(ctx)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
||||
runtime.GC()
|
||||
runtime.GC()
|
||||
runtime.GC()
|
||||
|
||||
prof := pprof.Lookup("go-glib-reffed-objects")
|
||||
|
||||
prof.WriteTo(os.Stdout, 1)
|
||||
|
||||
// we are creating 3 custom elements in total. If this panics, then the go struct will memory leak
|
||||
common.AssertFinalizersCalled(3)
|
||||
}
|
6
go.mod
6
go.mod
@@ -1,9 +1,11 @@
|
||||
module github.com/go-gst/go-gst
|
||||
|
||||
go 1.23
|
||||
go 1.23.1
|
||||
|
||||
toolchain go1.23.2
|
||||
|
||||
require github.com/mattn/go-pointer v0.0.1
|
||||
|
||||
require github.com/go-gst/go-glib v1.4.0
|
||||
require github.com/go-gst/go-glib v1.4.1-0.20241115142200-3da60b6536bd
|
||||
|
||||
require golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
||||
github.com/go-gst/go-glib v1.4.0 h1:FB2uVfB0uqz7/M6EaDdWWlBZRQpvFAbWfL7drdw8lAE=
|
||||
github.com/go-gst/go-glib v1.4.0/go.mod h1:GUIpWmkxQ1/eL+FYSjKpLDyTZx6Vgd9nNXt8dA31d5M=
|
||||
github.com/go-gst/go-glib v1.4.1-0.20241115142200-3da60b6536bd h1:9iZxYxazkdrKSGmKpiV+eEoaFeNXLGW3PPHcDfHp1n8=
|
||||
github.com/go-gst/go-glib v1.4.1-0.20241115142200-3da60b6536bd/go.mod h1:GUIpWmkxQ1/eL+FYSjKpLDyTZx6Vgd9nNXt8dA31d5M=
|
||||
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
|
||||
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||
|
@@ -10,96 +10,119 @@ import (
|
||||
"github.com/go-gst/go-glib/glib"
|
||||
)
|
||||
|
||||
func cbWrapBin(bin *C.GstBin) *Bin {
|
||||
return wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
}
|
||||
|
||||
func cbWrapElement(elem *C.GstElement) *Element {
|
||||
return wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
}
|
||||
|
||||
//export goGstBinAddElement
|
||||
func goGstBinAddElement(bin *C.GstBin, element *C.GstElement) C.gboolean {
|
||||
func goGstBinAddElement(bin *C.GstBin, child *C.GstElement) C.gboolean {
|
||||
var ret bool
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
AddElement(self *Bin, element *Element) bool
|
||||
})
|
||||
ret = caller.AddElement(wrapBin(gobj), cbWrapElement(element))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
AddElement(self *Bin, element *Element) bool
|
||||
})
|
||||
ret = caller.AddElement(goBin, gochild)
|
||||
|
||||
return gboolean(ret)
|
||||
}
|
||||
|
||||
//export goGstBinDeepElementAdded
|
||||
func goGstBinDeepElementAdded(bin *C.GstBin, subbin *C.GstBin, child *C.GstElement) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
DeepElementAdded(self *Bin, subbin *Bin, child *Element)
|
||||
})
|
||||
caller.DeepElementAdded(wrapBin(gobj), cbWrapBin(subbin), cbWrapElement(child))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gosubbin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(subbin))})
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
DeepElementAdded(self *Bin, subbin *Bin, child *Element)
|
||||
})
|
||||
caller.DeepElementAdded(goBin, gosubbin, gochild)
|
||||
}
|
||||
|
||||
//export goGstBinDeepElementRemoved
|
||||
func goGstBinDeepElementRemoved(bin *C.GstBin, subbin *C.GstBin, child *C.GstElement) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
DeepElementRemoved(self *Bin, subbin *Bin, child *Element)
|
||||
})
|
||||
caller.DeepElementRemoved(wrapBin(gobj), cbWrapBin(subbin), cbWrapElement(child))
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gosubbin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(subbin))})
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
DeepElementRemoved(self *Bin, subbin *Bin, child *Element)
|
||||
})
|
||||
caller.DeepElementRemoved(goBin, gosubbin, gochild)
|
||||
}
|
||||
|
||||
//export goGstBinDoLatency
|
||||
func goGstBinDoLatency(bin *C.GstBin) C.gboolean {
|
||||
var ret bool
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
DoLatency(self *Bin) bool
|
||||
})
|
||||
ret = caller.DoLatency(wrapBin(gobj))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
caller := subclass.(interface {
|
||||
DoLatency(self *Bin) bool
|
||||
})
|
||||
ret = caller.DoLatency(goBin)
|
||||
|
||||
return gboolean(ret)
|
||||
}
|
||||
|
||||
//export goGstBinElementAdded
|
||||
func goGstBinElementAdded(bin *C.GstBin, child *C.GstElement) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
ElementAdded(self *Bin, child *Element)
|
||||
})
|
||||
caller.ElementAdded(wrapBin(gobj), cbWrapElement(child))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
ElementAdded(self *Bin, child *Element)
|
||||
})
|
||||
caller.ElementAdded(goBin, gochild)
|
||||
}
|
||||
|
||||
//export goGstBinElementRemoved
|
||||
func goGstBinElementRemoved(bin *C.GstBin, child *C.GstElement) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
ElementRemoved(self *Bin, child *Element)
|
||||
})
|
||||
caller.ElementRemoved(wrapBin(gobj), cbWrapElement(child))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
ElementRemoved(self *Bin, child *Element)
|
||||
})
|
||||
caller.ElementRemoved(goBin, gochild)
|
||||
}
|
||||
|
||||
//export goGstBinHandleMessage
|
||||
func goGstBinHandleMessage(bin *C.GstBin, message *C.GstMessage) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
HandleMessage(self *Bin, msg *Message)
|
||||
})
|
||||
caller.HandleMessage(wrapBin(gobj), wrapMessage(message))
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
caller := subclass.(interface {
|
||||
HandleMessage(self *Bin, msg *Message)
|
||||
})
|
||||
caller.HandleMessage(goBin, wrapMessage(message))
|
||||
}
|
||||
|
||||
//export goGstBinRemoveElement
|
||||
func goGstBinRemoveElement(bin *C.GstBin, element *C.GstElement) C.gboolean {
|
||||
func goGstBinRemoveElement(bin *C.GstBin, child *C.GstElement) C.gboolean {
|
||||
var ret bool
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(bin), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
caller := obj.(interface {
|
||||
RemoveElement(self *Bin, child *Element) bool
|
||||
})
|
||||
ret = caller.RemoveElement(wrapBin(gobj), cbWrapElement(element))
|
||||
|
||||
goBin := wrapBin(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(bin))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(bin))
|
||||
|
||||
gochild := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(child))})
|
||||
|
||||
caller := subclass.(interface {
|
||||
RemoveElement(self *Bin, child *Element) bool
|
||||
})
|
||||
ret = caller.RemoveElement(goBin, gochild)
|
||||
|
||||
return gboolean(ret)
|
||||
}
|
||||
|
@@ -15,73 +15,85 @@ import (
|
||||
//export goGstElementClassChangeState
|
||||
func goGstElementClassChangeState(elem *C.GstElement, change C.GstStateChange) C.GstStateChangeReturn {
|
||||
var ret StateChangeReturn
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface {
|
||||
ChangeState(*Element, StateChange) StateChangeReturn
|
||||
})
|
||||
ret = iface.ChangeState(wrapElement(gobj), StateChange(change))
|
||||
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface {
|
||||
ChangeState(*Element, StateChange) StateChangeReturn
|
||||
})
|
||||
ret = iface.ChangeState(goElem, StateChange(change))
|
||||
|
||||
return C.GstStateChangeReturn(ret)
|
||||
}
|
||||
|
||||
//export goGstElementClassGetState
|
||||
func goGstElementClassGetState(elem *C.GstElement, state, pending *C.GstState, timeout C.GstClockTime) C.GstStateChangeReturn {
|
||||
var ret StateChangeReturn
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface {
|
||||
GetState(*Element, time.Duration) (ret StateChangeReturn, current, pending State) // should this be a ClockTime?
|
||||
})
|
||||
var cur, pend State
|
||||
ret, cur, pend = iface.GetState(wrapElement(gobj), time.Duration(timeout)*time.Nanosecond)
|
||||
if ret != StateChangeFailure {
|
||||
*state = C.GstState(cur)
|
||||
*pending = C.GstState(pend)
|
||||
}
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface {
|
||||
GetState(*Element, time.Duration) (ret StateChangeReturn, current, pending State) // should this be a ClockTime?
|
||||
})
|
||||
var cur, pend State
|
||||
ret, cur, pend = iface.GetState(goElem, time.Duration(timeout)*time.Nanosecond)
|
||||
if ret != StateChangeFailure {
|
||||
*state = C.GstState(cur)
|
||||
*pending = C.GstState(pend)
|
||||
}
|
||||
|
||||
return C.GstStateChangeReturn(ret)
|
||||
}
|
||||
|
||||
//export goGstElementClassNoMorePads
|
||||
func goGstElementClassNoMorePads(elem *C.GstElement) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ NoMorePads(*Element) })
|
||||
iface.NoMorePads(wrapElement(gobj))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ NoMorePads(*Element) })
|
||||
iface.NoMorePads(goElem)
|
||||
}
|
||||
|
||||
//export goGstElementClassPadAdded
|
||||
func goGstElementClassPadAdded(elem *C.GstElement, pad *C.GstPad) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ PadAdded(*Element, *Pad) })
|
||||
iface.PadAdded(wrapElement(gobj), wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ PadAdded(*Element, *Pad) })
|
||||
iface.PadAdded(goElem, wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
}
|
||||
|
||||
//export goGstElementClassPadRemoved
|
||||
func goGstElementClassPadRemoved(elem *C.GstElement, pad *C.GstPad) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ PadRemoved(*Element, *Pad) })
|
||||
iface.PadRemoved(wrapElement(gobj), wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ PadRemoved(*Element, *Pad) })
|
||||
iface.PadRemoved(goElem, wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
}
|
||||
|
||||
//export goGstElementClassPostMessage
|
||||
func goGstElementClassPostMessage(elem *C.GstElement, msg *C.GstMessage) C.gboolean {
|
||||
var ret C.gboolean
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ PostMessage(*Element, *Message) bool })
|
||||
ret = gboolean(iface.PostMessage(wrapElement(gobj), wrapMessage(msg)))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ PostMessage(*Element, *Message) bool })
|
||||
ret = gboolean(iface.PostMessage(goElem, wrapMessage(msg)))
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
//export goGstElementClassProvideClock
|
||||
func goGstElementClassProvideClock(elem *C.GstElement) *C.GstClock {
|
||||
var clock *Clock
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ ProvideClock(*Element) *Clock })
|
||||
clock = iface.ProvideClock(wrapElement(gobj))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ ProvideClock(*Element) *Clock })
|
||||
clock = iface.ProvideClock(goElem)
|
||||
|
||||
if clock == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -91,35 +103,41 @@ func goGstElementClassProvideClock(elem *C.GstElement) *C.GstClock {
|
||||
//export goGstElementClassQuery
|
||||
func goGstElementClassQuery(elem *C.GstElement, query *C.GstQuery) C.gboolean {
|
||||
var ret C.gboolean
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ Query(*Element, *Query) bool })
|
||||
ret = gboolean(iface.Query(wrapElement(gobj), wrapQuery(query)))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ Query(*Element, *Query) bool })
|
||||
ret = gboolean(iface.Query(goElem, wrapQuery(query)))
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
//export goGstElementClassReleasePad
|
||||
func goGstElementClassReleasePad(elem *C.GstElement, pad *C.GstPad) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ ReleasePad(*Element, *Pad) })
|
||||
iface.ReleasePad(wrapElement(gobj), wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ ReleasePad(*Element, *Pad) })
|
||||
iface.ReleasePad(goElem, wrapPad(toGObject(unsafe.Pointer(pad))))
|
||||
}
|
||||
|
||||
//export goGstElementClassRequestNewPad
|
||||
func goGstElementClassRequestNewPad(elem *C.GstElement, templ *C.GstPadTemplate, name *C.gchar, caps *C.GstCaps) *C.GstPad {
|
||||
var pad *Pad
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface {
|
||||
RequestNewPad(self *Element, templ *PadTemplate, name string, caps *Caps) *Pad
|
||||
})
|
||||
pad = iface.RequestNewPad(
|
||||
wrapElement(gobj),
|
||||
wrapPadTemplate(toGObject(unsafe.Pointer(templ))),
|
||||
C.GoString(name),
|
||||
wrapCaps(caps),
|
||||
)
|
||||
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface {
|
||||
RequestNewPad(self *Element, templ *PadTemplate, name string, caps *Caps) *Pad
|
||||
})
|
||||
pad = iface.RequestNewPad(
|
||||
goElem,
|
||||
wrapPadTemplate(toGObject(unsafe.Pointer(templ))),
|
||||
C.GoString(name),
|
||||
wrapCaps(caps),
|
||||
)
|
||||
|
||||
if pad == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -129,57 +147,70 @@ func goGstElementClassRequestNewPad(elem *C.GstElement, templ *C.GstPadTemplate,
|
||||
//export goGstElementClassSendEvent
|
||||
func goGstElementClassSendEvent(elem *C.GstElement, event *C.GstEvent) C.gboolean {
|
||||
var ret C.gboolean
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ SendEvent(*Element, *Event) bool })
|
||||
ret = gboolean(iface.SendEvent(wrapElement(gobj), wrapEvent(event)))
|
||||
})
|
||||
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ SendEvent(*Element, *Event) bool })
|
||||
ret = gboolean(iface.SendEvent(goElem, wrapEvent(event)))
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
//export goGstElementClassSetBus
|
||||
func goGstElementClassSetBus(elem *C.GstElement, bus *C.GstBus) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ SetBus(*Element, *Bus) })
|
||||
iface.SetBus(wrapElement(gobj), wrapBus(toGObject(unsafe.Pointer(bus))))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ SetBus(*Element, *Bus) })
|
||||
iface.SetBus(goElem, wrapBus(toGObject(unsafe.Pointer(bus))))
|
||||
}
|
||||
|
||||
//export goGstElementClassSetClock
|
||||
func goGstElementClassSetClock(elem *C.GstElement, clock *C.GstClock) C.gboolean {
|
||||
var ret C.gboolean
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ SetClock(*Element, *Clock) bool })
|
||||
ret = gboolean(iface.SetClock(wrapElement(gobj), wrapClock(toGObject(unsafe.Pointer(clock)))))
|
||||
})
|
||||
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ SetClock(*Element, *Clock) bool })
|
||||
ret = gboolean(iface.SetClock(goElem, wrapClock(toGObject(unsafe.Pointer(clock)))))
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
//export goGstElementClassSetContext
|
||||
func goGstElementClassSetContext(elem *C.GstElement, ctx *C.GstContext) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface{ SetContext(*Element, *Context) })
|
||||
iface.SetContext(wrapElement(gobj), wrapContext(ctx))
|
||||
})
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface{ SetContext(*Element, *Context) })
|
||||
iface.SetContext(goElem, wrapContext(ctx))
|
||||
}
|
||||
|
||||
//export goGstElementClassSetState
|
||||
func goGstElementClassSetState(elem *C.GstElement, state C.GstState) C.GstStateChangeReturn {
|
||||
var ret C.GstStateChangeReturn
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface {
|
||||
SetState(*Element, State) StateChangeReturn
|
||||
})
|
||||
ret = C.GstStateChangeReturn(iface.SetState(wrapElement(gobj), State(state)))
|
||||
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface {
|
||||
SetState(*Element, State) StateChangeReturn
|
||||
})
|
||||
ret = C.GstStateChangeReturn(iface.SetState(goElem, State(state)))
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
//export goGstElementClassStateChanged
|
||||
func goGstElementClassStateChanged(elem *C.GstElement, old, new, pending C.GstState) {
|
||||
glib.WithPointerTransferOriginal(unsafe.Pointer(elem), func(gobj *glib.Object, obj glib.GoObjectSubclass) {
|
||||
iface := obj.(interface {
|
||||
StateChanged(self *Element, old, new, pending State)
|
||||
})
|
||||
iface.StateChanged(wrapElement(gobj), State(old), State(new), State(pending))
|
||||
goElem := wrapElement(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(elem))})
|
||||
subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(elem))
|
||||
|
||||
iface := subclass.(interface {
|
||||
StateChanged(self *Element, old, new, pending State)
|
||||
})
|
||||
iface.StateChanged(goElem, State(old), State(new), State(pending))
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user