mirror of
https://github.com/cosyneco/MediaPipe.NET.git
synced 2025-08-25 01:00:27 +08:00

* Remove this bool marshal
* Literally remove all bool marshals
* Remove CharSet.Unicode warning
* Remove most FunctionPtr marshals
* Remove `[return: MarshalAs(...)]`
* Replace all `IntPtr`s with `void*`s
* Replace all `void*.Zero`s with `null`s
* Make native method classes unsafe
* U N S A F E
* Replace `PtrToStructure` with pointer arithmetic
* Run `dotnet format`
* Temp ugly Activator fix
* Remove `.ToPointer()`
* Use `byte` to return a `bool`
* Backwards compatibility with `Activator`
Yeah that sucks :(
* Replace `Marshal.Copy` by pointer arithmetic
* Replace `PtrToStringAnsi()` with `new string()`
* Remove unnecessary usings
* Explicitly type string pointers as `sbyte*`
* It actually doesn't hang?
* `MediaPipeException` -> `MediapipeException`
* Simplify `for` loops
* Remove unnecessary `float*` cast
* Some more explicit types for `ImageFrame`
* Remove unnecessary cast
* Looks like we forgor a `using` 💀
* Create `SafeArrayCopy` helper method
* Document `SafeArrayCopy`
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
// Copyright (c) homuler and Vignette
|
|
// This file is part of MediaPipe.NET.
|
|
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
|
|
|
|
using System;
|
|
using Mediapipe.Net.Framework.Port;
|
|
using Mediapipe.Net.Gpu;
|
|
using Mediapipe.Net.Native;
|
|
|
|
namespace Mediapipe.Net.Framework.Packet
|
|
{
|
|
public unsafe class GpuBufferPacket : Packet<GpuBuffer>
|
|
{
|
|
public GpuBufferPacket() : base() { }
|
|
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
|
|
|
|
Ptr = ptr;
|
|
}
|
|
|
|
public GpuBufferPacket(GpuBuffer gpuBuffer, Timestamp timestamp)
|
|
{
|
|
UnsafeNativeMethods.mp__MakeGpuBufferPacket_At__Rgb_Rts(gpuBuffer.MpPtr, timestamp.MpPtr, out var ptr).Assert();
|
|
GC.KeepAlive(timestamp);
|
|
gpuBuffer.Dispose(); // respect move semantics
|
|
|
|
Ptr = ptr;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|