mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-17 13:31:43 +08:00
major rework of reference handling
This commit is contained in:
@@ -3,16 +3,32 @@ package gst
|
||||
// #include "gst.go.h"
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Sample is a go wrapper around a GstSample object.
|
||||
type Sample struct {
|
||||
sample *C.GstSample
|
||||
}
|
||||
|
||||
// FromGstSampleUnsafe wraps the pointer to the given C GstSample with the go type.
|
||||
// FromGstSampleUnsafeNone wraps the pointer to the given C GstSample with the go type.
|
||||
// This is meant for internal usage and is exported for visibility to other packages.
|
||||
func FromGstSampleUnsafe(sample unsafe.Pointer) *Sample { return wrapSample(C.toGstSample(sample)) }
|
||||
func FromGstSampleUnsafeNone(sample unsafe.Pointer) *Sample {
|
||||
s := wrapSample(C.toGstSample(sample))
|
||||
s.Ref()
|
||||
runtime.SetFinalizer(s, (*Sample).Unref)
|
||||
return s
|
||||
}
|
||||
|
||||
// FromGstSampleUnsafeFull wraps the pointer to the given C GstSample with the go type.
|
||||
// This is meant for internal usage and is exported for visibility to other packages.
|
||||
func FromGstSampleUnsafeFull(sample unsafe.Pointer) *Sample {
|
||||
s := wrapSample(C.toGstSample(sample))
|
||||
runtime.SetFinalizer(s, (*Sample).Unref)
|
||||
return s
|
||||
}
|
||||
|
||||
// Instance returns the underlying *GstSample instance.
|
||||
func (s *Sample) Instance() *C.GstSample { return C.toGstSample(unsafe.Pointer(s.sample)) }
|
||||
@@ -24,21 +40,25 @@ func (s *Sample) Ref() *Sample {
|
||||
|
||||
// Copy creates a copy of the given sample. This will also make a newly allocated copy of the data
|
||||
// the source sample contains.
|
||||
func (s *Sample) Copy() *Sample { return wrapSample(C.gst_sample_copy(s.Instance())) }
|
||||
func (s *Sample) Copy() *Sample {
|
||||
return FromGstSampleUnsafeFull(unsafe.Pointer(C.gst_sample_copy(s.Instance())))
|
||||
}
|
||||
|
||||
// GetBuffer returns the buffer inside this sample.
|
||||
func (s *Sample) GetBuffer() *Buffer {
|
||||
return wrapBuffer(C.gst_sample_get_buffer((*C.GstSample)(s.Instance())))
|
||||
return FromGstBufferUnsafeNone(unsafe.Pointer(C.gst_sample_get_buffer((*C.GstSample)(s.Instance()))))
|
||||
}
|
||||
|
||||
// GetBufferList gets the buffer list associated with this sample.
|
||||
func (s *Sample) GetBufferList() *BufferList {
|
||||
return wrapBufferList(C.gst_sample_get_buffer_list(s.Instance()))
|
||||
return FromGstBufferListUnsafeNone(unsafe.Pointer(C.gst_sample_get_buffer_list(s.Instance())))
|
||||
}
|
||||
|
||||
// GetCaps returns the caps associated with this sample. Take a ref if you need to hold on to them
|
||||
// longer then the life of the sample.
|
||||
func (s *Sample) GetCaps() *Caps { return wrapCaps(C.gst_sample_get_caps(s.Instance())) }
|
||||
func (s *Sample) GetCaps() *Caps {
|
||||
return FromGstCapsUnsafeNone(unsafe.Pointer(C.gst_sample_get_caps(s.Instance())))
|
||||
}
|
||||
|
||||
// GetInfo gets extra information about this sample. The structure remains valid as long as sample is valid.
|
||||
func (s *Sample) GetInfo() *Structure { return wrapStructure(C.gst_sample_get_info(s.Instance())) }
|
||||
|
Reference in New Issue
Block a user