mirror of
https://github.com/go-gst/go-gst.git
synced 2025-10-17 13:31:43 +08:00
Squashed commit of the following:
commit 7f46be64521d7cdf4d94409f979143a55acd665a Author: Avi Zimmerman <avi.zimmerman@gmail.com> Date: Thu Jan 7 12:18:37 2021 +0200 improve plugin interfaces
This commit is contained in:
@@ -6,40 +6,8 @@ package gst
|
||||
extern void goClassInit (gpointer g_class, gpointer class_data);
|
||||
extern void goInstanceInit (GTypeInstance * instance, gpointer g_class);
|
||||
|
||||
extern void goObjectSetProperty (GObject * object, guint property_id, const GValue * value, GParamSpec *pspec);
|
||||
extern void goObjectGetProperty (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
|
||||
extern void goObjectConstructed (GObject * object);
|
||||
extern void goObjectFinalize (GObject * object, gpointer klass);
|
||||
|
||||
void objectFinalize (GObject * object)
|
||||
{
|
||||
GObjectClass *parent = g_type_class_peek_parent((G_OBJECT_GET_CLASS(object)));
|
||||
goObjectFinalize(object, G_OBJECT_GET_CLASS(object));
|
||||
parent->finalize(object);
|
||||
}
|
||||
|
||||
void objectConstructed (GObject * object)
|
||||
{
|
||||
GObjectClass *parent = g_type_class_peek_parent((G_OBJECT_GET_CLASS(object)));
|
||||
goObjectConstructed(object);
|
||||
parent->constructed(object);
|
||||
}
|
||||
|
||||
void cgoClassInit (gpointer g_class, gpointer class_data)
|
||||
{
|
||||
((GObjectClass *)g_class)->set_property = goObjectSetProperty;
|
||||
((GObjectClass *)g_class)->get_property = goObjectGetProperty;
|
||||
((GObjectClass *)g_class)->constructed = objectConstructed;
|
||||
((GObjectClass *)g_class)->finalize = objectFinalize;
|
||||
|
||||
goClassInit(g_class, class_data);
|
||||
}
|
||||
|
||||
void cgoInstanceInit (GTypeInstance * instance, gpointer g_class)
|
||||
{
|
||||
goInstanceInit(instance, g_class);
|
||||
}
|
||||
|
||||
void cgoClassInit (gpointer g_class, gpointer class_data) { goClassInit(g_class, class_data); }
|
||||
void cgoInstanceInit (GTypeInstance * instance, gpointer g_class) { goInstanceInit(instance, g_class); }
|
||||
*/
|
||||
import "C"
|
||||
|
||||
@@ -51,45 +19,28 @@ import (
|
||||
gopointer "github.com/mattn/go-pointer"
|
||||
)
|
||||
|
||||
// GoElement is an interface to be implemented by GStreamer elements built using the
|
||||
// go bindings. Select methods from other interfaces can be overridden and declared via
|
||||
// the Extendable properties.
|
||||
//
|
||||
// Typically, at the very least, an element will want to implement methods from the Element
|
||||
// Extendable (and by extension the GoObject).
|
||||
type GoElement interface{ GoObjectSubclass }
|
||||
|
||||
// Extendable is an interface implemented by extendable classes. It provides
|
||||
// the methods necessary to setup the vmethods on the object it represents.
|
||||
type Extendable interface {
|
||||
// Type should return the type of the extended object
|
||||
Type() glib.Type
|
||||
// ClasSize should return the size of the extended class
|
||||
ClassSize() int64
|
||||
// InstanceSize should return the size of the object itself
|
||||
InstanceSize() int64
|
||||
// InitClass should take a pointer to a new subclass and a GoElement and override any
|
||||
// methods implemented by the GoElement in the subclass.
|
||||
InitClass(unsafe.Pointer, GoElement)
|
||||
}
|
||||
|
||||
type extendElement struct{}
|
||||
|
||||
func (e *extendElement) Type() glib.Type { return glib.Type(C.gst_element_get_type()) }
|
||||
func (e *extendElement) ClassSize() int64 { return int64(C.sizeof_GstElementClass) }
|
||||
func (e *extendElement) InstanceSize() int64 { return int64(C.sizeof_GstElement) }
|
||||
func (e *extendElement) InitClass(klass unsafe.Pointer, elem GoElement) {}
|
||||
|
||||
// ExtendsElement signifies a GoElement that extends a GstElement.
|
||||
var ExtendsElement Extendable = &extendElement{}
|
||||
|
||||
// GoElement is an interface to be implemented by GStreamer elements built using the
|
||||
// go bindings. The various methods are called throughout the lifecycle of the plugin.
|
||||
type GoElement interface {
|
||||
GoObjectSubclass
|
||||
GoObject
|
||||
}
|
||||
|
||||
// privateFromObj returns the actual value of the address we stored in the object's private data.
|
||||
func privateFromObj(obj unsafe.Pointer) unsafe.Pointer {
|
||||
private := C.g_type_instance_get_private((*C.GTypeInstance)(obj), C.objectGType((*C.GObject)(obj)))
|
||||
privAddr := (*unsafe.Pointer)(unsafe.Pointer(private))
|
||||
return *privAddr
|
||||
}
|
||||
|
||||
// FromObjectUnsafePrivate will return the GoElement addressed in the private data of the given GObject.
|
||||
func FromObjectUnsafePrivate(obj unsafe.Pointer) GoElement {
|
||||
ptr := gopointer.Restore(privateFromObj(obj))
|
||||
return ptr.(GoElement)
|
||||
}
|
||||
|
||||
// GoObjectSubclass is an interface that abstracts on the GObjectClass. It should be implemented
|
||||
// by plugins using the go bindings.
|
||||
type GoObjectSubclass interface {
|
||||
@@ -99,21 +50,14 @@ type GoObjectSubclass interface {
|
||||
// element should add any interfaces it plans to implement.
|
||||
TypeInit(*TypeInstance)
|
||||
// ClassInit is called on the element after registering it with GStreamer. This is when the element
|
||||
// should install any properties and pad templates it has.
|
||||
// should install its properties and pad templates.
|
||||
ClassInit(*ElementClass)
|
||||
}
|
||||
|
||||
// GoObject is an interface that abstracts on the GObject. It should be implemented by plugins using
|
||||
// the gobindings.
|
||||
type GoObject interface {
|
||||
// SetProperty should set the value of the property with the given id. ID is the index+1 of the parameter
|
||||
// in the order it was registered.
|
||||
SetProperty(obj *Object, id uint, value *glib.Value)
|
||||
// GetProperty should retrieve the value of the property with the given id. ID is the index+1 of the parameter
|
||||
// in the order it was registered.
|
||||
GetProperty(obj *Object, id uint) *glib.Value
|
||||
// Constructed is called when the Object has finished setting up.
|
||||
Constructed(*Object)
|
||||
// FromObjectUnsafePrivate will return the GoElement addressed in the private data of the given GObject.
|
||||
func FromObjectUnsafePrivate(obj unsafe.Pointer) GoElement {
|
||||
ptr := gopointer.Restore(privateFromObj(obj))
|
||||
return ptr.(GoElement)
|
||||
}
|
||||
|
||||
type classData struct {
|
||||
@@ -156,3 +100,10 @@ func gtypeForGoElement(name string, elem GoElement, extendable Extendable) C.GTy
|
||||
registeredTypes[reflect.TypeOf(elem).String()] = gtype
|
||||
return gtype
|
||||
}
|
||||
|
||||
// privateFromObj returns the actual value of the address we stored in the object's private data.
|
||||
func privateFromObj(obj unsafe.Pointer) unsafe.Pointer {
|
||||
private := C.g_type_instance_get_private((*C.GTypeInstance)(obj), C.objectGType((*C.GObject)(obj)))
|
||||
privAddr := (*unsafe.Pointer)(unsafe.Pointer(private))
|
||||
return *privAddr
|
||||
}
|
||||
|
Reference in New Issue
Block a user