feat: Support for C++ Frame Processor Plugins by publishing VisionCamera as a prefab (#2251)
* update docs * add prefabs support
This commit is contained in:
parent
df32d2c5e9
commit
248a08b18c
@ -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.
|
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.
|
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
|
## Interacting with Frame Processors
|
||||||
|
|
||||||
### Access JS values
|
### Access JS values
|
||||||
|
@ -92,6 +92,13 @@ android {
|
|||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
prefab true
|
prefab true
|
||||||
|
prefabPublishing true
|
||||||
|
}
|
||||||
|
|
||||||
|
prefab {
|
||||||
|
VisionCamera {
|
||||||
|
headers "${project.buildDir}/headers/visioncamera/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
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 ->
|
tasks.configureEach { task ->
|
||||||
// C++ build
|
// C++ build
|
||||||
if (task.name.contains("configureCMakeDebug")) {
|
if (task.name.contains("configureCMakeDebug")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user