add custom transform example and remove calls to deprecated methods

This commit is contained in:
RSWilli
2024-12-09 10:53:09 +01:00
parent b9dce0b926
commit 96b7315e7a
10 changed files with 690 additions and 319 deletions

View File

@@ -0,0 +1,68 @@
package customtransform
import (
"github.com/go-gst/go-glib/glib"
"github.com/go-gst/go-gst/gst"
"github.com/go-gst/go-gst/gst/base"
)
type customBaseTransform struct{}
// ClassInit is the place where you define pads and properties
func (*customBaseTransform) ClassInit(klass *glib.ObjectClass) {
class := gst.ToElementClass(klass)
class.SetMetadata(
"custom base transform",
"Transform/demo",
"custom base transform",
"Wilhelm Bartel <bartel.wilhelm@gmail.com>",
)
class.AddPadTemplate(gst.NewPadTemplate(
"src",
gst.PadDirectionSource,
gst.PadPresenceAlways,
gst.NewCapsFromString("audio/x-raw,channels=2,rate=48000"),
))
class.AddPadTemplate(gst.NewPadTemplate(
"sink",
gst.PadDirectionSink,
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 *customBaseTransform) 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 *customBaseTransform) 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 (*customBaseTransform) New() glib.GoObjectSubclass {
return &customBaseTransform{}
}
// InstanceInit should initialize the element. Keep in mind that the properties are not yet present. When this is called.
func (s *customBaseTransform) InstanceInit(instance *glib.Object) {}
func (s *customBaseTransform) Constructed(o *glib.Object) {}
func (s *customBaseTransform) Finalize(o *glib.Object) {}
// see base.GstBaseTransformImpl interface for the method signatures of the virtual methods
//
// it is not required to implement all methods
var _ base.GstBaseTransformImpl = nil
func (s *customBaseTransform) SinkEvent(self *base.GstBaseTransform, event *gst.Event) bool {
return self.ParentSinkEvent(event)
}
func (s *customBaseTransform) SrcEvent(self *base.GstBaseTransform, event *gst.Event) bool {
return self.ParentSrcEvent(event)
}

View File

@@ -0,0 +1,23 @@
package customtransform
import (
"github.com/go-gst/go-gst/gst"
"github.com/go-gst/go-gst/gst/base"
)
// 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
"gocustomtransform",
// The rank of the element
gst.RankNone,
// The GoElement implementation for the element
&customBaseTransform{},
// The base subclass this element extends
base.ExtendsBaseTransform,
)
}

View File

@@ -0,0 +1,46 @@
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/go-gst/go-gst/examples/plugins/basetransform/internal/customtransform"
"github.com/go-gst/go-gst/gst"
)
func run(ctx context.Context) error {
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
gst.Init(nil)
customtransform.Register()
pipeline, err := gst.NewPipelineFromString("audiotestsrc ! gocustomtransform ! fakesink")
if err != nil {
return err
}
pipeline.SetState(gst.StatePlaying)
<-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)
}
}