From 7c7d4d53e98e828d4b83c8b5236ca0a6fcf31c9b Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Fri, 25 Aug 2023 10:27:02 +0100 Subject: [PATCH] make audio meta use glib's transfer none --- gst/audio/gst_audio_meta.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gst/audio/gst_audio_meta.go b/gst/audio/gst_audio_meta.go index 6749697..f6766f8 100644 --- a/gst/audio/gst_audio_meta.go +++ b/gst/audio/gst_audio_meta.go @@ -8,29 +8,32 @@ import "C" import ( "unsafe" + "github.com/tinyzimmer/go-glib/glib" "github.com/go-gst/go-gst/gst" ) -type AudioMeta struct { - ptr *C.GstAudioMeta +// AudioMeta is a Go representation of a GstAudioMeta. +type AudioMeta struct{ *Object } + +// FromGstAudioMetaUnsafeNone wraps the given audioMeta with a ref and finalizer. +func FromGstAudioMetaUnsafeNone(audioMeta unsafe.Pointer) *AudioMeta { + return &AudioMeta{wrapObject(glib.TransferNone(audioMeta))} } -func wrapMetaFull(ptr *C.GstAudioMeta) *AudioMeta { - meta := &AudioMeta{ptr} - return meta -} +func BufferAddAudioMeta(buffer *gst.Buffer, info *Info, samples int, offsets []int) *AudioMeta { + // offsets is not yet implemented, always pass `nil` or this will panic + if offsets != nil { + panic("offsets is not implemented") + } -func BufferAddAudioMeta(buffer *gst.Buffer, info *Info, samples int /*, offsets *[]int*/) *AudioMeta { - /*gSizeOffsets := C.gsize(unsafe.Sizeof(unsafe.Pointer(offsets)))*/ + // gSizeOffsets := C.gsize(unsafe.Sizeof(unsafe.Pointer(offsets))) // if you pass in NULL as the last param then gstreamer assumes things are tightly packed... - // and they are for me so this makes things work... but obviously would be nice for it to work - // properly + // so that's what we currently assume until we inplement offsets - return wrapMetaFull(C.gst_buffer_add_audio_meta( + return FromGstAudioMetaUnsafeNone(unsafe.Pointer(C.gst_buffer_add_audio_meta( (*C.GstBuffer)(unsafe.Pointer(buffer.Instance())), info.ptr, C.gsize(samples), - /*&gSizeOffsets,*/ - nil, - )) + offsets, + )))) }