feat: Support for C++ Frame Processor Plugins by publishing VisionCamera as a prefab (#2251)

* update docs

* add prefabs support
This commit is contained in:
Rodrigo Gomes 2023-12-12 07:21:21 -03:00 committed by GitHub
parent df32d2c5e9
commit 248a08b18c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -98,6 +98,36 @@ const frameProcessor = useFrameProcessor((frame) => {
It is however recommended to use native **Frame Processor Plugins** for processing, as those are much faster than JavaScript and can sometimes operate with the GPU buffer directly.
You can simply pass a `Frame` to a native Frame Processor Plugin directly.
## Advanced Frame Handling in C++
**vision-camera** is built using prefabs, which allow you to easily extend the library with your own native code.
you can link it in your `CMakeLists.txt` like this:
```make
find_package(react-native-vision-camera REQUIRED CONFIG)
# ...
target_link_libraries(
${PACKAGE_NAME}
# ... other libs
react-native-vision-camera::VisionCamera
)
```
then pass a `jsi::Object` to your C++ code. and then use the `FrameHostObject` to access the frame data:
```cpp
#include "frameprocessor/FrameHostObject.h"
# in your jsi::Function
jni::global_ref <JFrame> unwrappedFrame = frame->frame;
auto frameWidth = unwrappedFrame->getWidth();
__android_log_print(ANDROID_LOG_DEBUG, "VisionCamera",
"frame width: %d", frameWidth);
auto frameHeight = unwrappedFrame->getHeight();
__android_log_print(ANDROID_LOG_DEBUG, "VisionCamera",
"frame height: %d", frameHeight);
```
## Interacting with Frame Processors
### Access JS values

View File

@ -92,6 +92,13 @@ android {
buildFeatures {
prefab true
prefabPublishing true
}
prefab {
VisionCamera {
headers "${project.buildDir}/headers/visioncamera/"
}
}
defaultConfig {
@ -171,6 +178,14 @@ task deleteCmakeCache() {
}
}
task prepareHeaders(type: Copy) {
from fileTree('./src/main/cpp').filter { it.isFile() }
into "${project.buildDir}/headers/visioncamera/react-native-vision-camera/"
includeEmptyDirs = false
}
preBuild.dependsOn(prepareHeaders)
tasks.configureEach { task ->
// C++ build
if (task.name.contains("configureCMakeDebug")) {