[gst-cvs] gstreamer-sharp: Fix Gst.Bin bindings and add bindings for the iterators

Sebastian Dröge slomo at kemper.freedesktop.org
Fri May 1 08:11:41 PDT 2009


Module: gstreamer-sharp
Branch: master
Commit: 29f25c326d719e7b955af28844d3c8f0b5e10288
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer-sharp/commit/?id=29f25c326d719e7b955af28844d3c8f0b5e10288

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Fri May  1 17:08:07 2009 +0200

Fix Gst.Bin bindings and add bindings for the iterators

---

 gstreamer-sharp/Bin.custom         |  173 ++++++++++++++++++++++++++++++------
 gstreamer-sharp/Gstreamer.metadata |   13 ++-
 gstreamer-sharp/glue/Makefile.am   |    1 -
 gstreamer-sharp/glue/bin.c         |   11 ---
 4 files changed, 155 insertions(+), 43 deletions(-)

diff --git a/gstreamer-sharp/Bin.custom b/gstreamer-sharp/Bin.custom
index b8dc132..2d1e4b2 100644
--- a/gstreamer-sharp/Bin.custom
+++ b/gstreamer-sharp/Bin.custom
@@ -1,28 +1,3 @@
-
-[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 ("gstreamer-0.10.dll") ]
 static extern bool gst_bin_add (IntPtr raw, IntPtr element);
 
@@ -39,7 +14,7 @@ public bool Add (Gst.Element element) {
   return ret;
 }
 
