Wes xx mediapipe integration

This commit is contained in:
Jelle De Geest
2023-03-12 20:34:16 +00:00
parent 8349b5f149
commit b11eeb465c
975 changed files with 192230 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f21484d7914a56a4abbcfaf9dc525c77
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
/// based on [OpenCvSharp](https://github.com/shimat/opencvsharp/blob/9a5f9828a74cfa3995562a06716e177705cde038/src/OpenCvSharp/Fundamentals/DisposableObject.cs)
using System;
using System.Threading;
namespace Mediapipe
{
public abstract class DisposableObject : IDisposable
{
private volatile int _disposeSignaled = 0;
public bool isDisposed { get; protected set; }
protected bool isOwner { get; private set; }
protected DisposableObject() : this(true) { }
protected DisposableObject(bool isOwner)
{
isDisposed = false;
this.isOwner = isOwner;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (Interlocked.Exchange(ref _disposeSignaled, 1) != 0)
{
return;
}
isDisposed = true;
if (disposing)
{
DisposeManaged();
}
DisposeUnmanaged();
}
~DisposableObject()
{
Dispose(false);
}
protected virtual void DisposeManaged() { }
protected virtual void DisposeUnmanaged() { }
public void TransferOwnership()
{
isOwner = false;
}
public void ThrowIfDisposed()
{
if (isDisposed)
{
throw new ObjectDisposedException(GetType().FullName);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e9bf4260db1fcf38d9ab2123b9b848aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public interface IMpResourceHandle : IDisposable
{
IntPtr mpPtr { get; }
/// <summary>
/// Relinquish the ownership, and release the resource it owns if necessary.
/// This method should be called only if the underlying native api moves the pointer.
/// </summary>
/// <remarks>If the object itself is no longer used, call <see cref="Dispose" /> instead.</remarks>
void ReleaseMpResource();
/// <summary>Relinquish the ownership</summary>
void TransferOwnership();
bool OwnsResource();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5d6d5b8194184fe7bf9b284a3d1d76c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class InternalException : Exception
{
public InternalException(string message) : base(message) { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c01fc4de4ae037a79dab98092851538
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class MediaPipeException : Exception
{
public MediaPipeException(string message) : base(message) { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 09e5bf77632ac85288dacb5b5445e9ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class MediaPipePluginException : Exception
{
public MediaPipePluginException(string message) : base(message) { }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e17a1d893e9d74c4eb7e85860d115c02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe
{
public abstract class MpResourceHandle : DisposableObject, IMpResourceHandle
{
private IntPtr _ptr = IntPtr.Zero;
protected IntPtr ptr
{
get => _ptr;
set
{
if (value != IntPtr.Zero && OwnsResource())
{
throw new InvalidOperationException($"This object owns another resource");
}
_ptr = value;
}
}
protected MpResourceHandle(bool isOwner = true) : this(IntPtr.Zero, isOwner) { }
protected MpResourceHandle(IntPtr ptr, bool isOwner = true) : base(isOwner)
{
this.ptr = ptr;
}
#region IMpResourceHandle
public IntPtr mpPtr
{
get
{
ThrowIfDisposed();
return ptr;
}
}
public void ReleaseMpResource()
{
if (OwnsResource())
{
DeleteMpPtr();
}
ReleaseMpPtr();
TransferOwnership();
}
public bool OwnsResource()
{
return isOwner && IsResourcePresent();
}
#endregion
protected override void DisposeUnmanaged()
{
if (OwnsResource())
{
DeleteMpPtr();
}
ReleaseMpPtr();
base.DisposeUnmanaged();
}
/// <summary>
/// Forgets the pointer address.
/// After calling this method, <see ref="OwnsResource" /> will return false.
/// </summary>
protected void ReleaseMpPtr()
{
ptr = IntPtr.Zero;
}
/// <summary>
/// Release the memory (call `delete` or `delete[]`) whether or not it owns it.
/// </summary>
/// <remarks>In most cases, this method should not be called directly</remarks>
protected abstract void DeleteMpPtr();
protected delegate MpReturnCode StringOutFunc(IntPtr ptr, out IntPtr strPtr);
protected string MarshalStringFromNative(StringOutFunc f)
{
f(mpPtr, out var strPtr).Assert();
GC.KeepAlive(this);
var str = Marshal.PtrToStringAnsi(strPtr);
UnsafeNativeMethods.delete_array__PKc(strPtr);
return str;
}
protected bool IsResourcePresent()
{
return ptr != IntPtr.Zero;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63faa26aefbc969038939ad114363133
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public abstract class SharedPtrHandle : MpResourceHandle
{
protected SharedPtrHandle(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
/// <returns>The owning pointer</returns>
public abstract IntPtr Get();
/// <summary>Release the owning pointer</summary>
public abstract void Reset();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90b1644d510da0d46a0db08fd07d3c49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public abstract class UniquePtrHandle : MpResourceHandle
{
protected UniquePtrHandle(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
/// <returns>The owning pointer</returns>
public abstract IntPtr Get();
/// <summary>Release the owning pointer</summary>
public abstract IntPtr Release();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d0d5e05b9407fab79fe7814143e1fe6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce49803463ef3a0449a99d42aaaddc74
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public static class Glog
{
public enum Severity : int
{
INFO = 0,
WARNING = 1,
ERROR = 2,
FATAL = 3,
}
private static bool _Logtostderr = false;
public static bool Logtostderr
{
get => _Logtostderr;
set
{
UnsafeNativeMethods.glog_FLAGS_logtostderr(value);
_Logtostderr = value;
}
}
private static int _Stderrthreshold = 2;
public static int Stderrthreshold
{
get => _Stderrthreshold;
set
{
UnsafeNativeMethods.glog_FLAGS_stderrthreshold(value);
_Stderrthreshold = value;
}
}
private static int _Minloglevel = 0;
public static int Minloglevel
{
get => _Minloglevel;
set
{
UnsafeNativeMethods.glog_FLAGS_minloglevel(value);
_Minloglevel = value;
}
}
private static string _LogDir;
public static string LogDir
{
get => _LogDir;
set
{
UnsafeNativeMethods.glog_FLAGS_log_dir(value ?? "");
_LogDir = value;
}
}
private static int _V = 0;
public static int V
{
get => _V;
set
{
UnsafeNativeMethods.glog_FLAGS_v(value);
_V = value;
}
}
public static void Initialize(string name)
{
UnsafeNativeMethods.google_InitGoogleLogging__PKc(name).Assert();
}
public static void Shutdown()
{
UnsafeNativeMethods.google_ShutdownGoogleLogging().Assert();
}
public static void Log(Severity severity, string str)
{
switch (severity)
{
case Severity.INFO:
{
UnsafeNativeMethods.glog_LOG_INFO__PKc(str);
break;
}
case Severity.WARNING:
{
UnsafeNativeMethods.glog_LOG_WARNING__PKc(str);
break;
}
case Severity.ERROR:
{
UnsafeNativeMethods.glog_LOG_ERROR__PKc(str);
break;
}
case Severity.FATAL:
{
UnsafeNativeMethods.glog_LOG_FATAL__PKc(str);
break;
}
default:
{
throw new ArgumentException($"Unknown Severity: {severity}");
}
}
}
public static void FlushLogFiles(Severity severity = Severity.INFO)
{
UnsafeNativeMethods.google_FlushLogFiles(severity);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 86fef837b136593f2b178163cdc337b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
namespace Mediapipe
{
public static class Protobuf
{
public delegate void LogHandler(int level, string filename, int line, string message);
public static readonly LogHandler DefaultLogHandler = LogProtobufMessage;
public static void SetLogHandler(LogHandler logHandler)
{
UnsafeNativeMethods.google_protobuf__SetLogHandler__PF(logHandler).Assert();
}
/// <summary>
/// Reset the <see cref="LogHandler" />.
/// If <see cref="SetLogHandler" /> is called, this method should be called before the program exits.
/// </summary>
public static void ResetLogHandler()
{
UnsafeNativeMethods.google_protobuf__ResetLogHandler().Assert();
}
[AOT.MonoPInvokeCallback(typeof(LogHandler))]
private static void LogProtobufMessage(int level, string filename, int line, string message)
{
switch (level)
{
case 1:
{
UnityEngine.Debug.LogWarning($"[libprotobuf WARNING {filename}:{line}] {message}");
return;
}
case 2:
{
UnityEngine.Debug.LogError($"[libprotobuf ERROR {filename}:{line}] {message}");
return;
}
case 3:
{
UnityEngine.Debug.LogError($"[libprotobuf FATAL {filename}:{line}] {message}");
return;
}
default:
{
UnityEngine.Debug.Log($"[libprotobuf INFO {filename}:{line}] {message}");
return;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c258e2200c807137bb781aa54c9c8a3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Runtime.InteropServices;
using pb = Google.Protobuf;
namespace Mediapipe
{
[StructLayout(LayoutKind.Sequential)]
internal readonly struct SerializedProto
{
private readonly IntPtr _str;
private readonly int _length;
public void Dispose()
{
UnsafeNativeMethods.delete_array__PKc(_str);
}
public T Deserialize<T>(pb::MessageParser<T> parser) where T : pb::IMessage<T>
{
var bytes = new byte[_length];
Marshal.Copy(_str, bytes, 0, bytes.Length);
return parser.ParseFrom(bytes);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8d10ad9609f7ff51963ca10e709bba5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using pb = Google.Protobuf;
namespace Mediapipe
{
[StructLayout(LayoutKind.Sequential)]
internal readonly struct SerializedProtoVector
{
private readonly IntPtr _data;
private readonly int _size;
public void Dispose()
{
UnsafeNativeMethods.mp_api_SerializedProtoArray__delete(_data, _size);
}
public List<T> Deserialize<T>(pb::MessageParser<T> parser) where T : pb::IMessage<T>
{
var protos = new List<T>(_size);
unsafe
{
var protoPtr = (SerializedProto*)_data;
for (var i = 0; i < _size; i++)
{
var serializedProto = Marshal.PtrToStructure<SerializedProto>((IntPtr)protoPtr++);
protos.Add(serializedProto.Deserialize(parser));
}
}
return protos;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d42fce9f6c3543838b1c20085f531c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class StdString : MpResourceHandle
{
public StdString(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public StdString(byte[] bytes) : base()
{
UnsafeNativeMethods.std_string__PKc_i(bytes, bytes.Length, out var ptr).Assert();
this.ptr = ptr;
}
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.std_string__delete(ptr);
}
public void Swap(StdString str)
{
UnsafeNativeMethods.std_string__swap__Rstr(mpPtr, str.mpPtr);
GC.KeepAlive(this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3cb68ad64fa60ce26874036c880a55a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1253c8fbe82b7704f868091ebe91f900
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,231 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Runtime.InteropServices;
using Google.Protobuf;
namespace Mediapipe
{
public class CalculatorGraph : MpResourceHandle
{
public delegate Status.StatusArgs NativePacketCallback(IntPtr graphPtr, int streamId, IntPtr packetPtr);
public delegate void PacketCallback<TPacket, TValue>(TPacket packet) where TPacket : Packet<TValue>;
public CalculatorGraph() : base()
{
UnsafeNativeMethods.mp_CalculatorGraph__(out var ptr).Assert();
this.ptr = ptr;
}
private CalculatorGraph(byte[] serializedConfig) : base()
{
UnsafeNativeMethods.mp_CalculatorGraph__PKc_i(serializedConfig, serializedConfig.Length, out var ptr).Assert();
this.ptr = ptr;
}
public CalculatorGraph(CalculatorGraphConfig config) : this(config.ToByteArray()) { }
public CalculatorGraph(string textFormatConfig) : this(CalculatorGraphConfig.Parser.ParseFromTextFormat(textFormatConfig)) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_CalculatorGraph__delete(ptr);
}
public Status Initialize(CalculatorGraphConfig config)
{
var bytes = config.ToByteArray();
UnsafeNativeMethods.mp_CalculatorGraph__Initialize__PKc_i(mpPtr, bytes, bytes.Length, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status Initialize(CalculatorGraphConfig config, SidePacket sidePacket)
{
var bytes = config.ToByteArray();
UnsafeNativeMethods.mp_CalculatorGraph__Initialize__PKc_i_Rsp(mpPtr, bytes, bytes.Length, sidePacket.mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
/// <remarks>Crashes if config is not set</remarks>
public CalculatorGraphConfig Config()
{
UnsafeNativeMethods.mp_CalculatorGraph__Config(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var config = serializedProto.Deserialize(CalculatorGraphConfig.Parser);
serializedProto.Dispose();
return config;
}
public Status ObserveOutputStream(string streamName, int streamId, NativePacketCallback nativePacketCallback, bool observeTimestampBounds = false)
{
UnsafeNativeMethods.mp_CalculatorGraph__ObserveOutputStream__PKc_PF_b(mpPtr, streamName, streamId, nativePacketCallback, observeTimestampBounds, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status ObserveOutputStream<TPacket, TValue>(string streamName, PacketCallback<TPacket, TValue> packetCallback, bool observeTimestampBounds, out GCHandle callbackHandle) where TPacket : Packet<TValue>, new()
{
NativePacketCallback nativePacketCallback = (IntPtr graphPtr, int streamId, IntPtr packetPtr) =>
{
try
{
var packet = Packet<TValue>.Create<TPacket>(packetPtr, false);
packetCallback(packet);
return Status.StatusArgs.Ok();
}
catch (Exception e)
{
return Status.StatusArgs.Internal(e.ToString());
}
};
callbackHandle = GCHandle.Alloc(nativePacketCallback, GCHandleType.Pinned);
return ObserveOutputStream(streamName, 0, nativePacketCallback, observeTimestampBounds);
}
public Status ObserveOutputStream<TPacket, TValue>(string streamName, PacketCallback<TPacket, TValue> packetCallback, out GCHandle callbackHandle) where TPacket : Packet<TValue>, new()
{
return ObserveOutputStream(streamName, packetCallback, false, out callbackHandle);
}
public StatusOrPoller<T> AddOutputStreamPoller<T>(string streamName, bool observeTimestampBounds = false)
{
UnsafeNativeMethods.mp_CalculatorGraph__AddOutputStreamPoller__PKc_b(mpPtr, streamName, observeTimestampBounds, out var statusOrPollerPtr).Assert();
GC.KeepAlive(this);
return new StatusOrPoller<T>(statusOrPollerPtr);
}
public Status Run()
{
return Run(new SidePacket());
}
public Status Run(SidePacket sidePacket)
{
UnsafeNativeMethods.mp_CalculatorGraph__Run__Rsp(mpPtr, sidePacket.mpPtr, out var statusPtr).Assert();
GC.KeepAlive(sidePacket);
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status StartRun()
{
return StartRun(new SidePacket());
}
public Status StartRun(SidePacket sidePacket)
{
UnsafeNativeMethods.mp_CalculatorGraph__StartRun__Rsp(mpPtr, sidePacket.mpPtr, out var statusPtr).Assert();
GC.KeepAlive(sidePacket);
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status WaitUntilIdle()
{
UnsafeNativeMethods.mp_CalculatorGraph__WaitUntilIdle(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status WaitUntilDone()
{
UnsafeNativeMethods.mp_CalculatorGraph__WaitUntilDone(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public bool HasError()
{
return SafeNativeMethods.mp_CalculatorGraph__HasError(mpPtr);
}
public Status AddPacketToInputStream<T>(string streamName, Packet<T> packet)
{
UnsafeNativeMethods.mp_CalculatorGraph__AddPacketToInputStream__PKc_Ppacket(mpPtr, streamName, packet.mpPtr, out var statusPtr).Assert();
packet.Dispose(); // respect move semantics
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status SetInputStreamMaxQueueSize(string streamName, int maxQueueSize)
{
UnsafeNativeMethods.mp_CalculatorGraph__SetInputStreamMaxQueueSize__PKc_i(mpPtr, streamName, maxQueueSize, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status CloseInputStream(string streamName)
{
UnsafeNativeMethods.mp_CalculatorGraph__CloseInputStream__PKc(mpPtr, streamName, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status CloseAllPacketSources()
{
UnsafeNativeMethods.mp_CalculatorGraph__CloseAllPacketSources(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public void Cancel()
{
UnsafeNativeMethods.mp_CalculatorGraph__Cancel(mpPtr).Assert();
GC.KeepAlive(this);
}
public bool GraphInputStreamsClosed()
{
return SafeNativeMethods.mp_CalculatorGraph__GraphInputStreamsClosed(mpPtr);
}
public bool IsNodeThrottled(int nodeId)
{
return SafeNativeMethods.mp_CalculatorGraph__IsNodeThrottled__i(mpPtr, nodeId);
}
public bool UnthrottleSources()
{
return SafeNativeMethods.mp_CalculatorGraph__UnthrottleSources(mpPtr);
}
public GpuResources GetGpuResources()
{
UnsafeNativeMethods.mp_CalculatorGraph__GetGpuResources(mpPtr, out var gpuResourcesPtr).Assert();
GC.KeepAlive(this);
return new GpuResources(gpuResourcesPtr);
}
public Status SetGpuResources(GpuResources gpuResources)
{
UnsafeNativeMethods.mp_CalculatorGraph__SetGpuResources__SPgpu(mpPtr, gpuResources.sharedPtr, out var statusPtr).Assert();
GC.KeepAlive(gpuResources);
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aac82f941ea6a90309bfe58c72f0be18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using pb = Google.Protobuf;
namespace Mediapipe
{
public static class CalculatorGraphConfigExtension
{
public static CalculatorGraphConfig ParseFromTextFormat(this pb::MessageParser<CalculatorGraphConfig> _, string configText)
{
if (UnsafeNativeMethods.mp_api__ConvertFromCalculatorGraphConfigTextFormat(configText, out var serializedProto))
{
var config = serializedProto.Deserialize(CalculatorGraphConfig.Parser);
serializedProto.Dispose();
return config;
}
throw new MediaPipeException("Failed to parse config text. See error logs for more details");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d17ea3a25da1d9e79b6121a228e2a99
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0c78bb0fe754bbb448fd9fd8082b8906
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,320 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
namespace Mediapipe
{
public class ImageFrame : MpResourceHandle
{
public static readonly uint DefaultAlignmentBoundary = 16;
public static readonly uint GlDefaultAlignmentBoundary = 4;
public delegate void Deleter(IntPtr ptr);
public ImageFrame() : base()
{
UnsafeNativeMethods.mp_ImageFrame__(out var ptr).Assert();
this.ptr = ptr;
}
public ImageFrame(IntPtr imageFramePtr, bool isOwner = true) : base(imageFramePtr, isOwner) { }
public ImageFrame(ImageFormat.Types.Format format, int width, int height) : this(format, width, height, DefaultAlignmentBoundary) { }
public ImageFrame(ImageFormat.Types.Format format, int width, int height, uint alignmentBoundary) : base()
{
UnsafeNativeMethods.mp_ImageFrame__ui_i_i_ui(format, width, height, alignmentBoundary, out var ptr).Assert();
this.ptr = ptr;
}
public ImageFrame(ImageFormat.Types.Format format, int width, int height, int widthStep, IntPtr pixelData, Deleter deleter) : base()
{
unsafe
{
UnsafeNativeMethods.mp_ImageFrame__ui_i_i_i_Pui8_PF(format, width, height, widthStep, pixelData, deleter, out var ptr).Assert();
this.ptr = ptr;
}
}
public unsafe ImageFrame(ImageFormat.Types.Format format, int width, int height, int widthStep, NativeArray<byte> pixelData, Deleter deleter)
: this(format, width, height, widthStep, (IntPtr)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(pixelData), deleter)
{ }
/// <summary>
/// Initialize an <see cref="ImageFrame" />.
/// </summary>
/// <remarks>
/// <paramref name="pixelData" /> won't be released if the instance is disposed of.<br />
/// It's useful when:
/// <list type="bullet">
/// <item>
/// <description>You can reuse the memory allocated to <paramref name="pixelData" />.</description>
/// </item>
/// <item>
/// <description>You've not allocated the memory (e.g. <see cref="Texture2D.GetRawTextureData" />).</description>
/// </item>
/// </list>
/// </remarks>
public ImageFrame(ImageFormat.Types.Format format, int width, int height, int widthStep, NativeArray<byte> pixelData)
: this(format, width, height, widthStep, pixelData, VoidDeleter)
{ }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_ImageFrame__delete(ptr);
}
[AOT.MonoPInvokeCallback(typeof(Deleter))]
private static void VoidDeleter(IntPtr _) { }
/// <returns>
/// The number of channels for a <paramref name="format" />.
/// If channels don't make sense in the <paramref name="format" />, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public static int NumberOfChannelsForFormat(ImageFormat.Types.Format format)
{
switch (format)
{
case ImageFormat.Types.Format.Srgb:
case ImageFormat.Types.Format.Srgb48:
return 3;
case ImageFormat.Types.Format.Srgba:
case ImageFormat.Types.Format.Srgba64:
case ImageFormat.Types.Format.Sbgra:
return 4;
case ImageFormat.Types.Format.Gray8:
case ImageFormat.Types.Format.Gray16:
return 1;
case ImageFormat.Types.Format.Vec32F1:
return 1;
case ImageFormat.Types.Format.Vec32F2:
return 2;
case ImageFormat.Types.Format.Lab8:
return 3;
case ImageFormat.Types.Format.Ycbcr420P:
case ImageFormat.Types.Format.Ycbcr420P10:
case ImageFormat.Types.Format.Unknown:
default:
return 0;
}
}
/// <returns>
/// The channel size for a <paramref name="format" />.
/// If channels don't make sense in the <paramref name="format" />, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public static int ChannelSizeForFormat(ImageFormat.Types.Format format)
{
switch (format)
{
case ImageFormat.Types.Format.Srgb:
case ImageFormat.Types.Format.Srgba:
case ImageFormat.Types.Format.Sbgra:
return sizeof(byte);
case ImageFormat.Types.Format.Srgb48:
case ImageFormat.Types.Format.Srgba64:
return sizeof(ushort);
case ImageFormat.Types.Format.Gray8:
return sizeof(byte);
case ImageFormat.Types.Format.Gray16:
return sizeof(ushort);
case ImageFormat.Types.Format.Vec32F1:
case ImageFormat.Types.Format.Vec32F2:
// sizeof float may be wrong since it's platform-dependent, but we assume that it's constant across all supported platforms.
return sizeof(float);
case ImageFormat.Types.Format.Lab8:
return sizeof(byte);
case ImageFormat.Types.Format.Ycbcr420P:
case ImageFormat.Types.Format.Ycbcr420P10:
case ImageFormat.Types.Format.Unknown:
default:
return 0;
}
}
/// <returns>
/// The depth of each channel in bytes for a <paramref name="format" />.
/// If channels don't make sense in the <paramref name="format" />, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public static int ByteDepthForFormat(ImageFormat.Types.Format format)
{
switch (format)
{
case ImageFormat.Types.Format.Srgb:
case ImageFormat.Types.Format.Srgba:
case ImageFormat.Types.Format.Sbgra:
return 1;
case ImageFormat.Types.Format.Srgb48:
case ImageFormat.Types.Format.Srgba64:
return 2;
case ImageFormat.Types.Format.Gray8:
return 1;
case ImageFormat.Types.Format.Gray16:
return 2;
case ImageFormat.Types.Format.Vec32F1:
case ImageFormat.Types.Format.Vec32F2:
return 4;
case ImageFormat.Types.Format.Lab8:
return 1;
case ImageFormat.Types.Format.Ycbcr420P:
case ImageFormat.Types.Format.Ycbcr420P10:
case ImageFormat.Types.Format.Unknown:
default:
return 0;
}
}
public bool IsEmpty()
{
return SafeNativeMethods.mp_ImageFrame__IsEmpty(mpPtr);
}
public bool IsContiguous()
{
return SafeNativeMethods.mp_ImageFrame__IsContiguous(mpPtr);
}
public bool IsAligned(uint alignmentBoundary)
{
SafeNativeMethods.mp_ImageFrame__IsAligned__ui(mpPtr, alignmentBoundary, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public ImageFormat.Types.Format Format()
{
return SafeNativeMethods.mp_ImageFrame__Format(mpPtr);
}
public int Width()
{
return SafeNativeMethods.mp_ImageFrame__Width(mpPtr);
}
public int Height()
{
return SafeNativeMethods.mp_ImageFrame__Height(mpPtr);
}
/// <returns>
/// The channel size.
/// If channels don't make sense, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public int ChannelSize()
{
return ChannelSizeForFormat(Format());
}
/// <returns>
/// The Number of channels.
/// If channels don't make sense, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public int NumberOfChannels()
{
return NumberOfChannelsForFormat(Format());
}
/// <returns>
/// The depth of each image channel in bytes.
/// If channels don't make sense, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public int ByteDepth()
{
return ByteDepthForFormat(Format());
}
public int WidthStep()
{
return SafeNativeMethods.mp_ImageFrame__WidthStep(mpPtr);
}
public IntPtr MutablePixelData()
{
return SafeNativeMethods.mp_ImageFrame__MutablePixelData(mpPtr);
}
public int PixelDataSize()
{
return Height() * WidthStep();
}
/// <returns>
/// The total size the pixel data would take if it was stored contiguously (which may not be the case).
/// If channels don't make sense, returns <c>0</c>.
/// </returns>
/// <remarks>
/// Unlike the original implementation, this API won't signal SIGABRT.
/// </remarks>
public int PixelDataSizeStoredContiguously()
{
return Width() * Height() * ByteDepth() * NumberOfChannels();
}
public void SetToZero()
{
UnsafeNativeMethods.mp_ImageFrame__SetToZero(mpPtr).Assert();
GC.KeepAlive(this);
}
public void SetAlignmentPaddingAreas()
{
UnsafeNativeMethods.mp_ImageFrame__SetAlignmentPaddingAreas(mpPtr).Assert();
GC.KeepAlive(this);
}
public void CopyToBuffer(byte[] buffer)
{
CopyToBuffer(UnsafeNativeMethods.mp_ImageFrame__CopyToBuffer__Pui8_i, buffer);
}
public void CopyToBuffer(ushort[] buffer)
{
CopyToBuffer(UnsafeNativeMethods.mp_ImageFrame__CopyToBuffer__Pui16_i, buffer);
}
public void CopyToBuffer(float[] buffer)
{
CopyToBuffer(UnsafeNativeMethods.mp_ImageFrame__CopyToBuffer__Pf_i, buffer);
}
private delegate MpReturnCode CopyToBufferHandler(IntPtr ptr, IntPtr buffer, int bufferSize);
private void CopyToBuffer<T>(CopyToBufferHandler handler, T[] buffer) where T : unmanaged
{
unsafe
{
fixed (T* bufferPtr = buffer)
{
handler(mpPtr, (IntPtr)bufferPtr, buffer.Length).Assert();
}
}
GC.KeepAlive(this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d935bef0b56e4e630af77963694500c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class OutputStreamPoller<T> : MpResourceHandle
{
public OutputStreamPoller(IntPtr ptr) : base(ptr) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_OutputStreamPoller__delete(ptr);
}
public bool Next(Packet<T> packet)
{
UnsafeNativeMethods.mp_OutputStreamPoller__Next_Ppacket(mpPtr, packet.mpPtr, out var result).Assert();
GC.KeepAlive(this);
return result;
}
public void Reset()
{
UnsafeNativeMethods.mp_OutputStreamPoller__Reset(mpPtr).Assert();
}
public void SetMaxQueueSize(int queueSize)
{
UnsafeNativeMethods.mp_OutputStreamPoller__SetMaxQueueSize(mpPtr, queueSize).Assert();
}
public int QueueSize()
{
UnsafeNativeMethods.mp_OutputStreamPoller__QueueSize(mpPtr, out var result).Assert();
GC.KeepAlive(this);
return result;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e58cdfa177e4fe2c3aa7970d82850fcf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 97cecb58177d3e64a9d08c53b7988347
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class Anchor3dVectorPacket : Packet<List<Anchor3d>>
{
/// <summary>
/// Creates an empty <see cref="Anchor3dVectorPacket" /> instance.
/// </summary>
public Anchor3dVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public Anchor3dVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public Anchor3dVectorPacket(Anchor3d[] value) : base()
{
UnsafeNativeMethods.mp__MakeAnchor3dVectorPacket__PA_i(value, value.Length, out var ptr).Assert();
this.ptr = ptr;
}
public Anchor3dVectorPacket(Anchor3d[] value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeAnchor3dVectorPacket_At__PA_i_Rt(value, value.Length, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public Anchor3dVectorPacket At(Timestamp timestamp)
{
return At<Anchor3dVectorPacket>(timestamp);
}
public override List<Anchor3d> Get()
{
UnsafeNativeMethods.mp_Packet__GetAnchor3dVector(mpPtr, out var anchorVector).Assert();
GC.KeepAlive(this);
var anchors = anchorVector.ToList();
anchorVector.Dispose();
return anchors;
}
public override StatusOr<List<Anchor3d>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e1747c248b3628738bcd536767bfc09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class BoolPacket : Packet<bool>
{
/// <summary>
/// Creates an empty <see cref="BoolPacket" /> instance.
/// </summary>
public BoolPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public BoolPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public BoolPacket(bool value) : base()
{
UnsafeNativeMethods.mp__MakeBoolPacket__b(value, out var ptr).Assert();
this.ptr = ptr;
}
public BoolPacket(bool value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeBoolPacket_At__b_Rt(value, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public BoolPacket At(Timestamp timestamp)
{
return At<BoolPacket>(timestamp);
}
public override bool Get()
{
UnsafeNativeMethods.mp_Packet__GetBool(mpPtr, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public override StatusOr<bool> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsBool(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2df39f2282bdd39baa43635710e5ddc2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class ClassificationListPacket : Packet<ClassificationList>
{
/// <summary>
/// Creates an empty <see cref="ClassificationListPacket" /> instance.
/// </summary>
public ClassificationListPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public ClassificationListPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public ClassificationListPacket At(Timestamp timestamp)
{
return At<ClassificationListPacket>(timestamp);
}
public override ClassificationList Get()
{
UnsafeNativeMethods.mp_Packet__GetClassificationList(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var classificationList = serializedProto.Deserialize(ClassificationList.Parser);
serializedProto.Dispose();
return classificationList;
}
public override StatusOr<ClassificationList> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 135912f48f055c6b594eac0dcb8c66b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class ClassificationListVectorPacket : Packet<List<ClassificationList>>
{
/// <summary>
/// Creates an empty <see cref="ClassificationListVectorPacket" /> instance.
/// </summary>
public ClassificationListVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public ClassificationListVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public ClassificationListVectorPacket At(Timestamp timestamp)
{
return At<ClassificationListVectorPacket>(timestamp);
}
public override List<ClassificationList> Get()
{
UnsafeNativeMethods.mp_Packet__GetClassificationListVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var classificationLists = serializedProtoVector.Deserialize(ClassificationList.Parser);
serializedProtoVector.Dispose();
return classificationLists;
}
public override StatusOr<List<ClassificationList>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c078b368cd8dfd66fba14dce3e749bcc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class DetectionPacket : Packet<Detection>
{
/// <summary>
/// Creates an empty <see cref="DetectionPacket" /> instance.
/// </summary>
public DetectionPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public DetectionPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public DetectionPacket At(Timestamp timestamp)
{
return At<DetectionPacket>(timestamp);
}
public override Detection Get()
{
UnsafeNativeMethods.mp_Packet__GetDetection(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var detection = serializedProto.Deserialize(Detection.Parser);
serializedProto.Dispose();
return detection;
}
public override StatusOr<Detection> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cfc4da8c1878374569d2813d16c368e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class DetectionVectorPacket : Packet<List<Detection>>
{
/// <summary>
/// Creates an empty <see cref="DetectionVectorPacket" /> instance.
/// </summary>
public DetectionVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public DetectionVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public DetectionVectorPacket At(Timestamp timestamp)
{
return At<DetectionVectorPacket>(timestamp);
}
public override List<Detection> Get()
{
UnsafeNativeMethods.mp_Packet__GetDetectionVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var detections = serializedProtoVector.Deserialize(Detection.Parser);
serializedProtoVector.Dispose();
return detections;
}
public override StatusOr<List<Detection>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e75eecc27e896404b76f06106435394
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class FaceGeometryPacket : Packet<FaceGeometry.FaceGeometry>
{
/// <summary>
/// Creates an empty <see cref="FaceGeometryPacket" /> instance.
/// </summary>
public FaceGeometryPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FaceGeometryPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FaceGeometryPacket At(Timestamp timestamp)
{
return At<FaceGeometryPacket>(timestamp);
}
public override FaceGeometry.FaceGeometry Get()
{
UnsafeNativeMethods.mp_Packet__GetFaceGeometry(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var geometry = serializedProto.Deserialize(FaceGeometry.FaceGeometry.Parser);
serializedProto.Dispose();
return geometry;
}
public override StatusOr<FaceGeometry.FaceGeometry> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe56866aa90e25df2b520b254aa7d971
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class FaceGeometryVectorPacket : Packet<List<FaceGeometry.FaceGeometry>>
{
/// <summary>
/// Creates an empty <see cref="FaceGeometryVectorPacket" /> instance.
/// </summary>
public FaceGeometryVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FaceGeometryVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FaceGeometryVectorPacket At(Timestamp timestamp)
{
return At<FaceGeometryVectorPacket>(timestamp);
}
public override List<FaceGeometry.FaceGeometry> Get()
{
UnsafeNativeMethods.mp_Packet__GetFaceGeometryVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var geometries = serializedProtoVector.Deserialize(FaceGeometry.FaceGeometry.Parser);
serializedProtoVector.Dispose();
return geometries;
}
public override StatusOr<List<FaceGeometry.FaceGeometry>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26bc289e136a1adfcb6608d60a732931
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class FloatArrayPacket : Packet<float[]>
{
private int _length = -1;
public int length
{
get => _length;
set
{
if (_length >= 0)
{
throw new InvalidOperationException("Length is already set and cannot be changed");
}
_length = value;
}
}
/// <summary>
/// Creates an empty <see cref="FloatArrayPacket" /> instance.
/// </summary>
public FloatArrayPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FloatArrayPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FloatArrayPacket(float[] value) : base()
{
UnsafeNativeMethods.mp__MakeFloatArrayPacket__Pf_i(value, value.Length, out var ptr).Assert();
this.ptr = ptr;
length = value.Length;
}
public FloatArrayPacket(float[] value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeFloatArrayPacket_At__Pf_i_Rt(value, value.Length, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
length = value.Length;
}
public FloatArrayPacket At(Timestamp timestamp)
{
var packet = At<FloatArrayPacket>(timestamp);
packet.length = length;
return packet;
}
public override float[] Get()
{
if (length < 0)
{
throw new InvalidOperationException("The array's length is unknown, set Length first");
}
var result = new float[length];
UnsafeNativeMethods.mp_Packet__GetFloatArray_i(mpPtr, length, out var arrayPtr).Assert();
GC.KeepAlive(this);
unsafe
{
var src = (float*)arrayPtr;
for (var i = 0; i < result.Length; i++)
{
result[i] = *src++;
}
}
UnsafeNativeMethods.delete_array__Pf(arrayPtr);
return result;
}
public override StatusOr<float[]> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsFloatArray(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: febbf4ee3984896dc8b2f12c06963c37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class FloatPacket : Packet<float>
{
/// <summary>
/// Creates an empty <see cref="FloatPacket" /> instance.
/// </summary>
public FloatPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FloatPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FloatPacket(float value) : base()
{
UnsafeNativeMethods.mp__MakeFloatPacket__f(value, out var ptr).Assert();
this.ptr = ptr;
}
public FloatPacket(float value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeFloatPacket_At__f_Rt(value, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public FloatPacket At(Timestamp timestamp)
{
return At<FloatPacket>(timestamp);
}
public override float Get()
{
UnsafeNativeMethods.mp_Packet__GetFloat(mpPtr, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public override StatusOr<float> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsFloat(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e3f137c2b492809ca377d451e20c329
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,108 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Mediapipe
{
[StructLayout(LayoutKind.Sequential)]
internal readonly struct FloatVector
{
private readonly IntPtr _data;
private readonly int _size;
public void Dispose()
{
UnsafeNativeMethods.delete_array__Pf(_data);
}
public List<float> Copy()
{
var data = new List<float>(_size);
unsafe
{
var floatPtr = (float*)_data;
for (var i = 0; i < _size; i++)
{
data.Add(*floatPtr++);
}
}
return data;
}
}
public class FloatVectorPacket : Packet<List<float>>
{
/// <summary>
/// Creates an empty <see cref="FloatVectorPacket" /> instance.
/// </summary>
///
public FloatVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FloatVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FloatVectorPacket(float[] value) : base()
{
UnsafeNativeMethods.mp__MakeFloatVectorPacket__Pf_i(value, value.Length, out var ptr).Assert();
this.ptr = ptr;
}
public FloatVectorPacket(float[] value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeFloatVectorPacket_At__Pf_i_Rt(value, value.Length, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public FloatVectorPacket(List<float> value) : base()
{
UnsafeNativeMethods.mp__MakeFloatVectorPacket__Pf_i(value.ToArray(), value.Count, out var ptr).Assert();
this.ptr = ptr;
}
public FloatVectorPacket(List<float> value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeFloatVectorPacket_At__Pf_i_Rt(value.ToArray(), value.Count, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public FloatVectorPacket At(Timestamp timestamp)
{
return At<FloatVectorPacket>(timestamp);
}
public override List<float> Get()
{
UnsafeNativeMethods.mp_Packet__GetFloatVector(mpPtr, out var floatVector).Assert();
GC.KeepAlive(this);
var result = floatVector.Copy();
floatVector.Dispose();
return result;
}
public override StatusOr<List<float>> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsFloatVector(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a9b77e746fd38d46a09d847f7370446
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class FrameAnnotationPacket : Packet<FrameAnnotation>
{
/// <summary>
/// Creates an empty <see cref="FrameAnnotationPacket" /> instance.
/// </summary>
public FrameAnnotationPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public FrameAnnotationPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public FrameAnnotationPacket At(Timestamp timestamp)
{
return At<FrameAnnotationPacket>(timestamp);
}
public override FrameAnnotation Get()
{
UnsafeNativeMethods.mp_Packet__GetFrameAnnotation(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var frameAnnotation = serializedProto.Deserialize(FrameAnnotation.Parser);
serializedProto.Dispose();
return frameAnnotation;
}
public override StatusOr<FrameAnnotation> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bd57a3f3c77dbb16babe8243fc373c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GpuBufferPacket : Packet<GpuBuffer>
{
/// <summary>
/// Creates an empty <see cref="GpuBufferPacket" /> instance.
/// </summary>
public GpuBufferPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public GpuBufferPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public GpuBufferPacket(GpuBuffer gpuBuffer) : base()
{
UnsafeNativeMethods.mp__MakeGpuBufferPacket__Rgb(gpuBuffer.mpPtr, out var ptr).Assert();
gpuBuffer.Dispose(); // respect move semantics
this.ptr = ptr;
}
public GpuBufferPacket(GpuBuffer gpuBuffer, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeGpuBufferPacket_At__Rgb_Rts(gpuBuffer.mpPtr, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
gpuBuffer.Dispose(); // respect move semantics
this.ptr = ptr;
}
public GpuBufferPacket At(Timestamp timestamp)
{
return At<GpuBufferPacket>(timestamp);
}
public override GpuBuffer Get()
{
UnsafeNativeMethods.mp_Packet__GetGpuBuffer(mpPtr, out var gpuBufferPtr).Assert();
GC.KeepAlive(this);
return new GpuBuffer(gpuBufferPtr, false);
}
public override StatusOr<GpuBuffer> Consume()
{
UnsafeNativeMethods.mp_Packet__ConsumeGpuBuffer(mpPtr, out var statusOrGpuBufferPtr).Assert();
GC.KeepAlive(this);
return new StatusOrGpuBuffer(statusOrGpuBufferPtr);
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsGpuBuffer(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62016354701eafa7a9a1b07d445b0c44
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,67 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class ImageFramePacket : Packet<ImageFrame>
{
/// <summary>
/// Creates an empty <see cref="ImageFramePacket" /> instance.
/// </summary>
public ImageFramePacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public ImageFramePacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public ImageFramePacket(ImageFrame imageFrame) : base()
{
UnsafeNativeMethods.mp__MakeImageFramePacket__Pif(imageFrame.mpPtr, out var ptr).Assert();
imageFrame.Dispose(); // respect move semantics
this.ptr = ptr;
}
public ImageFramePacket(ImageFrame imageFrame, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeImageFramePacket_At__Pif_Rt(imageFrame.mpPtr, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
imageFrame.Dispose(); // respect move semantics
this.ptr = ptr;
}
public ImageFramePacket At(Timestamp timestamp)
{
return At<ImageFramePacket>(timestamp);
}
public override ImageFrame Get()
{
UnsafeNativeMethods.mp_Packet__GetImageFrame(mpPtr, out var imageFramePtr).Assert();
GC.KeepAlive(this);
return new ImageFrame(imageFramePtr, false);
}
public override StatusOr<ImageFrame> Consume()
{
UnsafeNativeMethods.mp_Packet__ConsumeImageFrame(mpPtr, out var statusOrImageFramePtr).Assert();
GC.KeepAlive(this);
return new StatusOrImageFrame(statusOrImageFramePtr);
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsImageFrame(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be86f766875a6a848b0add7e41a2226b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class IntPacket : Packet<int>
{
/// <summary>
/// Creates an empty <see cref="IntPacket" /> instance.
/// </summary>
public IntPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public IntPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public IntPacket(int value) : base()
{
UnsafeNativeMethods.mp__MakeIntPacket__i(value, out var ptr).Assert();
this.ptr = ptr;
}
public IntPacket(int value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeIntPacket_At__i_Rt(value, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public IntPacket At(Timestamp timestamp)
{
return At<IntPacket>(timestamp);
}
public override int Get()
{
UnsafeNativeMethods.mp_Packet__GetInt(mpPtr, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public override StatusOr<int> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsInt(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea1e37ccb5fd27c0c85d183ab96562e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class LandmarkListPacket : Packet<LandmarkList>
{
/// <summary>
/// Creates an empty <see cref="LandmarkListPacket" /> instance.
/// </summary>
public LandmarkListPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public LandmarkListPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public LandmarkListPacket At(Timestamp timestamp)
{
return At<LandmarkListPacket>(timestamp);
}
public override LandmarkList Get()
{
UnsafeNativeMethods.mp_Packet__GetLandmarkList(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var landmarkList = serializedProto.Deserialize(LandmarkList.Parser);
serializedProto.Dispose();
return landmarkList;
}
public override StatusOr<LandmarkList> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a52c4850b3d6f4fff840b03da689e307
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class LandmarkListVectorPacket : Packet<List<LandmarkList>>
{
/// <summary>
/// Creates an empty <see cref="LandmarkListVectorPacket" /> instance.
/// </summary>
public LandmarkListVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public LandmarkListVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public LandmarkListVectorPacket At(Timestamp timestamp)
{
return At<LandmarkListVectorPacket>(timestamp);
}
public override List<LandmarkList> Get()
{
UnsafeNativeMethods.mp_Packet__GetLandmarkListVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var landmarkLists = serializedProtoVector.Deserialize(LandmarkList.Parser);
serializedProtoVector.Dispose();
return landmarkLists;
}
public override StatusOr<List<LandmarkList>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5221b835adb8927dc84cb8c5f3af2f8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using Google.Protobuf;
using System;
namespace Mediapipe
{
public class MatrixPacket : Packet<MatrixData>
{
/// <summary>
/// Creates an empty <see cref="MatrixPacket" /> instance.
/// </summary>
public MatrixPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public MatrixPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public MatrixPacket(MatrixData matrixData) : base()
{
var value = matrixData.ToByteArray();
UnsafeNativeMethods.mp__MakeMatrixPacket__PKc_i(value, value.Length, out var ptr).Assert();
this.ptr = ptr;
}
public MatrixPacket(MatrixData matrixData, Timestamp timestamp) : base()
{
var value = matrixData.ToByteArray();
UnsafeNativeMethods.mp__MakeMatrixPacket_At__PKc_i_Rt(value, value.Length, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public MatrixPacket At(Timestamp timestamp)
{
return At<MatrixPacket>(timestamp);
}
public override MatrixData Get()
{
UnsafeNativeMethods.mp_Packet__GetMatrix(mpPtr, out var serializedMatrixData).Assert();
GC.KeepAlive(this);
var matrixData = serializedMatrixData.Deserialize(MatrixData.Parser);
serializedMatrixData.Dispose();
return matrixData;
}
public override StatusOr<MatrixData> Consume()
{
throw new NotSupportedException();
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsMatrix(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ef898503888a0ee42af28aef1fbbe794
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class NormalizedLandmarkListPacket : Packet<NormalizedLandmarkList>
{
/// <summary>
/// Creates an empty <see cref="NormalizedLandmarkListPacket" /> instance.
/// </summary>
public NormalizedLandmarkListPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public NormalizedLandmarkListPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public NormalizedLandmarkListPacket At(Timestamp timestamp)
{
return At<NormalizedLandmarkListPacket>(timestamp);
}
public override NormalizedLandmarkList Get()
{
UnsafeNativeMethods.mp_Packet__GetNormalizedLandmarkList(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var normalizedLandmarkList = serializedProto.Deserialize(NormalizedLandmarkList.Parser);
serializedProto.Dispose();
return normalizedLandmarkList;
}
public override StatusOr<NormalizedLandmarkList> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f33ad7ff69288fbda9c5d2d3a173a23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class NormalizedLandmarkListVectorPacket : Packet<List<NormalizedLandmarkList>>
{
/// <summary>
/// Creates an empty <see cref="NormalizedLandmarkListVectorPacket" /> instance.
/// </summary>
public NormalizedLandmarkListVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public NormalizedLandmarkListVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public NormalizedLandmarkListVectorPacket At(Timestamp timestamp)
{
return At<NormalizedLandmarkListVectorPacket>(timestamp);
}
public override List<NormalizedLandmarkList> Get()
{
UnsafeNativeMethods.mp_Packet__GetNormalizedLandmarkListVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var normalizedLandmarkLists = serializedProtoVector.Deserialize(NormalizedLandmarkList.Parser);
serializedProtoVector.Dispose();
return normalizedLandmarkLists;
}
public override StatusOr<List<NormalizedLandmarkList>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf1c0c41a515dfae985791690002e1fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class NormalizedRectPacket : Packet<NormalizedRect>
{
/// <summary>
/// Creates an empty <see cref="NormalizedRectPacket" /> instance.
/// </summary>
public NormalizedRectPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public NormalizedRectPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public NormalizedRectPacket At(Timestamp timestamp)
{
return At<NormalizedRectPacket>(timestamp);
}
public override NormalizedRect Get()
{
UnsafeNativeMethods.mp_Packet__GetNormalizedRect(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var normalizedRect = serializedProto.Deserialize(NormalizedRect.Parser);
serializedProto.Dispose();
return normalizedRect;
}
public override StatusOr<NormalizedRect> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e39d3cdad5a34bdaf93a850f4f3880eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class NormalizedRectVectorPacket : Packet<List<NormalizedRect>>
{
/// <summary>
/// Creates an empty <see cref="NormalizedRectVectorPacket" /> instance.
/// </summary>
public NormalizedRectVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public NormalizedRectVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public NormalizedRectVectorPacket At(Timestamp timestamp)
{
return At<NormalizedRectVectorPacket>(timestamp);
}
public override List<NormalizedRect> Get()
{
UnsafeNativeMethods.mp_Packet__GetNormalizedRectVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var normalizedRects = serializedProtoVector.Deserialize(NormalizedRect.Parser);
serializedProtoVector.Dispose();
return normalizedRects;
}
public override StatusOr<List<NormalizedRect>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 227b1bd0b120bd104af18a436ed254ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public abstract class Packet<TValue> : MpResourceHandle
{
/// <remarks>
/// The native resource won't be initialized.
/// </remarks>
protected Packet() : base() { }
/// <remarks>
/// If <paramref name="isOwner" /> is set to <c>false</c>, the native resource won't be initialized.
/// </remarks>
protected Packet(bool isOwner) : base(isOwner)
{
if (isOwner)
{
UnsafeNativeMethods.mp_Packet__(out var ptr).Assert();
this.ptr = ptr;
}
}
protected Packet(IntPtr ptr, bool isOwner) : base(ptr, isOwner) { }
/// <summary>
/// Creates a read-write <typeparamref name="TPacket" /> instance.
/// </summary>
/// <remarks>
/// This is a slow operation that makes use of <see cref="Activator.CreateInstance" /> internally, so you should avoid calling it in a loop.<br/>
/// If you need to call it in a loop and <paramref name="isOwner" /> is set to <c>false</c>, call <see cref="SwitchNativePtr" /> instead.
/// </remarks>
public static TPacket Create<TPacket>(IntPtr packetPtr, bool isOwner) where TPacket : Packet<TValue>, new()
{
return (TPacket)Activator.CreateInstance(typeof(TPacket), packetPtr, isOwner);
}
public void SwitchNativePtr(IntPtr packetPtr)
{
if (isOwner)
{
throw new InvalidOperationException("This operation is permitted only when the packet instance is for reference");
}
ptr = packetPtr;
}
/// <exception cref="MediaPipeException">Thrown when the value is not set</exception>
public abstract TValue Get();
public abstract StatusOr<TValue> Consume();
public bool IsEmpty()
{
return SafeNativeMethods.mp_Packet__IsEmpty(mpPtr);
}
public Status ValidateAsProtoMessageLite()
{
UnsafeNativeMethods.mp_Packet__ValidateAsProtoMessageLite(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
// TODO: declare as abstract
public virtual Status ValidateAsType()
{
throw new NotImplementedException();
}
public Timestamp Timestamp()
{
UnsafeNativeMethods.mp_Packet__Timestamp(mpPtr, out var timestampPtr).Assert();
GC.KeepAlive(this);
return new Timestamp(timestampPtr);
}
public string DebugString()
{
return MarshalStringFromNative(UnsafeNativeMethods.mp_Packet__DebugString);
}
public string RegisteredTypeName()
{
var typeName = MarshalStringFromNative(UnsafeNativeMethods.mp_Packet__RegisteredTypeName);
return typeName ?? "";
}
public string DebugTypeName()
{
return MarshalStringFromNative(UnsafeNativeMethods.mp_Packet__DebugTypeName);
}
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_Packet__delete(ptr);
}
/// <remarks>
/// This method will copy the value and create another packet internally.
/// To avoid copying the value, it's preferable to instantiate the packet with timestamp in the first place.
/// </remarks>
/// <returns>New packet with the given timestamp and the copied value</returns>
protected TPacket At<TPacket>(Timestamp timestamp) where TPacket : Packet<TValue>, new()
{
UnsafeNativeMethods.mp_Packet__At__Rt(mpPtr, timestamp.mpPtr, out var packetPtr).Assert();
GC.KeepAlive(timestamp);
return Create<TPacket>(packetPtr, true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a857adad76d497e579b18d1b74c2183c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class RectPacket : Packet<Rect>
{
/// <summary>
/// Creates an empty <see cref="RectPacket" /> instance.
/// </summary>
public RectPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public RectPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public RectPacket At(Timestamp timestamp)
{
return At<RectPacket>(timestamp);
}
public override Rect Get()
{
UnsafeNativeMethods.mp_Packet__GetRect(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var rect = serializedProto.Deserialize(Rect.Parser);
serializedProto.Dispose();
return rect;
}
public override StatusOr<Rect> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bab9dce43b38fd7939bfef3e750d3340
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Collections.Generic;
namespace Mediapipe
{
public class RectVectorPacket : Packet<List<Rect>>
{
/// <summary>
/// Creates an empty <see cref="RectVectorPacket" /> instance.
/// </summary>
public RectVectorPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public RectVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public RectVectorPacket At(Timestamp timestamp)
{
return At<RectVectorPacket>(timestamp);
}
public override List<Rect> Get()
{
UnsafeNativeMethods.mp_Packet__GetRectVector(mpPtr, out var serializedProtoVector).Assert();
GC.KeepAlive(this);
var rects = serializedProtoVector.Deserialize(Rect.Parser);
serializedProtoVector.Dispose();
return rects;
}
public override StatusOr<List<Rect>> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b3010621ded8ad44949c9958d647b3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class SidePacket : MpResourceHandle
{
public SidePacket() : base()
{
UnsafeNativeMethods.mp_SidePacket__(out var ptr).Assert();
this.ptr = ptr;
}
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_SidePacket__delete(ptr);
}
public int size => SafeNativeMethods.mp_SidePacket__size(mpPtr);
/// <remarks>
/// This method cannot verify that the packet type corresponding to the <paramref name="key" /> is indeed a <typeparamref name="TPacket" />,
/// so you must make sure by youreself that it is.
/// </remarks>
public TPacket At<TPacket, TValue>(string key) where TPacket : Packet<TValue>, new()
{
UnsafeNativeMethods.mp_SidePacket__at__PKc(mpPtr, key, out var packetPtr).Assert();
if (packetPtr == IntPtr.Zero)
{
return default; // null
}
GC.KeepAlive(this);
return Packet<TValue>.Create<TPacket>(packetPtr, true);
}
public void Emplace<T>(string key, Packet<T> packet)
{
UnsafeNativeMethods.mp_SidePacket__emplace__PKc_Rp(mpPtr, key, packet.mpPtr).Assert();
packet.Dispose(); // respect move semantics
GC.KeepAlive(this);
}
public int Erase(string key)
{
UnsafeNativeMethods.mp_SidePacket__erase__PKc(mpPtr, key, out var count).Assert();
GC.KeepAlive(this);
return count;
}
public void Clear()
{
SafeNativeMethods.mp_SidePacket__clear(mpPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8976efac5d9187e5ea5bd0f2c974425e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe
{
public class StringPacket : Packet<string>
{
/// <summary>
/// Creates an empty <see cref="StringPacket" /> instance.
/// </summary>
public StringPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public StringPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public StringPacket(string value) : base()
{
UnsafeNativeMethods.mp__MakeStringPacket__PKc(value, out var ptr).Assert();
this.ptr = ptr;
}
public StringPacket(byte[] bytes) : base()
{
UnsafeNativeMethods.mp__MakeStringPacket__PKc_i(bytes, bytes.Length, out var ptr).Assert();
this.ptr = ptr;
}
public StringPacket(string value, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeStringPacket_At__PKc_Rt(value, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public StringPacket(byte[] bytes, Timestamp timestamp) : base()
{
UnsafeNativeMethods.mp__MakeStringPacket_At__PKc_i_Rt(bytes, bytes.Length, timestamp.mpPtr, out var ptr).Assert();
GC.KeepAlive(timestamp);
this.ptr = ptr;
}
public StringPacket At(Timestamp timestamp)
{
return At<StringPacket>(timestamp);
}
public override string Get()
{
return MarshalStringFromNative(UnsafeNativeMethods.mp_Packet__GetString);
}
public byte[] GetByteArray()
{
UnsafeNativeMethods.mp_Packet__GetByteString(mpPtr, out var strPtr, out var size).Assert();
GC.KeepAlive(this);
var bytes = new byte[size];
Marshal.Copy(strPtr, bytes, 0, size);
UnsafeNativeMethods.delete_array__PKc(strPtr);
return bytes;
}
public override StatusOr<string> Consume()
{
UnsafeNativeMethods.mp_Packet__ConsumeString(mpPtr, out var statusOrStringPtr).Assert();
GC.KeepAlive(this);
return new StatusOrString(statusOrStringPtr);
}
public override Status ValidateAsType()
{
UnsafeNativeMethods.mp_Packet__ValidateAsString(mpPtr, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70e3fdcd8f227f24d8b41100474fec7c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class TimedModelMatrixProtoListPacket : Packet<TimedModelMatrixProtoList>
{
/// <summary>
/// Creates an empty <see cref="TimedModelMatrixProtoListPacket" /> instance.
/// </summary>
public TimedModelMatrixProtoListPacket() : base(true) { }
[UnityEngine.Scripting.Preserve]
public TimedModelMatrixProtoListPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
public TimedModelMatrixProtoListPacket At(Timestamp timestamp)
{
return At<TimedModelMatrixProtoListPacket>(timestamp);
}
public override TimedModelMatrixProtoList Get()
{
UnsafeNativeMethods.mp_Packet__GetTimedModelMatrixProtoList(mpPtr, out var serializedProto).Assert();
GC.KeepAlive(this);
var matrixProtoList = serializedProto.Deserialize(TimedModelMatrixProtoList.Parser);
serializedProto.Dispose();
return matrixProtoList;
}
public override StatusOr<TimedModelMatrixProtoList> Consume()
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 244922fa9b8ff20ef8962313f8179a24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 05b4466114b944943af1190894cbc5db
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,273 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
using System.Runtime.InteropServices;
namespace Mediapipe
{
public class Status : MpResourceHandle
{
public enum StatusCode : int
{
Ok = 0,
Cancelled = 1,
Unknown = 2,
InvalidArgument = 3,
DeadlineExceeded = 4,
NotFound = 5,
AlreadyExists = 6,
PermissionDenied = 7,
ResourceExhausted = 8,
FailedPrecondition = 9,
Aborted = 10,
OutOfRange = 11,
Unimplemented = 12,
Internal = 13,
Unavailable = 14,
DataLoss = 15,
Unauthenticated = 16,
}
[StructLayout(LayoutKind.Sequential)]
public readonly struct StatusArgs
{
private readonly StatusCode _code;
private readonly IntPtr _message;
private StatusArgs(StatusCode code, string message = null)
{
_code = code;
_message = Marshal.StringToHGlobalAnsi(message);
}
public static StatusArgs Ok()
{
return new StatusArgs(StatusCode.Ok);
}
public static StatusArgs Cancelled(string message = null)
{
return new StatusArgs(StatusCode.Cancelled, message);
}
public static StatusArgs Unknown(string message = null)
{
return new StatusArgs(StatusCode.Unknown, message);
}
public static StatusArgs InvalidArgument(string message = null)
{
return new StatusArgs(StatusCode.InvalidArgument, message);
}
public static StatusArgs DeadlineExceeded(string message = null)
{
return new StatusArgs(StatusCode.DeadlineExceeded, message);
}
public static StatusArgs NotFound(string message = null)
{
return new StatusArgs(StatusCode.NotFound, message);
}
public static StatusArgs AlreadyExists(string message = null)
{
return new StatusArgs(StatusCode.AlreadyExists, message);
}
public static StatusArgs PermissionDenied(string message = null)
{
return new StatusArgs(StatusCode.PermissionDenied, message);
}
public static StatusArgs ResourceExhausted(string message = null)
{
return new StatusArgs(StatusCode.ResourceExhausted, message);
}
public static StatusArgs FailedPrecondition(string message = null)
{
return new StatusArgs(StatusCode.FailedPrecondition, message);
}
public static StatusArgs Aborted(string message = null)
{
return new StatusArgs(StatusCode.Aborted, message);
}
public static StatusArgs OutOfRange(string message = null)
{
return new StatusArgs(StatusCode.OutOfRange, message);
}
public static StatusArgs Unimplemented(string message = null)
{
return new StatusArgs(StatusCode.Unimplemented, message);
}
public static StatusArgs Internal(string message = null)
{
return new StatusArgs(StatusCode.Internal, message);
}
public static StatusArgs Unavailable(string message = null)
{
return new StatusArgs(StatusCode.Unavailable, message);
}
public static StatusArgs DataLoss(string message = null)
{
return new StatusArgs(StatusCode.DataLoss, message);
}
public static StatusArgs Unauthenticated(string message = null)
{
return new StatusArgs(StatusCode.Unauthenticated, message);
}
}
public Status(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.absl_Status__delete(ptr);
}
private bool? _ok;
private int? _rawCode;
public void AssertOk()
{
if (!Ok())
{
throw new MediaPipeException(ToString());
}
}
public bool Ok()
{
if (_ok is bool valueOfOk)
{
return valueOfOk;
}
_ok = SafeNativeMethods.absl_Status__ok(mpPtr);
return (bool)_ok;
}
public StatusCode Code()
{
return (StatusCode)RawCode();
}
public int RawCode()
{
if (_rawCode is int valueOfRawCode)
{
return valueOfRawCode;
}
_rawCode = SafeNativeMethods.absl_Status__raw_code(mpPtr);
return (int)_rawCode;
}
public override string ToString()
{
return MarshalStringFromNative(UnsafeNativeMethods.absl_Status__ToString);
}
public static Status Build(StatusCode code, string message, bool isOwner = true)
{
UnsafeNativeMethods.absl_Status__i_PKc((int)code, message, out var ptr).Assert();
return new Status(ptr, isOwner);
}
public static Status Ok(bool isOwner = true)
{
return Build(StatusCode.Ok, "", isOwner);
}
public static Status Cancelled(string message = "", bool isOwner = true)
{
return Build(StatusCode.Cancelled, message, isOwner);
}
public static Status Unknown(string message = "", bool isOwner = true)
{
return Build(StatusCode.Unknown, message, isOwner);
}
public static Status InvalidArgument(string message = "", bool isOwner = true)
{
return Build(StatusCode.InvalidArgument, message, isOwner);
}
public static Status DeadlineExceeded(string message = "", bool isOwner = true)
{
return Build(StatusCode.DeadlineExceeded, message, isOwner);
}
public static Status NotFound(string message = "", bool isOwner = true)
{
return Build(StatusCode.NotFound, message, isOwner);
}
public static Status AlreadyExists(string message = "", bool isOwner = true)
{
return Build(StatusCode.AlreadyExists, message, isOwner);
}
public static Status PermissionDenied(string message = "", bool isOwner = true)
{
return Build(StatusCode.PermissionDenied, message, isOwner);
}
public static Status ResourceExhausted(string message = "", bool isOwner = true)
{
return Build(StatusCode.ResourceExhausted, message, isOwner);
}
public static Status FailedPrecondition(string message = "", bool isOwner = true)
{
return Build(StatusCode.FailedPrecondition, message, isOwner);
}
public static Status Aborted(string message = "", bool isOwner = true)
{
return Build(StatusCode.Aborted, message, isOwner);
}
public static Status OutOfRange(string message = "", bool isOwner = true)
{
return Build(StatusCode.OutOfRange, message, isOwner);
}
public static Status Unimplemented(string message = "", bool isOwner = true)
{
return Build(StatusCode.Unimplemented, message, isOwner);
}
public static Status Internal(string message = "", bool isOwner = true)
{
return Build(StatusCode.Internal, message, isOwner);
}
public static Status Unavailable(string message = "", bool isOwner = true)
{
return Build(StatusCode.Unavailable, message, isOwner);
}
public static Status DataLoss(string message = "", bool isOwner = true)
{
return Build(StatusCode.DataLoss, message, isOwner);
}
public static Status Unauthenticated(string message = "", bool isOwner = true)
{
return Build(StatusCode.Unauthenticated, message, isOwner);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3eaa030180f28e4098aed69b42d8294
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public abstract class StatusOr<T> : MpResourceHandle
{
public StatusOr(IntPtr ptr) : base(ptr) { }
public abstract Status status { get; }
public virtual bool Ok()
{
return status.Ok();
}
public virtual T ValueOr(T defaultValue = default)
{
return Ok() ? Value() : defaultValue;
}
/// <exception cref="MediaPipePluginException">Thrown when status is not ok</exception>
public abstract T Value();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8265706b497a321ed85fa4a0f30c8edc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More