using System;
using System.Runtime.InteropServices;
-namespace Gst
-{
- public static class Application
- {
- public static void Init()
- {
- IntPtr argv = new IntPtr(0);
- int argc = 0;
-
- gst_init(ref argc, ref argv);
- }
+namespace Gst {
+ public static class Application {
+ public static void Init() {
+ IntPtr argv = new IntPtr (0);
+ int argc = 0;
- public static void Init(string progname, ref string [] args)
- {
- FullInit(progname, ref args, false);
- }
-
- public static void InitCheck(string progname, ref string [] args)
- {
- FullInit(progname, ref args, true);
- }
-
- public static void Deinit()
- {
- gst_deinit();
- }
-
- private static void FullInit(string progname, ref string [] args, bool check)
- {
- string [] progargs = new string[args.Length + 1];
-
- progargs[0] = progname;
- args.CopyTo(progargs, 1);
-
- GLib.Argv argv = new GLib.Argv(progargs);
- IntPtr argv_ptr = argv.Handle;
- int argc = progargs.Length;
-
- if(check) {
- IntPtr error_ptr;
- bool result = gst_init_check(ref argc, ref argv_ptr, out error_ptr);
-
- if(error_ptr != IntPtr.Zero) {
- string message = GError.GetMessage (error_ptr);
-
- if (message == String.Empty)
- message = "Reason unknown";
-
- GError.Free (error_ptr);
-
- throw new ApplicationException(String.Format ("gst_init_check() failed: {0}", message));
- } else if(!result) {
- throw new ApplicationException("gst_init_check() failed: Reason unknown");
- }
- } else {
- gst_init(ref argc, ref argv_ptr);
- }
-
- if(argv_ptr != argv.Handle) {
- string init_call = check ? "gst_init_check()" : "gst_init()";
- throw new ApplicationException(init_call + " returned a new argv handle");
- }
-
- if(argc <= 1) {
- args = new string[0];
- } else {
- progargs = argv.GetArgs(argc);
- args = new string[argc - 1];
- Array.Copy(progargs, 1, args, 0, argc - 1);
- }
+ gst_init (ref argc, ref argv);
+ }
+
+ public static void Init (string progname, ref string [] args) {
+ FullInit (progname, ref args, false);
+ }
+
+ public static void InitCheck (string progname, ref string [] args) {
+ FullInit (progname, ref args, true);
+ }
+
+ public static void Deinit() {
+ gst_deinit();
+ }
+
+ private static void FullInit (string progname, ref string [] args, bool check) {
+ string [] progargs = new string[args.Length + 1];
+
+ progargs[0] = progname;
+ args.CopyTo (progargs, 1);
+
+ GLib.Argv argv = new GLib.Argv (progargs);
+ IntPtr argv_ptr = argv.Handle;
+ int argc = progargs.Length;
+
+ if (check) {
+ IntPtr error_ptr;
+ bool result = gst_init_check (ref argc, ref argv_ptr, out error_ptr);
+
+ if (error_ptr != IntPtr.Zero) {
+ string message = GError.GetMessage (error_ptr);
+
+ if (message == String.Empty)
+ message = "Reason unknown";
+
+ GError.Free (error_ptr);
+
+ throw new ApplicationException (String.Format ("gst_init_check() failed: {0}", message));
+ } else if (!result) {
+ throw new ApplicationException ("gst_init_check() failed: Reason unknown");
}
+ } else {
+ gst_init (ref argc, ref argv_ptr);
+ }
- [DllImport("gstreamer-0.10")]
- private static extern void gst_init(ref int argc, ref IntPtr argv);
+ if (argv_ptr != argv.Handle) {
+ string init_call = check ? "gst_init_check()" : "gst_init()";
+ throw new ApplicationException (init_call + " returned a new argv handle");
+ }
- [DllImport("gstreamer-0.10")]
- private static extern bool gst_init_check(ref int argc, ref IntPtr argv, out IntPtr error);
-
- [DllImport("gstreamer-0.10")]
- private static extern void gst_deinit();
+ if (argc <= 1) {
+ args = new string[0];
+ } else {
+ progargs = argv.GetArgs (argc);
+ args = new string[argc - 1];
+ Array.Copy (progargs, 1, args, 0, argc - 1);
+ }
}
+
+ [DllImport ("gstreamer-0.10") ]
+ private static extern void gst_init (ref int argc, ref IntPtr argv);
+
+ [DllImport ("gstreamer-0.10") ]
+ private static extern bool gst_init_check (ref int argc, ref IntPtr argv, out IntPtr error);
+
+ [DllImport ("gstreamer-0.10") ]
+ private static extern void gst_deinit();
+ }
}
using System.Reflection;
using System.Runtime.CompilerServices;
-[assembly:AssemblyVersion("@VERSION@")]
-[assembly:AssemblyDelaySign(false)]
-[assembly:AssemblyKeyFile("gstreamer-sharp.snk")]
+[assembly:AssemblyVersion ("@VERSION@") ]
+[assembly:AssemblyDelaySign (false) ]
+[assembly:AssemblyKeyFile ("gstreamer-sharp.snk") ]
- [DllImport ("gstreamersharpglue-0.10")]
- private extern static uint gstsharp_gst_bin_get_children_offset();
-
- static uint children_offset = gstsharp_gst_bin_get_children_offset();
-
- public Element [] Children {
- get {
- GLib.List list;
-
- unsafe {
- IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + children_offset);
- list = new GLib.List((*raw_ptr));
- }
-
- Element [] result = new Element[list.Count];
-
- for(int i = list.Count - 1; i >= 0; i--) {
- result[i] = list[i] as Element;
- }
-
- return result;
- }
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static uint gstsharp_gst_bin_get_children_offset();
+
+static uint children_offset = gstsharp_gst_bin_get_children_offset();
+
+public Element [] Children {
+ get {
+ GLib.List list;
+
+ unsafe {
+ IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + children_offset);
+ list = new GLib.List ( (*raw_ptr));
}
- [DllImport("gstreamer-0.10.dll")]
- static extern bool gst_bin_add(IntPtr raw, IntPtr element);
-
- public bool Add(Gst.Element element) {
- bool raw_ret = gst_bin_add(Handle, element == null ? IntPtr.Zero : element.Handle);
- if(raw_ret) {
- // Incrmenting the refcount of the element.
- Gst.Object.Ref(element.Handle);
- }
- bool ret = raw_ret;
- return ret;
+ Element [] result = new Element[list.Count];
+
+ for (int i = list.Count - 1; i >= 0; i--) {
+ result[i] = list[i] as Element;
}
- public bool AddMany(params Element[] elements)
- {
- if(elements == null) {
- return false;
- }
-
- foreach(Element element in elements) {
- if(element == null || !Add(element)) {
- return false;
- }
- }
-
- return true;
+ return result;
+ }
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+static extern bool gst_bin_add (IntPtr raw, IntPtr element);
+
+public bool Add (Gst.Element element) {
+ bool raw_ret = gst_bin_add (Handle, element == null ? IntPtr.Zero : element.Handle);
+ if (raw_ret) {
+ // Incrmenting the refcount of the element.
+ Gst.Object.Ref (element.Handle);
+ }
+ bool ret = raw_ret;
+ return ret;
+}
+
+public bool AddMany (params Element[] elements) {
+ if (elements == null) {
+ return false;
+ }
+
+ foreach (Element element in elements) {
+ if (element == null || !Add (element)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+public bool RemoveMany (params Element[] elements) {
+ if (elements == null) {
+ return false;
+ }
+
+ foreach (Element element in elements) {
+ if (element == null || !Remove (element)) {
+ return false;
}
+ }
+
+ return true;
+}
- public bool RemoveMany(params Element[] elements)
- {
- if(elements == null) {
- return false;
- }
-
- foreach(Element element in elements) {
- if(element == null || !Remove(element)) {
- return false;
- }
- }
-
- return true;
- }
-
//
// BindingHelper.cs: Utility methods to make creating
-// element bindings by hand an easier task
+// element bindings by hand an easier task
//
// Authors:
// Aaron Bockover (abockover@novell.com)
using System;
using GLib;
-namespace Gst
-{
- public static class BindingHelper
- {
- public static Delegate AddProxySignalDelegate(Element element, string signal,
- DynamicSignalHandler baseHandler, Delegate existingHandler, Delegate addHandler)
- {
- if(existingHandler == null) {
- element.Connect(signal, baseHandler);
- }
-
- return Delegate.Combine(existingHandler, addHandler);
- }
-
- public static Delegate RemoveProxySignalDelegate(Element element, string signal,
- DynamicSignalHandler baseHandler, Delegate existingHandler, Delegate removeHandler)
- {
- Delegate temp_delegate = Delegate.Remove(existingHandler, removeHandler);
- if(temp_delegate == null) {
- element.Disconnect(signal, baseHandler);
- }
-
- return temp_delegate;
- }
-
- public static void InvokeProxySignalDelegate(Delegate raiseDelegate, Type type,
- object o, GLib.SignalArgs args)
- {
- if(!type.IsSubclassOf(typeof(GLib.SignalArgs))) {
- throw new ArgumentException("Args type must derive SignalArgs");
- }
-
- if(raiseDelegate != null) {
- GLib.SignalArgs new_args = (GLib.SignalArgs) Activator.CreateInstance (type);
- new_args.RetVal = args.RetVal;
- new_args.Args = args.Args;
-
- raiseDelegate.DynamicInvoke(new object [] { o, new_args });
- }
- }
+namespace Gst {
+ public static class BindingHelper {
+ public static Delegate AddProxySignalDelegate (Element element, string signal,
+ DynamicSignalHandler baseHandler, Delegate existingHandler, Delegate addHandler) {
+ if (existingHandler == null) {
+ element.Connect (signal, baseHandler);
+ }
+
+ return Delegate.Combine (existingHandler, addHandler);
+ }
+
+ public static Delegate RemoveProxySignalDelegate (Element element, string signal,
+ DynamicSignalHandler baseHandler, Delegate existingHandler, Delegate removeHandler) {
+ Delegate temp_delegate = Delegate.Remove (existingHandler, removeHandler);
+ if (temp_delegate == null) {
+ element.Disconnect (signal, baseHandler);
+ }
+
+ return temp_delegate;
+ }
+
+ public static void InvokeProxySignalDelegate (Delegate raiseDelegate, Type type,
+ object o, GLib.SignalArgs args) {
+ if (!type.IsSubclassOf (typeof (GLib.SignalArgs))) {
+ throw new ArgumentException ("Args type must derive SignalArgs");
+ }
+
+ if (raiseDelegate != null) {
+ GLib.SignalArgs new_args = (GLib.SignalArgs) Activator.CreateInstance (type);
+ new_args.RetVal = args.RetVal;
+ new_args.Args = args.Args;
+
+ raiseDelegate.DynamicInvoke (new object [] { o, new_args });
+ }
}
+ }
}
- [DllImport("gstreamer-0.10")]
- static extern IntPtr gst_mini_object_ref (IntPtr buf);
+[DllImport ("gstreamer-0.10") ]
+static extern IntPtr gst_mini_object_ref (IntPtr buf);
- public void Ref()
- {
- IntPtr tmp = gst_mini_object_ref(this.Handle);
- }
+public void Ref() {
+ IntPtr tmp = gst_mini_object_ref (this.Handle);
+}
- [DllImport("gstreamer-0.10")]
- static extern void gst_mini_object_unref(IntPtr buf);
+[DllImport ("gstreamer-0.10") ]
+static extern void gst_mini_object_unref (IntPtr buf);
- public void Unref()
- {
- gst_mini_object_unref(this.Handle);
- }
+public void Unref() {
+ gst_mini_object_unref (this.Handle);
+}
- [DllImport("gstreamersharpglue-0.10")]
- static extern uint gstsharp_gst_buffer_refcount(IntPtr buf);
+[DllImport ("gstreamersharpglue-0.10") ]
+static extern uint gstsharp_gst_buffer_refcount (IntPtr buf);
- public uint Refcount
- {
- get {
- return gstsharp_gst_buffer_refcount(this.Handle);
- }
- }
+public uint Refcount {
+ get {
+ return gstsharp_gst_buffer_refcount (this.Handle);
+ }
+}
-
- public uint AddWatch(BusFunc func)
- {
- return AddWatchFull(0, func);
- }
+
+public uint AddWatch (BusFunc func) {
+ return AddWatchFull (0, func);
+}
- [DllImport("gstreamersharpglue-0.10")]
- private extern static ulong gstsharp_gst_clock_get_gst_second();
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static ulong gstsharp_gst_clock_get_gst_second();
- public static readonly ulong Second = gstsharp_gst_clock_get_gst_second();
+public static readonly ulong Second = gstsharp_gst_clock_get_gst_second();
- [DllImport("gstreamersharpglue-0.10")]
- private extern static ulong gstsharp_gst_clock_get_gst_msecond();
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static ulong gstsharp_gst_clock_get_gst_msecond();
- public static readonly ulong MSecond = gstsharp_gst_clock_get_gst_second();
+public static readonly ulong MSecond = gstsharp_gst_clock_get_gst_second();
- [DllImport("gstreamersharpglue-0.10")]
- private extern static ulong gstsharp_gst_clock_get_gst_usecond();
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static ulong gstsharp_gst_clock_get_gst_usecond();
- public static readonly ulong USecond = gstsharp_gst_clock_get_gst_second();
+public static readonly ulong USecond = gstsharp_gst_clock_get_gst_second();
- [DllImport("gstreamersharpglue-0.10")]
- private extern static ulong gstsharp_gst_clock_get_gst_nsecond();
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static ulong gstsharp_gst_clock_get_gst_nsecond();
- public static readonly ulong NSecond = gstsharp_gst_clock_get_gst_second();
+public static readonly ulong NSecond = gstsharp_gst_clock_get_gst_second();
+
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static ulong gstsharp_gst_clock_get_time_none();
+
+public static readonly ulong TimeNone = gstsharp_gst_clock_get_time_none();
+
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static bool gstsharp_gst_clock_time_is_valid (ulong time);
+
+public static bool TimeIsValid (ulong time) {
+ return gstsharp_gst_clock_time_is_valid (time);
+}
- [DllImport("gstreamersharpglue-0.10")]
- private extern static ulong gstsharp_gst_clock_get_time_none();
-
- public static readonly ulong TimeNone = gstsharp_gst_clock_get_time_none();
-
- [DllImport("gstreamersharpglue-0.10")]
- private extern static bool gstsharp_gst_clock_time_is_valid(ulong time);
-
- public static bool TimeIsValid(ulong time)
- {
- return gstsharp_gst_clock_time_is_valid(time);
- }
-
// (C) 2002 Alp Toker
//
-namespace Gst
-{
- public sealed class CommonTags
- {
- public const string Title = "title";
- public const string Artist = "artist";
- public const string Album = "album";
- public const string Date = "date";
- public const string Genre = "genre";
- public const string Comment = "comment";
- public const string TrackNumber = "track-number";
- public const string TrackCount = "track-count";
- public const string AlbumVolumeNumber = "album-disc-number";
- public const string AlbumVolumeCount = "album-disc-count";
- public const string Location = "location";
- public const string Description = "description";
- public const string Version = "version";
- public const string Isrc = "isrc";
- public const string Organization = "organization";
- public const string Copyright = "copyright";
- public const string Contact = "contact";
- public const string License = "license";
- public const string Performer = "performer";
- public const string Duration = "duration";
- public const string Codec = "codec";
- public const string VideoCodec = "video-codec";
- public const string AudioCodec = "audio-codec";
- public const string Bitrate = "bitrate";
- public const string NominalBitrate = "nominal-bitrate";
- public const string MinimumBitrate = "minimum-bitrate";
- public const string MaximumBitrate = "maximum-bitrate";
- public const string Serial = "serial";
- public const string Encoder = "encoder";
- public const string EncoderVersion = "encoder-version";
- public const string TrackGain = "replaygain-track-gain";
- public const string TrackPeak = "replaygain-track-peak";
- public const string AlbumGain = "replaygain-album-gain";
- public const string AlbumPeak = "replaygain-album-peak";
- }
+namespace Gst {
+ public sealed class CommonTags {
+ public const string Title = "title";
+ public const string Artist = "artist";
+ public const string Album = "album";
+ public const string Date = "date";
+ public const string Genre = "genre";
+ public const string Comment = "comment";
+ public const string TrackNumber = "track-number";
+ public const string TrackCount = "track-count";
+ public const string AlbumVolumeNumber = "album-disc-number";
+ public const string AlbumVolumeCount = "album-disc-count";
+ public const string Location = "location";
+ public const string Description = "description";
+ public const string Version = "version";
+ public const string Isrc = "isrc";
+ public const string Organization = "organization";
+ public const string Copyright = "copyright";
+ public const string Contact = "contact";
+ public const string License = "license";
+ public const string Performer = "performer";
+ public const string Duration = "duration";
+ public const string Codec = "codec";
+ public const string VideoCodec = "video-codec";
+ public const string AudioCodec = "audio-codec";
+ public const string Bitrate = "bitrate";
+ public const string NominalBitrate = "nominal-bitrate";
+ public const string MinimumBitrate = "minimum-bitrate";
+ public const string MaximumBitrate = "maximum-bitrate";
+ public const string Serial = "serial";
+ public const string Encoder = "encoder";
+ public const string EncoderVersion = "encoder-version";
+ public const string TrackGain = "replaygain-track-gain";
+ public const string TrackPeak = "replaygain-track-peak";
+ public const string AlbumGain = "replaygain-album-gain";
+ public const string AlbumPeak = "replaygain-album-peak";
+ }
}
- [DllImport("gstreamer-0.10.dll")]
- static extern void gst_debug_set_default_threshold(Gst.DebugLevel debug_level);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern void gst_debug_set_default_threshold (Gst.DebugLevel debug_level);
- public static void SetDefaultThreshold(Gst.DebugLevel debug_level)
- {
- gst_debug_set_default_threshold(debug_level);
- }
+public static void SetDefaultThreshold (Gst.DebugLevel debug_level) {
+ gst_debug_set_default_threshold (debug_level);
+}
//
// This class implements functions to bind callbacks to GObject signals
// dynamically and to emit signals dynamically.
-//
+//
//
using GLib;
using System.Collections;
namespace Gst {
-
- public delegate void DynamicSignalHandler(object o, SignalArgs args);
-
- delegate void GClosureMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
- IntPtr invocation_hint, IntPtr data);
-
- public static class DynamicSignal {
-
- private static readonly int gvalue_struct_size = Marshal.SizeOf(typeof(GLib.Value));
-
- class ObjectSignalKey {
- object o;
- string signal_name;
-
- public ObjectSignalKey (object o, string name) {
- this.o = o;
- signal_name = name;
- }
-
- public override bool Equals(object o) {
- if(o is ObjectSignalKey) {
- ObjectSignalKey k = (ObjectSignalKey) o;
- return k.o.Equals(this.o) && signal_name.Equals(k.signal_name);
- }
- return base.Equals(o);
- }
-
- public override int GetHashCode() {
- return o.GetHashCode() ^ signal_name.GetHashCode();
- }
- }
-
- class SignalInfo {
- uint handlerId;
- IntPtr closure;
- Delegate registeredHandler;
-
- public IntPtr Closure {
- get { return closure; }
- set { closure = value; }
- }
-
- public uint HandlerId {
- get { return handlerId; }
- set { handlerId = value; }
- }
-
- public Delegate RegisteredHandler {
- get { return registeredHandler; }
- set { registeredHandler = value; }
- }
-
- public SignalInfo(uint handlerId, IntPtr closure, Delegate registeredHandler) {
- this.handlerId = handlerId;
- this.closure = closure;
- this.registeredHandler = registeredHandler;
- }
- }
-
- static Hashtable SignalHandlers = new Hashtable();
-
- static GClosureMarshal marshalHandler = new GClosureMarshal(OnMarshal);
-
- public static void Connect(GLib.Object o, string name, DynamicSignalHandler handler) {
- Connect(o, name, false, handler);
- }
-
- static int g_closure_sizeof = gstsharp_g_closure_sizeof ();
-
- public static void Connect(GLib.Object o, string name,
- bool after, DynamicSignalHandler handler)
- {
- Delegate newHandler;
-
- ObjectSignalKey k = new ObjectSignalKey(o, name);
-
- if(SignalHandlers[k] != null) {
- SignalInfo si = (SignalInfo) SignalHandlers[k];
- newHandler = Delegate.Combine(si.RegisteredHandler, handler);
- si.RegisteredHandler = newHandler;
- }
- else {
- IntPtr closure = g_closure_new_simple(g_closure_sizeof, IntPtr.Zero);
- g_closure_set_meta_marshal(closure, (IntPtr) GCHandle.Alloc(k), marshalHandler);
- uint signalId = g_signal_connect_closure(o.Handle, name, closure, after);
- SignalHandlers.Add(k, new SignalInfo(signalId, closure, handler));
- }
- }
-
- [DllImport("gstreamersharpglue-0.10")]
- static extern int gstsharp_g_closure_sizeof ();
-
- public static void Disconnect(GLib.Object o, string name, DynamicSignalHandler handler) {
- ObjectSignalKey k = new ObjectSignalKey(o, name);
- if(SignalHandlers[k] != null)
- {
- SignalInfo si = (SignalInfo) SignalHandlers[k];
- Delegate newHandler = Delegate.Remove(si.RegisteredHandler, handler);
- if(newHandler == null || handler == null) {
- g_signal_handler_disconnect(o.Handle, si.HandlerId);
- SignalHandlers.Remove(k);
- } else {
- si.RegisteredHandler = newHandler;
- }
- }
- }
-
- [DllImport("libgobject-2.0-0.dll")]
- static extern IntPtr g_value_peek_pointer(IntPtr ptr);
-
- static void OnMarshal(IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
- IntPtr ihint, IntPtr data)
- {
- object [] args = new object[argc - 1];
- object o = ((GLib.Value) Marshal.PtrToStructure(argsPtr, typeof(GLib.Value))).Val;
-
- for(int i=1; i < argc; i++) {
- IntPtr struct_ptr = (IntPtr)((long) argsPtr + (i * gvalue_struct_size));
- Type detectedType = GLib.GType.LookupType(Marshal.ReadIntPtr(struct_ptr));
- if(detectedType.IsSubclassOf(typeof(Opaque))) {
- args[i - 1] = (Opaque) Opaque.GetOpaque(g_value_peek_pointer(struct_ptr), detectedType, false);
- }
- else {
- GLib.Value argument = (GLib.Value) Marshal.PtrToStructure(struct_ptr, typeof(GLib.Value));
- args[i - 1] = argument.Val;
- }
- }
-
- if(data == IntPtr.Zero) {
- Console.Error.WriteLine("No available data");
- }
-
- ObjectSignalKey k = (ObjectSignalKey)((GCHandle) data).Target;
- if(k != null) {
- SignalArgs arg = new SignalArgs();
- arg.Args = args;
- SignalInfo si = (SignalInfo) SignalHandlers[k];
- DynamicSignalHandler handler = (DynamicSignalHandler) si.RegisteredHandler;
- handler(o, arg);
- if(arg.RetVal != null) {
- retval.Val = arg.RetVal;
- }
- }
- }
-
-
- [DllImport("gobject-2.0.dll")]
- static extern IntPtr g_closure_new_simple(int size, IntPtr data);
-
- [DllImport("gobject-2.0.dll")]
- static extern uint g_signal_connect_closure(IntPtr instance,
- string name, IntPtr closure, bool after);
-
- [DllImport("gobject-2.0.dll")]
- static extern void g_closure_set_meta_marshal(IntPtr closure, IntPtr data, GClosureMarshal marshal);
-
- class GTypeSignalKey {
- GType type;
- string signal_name;
-
- public GTypeSignalKey (GType type, string name) {
- this.type = type;
- signal_name = name;
- }
-
- public override bool Equals(object o) {
- if(o is GTypeSignalKey) {
- GTypeSignalKey k = (GTypeSignalKey) o;
- return k.type.Equals(this.type) && signal_name.Equals(k.signal_name);
- }
- return base.Equals(o);
- }
-
- public override int GetHashCode() {
- return type.GetHashCode() ^ signal_name.GetHashCode();
- }
- }
-
- struct SignalQuery {
- public uint signal_id;
- public string signal_name;
- public GType itype;
- public uint signal_flags;
- public GType return_type;
- public uint n_params;
- public Type[] param_types;
- }
-
- static Hashtable SignalEmitInfo = new Hashtable ();
-
- public static object Emit (GLib.Object o, string name, params object[] parameters)
- {
- SignalQuery query;
- IntPtr type = gstsharp_g_type_from_instance (o.Handle);
- GType gtype = new GType (type);
- string signal_name, signal_detail;
- uint signal_detail_quark = 0;
- int colon;
-
- colon = name.LastIndexOf ("::");
-
- if (colon == -1) {
- signal_name = name;
- signal_detail = String.Empty;
- } else {
- signal_name = name.Substring (0, colon);
- signal_detail = name.Substring (colon + 2);
- }
-
- GTypeSignalKey key = new GTypeSignalKey (gtype, signal_name);
-
- if (SignalEmitInfo[key] == null) {
- uint signal_id = g_signal_lookup (signal_name, type);
-
- if (signal_id == 0)
- throw new NotSupportedException (String.Format ("{0} has no signal of name {1}", o, name));
- GSignalQuery q = new GSignalQuery ();
- g_signal_query (signal_id, ref q);
-
- if (q.signal_id == 0)
- throw new NotSupportedException (String.Format ("{0} couldn't be queried for signal with name {1}", o, name));
-
- query = new SignalQuery ();
-
- query.signal_id = signal_id;
- query.signal_name = Marshaller.Utf8PtrToString (q.signal_name);
- query.itype = new GType (q.itype);
- query.signal_flags = q.signal_flags;
- query.return_type = new GType (q.return_type);
- query.n_params = q.n_params;
- query.param_types = new Type[q.n_params];
-
- for (int i = 0; i < query.n_params; i++) {
- IntPtr t = Marshal.ReadIntPtr (q.param_types, i);
- GType g = new GType (t);
-
- query.param_types[i] = (Type) g;
- }
-
- SignalEmitInfo.Add (key, query);
- }
-
- query = (SignalQuery) SignalEmitInfo[key];
- GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
- signal_parameters[0] = new GLib.Value (o);
-
- if (parameters.Length != query.n_params)
- 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++) {
- Type expected_type = (Type) query.param_types[i];
- Type given_type = parameters[i].GetType ();
-
- 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));
-
- signal_parameters[i + 1] = new GLib.Value (parameters[i]);
- }
-
- GLib.Value return_value = new GLib.Value ();
- if (query.return_type != GType.Invalid && query.return_type != GType.None)
- return_value.Init (query.return_type);
-
- if (signal_detail != String.Empty)
- signal_detail_quark = g_quark_from_string (signal_detail);
-
- g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value);
-
- return (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null;
- }
-
- [DllImport ("gstreamersharpglue-0.10")]
- static extern IntPtr gstsharp_g_type_from_instance (IntPtr o);
-
- [DllImport("gobject-2.0.dll")]
- static extern int g_signal_handler_disconnect(IntPtr o, uint handler_id);
-
- [DllImport("gobject-2.0.dll")]
- static extern uint g_signal_lookup (string name, IntPtr itype);
-
- [DllImport("glib-2.0.dll")]
- static extern uint g_quark_from_string (string str);
-
- [DllImport("gobject-2.0.dll")]
- static extern void g_signal_emitv (GLib.Value[] parameters, uint signal_id, uint detail, ref GLib.Value return_value);
-
- [StructLayout(LayoutKind.Sequential)]
- struct GSignalQuery {
- public uint signal_id;
- public IntPtr signal_name;
- public IntPtr itype;
- public uint signal_flags;
- public IntPtr return_type;
- public uint n_params;
- public IntPtr param_types;
- }
-
- [DllImport("gobject-2.0.dll")]
- static extern void g_signal_query (uint signal_id, ref GSignalQuery query);
- }
+
+ public delegate void DynamicSignalHandler (object o, SignalArgs args);
+
+ delegate void GClosureMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
+ IntPtr invocation_hint, IntPtr data);
+
+ public static class DynamicSignal {
+
+ private static readonly int gvalue_struct_size = Marshal.SizeOf (typeof (GLib.Value));
+
+ class ObjectSignalKey {
+ object o;
+ string signal_name;
+
+ public ObjectSignalKey (object o, string name) {
+ this.o = o;
+ signal_name = name;
+ }
+
+ public override bool Equals (object o) {
+ if (o is ObjectSignalKey) {
+ ObjectSignalKey k = (ObjectSignalKey) o;
+ return k.o.Equals (this.o) && signal_name.Equals (k.signal_name);
+ }
+ return base.Equals (o);
+ }
+
+ public override int GetHashCode() {
+ return o.GetHashCode() ^ signal_name.GetHashCode();
+ }
+ }
+
+ class SignalInfo {
+ uint handlerId;
+ IntPtr closure;
+ Delegate registeredHandler;
+
+ public IntPtr Closure {
+ get {
+ return closure;
+ }
+ set {
+ closure = value;
+ }
+ }
+
+ public uint HandlerId {
+ get {
+ return handlerId;
+ }
+ set {
+ handlerId = value;
+ }
+ }
+
+ public Delegate RegisteredHandler {
+ get {
+ return registeredHandler;
+ }
+ set {
+ registeredHandler = value;
+ }
+ }
+
+ public SignalInfo (uint handlerId, IntPtr closure, Delegate registeredHandler) {
+ this.handlerId = handlerId;
+ this.closure = closure;
+ this.registeredHandler = registeredHandler;
+ }
+ }
+
+ static Hashtable SignalHandlers = new Hashtable();
+
+ static GClosureMarshal marshalHandler = new GClosureMarshal (OnMarshal);
+
+ public static void Connect (GLib.Object o, string name, DynamicSignalHandler handler) {
+ Connect (o, name, false, handler);
+ }
+
+ static int g_closure_sizeof = gstsharp_g_closure_sizeof ();
+
+ public static void Connect (GLib.Object o, string name,
+ bool after, DynamicSignalHandler handler) {
+ Delegate newHandler;
+
+ ObjectSignalKey k = new ObjectSignalKey (o, name);
+
+ if (SignalHandlers[k] != null) {
+ SignalInfo si = (SignalInfo) SignalHandlers[k];
+ newHandler = Delegate.Combine (si.RegisteredHandler, handler);
+ si.RegisteredHandler = newHandler;
+ } else {
+ IntPtr closure = g_closure_new_simple (g_closure_sizeof, IntPtr.Zero);
+ g_closure_set_meta_marshal (closure, (IntPtr) GCHandle.Alloc (k), marshalHandler);
+ uint signalId = g_signal_connect_closure (o.Handle, name, closure, after);
+ SignalHandlers.Add (k, new SignalInfo (signalId, closure, handler));
+ }
+ }
+
+ [DllImport ("gstreamersharpglue-0.10") ]
+ static extern int gstsharp_g_closure_sizeof ();
+
+ public static void Disconnect (GLib.Object o, string name, DynamicSignalHandler handler) {
+ ObjectSignalKey k = new ObjectSignalKey (o, name);
+ if (SignalHandlers[k] != null) {
+ SignalInfo si = (SignalInfo) SignalHandlers[k];
+ Delegate newHandler = Delegate.Remove (si.RegisteredHandler, handler);
+ if (newHandler == null || handler == null) {
+ g_signal_handler_disconnect (o.Handle, si.HandlerId);
+ SignalHandlers.Remove (k);
+ } else {
+ si.RegisteredHandler = newHandler;
+ }
+ }
+ }
+
+ [DllImport ("libgobject-2.0-0.dll") ]
+ static extern IntPtr g_value_peek_pointer (IntPtr ptr);
+
+ static void OnMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
+ IntPtr ihint, IntPtr data) {
+ object [] args = new object[argc - 1];
+ object o = ( (GLib.Value) Marshal.PtrToStructure (argsPtr, typeof (GLib.Value))).Val;
+
+ for (int i = 1; i < argc; i++) {
+ IntPtr struct_ptr = (IntPtr) ( (long) argsPtr + (i * gvalue_struct_size));
+ Type detectedType = GLib.GType.LookupType (Marshal.ReadIntPtr (struct_ptr));
+ if (detectedType.IsSubclassOf (typeof (Opaque))) {
+ args[i - 1] = (Opaque) Opaque.GetOpaque (g_value_peek_pointer (struct_ptr), detectedType, false);
+ } else {
+ GLib.Value argument = (GLib.Value) Marshal.PtrToStructure (struct_ptr, typeof (GLib.Value));
+ args[i - 1] = argument.Val;
+ }
+ }
+
+ if (data == IntPtr.Zero) {
+ Console.Error.WriteLine ("No available data");
+ }
+
+ ObjectSignalKey k = (ObjectSignalKey) ( (GCHandle) data).Target;
+ if (k != null) {
+ SignalArgs arg = new SignalArgs();
+ arg.Args = args;
+ SignalInfo si = (SignalInfo) SignalHandlers[k];
+ DynamicSignalHandler handler = (DynamicSignalHandler) si.RegisteredHandler;
+ handler (o, arg);
+ if (arg.RetVal != null) {
+ retval.Val = arg.RetVal;
+ }
+ }
+ }
+
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern IntPtr g_closure_new_simple (int size, IntPtr data);
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern uint g_signal_connect_closure (IntPtr instance,
+ string name, IntPtr closure, bool after);
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern void g_closure_set_meta_marshal (IntPtr closure, IntPtr data, GClosureMarshal marshal);
+
+ class GTypeSignalKey {
+ GType type;
+ string signal_name;
+
+ public GTypeSignalKey (GType type, string name) {
+ this.type = type;
+ signal_name = name;
+ }
+
+ public override bool Equals (object o) {
+ if (o is GTypeSignalKey) {
+ GTypeSignalKey k = (GTypeSignalKey) o;
+ return k.type.Equals (this.type) && signal_name.Equals (k.signal_name);
+ }
+ return base.Equals (o);
+ }
+
+ public override int GetHashCode() {
+ return type.GetHashCode() ^ signal_name.GetHashCode();
+ }
+ }
+
+ struct SignalQuery {
+ public uint signal_id;
+ public string signal_name;
+ public GType itype;
+ public uint signal_flags;
+ public GType return_type;
+ public uint n_params;
+ public Type[] param_types;
+ }
+
+ static Hashtable SignalEmitInfo = new Hashtable ();
+
+ public static object Emit (GLib.Object o, string name, params object[] parameters) {
+ SignalQuery query;
+ IntPtr type = gstsharp_g_type_from_instance (o.Handle);
+ GType gtype = new GType (type);
+ string signal_name, signal_detail;
+ uint signal_detail_quark = 0;
+ int colon;
+
+ colon = name.LastIndexOf ("::");
+
+ if (colon == -1) {
+ signal_name = name;
+ signal_detail = String.Empty;
+ } else {
+ signal_name = name.Substring (0, colon);
+ signal_detail = name.Substring (colon + 2);
+ }
+
+ GTypeSignalKey key = new GTypeSignalKey (gtype, signal_name);
+
+ if (SignalEmitInfo[key] == null) {
+ uint signal_id = g_signal_lookup (signal_name, type);
+
+ if (signal_id == 0)
+ throw new NotSupportedException (String.Format ("{0} has no signal of name {1}", o, name));
+ GSignalQuery q = new GSignalQuery ();
+ g_signal_query (signal_id, ref q);
+
+ if (q.signal_id == 0)
+ throw new NotSupportedException (String.Format ("{0} couldn't be queried for signal with name {1}", o, name));
+
+ query = new SignalQuery ();
+
+ query.signal_id = signal_id;
+ query.signal_name = Marshaller.Utf8PtrToString (q.signal_name);
+ query.itype = new GType (q.itype);
+ query.signal_flags = q.signal_flags;
+ query.return_type = new GType (q.return_type);
+ query.n_params = q.n_params;
+ query.param_types = new Type[q.n_params];
+
+ for (int i = 0; i < query.n_params; i++) {
+ IntPtr t = Marshal.ReadIntPtr (q.param_types, i);
+ GType g = new GType (t);
+
+ query.param_types[i] = (Type) g;
+ }
+
+ SignalEmitInfo.Add (key, query);
+ }
+
+ query = (SignalQuery) SignalEmitInfo[key];
+ GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
+ signal_parameters[0] = new GLib.Value (o);
+
+ if (parameters.Length != query.n_params)
+ 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++) {
+ Type expected_type = (Type) query.param_types[i];
+ Type given_type = parameters[i].GetType ();
+
+ 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));
+
+ signal_parameters[i + 1] = new GLib.Value (parameters[i]);
+ }
+
+ GLib.Value return_value = new GLib.Value ();
+ if (query.return_type != GType.Invalid && query.return_type != GType.None)
+ return_value.Init (query.return_type);
+
+ if (signal_detail != String.Empty)
+ signal_detail_quark = g_quark_from_string (signal_detail);
+
+ g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value);
+
+ return (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null;
+ }
+
+ [DllImport ("gstreamersharpglue-0.10") ]
+ static extern IntPtr gstsharp_g_type_from_instance (IntPtr o);
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern int g_signal_handler_disconnect (IntPtr o, uint handler_id);
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern uint g_signal_lookup (string name, IntPtr itype);
+
+ [DllImport ("glib-2.0.dll") ]
+ static extern uint g_quark_from_string (string str);
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern void g_signal_emitv (GLib.Value[] parameters, uint signal_id, uint detail, ref GLib.Value return_value);
+
+ [StructLayout (LayoutKind.Sequential) ]
+ struct GSignalQuery {
+ public uint signal_id;
+ public IntPtr signal_name;
+ public IntPtr itype;
+ public uint signal_flags;
+ public IntPtr return_type;
+ public uint n_params;
+ public IntPtr param_types;
+ }
+
+ [DllImport ("gobject-2.0.dll") ]
+ static extern void g_signal_query (uint signal_id, ref GSignalQuery query);
+ }
}
- public object this[string property] {
- get { return GetProperty(property).Val; }
- set { SetProperty(property, value); }
- }
-
- public new GLib.Value GetProperty(string propertyName)
- {
- return base.GetProperty(propertyName);
- }
-
- public new void SetProperty(string propertyName, GLib.Value value)
- {
- base.SetProperty(propertyName, value);
- }
-
- public void SetProperty(string propertyName, object value)
- {
- base.SetProperty(propertyName, new GLib.Value(value));
- }
-
- public void SetProperty(string propertyName, string value)
- {
- base.SetProperty(propertyName, new GLib.Value(value));
- }
-
- public void SetProperty(string propertyName, int value)
- {
- base.SetProperty(propertyName, new GLib.Value(value));
- }
-
- public void SetProperty(string propertyName, double value)
- {
- base.SetProperty(propertyName, new GLib.Value(value));
- }
-
- public void SetProperty(string propertyName, bool value)
- {
- base.SetProperty(propertyName, new GLib.Value(value));
- }
-
-
- public bool QueryPosition(Gst.Format format, out long current)
- {
- return gst_element_query_position(Handle, ref format, out current);
- }
-
-
- public bool QueryDuration(Gst.Format format, out long duration)
- {
- return gst_element_query_duration(Handle, ref format, out duration);
- }
-
- public void Connect(string signal, DynamicSignalHandler handler)
- {
- DynamicSignal.Connect(this, signal, handler);
- }
-
- public void Disconnect(string signal, DynamicSignalHandler handler)
- {
- DynamicSignal.Disconnect(this, signal, handler);
- }
-
- public bool AddPad(Pad p)
- {
- bool ret = gst_element_add_pad(this.Handle, p == null ? IntPtr.Zero : p.Handle);
- if(ret)
- Gst.Object.Ref(p.Handle);
- return ret;
- }
-
- public static bool LinkMany(params Element [] elements)
- {
- for(int i=0; i < elements.Length - 1; i++)
- {
- if(!elements[i].Link(elements[i+1]))
- return false;
- }
-
- return true;
- }
-
- public static void UnlinkMany(params Element [] elements)
- {
- for(int i=0; i < elements.Length - 1; i++)
- {
- elements[i].Unlink(elements[i+1]);
- }
- }
-
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern bool gst_element_query_position(IntPtr raw, ref Format format, out long cur);
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern bool gst_element_query_duration(IntPtr raw, ref Format format, out long duration);
-
- [DllImport("gstreamer-0.10.dll")]
- static extern bool gst_element_add_pad(IntPtr raw, IntPtr pad);
+public object this[string property] {
+ get {
+ return GetProperty (property).Val;
+ }
+ set {
+ SetProperty (property, value);
+ }
+}
+
+public new GLib.Value GetProperty (string propertyName) {
+ return base.GetProperty (propertyName);
+}
+
+public new void SetProperty (string propertyName, GLib.Value value) {
+ base.SetProperty (propertyName, value);
+}
+
+public void SetProperty (string propertyName, object value) {
+ base.SetProperty (propertyName, new GLib.Value (value));
+}
+
+public void SetProperty (string propertyName, string value) {
+ base.SetProperty (propertyName, new GLib.Value (value));
+}
+
+public void SetProperty (string propertyName, int value) {
+ base.SetProperty (propertyName, new GLib.Value (value));
+}
+
+public void SetProperty (string propertyName, double value) {
+ base.SetProperty (propertyName, new GLib.Value (value));
+}
+
+public void SetProperty (string propertyName, bool value) {
+ base.SetProperty (propertyName, new GLib.Value (value));
+}
+
+
+public bool QueryPosition (Gst.Format format, out long current) {
+ return gst_element_query_position (Handle, ref format, out current);
+}
+
+
+public bool QueryDuration (Gst.Format format, out long duration) {
+ return gst_element_query_duration (Handle, ref format, out duration);
+}
+
+public void Connect (string signal, DynamicSignalHandler handler) {
+ DynamicSignal.Connect (this, signal, handler);
+}
+
+public void Disconnect (string signal, DynamicSignalHandler handler) {
+ DynamicSignal.Disconnect (this, signal, handler);
+}
+
+public bool AddPad (Pad p) {
+ bool ret = gst_element_add_pad (this.Handle, p == null ? IntPtr.Zero : p.Handle);
+ if (ret)
+ Gst.Object.Ref (p.Handle);
+ return ret;
+}
+
+public static bool LinkMany (params Element [] elements) {
+ for (int i = 0; i < elements.Length - 1; i++) {
+ if (!elements[i].Link (elements[i+1]))
+ return false;
+ }
+
+ return true;
+}
+
+public static void UnlinkMany (params Element [] elements) {
+ for (int i = 0; i < elements.Length - 1; i++) {
+ elements[i].Unlink (elements[i+1]);
+ }
+}
+
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern bool gst_element_query_position (IntPtr raw, ref Format format, out long cur);
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern bool gst_element_query_duration (IntPtr raw, ref Format format, out long duration);
+
+[DllImport ("gstreamer-0.10.dll") ]
+static extern bool gst_element_add_pad (IntPtr raw, IntPtr pad);
using System.Runtime.InteropServices;
namespace Gst {
- internal static class GError
- {
- public static string GetMessage (IntPtr error)
- {
- if (error == IntPtr.Zero)
- return String.Empty;
+ internal static class GError {
+ public static string GetMessage (IntPtr error) {
+ if (error == IntPtr.Zero)
+ return String.Empty;
- IntPtr message = gstsharp_g_error_get_message (error);
- if (message == IntPtr.Zero)
- return String.Empty;
-
- return GLib.Marshaller.PtrToStringGFree (message);
- }
+ IntPtr message = gstsharp_g_error_get_message (error);
+ if (message == IntPtr.Zero)
+ return String.Empty;
- public static void Free (IntPtr error)
- {
- if (error != IntPtr.Zero)
- g_error_free (error);
- }
-
- [DllImport("gstreamersharpglue-0.10")]
- static extern IntPtr gstsharp_g_error_get_message (IntPtr error);
+ return GLib.Marshaller.PtrToStringGFree (message);
+ }
- [DllImport("glib-2.0.dll")]
- static extern void g_error_free (IntPtr error);
+ public static void Free (IntPtr error) {
+ if (error != IntPtr.Zero)
+ g_error_free (error);
}
+
+ [DllImport ("gstreamersharpglue-0.10") ]
+ static extern IntPtr gstsharp_g_error_get_message (IntPtr error);
+
+ [DllImport ("glib-2.0.dll") ]
+ static extern void g_error_free (IntPtr error);
+ }
}
- [DllImport("gstreamersharpglue-0.10")]
- private extern static IntPtr gstsharp_message_parse_error(IntPtr raw);
-
- public void ParseError(out string error)
- {
- IntPtr err = gstsharp_message_parse_error(Handle);
- error = GLib.Marshaller.PtrToStringGFree(err);
- }
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static IntPtr gstsharp_message_parse_error (IntPtr raw);
- [DllImport("gstreamersharpglue-0.10")]
- private extern static IntPtr gstsharp_message_error_new();
+public void ParseError (out string error) {
+ IntPtr err = gstsharp_message_parse_error (Handle);
+ error = GLib.Marshaller.PtrToStringGFree (err);
+}
- public Message(Gst.Object src, string debug)
- {
- IntPtr error = gstsharp_message_error_new();
- Raw = gst_message_new_error(src == null ? IntPtr.Zero : src.Handle, error, GLib.Marshaller.StringToPtrGStrdup(debug));
- }
+[DllImport ("gstreamersharpglue-0.10") ]
+private extern static IntPtr gstsharp_message_error_new();
+
+public Message (Gst.Object src, string debug) {
+ IntPtr error = gstsharp_message_error_new();
+ Raw = gst_message_new_error (src == null ? IntPtr.Zero : src.Handle, error, GLib.Marshaller.StringToPtrGStrdup (debug));
+}
- protected MiniObject () : base (IntPtr.Zero)
- {
- }
+protected MiniObject () : base (IntPtr.Zero)
+{
+}
- public int Refcount {
- get { return this.RefCount; }
- }
+public int Refcount {
+ get {
+ return this.RefCount;
+ }
+}
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern bool gst_pad_query_position(IntPtr raw, ref Format format, out long cur);
-
- public bool QueryPosition(Gst.Format format, out long current)
- {
- return gst_pad_query_position(Handle, ref format, out current);
- }
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern bool gst_pad_query_duration(IntPtr raw, ref Format format, out long duration);
-
- public bool QueryDuration(Gst.Format format, out long duration)
- {
- return gst_pad_query_duration(Handle, ref format, out duration);
- }
-
-
- public delegate bool BufferProbeDelegate(Pad pad, Gst.Buffer buffer);
- internal delegate bool BufferProbeNativeDelegate(IntPtr pad, IntPtr buf, IntPtr data);
-
- internal class BufferProbeWrapper {
- internal BufferProbeNativeDelegate NativeFunc;
- BufferProbeDelegate managedFunc;
-
- public BufferProbeWrapper(BufferProbeDelegate func)
- {
- managedFunc = func;
- if(func != null)
- NativeFunc = new BufferProbeNativeDelegate(BufferProbeMarshaller);
- }
-
- public bool BufferProbeMarshaller(IntPtr raw_pad, IntPtr buf, IntPtr data)
- {
- Pad pad = GLib.Object.GetObject(raw_pad) as Pad;
- Gst.Buffer buffer = GLib.Opaque.GetOpaque(buf, typeof(Gst.Buffer), false) as Gst.Buffer;
- return (bool) (managedFunc (pad, buffer));
- }
- }
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern ulong gst_pad_add_buffer_probe(IntPtr pad, BufferProbeNativeDelegate func, IntPtr data);
-
- public ulong AddBufferProbe(BufferProbeDelegate func)
- {
- BufferProbeWrapper func_wrapper;
- if(PersistentData["AddBufferProbe"] != null) {
- func_wrapper = PersistentData["AddBufferProbe"] as BufferProbeWrapper;
- }
- else
- {
- func_wrapper = new BufferProbeWrapper(func);
- PersistentData["AddBufferProbe"] = func_wrapper;
- }
-
- return gst_pad_add_buffer_probe(this.Handle, func_wrapper.NativeFunc, IntPtr.Zero);
- }
-
- [DllImport("gstreamer-0.10.dll")]
- private static extern void gst_pad_remove_buffer_probe(IntPtr pad, uint handler_id);
-
- public void RemoveBufferProbe(uint handler_id)
- {
- gst_pad_remove_buffer_probe(this.Handle, handler_id);
- PersistentData["AddBufferProbe"] = null;
- }
-
- public delegate bool DataProbeDelegate (Pad pad, GLib.Opaque miniobject);
- internal delegate bool DataProbeNativeDelegate(IntPtr pad, IntPtr miniobj, IntPtr data);
-
- internal class DataProbeWrapper {
- internal DataProbeNativeDelegate NativeFunc;
- DataProbeDelegate ManagedFunc;
-
- public DataProbeWrapper(DataProbeDelegate func)
- {
- ManagedFunc = func;
- if(func != null)
- NativeFunc = new DataProbeNativeDelegate(DataProbeMarshaller);
- }
-
- public bool DataProbeMarshaller (IntPtr raw_pad, IntPtr miniobj, IntPtr data)
- {
- Pad pad = GLib.Object.GetObject(raw_pad) as Pad;
- GLib.Opaque opaque = GLib.Opaque.GetOpaque(miniobj, typeof(GLib.Opaque), true);
- return ManagedFunc(pad, opaque);
- }
- }
-
- [DllImport("gstreamer-0.10.dll")]
- static extern uint gst_pad_add_data_probe(IntPtr pad, DataProbeNativeDelegate func, IntPtr data);
-
- public uint AddDataProbe(DataProbeDelegate func)
- {
- DataProbeWrapper func_wrapper;
- if(PersistentData["AddDataProbe"] != null) {
- func_wrapper = PersistentData["AddDataProbe"] as DataProbeWrapper;
- } else {
- func_wrapper = new DataProbeWrapper(func);
- PersistentData["AddDataProbe"] = func_wrapper;
- }
-
- return gst_pad_add_data_probe(this.Handle, func_wrapper.NativeFunc, IntPtr.Zero);
- }
-
- [DllImport("gstreamer-0.10.dll")]
- static extern void gst_pad_remove_data_probe(IntPtr pad, uint handler_id);
-
- public void RemoveDataProbe(uint handler_id)
- {
- gst_pad_remove_data_probe(this.Handle, handler_id);
- PersistentData["AddDataProbe"] = null;
- }
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern bool gst_pad_query_position (IntPtr raw, ref Format format, out long cur);
+
+public bool QueryPosition (Gst.Format format, out long current) {
+ return gst_pad_query_position (Handle, ref format, out current);
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern bool gst_pad_query_duration (IntPtr raw, ref Format format, out long duration);
+
+public bool QueryDuration (Gst.Format format, out long duration) {
+ return gst_pad_query_duration (Handle, ref format, out duration);
+}
+
+
+public delegate bool BufferProbeDelegate (Pad pad, Gst.Buffer buffer);
+internal delegate bool BufferProbeNativeDelegate (IntPtr pad, IntPtr buf, IntPtr data);
+
+internal class BufferProbeWrapper {
+ internal BufferProbeNativeDelegate NativeFunc;
+ BufferProbeDelegate managedFunc;
+
+ public BufferProbeWrapper (BufferProbeDelegate func) {
+ managedFunc = func;
+ if (func != null)
+ NativeFunc = new BufferProbeNativeDelegate (BufferProbeMarshaller);
+ }
+
+ public bool BufferProbeMarshaller (IntPtr raw_pad, IntPtr buf, IntPtr data) {
+ Pad pad = GLib.Object.GetObject (raw_pad) as Pad;
+ Gst.Buffer buffer = GLib.Opaque.GetOpaque (buf, typeof (Gst.Buffer), false) as Gst.Buffer;
+ return (bool) (managedFunc (pad, buffer));
+ }
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern ulong gst_pad_add_buffer_probe (IntPtr pad, BufferProbeNativeDelegate func, IntPtr data);
+
+public ulong AddBufferProbe (BufferProbeDelegate func) {
+ BufferProbeWrapper func_wrapper;
+ if (PersistentData["AddBufferProbe"] != null) {
+ func_wrapper = PersistentData["AddBufferProbe"] as BufferProbeWrapper;
+ } else {
+ func_wrapper = new BufferProbeWrapper (func);
+ PersistentData["AddBufferProbe"] = func_wrapper;
+ }
+
+ return gst_pad_add_buffer_probe (this.Handle, func_wrapper.NativeFunc, IntPtr.Zero);
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+private static extern void gst_pad_remove_buffer_probe (IntPtr pad, uint handler_id);
+
+public void RemoveBufferProbe (uint handler_id) {
+ gst_pad_remove_buffer_probe (this.Handle, handler_id);
+ PersistentData["AddBufferProbe"] = null;
+}
+
+public delegate bool DataProbeDelegate (Pad pad, GLib.Opaque miniobject);
+internal delegate bool DataProbeNativeDelegate (IntPtr pad, IntPtr miniobj, IntPtr data);
+
+internal class DataProbeWrapper {
+ internal DataProbeNativeDelegate NativeFunc;
+ DataProbeDelegate ManagedFunc;
+
+ public DataProbeWrapper (DataProbeDelegate func) {
+ ManagedFunc = func;
+ if (func != null)
+ NativeFunc = new DataProbeNativeDelegate (DataProbeMarshaller);
+ }
+
+ public bool DataProbeMarshaller (IntPtr raw_pad, IntPtr miniobj, IntPtr data) {
+ Pad pad = GLib.Object.GetObject (raw_pad) as Pad;
+ GLib.Opaque opaque = GLib.Opaque.GetOpaque (miniobj, typeof (GLib.Opaque), true);
+ return ManagedFunc (pad, opaque);
+ }
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+static extern uint gst_pad_add_data_probe (IntPtr pad, DataProbeNativeDelegate func, IntPtr data);
+
+public uint AddDataProbe (DataProbeDelegate func) {
+ DataProbeWrapper func_wrapper;
+ if (PersistentData["AddDataProbe"] != null) {
+ func_wrapper = PersistentData["AddDataProbe"] as DataProbeWrapper;
+ } else {
+ func_wrapper = new DataProbeWrapper (func);
+ PersistentData["AddDataProbe"] = func_wrapper;
+ }
+
+ return gst_pad_add_data_probe (this.Handle, func_wrapper.NativeFunc, IntPtr.Zero);
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+static extern void gst_pad_remove_data_probe (IntPtr pad, uint handler_id);
+
+public void RemoveDataProbe (uint handler_id) {
+ gst_pad_remove_data_probe (this.Handle, handler_id);
+ PersistentData["AddDataProbe"] = null;
+}
using System;
using System.Runtime.InteropServices;
-namespace Gst
-{
- public static class Version
- {
- private static uint major;
- private static uint minor;
- private static uint micro;
- private static uint nano;
- private static string version_string;
-
- static Version()
- {
- gst_version(out major, out minor, out micro, out nano);
- }
-
- public static string Description {
- get {
- if (version_string == null) {
- IntPtr version_string_ptr = gst_version_string();
- version_string = GLib.Marshaller.Utf8PtrToString(version_string_ptr);
- }
-
- return version_string;
- }
- }
-
- public static uint Major {
- get { return major; }
- }
-
- public static uint Minor {
- get { return minor; }
- }
-
- public static uint Micro {
- get { return micro; }
- }
-
- public static uint Nano {
- get { return nano; }
+namespace Gst {
+ public static class Version {
+ private static uint major;
+ private static uint minor;
+ private static uint micro;
+ private static uint nano;
+ private static string version_string;
+
+ static Version() {
+ gst_version (out major, out minor, out micro, out nano);
+ }
+
+ public static string Description {
+ get {
+ if (version_string == null) {
+ IntPtr version_string_ptr = gst_version_string();
+ version_string = GLib.Marshaller.Utf8PtrToString (version_string_ptr);
}
-
- [DllImport("gstreamer-0.10")]
- private static extern void gst_version(out uint major, out uint minor, out uint micro, out uint nano);
-
- [DllImport("gstreamer-0.10")]
- private static extern IntPtr gst_version_string();
+
+ return version_string;
+ }
}
+
+ public static uint Major {
+ get {
+ return major;
+ }
+ }
+
+ public static uint Minor {
+ get {
+ return minor;
+ }
+ }
+
+ public static uint Micro {
+ get {
+ return micro;
+ }
+ }
+
+ public static uint Nano {
+ get {
+ return nano;
+ }
+ }
+
+ [DllImport ("gstreamer-0.10") ]
+ private static extern void gst_version (out uint major, out uint minor, out uint micro, out uint nano);
+
+ [DllImport ("gstreamer-0.10") ]
+ private static extern IntPtr gst_version_string();
+ }
}
#include <gst/gstpipeline.h>
#include <gst/gstsegment.h>
-guint
-gstsharp_gst_bin_get_children_offset (void);
+guint gstsharp_gst_bin_get_children_offset (void);
-guint gstsharp_gst_bin_get_children_offset (void) {
- return (guint)G_STRUCT_OFFSET (GstBin, children);
+guint
+gstsharp_gst_bin_get_children_offset (void)
+{
+ return (guint) G_STRUCT_OFFSET (GstBin, children);
}
#include <gst/gst.h>
guint
-gstsharp_gst_buffer_refcount(GstBuffer * buf)
+gstsharp_gst_buffer_refcount (GstBuffer * buf)
{
- return GST_MINI_OBJECT_REFCOUNT_VALUE(buf);
+ return GST_MINI_OBJECT_REFCOUNT_VALUE (buf);
}
#include <glib.h>
#include <gst/gstclock.h>
-guint64 gstsharp_gst_clock_get_gst_second()
+guint64
+gstsharp_gst_clock_get_gst_second ()
{
- return GST_SECOND;
+ return GST_SECOND;
}
-guint64 gstsharp_gst_clock_get_gst_msecond()
+guint64
+gstsharp_gst_clock_get_gst_msecond ()
{
- return GST_MSECOND;
+ return GST_MSECOND;
}
-guint64 gstsharp_gst_clock_get_gst_usecond()
+guint64
+gstsharp_gst_clock_get_gst_usecond ()
{
- return GST_USECOND;
+ return GST_USECOND;
}
-guint64 gstsharp_gst_clock_get_gst_nsecond()
+guint64
+gstsharp_gst_clock_get_gst_nsecond ()
{
- return GST_NSECOND;
+ return GST_NSECOND;
}
-guint64 gstsharp_gst_clock_get_time_none()
+guint64
+gstsharp_gst_clock_get_time_none ()
{
- return GST_CLOCK_TIME_NONE;
+ return GST_CLOCK_TIME_NONE;
}
-gboolean gstsharp_gst_clock_time_is_valid(GstClockTime time)
+gboolean
+gstsharp_gst_clock_time_is_valid (GstClockTime time)
{
- return GST_CLOCK_TIME_IS_VALID(time);
+ return GST_CLOCK_TIME_IS_VALID (time);
}
-
}
GType
-gstsharp_g_type_from_instance (GTypeInstance *instance)
+gstsharp_g_type_from_instance (GTypeInstance * instance)
{
return G_TYPE_FROM_INSTANCE (instance);
}
#include <glib/gquark.h>
gchar *
-gstsharp_message_parse_error(GstMessage *message)
+gstsharp_message_parse_error (GstMessage * message)
{
- GError *gerror;
- gchar *error;
+ GError *gerror;
+ gchar *error;
- gst_message_parse_error(message, &gerror, NULL);
+ gst_message_parse_error (message, &gerror, NULL);
- error = g_strdup(gerror->message);
- g_error_free(gerror);
-
- return error;
+ error = g_strdup (gerror->message);
+ g_error_free (gerror);
+
+ return error;
}
GError *
-gstsharp_message_error_new()
+gstsharp_message_error_new ()
{
- GQuark domain = g_quark_from_string ("test");
- return g_error_new (domain, 10, "test error");
+ GQuark domain = g_quark_from_string ("test");
+ return g_error_new (domain, 10, "test error");
}
#include <gst/gstminiobject.h>
GType
-gstsharp_get_type_id(GObject *obj)
-{
- return G_TYPE_FROM_INSTANCE(obj);
+gstsharp_get_type_id (GObject * obj)
+{
+ return G_TYPE_FROM_INSTANCE (obj);
}
GType
-gstsharp_register_type(gchar *name, GType parent)
-{
- GTypeQuery query;
- GTypeInfo info = { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL };
+gstsharp_register_type (gchar * name, GType parent)
+{
+ GTypeQuery query;
+ GTypeInfo info = { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL };
- g_type_query (parent, &query);
+ g_type_query (parent, &query);
- info.class_size = query.class_size;
- info.instance_size = query.instance_size;
+ info.class_size = query.class_size;
+ info.instance_size = query.instance_size;
- return g_type_register_static(parent, name, &info, 0);
+ return g_type_register_static (parent, name, &info, 0);
}
\r
namespace GtkSharp.Parsing {\r
\r
- using System;\r
- using System.IO;\r
- using System.Xml;\r
- using System.Xml.XPath;\r
-\r
- public class Fixup {\r
-\r
- public static int Main (string[] args)\r
- {\r
- if (args.Length < 2) {\r
- Console.WriteLine ("Usage: gst-gapi-fixup --metadata=<filename> --api=<filename> --symbols=<filename>");\r
- return 0;\r
- }\r
-\r
- string api_filename = "";\r
- XmlDocument api_doc = new XmlDocument ();\r
- XmlDocument meta_doc = new XmlDocument ();\r
- XmlDocument symbol_doc = new XmlDocument ();\r
-\r
- foreach (string arg in args) {\r
-\r
- if (arg.StartsWith("--metadata=")) {\r
-\r
- string meta_filename = arg.Substring (11);\r
-\r
- try {\r
- Stream stream = File.OpenRead (meta_filename);\r
- meta_doc.Load (stream);\r
- stream.Close ();\r
- } catch (XmlException e) {\r
- Console.WriteLine ("Invalid meta file.");\r
- Console.WriteLine (e);\r
- return 1;\r
- }\r
-\r
- } else if (arg.StartsWith ("--api=")) {\r
-\r
- api_filename = arg.Substring (6);\r
-\r
- try {\r
- Stream stream = File.OpenRead (api_filename);\r
- api_doc.Load (stream);\r
- stream.Close ();\r
- } catch (XmlException e) {\r
- Console.WriteLine ("Invalid api file.");\r
- Console.WriteLine (e);\r
- return 1;\r
- }\r
-\r
- } else if (arg.StartsWith ("--symbols=")) {\r
-\r
- string symbol_filename = arg.Substring (10);\r
-\r
- try {\r
- Stream stream = File.OpenRead (symbol_filename);\r
- symbol_doc.Load (stream);\r
- stream.Close ();\r
- } catch (XmlException e) {\r
- Console.WriteLine ("Invalid api file.");\r
- Console.WriteLine (e);\r
- return 1;\r
- }\r
-\r
- } else {\r
- Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename>");\r
- return 1;\r
- }\r
- }\r
-\r
- XPathNavigator meta_nav = meta_doc.CreateNavigator ();\r
- XPathNavigator api_nav = api_doc.CreateNavigator ();\r
-\r
- XPathNodeIterator change_node_type_iter = meta_nav.Select ("/metadata/change-node-type");\r
- while (change_node_type_iter.MoveNext ()) {\r
- string path = change_node_type_iter.Current.GetAttribute ("path", "");\r
- XPathNodeIterator api_iter = api_nav.Select (path);\r
- bool matched = false;\r
- while (api_iter.MoveNext ()) {\r
- XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;\r
- XmlElement parent = node.ParentNode as XmlElement;\r
- XmlElement new_node = api_doc.CreateElement (change_node_type_iter.Current.Value);\r
-\r
- foreach (XmlNode child in node.ChildNodes)\r
- new_node.AppendChild (child.Clone ());\r
- foreach (XmlAttribute attribute in node.Attributes)\r
- new_node.Attributes.Append ((XmlAttribute) attribute.Clone ());\r
- \r
- parent.ReplaceChild (new_node, node);\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <change-node-type path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- XPathNodeIterator move_iter = meta_nav.Select ("/metadata/move-node");\r
- while (move_iter.MoveNext ()) {\r
- string path = move_iter.Current.GetAttribute ("path", "");\r
- XPathExpression expr = api_nav.Compile (path);\r
- string parent = move_iter.Current.Value;\r
- XPathNodeIterator parent_iter = api_nav.Select (parent);\r
- bool matched = false;\r
- while (parent_iter.MoveNext ()) {\r
- XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();\r
- XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);\r
- while (path_iter.MoveNext ()) {\r
- XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();\r
- parent_node.AppendChild (node.Clone ());\r
- node.ParentNode.RemoveChild (node);\r
- }\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <move-node path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");\r
- while (rmv_iter.MoveNext ()) {\r
- string path = rmv_iter.Current.GetAttribute ("path", "");\r
- XPathNodeIterator api_iter = api_nav.Select (path);\r
- bool matched = false;\r
- while (api_iter.MoveNext ()) {\r
- XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;\r
- api_node.ParentNode.RemoveChild (api_node);\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <remove-node path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- XPathNodeIterator add_iter = meta_nav.Select ("/metadata/add-node");\r
- while (add_iter.MoveNext ()) {\r
- string path = add_iter.Current.GetAttribute ("path", "");\r
- XPathNodeIterator api_iter = api_nav.Select (path);\r
- bool matched = false;\r
- while (api_iter.MoveNext ()) {\r
- XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;\r
- foreach (XmlNode child in ((IHasXmlNode)add_iter.Current).GetNode().ChildNodes)\r
- api_node.AppendChild (api_doc.ImportNode (child, true));\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <add-node path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- XPathNodeIterator attr_iter = meta_nav.Select ("/metadata/attr");\r
- while (attr_iter.MoveNext ()) {\r
- string path = attr_iter.Current.GetAttribute ("path", "");\r
- string attr_name = attr_iter.Current.GetAttribute ("name", "");\r
- XPathNodeIterator api_iter = api_nav.Select (path);\r
- bool matched = false;\r
- while (api_iter.MoveNext ()) {\r
- XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;\r
- node.SetAttribute (attr_name, attr_iter.Current.Value);\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <attr path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- XPathNodeIterator remove_attr_iter = meta_nav.Select ("/metadata/remove-attr");\r
- while (remove_attr_iter.MoveNext ()) {\r
- string path = remove_attr_iter.Current.GetAttribute ("path", "");\r
- string name = remove_attr_iter.Current.GetAttribute ("name", "");\r
- XPathNodeIterator api_iter = api_nav.Select (path);\r
- bool matched = false;\r
- while (api_iter.MoveNext ()) {\r
- XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;\r
-\r
- node.RemoveAttribute (name);\r
- matched = true;\r
- }\r
- if (!matched)\r
- Console.WriteLine ("Warning: <remove-attr path=\"{0}\"/> matched no nodes", path);\r
- }\r
-\r
- if (symbol_doc != null) {\r
- XPathNavigator symbol_nav = symbol_doc.CreateNavigator ();\r
- XPathNodeIterator iter = symbol_nav.Select ("/api/*");\r
- while (iter.MoveNext ()) {\r
- XmlNode sym_node = ((IHasXmlNode)iter.Current).GetNode ();\r
- XPathNodeIterator parent_iter = api_nav.Select ("/api");\r
- if (parent_iter.MoveNext ()) {\r
- XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();\r
- parent_node.AppendChild (api_doc.ImportNode (sym_node, true));\r
- }\r
- }\r
- }\r
-\r
- api_doc.Save (api_filename);\r
- return 0;\r
- }\r
- }\r
+ using System;\r
+ using System.IO;\r
+ using System.Xml;\r
+ using System.Xml.XPath;\r
+\r
+ public class Fixup {\r
+\r
+ public static int Main (string[] args) {\r
+ if (args.Length < 2) {\r
+ Console.WriteLine ("Usage: gst-gapi-fixup --metadata=<filename> --api=<filename> --symbols=<filename>");\r
+ return 0;\r
+ }\r
+\r
+ string api_filename = "";\r
+ XmlDocument api_doc = new XmlDocument ();\r
+ XmlDocument meta_doc = new XmlDocument ();\r
+ XmlDocument symbol_doc = new XmlDocument ();\r
+\r
+ foreach (string arg in args) {\r
+\r
+ if (arg.StartsWith ("--metadata=")) {\r
+\r
+ string meta_filename = arg.Substring (11);\r
+\r
+ try {\r
+ Stream stream = File.OpenRead (meta_filename);\r
+ meta_doc.Load (stream);\r
+ stream.Close ();\r
+ } catch (XmlException e) {\r
+ Console.WriteLine ("Invalid meta file.");\r
+ Console.WriteLine (e);\r
+ return 1;\r
+ }\r
+\r
+ } else if (arg.StartsWith ("--api=")) {\r
+\r
+ api_filename = arg.Substring (6);\r
+\r
+ try {\r
+ Stream stream = File.OpenRead (api_filename);\r
+ api_doc.Load (stream);\r
+ stream.Close ();\r
+ } catch (XmlException e) {\r
+ Console.WriteLine ("Invalid api file.");\r
+ Console.WriteLine (e);\r
+ return 1;\r
+ }\r
+\r
+ } else if (arg.StartsWith ("--symbols=")) {\r
+\r
+ string symbol_filename = arg.Substring (10);\r
+\r
+ try {\r
+ Stream stream = File.OpenRead (symbol_filename);\r
+ symbol_doc.Load (stream);\r
+ stream.Close ();\r
+ } catch (XmlException e) {\r
+ Console.WriteLine ("Invalid api file.");\r
+ Console.WriteLine (e);\r
+ return 1;\r
+ }\r
+\r
+ } else {\r
+ Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename>");\r
+ return 1;\r
+ }\r
+ }\r
+\r
+ XPathNavigator meta_nav = meta_doc.CreateNavigator ();\r
+ XPathNavigator api_nav = api_doc.CreateNavigator ();\r
+\r
+ XPathNodeIterator change_node_type_iter = meta_nav.Select ("/metadata/change-node-type");\r
+ while (change_node_type_iter.MoveNext ()) {\r
+ string path = change_node_type_iter.Current.GetAttribute ("path", "");\r
+ XPathNodeIterator api_iter = api_nav.Select (path);\r
+ bool matched = false;\r
+ while (api_iter.MoveNext ()) {\r
+ XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;\r
+ XmlElement parent = node.ParentNode as XmlElement;\r
+ XmlElement new_node = api_doc.CreateElement (change_node_type_iter.Current.Value);\r
+\r
+ foreach (XmlNode child in node.ChildNodes)\r
+ new_node.AppendChild (child.Clone ());\r
+ foreach (XmlAttribute attribute in node.Attributes)\r
+ new_node.Attributes.Append ( (XmlAttribute) attribute.Clone ());\r
+\r
+ parent.ReplaceChild (new_node, node);\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <change-node-type path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ XPathNodeIterator move_iter = meta_nav.Select ("/metadata/move-node");\r
+ while (move_iter.MoveNext ()) {\r
+ string path = move_iter.Current.GetAttribute ("path", "");\r
+ XPathExpression expr = api_nav.Compile (path);\r
+ string parent = move_iter.Current.Value;\r
+ XPathNodeIterator parent_iter = api_nav.Select (parent);\r
+ bool matched = false;\r
+ while (parent_iter.MoveNext ()) {\r
+ XmlNode parent_node = ( (IHasXmlNode) parent_iter.Current).GetNode ();\r
+ XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);\r
+ while (path_iter.MoveNext ()) {\r
+ XmlNode node = ( (IHasXmlNode) path_iter.Current).GetNode ();\r
+ parent_node.AppendChild (node.Clone ());\r
+ node.ParentNode.RemoveChild (node);\r
+ }\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <move-node path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");\r
+ while (rmv_iter.MoveNext ()) {\r
+ string path = rmv_iter.Current.GetAttribute ("path", "");\r
+ XPathNodeIterator api_iter = api_nav.Select (path);\r
+ bool matched = false;\r
+ while (api_iter.MoveNext ()) {\r
+ XmlElement api_node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;\r
+ api_node.ParentNode.RemoveChild (api_node);\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <remove-node path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ XPathNodeIterator add_iter = meta_nav.Select ("/metadata/add-node");\r
+ while (add_iter.MoveNext ()) {\r
+ string path = add_iter.Current.GetAttribute ("path", "");\r
+ XPathNodeIterator api_iter = api_nav.Select (path);\r
+ bool matched = false;\r
+ while (api_iter.MoveNext ()) {\r
+ XmlElement api_node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;\r
+ foreach (XmlNode child in ( (IHasXmlNode) add_iter.Current).GetNode().ChildNodes)\r
+ api_node.AppendChild (api_doc.ImportNode (child, true));\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <add-node path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ XPathNodeIterator attr_iter = meta_nav.Select ("/metadata/attr");\r
+ while (attr_iter.MoveNext ()) {\r
+ string path = attr_iter.Current.GetAttribute ("path", "");\r
+ string attr_name = attr_iter.Current.GetAttribute ("name", "");\r
+ XPathNodeIterator api_iter = api_nav.Select (path);\r
+ bool matched = false;\r
+ while (api_iter.MoveNext ()) {\r
+ XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;\r
+ node.SetAttribute (attr_name, attr_iter.Current.Value);\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <attr path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ XPathNodeIterator remove_attr_iter = meta_nav.Select ("/metadata/remove-attr");\r
+ while (remove_attr_iter.MoveNext ()) {\r
+ string path = remove_attr_iter.Current.GetAttribute ("path", "");\r
+ string name = remove_attr_iter.Current.GetAttribute ("name", "");\r
+ XPathNodeIterator api_iter = api_nav.Select (path);\r
+ bool matched = false;\r
+ while (api_iter.MoveNext ()) {\r
+ XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;\r
+\r
+ node.RemoveAttribute (name);\r
+ matched = true;\r
+ }\r
+ if (!matched)\r
+ Console.WriteLine ("Warning: <remove-attr path=\"{0}\"/> matched no nodes", path);\r
+ }\r
+\r
+ if (symbol_doc != null) {\r
+ XPathNavigator symbol_nav = symbol_doc.CreateNavigator ();\r
+ XPathNodeIterator iter = symbol_nav.Select ("/api/*");\r
+ while (iter.MoveNext ()) {\r
+ XmlNode sym_node = ( (IHasXmlNode) iter.Current).GetNode ();\r
+ XPathNodeIterator parent_iter = api_nav.Select ("/api");\r
+ if (parent_iter.MoveNext ()) {\r
+ XmlNode parent_node = ( (IHasXmlNode) parent_iter.Current).GetNode ();\r
+ parent_node.AppendChild (api_doc.ImportNode (sym_node, true));\r
+ }\r
+ }\r
+ }\r
+\r
+ api_doc.Save (api_filename);\r
+ return 0;\r
+ }\r
+ }\r
}\r