Skip to content

Commit

Permalink
feat(sdk): implement Timestamp API
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Nov 1, 2020
1 parent 8df15b4 commit f647755
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 0 deletions.
121 changes: 121 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/Framework/Timestamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Runtime.InteropServices;

namespace Mediapipe {
public class Timestamp : MpResourceHandle {
public Timestamp(IntPtr ptr) : base(ptr) {}

public Timestamp(Int64 value) : base() {
UnsafeNativeMethods.mp_Timestamp__l(value, out var ptr);
this.ptr = ptr;
}

protected override void DisposeUnmanaged() {
if (OwnsResource()) {
UnsafeNativeMethods.mp_Timestamp__delete(ptr);
}
base.DisposeUnmanaged();
}

public Int64 Value() {
return SafeNativeMethods.mp_Timestamp__Value(mpPtr);
}

public double Seconds() {
return SafeNativeMethods.mp_Timestamp__Seconds(mpPtr);
}

public Int64 Microseconds() {
return SafeNativeMethods.mp_Timestamp__Microseconds(mpPtr);
}

public bool IsSpecialValue() {
return SafeNativeMethods.mp_Timestamp__IsSpecialValue(mpPtr);
}

public bool IsRangeValue() {
return SafeNativeMethods.mp_Timestamp__IsRangeValue(mpPtr);
}

public bool IsAllowedInStream() {
return SafeNativeMethods.mp_Timestamp__IsAllowedInStream(mpPtr);
}

public string DebugString() {
UnsafeNativeMethods.mp_Timestamp__DebugString(mpPtr, out var strPtr).Assert();
var str = Marshal.PtrToStringAnsi(strPtr);
UnsafeNativeMethods.delete_array__PKc(strPtr);

GC.KeepAlive(this);
return str;
}

public Timestamp NextAllowedInStream() {
UnsafeNativeMethods.mp_Timestamp__NextAllowedInStream(mpPtr, out var nextPtr).Assert();

GC.KeepAlive(this);
return new Timestamp(nextPtr);
}

public Timestamp PreviousAllowedInStream() {
UnsafeNativeMethods.mp_Timestamp__PreviousAllowedInStream(mpPtr, out var prevPtr).Assert();

GC.KeepAlive(this);
return new Timestamp(prevPtr);
}

public static Timestamp FromSeconds(double seconds) {
UnsafeNativeMethods.mp_Timestamp_FromSeconds__d(seconds, out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp Unset() {
UnsafeNativeMethods.mp_Timestamp_Unset(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp Unstarted() {
UnsafeNativeMethods.mp_Timestamp_Unstarted(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp PreStream() {
UnsafeNativeMethods.mp_Timestamp_PreStream(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp Min() {
UnsafeNativeMethods.mp_Timestamp_Min(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp Max() {
UnsafeNativeMethods.mp_Timestamp_Max(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp PostStream() {
UnsafeNativeMethods.mp_Timestamp_PostStream(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp OneOverPostStream() {
UnsafeNativeMethods.mp_Timestamp_OneOverPostStream(out var ptr).Assert();

return new Timestamp(ptr);
}

public static Timestamp Done() {
UnsafeNativeMethods.mp_Timestamp_Done(out var ptr).Assert();

return new Timestamp(ptr);
}
}
}
11 changes: 11 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/Framework/Timestamp.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;

namespace Mediapipe {
internal static partial class SafeNativeMethods {
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern Int64 mp_Timestamp__Value(IntPtr timestamp);

[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern double mp_Timestamp__Seconds(IntPtr timestamp);

[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern Int64 mp_Timestamp__Microseconds(IntPtr timestamp);

[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_Timestamp__IsSpecialValue(IntPtr timestamp);

[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_Timestamp__IsRangeValue(IntPtr timestamp);

[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool mp_Timestamp__IsAllowedInStream(IntPtr timestamp);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Runtime.InteropServices;

namespace Mediapipe {
internal static partial class UnsafeNativeMethods {
[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp__l(Int64 value, out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern void mp_Timestamp__delete(IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp__DebugString(IntPtr timestamp, out IntPtr str);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp__NextAllowedInStream(IntPtr timestamp, out IntPtr nextTimestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp__PreviousAllowedInStream(IntPtr timestamp, out IntPtr prevTimestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_FromSeconds__d(double seconds, out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_Unset(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_Unstarted(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_PreStream(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_Min(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_Max(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_PostStream(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_OneOverPostStream(out IntPtr timestamp);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Timestamp_Done(out IntPtr timestamp);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f647755

Please sign in to comment.