feat: Add zero-copy SharedArray
type to Frame Processor Plugins (#2383)
* feat: Create `TypedArray` class for Frame Processor Plugins * Type * feat: Pass `VisionCameraProxy` along (BREAKING) * feat: Finish implementation * Log a bit * feat: Successfully convert JSI <> JNI buffers * Wrap buffer * fix: Fix using wrong Runtime * feat: Add docs * add zero copy example * Format C++ * Create iOS base * feat: Finish iOS implementation * chore: Format * fix: Use `NSData` instead of `NSMutableData` * Format * fix: Fix build when Frame Processors are disabled * chore: Rename `TypedArray` to `SharedArray` * fix: Fix Swift typings for Array * Remove a few default inits * fix: Fix Android build * fix: Use `NSInteger` * Update SharedArray.mm * fix: Expose bytes directly on iOS (NSData was immutable)
This commit is contained in:
@@ -5,15 +5,21 @@ import android.util.Log;
|
||||
|
||||
import com.mrousavy.camera.frameprocessor.Frame;
|
||||
import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin;
|
||||
import com.mrousavy.camera.frameprocessor.SharedArray;
|
||||
import com.mrousavy.camera.frameprocessor.VisionCameraProxy;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExampleFrameProcessorPlugin extends FrameProcessorPlugin {
|
||||
SharedArray _sharedArray;
|
||||
|
||||
@Override
|
||||
public Object callback(@NotNull Frame frame, @Nullable Map<String, Object> params) {
|
||||
if (params == null) return null;
|
||||
@@ -37,11 +43,17 @@ public class ExampleFrameProcessorPlugin extends FrameProcessorPlugin {
|
||||
array.add(17.38);
|
||||
|
||||
map.put("example_array", array);
|
||||
|
||||
ByteBuffer byteBuffer = _sharedArray.getByteBuffer();
|
||||
byteBuffer.put(0, (byte)(Math.random() * 100));
|
||||
map.put("example_array_buffer", _sharedArray);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
ExampleFrameProcessorPlugin(@Nullable Map<String, Object> options) {
|
||||
super(options);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,9 @@ package com.mrousavy.camera.example
|
||||
import android.util.Log
|
||||
import com.mrousavy.camera.frameprocessor.Frame
|
||||
import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
|
||||
import com.mrousavy.camera.frameprocessor.VisionCameraProxy
|
||||
|
||||
class ExampleKotlinFrameProcessorPlugin(options: Map<String, Any>?): FrameProcessorPlugin(options) {
|
||||
class ExampleKotlinFrameProcessorPlugin(proxy: VisionCameraProxy, options: Map<String, Any>?): FrameProcessorPlugin() {
|
||||
init {
|
||||
Log.d("ExampleKotlinPlugin", "ExampleKotlinFrameProcessorPlugin initialized with options: " + options?.toString())
|
||||
}
|
||||
|
@@ -20,8 +20,8 @@ import com.mrousavy.camera.frameprocessor.FrameProcessorPluginRegistry;
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
// Register the Frame Processor Plugins for our app
|
||||
static {
|
||||
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_plugin", options -> new ExampleFrameProcessorPlugin(options));
|
||||
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_kotlin_swift_plugin", options -> new ExampleKotlinFrameProcessorPlugin(options));
|
||||
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_plugin", ExampleFrameProcessorPlugin::new);
|
||||
FrameProcessorPluginRegistry.addFrameProcessorPlugin("example_kotlin_swift_plugin", ExampleKotlinFrameProcessorPlugin::new);
|
||||
}
|
||||
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
@@ -33,7 +33,6 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
// Packages that cannot be autolinked yet can be added manually here, for VisionCameraExample:
|
||||
packages.add(new CameraPackage());
|
||||
|
Reference in New Issue
Block a user