-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,40 @@ | ||
cmake_minimum_required(VERSION 3.4.1) | ||
project(VisionCameraTflite) | ||
cmake_minimum_required(VERSION 3.9.0) | ||
|
||
set (CMAKE_VERBOSE_MAKEFILE ON) | ||
set (CMAKE_CXX_STANDARD 11) | ||
set (PACKAGE_NAME "VisionCameraTflite") | ||
set (CMAKE_CXX_STANDARD 17) | ||
|
||
add_library(cpp | ||
SHARED | ||
../cpp/vision-camera-tflite.cpp | ||
cpp-adapter.cpp | ||
find_package(ReactAndroid REQUIRED CONFIG) | ||
find_package(fbjni REQUIRED CONFIG) | ||
|
||
add_library( | ||
${PACKAGE_NAME} | ||
SHARED | ||
../cpp/jsi/Promise.cpp | ||
../cpp/jsi/TypedArray.cpp | ||
../cpp/TensorflowPlugin.cpp | ||
../cpp/TensorHelpers.cpp | ||
src/main/cpp/Tflite.cpp | ||
) | ||
|
||
# Specifies a path to native header files. | ||
include_directories( | ||
../cpp | ||
target_include_directories( | ||
${PACKAGE_NAME} | ||
PRIVATE | ||
"../cpp" | ||
"src/main/cpp" | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon" | ||
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker" | ||
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule" # <-- CallInvokerHolder JNI wrapper | ||
) | ||
|
||
set_target_properties(${PACKAGE_NAME} PROPERTIES LINKER_LANGUAGE CXX) | ||
|
||
target_link_libraries( | ||
${PACKAGE_NAME} | ||
android # <-- log | ||
ReactAndroid::jsi # <-- jsi.h | ||
ReactAndroid::reactnativejni # <-- CallInvokerImpl | ||
fbjni::fbjni # <-- fbjni.h | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <jni.h> | ||
#include <jsi/jsi.h> | ||
#include <fbjni/fbjni.h> | ||
|
||
#include "TensorflowPlugin.h" | ||
#include <ReactCommon/CallInvoker.h> | ||
#include <ReactCommon/CallInvokerHolder.h> | ||
|
||
using namespace facebook; | ||
|
||
class TfliteModule: jni::JavaClass<TfliteModule> { | ||
public: | ||
static constexpr auto kJavaDescriptor = "Lcom/tflite/TfliteModule;"; | ||
|
||
static bool nativeInstall(jlong runtimePtr, jni::alias_ref<facebook::react::CallInvokerHolder::javaobject> jsCallInvokerHolder) { | ||
auto runtime = reinterpret_cast<jsi::Runtime*>(runtimePtr); | ||
if (runtime == nullptr) { | ||
// Runtime was null! | ||
return false; | ||
} | ||
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); | ||
|
||
return true; | ||
} | ||
|
||
static void registerNatives() { | ||
javaClassStatic()->registerNatives({ | ||
makeNativeMethod("nativeInstall", nativeInstall); | ||
}); | ||
} | ||
}; | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
TfliteModule::registerNatives(); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters