diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3755b6f..20a628d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,23 @@ jobs: - name: Setup GStreamer id: setup_gstreamer uses: blinemedical/setup-gstreamer@v1.4.0 + with: + version: "1.24.10" + gstreamerOptions: |- + -Dauto_features=disabled + -Dgpl=enabled + -Dexamples=disabled + -Dgtk_doc=disabled + -Dintrospection=disabled + -Dlibav=disabled + -Dpython=disabled + -Dvaapi=disabled + -Dwebrtc=enabled + -Dgstreamer:coretracers=enabled + -Dgst-plugins-bad:dtls=enabled + -Dgst-plugins-bad:sctp=enabled + -Dgst-plugins-bad:srtp=enabled + -Dlibnice=enabled - name: checkout uses: actions/checkout@v3 - uses: actions/setup-go@v5 diff --git a/examples/custom_events/main.go b/examples/custom_events/main.go index 1445127..b158668 100644 --- a/examples/custom_events/main.go +++ b/examples/custom_events/main.go @@ -49,14 +49,14 @@ func createPipeline() (*gst.Pipeline, error) { // Extra check to make sure it is the right type. if ev.Type() != gst.EventTypeCustomDownstream { - return gst.PadProbeUnhandled + return gst.PadProbeHandled } // Unmarshal the event into our custom one var customEvent ExampleCustomEvent if err := ev.GetStructure().UnmarshalInto(&customEvent); err != nil { fmt.Println("Could not parse the custom event!") - return gst.PadProbeUnhandled + return gst.PadProbeHandled } // Log and act accordingly diff --git a/examples/plugins/basetransform/internal/customtransform/element.go b/examples/plugins/basetransform/internal/customtransform/element.go new file mode 100644 index 0000000..8821ac6 --- /dev/null +++ b/examples/plugins/basetransform/internal/customtransform/element.go @@ -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 ", + ) + 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) +} diff --git a/examples/plugins/basetransform/internal/customtransform/register.go b/examples/plugins/basetransform/internal/customtransform/register.go new file mode 100644 index 0000000..980b198 --- /dev/null +++ b/examples/plugins/basetransform/internal/customtransform/register.go @@ -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, + ) +} diff --git a/examples/plugins/basetransform/main.go b/examples/plugins/basetransform/main.go new file mode 100644 index 0000000..892dec3 --- /dev/null +++ b/examples/plugins/basetransform/main.go @@ -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) + } +} diff --git a/examples/plugins/registered_elements/main.go b/examples/plugins/registered_elements/main.go index 13105a4..1440045 100644 --- a/examples/plugins/registered_elements/main.go +++ b/examples/plugins/registered_elements/main.go @@ -6,7 +6,6 @@ import ( "os" "os/signal" "path/filepath" - "runtime" "runtime/pprof" "github.com/go-gst/go-glib/glib" @@ -83,14 +82,10 @@ func run(ctx context.Context) error { go mainloop.Run() - go func() { - <-ctx.Done() - - mainloop.Quit() - }() - <-ctx.Done() + mainloop.Quit() + pipeline.BlockSetState(gst.StateNull) gst.Deinit() @@ -107,9 +102,8 @@ func main() { fmt.Fprintln(os.Stderr, err) } - runtime.GC() - runtime.GC() - runtime.GC() + // this is very helpful to find memory leaks, see github.com/go-gst/asanutils + // asanutils.CheckLeaks() prof := pprof.Lookup("go-glib-reffed-objects") diff --git a/go.mod b/go.mod index 778c332..5b30a5a 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,10 @@ module github.com/go-gst/go-gst -go 1.23.1 +go 1.23.2 -toolchain go1.23.2 - -require github.com/mattn/go-pointer v0.0.1 - -require github.com/go-gst/go-glib v1.4.1-0.20241115142200-3da60b6536bd +require ( + github.com/go-gst/go-glib v1.4.1-0.20241209142714-f53cebf18559 + github.com/go-gst/go-pointer v0.0.0-20241127163939-ba766f075b4c +) require golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect diff --git a/go.sum b/go.sum index 558e5d9..f3b3a15 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ -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= +github.com/go-gst/go-glib v1.4.1-0.20241209142714-f53cebf18559 h1:AK60n6W3FLZTp9H1KU5VOa8XefNO0w0R3pfszphwX14= +github.com/go-gst/go-glib v1.4.1-0.20241209142714-f53cebf18559/go.mod h1:ZWT4LXOO2PH8lSNu/dR5O2yoNQJKEgmijNa2d7nByK8= +github.com/go-gst/go-pointer v0.0.0-20241127163939-ba766f075b4c h1:x8kKRVDmz5BRlolmDZGcsuZ1l+js6TRL3QWBJjGVctM= +github.com/go-gst/go-pointer v0.0.0-20241127163939-ba766f075b4c/go.mod h1:qKw5ZZ0U58W6PU/7F/Lopv+14nKYmdXlOd7VnAZ17Mk= golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= diff --git a/gst/app/cgo_exports.go b/gst/app/cgo_exports.go index 1c0c3b8..7a3dcf2 100644 --- a/gst/app/cgo_exports.go +++ b/gst/app/cgo_exports.go @@ -7,7 +7,7 @@ import ( "github.com/go-gst/go-glib/glib" "github.com/go-gst/go-gst/gst" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) func getSinkCbsFromPtr(userData C.gpointer) *SinkCallbacks { @@ -64,7 +64,8 @@ func goNeedDataCb(src *C.GstAppSrc, length C.guint, userData C.gpointer) { return } gosrc := wrapCSource(src) - gosrc.WithTransferOriginal(func() { cbs.NeedDataFunc(gosrc, uint(length)) }) + + cbs.NeedDataFunc(gosrc, uint(length)) } //export goEnoughDataDb @@ -77,7 +78,7 @@ func goEnoughDataDb(src *C.GstAppSrc, userData C.gpointer) { return } gosrc := wrapCSource(src) - gosrc.WithTransferOriginal(func() { cbs.EnoughDataFunc(gosrc) }) + cbs.EnoughDataFunc(gosrc) } //export goSeekDataCb @@ -90,9 +91,8 @@ func goSeekDataCb(src *C.GstAppSrc, offset C.guint64, userData C.gpointer) C.gbo return gboolean(true) } gosrc := wrapCSource(src) - var ret C.gboolean - gosrc.WithTransferOriginal(func() { ret = gboolean(cbs.SeekDataFunc(gosrc, uint64(offset))) }) - return ret + + return gboolean(cbs.SeekDataFunc(gosrc, uint64(offset))) } //export goSinkEOSCb @@ -105,7 +105,8 @@ func goSinkEOSCb(sink *C.GstAppSink, userData C.gpointer) { return } gosink := wrapCSink(sink) - gosink.WithTransferOriginal(func() { cbs.EOSFunc(gosink) }) + + cbs.EOSFunc(gosink) } //export goSinkNewPrerollCb @@ -118,8 +119,9 @@ func goSinkNewPrerollCb(sink *C.GstAppSink, userData C.gpointer) C.GstFlowReturn return C.GstFlowReturn(gst.FlowOK) } gosink := wrapCSink(sink) - var ret C.GstFlowReturn - gosink.WithTransferOriginal(func() { ret = C.GstFlowReturn(cbs.NewPrerollFunc(gosink)) }) + + ret := C.GstFlowReturn(cbs.NewPrerollFunc(gosink)) + return ret } @@ -133,8 +135,9 @@ func goSinkNewSampleCb(sink *C.GstAppSink, userData C.gpointer) C.GstFlowReturn return C.GstFlowReturn(gst.FlowOK) } gosink := wrapCSink(sink) - var ret C.GstFlowReturn - gosink.WithTransferOriginal(func() { ret = C.GstFlowReturn(cbs.NewSampleFunc(gosink)) }) + + ret := C.GstFlowReturn(cbs.NewSampleFunc(gosink)) + return ret } diff --git a/gst/app/gst_app_sink.go b/gst/app/gst_app_sink.go index bb15b83..24b64ba 100644 --- a/gst/app/gst_app_sink.go +++ b/gst/app/gst_app_sink.go @@ -21,7 +21,7 @@ import ( "errors" "unsafe" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" "github.com/go-gst/go-gst/gst" "github.com/go-gst/go-gst/gst/base" diff --git a/gst/app/gst_app_src.go b/gst/app/gst_app_src.go index 888870d..092323c 100644 --- a/gst/app/gst_app_src.go +++ b/gst/app/gst_app_src.go @@ -22,7 +22,7 @@ import ( "github.com/go-gst/go-gst/gst" "github.com/go-gst/go-gst/gst/base" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // SourceCallbacks represents callbacks to configure on an AppSource. diff --git a/gst/base/gst_base_sink_exports.go b/gst/base/gst_base_sink_exports.go index 92c5d6b..dd24ba7 100644 --- a/gst/base/gst_base_sink_exports.go +++ b/gst/base/gst_base_sink_exports.go @@ -16,36 +16,42 @@ import ( //export goGstBaseSinkActivatePull func goGstBaseSinkActivatePull(sink *C.GstBaseSink, active C.gboolean) C.gboolean { var ret C.gboolean - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - ActivatePull(self *GstBaseSink, active bool) bool - }) - ret = gboolean(iface.ActivatePull(ToGstBaseSink(gObject), gobool(active))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + ActivatePull(self *GstBaseSink, active bool) bool }) + ret = gboolean(iface.ActivatePull(goBaseSink, gobool(active))) + return ret } //export goGstBaseSinkEvent func goGstBaseSinkEvent(sink *C.GstBaseSink, event *C.GstEvent) C.gboolean { var ret C.gboolean - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Event(self *GstBaseSink, event *gst.Event) bool - }) - ret = gboolean(iface.Event(ToGstBaseSink(gObject), gst.ToGstEvent(unsafe.Pointer(event)))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Event(self *GstBaseSink, event *gst.Event) bool }) + ret = gboolean(iface.Event(goBaseSink, gst.ToGstEvent(unsafe.Pointer(event)))) + return ret } //export goGstBaseSinkFixate func goGstBaseSinkFixate(sink *C.GstBaseSink, caps *C.GstCaps) *C.GstCaps { var fixated *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Fixate(self *GstBaseSink, caps *gst.Caps) *gst.Caps - }) - fixated = iface.Fixate(ToGstBaseSink(gObject), gst.ToGstCaps(unsafe.Pointer(caps))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Fixate(self *GstBaseSink, caps *gst.Caps) *gst.Caps }) + fixated = iface.Fixate(goBaseSink, gst.ToGstCaps(unsafe.Pointer(caps))) + if fixated == nil { return nil } @@ -55,12 +61,14 @@ func goGstBaseSinkFixate(sink *C.GstBaseSink, caps *C.GstCaps) *C.GstCaps { //export goGstBaseSinkGetCaps func goGstBaseSinkGetCaps(sink *C.GstBaseSink, filter *C.GstCaps) *C.GstCaps { var filtered *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetCaps(self *GstBaseSink, filter *gst.Caps) *gst.Caps - }) - filtered = iface.GetCaps(ToGstBaseSink(gObject), gst.ToGstCaps(unsafe.Pointer(filter))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + GetCaps(self *GstBaseSink, filter *gst.Caps) *gst.Caps }) + filtered = iface.GetCaps(goBaseSink, gst.ToGstCaps(unsafe.Pointer(filter))) + if filtered == nil { return nil } @@ -70,12 +78,14 @@ func goGstBaseSinkGetCaps(sink *C.GstBaseSink, filter *C.GstCaps) *C.GstCaps { //export goGstBaseSinkGetTimes func goGstBaseSinkGetTimes(sink *C.GstBaseSink, buf *C.GstBuffer, start, end *C.GstClockTime) { var retStart, retEnd time.Duration - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetTimes(self *GstBaseSink, buffer *gst.Buffer) (start, end time.Duration) // should this be a ClockTime? - }) - retStart, retEnd = iface.GetTimes(ToGstBaseSink(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + GetTimes(self *GstBaseSink, buffer *gst.Buffer) (start, end time.Duration) // should this be a ClockTime? }) + retStart, retEnd = iface.GetTimes(goBaseSink, gst.ToGstBuffer(unsafe.Pointer(buf))) + *start = C.GstClockTime(retStart.Nanoseconds()) *end = C.GstClockTime(retEnd.Nanoseconds()) } @@ -83,155 +93,181 @@ func goGstBaseSinkGetTimes(sink *C.GstBaseSink, buf *C.GstBuffer, start, end *C. //export goGstBaseSinkPrepare func goGstBaseSinkPrepare(sink *C.GstBaseSink, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Prepare(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn - }) - ret = iface.Prepare(ToGstBaseSink(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Prepare(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn }) + ret = iface.Prepare(goBaseSink, gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } //export goGstBaseSinkPrepareList func goGstBaseSinkPrepareList(sink *C.GstBaseSink, list *C.GstBufferList) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - PrepareList(self *GstBaseSink, bufferList *gst.BufferList) gst.FlowReturn - }) - ret = iface.PrepareList(ToGstBaseSink(gObject), gst.ToGstBufferList(unsafe.Pointer(list))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + PrepareList(self *GstBaseSink, bufferList *gst.BufferList) gst.FlowReturn }) + ret = iface.PrepareList(goBaseSink, gst.ToGstBufferList(unsafe.Pointer(list))) + return C.GstFlowReturn(ret) } //export goGstBaseSinkPreroll func goGstBaseSinkPreroll(sink *C.GstBaseSink, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Preroll(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn - }) - ret = iface.Preroll(ToGstBaseSink(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Preroll(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn }) + ret = iface.Preroll(goBaseSink, gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } //export goGstBaseSinkProposeAllocation func goGstBaseSinkProposeAllocation(sink *C.GstBaseSink, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - ProposeAllocation(self *GstBaseSink, query *gst.Query) bool - }) - ret = iface.ProposeAllocation(ToGstBaseSink(gObject), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + ProposeAllocation(self *GstBaseSink, query *gst.Query) bool }) + ret = iface.ProposeAllocation(goBaseSink, gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseSinkQuery func goGstBaseSinkQuery(sink *C.GstBaseSink, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Query(self *GstBaseSink, query *gst.Query) bool - }) - ret = iface.Query(ToGstBaseSink(gObject), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Query(self *GstBaseSink, query *gst.Query) bool }) + ret = iface.Query(goBaseSink, gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseSinkRender func goGstBaseSinkRender(sink *C.GstBaseSink, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Render(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn - }) - ret = iface.Render(ToGstBaseSink(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Render(self *GstBaseSink, buffer *gst.Buffer) gst.FlowReturn }) + ret = iface.Render(goBaseSink, gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } //export goGstBaseSinkRenderList func goGstBaseSinkRenderList(sink *C.GstBaseSink, buf *C.GstBufferList) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - RenderList(self *GstBaseSink, bufferList *gst.BufferList) gst.FlowReturn - }) - ret = iface.RenderList(ToGstBaseSink(gObject), gst.ToGstBufferList(unsafe.Pointer(buf))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + RenderList(self *GstBaseSink, bufferList *gst.BufferList) gst.FlowReturn }) + ret = iface.RenderList(goBaseSink, gst.ToGstBufferList(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } //export goGstBaseSinkSetCaps func goGstBaseSinkSetCaps(sink *C.GstBaseSink, caps *C.GstCaps) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SetCaps(self *GstBaseSink, caps *gst.Caps) bool - }) - ret = iface.SetCaps(ToGstBaseSink(gObject), gst.ToGstCaps(unsafe.Pointer(caps))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + SetCaps(self *GstBaseSink, caps *gst.Caps) bool }) + ret = iface.SetCaps(goBaseSink, gst.ToGstCaps(unsafe.Pointer(caps))) + return gboolean(ret) } //export goGstBaseSinkStart func goGstBaseSinkStart(sink *C.GstBaseSink) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Start(self *GstBaseSink) bool - }) - ret = iface.Start(ToGstBaseSink(gObject)) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Start(self *GstBaseSink) bool }) + ret = iface.Start(goBaseSink) + return gboolean(ret) } //export goGstBaseSinkStop func goGstBaseSinkStop(sink *C.GstBaseSink) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Stop(self *GstBaseSink) bool - }) - ret = iface.Stop(ToGstBaseSink(gObject)) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Stop(self *GstBaseSink) bool }) + ret = iface.Stop(goBaseSink) + return gboolean(ret) } //export goGstBaseSinkUnlock func goGstBaseSinkUnlock(sink *C.GstBaseSink) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Unlock(self *GstBaseSink) bool - }) - ret = iface.Unlock(ToGstBaseSink(gObject)) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + Unlock(self *GstBaseSink) bool }) + ret = iface.Unlock(goBaseSink) + return gboolean(ret) } //export goGstBaseSinkUnlockStop func goGstBaseSinkUnlockStop(sink *C.GstBaseSink) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - UnlockStop(self *GstBaseSink) bool - }) - ret = iface.UnlockStop(ToGstBaseSink(gObject)) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + UnlockStop(self *GstBaseSink) bool }) + ret = iface.UnlockStop(goBaseSink) + return gboolean(ret) } //export goGstBaseSinkWaitEvent func goGstBaseSinkWaitEvent(sink *C.GstBaseSink, event *C.GstEvent) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(sink), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - WaitEvent(self *GstBaseSink, event *gst.Event) gst.FlowReturn - }) - ret = iface.WaitEvent(ToGstBaseSink(gObject), gst.ToGstEvent(unsafe.Pointer(event))) + goBaseSink := ToGstBaseSink(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(sink))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(sink)) + + iface := subclass.(interface { + WaitEvent(self *GstBaseSink, event *gst.Event) gst.FlowReturn }) + ret = iface.WaitEvent(goBaseSink, gst.ToGstEvent(unsafe.Pointer(event))) + return C.GstFlowReturn(ret) } diff --git a/gst/base/gst_base_src_exports.go b/gst/base/gst_base_src_exports.go index 1455917..bb655f6 100644 --- a/gst/base/gst_base_src_exports.go +++ b/gst/base/gst_base_src_exports.go @@ -14,12 +14,15 @@ import ( //export goGstBaseSrcGetCaps func goGstBaseSrcGetCaps(src *C.GstBaseSrc, filter *C.GstCaps) *C.GstCaps { var caps *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetCaps(*GstBaseSrc, *gst.Caps) *gst.Caps - }) - caps = iface.GetCaps(ToGstBaseSrc(gObject), gst.ToGstCaps(unsafe.Pointer(filter))) + + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + GetCaps(*GstBaseSrc, *gst.Caps) *gst.Caps }) + caps = iface.GetCaps(goBaseSrc, gst.ToGstCaps(unsafe.Pointer(filter))) + if caps == nil { return nil } @@ -29,24 +32,28 @@ func goGstBaseSrcGetCaps(src *C.GstBaseSrc, filter *C.GstCaps) *C.GstCaps { //export goGstBaseSrcNegotiate func goGstBaseSrcNegotiate(src *C.GstBaseSrc) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Negotiate(*GstBaseSrc) bool - }) - ret = iface.Negotiate(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Negotiate(*GstBaseSrc) bool }) + ret = iface.Negotiate(goBaseSrc) + return gboolean(ret) } //export goGstBaseSrcFixate func goGstBaseSrcFixate(src *C.GstBaseSrc, filter *C.GstCaps) *C.GstCaps { var caps *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Fixate(*GstBaseSrc, *gst.Caps) *gst.Caps - }) - caps = iface.Fixate(ToGstBaseSrc(gObject), gst.ToGstCaps(unsafe.Pointer(filter))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Fixate(*GstBaseSrc, *gst.Caps) *gst.Caps }) + caps = iface.Fixate(goBaseSrc, gst.ToGstCaps(unsafe.Pointer(filter))) + if caps == nil { return nil } @@ -56,60 +63,70 @@ func goGstBaseSrcFixate(src *C.GstBaseSrc, filter *C.GstCaps) *C.GstCaps { //export goGstBaseSrcSetCaps func goGstBaseSrcSetCaps(src *C.GstBaseSrc, caps *C.GstCaps) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SetCaps(*GstBaseSrc, *gst.Caps) bool - }) - ret = iface.SetCaps(ToGstBaseSrc(gObject), gst.ToGstCaps(unsafe.Pointer(caps))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + SetCaps(*GstBaseSrc, *gst.Caps) bool }) + ret = iface.SetCaps(goBaseSrc, gst.ToGstCaps(unsafe.Pointer(caps))) + return gboolean(ret) } //export goGstBaseSrcDecideAllocation func goGstBaseSrcDecideAllocation(src *C.GstBaseSrc, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - DecideAllocation(*GstBaseSrc, *gst.Query) bool - }) - ret = iface.DecideAllocation(ToGstBaseSrc(gObject), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + DecideAllocation(*GstBaseSrc, *gst.Query) bool }) + ret = iface.DecideAllocation(goBaseSrc, gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseSrcStart func goGstBaseSrcStart(src *C.GstBaseSrc) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Start(*GstBaseSrc) bool - }) - ret = iface.Start(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Start(*GstBaseSrc) bool }) + ret = iface.Start(goBaseSrc) + return gboolean(ret) } //export goGstBaseSrcStop func goGstBaseSrcStop(src *C.GstBaseSrc) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Stop(*GstBaseSrc) bool - }) - ret = iface.Stop(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Stop(*GstBaseSrc) bool }) + ret = iface.Stop(goBaseSrc) + return gboolean(ret) } //export goGstBaseSrcGetTimes func goGstBaseSrcGetTimes(src *C.GstBaseSrc, buf *C.GstBuffer, start *C.GstClockTime, end *C.GstClockTime) { var gostart, goend time.Duration - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetTimes(*GstBaseSrc, *gst.Buffer) (start, end time.Duration) // should this be a ClockTime? - }) - gostart, goend = iface.GetTimes(ToGstBaseSrc(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + GetTimes(*GstBaseSrc, *gst.Buffer) (start, end time.Duration) // should this be a ClockTime? }) + gostart, goend = iface.GetTimes(goBaseSrc, gst.ToGstBuffer(unsafe.Pointer(buf))) + *start = C.GstClockTime(gostart.Nanoseconds()) *end = C.GstClockTime(goend.Nanoseconds()) } @@ -118,12 +135,14 @@ func goGstBaseSrcGetTimes(src *C.GstBaseSrc, buf *C.GstBuffer, start *C.GstClock func goGstBaseSrcGetSize(src *C.GstBaseSrc, size *C.guint64) C.gboolean { var gosize int64 var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetSize(*GstBaseSrc) (bool, int64) - }) - ok, gosize = iface.GetSize(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + GetSize(*GstBaseSrc) (bool, int64) }) + ok, gosize = iface.GetSize(goBaseSrc) + if ok { *size = C.guint64(gosize) } @@ -133,84 +152,98 @@ func goGstBaseSrcGetSize(src *C.GstBaseSrc, size *C.guint64) C.gboolean { //export goGstBaseSrcIsSeekable func goGstBaseSrcIsSeekable(src *C.GstBaseSrc) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - IsSeekable(*GstBaseSrc) bool - }) - ok = iface.IsSeekable(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + IsSeekable(*GstBaseSrc) bool }) + ok = iface.IsSeekable(goBaseSrc) + return gboolean(ok) } //export goGstBaseSrcPrepareSeekSegment func goGstBaseSrcPrepareSeekSegment(src *C.GstBaseSrc, seek *C.GstEvent, segment *C.GstSegment) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - PrepareSeekSegment(*GstBaseSrc, *gst.Event, *gst.Segment) bool - }) - ok = iface.PrepareSeekSegment(ToGstBaseSrc(gObject), gst.ToGstEvent(unsafe.Pointer(seek)), gst.FromGstSegmentUnsafe(unsafe.Pointer(segment))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + PrepareSeekSegment(*GstBaseSrc, *gst.Event, *gst.Segment) bool }) + ok = iface.PrepareSeekSegment(goBaseSrc, gst.ToGstEvent(unsafe.Pointer(seek)), gst.FromGstSegmentUnsafe(unsafe.Pointer(segment))) + return gboolean(ok) } //export goGstBaseSrcDoSeek func goGstBaseSrcDoSeek(src *C.GstBaseSrc, segment *C.GstSegment) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - DoSeek(*GstBaseSrc, *gst.Segment) bool - }) - ok = iface.DoSeek(ToGstBaseSrc(gObject), gst.ToGstSegment(unsafe.Pointer(segment))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + DoSeek(*GstBaseSrc, *gst.Segment) bool }) + ok = iface.DoSeek(goBaseSrc, gst.ToGstSegment(unsafe.Pointer(segment))) + return gboolean(ok) } //export goGstBaseSrcUnlock func goGstBaseSrcUnlock(src *C.GstBaseSrc) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Unlock(*GstBaseSrc) bool - }) - ok = iface.Unlock(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Unlock(*GstBaseSrc) bool }) + ok = iface.Unlock(goBaseSrc) + return gboolean(ok) } //export goGstBaseSrcUnlockStop func goGstBaseSrcUnlockStop(src *C.GstBaseSrc) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - UnlockStop(*GstBaseSrc) bool - }) - ok = iface.UnlockStop(ToGstBaseSrc(gObject)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + UnlockStop(*GstBaseSrc) bool }) + ok = iface.UnlockStop(goBaseSrc) + return gboolean(ok) } //export goGstBaseSrcQuery func goGstBaseSrcQuery(src *C.GstBaseSrc, query *C.GstQuery) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Query(*GstBaseSrc, *gst.Query) bool - }) - ok = iface.Query(ToGstBaseSrc(gObject), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Query(*GstBaseSrc, *gst.Query) bool }) + ok = iface.Query(goBaseSrc, gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ok) } //export goGstBaseSrcEvent func goGstBaseSrcEvent(src *C.GstBaseSrc, event *C.GstEvent) C.gboolean { var ok bool - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Event(*GstBaseSrc, *gst.Event) bool - }) - ok = iface.Event(ToGstBaseSrc(gObject), gst.ToGstEvent(unsafe.Pointer(event))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Event(*GstBaseSrc, *gst.Event) bool }) + ok = iface.Event(goBaseSrc, gst.ToGstEvent(unsafe.Pointer(event))) + return gboolean(ok) } @@ -218,12 +251,14 @@ func goGstBaseSrcEvent(src *C.GstBaseSrc, event *C.GstEvent) C.gboolean { func goGstBaseSrcCreate(src *C.GstBaseSrc, offset C.guint64, size C.guint, buf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var gobuf *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Create(*GstBaseSrc, uint64, uint) (gst.FlowReturn, *gst.Buffer) - }) - ret, gobuf = iface.Create(ToGstBaseSrc(gObject), uint64(offset), uint(size)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Create(*GstBaseSrc, uint64, uint) (gst.FlowReturn, *gst.Buffer) }) + ret, gobuf = iface.Create(goBaseSrc, uint64(offset), uint(size)) + if ret == gst.FlowOK { C.memcpy(unsafe.Pointer(*buf), unsafe.Pointer(gobuf.Instance()), C.sizeof_GstBuffer) } @@ -234,12 +269,14 @@ func goGstBaseSrcCreate(src *C.GstBaseSrc, offset C.guint64, size C.guint, buf * func goGstBaseSrcAlloc(src *C.GstBaseSrc, offset C.guint64, size C.guint, buf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var gobuf *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Alloc(*GstBaseSrc, uint64, uint) (gst.FlowReturn, *gst.Buffer) - }) - ret, gobuf = iface.Alloc(ToGstBaseSrc(gObject), uint64(offset), uint(size)) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Alloc(*GstBaseSrc, uint64, uint) (gst.FlowReturn, *gst.Buffer) }) + ret, gobuf = iface.Alloc(goBaseSrc, uint64(offset), uint(size)) + if ret == gst.FlowOK { C.memcpy(unsafe.Pointer(*buf), unsafe.Pointer(gobuf.Instance()), C.sizeof_GstBuffer) } @@ -249,11 +286,13 @@ func goGstBaseSrcAlloc(src *C.GstBaseSrc, offset C.guint64, size C.guint, buf ** //export goGstBaseSrcFill func goGstBaseSrcFill(src *C.GstBaseSrc, offset C.guint64, size C.guint, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Fill(*GstBaseSrc, uint64, uint, *gst.Buffer) gst.FlowReturn - }) - ret = iface.Fill(ToGstBaseSrc(gObject), uint64(offset), uint(size), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseSrc := ToGstBaseSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Fill(*GstBaseSrc, uint64, uint, *gst.Buffer) gst.FlowReturn }) + ret = iface.Fill(goBaseSrc, uint64(offset), uint(size), gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } diff --git a/gst/base/gst_base_transform.go b/gst/base/gst_base_transform.go index 54c9c98..9eeca63 100644 --- a/gst/base/gst_base_transform.go +++ b/gst/base/gst_base_transform.go @@ -18,6 +18,22 @@ setGstBaseTransformTransformIPOnPassthrough (GstBaseTransform * obj, gboolean en GstBaseTransformClass * klass = toGstBaseTransformClass(g_type_class_peek_parent(this_class)); klass->transform_ip_on_passthrough = enabled; } + +gboolean +gstBaseTransformParentSrcEvent (GstBaseTransform * obj, GstEvent * event) +{ + GObjectClass * this_class = G_OBJECT_GET_CLASS(G_OBJECT(obj)); + GstBaseTransformClass * parent = toGstBaseTransformClass(g_type_class_peek_parent(this_class)); + return parent->src_event(obj, event); +} + +gboolean +gstBaseTransformParentSinkEvent (GstBaseTransform * obj, GstEvent * event) +{ + GObjectClass * this_class = G_OBJECT_GET_CLASS(G_OBJECT(obj)); + GstBaseTransformClass * parent = toGstBaseTransformClass(g_type_class_peek_parent(this_class)); + return parent->sink_event(obj, event); +} */ import "C" @@ -196,3 +212,93 @@ func (g *GstBaseTransform) UpdateSrcCaps(caps *gst.Caps) { (*C.GstCaps)(unsafe.Pointer(caps.Instance())), ) } + +func (g *GstBaseTransform) ParentAcceptCaps(direction gst.PadDirection, caps *gst.Caps) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentBeforeTransform(buffer *gst.Buffer) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentCopyMetadata(input, output *gst.Buffer) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentDecideAllocation(query *gst.Query) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentFilterMeta(query *gst.Query, api glib.Type, params *gst.Structure) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentFixateCaps(directon gst.PadDirection, caps *gst.Caps, othercaps *gst.Caps) *gst.Caps { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentGenerateOutput(gst.FlowReturn, *gst.Buffer) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentGetUnitSize(caps *gst.Caps) (ok bool, size int64) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentPrepareOutputBuffer(input *gst.Buffer) (gst.FlowReturn, *gst.Buffer) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentProposeAllocation(decideQuery, query *gst.Query) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentQuery(direction gst.PadDirection, query *gst.Query) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentSetCaps(incaps, outcaps *gst.Caps) bool { + panic("not implemented") +} + +// ParentSrcEvent chains the event up to the parent class +func (g *GstBaseTransform) ParentSrcEvent(event *gst.Event) bool { + return gobool(C.gstBaseTransformParentSrcEvent(g.Instance(), (*C.GstEvent)(unsafe.Pointer(event.Instance())))) +} + +// ParentSinkEvent chains the event up to the parent class +func (g *GstBaseTransform) ParentSinkEvent(event *gst.Event) bool { + return gobool(C.gstBaseTransformParentSinkEvent(g.Instance(), (*C.GstEvent)(unsafe.Pointer(event.Instance())))) +} + +func (g *GstBaseTransform) ParentStart(bool) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentStop(bool) { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentSubmitInputBuffer(isDiscont bool, input *gst.Buffer) gst.FlowReturn { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentTransform(inbuf, outbuf *gst.Buffer) gst.FlowReturn { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentTransformCaps(direction gst.PadDirection, caps, filter *gst.Caps) *gst.Caps { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentTransformIP(buf *gst.Buffer) gst.FlowReturn { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentTransformMeta(outbuf *gst.Buffer, meta *gst.Meta, inbuf *gst.Buffer) bool { + panic("not implemented") +} + +func (g *GstBaseTransform) ParentTransformSize(direction gst.PadDirection, caps *gst.Caps, size int64, othercaps *gst.Caps) (ok bool, othersize int64) { + panic("not implemented") +} diff --git a/gst/base/gst_base_transform_exports.go b/gst/base/gst_base_transform_exports.go index b657285..602492a 100644 --- a/gst/base/gst_base_transform_exports.go +++ b/gst/base/gst_base_transform_exports.go @@ -15,70 +15,80 @@ import ( //export goGstBaseTransformAcceptCaps func goGstBaseTransformAcceptCaps(self *C.GstBaseTransform, direction C.GstPadDirection, caps *C.GstCaps) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - AcceptCaps(*GstBaseTransform, gst.PadDirection, *gst.Caps) bool - }) - ret = iface.AcceptCaps(ToGstBaseTransform(self), gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + AcceptCaps(*GstBaseTransform, gst.PadDirection, *gst.Caps) bool }) + ret = iface.AcceptCaps(goBaseT, gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps))) + return gboolean(ret) } //export goGstBaseTransformBeforeTransform func goGstBaseTransformBeforeTransform(self *C.GstBaseTransform, buffer *C.GstBuffer) { - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - BeforeTransform(*GstBaseTransform, *gst.Buffer) - }) - iface.BeforeTransform(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(buffer))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + BeforeTransform(*GstBaseTransform, *gst.Buffer) }) + iface.BeforeTransform(goBaseT, gst.ToGstBuffer(unsafe.Pointer(buffer))) } //export goGstBaseTransformCopyMetadata func goGstBaseTransformCopyMetadata(self *C.GstBaseTransform, input, output *C.GstBuffer) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - CopyMetadata(self *GstBaseTransform, input, output *gst.Buffer) bool - }) - ret = iface.CopyMetadata(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(input)), gst.ToGstBuffer(unsafe.Pointer(output))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + CopyMetadata(self *GstBaseTransform, input, output *gst.Buffer) bool }) + ret = iface.CopyMetadata(goBaseT, gst.ToGstBuffer(unsafe.Pointer(input)), gst.ToGstBuffer(unsafe.Pointer(output))) return gboolean(ret) } //export goGstBaseTransformDecideAllocation func goGstBaseTransformDecideAllocation(self *C.GstBaseTransform, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - DecideAllocation(self *GstBaseTransform, query *gst.Query) bool - }) - ret = iface.DecideAllocation(ToGstBaseTransform(self), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + DecideAllocation(self *GstBaseTransform, query *gst.Query) bool }) + ret = iface.DecideAllocation(goBaseT, gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseTransformFilterMeta func goGstBaseTransformFilterMeta(self *C.GstBaseTransform, query *C.GstQuery, api C.GType, params *C.GstStructure) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - FilterMeta(self *GstBaseTransform, query *gst.Query, api glib.Type, params *gst.Structure) bool - }) - ret = iface.FilterMeta(ToGstBaseTransform(self), gst.ToGstQuery(unsafe.Pointer(query)), glib.Type(api), gst.FromGstStructureUnsafe(unsafe.Pointer(params))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + FilterMeta(self *GstBaseTransform, query *gst.Query, api glib.Type, params *gst.Structure) bool }) + ret = iface.FilterMeta(goBaseT, gst.ToGstQuery(unsafe.Pointer(query)), glib.Type(api), gst.FromGstStructureUnsafe(unsafe.Pointer(params))) + return gboolean(ret) } //export goGstBaseTransformFixateCaps func goGstBaseTransformFixateCaps(self *C.GstBaseTransform, direction C.GstPadDirection, caps, othercaps *C.GstCaps) *C.GstCaps { var ret *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - FixateCaps(self *GstBaseTransform, directon gst.PadDirection, caps *gst.Caps, othercaps *gst.Caps) *gst.Caps - }) - ret = iface.FixateCaps(ToGstBaseTransform(self), gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), gst.ToGstCaps(unsafe.Pointer(othercaps))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + FixateCaps(self *GstBaseTransform, directon gst.PadDirection, caps *gst.Caps, othercaps *gst.Caps) *gst.Caps }) + ret = iface.FixateCaps(goBaseT, gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), gst.ToGstCaps(unsafe.Pointer(othercaps))) + if ret == nil { return nil } @@ -89,12 +99,14 @@ func goGstBaseTransformFixateCaps(self *C.GstBaseTransform, direction C.GstPadDi func goGstBaseTransformGenerateOutput(self *C.GstBaseTransform, buf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var out *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GenerateOutput(self *GstBaseTransform) (gst.FlowReturn, *gst.Buffer) - }) - ret, out = iface.GenerateOutput(ToGstBaseTransform(self)) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + GenerateOutput(self *GstBaseTransform) (gst.FlowReturn, *gst.Buffer) }) + ret, out = iface.GenerateOutput(goBaseT) + if out != nil { C.memcpy(unsafe.Pointer(*buf), unsafe.Pointer(out.Instance()), C.sizeof_GstBuffer) } @@ -105,12 +117,14 @@ func goGstBaseTransformGenerateOutput(self *C.GstBaseTransform, buf **C.GstBuffe func goGstBaseTransformGetUnitSize(self *C.GstBaseTransform, caps *C.GstCaps, size *C.gsize) C.gboolean { var ret bool var out int64 - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - GetUnitSize(self *GstBaseTransform, caps *gst.Caps) (ok bool, size int64) - }) - ret, out = iface.GetUnitSize(ToGstBaseTransform(self), gst.ToGstCaps(unsafe.Pointer(caps))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + GetUnitSize(self *GstBaseTransform, caps *gst.Caps) (ok bool, size int64) }) + ret, out = iface.GetUnitSize(goBaseT, gst.ToGstCaps(unsafe.Pointer(caps))) + if ret { *size = C.gsize(out) } @@ -121,12 +135,14 @@ func goGstBaseTransformGetUnitSize(self *C.GstBaseTransform, caps *C.GstCaps, si func goGstBaseTransformPrepareOutputBuffer(self *C.GstBaseTransform, input *C.GstBuffer, outbuf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var out *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - PrepareOutputBuffer(self *GstBaseTransform, input *gst.Buffer) (gst.FlowReturn, *gst.Buffer) - }) - ret, out = iface.PrepareOutputBuffer(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(input))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + PrepareOutputBuffer(self *GstBaseTransform, input *gst.Buffer) (gst.FlowReturn, *gst.Buffer) }) + ret, out = iface.PrepareOutputBuffer(goBaseT, gst.ToGstBuffer(unsafe.Pointer(input))) + if out != nil { C.memcpy(unsafe.Pointer(*outbuf), unsafe.Pointer(out.Instance()), C.sizeof_GstBuffer) } @@ -136,120 +152,143 @@ func goGstBaseTransformPrepareOutputBuffer(self *C.GstBaseTransform, input *C.Gs //export goGstBaseTransformProposeAllocation func goGstBaseTransformProposeAllocation(self *C.GstBaseTransform, decide, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - ProposeAllocation(self *GstBaseTransform, decideQuery, query *gst.Query) bool - }) - ret = iface.ProposeAllocation(ToGstBaseTransform(self), gst.ToGstQuery(unsafe.Pointer(decide)), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + ProposeAllocation(self *GstBaseTransform, decideQuery, query *gst.Query) bool }) + ret = iface.ProposeAllocation(goBaseT, gst.ToGstQuery(unsafe.Pointer(decide)), gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseTransformQuery func goGstBaseTransformQuery(self *C.GstBaseTransform, direction C.GstPadDirection, query *C.GstQuery) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Query(self *GstBaseTransform, direction gst.PadDirection, query *gst.Query) bool - }) - ret = iface.Query(ToGstBaseTransform(self), gst.PadDirection(direction), gst.ToGstQuery(unsafe.Pointer(query))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + Query(self *GstBaseTransform, direction gst.PadDirection, query *gst.Query) bool }) + ret = iface.Query(goBaseT, gst.PadDirection(direction), gst.ToGstQuery(unsafe.Pointer(query))) + return gboolean(ret) } //export goGstBaseTransformSetCaps func goGstBaseTransformSetCaps(self *C.GstBaseTransform, incaps, outcaps *C.GstCaps) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SetCaps(self *GstBaseTransform, incaps, outcaps *gst.Caps) bool - }) - ret = iface.SetCaps(ToGstBaseTransform(self), gst.ToGstCaps(unsafe.Pointer(incaps)), gst.ToGstCaps(unsafe.Pointer(outcaps))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + SetCaps(self *GstBaseTransform, incaps, outcaps *gst.Caps) bool }) + ret = iface.SetCaps(goBaseT, gst.ToGstCaps(unsafe.Pointer(incaps)), gst.ToGstCaps(unsafe.Pointer(outcaps))) + return gboolean(ret) } //export goGstBaseTransformSinkEvent func goGstBaseTransformSinkEvent(self *C.GstBaseTransform, event *C.GstEvent) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SinkEvent(self *GstBaseTransform, event *gst.Event) bool - }) - ret = iface.SinkEvent(ToGstBaseTransform(self), gst.ToGstEvent(unsafe.Pointer(event))) + + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + SinkEvent(self *GstBaseTransform, event *gst.Event) bool }) + + ret = iface.SinkEvent(goBaseT, gst.ToGstEvent(unsafe.Pointer(event))) + return gboolean(ret) } //export goGstBaseTransformSrcEvent func goGstBaseTransformSrcEvent(self *C.GstBaseTransform, event *C.GstEvent) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SrcEvent(self *GstBaseTransform, event *gst.Event) bool - }) - ret = iface.SrcEvent(ToGstBaseTransform(self), gst.ToGstEvent(unsafe.Pointer(event))) + + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + SrcEvent(self *GstBaseTransform, event *gst.Event) bool }) + ret = iface.SrcEvent(goBaseT, gst.ToGstEvent(unsafe.Pointer(event))) + return gboolean(ret) } //export goGstBaseTransformStart func goGstBaseTransformStart(self *C.GstBaseTransform) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Start(self *GstBaseTransform) bool - }) - ret = iface.Start(ToGstBaseTransform(self)) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + Start(self *GstBaseTransform) bool }) + ret = iface.Start(goBaseT) + return gboolean(ret) } //export goGstBaseTransformStop func goGstBaseTransformStop(self *C.GstBaseTransform) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Stop(self *GstBaseTransform) bool - }) - ret = iface.Stop(ToGstBaseTransform(self)) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + Stop(self *GstBaseTransform) bool }) + ret = iface.Stop(goBaseT) + return gboolean(ret) } //export goGstBaseTransformSubmitInputBuffer func goGstBaseTransformSubmitInputBuffer(self *C.GstBaseTransform, isDiscont C.gboolean, input *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - SubmitInputBuffer(self *GstBaseTransform, isDiscont bool, input *gst.Buffer) gst.FlowReturn - }) - ret = iface.SubmitInputBuffer(ToGstBaseTransform(self), gobool(isDiscont), gst.ToGstBuffer(unsafe.Pointer(input))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + SubmitInputBuffer(self *GstBaseTransform, isDiscont bool, input *gst.Buffer) gst.FlowReturn }) + ret = iface.SubmitInputBuffer(goBaseT, gobool(isDiscont), gst.ToGstBuffer(unsafe.Pointer(input))) + return C.GstFlowReturn(ret) } //export goGstBaseTransformTransform func goGstBaseTransformTransform(self *C.GstBaseTransform, inbuf, outbuf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Transform(self *GstBaseTransform, inbuf, outbuf *gst.Buffer) gst.FlowReturn - }) - ret = iface.Transform(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(inbuf)), gst.ToGstBuffer(unsafe.Pointer(outbuf))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + Transform(self *GstBaseTransform, inbuf, outbuf *gst.Buffer) gst.FlowReturn }) + ret = iface.Transform(goBaseT, gst.ToGstBuffer(unsafe.Pointer(inbuf)), gst.ToGstBuffer(unsafe.Pointer(outbuf))) + return C.GstFlowReturn(ret) } //export goGstBaseTransformTransformCaps func goGstBaseTransformTransformCaps(self *C.GstBaseTransform, direction C.GstPadDirection, caps, filter *C.GstCaps) *C.GstCaps { var ret *gst.Caps - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - TransformCaps(self *GstBaseTransform, direction gst.PadDirection, caps, filter *gst.Caps) *gst.Caps - }) - ret = iface.TransformCaps(ToGstBaseTransform(self), gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), gst.ToGstCaps(unsafe.Pointer(filter))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + TransformCaps(self *GstBaseTransform, direction gst.PadDirection, caps, filter *gst.Caps) *gst.Caps }) + ret = iface.TransformCaps(goBaseT, gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), gst.ToGstCaps(unsafe.Pointer(filter))) + if ret == nil { return nil } @@ -259,24 +298,28 @@ func goGstBaseTransformTransformCaps(self *C.GstBaseTransform, direction C.GstPa //export goGstBaseTransformTransformIP func goGstBaseTransformTransformIP(self *C.GstBaseTransform, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - TransformIP(self *GstBaseTransform, buf *gst.Buffer) gst.FlowReturn - }) - ret = iface.TransformIP(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(buf))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + TransformIP(self *GstBaseTransform, buf *gst.Buffer) gst.FlowReturn }) + ret = iface.TransformIP(goBaseT, gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } //export goGstBaseTransformTransformMeta func goGstBaseTransformTransformMeta(self *C.GstBaseTransform, outbuf *C.GstBuffer, meta *C.GstMeta, inbuf *C.GstBuffer) C.gboolean { var ret bool - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - TransformMeta(self *GstBaseTransform, outbuf *gst.Buffer, meta *gst.Meta, inbuf *gst.Buffer) bool - }) - ret = iface.TransformMeta(ToGstBaseTransform(self), gst.ToGstBuffer(unsafe.Pointer(outbuf)), gst.FromGstMetaUnsafe(unsafe.Pointer(meta)), gst.ToGstBuffer(unsafe.Pointer(inbuf))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + TransformMeta(self *GstBaseTransform, outbuf *gst.Buffer, meta *gst.Meta, inbuf *gst.Buffer) bool }) + ret = iface.TransformMeta(goBaseT, gst.ToGstBuffer(unsafe.Pointer(outbuf)), gst.FromGstMetaUnsafe(unsafe.Pointer(meta)), gst.ToGstBuffer(unsafe.Pointer(inbuf))) + return gboolean(ret) } @@ -284,12 +327,14 @@ func goGstBaseTransformTransformMeta(self *C.GstBaseTransform, outbuf *C.GstBuff func goGstBaseTransformTransformSize(self *C.GstBaseTransform, direction C.GstPadDirection, caps *C.GstCaps, size C.gsize, othercaps *C.GstCaps, outsize *C.gsize) C.gboolean { var ret bool var othersize int64 - glib.WithPointerTransferOriginal(unsafe.Pointer(self), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - TransformSize(self *GstBaseTransform, direction gst.PadDirection, caps *gst.Caps, size int64, othercaps *gst.Caps) (ok bool, othersize int64) - }) - ret, othersize = iface.TransformSize(ToGstBaseTransform(self), gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), int64(size), gst.ToGstCaps(unsafe.Pointer(othercaps))) + goBaseT := ToGstBaseTransform(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(self))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(self)) + + iface := subclass.(interface { + TransformSize(self *GstBaseTransform, direction gst.PadDirection, caps *gst.Caps, size int64, othercaps *gst.Caps) (ok bool, othersize int64) }) + ret, othersize = iface.TransformSize(goBaseT, gst.PadDirection(direction), gst.ToGstCaps(unsafe.Pointer(caps)), int64(size), gst.ToGstCaps(unsafe.Pointer(othercaps))) + if ret { *outsize = C.gsize(othersize) } diff --git a/gst/base/gst_collect_pads.go b/gst/base/gst_collect_pads.go index 4e6249e..8d6cc88 100644 --- a/gst/base/gst_collect_pads.go +++ b/gst/base/gst_collect_pads.go @@ -60,7 +60,7 @@ import ( "time" "unsafe" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" "github.com/go-gst/go-gst/gst" ) diff --git a/gst/base/gst_collect_pads_exports.go b/gst/base/gst_collect_pads_exports.go index eb28af5..a986aad 100644 --- a/gst/base/gst_collect_pads_exports.go +++ b/gst/base/gst_collect_pads_exports.go @@ -8,7 +8,7 @@ import ( "time" "unsafe" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" "github.com/go-gst/go-gst/gst" ) diff --git a/gst/base/gst_push_src_exports.go b/gst/base/gst_push_src_exports.go index dd19312..c3797bb 100644 --- a/gst/base/gst_push_src_exports.go +++ b/gst/base/gst_push_src_exports.go @@ -16,12 +16,14 @@ import ( func goGstPushSrcAlloc(src *C.GstPushSrc, buf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var outbuf *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Alloc(*GstPushSrc) (gst.FlowReturn, *gst.Buffer) - }) - ret, outbuf = iface.Alloc(ToGstPushSrc(gObject)) + goPushSrc := ToGstPushSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Alloc(*GstPushSrc) (gst.FlowReturn, *gst.Buffer) }) + ret, outbuf = iface.Alloc(goPushSrc) + if outbuf != nil { C.memcpy(unsafe.Pointer(*buf), unsafe.Pointer(outbuf.Instance()), C.sizeof_GstBuffer) } @@ -32,12 +34,14 @@ func goGstPushSrcAlloc(src *C.GstPushSrc, buf **C.GstBuffer) C.GstFlowReturn { func goGstPushSrcCreate(src *C.GstPushSrc, buf **C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn var outbuf *gst.Buffer - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Create(*GstPushSrc) (gst.FlowReturn, *gst.Buffer) - }) - ret, outbuf = iface.Create(ToGstPushSrc(gObject)) + goPushSrc := ToGstPushSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Create(*GstPushSrc) (gst.FlowReturn, *gst.Buffer) }) + ret, outbuf = iface.Create(goPushSrc) + if outbuf != nil { C.memcpy(unsafe.Pointer(*buf), unsafe.Pointer(outbuf.Instance()), C.sizeof_GstBuffer) } @@ -47,11 +51,13 @@ func goGstPushSrcCreate(src *C.GstPushSrc, buf **C.GstBuffer) C.GstFlowReturn { //export goGstPushSrcFill func goGstPushSrcFill(src *C.GstPushSrc, buf *C.GstBuffer) C.GstFlowReturn { var ret gst.FlowReturn - glib.WithPointerTransferOriginal(unsafe.Pointer(src), func(gObject *glib.Object, goObject glib.GoObjectSubclass) { - iface := goObject.(interface { - Fill(*GstPushSrc, *gst.Buffer) gst.FlowReturn - }) - ret = iface.Fill(ToGstPushSrc(gObject), gst.ToGstBuffer(unsafe.Pointer(buf))) + goPushSrc := ToGstPushSrc(&glib.Object{GObject: glib.ToGObject(unsafe.Pointer(src))}) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(src)) + + iface := subclass.(interface { + Fill(*GstPushSrc, *gst.Buffer) gst.FlowReturn }) + ret = iface.Fill(goPushSrc, gst.ToGstBuffer(unsafe.Pointer(buf))) + return C.GstFlowReturn(ret) } diff --git a/gst/cgo_exports.go b/gst/cgo_exports.go index 9207fc1..4d9515d 100644 --- a/gst/cgo_exports.go +++ b/gst/cgo_exports.go @@ -13,7 +13,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) //export goElementCallAsync diff --git a/gst/constants.go b/gst/constants.go index b8f4b8c..fb0fa5e 100644 --- a/gst/constants.go +++ b/gst/constants.go @@ -456,11 +456,11 @@ type PadProbeReturn int // Type castings of ProbeReturns const ( - PadProbeDrop PadProbeReturn = C.GST_PAD_PROBE_DROP // (0) – drop data in data probes. For push mode this means that the data item is not sent downstream. For pull mode, it means that the data item is not passed upstream. In both cases, no other probes are called for this item and GST_FLOW_OK or TRUE is returned to the caller. - PadProbeOK PadProbeReturn = C.GST_PAD_PROBE_OK // (1) – normal probe return value. This leaves the probe in place, and defers decisions about dropping or passing data to other probes, if any. If there are no other probes, the default behavior for the probe type applies ('block' for blocking probes, and 'pass' for non-blocking probes). - PadProbeRemove PadProbeReturn = C.GST_PAD_PROBE_REMOVE // (2) – remove this probe. - PadProbePass PadProbeReturn = C.GST_PAD_PROBE_PASS // (3) – pass the data item in the block probe and block on the next item. - PadProbeUnhandled PadProbeReturn = C.GST_PAD_PROBE_HANDLED // (4) – Data has been handled in the probe and will not be forwarded further. For events and buffers this is the same behavior as GST_PAD_PROBE_DROP (except that in this case you need to unref the buffer or event yourself). For queries it will also return TRUE to the caller. The probe can also modify the GstFlowReturn value by using the GST_PAD_PROBE_INFO_FLOW_RETURN() accessor. Note that the resulting query must contain valid entries. Since: 1.6 + PadProbeDrop PadProbeReturn = C.GST_PAD_PROBE_DROP // (0) – drop data in data probes. For push mode this means that the data item is not sent downstream. For pull mode, it means that the data item is not passed upstream. In both cases, no other probes are called for this item and GST_FLOW_OK or TRUE is returned to the caller. + PadProbeOK PadProbeReturn = C.GST_PAD_PROBE_OK // (1) – normal probe return value. This leaves the probe in place, and defers decisions about dropping or passing data to other probes, if any. If there are no other probes, the default behavior for the probe type applies ('block' for blocking probes, and 'pass' for non-blocking probes). + PadProbeRemove PadProbeReturn = C.GST_PAD_PROBE_REMOVE // (2) – remove this probe. + PadProbePass PadProbeReturn = C.GST_PAD_PROBE_PASS // (3) – pass the data item in the block probe and block on the next item. + PadProbeHandled PadProbeReturn = C.GST_PAD_PROBE_HANDLED // (4) – Data has been handled in the probe and will not be forwarded further. For events and buffers this is the same behavior as GST_PAD_PROBE_DROP (except that in this case you need to unref the buffer or event yourself). For queries it will also return TRUE to the caller. The probe can also modify the GstFlowReturn value by using the GST_PAD_PROBE_INFO_FLOW_RETURN() accessor. Note that the resulting query must contain valid entries. Since: 1.6 ) // PadProbeType casts GstPadProbeType diff --git a/gst/control_binding.go b/gst/control_binding.go index baaba2d..28f60cb 100644 --- a/gst/control_binding.go +++ b/gst/control_binding.go @@ -14,7 +14,7 @@ func (cb *ControlBinding) Instance() *C.GstControlBinding { return C.toGstControlBinding(cb.Unsafe()) } -type DirectControlBinding struct{ ControlBinding } +type DirectControlBinding struct{ *ControlBinding } func NewDirectControlBinding(obj *Object, prop string, csource *InterpolationControlSource) *DirectControlBinding { cprop := C.CString(prop) @@ -23,7 +23,7 @@ func NewDirectControlBinding(obj *Object, prop string, csource *InterpolationCon cbinding := C.gst_direct_control_binding_new(obj.Instance(), cprop, csource.Instance()) return &DirectControlBinding{ - ControlBinding: ControlBinding{ + ControlBinding: &ControlBinding{ Object: wrapObject(glib.TransferNone(unsafe.Pointer(cbinding))), }, } diff --git a/gst/gst_buffer.go b/gst/gst_buffer.go index dfea015..ee7906b 100644 --- a/gst/gst_buffer.go +++ b/gst/gst_buffer.go @@ -26,7 +26,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // GetMaxBufferMemory returns the maximum amount of memory a buffer can hold. diff --git a/gst/gst_buffer_list.go b/gst/gst_buffer_list.go index 345975f..5e7a114 100644 --- a/gst/gst_buffer_list.go +++ b/gst/gst_buffer_list.go @@ -15,7 +15,7 @@ import ( "runtime" "unsafe" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // BufferList is a go wrapper around a GstBufferList for grouping Buffers diff --git a/gst/gst_bus.go b/gst/gst_bus.go index da6f49d..d16a686 100644 --- a/gst/gst_bus.go +++ b/gst/gst_bus.go @@ -30,7 +30,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // Bus is a Go wrapper around a GstBus. It provides convenience methods for diff --git a/gst/gst_caps.go b/gst/gst_caps.go index 86ed44e..a185357 100644 --- a/gst/gst_caps.go +++ b/gst/gst_caps.go @@ -18,7 +18,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // TypeCaps is the static Glib Type for a GstCaps. diff --git a/gst/gst_clock.go b/gst/gst_clock.go index 7992290..ac75cf5 100644 --- a/gst/gst_clock.go +++ b/gst/gst_clock.go @@ -26,7 +26,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) type ClockTime C.GstClockTime diff --git a/gst/gst_element.go b/gst/gst_element.go index bdf116b..30a5ef1 100644 --- a/gst/gst_element.go +++ b/gst/gst_element.go @@ -47,7 +47,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // Element is a Go wrapper around a GstElement. diff --git a/gst/gst_event.go b/gst/gst_event.go index 19c4b7a..8ee8f14 100644 --- a/gst/gst_event.go +++ b/gst/gst_event.go @@ -285,6 +285,8 @@ func (e *Event) ParseStreamGroupDone() uint { // ParseStreamStart parses a stream-id event and store the result in the given stream_id location. func (e *Event) ParseStreamStart() string { idPtr := C.malloc(C.sizeof_char * 1024) + defer C.free(idPtr) + C.gst_event_parse_stream_start(e.Instance(), (**C.gchar)(unsafe.Pointer(&idPtr))) return C.GoString((*C.char)(unsafe.Pointer(idPtr))) } diff --git a/gst/gst_message.go b/gst/gst_message.go index c5880b8..91fcfd8 100644 --- a/gst/gst_message.go +++ b/gst/gst_message.go @@ -95,9 +95,7 @@ func (m *Message) GetStructure() *Structure { return nil } - // The returned structure must not be freed. Applies to all methods. - // https://gstreamer.freedesktop.org/documentation/gstreamer/gstmessage.html#gst_message_parse_error_details - return wrapStructure(st) + return structureFromGlibNone(st) } // parseToError returns a new GError from this message instance. There are multiple diff --git a/gst/gst_object.go b/gst/gst_object.go index bbf7aae..6c40c52 100644 --- a/gst/gst_object.go +++ b/gst/gst_object.go @@ -98,6 +98,10 @@ func (o *Object) AddControlBinding(binding *ControlBinding) { C.gst_object_add_control_binding(o.Instance(), binding.Instance()) } +func (o *Object) RemoveControlBinding(binding *ControlBinding) { + C.gst_object_remove_control_binding(o.Instance(), binding.Instance()) +} + // TODO: Consider wrapping GstObject GST_OBJECT_LOCK/GST_OBJECT_UNLOCK functionality // due to following flags related functionality is based on a regular uint32 field // and is not considered thread safe diff --git a/gst/gst_pad.go b/gst/gst_pad.go index 64a6ea8..98fcf1e 100644 --- a/gst/gst_pad.go +++ b/gst/gst_pad.go @@ -81,10 +81,11 @@ import "C" import ( "errors" + "runtime" "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // PadFuncMap is an type of map for registering callbacks to a pad instance. @@ -1138,7 +1139,13 @@ func (p *PadProbeInfo) GetEvent() *Event { if ev == nil { return nil } - return wrapEvent(ev) + + event := wrapEvent(ev) + + event.Ref() + runtime.SetFinalizer(event, (*Event).Unref) + + return event } // GetQuery returns the query, if any, inside this probe info. diff --git a/gst/gst_pad_exports.go b/gst/gst_pad_exports.go index f60b935..0a123ea 100644 --- a/gst/gst_pad_exports.go +++ b/gst/gst_pad_exports.go @@ -8,7 +8,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) func getParent(parent *C.GstObject) *Object { diff --git a/gst/gst_plugin.go b/gst/gst_plugin.go index 8e982ae..6328926 100644 --- a/gst/gst_plugin.go +++ b/gst/gst_plugin.go @@ -54,7 +54,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // PluginMetadata represents the information to include when registering a new plugin diff --git a/gst/gst_promise.go b/gst/gst_promise.go index 7856c76..05129a1 100644 --- a/gst/gst_promise.go +++ b/gst/gst_promise.go @@ -20,7 +20,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) type PromiseResult int diff --git a/gst/gst_structure.go b/gst/gst_structure.go index 6f10546..05f6c3f 100644 --- a/gst/gst_structure.go +++ b/gst/gst_structure.go @@ -17,11 +17,12 @@ import ( "fmt" "os" "reflect" + "runtime" "sync" "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // Structure is a go implementation of a C GstStructure. @@ -35,7 +36,7 @@ func NewStructure(name string) *Structure { cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) structure := C.gst_structure_new_empty(cName) - return wrapStructure(structure) + return structureFromGlibFull(structure) } // NewStructureFromString builds a new GstStructure from the given string. @@ -46,7 +47,7 @@ func NewStructureFromString(stStr string) *Structure { if structure == nil { return nil } - return wrapStructure(structure) + return structureFromGlibFull(structure) } // MarshalStructure will convert the given go struct into a GstStructure. Currently nested @@ -83,7 +84,13 @@ func (s *Structure) UnmarshalInto(data interface{}) error { nVal := rv.Elem() for i := 0; i < val.NumField(); i++ { nvField := nVal.Field(i) - fieldName := val.Type().Field(i).Name + + fieldName, ok := val.Type().Field(i).Tag.Lookup("gst") + + if !ok { + fieldName = val.Type().Field(i).Name + } + val, err := s.GetValue(fieldName) if err == nil { nvField.Set(reflect.ValueOf(val)) @@ -184,22 +191,56 @@ var TypeStructure = glib.Type(C.gst_structure_get_type()) var _ glib.ValueTransformer = &Structure{} +func (s *Structure) copy() *C.GstStructure { + return C.gst_structure_copy(s.Instance()) +} + // ToGValue implements a glib.ValueTransformer func (s *Structure) ToGValue() (*glib.Value, error) { val, err := glib.ValueInit(TypeStructure) if err != nil { return nil, err } - C.gst_value_set_structure( - (*C.GValue)(unsafe.Pointer(val.GValue)), - s.Instance(), - ) + + if s != nil { + C.gst_value_set_structure( + (*C.GValue)(unsafe.Pointer(val.GValue)), + s.copy(), + ) + } + return val, nil } +// marshalStructure is used to extract the GstStructure from a GValue. +func marshalStructure(p unsafe.Pointer) (interface{}, error) { + c := C.gst_value_get_structure(toGValue(p)) + return structureFromGlibNone(c), nil +} + func wrapStructure(st *C.GstStructure) *Structure { return &Structure{ ptr: unsafe.Pointer(st), gType: glib.Type(st._type), } } + +// structureFromGlibNone wraps a *C.GstStructure in a Structure after copying it. +// this is needed when the structure is returned from a function that does not transfer ownership. +func structureFromGlibNone(st *C.GstStructure) *Structure { + copy := C.gst_structure_copy(st) + + return structureFromGlibFull(copy) +} + +// structureFromGlibFull wraps a *C.GstStructure in a Structure. This is used when the structure +// is returned by a function that transfers ownership to the caller. +func structureFromGlibFull(st *C.GstStructure) *Structure { + s := wrapStructure(st) + + runtime.SetFinalizer(s, func(s *Structure) { + s.Free() + }) + + return s +} diff --git a/gst/gst_tag_list.go b/gst/gst_tag_list.go index f7c3220..a30389a 100644 --- a/gst/gst_tag_list.go +++ b/gst/gst_tag_list.go @@ -19,7 +19,7 @@ import ( "unsafe" "github.com/go-gst/go-glib/glib" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // TagList is a go wrapper around a GstTagList. For now, until the rest of the methods are diff --git a/gst/gst_tracer.go b/gst/gst_tracer.go new file mode 100644 index 0000000..7eab022 --- /dev/null +++ b/gst/gst_tracer.go @@ -0,0 +1,29 @@ +package gst + +// #include "gst.go.h" +import "C" +import ( + "unsafe" + + "github.com/go-gst/go-glib/glib" +) + +type Tracer struct { + *Object +} + +func TracingGetActiveTracers() []*Tracer { + cglist := C.gst_tracing_get_active_tracers() + + wrapped := glib.WrapList(unsafe.Pointer(cglist)) + defer wrapped.Free() + + out := make([]*Tracer, 0) + wrapped.Foreach(func(item interface{}) { + ctracer := item.(unsafe.Pointer) // item is a *C.GstTracer + out = append(out, &Tracer{ + Object: wrapObject(glib.Take(ctracer)), + }) + }) + return out +} diff --git a/gst/gst_uri_handler_exports.go b/gst/gst_uri_handler_exports.go index bf0e775..7826540 100644 --- a/gst/gst_uri_handler_exports.go +++ b/gst/gst_uri_handler_exports.go @@ -33,9 +33,9 @@ func goURIHdlrGetProtocols(gtype C.GType) **C.gchar { //export goURIHdlrGetURI func goURIHdlrGetURI(hdlr *C.GstURIHandler) *C.gchar { var uri string - glib.WithPointerTransferOriginal(unsafe.Pointer(hdlr), func(gobj *glib.Object, obj glib.GoObjectSubclass) { - uri = obj.(URIHandler).GetURI() - }) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(hdlr)) + uri = subclass.(URIHandler).GetURI() + if uri == "" { return nil } @@ -46,9 +46,10 @@ func goURIHdlrGetURI(hdlr *C.GstURIHandler) *C.gchar { func goURIHdlrSetURI(hdlr *C.GstURIHandler, uri *C.gchar, gerr **C.GError) C.gboolean { var ok bool var err error - glib.WithPointerTransferOriginal(unsafe.Pointer(hdlr), func(gobj *glib.Object, obj glib.GoObjectSubclass) { - ok, err = obj.(URIHandler).SetURI(C.GoString(uri)) - }) + subclass := glib.FromObjectUnsafePrivate(unsafe.Pointer(hdlr)) + + ok, err = subclass.(URIHandler).SetURI(C.GoString(uri)) + if err != nil { errMsg := C.CString(err.Error()) defer C.free(unsafe.Pointer(errMsg)) diff --git a/gst/gst_values.go b/gst/gst_values.go index 22ed2b5..20013cb 100644 --- a/gst/gst_values.go +++ b/gst/gst_values.go @@ -161,16 +161,6 @@ func ValueGetCapsFeatures(value *glib.Value) *CapsFeatures { return &CapsFeatures{native: feats} } -// ValueGetStructure extracts the GstStructure from a glib.Value, or nil -// if one does not exist. -func ValueGetStructure(gval *glib.Value) *Structure { - st := C.gst_value_get_structure((*C.GValue)(unsafe.Pointer(gval.GValue))) - if st == nil { - return nil - } - return wrapStructure(st) -} - // ValueIntersect calculates the intersection of two values. If the values have a non-empty intersection, // the value representing the intersection isreturned. Otherwise this function returns false. This function // can also return false for any allocation errors. @@ -644,8 +634,7 @@ func ValueList(ss []interface{}) *ValueListValue { (*C.GValue)(unsafe.Pointer(val.GValue)), ) } - out := ValueListValue(*v) - return &out + return (*ValueListValue)(v) } // Size returns the size of the list. @@ -682,8 +671,8 @@ func (v *ValueListValue) Concat(value *ValueListValue) *ValueListValue { (*C.GValue)(unsafe.Pointer(v.GValue)), (*C.GValue)(unsafe.Pointer(value.GValue)), ) - o := ValueListValue(*out) - return &o + + return (*ValueListValue)(out) } // Merge merges copies of value into this list. Values that are not of type TypeValueList are treated as @@ -701,12 +690,12 @@ func (v *ValueListValue) Merge(value *ValueListValue) *ValueListValue { (*C.GValue)(unsafe.Pointer(v.GValue)), (*C.GValue)(unsafe.Pointer(value.GValue)), ) - o := ValueListValue(*out) - return &o + + return (*ValueListValue)(out) } // ToGValue implements a glib.ValueTransformer. func (v *ValueListValue) ToGValue() (*glib.Value, error) { - out := glib.Value(*v) - return &out, nil + val := (*glib.Value)(v) + return val.Copy() } diff --git a/gst/gst_wrappers.go b/gst/gst_wrappers.go index 64659f9..fa20121 100644 --- a/gst/gst_wrappers.go +++ b/gst/gst_wrappers.go @@ -258,9 +258,16 @@ func marshalValueArray(p unsafe.Pointer) (interface{}, error) { } func marshalValueList(p unsafe.Pointer) (interface{}, error) { - val := glib.ValueFromNative(p) - out := ValueListValue(*glib.ValueFromNative(unsafe.Pointer(val))) - return &out, nil + value := glib.ValueFromNative(p) + + // must copy since we don't own the gvalue passed into this marshal + out, err := value.Copy() + + if err != nil { + return nil, err + } + + return (*ValueListValue)(out), nil } func marshalInt64Range(p unsafe.Pointer) (interface{}, error) { @@ -461,12 +468,6 @@ func marshalCapsFeatures(p unsafe.Pointer) (interface{}, error) { return wrapCapsFeatures(obj), nil } -func marshalStructure(p unsafe.Pointer) (interface{}, error) { - c := C.gst_value_get_structure(toGValue(p)) - obj := (*C.GstStructure)(unsafe.Pointer(c)) - return wrapStructure(obj), nil -} - func marshalContext(p unsafe.Pointer) (interface{}, error) { c := C.g_value_get_object(toGValue(p)) obj := (*C.GstContext)(unsafe.Pointer(c)) diff --git a/gst/video/cgo_exports.go b/gst/video/cgo_exports.go index dada5de..8c7bfb5 100644 --- a/gst/video/cgo_exports.go +++ b/gst/video/cgo_exports.go @@ -9,7 +9,7 @@ import ( "unsafe" "github.com/go-gst/go-gst/gst" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) //export goVideoGDestroyNotifyFunc diff --git a/gst/video/convert_frame.go b/gst/video/convert_frame.go index 790ee7c..25ba36b 100644 --- a/gst/video/convert_frame.go +++ b/gst/video/convert_frame.go @@ -22,7 +22,7 @@ import ( "unsafe" "github.com/go-gst/go-gst/gst" - gopointer "github.com/mattn/go-pointer" + gopointer "github.com/go-gst/go-pointer" ) // ConvertSampleCallback represents a callback from a video convert opereration.