-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
377 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
using System; | ||
using MpPacket = System.IntPtr; | ||
|
||
namespace Mediapipe { | ||
public class BoolPacket : Packet<bool> { | ||
public BoolPacket() : base() {} | ||
|
||
public BoolPacket(MpPacket ptr) : base(ptr) {} | ||
public BoolPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) {} | ||
|
||
public BoolPacket(bool value) : base(UnsafeNativeMethods.MpMakeBoolPacket(value)) {} | ||
public BoolPacket(bool value) : base() { | ||
UnsafeNativeMethods.mp__MakeBoolPacket__b(value, out var ptr).Assert(); | ||
this.ptr = ptr; | ||
} | ||
|
||
public override bool GetValue() { | ||
return UnsafeNativeMethods.MpPacketGetBool(ptr); | ||
public override bool Get() { | ||
return SafeNativeMethods.mp_Packet__GetBool(ptr); | ||
} | ||
|
||
public override bool ConsumeValue() { | ||
public override bool Consume() { | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override Status ValidateAsType() { | ||
UnsafeNativeMethods.mp_Packet__ValidateAsBool(mpPtr, out var statusPtr); | ||
|
||
GC.KeepAlive(this); | ||
return new Status(statusPtr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,71 @@ | ||
using System; | ||
|
||
using MpPacket = System.IntPtr; | ||
|
||
namespace Mediapipe { | ||
public abstract class Packet<T> : ResourceHandle { | ||
private bool _disposed = false; | ||
public abstract class Packet<T> : MpResourceHandle { | ||
public Packet() : base() { | ||
UnsafeNativeMethods.mp_Packet__(out var ptr).Assert(); | ||
this.ptr = ptr; | ||
} | ||
|
||
public Packet(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) {} | ||
|
||
public Packet() : base(UnsafeNativeMethods.MpPacketCreate(), true) {} | ||
public abstract T Get(); | ||
|
||
public Packet(MpPacket ptr, bool isOwner = true) : base(ptr, isOwner) {} | ||
[Obsolete("GetValue() is deprecated, use Get()")] | ||
public T GetValue() { return Get(); } | ||
|
||
public abstract T GetValue(); | ||
public abstract T Consume(); | ||
|
||
public abstract T ConsumeValue(); | ||
[Obsolete("ConsumeValue() is deprecated, use Consume()")] | ||
public T ConsumeValue() { return Consume(); } | ||
|
||
/// <remarks>To avoid copying the value, instantiate the packet with timestamp</remarks> | ||
/// <returns>New packet with the given timestamp and the copied value</returns> | ||
public Packet<T> At(Timestamp timestamp) { | ||
UnsafeNativeMethods.mp_Packet__At__Rtimestamp(mpPtr, timestamp.mpPtr, out var packetPtr).Assert(); | ||
|
||
GC.KeepAlive(timestamp); | ||
return (Packet<T>)Activator.CreateInstance(this.GetType(), packetPtr, true); | ||
} | ||
|
||
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(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) { | ||
if (_disposed) return; | ||
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 == null ? "" : typeName; | ||
} | ||
|
||
public string DebugTypeName() { | ||
return MarshalStringFromNative(UnsafeNativeMethods.mp_Packet__DebugTypeName); | ||
} | ||
|
||
protected override void DisposeUnmanaged() { | ||
if (OwnsResource()) { | ||
UnsafeNativeMethods.MpPacketDestroy(ptr); | ||
UnsafeNativeMethods.mp_Packet__delete(ptr); | ||
} | ||
|
||
ptr = IntPtr.Zero; | ||
_disposed = true; | ||
base.DisposeUnmanaged(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.