2009-05-09 17:29:40 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using GLib;
|
|
|
|
|
|
|
|
namespace Gst {
|
|
|
|
|
|
|
|
internal class Enumerable : IEnumerable {
|
|
|
|
private class Enumerator : IEnumerator {
|
2009-05-27 12:56:42 +00:00
|
|
|
Enumerable enumerable;
|
2009-05-09 17:29:40 +00:00
|
|
|
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);
|
2009-05-20 15:29:36 +00:00
|
|
|
retry = true;
|
2009-05-09 17:29:40 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-05-27 12:56:42 +00:00
|
|
|
public Enumerator (Enumerable enumerable, IntPtr iterator) {
|
|
|
|
this.enumerable = enumerable;
|
2009-05-09 17:29:40 +00:00
|
|
|
this.iterator = iterator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IntPtr iterator;
|
|
|
|
private Enumerator enumerator;
|
|
|
|
|
|
|
|
public Enumerable (IntPtr iterator) {
|
|
|
|
this.iterator = iterator;
|
2009-05-27 12:56:42 +00:00
|
|
|
this.enumerator = new Enumerator (this, iterator);
|
2009-05-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator GetEnumerator () {
|
2009-05-27 12:56:42 +00:00
|
|
|
return this.enumerator;
|
2009-05-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Enumerable () {
|
|
|
|
if (iterator != IntPtr.Zero)
|
|
|
|
gst_iterator_free (iterator);
|
|
|
|
}
|
|
|
|
|
2009-05-27 12:56:42 +00:00
|
|
|
[DllImport ("libgstreamer-0.10.dll") ]
|
2009-05-09 17:29:40 +00:00
|
|
|
static extern int gst_iterator_next (IntPtr iterator, out IntPtr elem);
|
2009-05-27 12:56:42 +00:00
|
|
|
[DllImport ("libgstreamer-0.10.dll") ]
|
2009-05-09 17:29:40 +00:00
|
|
|
static extern void gst_iterator_resync (IntPtr iterator);
|
2009-05-27 12:56:42 +00:00
|
|
|
[DllImport ("libgstreamer-0.10.dll") ]
|
2009-05-09 17:29:40 +00:00
|
|
|
static extern void gst_iterator_free (IntPtr iterator);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|