mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-21 07:46:38 +00:00
aa7bb8fa1c
glib-sharp will only get a new release with the new API that we need for 3.0 in a year or something. Instead of waiting a year before we can release something we now have our own internal copy of glib-sharp trunk that will be dropped once glib-sharp 3.0 is released. Everything is now compilable and working without any additional patches.
187 lines
5.7 KiB
Text
187 lines
5.7 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 ();
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
|
|
[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;
|
|
}
|
|
|