chore: Change line width to 140 in C++
This commit is contained in:
@@ -14,22 +14,12 @@
|
||||
@interface RCT_EXTERN_REMAP_MODULE (CameraView, CameraViewManager, RCTViewManager)
|
||||
|
||||
// Module Functions
|
||||
RCT_EXTERN_METHOD(getCameraPermissionStatus
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(getMicrophonePermissionStatus
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(requestCameraPermission
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(requestMicrophonePermission
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(getCameraPermissionStatus : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(getMicrophonePermissionStatus : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(requestCameraPermission : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(requestMicrophonePermission : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
|
||||
RCT_EXTERN_METHOD(getAvailableCameraDevices
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(getAvailableCameraDevices : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
|
||||
// Camera View Properties
|
||||
RCT_EXPORT_VIEW_PROPERTY(isActive, BOOL);
|
||||
@@ -73,10 +63,7 @@ RCT_EXTERN_METHOD(resumeRecording
|
||||
: (nonnull NSNumber*)node resolve
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(stopRecording
|
||||
: (nonnull NSNumber*)node resolve
|
||||
: (RCTPromiseResolveBlock)resolve reject
|
||||
: (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(stopRecording : (nonnull NSNumber*)node resolve : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
|
||||
RCT_EXTERN_METHOD(takePhoto
|
||||
: (nonnull NSNumber*)node options
|
||||
: (NSDictionary*)options resolve
|
||||
|
@@ -14,8 +14,7 @@
|
||||
|
||||
@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;
|
||||
|
@@ -15,8 +15,7 @@
|
||||
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;
|
||||
|
@@ -46,12 +46,10 @@ 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 {
|
||||
@@ -59,8 +57,7 @@ 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 {
|
||||
@@ -69,8 +66,7 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
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 {
|
||||
@@ -82,19 +78,15 @@ 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);
|
||||
}
|
||||
|
||||
@@ -105,13 +97,11 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
||||
|
||||
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") {
|
||||
|
@@ -46,11 +46,8 @@ using namespace facebook;
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -12,10 +12,8 @@
|
||||
@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;
|
||||
}
|
||||
|
||||
|
@@ -17,8 +17,7 @@ using namespace facebook;
|
||||
|
||||
class FrameProcessorPluginHostObject : public jsi::HostObject {
|
||||
public:
|
||||
explicit FrameProcessorPluginHostObject(FrameProcessorPlugin* plugin,
|
||||
std::shared_ptr<react::CallInvoker> callInvoker)
|
||||
explicit FrameProcessorPluginHostObject(FrameProcessorPlugin* plugin, std::shared_ptr<react::CallInvoker> callInvoker)
|
||||
: _plugin(plugin), _callInvoker(callInvoker) {}
|
||||
~FrameProcessorPluginHostObject() {}
|
||||
|
||||
|
@@ -14,33 +14,28 @@
|
||||
|
||||
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 {
|
||||
[=](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);
|
||||
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 = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, optionsObject, _callInvoker);
|
||||
}
|
||||
|
||||
// Call actual Frame Processor Plugin
|
||||
|
@@ -14,13 +14,10 @@
|
||||
|
||||
@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;
|
||||
+ (void)addFrameProcessorPlugin:(NSString* _Nonnull)name withInitializer:(PluginInitializerFunction _Nonnull)pluginInitializer;
|
||||
|
||||
+ (FrameProcessorPlugin* _Nullable)getPlugin:(NSString* _Nonnull)name
|
||||
withOptions:(NSDictionary* _Nullable)options;
|
||||
+ (FrameProcessorPlugin* _Nullable)getPlugin:(NSString* _Nonnull)name withOptions:(NSDictionary* _Nullable)options;
|
||||
|
||||
@end
|
||||
|
@@ -19,10 +19,8 @@
|
||||
return plugins;
|
||||
}
|
||||
|
||||
+ (void)addFrameProcessorPlugin:(NSString*)name
|
||||
withInitializer:(PluginInitializerFunction)pluginInitializer {
|
||||
BOOL alreadyExists =
|
||||
[[FrameProcessorPluginRegistry frameProcessorPlugins] valueForKey:name] != nil;
|
||||
+ (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 "
|
||||
@@ -32,10 +30,8 @@
|
||||
[[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;
|
||||
}
|
||||
|
@@ -39,27 +39,23 @@ 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,
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime, const jsi::Function& value,
|
||||
std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
} // namespace JSINSObjectConversion
|
||||
|
@@ -85,8 +85,8 @@ NSString* convertJSIStringToNSString(jsi::Runtime& runtime, const jsi::String& v
|
||||
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) {
|
||||
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];
|
||||
@@ -105,21 +105,17 @@ 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];
|
||||
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];
|
||||
[result 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];
|
||||
@@ -134,8 +130,7 @@ 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,8 +164,7 @@ id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value,
|
||||
throw std::runtime_error("Unsupported jsi::jsi::Value kind");
|
||||
}
|
||||
|
||||
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime,
|
||||
const jsi::Function& value,
|
||||
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:^() {
|
||||
@@ -198,8 +192,7 @@ RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime,
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@@ -20,8 +20,7 @@ using namespace facebook;
|
||||
|
||||
class VisionCameraProxy : public jsi::HostObject {
|
||||
public:
|
||||
explicit VisionCameraProxy(jsi::Runtime& runtime,
|
||||
std::shared_ptr<react::CallInvoker> callInvoker);
|
||||
explicit VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr<react::CallInvoker> callInvoker);
|
||||
~VisionCameraProxy();
|
||||
|
||||
public:
|
||||
@@ -31,8 +30,7 @@ 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;
|
||||
|
@@ -37,8 +37,7 @@ __attribute__((objc_runtime_name("_TtC12VisionCamera10CameraView")))
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime,
|
||||
std::shared_ptr<react::CallInvoker> callInvoker) {
|
||||
VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr<react::CallInvoker> callInvoker) {
|
||||
_callInvoker = callInvoker;
|
||||
|
||||
NSLog(@"VisionCameraProxy: Creating Worklet Context...");
|
||||
@@ -51,8 +50,7 @@ VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime,
|
||||
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!");
|
||||
}
|
||||
|
||||
@@ -71,23 +69,18 @@ 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];
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -95,20 +88,16 @@ void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag,
|
||||
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();
|
||||
}
|
||||
@@ -123,8 +112,7 @@ jsi::Value VisionCameraProxy::get(jsi::Runtime& runtime, const jsi::PropNameID&
|
||||
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 {
|
||||
[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);
|
||||
@@ -134,8 +122,7 @@ jsi::Value VisionCameraProxy::get(jsi::Runtime& runtime, const jsi::PropNameID&
|
||||
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 {
|
||||
[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();
|
||||
@@ -144,8 +131,7 @@ jsi::Value VisionCameraProxy::get(jsi::Runtime& runtime, const jsi::PropNameID&
|
||||
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 {
|
||||
[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)!");
|
||||
}
|
||||
@@ -170,8 +156,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",
|
||||
jsi::Object::createFromHostObject(runtime, visionCameraProxy));
|
||||
runtime.global().setProperty(runtime, "VisionCameraProxy", jsi::Object::createFromHostObject(runtime, visionCameraProxy));
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
Reference in New Issue
Block a user