mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-02 14:36:41 +00:00
Replace custom Enumerable code with generator GstIterator bindings
The custom properties that return a IEnumerable are replaced by generated properties that return an Iterator. Most of the code in Iterator.cs has moved to Iterator.custom to implement IEnumerable.
This commit is contained in:
parent
7613c99e54
commit
663d3e047d
7 changed files with 92 additions and 180 deletions
|
@ -53,53 +53,6 @@ public Gst.Element GetByInterface (System.Type type) {
|
|||
return GetByInterface (t);
|
||||
}
|
||||
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_elements (IntPtr bin);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_recurse (IntPtr bin);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_sinks (IntPtr bin);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_sorted (IntPtr bin);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_sources (IntPtr bin);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_bin_iterate_all_by_interface (IntPtr bin, IntPtr gtype);
|
||||
|
||||
public IEnumerable Elements {
|
||||
get {
|
||||
return new Enumerable (gst_bin_iterate_elements (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable ElementsRecurse {
|
||||
get {
|
||||
return new Enumerable (gst_bin_iterate_recurse (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable ElementsSorted {
|
||||
get {
|
||||
return new Enumerable (gst_bin_iterate_sorted (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable SinkElements {
|
||||
get {
|
||||
return new Enumerable (gst_bin_iterate_sinks (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable SourceElements {
|
||||
get {
|
||||
return new Enumerable (gst_bin_iterate_sources (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable GetAllByInterface (GLib.GType type) {
|
||||
return new Enumerable (gst_bin_iterate_all_by_interface (Handle, type.Val));
|
||||
}
|
||||
|
||||
public IEnumerable GetAllByInterface (System.Type type) {
|
||||
if (!type.IsSubclassOf (typeof (GLib.GInterfaceAdapter)))
|
||||
return null;
|
||||
|
|
|
@ -25,31 +25,6 @@ public static void Unlink (params Element [] elements) {
|
|||
}
|
||||
}
|
||||
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_element_iterate_pads (IntPtr element);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_element_iterate_src_pads (IntPtr element);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_element_iterate_sink_pads (IntPtr element);
|
||||
|
||||
public IEnumerable Pads {
|
||||
get {
|
||||
return new Enumerable (gst_element_iterate_pads (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable SinkPads {
|
||||
get {
|
||||
return new Enumerable (gst_element_iterate_sink_pads (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable SrcPads {
|
||||
get {
|
||||
return new Enumerable (gst_element_iterate_src_pads (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
public Gst.StateChangeReturn GetState (out Gst.State state, ulong timeout) {
|
||||
Gst.State pending;
|
||||
return GetState (out state, out pending, timeout);
|
||||
|
|
|
@ -45,6 +45,12 @@
|
|||
<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>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_elements']" name="name">GetElements</attr>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_sinks']" name="name">GetSinkElements</attr>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_sources']" name="name">GetSourceElements</attr>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_sorted']" name="name">GetElementsSorted</attr>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_recurse']" name="name">GetElementsRecurse</attr>
|
||||
<attr path="/api/namespace/object[@name='Bin']/method[@cname='gst_bin_iterate_all_by_interface']" name="name">GetAllByInterface</attr>
|
||||
<add-node path="/api/namespace/object[@name='Bin']">
|
||||
<implements>
|
||||
<interface cname="GstChildProxy" />
|
||||
|
@ -305,6 +311,9 @@
|
|||
<remove-attr path="/api/namespace/object[@name='Element']/field[@name='CurrentState']" name="hidden"/>
|
||||
<move-node path="/api/namespace/object[@name='Element']/method[@cname='gst_element_make_from_uri']">/api/namespace/object[@name='ElementFactory']</move-node>
|
||||
<move-node path="/api/namespace/object[@name='Element']/method[@cname='gst_element_register']">/api/namespace/object[@name='ElementFactory']</move-node>
|
||||
<attr path="/api/namespace/object[@name='Element']/method[@cname='gst_element_iterate_pads']" name="name">GetPads</attr>
|
||||
<attr path="/api/namespace/object[@name='Element']/method[@cname='gst_element_iterate_src_pads']" name="name">GetSrcPads</attr>
|
||||
<attr path="/api/namespace/object[@name='Element']/method[@cname='gst_element_iterate_sink_pads']" name="name">GetSinkPads</attr>
|
||||
|
||||
<attr path="/api/namespace/struct[@name='ElementDetails']" name="internal">1</attr>
|
||||
|
||||
|
@ -472,6 +481,11 @@
|
|||
<attr path="/api/namespace/callback[@name='IndexResolver']/parameters/parameter[@name='writer_string']" name="pass_as">out</attr>
|
||||
|
||||
<attr path="/api/namespace/class[@name='Iterator']" name="hidden">1</attr>
|
||||
<add-node path="/api/namespace[@name='Gst']">
|
||||
<struct name="Iterator" cname="GstIterator" opaque="true">
|
||||
<implements><interface name="IEnumerable" /></implements>
|
||||
</struct>
|
||||
</add-node>
|
||||
|
||||
<remove-node path="/api/namespace/class[@name='Init']" />
|
||||
|
||||
|
@ -587,9 +601,9 @@
|
|||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_set_query_type_function']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_get_query_types']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_get_query_types_default']" name="hidden">1</attr>
|
||||
<!-- FIXME: GstIterator* binding missing -->
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_set_iterate_internal_links_function']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_iterate_internal_links']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_iterate_internal_links_default']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@name='Pad']/method[@cname='gst_pad_iterate_internal_links']" name="name">GetInternalLinks</attr>
|
||||
<add-node path="/api/namespace[@name='Gst']">
|
||||
<callback name="PadQueryTypeFunction" cname="GstPadQueryTypeFunction" hidden="1">
|
||||
<return-type type="const-GstQueryType*" />
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
using GLib;
|
||||
|
||||
namespace Gst {
|
||||
|
||||
internal class Enumerable : IEnumerable {
|
||||
private class Enumerator : IEnumerator {
|
||||
Enumerable enumerable;
|
||||
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);
|
||||
retry = true;
|
||||
break;
|
||||
default:
|
||||
case 3:
|
||||
throw new Exception ("Error while iterating pads");
|
||||
}
|
||||
} while (retry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset () {
|
||||
seen.Clear ();
|
||||
if (iterator != IntPtr.Zero)
|
||||
gst_iterator_resync (iterator);
|
||||
}
|
||||
|
||||
public Enumerator (Enumerable enumerable, IntPtr iterator) {
|
||||
this.enumerable = enumerable;
|
||||
this.iterator = iterator;
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr iterator;
|
||||
private Enumerator enumerator;
|
||||
|
||||
public Enumerable (IntPtr iterator) {
|
||||
this.iterator = iterator;
|
||||
this.enumerator = new Enumerator (this, iterator);
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator () {
|
||||
return this.enumerator;
|
||||
}
|
||||
|
||||
~Enumerable () {
|
||||
if (iterator != IntPtr.Zero)
|
||||
gst_iterator_free (iterator);
|
||||
}
|
||||
|
||||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern int gst_iterator_next (IntPtr iterator, out IntPtr elem);
|
||||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern void gst_iterator_resync (IntPtr iterator);
|
||||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern void gst_iterator_free (IntPtr iterator);
|
||||
|
||||
}
|
||||
}
|
75
gstreamer-sharp/Iterator.custom
Executable file
75
gstreamer-sharp/Iterator.custom
Executable file
|
@ -0,0 +1,75 @@
|
|||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern int gst_iterator_next (IntPtr iterator, out IntPtr elem);
|
||||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern void gst_iterator_resync (IntPtr iterator);
|
||||
|
||||
private class Enumerator : IEnumerator {
|
||||
Iterator iterator;
|
||||
Hashtable seen = new Hashtable ();
|
||||
|
||||
private object current = null;
|
||||
public object Current {
|
||||
get {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext () {
|
||||
IntPtr raw_ret;
|
||||
bool retry = false;
|
||||
|
||||
if (iterator.Handle == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
do {
|
||||
int ret = gst_iterator_next (iterator.Handle, 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.Handle);
|
||||
retry = true;
|
||||
break;
|
||||
default:
|
||||
case 3:
|
||||
throw new Exception ("Error while iterating pads");
|
||||
}
|
||||
} while (retry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset () {
|
||||
seen.Clear ();
|
||||
if (iterator.Handle != IntPtr.Zero)
|
||||
gst_iterator_resync (iterator.Handle);
|
||||
}
|
||||
|
||||
public Enumerator (Iterator iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
}
|
||||
|
||||
private Enumerator enumerator = null;
|
||||
|
||||
public IEnumerator GetEnumerator () {
|
||||
if (this.enumerator == null)
|
||||
this.enumerator = new Enumerator (this);
|
||||
return this.enumerator;
|
||||
}
|
||||
|
||||
[DllImport ("libgstreamer-0.10.dll") ]
|
||||
static extern void gst_iterator_free (IntPtr iterator);
|
||||
|
||||
~Iterator () {
|
||||
if (Raw != IntPtr.Zero)
|
||||
gst_iterator_free (Raw);
|
||||
}
|
|
@ -45,7 +45,6 @@ sources = \
|
|||
Value.cs \
|
||||
PropertyInfo.cs \
|
||||
EnumInfo.cs \
|
||||
Iterator.cs \
|
||||
MiniObject.cs \
|
||||
Marshaller.cs \
|
||||
GstSharp.PadQueryTypeFunctionNative.cs \
|
||||
|
@ -103,6 +102,7 @@ customs = \
|
|||
IndexEntry.custom \
|
||||
Index.custom \
|
||||
IndexFactory.custom \
|
||||
Iterator.custom \
|
||||
Registry.custom \
|
||||
Query.custom \
|
||||
Structure.custom \
|
||||
|
|
|
@ -361,16 +361,3 @@ public void StreamUnlock (uint depth) {
|
|||
public bool StreamTryLock () {
|
||||
return g_static_rec_mutex_trylock (StreamLockPtr);
|
||||
}
|
||||
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_pad_iterate_internal_links (IntPtr pad);
|
||||
[DllImport("libgstreamer-0.10.dll") ]
|
||||
static extern IntPtr gst_pad_iterate_internal_links_default (IntPtr pad);
|
||||
|
||||
|
||||
public IEnumerable InternalLinks {
|
||||
get {
|
||||
return new Enumerable (gst_pad_iterate_internal_links (Handle));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue