feat: Use clang-format to keep the C++ codebase clean (#1741)
* Use clang-format * Create .clang-format * Update .clang-format * Update .clang-format * Update .clang-format * Only search in cpp dirs * Update clang-format.sh * Update .clang-format * Update .clang-format * Update .clang-format * Format C++ code! * Use version 16 * Update clang-format.sh * Remove Shaders.ts * fix: Lint Swift
This commit is contained in:
@@ -8,15 +8,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreMedia/CMSampleBuffer.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIImage.h>
|
||||
|
||||
@interface Frame : NSObject
|
||||
|
||||
- (instancetype _Nonnull) initWithBuffer:(CMSampleBufferRef _Nonnull)buffer orientation:(UIImageOrientation)orientation;
|
||||
- (instancetype _Nonnull)initWithBuffer:(CMSampleBufferRef _Nonnull)buffer
|
||||
orientation:(UIImageOrientation)orientation;
|
||||
|
||||
@property (nonatomic, readonly) CMSampleBufferRef _Nonnull buffer;
|
||||
@property (nonatomic, readonly) UIImageOrientation orientation;
|
||||
@property(nonatomic, readonly) CMSampleBufferRef _Nonnull buffer;
|
||||
@property(nonatomic, readonly) UIImageOrientation orientation;
|
||||
|
||||
@end
|
||||
|
@@ -7,15 +7,16 @@
|
||||
//
|
||||
|
||||
#import "Frame.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreMedia/CMSampleBuffer.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@implementation Frame {
|
||||
CMSampleBufferRef _Nonnull buffer;
|
||||
UIImageOrientation orientation;
|
||||
}
|
||||
|
||||
- (instancetype) initWithBuffer:(CMSampleBufferRef _Nonnull)buffer orientation:(UIImageOrientation)orientation {
|
||||
- (instancetype)initWithBuffer:(CMSampleBufferRef _Nonnull)buffer
|
||||
orientation:(UIImageOrientation)orientation {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_buffer = buffer;
|
||||
|
@@ -8,16 +8,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <jsi/jsi.h>
|
||||
#import <CoreMedia/CMSampleBuffer.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
#import "Frame.h"
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class JSI_EXPORT FrameHostObject: public jsi::HostObject {
|
||||
class JSI_EXPORT FrameHostObject : public jsi::HostObject {
|
||||
public:
|
||||
explicit FrameHostObject(Frame* frame): frame(frame) {}
|
||||
explicit FrameHostObject(Frame* frame) : frame(frame) {}
|
||||
|
||||
public:
|
||||
jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
|
||||
|
@@ -7,9 +7,9 @@
|
||||
//
|
||||
|
||||
#import "FrameHostObject.h"
|
||||
#import "WKTJsiHostObject.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <jsi/jsi.h>
|
||||
#import "WKTJsiHostObject.h"
|
||||
|
||||
#import "../../cpp/JSITypedArray.h"
|
||||
|
||||
@@ -46,10 +46,12 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
auto width = CVPixelBufferGetWidth(imageBuffer);
|
||||
auto height = CVPixelBufferGetHeight(imageBuffer);
|
||||
|
||||
NSMutableString* string = [NSMutableString stringWithFormat:@"%lu x %lu Frame", width, height];
|
||||
NSMutableString* string =
|
||||
[NSMutableString stringWithFormat:@"%lu x %lu Frame", width, height];
|
||||
return jsi::String::createFromUtf8(runtime, string.UTF8String);
|
||||
};
|
||||
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "toString"), 0, toString);
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "toString"), 0, toString);
|
||||
}
|
||||
if (name == "incrementRefCount") {
|
||||
auto incrementRefCount = JSI_HOST_FUNCTION_LAMBDA {
|
||||
@@ -57,21 +59,18 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
CFRetain(frame.buffer);
|
||||
return jsi::Value::undefined();
|
||||
};
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "incrementRefCount"),
|
||||
0,
|
||||
incrementRefCount);
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "incrementRefCount"), 0, incrementRefCount);
|
||||
}
|
||||
if (name == "decrementRefCount") {
|
||||
auto decrementRefCount = JSI_HOST_FUNCTION_LAMBDA {
|
||||
// Decrement retain count by one. If the retain count is zero, ARC will destroy the Frame Buffer.
|
||||
// Decrement retain count by one. If the retain count is zero, ARC will destroy the Frame
|
||||
// Buffer.
|
||||
CFRelease(frame.buffer);
|
||||
return jsi::Value::undefined();
|
||||
};
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "decrementRefCount"),
|
||||
0,
|
||||
decrementRefCount);
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "decrementRefCount"), 0, decrementRefCount);
|
||||
}
|
||||
if (name == "toArrayBuffer") {
|
||||
auto toArrayBuffer = JSI_HOST_FUNCTION_LAMBDA {
|
||||
@@ -83,41 +82,47 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
|
||||
static constexpr auto ARRAYBUFFER_CACHE_PROP_NAME = "__frameArrayBufferCache";
|
||||
if (!runtime.global().hasProperty(runtime, ARRAYBUFFER_CACHE_PROP_NAME)) {
|
||||
vision::TypedArray<vision::TypedArrayKind::Uint8ClampedArray> arrayBuffer(runtime, arraySize);
|
||||
vision::TypedArray<vision::TypedArrayKind::Uint8ClampedArray> arrayBuffer(runtime,
|
||||
arraySize);
|
||||
runtime.global().setProperty(runtime, ARRAYBUFFER_CACHE_PROP_NAME, arrayBuffer);
|
||||
}
|
||||
|
||||
auto arrayBufferCache = runtime.global().getPropertyAsObject(runtime, ARRAYBUFFER_CACHE_PROP_NAME);
|
||||
auto arrayBuffer = vision::getTypedArray(runtime, arrayBufferCache).get<vision::TypedArrayKind::Uint8ClampedArray>(runtime);
|
||||
auto arrayBufferCache =
|
||||
runtime.global().getPropertyAsObject(runtime, ARRAYBUFFER_CACHE_PROP_NAME);
|
||||
auto arrayBuffer = vision::getTypedArray(runtime, arrayBufferCache)
|
||||
.get<vision::TypedArrayKind::Uint8ClampedArray>(runtime);
|
||||
|
||||
if (arrayBuffer.size(runtime) != arraySize) {
|
||||
arrayBuffer = vision::TypedArray<vision::TypedArrayKind::Uint8ClampedArray>(runtime, arraySize);
|
||||
arrayBuffer =
|
||||
vision::TypedArray<vision::TypedArrayKind::Uint8ClampedArray>(runtime, arraySize);
|
||||
runtime.global().setProperty(runtime, ARRAYBUFFER_CACHE_PROP_NAME, arrayBuffer);
|
||||
}
|
||||
|
||||
CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
|
||||
auto buffer = (uint8_t*) CVPixelBufferGetBaseAddress(pixelBuffer);
|
||||
auto buffer = (uint8_t*)CVPixelBufferGetBaseAddress(pixelBuffer);
|
||||
arrayBuffer.updateUnsafe(runtime, buffer, arraySize);
|
||||
CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
|
||||
|
||||
return arrayBuffer;
|
||||
};
|
||||
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "toArrayBuffer"), 0, toArrayBuffer);
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "toArrayBuffer"), 0, toArrayBuffer);
|
||||
}
|
||||
|
||||
if (name == "isValid") {
|
||||
auto isValid = frame != nil && frame.buffer != nil && CFGetRetainCount(frame.buffer) > 0 && CMSampleBufferIsValid(frame.buffer);
|
||||
auto isValid = frame != nil && frame.buffer != nil && CFGetRetainCount(frame.buffer) > 0 &&
|
||||
CMSampleBufferIsValid(frame.buffer);
|
||||
return jsi::Value(isValid);
|
||||
}
|
||||
if (name == "width") {
|
||||
auto imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
|
||||
auto width = CVPixelBufferGetWidth(imageBuffer);
|
||||
return jsi::Value((double) width);
|
||||
return jsi::Value((double)width);
|
||||
}
|
||||
if (name == "height") {
|
||||
auto imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
|
||||
auto height = CVPixelBufferGetHeight(imageBuffer);
|
||||
return jsi::Value((double) height);
|
||||
return jsi::Value((double)height);
|
||||
}
|
||||
if (name == "orientation") {
|
||||
switch (frame.orientation) {
|
||||
@@ -170,12 +175,12 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
if (name == "bytesPerRow") {
|
||||
auto imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
|
||||
auto bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
|
||||
return jsi::Value((double) bytesPerRow);
|
||||
return jsi::Value((double)bytesPerRow);
|
||||
}
|
||||
if (name == "planesCount") {
|
||||
auto imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
|
||||
auto planesCount = CVPixelBufferGetPlaneCount(imageBuffer);
|
||||
return jsi::Value((double) planesCount);
|
||||
return jsi::Value((double)planesCount);
|
||||
}
|
||||
|
||||
// fallback to base implementation
|
||||
|
@@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "Frame.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#import "FrameHostObject.h"
|
||||
#import "WKTJsiWorklet.h"
|
||||
#import <jsi/jsi.h>
|
||||
#import "FrameHostObject.h"
|
||||
#import <memory.h>
|
||||
#endif
|
||||
|
||||
|
@@ -6,13 +6,13 @@
|
||||
// Copyright © 2023 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "FrameProcessor.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <memory>
|
||||
#import <jsi/jsi.h>
|
||||
#import "WKTJsiWorklet.h"
|
||||
#import "FrameHostObject.h"
|
||||
#import "WKTJsiWorklet.h"
|
||||
#import <jsi/jsi.h>
|
||||
#import <memory>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
@@ -33,21 +33,24 @@ using namespace facebook;
|
||||
- (void)callWithFrameHostObject:(std::shared_ptr<FrameHostObject>)frameHostObject {
|
||||
// Call the Frame Processor on the Worklet Runtime
|
||||
jsi::Runtime& runtime = _workletContext->getWorkletRuntime();
|
||||
|
||||
|
||||
try {
|
||||
// Wrap HostObject as JSI Value
|
||||
auto argument = jsi::Object::createFromHostObject(runtime, frameHostObject);
|
||||
jsi::Value jsValue(std::move(argument));
|
||||
|
||||
|
||||
// Call the Worklet with the Frame JS Host Object as an argument
|
||||
_workletInvoker->call(runtime, jsi::Value::undefined(), &jsValue, 1);
|
||||
} catch (jsi::JSError& jsError) {
|
||||
// JS Error occured, print it to console.
|
||||
auto message = jsError.getMessage();
|
||||
|
||||
|
||||
_workletContext->invokeOnJsThread([message](jsi::Runtime& jsRuntime) {
|
||||
auto logFn = jsRuntime.global().getPropertyAsObject(jsRuntime, "console").getPropertyAsFunction(jsRuntime, "error");
|
||||
logFn.call(jsRuntime, jsi::String::createFromUtf8(jsRuntime, "Frame Processor threw an error: " + message));
|
||||
auto logFn = jsRuntime.global()
|
||||
.getPropertyAsObject(jsRuntime, "console")
|
||||
.getPropertyAsFunction(jsRuntime, "error");
|
||||
logFn.call(jsRuntime, jsi::String::createFromUtf8(
|
||||
jsRuntime, "Frame Processor threw an error: " + message));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -8,19 +8,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Frame.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/// The base class for a Frame Processor Plugin which can be called synchronously from a JS Frame Processor.
|
||||
/// The base class for a Frame Processor Plugin which can be called synchronously from a JS Frame
|
||||
/// Processor.
|
||||
///
|
||||
/// Subclass this class in a Swift or Objective-C class and override the `callback:withArguments:` method, and
|
||||
/// implement your Frame Processing there.
|
||||
/// Subclass this class in a Swift or Objective-C class and override the `callback:withArguments:`
|
||||
/// method, and implement your Frame Processing there.
|
||||
///
|
||||
/// Use `[FrameProcessorPluginRegistry addFrameProcessorPlugin:]` to register the Plugin to the VisionCamera Runtime.
|
||||
/// Use `[FrameProcessorPluginRegistry addFrameProcessorPlugin:]` to register the Plugin to the
|
||||
/// VisionCamera Runtime.
|
||||
@interface FrameProcessorPlugin : NSObject
|
||||
|
||||
/// The actual callback when calling this plugin. Any Frame Processing should be handled there.
|
||||
/// Make sure your code is optimized, as this is a hot path.
|
||||
- (id _Nullable) callback:(Frame* _Nonnull)frame withArguments:(NSDictionary* _Nullable)arguments;
|
||||
- (id _Nullable)callback:(Frame* _Nonnull)frame withArguments:(NSDictionary* _Nullable)arguments;
|
||||
|
||||
@end
|
||||
|
@@ -12,8 +12,10 @@
|
||||
@implementation FrameProcessorPlugin
|
||||
|
||||
- (id _Nullable)callback:(Frame* _Nonnull)frame withArguments:(NSDictionary* _Nullable)arguments {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"Frame Processor Plugin does not override the `callback(frame:withArguments:)` method!"];
|
||||
[NSException
|
||||
raise:NSInternalInconsistencyException
|
||||
format:
|
||||
@"Frame Processor Plugin does not override the `callback(frame:withArguments:)` method!"];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@@ -8,24 +8,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <jsi/jsi.h>
|
||||
#import "FrameProcessorPlugin.h"
|
||||
#import <memory>
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <jsi/jsi.h>
|
||||
#import <memory>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class FrameProcessorPluginHostObject: public jsi::HostObject {
|
||||
class FrameProcessorPluginHostObject : public jsi::HostObject {
|
||||
public:
|
||||
explicit FrameProcessorPluginHostObject(FrameProcessorPlugin* plugin,
|
||||
std::shared_ptr<react::CallInvoker> callInvoker):
|
||||
_plugin(plugin), _callInvoker(callInvoker) { }
|
||||
~FrameProcessorPluginHostObject() { }
|
||||
|
||||
std::shared_ptr<react::CallInvoker> callInvoker)
|
||||
: _plugin(plugin), _callInvoker(callInvoker) {}
|
||||
~FrameProcessorPluginHostObject() {}
|
||||
|
||||
public:
|
||||
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override;
|
||||
jsi::Value get(jsi::Runtime& runtime, const jsi::PropNameID& name) override;
|
||||
|
||||
|
||||
private:
|
||||
FrameProcessorPlugin* _plugin;
|
||||
std::shared_ptr<react::CallInvoker> _callInvoker;
|
||||
|
@@ -7,47 +7,48 @@
|
||||
//
|
||||
|
||||
#import "FrameProcessorPluginHostObject.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <vector>
|
||||
#import "FrameHostObject.h"
|
||||
#import "JSINSObjectConversion.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <vector>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
std::vector<jsi::PropNameID> FrameProcessorPluginHostObject::getPropertyNames(jsi::Runtime& runtime) {
|
||||
std::vector<jsi::PropNameID>
|
||||
FrameProcessorPluginHostObject::getPropertyNames(jsi::Runtime& runtime) {
|
||||
std::vector<jsi::PropNameID> result;
|
||||
result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("call")));
|
||||
return result;
|
||||
}
|
||||
|
||||
jsi::Value FrameProcessorPluginHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
|
||||
jsi::Value FrameProcessorPluginHostObject::get(jsi::Runtime& runtime,
|
||||
const jsi::PropNameID& propName) {
|
||||
auto name = propName.utf8(runtime);
|
||||
|
||||
if (name == "call") {
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "call"),
|
||||
2,
|
||||
[=](jsi::Runtime& runtime,
|
||||
const jsi::Value& thisValue,
|
||||
const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
// Frame is first argument
|
||||
auto frameHostObject = arguments[0].asObject(runtime).asHostObject<FrameHostObject>(runtime);
|
||||
Frame* frame = frameHostObject->frame;
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "call"), 2,
|
||||
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
// Frame is first argument
|
||||
auto frameHostObject =
|
||||
arguments[0].asObject(runtime).asHostObject<FrameHostObject>(runtime);
|
||||
Frame* frame = frameHostObject->frame;
|
||||
|
||||
// Options are second argument (possibly undefined)
|
||||
NSDictionary* options = nil;
|
||||
if (count > 1) {
|
||||
auto optionsObject = arguments[1].asObject(runtime);
|
||||
options = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, optionsObject, _callInvoker);
|
||||
}
|
||||
// Options are second argument (possibly undefined)
|
||||
NSDictionary* options = nil;
|
||||
if (count > 1) {
|
||||
auto optionsObject = arguments[1].asObject(runtime);
|
||||
options = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, optionsObject,
|
||||
_callInvoker);
|
||||
}
|
||||
|
||||
// Call actual Frame Processor Plugin
|
||||
id result = [_plugin callback:frame withArguments:nil];
|
||||
// Call actual Frame Processor Plugin
|
||||
id result = [_plugin callback:frame withArguments:nil];
|
||||
|
||||
// Convert result value to jsi::Value (possibly undefined)
|
||||
return JSINSObjectConversion::convertObjCObjectToJSIValue(runtime, result);
|
||||
});
|
||||
// Convert result value to jsi::Value (possibly undefined)
|
||||
return JSINSObjectConversion::convertObjCObjectToJSIValue(runtime, result);
|
||||
});
|
||||
}
|
||||
|
||||
return jsi::Value::undefined();
|
||||
|
@@ -8,13 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Frame.h"
|
||||
#import "FrameProcessorPlugin.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface FrameProcessorPluginRegistry : NSObject
|
||||
|
||||
typedef FrameProcessorPlugin* _Nonnull (^PluginInitializerFunction)(NSDictionary* _Nullable options);
|
||||
typedef FrameProcessorPlugin* _Nonnull (^PluginInitializerFunction)(
|
||||
NSDictionary* _Nullable options);
|
||||
|
||||
+ (void)addFrameProcessorPlugin:(NSString* _Nonnull)name
|
||||
withInitializer:(PluginInitializerFunction _Nonnull)pluginInitializer;
|
||||
|
@@ -19,19 +19,27 @@
|
||||
return plugins;
|
||||
}
|
||||
|
||||
+ (void) addFrameProcessorPlugin:(NSString *)name withInitializer:(PluginInitializerFunction)pluginInitializer {
|
||||
BOOL alreadyExists = [[FrameProcessorPluginRegistry frameProcessorPlugins] valueForKey:name] != nil;
|
||||
NSAssert(!alreadyExists, @"Tried to add a Frame Processor Plugin with a name that already exists! Either choose unique names, or remove the unused plugin. Name: %@", name);
|
||||
+ (void)addFrameProcessorPlugin:(NSString*)name
|
||||
withInitializer:(PluginInitializerFunction)pluginInitializer {
|
||||
BOOL alreadyExists =
|
||||
[[FrameProcessorPluginRegistry frameProcessorPlugins] valueForKey:name] != nil;
|
||||
NSAssert(!alreadyExists,
|
||||
@"Tried to add a Frame Processor Plugin with a name that already exists! Either choose "
|
||||
@"unique names, or "
|
||||
@"remove the unused plugin. Name: %@",
|
||||
name);
|
||||
|
||||
[[FrameProcessorPluginRegistry frameProcessorPlugins] setValue:pluginInitializer forKey:name];
|
||||
}
|
||||
|
||||
+ (FrameProcessorPlugin*)getPlugin:(NSString* _Nonnull)name withOptions:(NSDictionary* _Nullable)options {
|
||||
PluginInitializerFunction initializer = [[FrameProcessorPluginRegistry frameProcessorPlugins] objectForKey:name];
|
||||
+ (FrameProcessorPlugin*)getPlugin:(NSString* _Nonnull)name
|
||||
withOptions:(NSDictionary* _Nullable)options {
|
||||
PluginInitializerFunction initializer =
|
||||
[[FrameProcessorPluginRegistry frameProcessorPlugins] objectForKey:name];
|
||||
if (initializer == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
return initializer(options);
|
||||
}
|
||||
|
||||
|
@@ -8,9 +8,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <jsi/jsi.h>
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <React/RCTBridgeModule.h>
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
namespace JSINSObjectConversion {
|
||||
|
||||
@@ -39,21 +39,27 @@ jsi::Value convertObjCObjectToJSIValue(jsi::Runtime& runtime, id value);
|
||||
NSString* convertJSIStringToNSString(jsi::Runtime& runtime, const jsi::String& value);
|
||||
|
||||
// any... -> NSArray
|
||||
NSArray* convertJSICStyleArrayToNSArray(jsi::Runtime& runtime, const jsi::Value* array, size_t length, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
NSArray* convertJSICStyleArrayToNSArray(jsi::Runtime& runtime, const jsi::Value* array,
|
||||
size_t length, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
// NSArray -> any...
|
||||
jsi::Value* convertNSArrayToJSICStyleArray(jsi::Runtime& runtime, NSArray* array);
|
||||
|
||||
// [] -> NSArray
|
||||
NSArray* convertJSIArrayToNSArray(jsi::Runtime& runtime, const jsi::Array& value, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
NSArray* convertJSIArrayToNSArray(jsi::Runtime& runtime, const jsi::Array& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
// {} -> NSDictionary
|
||||
NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime& runtime, const jsi::Object& value, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime& runtime, const jsi::Object& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
// any -> id
|
||||
id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
// (any...) => any -> (void)(id, id)
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime, const jsi::Function& value, std::shared_ptr<CallInvoker> jsInvoker);
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime,
|
||||
const jsi::Function& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
} // namespace JSINSObjectConversion
|
||||
|
@@ -5,7 +5,8 @@
|
||||
// Forked and Adjusted by Marc Rousavy on 02.05.21.
|
||||
// Copyright © 2021 mrousavy & Facebook. All rights reserved.
|
||||
//
|
||||
// Forked and adjusted from: https://github.com/facebook/react-native/blob/900210cacc4abca0079e3903781bc223c80c8ac7/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModule.mm
|
||||
// Forked and adjusted from:
|
||||
// https://github.com/facebook/react-native/blob/900210cacc4abca0079e3903781bc223c80c8ac7/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModule.mm
|
||||
// Original Copyright Notice:
|
||||
//
|
||||
// Copyright (c) Facebook, Inc. and its affiliates.
|
||||
@@ -15,46 +16,41 @@
|
||||
//
|
||||
|
||||
#import "JSINSObjectConversion.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <jsi/jsi.h>
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <React/RCTBridge.h>
|
||||
#import <ReactCommon/TurboModuleUtils.h>
|
||||
#import <ReactCommon/RCTBlockGuard.h>
|
||||
#import "../Frame Processor/Frame.h"
|
||||
#import "../Frame Processor/FrameHostObject.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <React/RCTBridge.h>
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <ReactCommon/RCTBlockGuard.h>
|
||||
#import <ReactCommon/TurboModuleUtils.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
using namespace facebook;
|
||||
using namespace facebook::react;
|
||||
|
||||
namespace JSINSObjectConversion {
|
||||
|
||||
jsi::Value convertNSNumberToJSIBoolean(jsi::Runtime &runtime, NSNumber *value)
|
||||
{
|
||||
jsi::Value convertNSNumberToJSIBoolean(jsi::Runtime& runtime, NSNumber* value) {
|
||||
return jsi::Value((bool)[value boolValue]);
|
||||
}
|
||||
|
||||
jsi::Value convertNSNumberToJSINumber(jsi::Runtime &runtime, NSNumber *value)
|
||||
{
|
||||
jsi::Value convertNSNumberToJSINumber(jsi::Runtime& runtime, NSNumber* value) {
|
||||
return jsi::Value([value doubleValue]);
|
||||
}
|
||||
|
||||
jsi::String convertNSStringToJSIString(jsi::Runtime &runtime, NSString *value)
|
||||
{
|
||||
jsi::String convertNSStringToJSIString(jsi::Runtime& runtime, NSString* value) {
|
||||
return jsi::String::createFromUtf8(runtime, [value UTF8String] ?: "");
|
||||
}
|
||||
|
||||
jsi::Object convertNSDictionaryToJSIObject(jsi::Runtime &runtime, NSDictionary *value)
|
||||
{
|
||||
jsi::Object convertNSDictionaryToJSIObject(jsi::Runtime& runtime, NSDictionary* value) {
|
||||
jsi::Object result = jsi::Object(runtime);
|
||||
for (NSString *k in value) {
|
||||
for (NSString* k in value) {
|
||||
result.setProperty(runtime, [k UTF8String], convertObjCObjectToJSIValue(runtime, value[k]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
jsi::Array convertNSArrayToJSIArray(jsi::Runtime &runtime, NSArray *value)
|
||||
{
|
||||
jsi::Array convertNSArrayToJSIArray(jsi::Runtime& runtime, NSArray* value) {
|
||||
jsi::Array result = jsi::Array(runtime, value.count);
|
||||
for (size_t i = 0; i < value.count; i++) {
|
||||
result.setValueAtIndex(runtime, i, convertObjCObjectToJSIValue(runtime, value[i]));
|
||||
@@ -62,21 +58,20 @@ jsi::Array convertNSArrayToJSIArray(jsi::Runtime &runtime, NSArray *value)
|
||||
return result;
|
||||
}
|
||||
|
||||
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
|
||||
{
|
||||
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime& runtime, id value) {
|
||||
if (value == nil) {
|
||||
return jsi::Value::undefined();
|
||||
} else if ([value isKindOfClass:[NSString class]]) {
|
||||
return convertNSStringToJSIString(runtime, (NSString *)value);
|
||||
return convertNSStringToJSIString(runtime, (NSString*)value);
|
||||
} else if ([value isKindOfClass:[NSNumber class]]) {
|
||||
if ([value isKindOfClass:[@YES class]]) {
|
||||
return convertNSNumberToJSIBoolean(runtime, (NSNumber *)value);
|
||||
return convertNSNumberToJSIBoolean(runtime, (NSNumber*)value);
|
||||
}
|
||||
return convertNSNumberToJSINumber(runtime, (NSNumber *)value);
|
||||
return convertNSNumberToJSINumber(runtime, (NSNumber*)value);
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
return convertNSDictionaryToJSIObject(runtime, (NSDictionary *)value);
|
||||
return convertNSDictionaryToJSIObject(runtime, (NSDictionary*)value);
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
return convertNSArrayToJSIArray(runtime, (NSArray *)value);
|
||||
return convertNSArrayToJSIArray(runtime, (NSArray*)value);
|
||||
} else if (value == (id)kCFNull) {
|
||||
return jsi::Value::null();
|
||||
} else if ([value isKindOfClass:[Frame class]]) {
|
||||
@@ -86,23 +81,23 @@ jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
NSString *convertJSIStringToNSString(jsi::Runtime &runtime, const jsi::String &value)
|
||||
{
|
||||
NSString* convertJSIStringToNSString(jsi::Runtime& runtime, const jsi::String& value) {
|
||||
return [NSString stringWithUTF8String:value.utf8(runtime).c_str()];
|
||||
}
|
||||
|
||||
NSArray* convertJSICStyleArrayToNSArray(jsi::Runtime &runtime, const jsi::Value* array, size_t length, std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
if (length < 1) return @[];
|
||||
NSMutableArray *result = [NSMutableArray new];
|
||||
NSArray* convertJSICStyleArrayToNSArray(jsi::Runtime& runtime, const jsi::Value* array,
|
||||
size_t length, std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
if (length < 1)
|
||||
return @[];
|
||||
NSMutableArray* result = [NSMutableArray new];
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
// Insert kCFNull when it's `undefined` value to preserve the indices.
|
||||
[result
|
||||
addObject:convertJSIValueToObjCObject(runtime, array[i], jsInvoker) ?: (id)kCFNull];
|
||||
[result addObject:convertJSIValueToObjCObject(runtime, array[i], jsInvoker) ?: (id)kCFNull];
|
||||
}
|
||||
return [result copy];
|
||||
}
|
||||
|
||||
jsi::Value* convertNSArrayToJSICStyleArray(jsi::Runtime &runtime, NSArray* array) {
|
||||
jsi::Value* convertNSArrayToJSICStyleArray(jsi::Runtime& runtime, NSArray* array) {
|
||||
auto result = new jsi::Value[array.count];
|
||||
for (size_t i = 0; i < array.count; i++) {
|
||||
result[i] = convertObjCObjectToJSIValue(runtime, array[i]);
|
||||
@@ -110,26 +105,27 @@ jsi::Value* convertNSArrayToJSICStyleArray(jsi::Runtime &runtime, NSArray* array
|
||||
return result;
|
||||
}
|
||||
|
||||
NSArray* convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array &value, std::shared_ptr<CallInvoker> jsInvoker)
|
||||
{
|
||||
NSArray* convertJSIArrayToNSArray(jsi::Runtime& runtime, const jsi::Array& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
size_t size = value.size(runtime);
|
||||
NSMutableArray *result = [NSMutableArray new];
|
||||
NSMutableArray* result = [NSMutableArray new];
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
// Insert kCFNull when it's `undefined` value to preserve the indices.
|
||||
[result
|
||||
addObject:convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i), jsInvoker) ?: (id)kCFNull];
|
||||
addObject:convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i), jsInvoker)
|
||||
?: (id)kCFNull];
|
||||
}
|
||||
return [result copy];
|
||||
}
|
||||
|
||||
NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::Object &value, std::shared_ptr<CallInvoker> jsInvoker)
|
||||
{
|
||||
NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime& runtime, const jsi::Object& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
jsi::Array propertyNames = value.getPropertyNames(runtime);
|
||||
size_t size = propertyNames.size(runtime);
|
||||
NSMutableDictionary *result = [NSMutableDictionary new];
|
||||
NSMutableDictionary* result = [NSMutableDictionary new];
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
jsi::String name = propertyNames.getValueAtIndex(runtime, i).getString(runtime);
|
||||
NSString *k = convertJSIStringToNSString(runtime, name);
|
||||
NSString* k = convertJSIStringToNSString(runtime, name);
|
||||
id v = convertJSIValueToObjCObject(runtime, value.getProperty(runtime, name), jsInvoker);
|
||||
if (v) {
|
||||
result[k] = v;
|
||||
@@ -138,8 +134,8 @@ NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const jsi::O
|
||||
return [result copy];
|
||||
}
|
||||
|
||||
id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, std::shared_ptr<CallInvoker> jsInvoker)
|
||||
{
|
||||
id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
if (value.isUndefined() || value.isNull()) {
|
||||
return nil;
|
||||
}
|
||||
@@ -169,50 +165,52 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
|
||||
}
|
||||
return convertJSIObjectToNSDictionary(runtime, o, jsInvoker);
|
||||
}
|
||||
|
||||
|
||||
throw std::runtime_error("Unsupported jsi::jsi::Value kind");
|
||||
}
|
||||
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const jsi::Function &value, std::shared_ptr<CallInvoker> jsInvoker)
|
||||
{
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime,
|
||||
const jsi::Function& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker) {
|
||||
auto weakWrapper = CallbackWrapper::createWeak(value.getFunction(runtime), runtime, jsInvoker);
|
||||
RCTBlockGuard *blockGuard = [[RCTBlockGuard alloc] initWithCleanup:^() {
|
||||
RCTBlockGuard* blockGuard = [[RCTBlockGuard alloc] initWithCleanup:^() {
|
||||
auto strongWrapper = weakWrapper.lock();
|
||||
if (strongWrapper) {
|
||||
strongWrapper->destroy();
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
BOOL __block wrapperWasCalled = NO;
|
||||
RCTResponseSenderBlock callback = ^(NSArray *responses) {
|
||||
RCTResponseSenderBlock callback = ^(NSArray* responses) {
|
||||
if (wrapperWasCalled) {
|
||||
throw std::runtime_error("callback arg cannot be called more than once");
|
||||
}
|
||||
|
||||
|
||||
auto strongWrapper = weakWrapper.lock();
|
||||
if (!strongWrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
strongWrapper->jsInvoker().invokeAsync([weakWrapper, responses, blockGuard]() {
|
||||
auto strongWrapper2 = weakWrapper.lock();
|
||||
if (!strongWrapper2) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const jsi::Value* args = convertNSArrayToJSICStyleArray(strongWrapper2->runtime(), responses);
|
||||
strongWrapper2->callback().call(strongWrapper2->runtime(), args, static_cast<size_t>(responses.count));
|
||||
strongWrapper2->callback().call(strongWrapper2->runtime(), args,
|
||||
static_cast<size_t>(responses.count));
|
||||
strongWrapper2->destroy();
|
||||
delete[] args;
|
||||
|
||||
|
||||
// Delete the CallbackWrapper when the block gets dealloced without being invoked.
|
||||
(void)blockGuard;
|
||||
});
|
||||
|
||||
|
||||
wrapperWasCalled = YES;
|
||||
};
|
||||
|
||||
|
||||
return [callback copy];
|
||||
}
|
||||
|
||||
} // namespace JSIJNIObjectConversion
|
||||
} // namespace JSINSObjectConversion
|
||||
|
@@ -12,13 +12,13 @@
|
||||
#import <React/RCTBridge.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#import <jsi/jsi.h>
|
||||
#import "WKTJsiWorkletContext.h"
|
||||
#import <ReactCommon/CallInvoker.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class VisionCameraProxy: public jsi::HostObject {
|
||||
class VisionCameraProxy : public jsi::HostObject {
|
||||
public:
|
||||
explicit VisionCameraProxy(jsi::Runtime& runtime,
|
||||
std::shared_ptr<react::CallInvoker> callInvoker);
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
private:
|
||||
void setFrameProcessor(jsi::Runtime& runtime, int viewTag, const jsi::Object& frameProcessor);
|
||||
void removeFrameProcessor(jsi::Runtime& runtime, int viewTag);
|
||||
jsi::Value getFrameProcessorPlugin(jsi::Runtime& runtime, std::string name, const jsi::Object& options);
|
||||
jsi::Value getFrameProcessorPlugin(jsi::Runtime& runtime, std::string name,
|
||||
const jsi::Object& options);
|
||||
|
||||
private:
|
||||
std::shared_ptr<RNWorklet::JsiWorkletContext> _workletContext;
|
||||
|
@@ -10,29 +10,29 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <jsi/jsi.h>
|
||||
|
||||
#import "FrameProcessorPluginRegistry.h"
|
||||
#import "FrameProcessorPluginHostObject.h"
|
||||
#import "FrameProcessor.h"
|
||||
#import "FrameHostObject.h"
|
||||
#import "JSINSObjectConversion.h"
|
||||
#import "../../cpp/JSITypedArray.h"
|
||||
#import "FrameHostObject.h"
|
||||
#import "FrameProcessor.h"
|
||||
#import "FrameProcessorPluginHostObject.h"
|
||||
#import "FrameProcessorPluginRegistry.h"
|
||||
#import "JSINSObjectConversion.h"
|
||||
#import "WKTJsiWorklet.h"
|
||||
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTBridge+Private.h>
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTUIManager.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <ReactCommon/RCTTurboModuleManager.h>
|
||||
|
||||
// Swift forward-declarations
|
||||
__attribute__((objc_runtime_name("_TtC12VisionCamera12CameraQueues")))
|
||||
@interface CameraQueues: NSObject
|
||||
@property (nonatomic, class, readonly, strong) dispatch_queue_t _Nonnull videoQueue;
|
||||
@interface CameraQueues : NSObject
|
||||
@property(nonatomic, class, readonly, strong) dispatch_queue_t _Nonnull videoQueue;
|
||||
@end
|
||||
|
||||
__attribute__((objc_runtime_name("_TtC12VisionCamera10CameraView")))
|
||||
@interface CameraView: UIView
|
||||
@property (nonatomic, copy) FrameProcessor* _Nullable frameProcessor;
|
||||
@interface CameraView : UIView
|
||||
@property(nonatomic, copy) FrameProcessor* _Nullable frameProcessor;
|
||||
@end
|
||||
|
||||
using namespace facebook;
|
||||
@@ -48,15 +48,11 @@ VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime,
|
||||
};
|
||||
auto runOnWorklet = [](std::function<void()>&& f) {
|
||||
// Run on Frame Processor Worklet Runtime
|
||||
dispatch_async(CameraQueues.videoQueue, [f = std::move(f)](){
|
||||
f();
|
||||
});
|
||||
dispatch_async(CameraQueues.videoQueue, [f = std::move(f)]() { f(); });
|
||||
};
|
||||
|
||||
_workletContext = std::make_shared<RNWorklet::JsiWorkletContext>("VisionCamera",
|
||||
&runtime,
|
||||
runOnJS,
|
||||
runOnWorklet);
|
||||
_workletContext = std::make_shared<RNWorklet::JsiWorkletContext>("VisionCamera", &runtime,
|
||||
runOnJS, runOnWorklet);
|
||||
NSLog(@"VisionCameraProxy: Worklet Context Created!");
|
||||
}
|
||||
|
||||
@@ -75,20 +71,23 @@ std::vector<jsi::PropNameID> VisionCameraProxy::getPropertyNames(jsi::Runtime& r
|
||||
return result;
|
||||
}
|
||||
|
||||
void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag, const jsi::Object& object) {
|
||||
void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag,
|
||||
const jsi::Object& object) {
|
||||
auto frameProcessorType = object.getProperty(runtime, "type").asString(runtime).utf8(runtime);
|
||||
auto worklet = std::make_shared<RNWorklet::JsiWorklet>(runtime, object.getProperty(runtime, "frameProcessor"));
|
||||
auto worklet = std::make_shared<RNWorklet::JsiWorklet>(
|
||||
runtime, object.getProperty(runtime, "frameProcessor"));
|
||||
|
||||
RCTExecuteOnMainQueue(^{
|
||||
auto currentBridge = [RCTBridge currentBridge];
|
||||
auto anonymousView = [currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]];
|
||||
auto anonymousView =
|
||||
[currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]];
|
||||
auto view = static_cast<CameraView*>(anonymousView);
|
||||
if (frameProcessorType == "frame-processor") {
|
||||
view.frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet
|
||||
context:_workletContext];
|
||||
|
||||
} else {
|
||||
throw std::runtime_error("Unknown FrameProcessor.type passed! Received: " + frameProcessorType);
|
||||
throw std::runtime_error("Unknown FrameProcessor.type passed! Received: " +
|
||||
frameProcessorType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -96,16 +95,20 @@ void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag, co
|
||||
void VisionCameraProxy::removeFrameProcessor(jsi::Runtime& runtime, int viewTag) {
|
||||
RCTExecuteOnMainQueue(^{
|
||||
auto currentBridge = [RCTBridge currentBridge];
|
||||
auto anonymousView = [currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]];
|
||||
auto anonymousView =
|
||||
[currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]];
|
||||
auto view = static_cast<CameraView*>(anonymousView);
|
||||
view.frameProcessor = nil;
|
||||
});
|
||||
}
|
||||
|
||||
jsi::Value VisionCameraProxy::getFrameProcessorPlugin(jsi::Runtime& runtime, std::string name, const jsi::Object& options) {
|
||||
jsi::Value VisionCameraProxy::getFrameProcessorPlugin(jsi::Runtime& runtime, std::string name,
|
||||
const jsi::Object& options) {
|
||||
NSString* key = [NSString stringWithUTF8String:name.c_str()];
|
||||
NSDictionary* optionsObjc = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, options, _callInvoker);
|
||||
FrameProcessorPlugin* plugin = [FrameProcessorPluginRegistry getPlugin:key withOptions:optionsObjc];
|
||||
NSDictionary* optionsObjc =
|
||||
JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, options, _callInvoker);
|
||||
FrameProcessorPlugin* plugin = [FrameProcessorPluginRegistry getPlugin:key
|
||||
withOptions:optionsObjc];
|
||||
if (plugin == nil) {
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
@@ -118,54 +121,44 @@ jsi::Value VisionCameraProxy::get(jsi::Runtime& runtime, const jsi::PropNameID&
|
||||
auto name = propName.utf8(runtime);
|
||||
|
||||
if (name == "setFrameProcessor") {
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "setFrameProcessor"),
|
||||
1,
|
||||
[this](jsi::Runtime& runtime,
|
||||
const jsi::Value& thisValue,
|
||||
const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
auto viewTag = arguments[0].asNumber();
|
||||
auto object = arguments[1].asObject(runtime);
|
||||
this->setFrameProcessor(runtime, static_cast<int>(viewTag), object);
|
||||
return jsi::Value::undefined();
|
||||
});
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "setFrameProcessor"), 1,
|
||||
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
auto viewTag = arguments[0].asNumber();
|
||||
auto object = arguments[1].asObject(runtime);
|
||||
this->setFrameProcessor(runtime, static_cast<int>(viewTag), object);
|
||||
return jsi::Value::undefined();
|
||||
});
|
||||
}
|
||||
if (name == "removeFrameProcessor") {
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "removeFrameProcessor"),
|
||||
1,
|
||||
[this](jsi::Runtime& runtime,
|
||||
const jsi::Value& thisValue,
|
||||
const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
auto viewTag = arguments[0].asNumber();
|
||||
this->removeFrameProcessor(runtime, static_cast<int>(viewTag));
|
||||
return jsi::Value::undefined();
|
||||
});
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "removeFrameProcessor"), 1,
|
||||
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
auto viewTag = arguments[0].asNumber();
|
||||
this->removeFrameProcessor(runtime, static_cast<int>(viewTag));
|
||||
return jsi::Value::undefined();
|
||||
});
|
||||
}
|
||||
if (name == "getFrameProcessorPlugin") {
|
||||
return jsi::Function::createFromHostFunction(runtime,
|
||||
jsi::PropNameID::forUtf8(runtime, "getFrameProcessorPlugin"),
|
||||
1,
|
||||
[this](jsi::Runtime& runtime,
|
||||
const jsi::Value& thisValue,
|
||||
const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
if (count < 1 || !arguments[0].isString()) {
|
||||
throw jsi::JSError(runtime, "First argument needs to be a string (pluginName)!");
|
||||
}
|
||||
auto pluginName = arguments[0].asString(runtime).utf8(runtime);
|
||||
auto options = count > 1 ? arguments[1].asObject(runtime) : jsi::Object(runtime);
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime, jsi::PropNameID::forUtf8(runtime, "getFrameProcessorPlugin"), 1,
|
||||
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
|
||||
size_t count) -> jsi::Value {
|
||||
if (count < 1 || !arguments[0].isString()) {
|
||||
throw jsi::JSError(runtime, "First argument needs to be a string (pluginName)!");
|
||||
}
|
||||
auto pluginName = arguments[0].asString(runtime).utf8(runtime);
|
||||
auto options = count > 1 ? arguments[1].asObject(runtime) : jsi::Object(runtime);
|
||||
|
||||
return this->getFrameProcessorPlugin(runtime, pluginName, options);
|
||||
});
|
||||
return this->getFrameProcessorPlugin(runtime, pluginName, options);
|
||||
});
|
||||
}
|
||||
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
|
||||
@implementation VisionCameraInstaller
|
||||
+ (BOOL)installToBridge:(RCTBridge* _Nonnull)bridge {
|
||||
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)[RCTBridge currentBridge];
|
||||
@@ -177,8 +170,7 @@ jsi::Value VisionCameraProxy::get(jsi::Runtime& runtime, const jsi::PropNameID&
|
||||
|
||||
// global.VisionCameraProxy
|
||||
auto visionCameraProxy = std::make_shared<VisionCameraProxy>(runtime, bridge.jsCallInvoker);
|
||||
runtime.global().setProperty(runtime,
|
||||
"VisionCameraProxy",
|
||||
runtime.global().setProperty(runtime, "VisionCameraProxy",
|
||||
jsi::Object::createFromHostObject(runtime, visionCameraProxy));
|
||||
|
||||
return YES;
|
||||
|
Reference in New Issue
Block a user