gstreamer/gstreamer-sharp/Clock.custom
2009-04-27 12:08:40 +02:00

152 lines
4.1 KiB
Text

public static readonly ulong Second = 1000000000;
public static readonly ulong MSecond = 1000000;
public static readonly ulong USecond = 1000;
public static readonly ulong NSecond = 1;
public static readonly ulong TimeNone = 0xffffffffffffffff;
public static bool TimeIsValid (ulong time) {
return (time != TimeNone);
}
[DllImport ("gstreamersharpglue-0.10") ]
extern static uint gstsharp_gst_clock_get_entries_changed_offset ();
static uint entries_changed_offset = gstsharp_gst_clock_get_entries_changed_offset ();
private IntPtr EntriesChangedPtr {
get {
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + entries_changed_offset);
return (*raw_ptr);
}
}
}
[DllImport ("libglib-2.0-0.dll") ]
static extern void g_cond_wait (IntPtr cond, IntPtr mutex);
[DllImport ("libglib-2.0-0.dll") ]
static extern bool g_cond_timed_wait (IntPtr cond, IntPtr mutex, ref _TimeVal abs_time);
[DllImport ("libglib-2.0-0.dll") ]
static extern void g_cond_broadcast (IntPtr cond);
public void Wait () {
g_cond_wait (EntriesChangedPtr, LockPtr);
}
[StructLayout (LayoutKind.Sequential) ]
private struct _TimeVal {
public IntPtr sec;
public IntPtr usec;
}
public bool Wait (uint mseconds) {
_TimeVal tv = new _TimeVal ();
long sec = mseconds / 1000;
long usec = 1000 * (mseconds - sec * 1000);
tv.sec = (IntPtr) (sec);
tv.usec = (IntPtr) (usec);
return g_cond_timed_wait (EntriesChangedPtr, LockPtr, ref tv);
}
public bool Wait (TimeSpan timespan) {
_TimeVal tv = new _TimeVal ();
long sec = (long) timespan.TotalSeconds;
long usec = 1000 * ( ( (long) timespan.TotalMilliseconds) - sec * 1000);
tv.sec = (IntPtr) (sec);
tv.usec = (IntPtr) (usec);
return g_cond_timed_wait (EntriesChangedPtr, LockPtr, ref tv);
}
public void Broadcast () {
g_cond_broadcast (EntriesChangedPtr);
}
[DllImport ("gstreamersharpglue-0.10") ]
extern static uint gstsharp_gst_clock_get_slave_lock_offset ();
static uint slave_lock_offset = gstsharp_gst_clock_get_slave_lock_offset ();
private IntPtr SlaveLockPtr {
get {
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + slave_lock_offset);
return (*raw_ptr);
}
}
}
[DllImport ("libglib-2.0-0.dll") ]
static extern void g_mutex_lock (IntPtr mutex);
[DllImport ("libglib-2.0-0.dll") ]
static extern void g_mutex_unlock (IntPtr mutex);
[DllImport ("libglib-2.0-0.dll") ]
static extern bool g_mutex_trylock (IntPtr mutex);
public void SlaveLock () {
g_mutex_lock (SlaveLockPtr);
}
public void SlaveUnlock () {
g_mutex_unlock (SlaveLockPtr);
}
public bool TrySlaveLock () {
return g_mutex_trylock (SlaveLockPtr);
}
[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_clock_get_master (IntPtr raw);
[DllImport ("gstreamer-0.10.dll") ]
static extern bool gst_clock_set_master (IntPtr raw, IntPtr master);
public Gst.Clock Master {
get {
IntPtr raw_ret = gst_clock_get_master (Handle);
Gst.Clock ret = GLib.Object.GetObject (raw_ret, true) as Gst.Clock;
return ret;
}
set {
if (!gst_clock_set_master (Handle, value == null ? IntPtr.Zero : value.Handle))
throw new Exception ();
}
}
[DllImport ("gstreamersharpglue-0.10") ]
extern static uint gstsharp_gst_clock_get_entries_offset ();
static uint entries_offset = gstsharp_gst_clock_get_entries_offset ();
private IntPtr EntriesPtr {
get {
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + entries_offset);
return (*raw_ptr);
}
}
}
protected Gst.ClockEntry[] Entries {
get {
return (Gst.ClockEntry[]) GLib.Marshaller.ListPtrToArray (EntriesPtr, typeof (GLib.List), false, false, typeof (Gst.ClockEntry));
}
}
[DllImport ("gstreamersharpglue-0.10") ]
extern static uint gstsharp_gst_clock_get_times_offset ();
static uint times_offset = gstsharp_gst_clock_get_times_offset ();
private IntPtr TimesPtr {
get {
unsafe {
IntPtr* raw_ptr = (IntPtr*) ( ( (byte*) Handle) + times_offset);
return (*raw_ptr);
}
}
}
protected ulong[] Times {
get {
ulong[] ret = new ulong[4 * WindowSize];
for (int i = 0; i < 4 * WindowSize; i++)
ret[i] = (ulong) Marshal.ReadInt64 (TimesPtr, 8 * i);
return ret;
}
}