add arrays/lists to values ; bind SetArg for Objects

This commit is contained in:
Avi Zimmerman
2021-02-12 14:27:16 +02:00
parent 04e4785c19
commit 19e4e20035
3 changed files with 267 additions and 54 deletions
+15
View File
@@ -51,6 +51,21 @@ func (o *Object) GetValue(property string, timestamp time.Duration) *glib.Value
return glib.ValueFromNative(unsafe.Pointer(gval))
}
// SetArg sets the argument name to value on this object. Note that function silently returns
// if object has no property named name or when value cannot be converted to the type for this
// property.
func (o *Object) SetArg(name, value string) {
cName := C.CString(name)
cValue := C.CString(value)
defer C.free(unsafe.Pointer(cName))
defer C.free(unsafe.Pointer(cValue))
C.gst_util_set_object_arg(
(*C.GObject)(o.Unsafe()),
(*C.gchar)(unsafe.Pointer(cName)),
(*C.gchar)(unsafe.Pointer(cValue)),
)
}
// Log logs a message to the given category from this object using the currently registered
// debugging handlers.
func (o *Object) Log(cat *DebugCategory, level DebugLevel, message string) {
+171
View File
@@ -2,6 +2,25 @@ package gst
/*
#include "gst.go.h"
gint
cgoGstValueCompare (const GValue * value1, const GValue * value2)
{
return 0;
}
gboolean
cgoGstValueDeserialize (GValue * dest, const gchar * s)
{
return TRUE;
}
gchar *
cgoGstValueSerialize (const GValue * value1)
{
return NULL;
}
*/
import "C"
import (
@@ -539,3 +558,155 @@ func (i *IntRangeValue) ToGValue() (*glib.Value, error) {
)
return val, nil
}
// TypeValueArray is the GType for a GstValueArray
var TypeValueArray = glib.Type(C.gst_value_array_get_type())
// ValueArrayValue represets a GstValueArray.
type ValueArrayValue glib.Value
// ValueArray converts the given slice of Go types into a ValueArrayValue.
// This function can return nil on any conversion or memory allocation errors.
func ValueArray(ss []interface{}) *ValueArrayValue {
v, err := glib.ValueAlloc()
if err != nil {
return nil
}
C.gst_value_array_init(
(*C.GValue)(unsafe.Pointer(v.GValue)),
C.guint(len(ss)),
)
for _, s := range ss {
val, err := glib.GValue(s)
if err != nil {
return nil
}
C.gst_value_array_append_value(
(*C.GValue)(unsafe.Pointer(v.GValue)),
(*C.GValue)(unsafe.Pointer(val.GValue)),
)
}
out := ValueArrayValue(*v)
return &out
}
// Size returns the size of the array.
func (v *ValueArrayValue) Size() uint {
return uint(C.gst_value_array_get_size((*C.GValue)(unsafe.Pointer(v.GValue))))
}
// ValueAt returns the value at the index in the array, or nil on any error.
func (v *ValueArrayValue) ValueAt(idx uint) interface{} {
gval := C.gst_value_array_get_value(
(*C.GValue)(unsafe.Pointer(v.GValue)),
C.guint(idx),
)
if gval == nil {
return nil
}
out, err := glib.ValueFromNative(unsafe.Pointer(gval)).GoValue()
if err != nil {
return nil
}
return out
}
// ToGValue implements a glib.ValueTransformer.
func (v *ValueArrayValue) ToGValue() (*glib.Value, error) {
out := glib.Value(*v)
return &out, nil
}
// TypeValueList is the GType for a GstValueList
var TypeValueList = glib.Type(C.gst_value_list_get_type())
// ValueListValue represets a GstValueList.
type ValueListValue glib.Value
// ValueList converts the given slice of Go types into a ValueListValue.
// This function can return nil on any conversion or memory allocation errors.
func ValueList(ss []interface{}) *ValueListValue {
v, err := glib.ValueAlloc()
if err != nil {
return nil
}
C.gst_value_list_init(
(*C.GValue)(unsafe.Pointer(v.GValue)),
C.guint(len(ss)),
)
for _, s := range ss {
val, err := glib.GValue(s)
if err != nil {
return nil
}
C.gst_value_list_append_value(
(*C.GValue)(unsafe.Pointer(v.GValue)),
(*C.GValue)(unsafe.Pointer(val.GValue)),
)
}
out := ValueListValue(*v)
return &out
}
// Size returns the size of the list.
func (v *ValueListValue) Size() uint {
return uint(C.gst_value_list_get_size((*C.GValue)(unsafe.Pointer(v.GValue))))
}
// ValueAt returns the value at the index in the lise, or nil on any error.
func (v *ValueListValue) ValueAt(idx uint) interface{} {
gval := C.gst_value_list_get_value(
(*C.GValue)(unsafe.Pointer(v.GValue)),
C.guint(idx),
)
if gval == nil {
return nil
}
out, err := glib.ValueFromNative(unsafe.Pointer(gval)).GoValue()
if err != nil {
return nil
}
return out
}
// Concat concatenates copies of this list and value into a new list. Values that are not of type
// TypeValueList are treated as if they were lists of length 1. dest will be initialized to the type
// TypeValueList.
func (v *ValueListValue) Concat(value *ValueListValue) *ValueListValue {
out, err := glib.ValueAlloc()
if err != nil {
return nil
}
C.gst_value_list_concat(
(*C.GValue)(unsafe.Pointer(out.GValue)),
(*C.GValue)(unsafe.Pointer(v.GValue)),
(*C.GValue)(unsafe.Pointer(value.GValue)),
)
o := ValueListValue(*out)
return &o
}
// Merge merges copies of value into this list. Values that are not of type TypeValueList are treated as
// if they were lists of length 1.
//
// The result will be put into a new value and will either be a list that will not contain any duplicates,
// or a non-list type (if the lists were equal).
func (v *ValueListValue) Merge(value *ValueListValue) *ValueListValue {
out, err := glib.ValueAlloc()
if err != nil {
return nil
}
C.gst_value_list_merge(
(*C.GValue)(unsafe.Pointer(out.GValue)),
(*C.GValue)(unsafe.Pointer(v.GValue)),
(*C.GValue)(unsafe.Pointer(value.GValue)),
)
o := ValueListValue(*out)
return &o
}
// ToGValue implements a glib.ValueTransformer.
func (v *ValueListValue) ToGValue() (*glib.Value, error) {
out := glib.Value(*v)
return &out, nil
}
+81 -54
View File
@@ -2,8 +2,6 @@ package gst
/*
#include "gst.go.h"
GValue * toGValue (guintptr p) { return (GValue*)(p); }
*/
import "C"
@@ -66,8 +64,6 @@ func wrapAllocationParams(obj *C.GstAllocationParams) *AllocationParams {
// Marshallers
func uintptrToGVal(p uintptr) *C.GValue { return (*C.GValue)(C.toGValue(C.guintptr(p))) }
func registerMarshalers() {
tm := []glib.TypeMarshaler{
{
@@ -230,56 +226,87 @@ func registerMarshalers() {
T: TypeIntRange,
F: marshalIntRange,
},
{
T: TypeValueArray,
F: marshalValueArray,
},
{
T: TypeValueList,
F: marshalValueList,
},
}
glib.RegisterGValueMarshalers(tm)
}
func toGValue(p uintptr) *C.GValue {
return (*C.GValue)((unsafe.Pointer)(p))
}
func marshalValueArray(p uintptr) (interface{}, error) {
val := toGValue(p)
out := ValueArrayValue(*glib.ValueFromNative(unsafe.Pointer(val)))
return &out, nil
}
func marshalValueList(p uintptr) (interface{}, error) {
val := glib.ValueFromNative(unsafe.Pointer(toGValue(p)))
out := ValueListValue(*glib.ValueFromNative(unsafe.Pointer(val)))
return &out, nil
}
func marshalInt64Range(p uintptr) (interface{}, error) {
v := toGValue(p)
return &Int64RangeValue{
start: int64(C.gst_value_get_int64_range_min(uintptrToGVal(p))),
end: int64(C.gst_value_get_int64_range_max(uintptrToGVal(p))),
step: int64(C.gst_value_get_int64_range_step(uintptrToGVal(p))),
start: int64(C.gst_value_get_int64_range_min(v)),
end: int64(C.gst_value_get_int64_range_max(v)),
step: int64(C.gst_value_get_int64_range_step(v)),
}, nil
}
func marshalIntRange(p uintptr) (interface{}, error) {
v := toGValue(p)
return &IntRangeValue{
start: int(C.gst_value_get_int_range_min(uintptrToGVal(p))),
end: int(C.gst_value_get_int_range_max(uintptrToGVal(p))),
step: int(C.gst_value_get_int_range_step(uintptrToGVal(p))),
start: int(C.gst_value_get_int_range_min(v)),
end: int(C.gst_value_get_int_range_max(v)),
step: int(C.gst_value_get_int_range_step(v)),
}, nil
}
func marshalBitmask(p uintptr) (interface{}, error) {
return Bitmask(C.gst_value_get_bitmask(uintptrToGVal(p))), nil
v := toGValue(p)
return Bitmask(C.gst_value_get_bitmask(v)), nil
}
func marshalFlagset(p uintptr) (interface{}, error) {
v := toGValue(p)
return &FlagsetValue{
flags: uint(C.gst_value_get_flagset_flags(uintptrToGVal(p))),
mask: uint(C.gst_value_get_flagset_mask(uintptrToGVal(p))),
flags: uint(C.gst_value_get_flagset_flags(v)),
mask: uint(C.gst_value_get_flagset_mask(v)),
}, nil
}
func marshalDoubleRange(p uintptr) (interface{}, error) {
v := toGValue(p)
return &Float64RangeValue{
start: float64(C.gst_value_get_double_range_min(uintptrToGVal(p))),
end: float64(C.gst_value_get_double_range_max(uintptrToGVal(p))),
start: float64(C.gst_value_get_double_range_min(v)),
end: float64(C.gst_value_get_double_range_max(v)),
}, nil
}
func marshalFraction(p uintptr) (interface{}, error) {
v := &FractionValue{
num: int(C.gst_value_get_fraction_numerator(uintptrToGVal(p))),
denom: int(C.gst_value_get_fraction_denominator(uintptrToGVal(p))),
v := toGValue(p)
out := &FractionValue{
num: int(C.gst_value_get_fraction_numerator(v)),
denom: int(C.gst_value_get_fraction_denominator(v)),
}
return v, nil
return out, nil
}
func marshalFractionRange(p uintptr) (interface{}, error) {
start := C.gst_value_get_fraction_range_min(uintptrToGVal(p))
end := C.gst_value_get_fraction_range_max(uintptrToGVal(p))
v := toGValue(p)
start := C.gst_value_get_fraction_range_min(v)
end := C.gst_value_get_fraction_range_max(v)
return &FractionRangeValue{
start: ValueGetFraction(glib.ValueFromNative(unsafe.Pointer(start))),
end: ValueGetFraction(glib.ValueFromNative(unsafe.Pointer(end))),
@@ -287,189 +314,189 @@ func marshalFractionRange(p uintptr) (interface{}, error) {
}
func marshalBufferingMode(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return BufferingMode(c), nil
}
func marshalFormat(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return Format(c), nil
}
func marshalMessageType(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return MessageType(c), nil
}
func marshalPadLinkReturn(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return PadLinkReturn(c), nil
}
func marshalState(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return State(c), nil
}
func marshalSeekFlags(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return SeekFlags(c), nil
}
func marshalSeekType(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return SeekType(c), nil
}
func marshalStateChangeReturn(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
c := C.g_value_get_enum(toGValue(p))
return StateChangeReturn(c), nil
}
func marshalGhostPad(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapGhostPad(obj), nil
}
func marshalProxyPad(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapProxyPad(obj), nil
}
func marshalPad(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapPad(obj), nil
}
func marshalMessage(p uintptr) (interface{}, error) {
c := C.g_value_get_boxed(uintptrToGVal(p))
c := C.g_value_get_boxed(toGValue(p))
return &Message{(*C.GstMessage)(unsafe.Pointer(c))}, nil
}
func marshalObject(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapObject(obj), nil
}
func marshalBus(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapBus(obj), nil
}
func marshalElementFactory(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapElementFactory(obj), nil
}
func marshalPipeline(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapPipeline(obj), nil
}
func marshalPluginFeature(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapPluginFeature(obj), nil
}
func marshalElement(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapElement(obj), nil
}
func marshalBin(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapBin(obj), nil
}
func marshalAllocationParams(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstAllocationParams)(unsafe.Pointer(c))
return wrapAllocationParams(obj), nil
}
func marshalMemory(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstMemory)(unsafe.Pointer(c))
return wrapMemory(obj), nil
}
func marshalBuffer(p uintptr) (interface{}, error) {
c := C.getBufferValue(uintptrToGVal(p))
c := C.getBufferValue(toGValue(p))
return wrapBuffer(c), nil
}
func marshalBufferList(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstBufferList)(unsafe.Pointer(c))
return wrapBufferList(obj), nil
}
func marshalCaps(p uintptr) (interface{}, error) {
c := C.gst_value_get_caps(uintptrToGVal(p))
c := C.gst_value_get_caps(toGValue(p))
obj := (*C.GstCaps)(unsafe.Pointer(c))
return wrapCaps(obj), nil
}
func marshalCapsFeatures(p uintptr) (interface{}, error) {
c := C.gst_value_get_caps_features(uintptrToGVal(p))
c := C.gst_value_get_caps_features(toGValue(p))
obj := (*C.GstCapsFeatures)(unsafe.Pointer(c))
return wrapCapsFeatures(obj), nil
}
func marshalStructure(p uintptr) (interface{}, error) {
c := C.gst_value_get_structure(uintptrToGVal(p))
c := C.gst_value_get_structure(toGValue(p))
obj := (*C.GstStructure)(unsafe.Pointer(c))
return wrapStructure(obj), nil
}
func marshalContext(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstContext)(unsafe.Pointer(c))
return wrapContext(obj), nil
}
func marshalTOC(p uintptr) (interface{}, error) {
c := C.gst_value_get_structure(uintptrToGVal(p))
c := C.gst_value_get_structure(toGValue(p))
obj := (*C.GstToc)(unsafe.Pointer(c))
return wrapTOC(obj), nil
}
func marshalTOCEntry(p uintptr) (interface{}, error) {
c := C.gst_value_get_structure(uintptrToGVal(p))
c := C.gst_value_get_structure(toGValue(p))
obj := (*C.GstTocEntry)(unsafe.Pointer(c))
return wrapTOCEntry(obj), nil
}
func marsalTagList(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstTagList)(unsafe.Pointer(c))
return wrapTagList(obj), nil
}
func marshalEvent(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstEvent)(unsafe.Pointer(c))
return wrapEvent(obj), nil
}
func marshalSegment(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstSegment)(unsafe.Pointer(c))
return wrapSegment(obj), nil
}
func marshalQuery(p uintptr) (interface{}, error) {
c := C.g_value_get_object(uintptrToGVal(p))
c := C.g_value_get_object(toGValue(p))
obj := (*C.GstQuery)(unsafe.Pointer(c))
return wrapQuery(obj), nil
}