Wes xx mediapipe integration
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3eaa030180f28e4098aed69b42d8294
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8265706b497a321ed85fa4a0f30c8edc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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 StatusOrGpuBuffer : StatusOr<GpuBuffer>
|
||||
{
|
||||
public StatusOrGpuBuffer(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuBuffer__delete(ptr);
|
||||
}
|
||||
|
||||
private Status _status;
|
||||
public override Status status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_status == null || _status.isDisposed)
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuBuffer__status(mpPtr, out var statusPtr).Assert();
|
||||
|
||||
GC.KeepAlive(this);
|
||||
_status = new Status(statusPtr);
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Ok()
|
||||
{
|
||||
return SafeNativeMethods.mp_StatusOrGpuBuffer__ok(mpPtr);
|
||||
}
|
||||
|
||||
public override GpuBuffer Value()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuBuffer__value(mpPtr, out var gpuBufferPtr).Assert();
|
||||
Dispose();
|
||||
|
||||
return new GpuBuffer(gpuBufferPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd1abb804326267d2ad3280f742335f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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 StatusOrGpuResources : StatusOr<GpuResources>
|
||||
{
|
||||
public StatusOrGpuResources(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuResources__delete(ptr);
|
||||
}
|
||||
|
||||
private Status _status;
|
||||
public override Status status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_status == null || _status.isDisposed)
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuResources__status(mpPtr, out var statusPtr).Assert();
|
||||
|
||||
GC.KeepAlive(this);
|
||||
_status = new Status(statusPtr);
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Ok()
|
||||
{
|
||||
return SafeNativeMethods.mp_StatusOrGpuResources__ok(mpPtr);
|
||||
}
|
||||
|
||||
public override GpuResources Value()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrGpuResources__value(mpPtr, out var gpuResourcesPtr).Assert();
|
||||
Dispose();
|
||||
|
||||
return new GpuResources(gpuResourcesPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b25d33a8b95748e448e3a0fa860ed096
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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 StatusOrImageFrame : StatusOr<ImageFrame>
|
||||
{
|
||||
public StatusOrImageFrame(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrImageFrame__delete(ptr);
|
||||
}
|
||||
|
||||
private Status _status;
|
||||
public override Status status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_status == null || _status.isDisposed)
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrImageFrame__status(mpPtr, out var statusPtr).Assert();
|
||||
|
||||
GC.KeepAlive(this);
|
||||
_status = new Status(statusPtr);
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Ok()
|
||||
{
|
||||
return SafeNativeMethods.mp_StatusOrImageFrame__ok(mpPtr);
|
||||
}
|
||||
|
||||
public override ImageFrame Value()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrImageFrame__value(mpPtr, out var imageFramePtr).Assert();
|
||||
Dispose();
|
||||
|
||||
return new ImageFrame(imageFramePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb972d14519613db3a10e80e53ccceb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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 StatusOrPoller<T> : StatusOr<OutputStreamPoller<T>>
|
||||
{
|
||||
public StatusOrPoller(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrPoller__delete(ptr);
|
||||
}
|
||||
|
||||
private Status _status;
|
||||
public override Status status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_status == null || _status.isDisposed)
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrPoller__status(mpPtr, out var statusPtr).Assert();
|
||||
|
||||
GC.KeepAlive(this);
|
||||
_status = new Status(statusPtr);
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Ok()
|
||||
{
|
||||
return SafeNativeMethods.mp_StatusOrPoller__ok(mpPtr);
|
||||
}
|
||||
|
||||
public override OutputStreamPoller<T> Value()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrPoller__value(mpPtr, out var pollerPtr).Assert();
|
||||
Dispose();
|
||||
|
||||
return new OutputStreamPoller<T>(pollerPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 516e50f1c8b1a564fb3a1a52ac7941a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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 StatusOrString : StatusOr<string>
|
||||
{
|
||||
public StatusOrString(IntPtr ptr) : base(ptr) { }
|
||||
|
||||
protected override void DeleteMpPtr()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrString__delete(ptr);
|
||||
}
|
||||
|
||||
private Status _status;
|
||||
public override Status status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_status == null || _status.isDisposed)
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrString__status(mpPtr, out var statusPtr).Assert();
|
||||
|
||||
GC.KeepAlive(this);
|
||||
_status = new Status(statusPtr);
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Ok()
|
||||
{
|
||||
return SafeNativeMethods.mp_StatusOrString__ok(mpPtr);
|
||||
}
|
||||
|
||||
public override string Value()
|
||||
{
|
||||
var str = MarshalStringFromNative(UnsafeNativeMethods.mp_StatusOrString__value);
|
||||
Dispose(); // respect move semantics
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public byte[] ValueAsByteArray()
|
||||
{
|
||||
UnsafeNativeMethods.mp_StatusOrString__bytearray(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);
|
||||
Dispose();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66b1ae14027703a7f9af3b146a26adfc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user