-public bool AddMany (params Element[] elements) {
+public bool Add (params Element[] elements) {
   if (elements == null) {
     return false;
   }
@@ -53,7 +28,7 @@ public bool AddMany (params Element[] elements) {
   return true;
 }
 
-public bool RemoveMany (params Element[] elements) {
+public bool Remove (params Element[] elements) {
   if (elements == null) {
     return false;
   }
@@ -67,3 +42,147 @@ public bool RemoveMany (params Element[] elements) {
   return true;
 }
 
+public Gst.Element GetByInterface (System.Type type) {
+  if (!type.IsSubclassOf (typeof (GLib.GInterfaceAdapter)))
+    return null;
+
+  GLib.GType t = (GLib.GType) type;
+
+  return GetByInterface (t);
+}
+
+[DllImport ("gstreamer-0.10.dll") ]
+static extern int gst_iterator_next (IntPtr iterator, out IntPtr elem);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern void gst_iterator_resync (IntPtr iterator);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern void gst_iterator_free (IntPtr iterator);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_elements (IntPtr bin);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_recurse (IntPtr bin);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_sinks (IntPtr bin);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_sorted (IntPtr bin);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_sources (IntPtr bin);
+[DllImport ("gstreamer-0.10.dll") ]
+static extern IntPtr gst_bin_iterate_all_by_interface (IntPtr bin, IntPtr gtype);
+
+private class ElementEnumerable : IEnumerable {
+  private class ElementEnumerator : IEnumerator {
+    Hashtable seen = new Hashtable ();
+    IntPtr iterator;
+
+    private object current = null;
+    public object Current {
+      get {
+        return current;
+      }
+    }
+
+    public bool MoveNext () {
+      IntPtr raw_ret;
+      bool retry = false;
+
+      if (iterator == IntPtr.Zero)
+        return false;
+
+      do {
+        int ret = gst_iterator_next (iterator, out raw_ret);
+        switch (ret) {
+          case 0:
+            return false;
+          case 1:
+            if (seen.Contains (raw_ret)) {
+              retry = true;
+              break;
+            }
+
+            seen.Add (raw_ret, null);
+            current = GLib.Object.GetObject (raw_ret, true);
+            return true;
+          case 2:
+            gst_iterator_resync (iterator);
+            break;
+          default:
+          case 3:
+            throw new Exception ("Error while iterating bin");
+        }
+      } while (retry);
+
+      return false;
+    }
+
+    public void Reset () {
+      seen.Clear ();
+      if (iterator != IntPtr.Zero)
+        gst_iterator_resync (iterator);
+    }
+
+    public ElementEnumerator (IntPtr iterator) {
+      this.iterator = iterator;
+    }
+  }
+
+  private IntPtr iterator;
+  private ElementEnumerator enumerator;
+
+  public ElementEnumerable (IntPtr iterator) {
+    this.iterator = iterator;
+    this.enumerator = new ElementEnumerator (iterator);
+  }
+
+  public IEnumerator GetEnumerator () {
+    return enumerator;
+  }
+
+  ~ElementEnumerable () {
+    if (iterator != IntPtr.Zero)
+      gst_iterator_free (iterator);
+  }
+}
+
+public IEnumerable Elements {
+  get {
+    return new ElementEnumerable (gst_bin_iterate_elements (Handle));
+  }
+}
+
+public IEnumerable ElementsRecurse {
+  get {
+    return new ElementEnumerable (gst_bin_iterate_recurse (Handle));
+  }
+}
+
+public IEnumerable ElementsSorted {
+  get {
+    return new ElementEnumerable (gst_bin_iterate_sorted (Handle));
+  }
+}
+
+public IEnumerable SinkElements {
+  get {
+    return new ElementEnumerable (gst_bin_iterate_sinks (Handle));
+  }
+}
+
+public IEnumerable SourceElements {
+  get {
+    return new ElementEnumerable (gst_bin_iterate_sources (Handle));
+  }
+}
+
+public IEnumerable GetAllByInterface (GLib.GType type) {
+  return new ElementEnumerable (gst_bin_iterate_all_by_interface (Handle, type.Val));
+}
+
+public IEnumerable GetAllByInterface (System.Type type) {
+  if (!type.IsSubclassOf (typeof (GLib.GInterfaceAdapter)))
+    return null;
+
+  GLib.GType t = (GLib.GType) type;
+
+  return GetAllByInterface (t);
+}
diff --git a/gstreamer-sharp/Gstreamer.metadata b/gstreamer-sharp/Gstreamer.metadata
index 5888560..86c2f99 100644
--- a/gstreamer-sharp/Gstreamer.metadata
+++ b/gstreamer-sharp/Gstreamer.metadata
@@ -27,10 +27,15 @@
   <attr path="/api/namespace/*/field[@array_len='GST_PADDING - 3']" name="array_len">3</attr>
   <attr path="/api/namespace/*/field[@array_len='GST_PADDING - 4']" name="array_len">0</attr>
 
-  <attr path="/api/namespace/object[@name='Bin']/method[@name='AddMany']" name="hidden">1</attr>
-  <attr path="/api/namespace/object[@name='Bin']/method[@name='RemoveMany']" name="hidden">1</attr>
-  <attr path="/api/namespace/object[@name='Bin']/field[@name='Children']" name="hidden">1</attr>
-  <attr path="/api/namespace/object[@name='Bin']/method[@name='Add']" name="hidden">1</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_add_many']" name="hidden">1</attr>
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_remove_many']" name="hidden">1</attr>
+  <attr path="/api/namespace/object[@name='Bin']/field" name="hidden">1</attr>
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_add']" name="hidden">1</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_find_unconnected_pad']" name="hidden">1</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_get_by_name']/return-type" name="owned">true</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_get_by_name_recurse_up']/return-type" name="owned">true</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_get_by_interface']/return-type" name="owned">true</attr> 
+  <attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_find_unlinked_pad']/return-type" name="owned">true</attr> 
   <add-node path="/api/namespace/object[@name='Bin']">
     <implements>
       <interface cname="GstChildProxy" />
diff --git a/gstreamer-sharp/glue/Makefile.am b/gstreamer-sharp/glue/Makefile.am
index 2a583aa..b1aa8a8 100644
--- a/gstreamer-sharp/glue/Makefile.am
+++ b/gstreamer-sharp/glue/Makefile.am
@@ -7,7 +7,6 @@ libgstreamersharpglue_0_10_la_SOURCES =	\
 	clockentry.c	\
 	message.c \
 	event.c \
-	bin.c \
 	structure.c \
 	taglist.c \
 	task.c \
diff --git a/gstreamer-sharp/glue/bin.c b/gstreamer-sharp/glue/bin.c
deleted file mode 100644
index 20ccd38..0000000
--- a/gstreamer-sharp/glue/bin.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <gst/gstbin.h>
-#include <gst/gstpipeline.h>
-#include <gst/gstsegment.h>
-
-guint gstsharp_gst_bin_get_children_offset (void);
-
-guint
-gstsharp_gst_bin_get_children_offset (void)
-{
-  return (guint) G_STRUCT_OFFSET (GstBin, children);
-}





More information about the Gstreamer-commits mailing list