mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-04 23:52:55 +08:00
add custom transform example and remove calls to deprecated methods
This commit is contained in:
@@ -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)
|
||||
}
|
@@ -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,
|
||||
)
|
||||
}
|
46
examples/plugins/basetransform/main.go
Normal file
46
examples/plugins/basetransform/main.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user