Jni.cpp 813 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "pch.h"
  2. #include "Jni.h"
  3. #include <jni.h>
  4. #undef JNIEXPORT
  5. #define JNIEXPORT __attribute__((visibility("default")))
  6. #include "sdk/android/native_api/base/init.h"
  7. #include "sdk/android/src/jni/class_reference_holder.h"
  8. #include "sdk/android/src/jni/jni_helpers.h"
  9. using namespace ::webrtc;
  10. namespace unity
  11. {
  12. namespace webrtc
  13. {
  14. static JavaVM* g_jvm = nullptr;
  15. extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM* jvm, void* reserved)
  16. {
  17. InitAndroid(jvm);
  18. g_jvm = jvm;
  19. JNIEnv* jni = nullptr;
  20. if (jvm->GetEnv(reinterpret_cast<void**>(&jni), JNI_VERSION_1_6) != JNI_OK)
  21. return -1;
  22. return JNI_VERSION_1_6;
  23. }
  24. extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* jvm, void* reserved)
  25. {
  26. g_jvm = nullptr;
  27. }
  28. bool IsVMInitialized()
  29. {
  30. return g_jvm != nullptr;
  31. }
  32. }
  33. }