gstreamer/gstreamer-sharp/Controller.custom
Sebastian Dröge f8bfb404f5 Extend Gst.Controller bindings
Add methods to set the object of a controller, to get a controller
instance from an object, to get/set control sources on an object
and to sync the properties of an object to a timestamp.
2010-02-13 09:38:10 +01:00

233 lines
7.3 KiB
Text

[DllImport ("libgstcontroller-0.10.dll") ]
static extern IntPtr gst_controller_new_list (IntPtr objekt, IntPtr list);
public Controller (Gst.GLib.Object objekt, string[] properties) : base (IntPtr.Zero) {
if (GetType () != typeof (Controller)) {
throw new InvalidOperationException ("Can't override this constructor.");
}
Gst.GLib.List list = new Gst.GLib.List (properties, typeof (string), true, true);
Raw = gst_controller_new_list (objekt == null ? IntPtr.Zero : objekt.Handle, list == null ? IntPtr.Zero : list.Handle);
}
public Controller (Gst.GLib.Object objekt, string property) : this (objekt, new string[] {property}) { }
[DllImport ("libgstcontroller-0.10.dll") ]
static extern bool gst_controller_remove_properties_list (IntPtr raw, IntPtr list);
public bool RemoveProperties (string[] properties) {
Gst.GLib.List list = new Gst.GLib.List (properties, typeof (string), true, true);
bool raw_ret = gst_controller_remove_properties_list (Handle, list == null ? IntPtr.Zero : list.Handle);
bool ret = raw_ret;
return ret;
}
public bool RemoveProperty (string property) {
return RemoveProperties (new string[] {property});
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gst__controllersharp_gst__controller_controller_get_properties_offset ();
static uint properties_offset = gst__controllersharp_gst__controller_controller_get_properties_offset ();
public string[] Properties {
get {
Gst.GLib.List properties_list;
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + properties_offset);
properties_list = new Gst.GLib.List ( (*raw_ptr), typeof (string));
}
string[] properties = new string[properties_list.Count];
for (int i = 0; i < properties_list.Count; i++)
properties[i] = (string) properties_list[i];
return properties;
}
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gst__controllersharp_gst__controller_controller_get_object_offset ();
[DllImport ("libgstcontroller-0.10.dll") ]
static extern bool gst_object_set_controller (IntPtr raw, IntPtr contr);
static uint object_offset = gst__controllersharp_gst__controller_controller_get_object_offset ();
public Gst.GLib.Object Object {
get {
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + object_offset);
return Gst.GLib.Object.GetObject ( (*raw_ptr));
}
}
set {
bool ret = gst_object_set_controller (value.Handle, this.Handle);
if (!ret)
throw new ApplicationException ();
}
}
[StructLayout (LayoutKind.Sequential) ]
struct GstValueArray {
public IntPtr property_name;
public int nbsamples;
public ulong sample_interval;
public IntPtr values;
}
[DllImport ("libgstcontroller-0.10.dll") ]
static extern bool gst_controller_get_value_array (IntPtr raw, ulong timestamp, ref GstValueArray value_array);
[DllImport ("libglib-2.0-0.dll") ]
static extern IntPtr g_try_malloc (int size);
static readonly Type[] supported_types = new Type[] {
typeof (string),
typeof (short),
typeof (ushort),
typeof (int),
typeof (uint),
typeof (long),
typeof (ulong),
typeof (float),
typeof (double),
typeof (bool)
};
public System.Array GetValueArray (string property, ulong timestamp, int nsamples, ulong interval) {
GstValueArray va = new GstValueArray ();
Gst.Object ob = (Gst.Object) this.Object;
Gst.PropertyInfo pi = ob.GetPropertyInfo (property);
System.Type t = (System.Type) pi.GType;
bool supported = false;
foreach (System.Type tmp in supported_types)
if (tmp == t)
supported = true;
if (!supported)
throw new Exception ("Unsupported type '" + t + "'");
int eltsize = Marshal.SizeOf (t);
va.values = g_try_malloc (eltsize * nsamples);
if (va.values == IntPtr.Zero)
throw new OutOfMemoryException ();
va.property_name = Gst.GLib.Marshaller.StringToPtrGStrdup (property);
va.nbsamples = nsamples;
va.sample_interval = interval;
bool raw_ret = gst_controller_get_value_array (Handle, timestamp, ref va);
if (!raw_ret) {
Gst.GLib.Marshaller.Free (va.property_name);
Gst.GLib.Marshaller.Free (va.values);
return null;
}
System.Array values = Array.CreateInstance (t, nsamples);
if (t == typeof (string)) {
string[] ret = (string[]) values;
for (int i = 0; i < nsamples; i++) {
IntPtr str = Marshal.ReadIntPtr (va.values, i * IntPtr.Size);
ret[i] = Gst.GLib.Marshaller.PtrToStringGFree (str);
}
} else if (t == typeof (short)) {
short[] ret = (short[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = Marshal.ReadInt16 (va.values, i * 2);
}
} else if (t == typeof (ushort)) {
ushort[] ret = (ushort[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = (ushort) Marshal.ReadInt16 (va.values, i * 2);
}
} else if (t == typeof (int)) {
int[] ret = (int[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = Marshal.ReadInt32 (va.values, i * 4);
}
} else if (t == typeof (uint)) {
uint[] ret = (uint[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = (uint) Marshal.ReadInt32 (va.values, i * 4);
}
} else if (t == typeof (long)) {
long[] ret = (long[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = Marshal.ReadInt64 (va.values, i * 8);
}
} else if (t == typeof (ulong)) {
ulong[] ret = (ulong[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = (ulong) Marshal.ReadInt64 (va.values, i * 8);
}
} else if (t == typeof (float)) {
float[] ret = (float[]) values;
Marshal.Copy (va.values, ret, 0, nsamples);
} else if (t == typeof (double)) {
double[] ret = (double[]) values;
Marshal.Copy (va.values, ret, 0, nsamples);
} else if (t == typeof (bool)) {
bool[] ret = (bool[]) values;
for (int i = 0; i < nsamples; i++) {
ret[i] = Marshal.ReadInt32 (va.values, i * 4) != 0;
}
}
Gst.GLib.Marshaller.Free (va.property_name);
Gst.GLib.Marshaller.Free (va.values);
return values;
}
[DllImport ("libgstcontroller-0.10.dll") ]
static extern IntPtr gst_object_get_controller (IntPtr raw);
static Controller GetController (Gst.Object obj) {
IntPtr raw_ret = gst_object_get_controller (obj.Handle);
return Gst.GLib.Object.GetObject (raw_ret, true) as Controller;
}
[DllImport ("libgstcontroller-0.10.dll") ]
static extern IntPtr gst_object_get_control_source (IntPtr raw, IntPtr property);
public static ControlSource GetControlSource (Gst.Object obj, string property) {
IntPtr raw_property = Gst.GLib.Marshaller.StringToPtrGStrdup (property);
IntPtr raw_ret = gst_object_get_control_source (obj.Handle, raw_property);
Gst.GLib.Marshaller.Free (raw_property);
return Gst.GLib.Object.GetObject (raw_ret, true) as ControlSource;
}
[DllImport ("libgstcontroller-0.10.dll") ]
static extern bool gst_object_set_control_source (IntPtr raw, IntPtr property, IntPtr csrc);
public static bool SetControlSource (Gst.Object obj, string property, ControlSource csrc) {
IntPtr raw_property = Gst.GLib.Marshaller.StringToPtrGStrdup (property);
bool ret = gst_object_set_control_source (obj.Handle, raw_property, csrc.Handle);
Gst.GLib.Marshaller.Free (raw_property);
return ret;
}
[DllImport ("libgstcontroller-0.10.dll") ]
static extern bool gst_object_sync_values (IntPtr raw, ulong timestamp);
public static bool SyncValue (Gst.Object obj, ulong timestamp) {
return gst_object_sync_values (obj.Handle, timestamp);
}