Esempio n. 1
0
File: gst.go Progetto: reusee/oplay
func toGValue(v interface{}) *C.GValue {
	value := C.gvalue_new()
	switch reflect.TypeOf(v).Kind() {
	case reflect.String:
		C.g_value_init(value, C.G_TYPE_STRING)
		cStr := C.CString(v.(string))
		defer C.free(unsafe.Pointer(cStr))
		C.g_value_set_string(value, (*C.gchar)(unsafe.Pointer(cStr)))
	case reflect.Int:
		C.g_value_init(value, C.G_TYPE_INT)
		C.g_value_set_int(value, C.gint(v.(int)))
	case reflect.Struct:
		switch rv := v.(type) {
		case Fraction:
			C.g_value_init(value, C.gst_fraction_get_type())
			C.gst_value_set_fraction(value, C.gint(rv.N), C.gint(rv.D))
		default:
			p("unknown struct type %v\n", v)
			panic("fixme") //TODO
		}
	case reflect.Ptr:
		switch reflect.TypeOf(v) {
		case gstCapsType:
			C.g_value_init(value, C.gst_caps_get_type())
			C.gst_value_set_caps(value, v.(*C.GstCaps))
		default:
			panic(fmt.Sprintf("unknown type %v", v)) //TODO
		}
	default:
		panic(fmt.Sprintf("unknown type %v", v)) //TODO
	}
	return value
}
Esempio n. 2
0
func (f *Fraction) Value() *glib.Value {
	v := glib.NewValue(f.Type())
	C.gst_value_set_fraction(v2g(v), C.gint(f.Numer), C.gint(f.Denom))
	return v
}