fix: Fix calling multiple Plugins in a single Frame Processor (#435)

* fix: Fix JNI <-> JSI conversion for Integers

* Create another plugin and call them both serially

* Use inline formatter for `__android_log_write`

* Update FrameProcessorRuntimeManager.cpp

* Log plugin class type

* Use `pluginGlobal->cthis()`

* Log class name

* fix dumb error

* C++: Dynamically get JNI `javaPart_` class & method

* clean up PR
This commit is contained in:
Marc Rousavy 2021-09-24 10:19:30 +02:00 committed by GitHub
parent ef40b1db23
commit 99fff446e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 12 deletions

View File

@ -38,8 +38,7 @@ void CameraView::frameProcessorCallback(const alias_ref<JImageProxy::javaobject>
frameProcessor_(frame); frameProcessor_(frame);
} catch (const std::exception& exception) { } catch (const std::exception& exception) {
// TODO: jsi::JSErrors cannot be caught on Hermes. They crash the entire app. // TODO: jsi::JSErrors cannot be caught on Hermes. They crash the entire app.
auto message = "Frame Processor threw an error! " + std::string(exception.what()); __android_log_print(ANDROID_LOG_ERROR, TAG, "Frame Processor threw an error! %s", exception.what());
__android_log_write(ANDROID_LOG_ERROR, TAG, message.c_str());
} }
} }

View File

@ -25,7 +25,8 @@ void FrameProcessorPlugin::registerNatives() {
} }
local_ref<jobject> FrameProcessorPlugin::callback(alias_ref<JImageProxy::javaobject> image, alias_ref<JArrayClass<jobject>> params) { local_ref<jobject> FrameProcessorPlugin::callback(alias_ref<JImageProxy::javaobject> image, alias_ref<JArrayClass<jobject>> params) {
static const auto func = javaPart_->getClass()->getMethod<TFrameProcessorPlugin>("callback"); auto func = javaPart_->getClass()->getMethod<TFrameProcessorPlugin>("callback");
auto result = func(javaPart_.get(), image, params); auto result = func(javaPart_.get(), image, params);
return make_local(result); return make_local(result);
} }

View File

@ -225,14 +225,12 @@ void FrameProcessorRuntimeManager::registerPlugin(alias_ref<FrameProcessorPlugin
// we need a strong reference on the plugin, make_global does that. // we need a strong reference on the plugin, make_global does that.
auto pluginGlobal = make_global(plugin); auto pluginGlobal = make_global(plugin);
auto pluginCxx = pluginGlobal->cthis();
// name is always prefixed with two underscores (__) // name is always prefixed with two underscores (__)
auto name = "__" + pluginCxx->getName(); auto name = "__" + pluginGlobal->cthis()->getName();
auto message = "Installing Frame Processor Plugin \"" + name + "\"..."; __android_log_print(ANDROID_LOG_INFO, TAG, "Installing Frame Processor Plugin \"%s\"...", name.c_str());
__android_log_write(ANDROID_LOG_INFO, TAG, message.c_str());
auto callback = [pluginCxx](jsi::Runtime& runtime, auto callback = [pluginGlobal](jsi::Runtime& runtime,
const jsi::Value& thisValue, const jsi::Value& thisValue,
const jsi::Value* arguments, const jsi::Value* arguments,
size_t count) -> jsi::Value { size_t count) -> jsi::Value {
@ -247,7 +245,7 @@ void FrameProcessorRuntimeManager::registerPlugin(alias_ref<FrameProcessorPlugin
} }
// call implemented virtual method // call implemented virtual method
auto result = pluginCxx->callback(frameHostObject->frame, params); auto result = pluginGlobal->cthis()->callback(frameHostObject->frame, params);
// convert result from JNI to JSI value // convert result from JNI to JSI value
return JSIJNIConversion::convertJNIObjectToJSIValue(runtime, result); return JSIJNIConversion::convertJNIObjectToJSIValue(runtime, result);