Skip to content

Commit

Permalink
feat(sdk): implement GlSyncToken API
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Oct 18, 2020
1 parent 40dfc70 commit 9f8435e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
20 changes: 19 additions & 1 deletion Assets/MediaPipe/SDK/Scripts/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using MpDetectionVector = System.IntPtr;
using MpGlCalculatorHelper = System.IntPtr;
using MpGlContext = System.IntPtr;
using MpGlSyncToken = System.IntPtr;
using MpGpuResources = System.IntPtr;
using MpLandmarkList = System.IntPtr;
using MpLandmarkListVector = System.IntPtr;
Expand Down Expand Up @@ -140,6 +141,23 @@ internal static class UnsafeNativeMethods {
public static extern unsafe GlContextPtr MpGlContextGet(MpGlContext glContext);


/// GlSyncToken API
[DllImport (MediaPipeLibrary)]
public static extern unsafe MpGlContext MpGlSyncTokenDestroy(MpGlSyncToken glSyncToken);

[DllImport (MediaPipeLibrary)]
public static extern unsafe void MpGlSyncTokenWait(MpGlSyncToken glSyncToken);

[DllImport (MediaPipeLibrary)]
public static extern unsafe void MpGlSyncTokenWaitOnGpu(MpGlSyncToken glSyncToken);

[DllImport (MediaPipeLibrary)]
public static extern unsafe bool MpGlSyncTokenIsReady(MpGlSyncToken glSyncToken);

[DllImport (MediaPipeLibrary)]
public static extern unsafe MpGlContext MpGlSyncTokenGetContext(MpGlSyncToken glSyncToken);


/// GlTexture API
[DllImport (MediaPipeLibrary)]
public static extern unsafe void MpGlTextureDestroy(GlTexturePtr glTexture);
Expand Down Expand Up @@ -353,8 +371,8 @@ internal static class UnsafeNativeMethods {
[DllImport (MediaPipeLibrary)]
public static extern unsafe void MpStringCopy(IntPtr dest, byte[] src, int size);

/// SidePacket API

/// SidePacket API
[DllImport (MediaPipeLibrary)]
public static extern unsafe MpSidePacket MpSidePacketCreate();

Expand Down
22 changes: 22 additions & 0 deletions C/mediapipe_api/gpu/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,25 @@ MpGlContext* MpGlContextGetCurrent() {
mediapipe::GlContext* MpGlContextGet(MpGlContext* gl_context) {
return gl_context->impl.get();
}

void MpGlSyncTokenDestroy(MpGlSyncToken* token) {
delete token;
}

void MpGlSyncTokenWait(MpGlSyncToken* token) {
token->impl->Wait();
}

void MpGlSyncTokenWaitOnGpu(MpGlSyncToken* token) {
token->impl->WaitOnGpu();
}

bool MpGlSyncTokenIsReady(MpGlSyncToken* token) {
return token->impl->IsReady();
}

MpGlContext* MpGlSyncTokenGetContext(MpGlSyncToken* token) {
auto context = token->impl->GetContext();

return new MpGlContext { context };
}
13 changes: 12 additions & 1 deletion C/mediapipe_api/gpu/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ typedef struct MpGlContext {
std::shared_ptr<mediapipe::GlContext> impl;
} MpGlContext;

typedef struct MpGlSyncToken {
std::shared_ptr<mediapipe::GlSyncPoint> impl;
} MpGlSyncToken;

MP_CAPI_EXPORT extern MpGlContext* MpGlContextGetCurrent();
MP_CAPI_EXPORT extern MpGlContext* MpGlContextGet();
MP_CAPI_EXPORT extern mediapipe::GlContext* MpGlContextGet(MpGlContext* gl_context);

/** GlSyncToken API */
MP_CAPI_EXPORT extern void MpGlSyncTokenDestroy(MpGlSyncToken* token);
MP_CAPI_EXPORT extern void MpGlSyncTokenWait(MpGlSyncToken* token);
MP_CAPI_EXPORT extern void MpGlSyncTokenWaitOnGpu(MpGlSyncToken* token);
MP_CAPI_EXPORT extern bool MpGlSyncTokenIsReady(MpGlSyncToken* token);
MP_CAPI_EXPORT extern MpGlContext* MpGlSyncTokenGetContext(MpGlSyncToken* token);

} // extern "C"

Expand Down

0 comments on commit 9f8435e

Please sign in to comment.