2021-06-27 04:37:54 -06:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 11.06.21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fbjni/fbjni.h>
|
|
|
|
#include <jsi/jsi.h>
|
|
|
|
#include <ReactCommon/CallInvokerHolder.h>
|
|
|
|
#include <memory>
|
2021-06-29 02:38:13 -06:00
|
|
|
#include <string>
|
2021-06-27 04:37:54 -06:00
|
|
|
|
|
|
|
#include "RuntimeManager.h"
|
|
|
|
#include "reanimated-headers/AndroidScheduler.h"
|
|
|
|
|
|
|
|
#include "CameraView.h"
|
2021-07-30 02:27:45 -06:00
|
|
|
#include "VisionCameraScheduler.h"
|
2021-09-29 04:30:50 -06:00
|
|
|
#include "java-bindings/JFrameProcessorPlugin.h"
|
2021-06-27 04:37:54 -06:00
|
|
|
|
|
|
|
namespace vision {
|
|
|
|
|
|
|
|
using namespace facebook;
|
|
|
|
|
|
|
|
class FrameProcessorRuntimeManager : public jni::HybridClass<FrameProcessorRuntimeManager> {
|
|
|
|
public:
|
|
|
|
static auto constexpr kJavaDescriptor = "Lcom/mrousavy/camera/frameprocessor/FrameProcessorRuntimeManager;";
|
|
|
|
static auto constexpr TAG = "VisionCamera";
|
|
|
|
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis,
|
|
|
|
jlong jsContext,
|
|
|
|
jni::alias_ref<facebook::react::CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
2021-07-30 02:27:45 -06:00
|
|
|
jni::alias_ref<vision::VisionCameraScheduler::javaobject> androidScheduler);
|
2021-06-27 04:37:54 -06:00
|
|
|
static void registerNatives();
|
|
|
|
|
|
|
|
explicit FrameProcessorRuntimeManager(jni::alias_ref<FrameProcessorRuntimeManager::jhybridobject> jThis,
|
|
|
|
jsi::Runtime* runtime,
|
|
|
|
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
2021-07-30 02:27:45 -06:00
|
|
|
std::shared_ptr<vision::VisionCameraScheduler> scheduler) :
|
2021-06-27 04:37:54 -06:00
|
|
|
javaPart_(jni::make_global(jThis)),
|
|
|
|
runtime_(runtime),
|
|
|
|
jsCallInvoker_(jsCallInvoker),
|
|
|
|
scheduler_(scheduler)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend HybridBase;
|
|
|
|
jni::global_ref<FrameProcessorRuntimeManager::javaobject> javaPart_;
|
|
|
|
jsi::Runtime* runtime_;
|
|
|
|
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker_;
|
|
|
|
std::shared_ptr<reanimated::RuntimeManager> _runtimeManager;
|
2021-07-30 02:27:45 -06:00
|
|
|
std::shared_ptr<vision::VisionCameraScheduler> scheduler_;
|
2021-06-27 04:37:54 -06:00
|
|
|
|
2021-09-29 04:30:50 -06:00
|
|
|
jni::global_ref<CameraView::javaobject> findCameraViewById(int viewId);
|
2021-06-27 04:37:54 -06:00
|
|
|
void initializeRuntime();
|
|
|
|
void installJSIBindings();
|
2021-09-29 04:30:50 -06:00
|
|
|
void registerPlugin(alias_ref<JFrameProcessorPlugin::javaobject> plugin);
|
2021-06-28 12:45:08 -06:00
|
|
|
void logErrorToJS(const std::string& message);
|
2021-09-29 04:30:50 -06:00
|
|
|
|
|
|
|
void setFrameProcessor(jsi::Runtime& runtime, // NOLINT(runtime/references)
|
|
|
|
int viewTag,
|
|
|
|
const jsi::Value& frameProcessor);
|
|
|
|
void unsetFrameProcessor(int viewTag);
|
2021-06-27 04:37:54 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace vision
|