mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-06 08:27:03 +08:00
port more examples over to new generated bindings
plugins not yet working, examples mostly untested
This commit is contained in:
@@ -3,85 +3,40 @@ 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"
|
||||
"github.com/go-gst/go-gst/pkg/gst"
|
||||
)
|
||||
|
||||
type customBin struct {
|
||||
// self *gst.Bin
|
||||
source1 *gst.Element
|
||||
source2 *gst.Element
|
||||
mixer *gst.Element
|
||||
gst.Bin // parent object must be first embedded field
|
||||
source1 gst.Elementer
|
||||
source2 gst.Elementer
|
||||
mixer gst.Elementer
|
||||
}
|
||||
|
||||
// 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{}{
|
||||
// init should initialize the element. Keep in mind that the properties are not yet present. When this is called.
|
||||
func (bin *customBin) init() {
|
||||
bin.source1 = gst.ElementFactoryMakeWithProperties("gocustomsrc", map[string]interface{}{
|
||||
"duration": int64(5 * time.Second),
|
||||
}))
|
||||
s.source2 = common.Must(gst.NewElementWithProperties("gocustomsrc", map[string]interface{}{
|
||||
})
|
||||
|
||||
bin.source2 = gst.ElementFactoryMakeWithProperties("gocustomsrc", map[string]interface{}{
|
||||
"duration": int64(10 * time.Second),
|
||||
}))
|
||||
})
|
||||
|
||||
s.mixer = common.Must(gst.NewElement("audiomixer"))
|
||||
bin.mixer = gst.ElementFactoryMake("audiomixer", "")
|
||||
|
||||
klass := instance.Class()
|
||||
class := gst.ToElementClass(klass)
|
||||
|
||||
self.AddMany(
|
||||
s.source1,
|
||||
s.source2,
|
||||
s.mixer,
|
||||
bin.AddMany(
|
||||
bin.source1,
|
||||
bin.source2,
|
||||
bin.mixer,
|
||||
)
|
||||
|
||||
srcpad := s.mixer.GetStaticPad("src")
|
||||
srcpad := bin.mixer.StaticPad("src")
|
||||
|
||||
ghostpad := gst.NewGhostPadFromTemplate("src", srcpad, class.GetPadTemplate("src"))
|
||||
ghostpad := gst.NewGhostPadFromTemplate("src", srcpad, bin.PadTemplate("src"))
|
||||
|
||||
s.source1.Link(s.mixer)
|
||||
s.source2.Link(s.mixer)
|
||||
bin.source1.Link(bin.mixer)
|
||||
bin.source2.Link(bin.mixer)
|
||||
|
||||
self.AddPad(ghostpad.Pad)
|
||||
}
|
||||
|
||||
func (s *customBin) Constructed(o *glib.Object) {}
|
||||
|
||||
func (s *customBin) Finalize(o *glib.Object) {
|
||||
common.FinalizersCalled++
|
||||
bin.AddPad(&ghostpad.Pad)
|
||||
}
|
||||
|
Reference in New Issue
Block a user