Internal change

PiperOrigin-RevId: 528632873
This commit is contained in:
MediaPipe Team 2023-05-01 18:38:20 -07:00 committed by Copybara-Service
parent fca728d226
commit 0a8be0d09d

View File

@ -14,6 +14,7 @@
#include "mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.h" #include "mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.h"
#include "absl/strings/str_format.h"
#include "mediapipe/gpu/gl_calculator_helper.h" #include "mediapipe/gpu/gl_calculator_helper.h"
#include "mediapipe/gpu/gl_context.h" #include "mediapipe/gpu/gl_context.h"
#include "mediapipe/gpu/gl_texture_buffer.h" #include "mediapipe/gpu/gl_texture_buffer.h"
@ -89,9 +90,20 @@ JNIEXPORT jlong JNICALL GRAPH_TEXTURE_FRAME_METHOD(
JNIEXPORT void JNICALL GRAPH_TEXTURE_FRAME_METHOD(nativeDidRead)( JNIEXPORT void JNICALL GRAPH_TEXTURE_FRAME_METHOD(nativeDidRead)(
JNIEnv* env, jobject thiz, jlong nativeHandle, jlong consumerSyncToken) { JNIEnv* env, jobject thiz, jlong nativeHandle, jlong consumerSyncToken) {
if (!consumerSyncToken) return;
GlTextureBufferSharedPtr* buffer = GlTextureBufferSharedPtr* buffer =
reinterpret_cast<GlTextureBufferSharedPtr*>(nativeHandle); reinterpret_cast<GlTextureBufferSharedPtr*>(nativeHandle);
mediapipe::GlSyncToken& token = mediapipe::GlSyncToken& token =
*reinterpret_cast<mediapipe::GlSyncToken*>(consumerSyncToken); *reinterpret_cast<mediapipe::GlSyncToken*>(consumerSyncToken);
// The below check attempts to detect when an invalid or already deleted
// `consumerSyncToken` is passed. (That results in undefined behavior.
// However, `DidRead` may succeed resulting in a later crash and masking the
// actual problem.)
if (token.use_count() == 0) {
LOG_FIRST_N(ERROR, 5) << absl::StrFormat("invalid sync token ref: %d",
consumerSyncToken);
return;
}
(*buffer)->DidRead(token); (*buffer)->DidRead(token);
} }