This commit is contained in:
H1Gdev 2023-12-30 15:13:07 +00:00 committed by GitHub
commit 30f1b36000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 6 deletions

View File

@ -214,15 +214,15 @@ public class PacketCreator {
}
public Packet createInt16Vector(short[] data) {
throw new UnsupportedOperationException("Not implemented yet");
return Packet.create(nativeCreateInt16Vector(mediapipeGraph.getNativeHandle(), data));
}
public Packet createInt32Vector(int[] data) {
throw new UnsupportedOperationException("Not implemented yet");
return Packet.create(nativeCreateInt32Vector(mediapipeGraph.getNativeHandle(), data));
}
public Packet createInt64Vector(long[] data) {
throw new UnsupportedOperationException("Not implemented yet");
return Packet.create(nativeCreateInt64Vector(mediapipeGraph.getNativeHandle(), data));
}
public Packet createFloat32Vector(float[] data) {
@ -230,7 +230,7 @@ public class PacketCreator {
}
public Packet createFloat64Vector(double[] data) {
throw new UnsupportedOperationException("Not implemented yet");
return Packet.create(nativeCreateFloat64Vector(mediapipeGraph.getNativeHandle(), data));
}
public Packet createInt32Array(int[] data) {
@ -457,7 +457,11 @@ public class PacketCreator {
private native long nativeCreateFloat32Array(long context, float[] data);
private native long nativeCreateInt16Vector(long context, short[] data);
private native long nativeCreateInt32Vector(long context, int[] data);
private native long nativeCreateInt64Vector(long context, long[] data);
private native long nativeCreateFloat32Vector(long context, float[] data);
private native long nativeCreateFloat64Vector(long context, double[] data);
private native long nativeCreateStringFromByteArray(long context, byte[] data);

View File

@ -428,8 +428,6 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateGpuBuffer)(
#endif // !MEDIAPIPE_DISABLE_GPU
// TODO: Add vector creators.
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
JNIEnv* env, jobject thiz, jlong context, jfloatArray data) {
jsize count = env->GetArrayLength(data);
@ -450,6 +448,45 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt16Vector)(
JNIEnv* env, jobject thiz, jlong context, jshortArray data) {
jsize count = env->GetArrayLength(data);
jshort* data_ref = env->GetShortArrayElements(data, nullptr);
static_assert(std::is_same<int16_t, jshort>::value, "jshort must be int16_t");
std::unique_ptr<std::vector<int16_t>> shorts =
absl::make_unique<std::vector<int16_t>>(data_ref, data_ref + count);
env->ReleaseShortArrayElements(data, data_ref, JNI_ABORT);
mediapipe::Packet packet = mediapipe::Adopt(shorts.release());
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Vector)(
JNIEnv* env, jobject thiz, jlong context, jintArray data) {
jsize count = env->GetArrayLength(data);
jint* data_ref = env->GetIntArrayElements(data, nullptr);
static_assert(std::is_same<int32_t, jint>::value, "jint must be int32_t");
std::unique_ptr<std::vector<int32_t>> ints =
absl::make_unique<std::vector<int32_t>>(data_ref, data_ref + count);
env->ReleaseIntArrayElements(data, data_ref, JNI_ABORT);
mediapipe::Packet packet = mediapipe::Adopt(ints.release());
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt64Vector)(
JNIEnv* env, jobject thiz, jlong context, jlongArray data) {
jsize count = env->GetArrayLength(data);
jlong* data_ref = env->GetLongArrayElements(data, nullptr);
static_assert(std::is_same<int64_t, jlong>::value, "jlong must be int64_t");
std::unique_ptr<std::vector<int64_t>> longs =
absl::make_unique<std::vector<int64_t>>(data_ref, data_ref + count);
env->ReleaseLongArrayElements(data, data_ref, JNI_ABORT);
mediapipe::Packet packet = mediapipe::Adopt(longs.release());
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
JNIEnv* env, jobject thiz, jlong context, jfloatArray data) {
jsize count = env->GetArrayLength(data);
@ -467,6 +504,19 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat64Vector)(
JNIEnv* env, jobject thiz, jlong context, jdoubleArray data) {
jsize count = env->GetArrayLength(data);
jdouble* data_ref = env->GetDoubleArrayElements(data, nullptr);
static_assert(std::is_same<double, jdouble>::value, "jdouble must be double");
std::unique_ptr<std::vector<double>> doubles =
absl::make_unique<std::vector<double>>(data_ref, data_ref + count);
env->ReleaseDoubleArrayElements(data, data_ref, JNI_ABORT);
mediapipe::Packet packet = mediapipe::Adopt(doubles.release());
return CreatePacketWithContext(context, packet);
}
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Array)(
JNIEnv* env, jobject thiz, jlong context, jintArray data) {
jsize count = env->GetArrayLength(data);

View File

@ -112,9 +112,21 @@ JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateGpuBuffer)(
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Array)(
JNIEnv* env, jobject thiz, jlong context, jfloatArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt16Vector)(
JNIEnv* env, jobject thiz, jlong context, jshortArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Vector)(
JNIEnv* env, jobject thiz, jlong context, jintArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt64Vector)(
JNIEnv* env, jobject thiz, jlong context, jlongArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat32Vector)(
JNIEnv* env, jobject thiz, jlong context, jfloatArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateFloat64Vector)(
JNIEnv* env, jobject thiz, jlong context, jdoubleArray data);
JNIEXPORT jlong JNICALL PACKET_CREATOR_METHOD(nativeCreateInt32Array)(
JNIEnv* env, jobject thiz, jlong context, jintArray data);