gstreamer-sharp: apply new code style to alll sources

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/983>
This commit is contained in:
Andoni Morales Alastruey 2021-09-30 13:02:26 +02:00 committed by GStreamer Marge Bot
parent f89dff303a
commit 6ddb443743
27 changed files with 676 additions and 780 deletions

View file

@ -15,23 +15,22 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA // 02110-1301 USA
namespace Gst.Base { namespace Gst.Base {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class Adapter public partial class Adapter {
{
[DllImport("gstbase-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstbase-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_adapter_copy(IntPtr raw, out IntPtr dest, int offset, int size); static extern void gst_adapter_copy(IntPtr raw, out IntPtr dest, int offset, int size);
public byte[] Copy(int offset, int size) { public byte[] Copy(int offset, int size) {
IntPtr mem = Marshal.AllocHGlobal (size); IntPtr mem = Marshal.AllocHGlobal(size);
gst_adapter_copy(Handle, out mem, offset, size); gst_adapter_copy(Handle, out mem, offset, size);
byte[] bytes = new byte[size]; byte[] bytes = new byte[size];
Marshal.Copy (mem, bytes, 0, size); Marshal.Copy(mem, bytes, 0, size);
return bytes; return bytes;
} }
@ -42,9 +41,9 @@ namespace Gst.Base {
public byte[] Map() { public byte[] Map() {
int size; int size;
IntPtr mem = gst_adapter_map (Handle, out size); IntPtr mem = gst_adapter_map(Handle, out size);
byte[] ret = new byte[size]; byte[] ret = new byte[size];
Marshal.Copy (mem, ret , 0, size); Marshal.Copy(mem, ret, 0, size);
return ret; return ret;
} }

View file

@ -25,9 +25,8 @@ namespace Gst.App {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class AppSink partial class AppSink {
{ public AppSink(String name) : base(IntPtr.Zero) {
public AppSink (String name) : base(IntPtr.Zero) {
Raw = ElementFactory.MakeRaw("appsink", name); Raw = ElementFactory.MakeRaw("appsink", name);
} }
} }

View file

@ -25,10 +25,9 @@ namespace Gst.App {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class AppSrc partial class AppSrc {
{ public AppSrc(String name) : base(IntPtr.Zero) {
public AppSrc (String name) : base(IntPtr.Zero) { Raw = ElementFactory.MakeRaw("appsrc", name);
Raw = ElementFactory.MakeRaw ("appsrc", name);
} }
} }
} }

View file

@ -19,19 +19,18 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Application partial class Application {
{
// Because of: https://bugzilla.gnome.org/show_bug.cgi?id=743062#c30 // Because of: https://bugzilla.gnome.org/show_bug.cgi?id=743062#c30
private static uint MIN_GSTREAMER_MINOR = 14; private static uint MIN_GSTREAMER_MINOR = 14;
static Application () { static Application() {
GLib.GType.Register (List.GType, typeof(List)); GLib.GType.Register(List.GType, typeof(List));
GLib.GType.Register (Fraction.GType, typeof(Fraction)); GLib.GType.Register(Fraction.GType, typeof(Fraction));
GLib.GType.Register (DoubleRange.GType, typeof(DoubleRange)); GLib.GType.Register(DoubleRange.GType, typeof(DoubleRange));
GLib.GType.Register (IntRange.GType, typeof(IntRange)); GLib.GType.Register(IntRange.GType, typeof(IntRange));
GLib.GType.Register (FractionRange.GType, typeof(FractionRange)); GLib.GType.Register(FractionRange.GType, typeof(FractionRange));
GLib.GType.Register (DateTime.GType, typeof(DateTime)); GLib.GType.Register(DateTime.GType, typeof(DateTime));
GLib.GType.Register (Gst.Array.GType, typeof(Gst.Array)); GLib.GType.Register(Gst.Array.GType, typeof(Gst.Array));
GLib.GType.Register(Promise.GType, typeof(Promise)); GLib.GType.Register(Promise.GType, typeof(Promise));
GLib.GType.Register(Gst.WebRTC.WebRTCSessionDescription.GType, typeof(Gst.WebRTC.WebRTCSessionDescription)); GLib.GType.Register(Gst.WebRTC.WebRTCSessionDescription.GType, typeof(Gst.WebRTC.WebRTCSessionDescription));
} }
@ -49,7 +48,7 @@ namespace Gst {
} }
public static void Init() { public static void Init() {
gst_init (IntPtr.Zero, IntPtr.Zero); gst_init(IntPtr.Zero, IntPtr.Zero);
CheckVersion(); CheckVersion();
} }
@ -57,11 +56,11 @@ namespace Gst {
int cnt_argv = argv == null ? 0 : argv.Length; int cnt_argv = argv == null ? 0 : argv.Length;
System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>(); System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
for (int i = 0; i < cnt_argv; i++) for (int i = 0; i < cnt_argv; i++)
native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i])); native_arg_list.Add(GLib.Marshaller.StringToPtrGStrdup(argv[i]));
IntPtr[] native_argv = native_arg_list.ToArray(); IntPtr[] native_argv = native_arg_list.ToArray();
gst_init(ref cnt_argv, ref native_argv); gst_init(ref cnt_argv, ref native_argv);
foreach (var native_arg in native_arg_list) foreach (var native_arg in native_arg_list)
GLib.Marshaller.Free (native_arg); GLib.Marshaller.Free(native_arg);
CheckVersion(); CheckVersion();
} }
@ -74,10 +73,10 @@ namespace Gst {
public static bool InitCheck() { public static bool InitCheck() {
IntPtr error = IntPtr.Zero; IntPtr error = IntPtr.Zero;
bool ret = gst_init_check (IntPtr.Zero, IntPtr.Zero, out error); bool ret = gst_init_check(IntPtr.Zero, IntPtr.Zero, out error);
CheckVersion(); CheckVersion();
if (error != IntPtr.Zero) throw new GLib.GException (error); if (error != IntPtr.Zero) throw new GLib.GException(error);
return ret; return ret;
} }
@ -85,13 +84,13 @@ namespace Gst {
int cnt_argv = argv == null ? 0 : argv.Length; int cnt_argv = argv == null ? 0 : argv.Length;
System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>(); System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
for (int i = 0; i < cnt_argv; i++) for (int i = 0; i < cnt_argv; i++)
native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i])); native_arg_list.Add(GLib.Marshaller.StringToPtrGStrdup(argv[i]));
IntPtr[] native_argv = native_arg_list.ToArray(); IntPtr[] native_argv = native_arg_list.ToArray();
IntPtr error = IntPtr.Zero; IntPtr error = IntPtr.Zero;
bool ret = gst_init_check(ref cnt_argv, ref native_argv, out error); bool ret = gst_init_check(ref cnt_argv, ref native_argv, out error);
foreach (var native_arg in native_arg_list) foreach (var native_arg in native_arg_list)
GLib.Marshaller.Free (native_arg); GLib.Marshaller.Free(native_arg);
if (error != IntPtr.Zero) throw new GLib.GException (error); if (error != IntPtr.Zero) throw new GLib.GException(error);
CheckVersion(); CheckVersion();
return ret; return ret;

View file

@ -25,13 +25,12 @@ namespace Gst.Audio {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class AudioFilter partial class AudioFilter {
{
[DllImport("gstaudio-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstaudio-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_audio_filter_class_add_pad_templates(IntPtr klass, IntPtr allowed_caps); static extern void gst_audio_filter_class_add_pad_templates(IntPtr klass, IntPtr allowed_caps);
public void AddPadTemplates(Gst.Caps allowed_caps) { public void AddPadTemplates(Gst.Caps allowed_caps) {
gst_audio_filter_class_add_pad_templates(LookupGType().GetClassPtr (), allowed_caps == null ? IntPtr.Zero : allowed_caps.Handle); gst_audio_filter_class_add_pad_templates(LookupGType().GetClassPtr(), allowed_caps == null ? IntPtr.Zero : allowed_caps.Handle);
} }
} }
} }

View file

@ -21,17 +21,17 @@ namespace Gst {
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Bin { partial class Bin {
public Bin () : this (null) {} public Bin() : this(null) { }
public void Add (params Element [] elements) { public void Add(params Element[] elements) {
foreach (var elem in elements) { foreach (var elem in elements) {
Add (elem); Add(elem);
} }
} }
public void Remove (params Element [] elements) { public void Remove(params Element[] elements) {
foreach (var elem in elements) { foreach (var elem in elements) {
Remove (elem); Remove(elem);
} }
} }
} }

View file

@ -25,8 +25,8 @@ namespace Gst {
static extern UIntPtr gst_buffer_extract(IntPtr raw, UIntPtr offset, byte[] dest, UIntPtr size); static extern UIntPtr gst_buffer_extract(IntPtr raw, UIntPtr offset, byte[] dest, UIntPtr size);
public ulong Extract(ulong offset, ref byte[] dest) { public ulong Extract(ulong offset, ref byte[] dest) {
UIntPtr raw_ret = gst_buffer_extract(Handle, new UIntPtr (offset), dest, new UIntPtr ((ulong)dest.Length)); UIntPtr raw_ret = gst_buffer_extract(Handle, new UIntPtr(offset), dest, new UIntPtr((ulong)dest.Length));
ulong ret = (ulong) raw_ret; ulong ret = (ulong)raw_ret;
return ret; return ret;
} }
@ -36,25 +36,24 @@ namespace Gst {
public ulong ExtractDup(ulong offset, ulong size, out byte[] dest) { public ulong ExtractDup(ulong offset, ulong size, out byte[] dest) {
UIntPtr native_dest_size; UIntPtr native_dest_size;
IntPtr ptr; IntPtr ptr;
gst_buffer_extract_dup(Handle, new UIntPtr (offset), new UIntPtr (size), out ptr, out native_dest_size); gst_buffer_extract_dup(Handle, new UIntPtr(offset), new UIntPtr(size), out ptr, out native_dest_size);
byte[] bytes = new byte[(ulong)native_dest_size]; byte[] bytes = new byte[(ulong)native_dest_size];
Marshal.Copy (ptr, bytes, 0, (int)native_dest_size); Marshal.Copy(ptr, bytes, 0, (int)native_dest_size);
dest = bytes; dest = bytes;
GLib.Marshaller.Free (ptr); GLib.Marshaller.Free(ptr);
return (ulong) native_dest_size; return (ulong)native_dest_size;
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gst_buffer_new_wrapped(IntPtr data, UIntPtr n_length); static extern IntPtr gst_buffer_new_wrapped(IntPtr data, UIntPtr n_length);
public Buffer (byte[] data) public Buffer(byte[] data) {
{ IntPtr ptr = GLib.Marshaller.Malloc((ulong)data.Length);
IntPtr ptr = GLib.Marshaller.Malloc((ulong) data.Length);
Marshal.Copy(data, 0, ptr, data.Length); Marshal.Copy(data, 0, ptr, data.Length);
Raw = gst_buffer_new_wrapped(ptr, new UIntPtr((ulong) data.Length)); Raw = gst_buffer_new_wrapped(ptr, new UIntPtr((ulong)data.Length));
} }
} }
} }

View file

@ -17,15 +17,12 @@
using System; using System;
namespace Gst namespace Gst {
{ partial class Bus {
partial class Bus public uint AddWatch(Gst.BusFunc func) {
{
public uint AddWatch (Gst.BusFunc func) {
// https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS // https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html#G-PRIORITY-DEFAULT:CAPS
int G_PRIORITY_DEFAULT = 0; int G_PRIORITY_DEFAULT = 0;
return AddWatchFull (G_PRIORITY_DEFAULT, func); return AddWatchFull(G_PRIORITY_DEFAULT, func);
} }
} }
} }

View file

@ -26,14 +26,13 @@ namespace Gst {
using System.Collections; using System.Collections;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Caps : IEnumerable partial class Caps : IEnumerable {
{ public Structure this[uint index] {
public Structure this [uint index] {
get { get {
if (index >= Size) if (index >= Size)
throw new ArgumentOutOfRangeException (); throw new ArgumentOutOfRangeException();
Structure structure = GetStructure ((uint) index); Structure structure = GetStructure((uint)index);
return structure; return structure;
} }
} }
@ -42,7 +41,7 @@ namespace Gst {
Gst.Caps caps; Gst.Caps caps;
long index; long index;
public StructureEnumerator (Gst.Caps caps) { public StructureEnumerator(Gst.Caps caps) {
this.caps = caps; this.caps = caps;
index = -1; index = -1;
} }
@ -50,26 +49,26 @@ namespace Gst {
public object Current { public object Current {
get { get {
if (index >= caps.Size) if (index >= caps.Size)
throw new ArgumentOutOfRangeException (); throw new ArgumentOutOfRangeException();
if (index == -1) if (index == -1)
throw new ArgumentException (); throw new ArgumentException();
return caps[ (uint) index]; return caps[(uint)index];
} }
} }
public bool MoveNext () { public bool MoveNext() {
index += 1; index += 1;
return (index < caps.Size); return (index < caps.Size);
} }
public void Reset () { public void Reset() {
index = -1; index = -1;
} }
} }
public IEnumerator GetEnumerator() { public IEnumerator GetEnumerator() {
return new StructureEnumerator (this); return new StructureEnumerator(this);
} }
} }
} }

View file

@ -25,61 +25,60 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class DeviceProvider partial class DeviceProvider {
{
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_device_provider_class_add_metadata(IntPtr klass, IntPtr key, IntPtr value); static extern void gst_device_provider_class_add_metadata(IntPtr klass, IntPtr key, IntPtr value);
public void AddMetadata(string key, string value) { public void AddMetadata(string key, string value) {
IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (key); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup(key);
IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup(value);
gst_device_provider_class_add_metadata(LookupGType().GetClassPtr (), native_key, native_value); gst_device_provider_class_add_metadata(LookupGType().GetClassPtr(), native_key, native_value);
GLib.Marshaller.Free (native_key); GLib.Marshaller.Free(native_key);
GLib.Marshaller.Free (native_value); GLib.Marshaller.Free(native_value);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_device_provider_class_add_static_metadata(IntPtr klass, IntPtr key, IntPtr value); static extern void gst_device_provider_class_add_static_metadata(IntPtr klass, IntPtr key, IntPtr value);
public void AddStaticMetadata(string key, string value) { public void AddStaticMetadata(string key, string value) {
IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (key); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup(key);
IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup(value);
gst_device_provider_class_add_static_metadata(LookupGType().GetClassPtr (), native_key, native_value); gst_device_provider_class_add_static_metadata(LookupGType().GetClassPtr(), native_key, native_value);
GLib.Marshaller.Free (native_key); GLib.Marshaller.Free(native_key);
GLib.Marshaller.Free (native_value); GLib.Marshaller.Free(native_value);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_device_provider_class_set_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author); static extern void gst_device_provider_class_set_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author);
public void SetMetadata(string longname, string classification, string description, string author) { public void SetMetadata(string longname, string classification, string description, string author) {
IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup (longname); IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup(longname);
IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup (classification); IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup(classification);
IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup (description); IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup(description);
IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup (author); IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup(author);
gst_device_provider_class_set_metadata(LookupGType().GetClassPtr (), native_longname, native_classification, native_description, native_author); gst_device_provider_class_set_metadata(LookupGType().GetClassPtr(), native_longname, native_classification, native_description, native_author);
GLib.Marshaller.Free (native_longname); GLib.Marshaller.Free(native_longname);
GLib.Marshaller.Free (native_classification); GLib.Marshaller.Free(native_classification);
GLib.Marshaller.Free (native_description); GLib.Marshaller.Free(native_description);
GLib.Marshaller.Free (native_author); GLib.Marshaller.Free(native_author);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_device_provider_class_set_static_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author); static extern void gst_device_provider_class_set_static_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author);
public void SetStaticMetadata(string longname, string classification, string description, string author) { public void SetStaticMetadata(string longname, string classification, string description, string author) {
IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup (longname); IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup(longname);
IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup (classification); IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup(classification);
IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup (description); IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup(description);
IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup (author); IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup(author);
gst_device_provider_class_set_static_metadata(LookupGType().GetClassPtr (), native_longname, native_classification, native_description, native_author); gst_device_provider_class_set_static_metadata(LookupGType().GetClassPtr(), native_longname, native_classification, native_description, native_author);
GLib.Marshaller.Free (native_longname); GLib.Marshaller.Free(native_longname);
GLib.Marshaller.Free (native_classification); GLib.Marshaller.Free(native_classification);
GLib.Marshaller.Free (native_description); GLib.Marshaller.Free(native_description);
GLib.Marshaller.Free (native_author); GLib.Marshaller.Free(native_author);
} }

View file

@ -25,52 +25,45 @@
using GLib; using GLib;
using System; using System;
using System.Collections;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Collections;
namespace Gst namespace Gst {
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void GClosureMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr, delegate void GClosureMarshal(IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
IntPtr invocation_hint, IntPtr data); IntPtr invocation_hint, IntPtr data);
public delegate void SignalHandler (object o, SignalArgs args); public delegate void SignalHandler(object o, SignalArgs args);
public static class DynamicSignal public static class DynamicSignal {
{
private static readonly int gvalue_struct_size = Marshal.SizeOf (typeof(GLib.Value)); private static readonly int gvalue_struct_size = Marshal.SizeOf(typeof(GLib.Value));
class ObjectSignalKey class ObjectSignalKey {
{
object o; object o;
string signal_name; string signal_name;
public ObjectSignalKey (object o, string name) public ObjectSignalKey(object o, string name) {
{
this.o = o; this.o = o;
signal_name = name; signal_name = name;
} }
public override bool Equals (object o) public override bool Equals(object o) {
{
if (o is ObjectSignalKey) { if (o is ObjectSignalKey) {
ObjectSignalKey k = (ObjectSignalKey)o; ObjectSignalKey k = (ObjectSignalKey)o;
return k.o.Equals (this.o) && signal_name.Equals (k.signal_name); return k.o.Equals(this.o) && signal_name.Equals(k.signal_name);
} }
return base.Equals (o); return base.Equals(o);
} }
public override int GetHashCode () public override int GetHashCode() {
{ return o.GetHashCode() ^ signal_name.GetHashCode();
return o.GetHashCode () ^ signal_name.GetHashCode ();
} }
} }
class SignalInfo : IDisposable class SignalInfo : IDisposable {
{
uint handlerId; uint handlerId;
IntPtr closure; IntPtr closure;
Delegate registeredHandler; Delegate registeredHandler;
@ -113,175 +106,166 @@ namespace Gst
} }
} }
public SignalInfo (uint handlerId, IntPtr closure, Delegate registeredHandler, GCHandle gch) public SignalInfo(uint handlerId, IntPtr closure, Delegate registeredHandler, GCHandle gch) {
{
this.handlerId = handlerId; this.handlerId = handlerId;
this.closure = closure; this.closure = closure;
this.registeredHandler = registeredHandler; this.registeredHandler = registeredHandler;
this.gch = gch; this.gch = gch;
if (!IsValidDelegate (registeredHandler)) if (!IsValidDelegate(registeredHandler))
throw new Exception ("Invalid delegate"); throw new Exception("Invalid delegate");
MethodInfo mi = registeredHandler.Method; MethodInfo mi = registeredHandler.Method;
ParameterInfo[] parms = mi.GetParameters (); ParameterInfo[] parms = mi.GetParameters();
this.argsType = parms [1].ParameterType; this.argsType = parms[1].ParameterType;
} }
public void UpdateArgsType (Delegate d) public void UpdateArgsType(Delegate d) {
{ if (!IsCompatibleDelegate(d))
if (!IsCompatibleDelegate (d)) throw new Exception("Incompatible delegate");
throw new Exception ("Incompatible delegate");
MethodInfo mi = d.Method; MethodInfo mi = d.Method;
ParameterInfo[] parms = mi.GetParameters (); ParameterInfo[] parms = mi.GetParameters();
Type t1 = parms [1].ParameterType; Type t1 = parms[1].ParameterType;
Type t2 = argsType; Type t2 = argsType;
if (t1 == t2) if (t1 == t2)
return; return;
if (t1.IsSubclassOf (t2)) if (t1.IsSubclassOf(t2))
argsType = t1; argsType = t1;
else if (t2.IsSubclassOf (t1)) else if (t2.IsSubclassOf(t1))
argsType = t2; argsType = t2;
else else
throw new Exception ("Incompatible delegate"); throw new Exception("Incompatible delegate");
} }
public bool IsCompatibleDelegate (Delegate d) public bool IsCompatibleDelegate(Delegate d) {
{ if (!IsValidDelegate(d))
if (!IsValidDelegate (d))
return false; return false;
MethodInfo mi = d.Method; MethodInfo mi = d.Method;
ParameterInfo[] parms = mi.GetParameters (); ParameterInfo[] parms = mi.GetParameters();
if (parms [1].ParameterType != this.argsType && if (parms[1].ParameterType != this.argsType &&
!parms [1].ParameterType.IsSubclassOf (this.argsType) && !parms[1].ParameterType.IsSubclassOf(this.argsType) &&
!this.argsType.IsSubclassOf (parms [1].ParameterType)) !this.argsType.IsSubclassOf(parms[1].ParameterType))
return false; return false;
return true; return true;
} }
public void Dispose () public void Dispose() {
{
registeredHandler = null; registeredHandler = null;
gch.Free (); gch.Free();
GC.SuppressFinalize (this); GC.SuppressFinalize(this);
} }
public static bool IsValidDelegate (Delegate d) public static bool IsValidDelegate(Delegate d) {
{
MethodInfo mi = d.Method; MethodInfo mi = d.Method;
if (mi.ReturnType != typeof(void)) if (mi.ReturnType != typeof(void))
return false; return false;
ParameterInfo[] parms = mi.GetParameters (); ParameterInfo[] parms = mi.GetParameters();
if (parms.Length != 2) if (parms.Length != 2)
return false; return false;
if (parms [1].ParameterType != typeof(GLib.SignalArgs) && if (parms[1].ParameterType != typeof(GLib.SignalArgs) &&
!parms [1].ParameterType.IsSubclassOf (typeof(GLib.SignalArgs))) !parms[1].ParameterType.IsSubclassOf(typeof(GLib.SignalArgs)))
return false; return false;
return true; return true;
} }
} }
static Hashtable SignalHandlers = new Hashtable (); static Hashtable SignalHandlers = new Hashtable();
static GClosureMarshal marshalHandler = new GClosureMarshal (OnMarshal); static GClosureMarshal marshalHandler = new GClosureMarshal(OnMarshal);
public static void Connect (GLib.Object o, string name, SignalHandler handler) public static void Connect(GLib.Object o, string name, SignalHandler handler) {
{ Connect(o, name, false, (Delegate)handler);
Connect (o, name, false, (Delegate)handler);
} }
public static void Connect (GLib.Object o, string name, public static void Connect(GLib.Object o, string name,
bool after, SignalHandler handler) bool after, SignalHandler handler) {
{ Connect(o, name, after, (Delegate)handler);
Connect (o, name, after, (Delegate)handler);
} }
public static void Connect (GLib.Object o, string name, Delegate handler) public static void Connect(GLib.Object o, string name, Delegate handler) {
{ Connect(o, name, false, handler);
Connect (o, name, false, handler);
} }
public static void Connect (GLib.Object o, string name, public static void Connect(GLib.Object o, string name,
bool after, Delegate handler) bool after, Delegate handler) {
{
Delegate newHandler; Delegate newHandler;
ObjectSignalKey k = new ObjectSignalKey (o, name); ObjectSignalKey k = new ObjectSignalKey(o, name);
if (!SignalInfo.IsValidDelegate (handler)) if (!SignalInfo.IsValidDelegate(handler))
throw new Exception ("Invalid delegate"); throw new Exception("Invalid delegate");
if (SignalHandlers [k] != null) { if (SignalHandlers[k] != null) {
SignalInfo si = (SignalInfo)SignalHandlers [k]; SignalInfo si = (SignalInfo)SignalHandlers[k];
if (!si.IsCompatibleDelegate (handler)) if (!si.IsCompatibleDelegate(handler))
throw new Exception ("Incompatible delegate"); throw new Exception("Incompatible delegate");
newHandler = Delegate.Combine (si.RegisteredHandler, handler); newHandler = Delegate.Combine(si.RegisteredHandler, handler);
si.UpdateArgsType (handler); si.UpdateArgsType(handler);
si.RegisteredHandler = newHandler; si.RegisteredHandler = newHandler;
} else { }
if (!SignalInfo.IsValidDelegate (handler)) else {
throw new Exception ("Invalid delegate"); if (!SignalInfo.IsValidDelegate(handler))
throw new Exception("Invalid delegate");
// Let's allocate 64bytes for the GClosure, it should be more than necessary. // Let's allocate 64bytes for the GClosure, it should be more than necessary.
IntPtr closure = g_closure_new_simple (64, IntPtr.Zero); IntPtr closure = g_closure_new_simple(64, IntPtr.Zero);
GCHandle gch = GCHandle.Alloc (k); GCHandle gch = GCHandle.Alloc(k);
g_closure_set_meta_marshal (closure, (IntPtr)gch, marshalHandler); g_closure_set_meta_marshal(closure, (IntPtr)gch, marshalHandler);
uint signalId = g_signal_connect_closure (o.Handle, name, closure, after); uint signalId = g_signal_connect_closure(o.Handle, name, closure, after);
SignalHandlers.Add (k, new SignalInfo (signalId, closure, handler, gch)); SignalHandlers.Add(k, new SignalInfo(signalId, closure, handler, gch));
} }
} }
public static void Disconnect (GLib.Object o, string name, Delegate handler) public static void Disconnect(GLib.Object o, string name, Delegate handler) {
{ ObjectSignalKey k = new ObjectSignalKey(o, name);
ObjectSignalKey k = new ObjectSignalKey (o, name); if (SignalHandlers[k] != null) {
if (SignalHandlers [k] != null) { SignalInfo si = (SignalInfo)SignalHandlers[k];
SignalInfo si = (SignalInfo)SignalHandlers [k]; Delegate newHandler = Delegate.Remove(si.RegisteredHandler, handler);
Delegate newHandler = Delegate.Remove (si.RegisteredHandler, handler);
if (newHandler == null || handler == null) { if (newHandler == null || handler == null) {
g_signal_handler_disconnect (o.Handle, si.HandlerId); g_signal_handler_disconnect(o.Handle, si.HandlerId);
SignalHandlers.Remove (k); SignalHandlers.Remove(k);
si.Dispose (); si.Dispose();
} else { }
else {
si.RegisteredHandler = newHandler; si.RegisteredHandler = newHandler;
} }
} }
} }
static void OnMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr, static void OnMarshal(IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
IntPtr ihint, IntPtr data) IntPtr ihint, IntPtr data) {
{
object[] args = new object[argc - 1]; object[] args = new object[argc - 1];
object o = ((GLib.Value)Marshal.PtrToStructure (argsPtr, typeof(GLib.Value))).Val; object o = ((GLib.Value)Marshal.PtrToStructure(argsPtr, typeof(GLib.Value))).Val;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
IntPtr struct_ptr = (IntPtr)((long)argsPtr + (i * gvalue_struct_size)); IntPtr struct_ptr = (IntPtr)((long)argsPtr + (i * gvalue_struct_size));
GLib.Value argument = (GLib.Value)Marshal.PtrToStructure (struct_ptr, typeof(GLib.Value)); GLib.Value argument = (GLib.Value)Marshal.PtrToStructure(struct_ptr, typeof(GLib.Value));
args [i - 1] = argument.Val; args[i - 1] = argument.Val;
} }
if (data == IntPtr.Zero) { if (data == IntPtr.Zero) {
Console.Error.WriteLine ("No available data"); Console.Error.WriteLine("No available data");
return; return;
} }
ObjectSignalKey k = (ObjectSignalKey)((GCHandle)data).Target; ObjectSignalKey k = (ObjectSignalKey)((GCHandle)data).Target;
if (k != null) { if (k != null) {
SignalInfo si = (SignalInfo)SignalHandlers [k]; SignalInfo si = (SignalInfo)SignalHandlers[k];
GLib.SignalArgs arg = (GLib.SignalArgs)Activator.CreateInstance (si.ArgsType); GLib.SignalArgs arg = (GLib.SignalArgs)Activator.CreateInstance(si.ArgsType);
arg.Args = args; arg.Args = args;
si.RegisteredHandler.DynamicInvoke (new object[] { o, arg }); si.RegisteredHandler.DynamicInvoke(new object[] { o, arg });
if (arg.RetVal != null) { if (arg.RetVal != null) {
retval.Val = arg.RetVal; retval.Val = arg.RetVal;
} }
@ -289,44 +273,39 @@ namespace Gst
} }
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_closure_new_simple (int size, IntPtr data); static extern IntPtr g_closure_new_simple(int size, IntPtr data);
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint g_signal_connect_closure (IntPtr instance, static extern uint g_signal_connect_closure(IntPtr instance,
string name, IntPtr closure, bool after); string name, IntPtr closure, bool after);
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_closure_set_meta_marshal (IntPtr closure, IntPtr data, GClosureMarshal marshal); static extern void g_closure_set_meta_marshal(IntPtr closure, IntPtr data, GClosureMarshal marshal);
class GTypeSignalKey class GTypeSignalKey {
{
GType type; GType type;
string signal_name; string signal_name;
public GTypeSignalKey (GType type, string name) public GTypeSignalKey(GType type, string name) {
{
this.type = type; this.type = type;
signal_name = name; signal_name = name;
} }
public override bool Equals (object o) public override bool Equals(object o) {
{
if (o is GTypeSignalKey) { if (o is GTypeSignalKey) {
GTypeSignalKey k = (GTypeSignalKey)o; GTypeSignalKey k = (GTypeSignalKey)o;
return k.type.Equals (this.type) && signal_name.Equals (k.signal_name); return k.type.Equals(this.type) && signal_name.Equals(k.signal_name);
} }
return base.Equals (o); return base.Equals(o);
} }
public override int GetHashCode () public override int GetHashCode() {
{ return type.GetHashCode() ^ signal_name.GetHashCode();
return type.GetHashCode () ^ signal_name.GetHashCode ();
} }
} }
struct SignalQuery struct SignalQuery {
{
public uint signal_id; public uint signal_id;
public string signal_name; public string signal_name;
public GType itype; public GType itype;
@ -336,10 +315,9 @@ namespace Gst
public Type[] param_types; public Type[] param_types;
} }
static Hashtable SignalEmitInfo = new Hashtable (); static Hashtable SignalEmitInfo = new Hashtable();
public static object Emit (GLib.Object o, string name, params object[] parameters) public static object Emit(GLib.Object o, string name, params object[] parameters) {
{
SignalQuery query; SignalQuery query;
GType gtype = o.NativeType; GType gtype = o.NativeType;
IntPtr type = gtype.Val; IntPtr type = gtype.Val;
@ -347,106 +325,106 @@ namespace Gst
uint signal_detail_quark = 0; uint signal_detail_quark = 0;
int colon; int colon;
colon = name.LastIndexOf ("::"); colon = name.LastIndexOf("::");
if (colon == -1) { if (colon == -1) {
signal_name = name; signal_name = name;
signal_detail = String.Empty; signal_detail = String.Empty;
} else { }
signal_name = name.Substring (0, colon); else {
signal_detail = name.Substring (colon + 2); signal_name = name.Substring(0, colon);
signal_detail = name.Substring(colon + 2);
} }
GTypeSignalKey key = new GTypeSignalKey (gtype, signal_name); GTypeSignalKey key = new GTypeSignalKey(gtype, signal_name);
if (SignalEmitInfo [key] == null) { if (SignalEmitInfo[key] == null) {
IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup (signal_name); IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup(signal_name);
uint signal_id = g_signal_lookup (native_string, type); uint signal_id = g_signal_lookup(native_string, type);
GLib.Marshaller.Free (native_string); GLib.Marshaller.Free(native_string);
if (signal_id == 0) if (signal_id == 0)
throw new NotSupportedException (String.Format ("{0} has no signal of name {1}", o, name)); throw new NotSupportedException(String.Format("{0} has no signal of name {1}", o, name));
GSignalQuery q = new GSignalQuery (); GSignalQuery q = new GSignalQuery();
g_signal_query (signal_id, ref q); g_signal_query(signal_id, ref q);
if (q.signal_id == 0) if (q.signal_id == 0)
throw new NotSupportedException (String.Format ("{0} couldn't be queried for signal with name {1}", o, name)); throw new NotSupportedException(String.Format("{0} couldn't be queried for signal with name {1}", o, name));
query = new SignalQuery (); query = new SignalQuery();
query.signal_id = signal_id; query.signal_id = signal_id;
query.signal_name = GLib.Marshaller.Utf8PtrToString (q.signal_name); query.signal_name = GLib.Marshaller.Utf8PtrToString(q.signal_name);
query.itype = new GType (q.itype); query.itype = new GType(q.itype);
query.signal_flags = q.signal_flags; query.signal_flags = q.signal_flags;
query.return_type = new GType (q.return_type); query.return_type = new GType(q.return_type);
query.n_params = q.n_params; query.n_params = q.n_params;
query.param_types = new Type[q.n_params]; query.param_types = new Type[q.n_params];
for (int i = 0; i < query.n_params; i++) { for (int i = 0; i < query.n_params; i++) {
IntPtr t = Marshal.ReadIntPtr (q.param_types, i * IntPtr.Size); IntPtr t = Marshal.ReadIntPtr(q.param_types, i * IntPtr.Size);
GType g = new GType (t); GType g = new GType(t);
query.param_types [i] = (Type)g; query.param_types[i] = (Type)g;
} }
SignalEmitInfo.Add (key, query); SignalEmitInfo.Add(key, query);
} }
query = (SignalQuery)SignalEmitInfo [key]; query = (SignalQuery)SignalEmitInfo[key];
GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1]; GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
signal_parameters [0] = new GLib.Value (o); signal_parameters[0] = new GLib.Value(o);
if (parameters.Length != query.n_params) if (parameters.Length != query.n_params)
throw new ApplicationException (String.Format ("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length)); throw new ApplicationException(String.Format("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length));
for (int i = 0; i < query.n_params; i++) { for (int i = 0; i < query.n_params; i++) {
Type expected_type = (Type)query.param_types [i]; Type expected_type = (Type)query.param_types[i];
Type given_type = parameters [i].GetType (); Type given_type = parameters[i].GetType();
if (expected_type != given_type && !given_type.IsSubclassOf (given_type)) if (expected_type != given_type && !given_type.IsSubclassOf(given_type))
throw new ApplicationException (String.Format ("Invalid parameter type: expected {0}, got {1}", expected_type, given_type)); throw new ApplicationException(String.Format("Invalid parameter type: expected {0}, got {1}", expected_type, given_type));
signal_parameters [i + 1] = new GLib.Value (parameters [i]); signal_parameters[i + 1] = new GLib.Value(parameters[i]);
} }
GLib.Value return_value = new GLib.Value (); GLib.Value return_value = new GLib.Value();
if (query.return_type != GType.Invalid && query.return_type != GType.None) if (query.return_type != GType.Invalid && query.return_type != GType.None)
return_value.Init (query.return_type); return_value.Init(query.return_type);
if (signal_detail != String.Empty) { if (signal_detail != String.Empty) {
IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup (signal_detail); IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup(signal_detail);
signal_detail_quark = g_quark_from_string (native_string); signal_detail_quark = g_quark_from_string(native_string);
GLib.Marshaller.Free (native_string); GLib.Marshaller.Free(native_string);
} }
g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value); g_signal_emitv(signal_parameters, query.signal_id, signal_detail_quark, ref return_value);
foreach (GLib.Value v in signal_parameters) foreach (GLib.Value v in signal_parameters)
v.Dispose (); v.Dispose();
object ret = (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null; object ret = (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null;
if (ret != null) if (ret != null)
return_value.Dispose (); return_value.Dispose();
return ret; return ret;
} }
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int g_signal_handler_disconnect (IntPtr o, uint handler_id); static extern int g_signal_handler_disconnect(IntPtr o, uint handler_id);
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint g_signal_lookup (IntPtr name, IntPtr itype); static extern uint g_signal_lookup(IntPtr name, IntPtr itype);
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern uint g_quark_from_string (IntPtr str); static extern uint g_quark_from_string(IntPtr str);
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_signal_emitv (GLib.Value[] parameters, uint signal_id, uint detail, ref GLib.Value return_value); static extern void g_signal_emitv(GLib.Value[] parameters, uint signal_id, uint detail, ref GLib.Value return_value);
[StructLayout (LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct GSignalQuery struct GSignalQuery {
{
public uint signal_id; public uint signal_id;
public IntPtr signal_name; public IntPtr signal_name;
public IntPtr itype; public IntPtr itype;
@ -456,7 +434,7 @@ namespace Gst
public IntPtr param_types; public IntPtr param_types;
} }
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_signal_query (uint signal_id, ref GSignalQuery query); static extern void g_signal_query(uint signal_id, ref GSignalQuery query);
} }
} }

View file

@ -30,19 +30,18 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Element partial class Element {
{ public static bool Link(params Element[] elements) {
public static bool Link (params Element [] elements) {
for (int i = 0; i < elements.Length - 1; i++) { for (int i = 0; i < elements.Length - 1; i++) {
if (!elements[i].Link (elements[i+1])) if (!elements[i].Link(elements[i + 1]))
return false; return false;
} }
return true; return true;
} }
public static void Unlink (params Element [] elements) { public static void Unlink(params Element[] elements) {
for (int i = 0; i < elements.Length - 1; i++) { for (int i = 0; i < elements.Length - 1; i++) {
elements[i].Unlink (elements[i+1]); elements[i].Unlink(elements[i + 1]);
} }
} }
@ -50,59 +49,59 @@ namespace Gst {
static extern void gst_element_class_add_metadata(IntPtr klass, IntPtr key, IntPtr value); static extern void gst_element_class_add_metadata(IntPtr klass, IntPtr key, IntPtr value);
public void AddMetadata(string key, string value) { public void AddMetadata(string key, string value) {
IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (key); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup(key);
IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup(value);
gst_element_class_add_metadata(LookupGType().GetClassPtr (), native_key, native_value); gst_element_class_add_metadata(LookupGType().GetClassPtr(), native_key, native_value);
GLib.Marshaller.Free (native_key); GLib.Marshaller.Free(native_key);
GLib.Marshaller.Free (native_value); GLib.Marshaller.Free(native_value);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_element_class_add_pad_template(IntPtr klass, IntPtr templ); static extern void gst_element_class_add_pad_template(IntPtr klass, IntPtr templ);
public void AddPadTemplate(Gst.PadTemplate templ) { public void AddPadTemplate(Gst.PadTemplate templ) {
gst_element_class_add_pad_template(LookupGType().GetClassPtr (), templ == null ? IntPtr.Zero : templ.OwnedHandle); gst_element_class_add_pad_template(LookupGType().GetClassPtr(), templ == null ? IntPtr.Zero : templ.OwnedHandle);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_element_class_add_static_metadata(IntPtr klass, IntPtr key, IntPtr value); static extern void gst_element_class_add_static_metadata(IntPtr klass, IntPtr key, IntPtr value);
public void AddStaticMetadata(string key, string value) { public void AddStaticMetadata(string key, string value) {
IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (key); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup(key);
IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup(value);
gst_element_class_add_static_metadata(LookupGType().GetClassPtr (), native_key, native_value); gst_element_class_add_static_metadata(LookupGType().GetClassPtr(), native_key, native_value);
GLib.Marshaller.Free (native_key); GLib.Marshaller.Free(native_key);
GLib.Marshaller.Free (native_value); GLib.Marshaller.Free(native_value);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_element_class_set_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author); static extern void gst_element_class_set_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author);
public void SetMetadata(string longname, string classification, string description, string author) { public void SetMetadata(string longname, string classification, string description, string author) {
IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup (longname); IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup(longname);
IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup (classification); IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup(classification);
IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup (description); IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup(description);
IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup (author); IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup(author);
gst_element_class_set_metadata(LookupGType().GetClassPtr (), native_longname, native_classification, native_description, native_author); gst_element_class_set_metadata(LookupGType().GetClassPtr(), native_longname, native_classification, native_description, native_author);
GLib.Marshaller.Free (native_longname); GLib.Marshaller.Free(native_longname);
GLib.Marshaller.Free (native_classification); GLib.Marshaller.Free(native_classification);
GLib.Marshaller.Free (native_description); GLib.Marshaller.Free(native_description);
GLib.Marshaller.Free (native_author); GLib.Marshaller.Free(native_author);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_element_class_set_static_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author); static extern void gst_element_class_set_static_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author);
public void SetStaticMetadata(string longname, string classification, string description, string author) { public void SetStaticMetadata(string longname, string classification, string description, string author) {
IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup (longname); IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup(longname);
IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup (classification); IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup(classification);
IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup (description); IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup(description);
IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup (author); IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup(author);
gst_element_class_set_static_metadata(LookupGType().GetClassPtr (), native_longname, native_classification, native_description, native_author); gst_element_class_set_static_metadata(LookupGType().GetClassPtr(), native_longname, native_classification, native_description, native_author);
GLib.Marshaller.Free (native_longname); GLib.Marshaller.Free(native_longname);
GLib.Marshaller.Free (native_classification); GLib.Marshaller.Free(native_classification);
GLib.Marshaller.Free (native_description); GLib.Marshaller.Free(native_description);
GLib.Marshaller.Free (native_author); GLib.Marshaller.Free(native_author);
} }
} }

View file

@ -21,15 +21,12 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA // 02110-1301 USA
namespace Gst namespace Gst {
{
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class ElementFactory public partial class ElementFactory {
{ public static IntPtr MakeRaw(string factoryname, string name) {
public static IntPtr MakeRaw(string factoryname, string name)
{
IntPtr native_factoryname = GLib.Marshaller.StringToPtrGStrdup(factoryname); IntPtr native_factoryname = GLib.Marshaller.StringToPtrGStrdup(factoryname);
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);
IntPtr raw_ret = gst_element_factory_make(native_factoryname, native_name); IntPtr raw_ret = gst_element_factory_make(native_factoryname, native_name);

View file

@ -25,14 +25,14 @@ namespace Gst.FFT {
public partial class FFTF32 : GLib.Opaque { public partial class FFTF32 : GLib.Opaque {
[DllImport("gstfft-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstfft-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gst_fft_f32_new (int len, bool inverse); static extern IntPtr gst_fft_f32_new(int len, bool inverse);
public FFTF32 (int len, bool inverse) { public FFTF32(int len, bool inverse) {
Raw = gst_fft_f32_new (len, inverse); Raw = gst_fft_f32_new(len, inverse);
} }
[DllImport("gstfft-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstfft-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gst_fft_f32_fft(IntPtr raw, float[] timedata, [MarshalAs (UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct)] FFTF32Complex[] freqdata); static extern void gst_fft_f32_fft(IntPtr raw, float[] timedata, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct)] FFTF32Complex[] freqdata);
public void Fft(float[] timedata, Gst.FFT.FFTF32Complex[] freqdata) { public void Fft(float[] timedata, Gst.FFT.FFTF32Complex[] freqdata) {
gst_fft_f32_fft(Handle, timedata, freqdata); gst_fft_f32_fft(Handle, timedata, freqdata);
@ -42,7 +42,7 @@ namespace Gst.FFT {
static extern void gst_fft_f32_window(IntPtr raw, float[] timedata, int window); static extern void gst_fft_f32_window(IntPtr raw, float[] timedata, int window);
public void Window(float[] timedata, Gst.FFT.FFTWindow window) { public void Window(float[] timedata, Gst.FFT.FFTWindow window) {
gst_fft_f32_window(Handle, timedata, (int) window); gst_fft_f32_window(Handle, timedata, (int)window);
} }
} }
} }

View file

@ -16,25 +16,23 @@
// 02110-1301 USA // 02110-1301 USA
namespace Gst { namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Global partial class Global {
{ public static string TimeFormat(ulong time) {
public static string TimeFormat(ulong time) { return (time / (Gst.Constants.SECOND * 60 * 60)) + ":" +
return (time / (Gst.Constants.SECOND * 60 * 60)) + ":" + (time / (Gst.Constants.SECOND * 60)) % 60 + ":" +
(time / (Gst.Constants.SECOND * 60)) % 60 + ":" + (time / (Gst.Constants.SECOND)) % 60 + ":" +
(time / (Gst.Constants.SECOND)) % 60 + ":" + (time % 60);
(time % 60); }
}
public static string TimeFormat(long time) { public static string TimeFormat(long time) {
return (time / (Gst.Constants.SECOND * 60 * 60)) + ":" + return (time / (Gst.Constants.SECOND * 60 * 60)) + ":" +
(time / (Gst.Constants.SECOND * 60)) % 60 + ":" + (time / (Gst.Constants.SECOND * 60)) % 60 + ":" +
(time / (Gst.Constants.SECOND)) % 60 + ":" + (time / (Gst.Constants.SECOND)) % 60 + ":" +
(time % 60); (time % 60);
} }
} }
} }

View file

@ -25,29 +25,29 @@
namespace Gst { namespace Gst {
using GLib;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using GLib;
public partial class Iterator : IEnumerable { public partial class Iterator : IEnumerable {
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_value_reset (ref GLib.Value val); static extern IntPtr g_value_reset(ref GLib.Value val);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int gst_iterator_next(IntPtr raw, ref GLib.Value elem); static extern int gst_iterator_next(IntPtr raw, ref GLib.Value elem);
public Gst.IteratorResult Next(ref GLib.Value elem) { public Gst.IteratorResult Next(ref GLib.Value elem) {
int raw_ret = gst_iterator_next(Handle, ref elem); int raw_ret = gst_iterator_next(Handle, ref elem);
Gst.IteratorResult ret = (Gst.IteratorResult) raw_ret; Gst.IteratorResult ret = (Gst.IteratorResult)raw_ret;
return ret; return ret;
} }
private class Enumerator : IEnumerator { private class Enumerator : IEnumerator {
Iterator iterator; Iterator iterator;
Hashtable seen = new Hashtable (); Hashtable seen = new Hashtable();
private object current = null; private object current = null;
public object Current { public object Current {
@ -56,7 +56,7 @@ namespace Gst {
} }
} }
public bool MoveNext () { public bool MoveNext() {
IntPtr raw_ret; IntPtr raw_ret;
bool retry = false; bool retry = false;
@ -64,51 +64,51 @@ namespace Gst {
return false; return false;
do { do {
GLib.Value value = new GLib.Value (GLib.GType.Boolean); GLib.Value value = new GLib.Value(GLib.GType.Boolean);
value.Dispose (); value.Dispose();
IteratorResult ret = iterator.Next (ref value); IteratorResult ret = iterator.Next(ref value);
switch (ret) { switch (ret) {
case IteratorResult.Done: case IteratorResult.Done:
return false; return false;
case IteratorResult.Ok: case IteratorResult.Ok:
if (seen.Contains (value)) { if (seen.Contains(value)) {
retry = true;
break;
}
seen.Add(value, null);
current = value.Val;
return true;
case IteratorResult.Resync:
iterator.Resync();
retry = true; retry = true;
break; break;
}
seen.Add (value , null);
current = value.Val;
return true;
case IteratorResult.Resync:
iterator.Resync ();
retry = true;
break;
default: default:
case IteratorResult.Error: case IteratorResult.Error:
throw new Exception ("Error while iterating"); throw new Exception("Error while iterating");
} }
} while (retry); } while (retry);
return false; return false;
} }
public void Reset () { public void Reset() {
seen.Clear (); seen.Clear();
if (iterator.Handle != IntPtr.Zero) if (iterator.Handle != IntPtr.Zero)
iterator.Resync (); iterator.Resync();
} }
public Enumerator (Iterator iterator) { public Enumerator(Iterator iterator) {
this.iterator = iterator; this.iterator = iterator;
} }
} }
private Enumerator enumerator = null; private Enumerator enumerator = null;
public IEnumerator GetEnumerator () { public IEnumerator GetEnumerator() {
if (this.enumerator == null) if (this.enumerator == null)
this.enumerator = new Enumerator (this); this.enumerator = new Enumerator(this);
return this.enumerator; return this.enumerator;
} }
} }

View file

@ -25,16 +25,15 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial struct MapInfo partial struct MapInfo {
{
public byte[] Data { public byte[] Data {
get { get {
byte[] data = new byte[Size]; byte[] data = new byte[Size];
Marshal.Copy (_data, data, 0, (int)Size); Marshal.Copy(_data, data, 0, (int)Size);
return data; return data;
} }
set { set {
Marshal.Copy (value, 0, _data, value.Length); Marshal.Copy(value, 0, _data, value.Length);
} }
} }

View file

@ -20,27 +20,26 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Message partial class Message {
{ [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport ("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void gst_message_parse_error(IntPtr msg, out IntPtr err, out IntPtr debug);
static extern void gst_message_parse_error (IntPtr msg, out IntPtr err, out IntPtr debug);
public void ParseError (out GLib.GException error, out string debug) { public void ParseError(out GLib.GException error, out string debug) {
IntPtr err; IntPtr err;
IntPtr dbg; IntPtr dbg;
gst_message_parse_error (Handle, out err, out dbg); gst_message_parse_error(Handle, out err, out dbg);
if (dbg != IntPtr.Zero) if (dbg != IntPtr.Zero)
debug = GLib.Marshaller.Utf8PtrToString (dbg); debug = GLib.Marshaller.Utf8PtrToString(dbg);
else else
debug = null; debug = null;
if (err == IntPtr.Zero) if (err == IntPtr.Zero)
throw new Exception (); throw new Exception();
error = new GLib.GException (err); error = new GLib.GException(err);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
@ -52,14 +51,14 @@ namespace Gst {
public GLib.Value StreamStatusObject { public GLib.Value StreamStatusObject {
get { get {
IntPtr raw_ret = gst_message_get_stream_status_object(Handle); IntPtr raw_ret = gst_message_get_stream_status_object(Handle);
GLib.Value ret = (GLib.Value) Marshal.PtrToStructure (raw_ret, typeof (GLib.Value)); GLib.Value ret = (GLib.Value)Marshal.PtrToStructure(raw_ret, typeof(GLib.Value));
return ret; return ret;
} }
set { set {
IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc (value); IntPtr native_value = GLib.Marshaller.StructureToPtrAlloc(value);
gst_message_set_stream_status_object(Handle, native_value); gst_message_set_stream_status_object(Handle, native_value);
value = (GLib.Value) Marshal.PtrToStructure (native_value, typeof (GLib.Value)); value = (GLib.Value)Marshal.PtrToStructure(native_value, typeof(GLib.Value));
Marshal.FreeHGlobal (native_value); Marshal.FreeHGlobal(native_value);
} }
} }
} }

View file

@ -20,9 +20,8 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class MiniObject partial class MiniObject {
{ protected MiniObject() { }
protected MiniObject () {}
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool gst_mini_object_replace(IntPtr olddata, IntPtr newdata); static extern bool gst_mini_object_replace(IntPtr olddata, IntPtr newdata);
@ -32,7 +31,7 @@ namespace Gst {
} }
public static bool Replace(ref Gst.MiniObject olddata) { public static bool Replace(ref Gst.MiniObject olddata) {
return Replace (ref olddata, null); return Replace(ref olddata, null);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
@ -46,12 +45,12 @@ namespace Gst {
static extern IntPtr gst_mini_object_make_writable(IntPtr mini_object); static extern IntPtr gst_mini_object_make_writable(IntPtr mini_object);
public void MakeWritable() { public void MakeWritable() {
IntPtr raw = gst_mini_object_make_writable (Raw); IntPtr raw = gst_mini_object_make_writable(Raw);
if (raw == Raw) if (raw == Raw)
return; return;
Raw = raw; Raw = raw;
if (raw != IntPtr.Zero) if (raw != IntPtr.Zero)
Unref (raw); Unref(raw);
} }
} }

View file

@ -26,11 +26,11 @@ namespace Gst.Video {
public partial class NavigationAdapter { public partial class NavigationAdapter {
public static bool ParseCommands (Gst.Query query, out NavigationCommand[] cmds) { public static bool ParseCommands(Gst.Query query, out NavigationCommand[] cmds) {
uint len; uint len;
cmds = null; cmds = null;
if (!QueryParseCommandsLength (query, out len)) if (!QueryParseCommandsLength(query, out len))
return false; return false;
cmds = new NavigationCommand[len]; cmds = new NavigationCommand[len];
@ -38,7 +38,7 @@ namespace Gst.Video {
for (uint i = 0; i < len; i++) { for (uint i = 0; i < len; i++) {
NavigationCommand cmd; NavigationCommand cmd;
if (!QueryParseCommandsNth (query, i, out cmd)) if (!QueryParseCommandsNth(query, i, out cmd))
return false; return false;
cmds[i] = cmd; cmds[i] = cmd;
} }

View file

@ -29,90 +29,92 @@ using System.Runtime.InteropServices;
namespace Gst { namespace Gst {
public class PropertyNotFoundException : Exception {} public class PropertyNotFoundException : Exception { }
[StructLayout (LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct GstObject { struct GstObject {
IntPtr _lock; IntPtr _lock;
public string name; public string name;
public Object parent; public Object parent;
public uint flags; public uint flags;
IntPtr controlBindings; IntPtr controlBindings;
public int control_rate; public int control_rate;
public int last_sync; public int last_sync;
private IntPtr[] _gstGstReserved; private IntPtr[] _gstGstReserved;
} }
partial class Object partial class Object {
{ private Dictionary<string, bool> PropertyNameCache = new Dictionary<string, bool>();
private Dictionary <string, bool> PropertyNameCache = new Dictionary<string, bool> ();
[DllImport ("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_object_class_find_property (IntPtr klass, IntPtr name); static extern IntPtr g_object_class_find_property(IntPtr klass, IntPtr name);
bool PropertyExists (string name) { bool PropertyExists(string name) {
if (PropertyNameCache.ContainsKey (name)) if (PropertyNameCache.ContainsKey(name))
return PropertyNameCache [name]; return PropertyNameCache[name];
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);
var ptr = g_object_class_find_property (Marshal.ReadIntPtr (Handle), native_name); var ptr = g_object_class_find_property(Marshal.ReadIntPtr(Handle), native_name);
var result = ptr != IntPtr.Zero; var result = ptr != IntPtr.Zero;
// just cache the positive results because there might // just cache the positive results because there might
// actually be new properties getting installed // actually be new properties getting installed
if (result) if (result)
PropertyNameCache [name] = result; PropertyNameCache[name] = result;
GLib.Marshaller.Free (native_name); GLib.Marshaller.Free(native_name);
return result; return result;
} }
public object this[string property] { public object this[string property] {
get { get {
if (PropertyExists (property)) { if (PropertyExists(property)) {
using (GLib.Value v = GetProperty (property)) { using (GLib.Value v = GetProperty(property)) {
return v.Val; return v.Val;
} }
} else }
throw new PropertyNotFoundException (); else
} set { throw new PropertyNotFoundException();
if (PropertyExists (property)) { }
set {
if (PropertyExists(property)) {
if (value == null) { if (value == null) {
throw new ArgumentNullException (); throw new ArgumentNullException();
} }
var type = value.GetType (); var type = value.GetType();
var gtype = (GLib.GType)type; var gtype = (GLib.GType)type;
if (gtype == null) { if (gtype == null) {
throw new Exception ("Could not find a GType for type " + type.FullName); throw new Exception("Could not find a GType for type " + type.FullName);
} }
GLib.Value v = new GLib.Value ((GLib.GType)value.GetType ()); GLib.Value v = new GLib.Value((GLib.GType)value.GetType());
v.Val = value; v.Val = value;
SetProperty (property, v); SetProperty(property, v);
v.Dispose (); v.Dispose();
} else }
throw new PropertyNotFoundException (); else
} throw new PropertyNotFoundException();
}
} }
public void Connect (string signal, SignalHandler handler) { public void Connect(string signal, SignalHandler handler) {
DynamicSignal.Connect (this, signal, handler); DynamicSignal.Connect(this, signal, handler);
} }
public void Disconnect (string signal, SignalHandler handler) { public void Disconnect(string signal, SignalHandler handler) {
DynamicSignal.Disconnect (this, signal, handler); DynamicSignal.Disconnect(this, signal, handler);
} }
public void Connect (string signal, Delegate handler) { public void Connect(string signal, Delegate handler) {
DynamicSignal.Connect (this, signal, handler); DynamicSignal.Connect(this, signal, handler);
} }
public void Disconnect (string signal, Delegate handler) { public void Disconnect(string signal, Delegate handler) {
DynamicSignal.Disconnect (this, signal, handler); DynamicSignal.Disconnect(this, signal, handler);
} }
public object Emit (string signal, params object[] parameters) { public object Emit(string signal, params object[] parameters) {
return DynamicSignal.Emit (this, signal, parameters); return DynamicSignal.Emit(this, signal, parameters);
} }
} }
} }

View file

@ -19,14 +19,13 @@ namespace Gst {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial class Pad partial class Pad {
{ [GLib.Property("caps")]
[GLib.Property ("caps")]
public Gst.Caps Caps { public Gst.Caps Caps {
get { get {
GLib.Value val = GetProperty ("caps"); GLib.Value val = GetProperty("caps");
Gst.Caps ret = (Gst.Caps) val.Val; Gst.Caps ret = (Gst.Caps)val.Val;
val.Dispose (); val.Dispose();
return ret; return ret;
} }
} }

View file

@ -23,6 +23,6 @@
namespace Gst { namespace Gst {
partial class Pipeline { partial class Pipeline {
public Pipeline () : this (null) {} public Pipeline() : this(null) { }
} }
} }

View file

@ -15,29 +15,27 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA // 02110-1301 USA
namespace Gst namespace Gst {
{
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public partial class TagList public partial class TagList {
{ public object this[string tag, uint index] {
public object this [string tag, uint index] { get { return GetValueIndex(tag, index).Val; }
get { return GetValueIndex (tag, index).Val; }
} }
public object this [string tag] { public object this[string tag] {
get { get {
var v = GLib.Value.Empty; var v = GLib.Value.Empty;
bool success; bool success;
success = CopyValue (ref v, this, tag); success = CopyValue(ref v, this, tag);
if (!success) if (!success)
return null; return null;
object ret = (object)v.Val; object ret = (object)v.Val;
v.Dispose (); v.Dispose();
return ret; return ret;
} }
@ -45,24 +43,23 @@ namespace Gst
public string[] Tags { public string[] Tags {
get { get {
int size = NTags (); int size = NTags();
string[] tags = new string[size]; string[] tags = new string[size];
for (uint i = 0; i < size; i++) for (uint i = 0; i < size; i++)
tags [i] = NthTagName (i); tags[i] = NthTagName(i);
return tags; return tags;
} }
} }
public void Add (Gst.TagMergeMode mode, string tag, object value) public void Add(Gst.TagMergeMode mode, string tag, object value) {
{ if (!Tag.Exists(tag))
if (!Tag.Exists (tag)) throw new ArgumentException(String.Format("Invalid tag name '{0}'", tag));
throw new ArgumentException (String.Format ("Invalid tag name '{0}'", tag));
GLib.Value v = new GLib.Value (value); GLib.Value v = new GLib.Value(value);
AddValue (mode, tag, v); AddValue(mode, tag, v);
v.Dispose (); v.Dispose();
} }
} }
} }

View file

@ -16,17 +16,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// Wrapper for GLib.Value to add support for GstFraction, GstFourcc, Gst*Range, ... // Wrapper for GLib.Value to add support for GstFraction, GstFourcc, Gst*Range, ...
using GLib;
using System; using System;
using System.Text;
using System.Collections; using System.Collections;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using GLib; using System.Text;
/* TODO: intersect, compare, substract, .... */ /* TODO: intersect, compare, substract, .... */
namespace Gst namespace Gst {
{ public struct Fraction {
public struct Fraction
{
public int Numerator { public int Numerator {
get { get {
return numerator; return numerator;
@ -34,7 +32,7 @@ namespace Gst
set { set {
numerator = value; numerator = value;
Reduce (); Reduce();
} }
} }
@ -45,10 +43,10 @@ namespace Gst
set { set {
if (denominator == 0) if (denominator == 0)
throw new ArgumentException (); throw new ArgumentException();
denominator = value; denominator = value;
Reduce (); Reduce();
} }
} }
@ -57,13 +55,12 @@ namespace Gst
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_fraction_get_type ()); return new GType(gst_fraction_get_type());
} }
} }
private void Reduce () private void Reduce() {
{ int gcd = GreatestCommonDivisor(this);
int gcd = GreatestCommonDivisor (this);
if (gcd != 0) { if (gcd != 0) {
this.numerator /= gcd; this.numerator /= gcd;
@ -71,8 +68,7 @@ namespace Gst
} }
} }
private static int GreatestCommonDivisor (Fraction fraction) private static int GreatestCommonDivisor(Fraction fraction) {
{
int a = fraction.numerator; int a = fraction.numerator;
int b = fraction.denominator; int b = fraction.denominator;
@ -82,288 +78,259 @@ namespace Gst
a = b; a = b;
b = temp % b; b = temp % b;
} }
return Math.Abs (a); return Math.Abs(a);
} }
public Fraction (int numerator, int denominator) public Fraction(int numerator, int denominator) {
{
if (denominator == 0) if (denominator == 0)
throw new ArgumentException (); throw new ArgumentException();
this.numerator = numerator; this.numerator = numerator;
this.denominator = denominator; this.denominator = denominator;
Reduce (); Reduce();
} }
public Fraction (GLib.Value val) : this () public Fraction(GLib.Value val) : this() {
{ this.numerator = gst_value_get_fraction_numerator(ref val);
this.numerator = gst_value_get_fraction_numerator (ref val); this.denominator = gst_value_get_fraction_denominator(ref val);
this.denominator = gst_value_get_fraction_denominator (ref val);
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{ gst_value_set_fraction(ref val, Numerator, Denominator);
gst_value_set_fraction (ref val, Numerator, Denominator);
} }
public override string ToString () public override string ToString() {
{ return String.Format("{0}/{1}", numerator, denominator);
return String.Format ("{0}/{1}", numerator, denominator);
} }
public static explicit operator GLib.Value (Fraction fraction) public static explicit operator GLib.Value(Fraction fraction) {
{ GLib.Value val = new GLib.Value(Fraction.GType);
GLib.Value val = new GLib.Value (Fraction.GType); gst_value_set_fraction(ref val, fraction.Numerator, fraction.Denominator);
gst_value_set_fraction (ref val, fraction.Numerator, fraction.Denominator);
return val; return val;
} }
public static explicit operator double (Fraction fraction) public static explicit operator double(Fraction fraction) {
{
return ((double)fraction.numerator) / ((double)fraction.denominator); return ((double)fraction.numerator) / ((double)fraction.denominator);
} }
public static Fraction operator + (Fraction a, Fraction b) public static Fraction operator +(Fraction a, Fraction b) {
{ return new Fraction((a.Numerator * b.Denominator) + (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
return new Fraction ((a.Numerator * b.Denominator) + (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
} }
public static Fraction operator - (Fraction a, Fraction b) public static Fraction operator -(Fraction a, Fraction b) {
{ return new Fraction((a.Numerator * b.Denominator) - (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
return new Fraction ((a.Numerator * b.Denominator) - (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
} }
public static Fraction operator * (Fraction a, Fraction b) public static Fraction operator *(Fraction a, Fraction b) {
{ return new Fraction(a.Numerator * b.Numerator, a.Denominator * b.Denominator);
return new Fraction (a.Numerator * b.Numerator, a.Denominator * b.Denominator);
} }
public static Fraction operator / (Fraction a, Fraction b) public static Fraction operator /(Fraction a, Fraction b) {
{ return new Fraction(a.Numerator * b.Denominator, a.Denominator * b.Numerator);
return new Fraction (a.Numerator * b.Denominator, a.Denominator * b.Numerator);
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_set_fraction (ref GLib.Value v, int numerator, int denominator); private static extern void gst_value_set_fraction(ref GLib.Value v, int numerator, int denominator);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int gst_value_get_fraction_numerator (ref GLib.Value v); private static extern int gst_value_get_fraction_numerator(ref GLib.Value v);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int gst_value_get_fraction_denominator (ref GLib.Value v); private static extern int gst_value_get_fraction_denominator(ref GLib.Value v);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_fraction_get_type (); private static extern IntPtr gst_fraction_get_type();
} }
public struct DoubleRange public struct DoubleRange {
{
public double Min; public double Min;
public double Max; public double Max;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_double_range_get_type ()); return new GType(gst_double_range_get_type());
} }
} }
public DoubleRange (double min, double max) public DoubleRange(double min, double max) {
{
if (min > max) if (min > max)
throw new ArgumentException (); throw new ArgumentException();
this.Min = min; this.Min = min;
this.Max = max; this.Max = max;
} }
public DoubleRange (GLib.Value val) : this () public DoubleRange(GLib.Value val) : this() {
{ this.Min = gst_value_get_double_range_min(ref val);
this.Min = gst_value_get_double_range_min (ref val); this.Max = gst_value_get_double_range_max(ref val);
this.Max = gst_value_get_double_range_max (ref val);
} }
public override string ToString () public override string ToString() {
{ return String.Format("[{0}, {1}]", Min, Max);
return String.Format ("[{0}, {1}]", Min, Max);
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{ gst_value_set_double_range(ref val, Min, Max);
gst_value_set_double_range (ref val, Min, Max);
} }
public static explicit operator GLib.Value (DoubleRange range) public static explicit operator GLib.Value(DoubleRange range) {
{ GLib.Value val = new GLib.Value(DoubleRange.GType);
GLib.Value val = new GLib.Value (DoubleRange.GType);
gst_value_set_double_range (ref val, range.Min, range.Max); gst_value_set_double_range(ref val, range.Min, range.Max);
return val; return val;
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_double_range_get_type (); private static extern IntPtr gst_double_range_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_set_double_range (ref GLib.Value v, double min, double max); private static extern void gst_value_set_double_range(ref GLib.Value v, double min, double max);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern double gst_value_get_double_range_min (ref GLib.Value v); private static extern double gst_value_get_double_range_min(ref GLib.Value v);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern double gst_value_get_double_range_max (ref GLib.Value v); private static extern double gst_value_get_double_range_max(ref GLib.Value v);
} }
public struct IntRange public struct IntRange {
{
public int Min; public int Min;
public int Max; public int Max;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_int_range_get_type ()); return new GType(gst_int_range_get_type());
} }
} }
public IntRange (int min, int max) public IntRange(int min, int max) {
{
if (min > max) if (min > max)
throw new ArgumentException (); throw new ArgumentException();
this.Min = min; this.Min = min;
this.Max = max; this.Max = max;
} }
public IntRange (GLib.Value val) : this () public IntRange(GLib.Value val) : this() {
{ this.Min = gst_value_get_int_range_min(ref val);
this.Min = gst_value_get_int_range_min (ref val); this.Max = gst_value_get_int_range_max(ref val);
this.Max = gst_value_get_int_range_max (ref val);
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{ gst_value_set_int_range(ref val, Min, Max);
gst_value_set_int_range (ref val, Min, Max);
} }
public override string ToString () public override string ToString() {
{ return String.Format("[{0}, {1}]", Min, Max);
return String.Format ("[{0}, {1}]", Min, Max);
} }
public static explicit operator GLib.Value (IntRange range) public static explicit operator GLib.Value(IntRange range) {
{ GLib.Value val = new GLib.Value(IntRange.GType);
GLib.Value val = new GLib.Value (IntRange.GType);
gst_value_set_int_range (ref val, range.Min, range.Max); gst_value_set_int_range(ref val, range.Min, range.Max);
return val; return val;
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_int_range_get_type (); private static extern IntPtr gst_int_range_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_set_int_range (ref GLib.Value v, int min, int max); private static extern void gst_value_set_int_range(ref GLib.Value v, int min, int max);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int gst_value_get_int_range_min (ref GLib.Value v); private static extern int gst_value_get_int_range_min(ref GLib.Value v);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int gst_value_get_int_range_max (ref GLib.Value v); private static extern int gst_value_get_int_range_max(ref GLib.Value v);
} }
public struct FractionRange public struct FractionRange {
{
public Fraction Min; public Fraction Min;
public Fraction Max; public Fraction Max;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_fraction_range_get_type ()); return new GType(gst_fraction_range_get_type());
} }
} }
public FractionRange (Fraction min, Fraction max) public FractionRange(Fraction min, Fraction max) {
{
double a = (double)min, b = (double)max; double a = (double)min, b = (double)max;
if (a > b) if (a > b)
throw new ArgumentException (); throw new ArgumentException();
this.Min = min; this.Min = min;
this.Max = max; this.Max = max;
} }
public FractionRange (GLib.Value val) : this () public FractionRange(GLib.Value val) : this() {
{
IntPtr min_ptr, max_ptr; IntPtr min_ptr, max_ptr;
GLib.Value min, max; GLib.Value min, max;
min_ptr = gst_value_get_fraction_range_min (ref val); min_ptr = gst_value_get_fraction_range_min(ref val);
max_ptr = gst_value_get_fraction_range_max (ref val); max_ptr = gst_value_get_fraction_range_max(ref val);
min = (GLib.Value)Marshal.PtrToStructure (min_ptr, typeof(GLib.Value)); min = (GLib.Value)Marshal.PtrToStructure(min_ptr, typeof(GLib.Value));
max = (GLib.Value)Marshal.PtrToStructure (max_ptr, typeof(GLib.Value)); max = (GLib.Value)Marshal.PtrToStructure(max_ptr, typeof(GLib.Value));
this.Min = (Fraction)min.Val; this.Min = (Fraction)min.Val;
this.Max = (Fraction)max.Val; this.Max = (Fraction)max.Val;
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{ GLib.Value min = new GLib.Value(Min);
GLib.Value min = new GLib.Value (Min); GLib.Value max = new GLib.Value(Max);
GLib.Value max = new GLib.Value (Max); gst_value_set_fraction_range(ref val, ref min, ref max);
gst_value_set_fraction_range (ref val, ref min, ref max); min.Dispose();
min.Dispose (); max.Dispose();
max.Dispose ();
} }
public override string ToString () public override string ToString() {
{ return String.Format("[{0}, {1}]", Min, Max);
return String.Format ("[{0}, {1}]", Min, Max);
} }
public static explicit operator GLib.Value (FractionRange range) public static explicit operator GLib.Value(FractionRange range) {
{ GLib.Value val = new GLib.Value(FractionRange.GType);
GLib.Value val = new GLib.Value (FractionRange.GType);
GLib.Value min = new GLib.Value (range.Min); GLib.Value min = new GLib.Value(range.Min);
GLib.Value max = new GLib.Value (range.Max); GLib.Value max = new GLib.Value(range.Max);
gst_value_set_fraction_range (ref val, ref min, ref max); gst_value_set_fraction_range(ref val, ref min, ref max);
min.Dispose (); min.Dispose();
max.Dispose (); max.Dispose();
return val; return val;
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_fraction_range_get_type (); private static extern IntPtr gst_fraction_range_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_set_fraction_range (ref GLib.Value v, ref GLib.Value min, ref GLib.Value max); private static extern void gst_value_set_fraction_range(ref GLib.Value v, ref GLib.Value min, ref GLib.Value max);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_get_fraction_range_min (ref GLib.Value v); private static extern IntPtr gst_value_get_fraction_range_min(ref GLib.Value v);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_get_fraction_range_max (ref GLib.Value v); private static extern IntPtr gst_value_get_fraction_range_max(ref GLib.Value v);
} }
public class Date : IWrapper public class Date : IWrapper {
{
public DateTime Val; public DateTime Val;
private IntPtr handle; private IntPtr handle;
@ -375,278 +342,256 @@ namespace Gst
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_date_get_type ()); return new GType(gst_date_get_type());
} }
} }
~Date () ~Date() {
{ g_date_free(handle);
g_date_free (handle);
} }
public Date (DateTime date) public Date(DateTime date) {
{
this.Val = date; this.Val = date;
handle = g_date_new_dmy ((byte)Val.Day, (int)Val.Month, (ushort)Val.Year); handle = g_date_new_dmy((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
} }
public Date (int day, int month, int year) public Date(int day, int month, int year) {
{ this.Val = new DateTime(year, month, day);
this.Val = new DateTime (year, month, day); handle = g_date_new_dmy((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
handle = g_date_new_dmy ((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
} }
public Date (GLib.Value val) public Date(GLib.Value val) {
{ IntPtr date = gst_value_get_date(ref val);
IntPtr date = gst_value_get_date (ref val);
this.Val = new DateTime (g_date_get_year (date), g_date_get_month (date), g_date_get_day (date)); this.Val = new DateTime(g_date_get_year(date), g_date_get_month(date), g_date_get_day(date));
handle = g_date_new_dmy ((byte)Val.Day, (int)Val.Month, (ushort)Val.Year); handle = g_date_new_dmy((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
} }
public static Date New (IntPtr date) public static Date New(IntPtr date) {
{ return new Date(g_date_get_day(date), g_date_get_month(date), g_date_get_year(date));
return new Date (g_date_get_day (date), g_date_get_month (date), g_date_get_year (date));
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{ IntPtr date_ptr = g_date_new_dmy((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
IntPtr date_ptr = g_date_new_dmy ((byte)Val.Day, (int)Val.Month, (ushort)Val.Year);
gst_value_set_date (ref val, date_ptr); gst_value_set_date(ref val, date_ptr);
GLib.Marshaller.Free (date_ptr); GLib.Marshaller.Free(date_ptr);
} }
public override string ToString () public override string ToString() {
{ return String.Format("{0}-{1}-{2}", Val.Year, Val.Month, Val.Day);
return String.Format ("{0}-{1}-{2}", Val.Year, Val.Month, Val.Day);
} }
public static explicit operator GLib.Value (Date date) public static explicit operator GLib.Value(Date date) {
{ GLib.Value val = new GLib.Value(Date.GType);
GLib.Value val = new GLib.Value (Date.GType);
date.SetGValue (ref val); date.SetGValue(ref val);
return val; return val;
} }
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern byte g_date_get_day (IntPtr date); private static extern byte g_date_get_day(IntPtr date);
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int g_date_get_month (IntPtr date); private static extern int g_date_get_month(IntPtr date);
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern ushort g_date_get_year (IntPtr date); private static extern ushort g_date_get_year(IntPtr date);
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr g_date_new_dmy (byte day, int month, ushort year); private static extern IntPtr g_date_new_dmy(byte day, int month, ushort year);
[DllImport ("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("glib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void g_date_free (IntPtr date); private static extern void g_date_free(IntPtr date);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_date_get_type (); private static extern IntPtr gst_date_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_get_date (ref GLib.Value val); private static extern IntPtr gst_value_get_date(ref GLib.Value val);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_set_date (ref GLib.Value val, IntPtr date); private static extern void gst_value_set_date(ref GLib.Value val, IntPtr date);
} }
public struct List : IEnumerable public struct List : IEnumerable {
{
private IList content; private IList content;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_value_list_get_type ()); return new GType(gst_value_list_get_type());
} }
} }
public List (IList content) public List(IList content) {
{
this.content = content; this.content = content;
} }
public List (GLib.Value val) public List(GLib.Value val) {
{ this.content = new ArrayList();
this.content = new ArrayList ();
uint n = gst_value_list_get_size (ref val); uint n = gst_value_list_get_size(ref val);
for (uint i = 0; i < n; i++) { for (uint i = 0; i < n; i++) {
IntPtr v_ptr = gst_value_list_get_value (ref val, i); IntPtr v_ptr = gst_value_list_get_value(ref val, i);
GLib.Value v = (GLib.Value)Marshal.PtrToStructure (v_ptr, typeof(GLib.Value)); GLib.Value v = (GLib.Value)Marshal.PtrToStructure(v_ptr, typeof(GLib.Value));
this.content.Add (v.Val); this.content.Add(v.Val);
} }
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{
foreach (object o in content) { foreach (object o in content) {
GLib.Value v = new GLib.Value (o); GLib.Value v = new GLib.Value(o);
gst_value_list_append_value (ref val, ref v); gst_value_list_append_value(ref val, ref v);
v.Dispose (); v.Dispose();
} }
} }
public override string ToString () public override string ToString() {
{ StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder ();
sb.Append ("< "); sb.Append("< ");
for (int i = 0; i < content.Count; i++) { for (int i = 0; i < content.Count; i++) {
sb.Append (content [i]); sb.Append(content[i]);
if (i < content.Count - 1) if (i < content.Count - 1)
sb.Append (", "); sb.Append(", ");
} }
sb.Append (" >"); sb.Append(" >");
return sb.ToString (); return sb.ToString();
} }
public static explicit operator GLib.Value (List l) public static explicit operator GLib.Value(List l) {
{ GLib.Value val = new GLib.Value(List.GType);
GLib.Value val = new GLib.Value (List.GType);
foreach (object o in l.content) { foreach (object o in l.content) {
GLib.Value v = new GLib.Value (o); GLib.Value v = new GLib.Value(o);
gst_value_list_append_value (ref val, ref v); gst_value_list_append_value(ref val, ref v);
v.Dispose (); v.Dispose();
} }
return val; return val;
} }
public IEnumerator GetEnumerator () public IEnumerator GetEnumerator() {
{ return content.GetEnumerator();
return content.GetEnumerator ();
} }
public object this [int index] { public object this[int index] {
set { set {
content [index] = value; content[index] = value;
} }
get { get {
return content [index]; return content[index];
} }
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_list_get_type (); private static extern IntPtr gst_value_list_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern uint gst_value_list_get_size (ref GLib.Value val); private static extern uint gst_value_list_get_size(ref GLib.Value val);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_list_get_value (ref GLib.Value val, uint index); private static extern IntPtr gst_value_list_get_value(ref GLib.Value val, uint index);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_list_append_value (ref GLib.Value val, ref GLib.Value el); private static extern void gst_value_list_append_value(ref GLib.Value val, ref GLib.Value el);
} }
public struct Array : IEnumerable public struct Array : IEnumerable {
{
private IList content; private IList content;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_value_array_get_type ()); return new GType(gst_value_array_get_type());
} }
} }
public Array (IList content) public Array(IList content) {
{
this.content = content; this.content = content;
} }
public Array (GLib.Value val) public Array(GLib.Value val) {
{ this.content = new ArrayList();
this.content = new ArrayList ();
uint n = gst_value_array_get_size (ref val); uint n = gst_value_array_get_size(ref val);
for (uint i = 0; i < n; i++) { for (uint i = 0; i < n; i++) {
IntPtr v_ptr = gst_value_array_get_value (ref val, i); IntPtr v_ptr = gst_value_array_get_value(ref val, i);
GLib.Value v = (GLib.Value)Marshal.PtrToStructure (v_ptr, typeof(GLib.Value)); GLib.Value v = (GLib.Value)Marshal.PtrToStructure(v_ptr, typeof(GLib.Value));
this.content.Add (v.Val); this.content.Add(v.Val);
} }
} }
public void SetGValue (ref GLib.Value val) public void SetGValue(ref GLib.Value val) {
{
foreach (object o in content) { foreach (object o in content) {
GLib.Value v = new GLib.Value (o); GLib.Value v = new GLib.Value(o);
gst_value_array_append_value (ref val, ref v); gst_value_array_append_value(ref val, ref v);
v.Dispose (); v.Dispose();
} }
} }
public static explicit operator GLib.Value (Array a) public static explicit operator GLib.Value(Array a) {
{ GLib.Value val = new GLib.Value(Gst.Array.GType);
GLib.Value val = new GLib.Value (Gst.Array.GType);
foreach (object o in a.content) { foreach (object o in a.content) {
GLib.Value v = new GLib.Value (o); GLib.Value v = new GLib.Value(o);
gst_value_array_append_value (ref val, ref v); gst_value_array_append_value(ref val, ref v);
v.Dispose (); v.Dispose();
} }
return val; return val;
} }
public override string ToString () public override string ToString() {
{ StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder ();
sb.Append ("{ "); sb.Append("{ ");
for (int i = 0; i < content.Count; i++) { for (int i = 0; i < content.Count; i++) {
sb.Append (content [i]); sb.Append(content[i]);
if (i < content.Count - 1) if (i < content.Count - 1)
sb.Append (", "); sb.Append(", ");
} }
sb.Append (" }"); sb.Append(" }");
return sb.ToString (); return sb.ToString();
} }
public IEnumerator GetEnumerator () public IEnumerator GetEnumerator() {
{ return content.GetEnumerator();
return content.GetEnumerator ();
} }
public object this [int index] { public object this[int index] {
set { set {
content [index] = value; content[index] = value;
} }
get { get {
return content [index]; return content[index];
} }
} }
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_array_get_type (); private static extern IntPtr gst_value_array_get_type();
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern uint gst_value_array_get_size (ref GLib.Value val); private static extern uint gst_value_array_get_size(ref GLib.Value val);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_value_array_get_value (ref GLib.Value val, uint index); private static extern IntPtr gst_value_array_get_value(ref GLib.Value val, uint index);
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_value_array_append_value (ref GLib.Value val, ref GLib.Value el); private static extern void gst_value_array_append_value(ref GLib.Value val, ref GLib.Value el);
} }
} }

View file

@ -25,26 +25,23 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Gst namespace Gst {
{ public static class Version {
public static class Version
{
private static uint major; private static uint major;
private static uint minor; private static uint minor;
private static uint micro; private static uint micro;
private static uint nano; private static uint nano;
private static string version_string; private static string version_string;
static Version () static Version() {
{ gst_version(out major, out minor, out micro, out nano);
gst_version (out major, out minor, out micro, out nano);
} }
public static string Description { public static string Description {
get { get {
if (version_string == null) { if (version_string == null) {
IntPtr version_string_ptr = gst_version_string (); IntPtr version_string_ptr = gst_version_string();
version_string = GLib.Marshaller.Utf8PtrToString (version_string_ptr); version_string = GLib.Marshaller.Utf8PtrToString(version_string_ptr);
} }
return version_string; return version_string;
@ -75,10 +72,10 @@ namespace Gst
} }
} }
[DllImport ("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gst_version (out uint major, out uint minor, out uint micro, out uint nano); private static extern void gst_version(out uint major, out uint minor, out uint micro, out uint nano);
[DllImport ("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr gst_version_string (); private static extern IntPtr gst_version_string();
} }
} }

View file

@ -19,11 +19,9 @@ namespace Gst.Video {
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
partial struct VideoGLTextureUploadMeta partial struct VideoGLTextureUploadMeta {
{ public bool Equals(VideoGLTextureUploadMeta other) {
public bool Equals (VideoGLTextureUploadMeta other) return Meta.Equals(other.Meta) && TextureOrientation.Equals(other.TextureOrientation) && NTextures.Equals(other.NTextures) && TextureType.Equals(other.TextureType);
{
return Meta.Equals (other.Meta) && TextureOrientation.Equals (other.TextureOrientation) && NTextures.Equals (other.NTextures) && TextureType.Equals (other.TextureType);
} }
} }
} }