feat: Use JSI's ArrayBuffer instead of TypedArray (#2408)

* feat: Use JSI's `ArrayBuffer` instead of `TypedArray`

* fix: Fix move memory

* feat: Implement iOS

* Format

* Update JSIJNIConversion.cpp

* fix: Fix Android `toArrayBuffer` and other

* Catch FP call errors

* Update return type

* Use `CPU_READ_OFTEN` flag as well

* CPU flag

* Run destructors under `jni::ThreadScope`

* Update FrameProcessorPluginHostObject.cpp

* fix: Fix `toArrayBuffer()` crash

* Update Frame.ts
This commit is contained in:
Marc Rousavy
2024-01-17 20:18:46 +01:00
committed by GitHub
parent 2f21609e39
commit ba1d7eec9c
26 changed files with 296 additions and 620 deletions

View File

@@ -19,17 +19,18 @@ import java.util.Map;
public class ExampleFrameProcessorPlugin extends FrameProcessorPlugin {
SharedArray _sharedArray;
private static final String TAG = "ExamplePlugin";
@Override
public Object callback(@NotNull Frame frame, @Nullable Map<String, Object> params) {
if (params == null) return null;
Image image = frame.getImage();
Log.d("ExamplePlugin", image.getWidth() + " x " + image.getHeight() + " Image with format #" + image.getFormat() + ". Logging " + params.size() + " parameters:");
Log.d(TAG, image.getWidth() + " x " + image.getHeight() + " Image with format #" + image.getFormat() + ". Logging " + params.size() + " parameters:");
for (String key : params.keySet()) {
Object value = params.get(key);
Log.d("ExamplePlugin", " -> " + (value == null ? "(null)" : value + " (" + value.getClass().getName() + ")"));
Log.d(TAG, " -> " + (value == null ? "(null)" : value + " (" + value.getClass().getName() + ")"));
}
Map<String, Object> map = new HashMap<>();
@@ -53,7 +54,13 @@ public class ExampleFrameProcessorPlugin extends FrameProcessorPlugin {
ExampleFrameProcessorPlugin(VisionCameraProxy proxy, @Nullable Map<String, Object> options) {
super();
_sharedArray = new SharedArray(proxy, SharedArray.Type.Uint8Array, 5);
Log.d("ExamplePlugin", "ExampleFrameProcessorPlugin initialized with options: " + options);
_sharedArray = new SharedArray(proxy, 5);
Log.d(TAG, "Successfully allocated SharedArray! Size: " + _sharedArray.getSize());
ByteBuffer buffer = ByteBuffer.allocateDirect(10);
SharedArray testArray = new SharedArray(proxy, buffer);
Log.d(TAG, "Successfully wrapped SharedArray in ByteBuffer! Size: " + testArray.getSize());
Log.d(TAG, "ExampleFrameProcessorPlugin initialized with options: " + options);
}
}