feat: Print Frame Processor errors to Metro console
This commit is contained in:
parent
0bbb03df90
commit
4bacee796a
@ -82,6 +82,26 @@ CameraView* FrameProcessorRuntimeManager::findCameraViewById(int viewId) {
|
|||||||
return result->cthis();
|
return result->cthis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrameProcessorRuntimeManager::logErrorToJS(std::string message) {
|
||||||
|
if (!this->jsCallInvoker_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->jsCallInvoker_->invokeAsync([this, message]() {
|
||||||
|
if (this->runtime_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& runtime = *this->runtime_;
|
||||||
|
auto consoleError = runtime
|
||||||
|
.global()
|
||||||
|
.getPropertyAsObject(runtime, "console")
|
||||||
|
.getPropertyAsFunction(runtime, "error");
|
||||||
|
consoleError.call(runtime, jsi::String::createFromUtf8(runtime, message));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// actual JSI installer
|
// actual JSI installer
|
||||||
void FrameProcessorRuntimeManager::installJSIBindings() {
|
void FrameProcessorRuntimeManager::installJSIBindings() {
|
||||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Installing JSI bindings...");
|
__android_log_write(ANDROID_LOG_INFO, TAG, "Installing JSI bindings...");
|
||||||
@ -132,10 +152,16 @@ void FrameProcessorRuntimeManager::installJSIBindings() {
|
|||||||
auto function = std::make_shared<jsi::Function>(worklet->getValue(rt).asObject(rt).asFunction(rt));
|
auto function = std::make_shared<jsi::Function>(worklet->getValue(rt).asObject(rt).asFunction(rt));
|
||||||
|
|
||||||
// assign lambda to frame processor
|
// assign lambda to frame processor
|
||||||
cameraView->setFrameProcessor([&rt, function](jni::local_ref<JImageProxy::javaobject> frame) {
|
cameraView->setFrameProcessor([this, &rt, function](jni::local_ref<JImageProxy::javaobject> frame) {
|
||||||
// create HostObject which holds the Frame (JImageProxy)
|
try {
|
||||||
auto hostObject = std::make_shared<JImageProxyHostObject>(frame);
|
// create HostObject which holds the Frame (JImageProxy)
|
||||||
function->call(rt, jsi::Object::createFromHostObject(rt, hostObject));
|
auto hostObject = std::make_shared<JImageProxyHostObject>(frame);
|
||||||
|
function->call(rt, jsi::Object::createFromHostObject(rt, hostObject));
|
||||||
|
} catch (jsi::JSError& jsError) {
|
||||||
|
auto message = "Frame Processor threw an error: " + jsError.getMessage();
|
||||||
|
__android_log_write(ANDROID_LOG_ERROR, TAG, message.c_str());
|
||||||
|
this->logErrorToJS(message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Frame Processor set!");
|
__android_log_write(ANDROID_LOG_INFO, TAG, "Frame Processor set!");
|
||||||
|
@ -53,6 +53,7 @@ class FrameProcessorRuntimeManager : public jni::HybridClass<FrameProcessorRunti
|
|||||||
void initializeRuntime();
|
void initializeRuntime();
|
||||||
void installJSIBindings();
|
void installJSIBindings();
|
||||||
void registerPlugin(alias_ref<FrameProcessorPlugin::javaobject> plugin);
|
void registerPlugin(alias_ref<FrameProcessorPlugin::javaobject> plugin);
|
||||||
|
void logErrorToJS(std::string message);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
|
@ -9,19 +9,35 @@
|
|||||||
#import "FrameProcessorUtils.h"
|
#import "FrameProcessorUtils.h"
|
||||||
#import <chrono>
|
#import <chrono>
|
||||||
#import <memory>
|
#import <memory>
|
||||||
|
|
||||||
#import "FrameHostObject.h"
|
#import "FrameHostObject.h"
|
||||||
#import "Frame.h"
|
#import "Frame.h"
|
||||||
|
|
||||||
|
#import <React/RCTBridge.h>
|
||||||
|
#import <React/RCTBridge+Private.h>
|
||||||
|
#import "JSConsoleHelper.h"
|
||||||
|
#import <ReactCommon/RCTTurboModule.h>
|
||||||
|
|
||||||
FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime &runtime, const jsi::Function &value) {
|
FrameProcessorCallback convertJSIFunctionToFrameProcessorCallback(jsi::Runtime &runtime, const jsi::Function &value) {
|
||||||
__block auto cb = value.getFunction(runtime);
|
__block auto cb = value.getFunction(runtime);
|
||||||
|
|
||||||
return ^(Frame* frame) {
|
return ^(Frame* frame) {
|
||||||
|
|
||||||
auto frameHostObject = std::make_shared<FrameHostObject>(frame);
|
auto frameHostObject = std::make_shared<FrameHostObject>(frame);
|
||||||
try {
|
try {
|
||||||
cb.call(runtime, jsi::Object::createFromHostObject(runtime, frameHostObject));
|
cb.call(runtime, jsi::Object::createFromHostObject(runtime, frameHostObject));
|
||||||
} catch (jsi::JSError& jsError) {
|
} catch (jsi::JSError& jsError) {
|
||||||
NSLog(@"Frame Processor threw an error: %s", jsError.getMessage().c_str());
|
auto message = jsError.getMessage();
|
||||||
|
|
||||||
|
RCTBridge* bridge = [RCTBridge currentBridge];
|
||||||
|
if (bridge != nil) {
|
||||||
|
bridge.jsCallInvoker->invokeAsync([bridge, message]() {
|
||||||
|
auto logFn = [JSConsoleHelper getLogFunctionForBridge:bridge];
|
||||||
|
logFn(RCTLogLevelError, [NSString stringWithFormat:@"Frame Processor threw an error: %s", message.c_str()]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
NSLog(@"Frame Processor threw an error: %s", message.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually free the buffer because:
|
// Manually free the buffer because:
|
||||||
|
Loading…
Reference in New Issue
Block a user