feat: Add console
logging support for Frame Processors (#297)
* Try to log to console via runOnJS * Call `console.log` * Create custom `VisionCameraScheduler` * Fix scheduler call * Call with this * Fix console setting * Move J---- to `java-bindings` * c++ style * Android: 1/2 Create custom Scheduler * Android: 2/2 Use custom Scheduler * Don't use `runOnJS`, use `__callAsync` directly
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
#if __has_include(<RNReanimated/RuntimeManager.h>)
|
||||
#import <RNReanimated/RuntimeManager.h>
|
||||
#import <RNReanimated/RuntimeDecorator.h>
|
||||
#import <RNReanimated/REAIOSScheduler.h>
|
||||
#import <RNReanimated/REAIOSErrorHandler.h>
|
||||
#define ENABLE_FRAME_PROCESSORS
|
||||
#else
|
||||
@@ -37,6 +36,7 @@
|
||||
|
||||
#import "FrameProcessorUtils.h"
|
||||
#import "FrameProcessorCallback.h"
|
||||
#import "VisionCameraScheduler.h"
|
||||
#import "../React Utils/MakeJSIRuntime.h"
|
||||
#import "../React Utils/JSIUtils.h"
|
||||
|
||||
@@ -69,7 +69,7 @@ __attribute__((objc_runtime_name("_TtC12VisionCamera10CameraView")))
|
||||
runtime->global().setProperty(*runtime, "_FRAME_PROCESSOR", jsi::Value(true));
|
||||
|
||||
auto callInvoker = bridge.jsCallInvoker;
|
||||
auto scheduler = std::make_shared<reanimated::REAIOSScheduler>(callInvoker);
|
||||
auto scheduler = std::make_shared<vision::VisionCameraScheduler>(callInvoker);
|
||||
runtimeManager = std::make_unique<reanimated::RuntimeManager>(std::move(runtime),
|
||||
std::make_shared<reanimated::REAIOSErrorHandler>(scheduler),
|
||||
scheduler);
|
||||
@@ -148,13 +148,14 @@ __attribute__((objc_runtime_name("_TtC12VisionCamera10CameraView")))
|
||||
auto worklet = reanimated::ShareableValue::adapt(runtime, arguments[1], runtimeManager.get());
|
||||
NSLog(@"FrameProcessorBindings: Successfully created worklet!");
|
||||
|
||||
RCTExecuteOnMainQueue([worklet, viewTag, self]() {
|
||||
RCTExecuteOnMainQueue([=]() {
|
||||
auto currentBridge = [RCTBridge currentBridge];
|
||||
auto anonymousView = [currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]];
|
||||
auto view = static_cast<CameraView*>(anonymousView);
|
||||
|
||||
dispatch_async(CameraQueues.frameProcessorQueue, [worklet, view, self]() {
|
||||
dispatch_async(CameraQueues.frameProcessorQueue, [=]() {
|
||||
NSLog(@"FrameProcessorBindings: Converting worklet to Objective-C callback...");
|
||||
|
||||
auto& rt = *runtimeManager->runtime;
|
||||
auto function = worklet->getValue(rt).asObject(rt).asFunction(rt);
|
||||
|
||||
|
@@ -25,7 +25,7 @@ FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime &
|
||||
|
||||
auto frameHostObject = std::make_shared<FrameHostObject>(frame);
|
||||
try {
|
||||
cb.call(runtime, jsi::Object::createFromHostObject(runtime, frameHostObject));
|
||||
cb.callWithThis(runtime, cb, jsi::Object::createFromHostObject(runtime, frameHostObject));
|
||||
} catch (jsi::JSError& jsError) {
|
||||
auto message = jsError.getMessage();
|
||||
RCTBridge* bridge = [RCTBridge currentBridge];
|
||||
|
26
ios/Frame Processor/VisionCameraScheduler.h
Normal file
26
ios/Frame Processor/VisionCameraScheduler.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// VisionCameraScheduler.h
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 23.07.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <RNReanimated/Scheduler.h>
|
||||
#import <React-callinvoker/ReactCommon/CallInvoker.h>
|
||||
|
||||
namespace vision {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
class VisionCameraScheduler : public reanimated::Scheduler {
|
||||
public:
|
||||
VisionCameraScheduler(std::shared_ptr<react::CallInvoker> jsInvoker);
|
||||
virtual ~VisionCameraScheduler();
|
||||
|
||||
void scheduleOnUI(std::function<void()> job) override;
|
||||
};
|
||||
|
||||
} // namespace vision
|
39
ios/Frame Processor/VisionCameraScheduler.mm
Normal file
39
ios/Frame Processor/VisionCameraScheduler.mm
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// VisionCameraScheduler.mm
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 23.07.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "VisionCameraScheduler.h"
|
||||
|
||||
#import <React-callinvoker/ReactCommon/CallInvoker.h>
|
||||
|
||||
// Forward declarations for the Swift classes
|
||||
__attribute__((objc_runtime_name("_TtC12VisionCamera12CameraQueues")))
|
||||
@interface CameraQueues : NSObject
|
||||
@property (nonatomic, class, readonly, strong) dispatch_queue_t _Nonnull frameProcessorQueue;
|
||||
@end
|
||||
|
||||
namespace vision {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
VisionCameraScheduler::VisionCameraScheduler(std::shared_ptr<react::CallInvoker> jsInvoker) {
|
||||
this->jsCallInvoker_ = jsInvoker;
|
||||
}
|
||||
|
||||
// does not schedule on UI thread but rather on Frame Processor Thread
|
||||
void VisionCameraScheduler::scheduleOnUI(std::function<void()> job) {
|
||||
dispatch_async(CameraQueues.frameProcessorQueue, ^{
|
||||
job();
|
||||
});
|
||||
}
|
||||
|
||||
VisionCameraScheduler::~VisionCameraScheduler(){
|
||||
}
|
||||
|
||||
|
||||
} // namespace vision
|
@@ -75,6 +75,8 @@
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
134814201AA4EA6300B7C361 /* libVisionCamera.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libVisionCamera.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B80416F026AB16E8000DEB6A /* VisionCameraScheduler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VisionCameraScheduler.mm; sourceTree = "<group>"; };
|
||||
B80416F126AB16F3000DEB6A /* VisionCameraScheduler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VisionCameraScheduler.h; sourceTree = "<group>"; };
|
||||
B80C0DFE260BDD97001699AB /* FrameProcessorPluginRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameProcessorPluginRegistry.h; sourceTree = "<group>"; };
|
||||
B80C0DFF260BDDF7001699AB /* FrameProcessorPluginRegistry.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameProcessorPluginRegistry.mm; sourceTree = "<group>"; };
|
||||
B80D67A825FA25380008FE8D /* FrameProcessorCallback.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameProcessorCallback.h; sourceTree = "<group>"; };
|
||||
@@ -261,6 +263,8 @@
|
||||
B80C0DFE260BDD97001699AB /* FrameProcessorPluginRegistry.h */,
|
||||
B80C0DFF260BDDF7001699AB /* FrameProcessorPluginRegistry.mm */,
|
||||
B88873E5263D46C7008B1D0E /* FrameProcessorPlugin.h */,
|
||||
B80416F026AB16E8000DEB6A /* VisionCameraScheduler.mm */,
|
||||
B80416F126AB16F3000DEB6A /* VisionCameraScheduler.h */,
|
||||
);
|
||||
path = "Frame Processor";
|
||||
sourceTree = "<group>";
|
||||
|
Reference in New Issue
Block a user