Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rewrite Android C++ part (VisionCameraProxy + JFrame) #1661

Merged
merged 11 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ add_library(
${PACKAGE_NAME}
SHARED
../cpp/JSITypedArray.cpp
src/main/cpp/VisionCamera.cpp
src/main/cpp/JSIJNIConversion.cpp
src/main/cpp/FrameHostObject.cpp
src/main/cpp/FrameProcessorRuntimeManager.cpp
src/main/cpp/CameraView.cpp
src/main/cpp/VisionCameraScheduler.cpp
src/main/cpp/FrameProcessorPluginHostObject.cpp
src/main/cpp/JSIJNIConversion.cpp
src/main/cpp/VisionCamera.cpp
src/main/cpp/VisionCameraProxy.cpp
src/main/cpp/java-bindings/JFrame.cpp
src/main/cpp/java-bindings/JFrameProcessor.cpp
src/main/cpp/java-bindings/JFrameProcessorPlugin.cpp
src/main/cpp/java-bindings/JImageProxy.cpp
src/main/cpp/java-bindings/JHashMap.cpp
src/main/cpp/java-bindings/JVisionCameraProxy.cpp
src/main/cpp/java-bindings/JVisionCameraScheduler.cpp
)

# Header Search Paths (includes)
Expand Down
58 changes: 0 additions & 58 deletions android/src/main/cpp/CameraView.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions android/src/main/cpp/CameraView.h

This file was deleted.

2 changes: 1 addition & 1 deletion android/src/main/cpp/FrameHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace vision {

using namespace facebook;

FrameHostObject::FrameHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(make_global(image)), _refCount(0) { }
FrameHostObject::FrameHostObject(jni::alias_ref<JFrame::javaobject> frame): frame(make_global(frame)), _refCount(0) { }

FrameHostObject::~FrameHostObject() {
// Hermes' Garbage Collector (Hades GC) calls destructors on a separate Thread
Expand Down
6 changes: 3 additions & 3 deletions android/src/main/cpp/FrameHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
#include <string>
#include <mutex>

#include "java-bindings/JImageProxy.h"
#include "java-bindings/JFrame.h"

namespace vision {

using namespace facebook;

class JSI_EXPORT FrameHostObject : public jsi::HostObject {
public:
explicit FrameHostObject(jni::alias_ref<JImageProxy::javaobject> image);
explicit FrameHostObject(jni::alias_ref<JFrame::javaobject> frame);
~FrameHostObject();

public:
jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) override;
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

public:
jni::global_ref<JImageProxy> frame;
jni::global_ref<JFrame> frame;

private:
static auto constexpr TAG = "VisionCamera";
Expand Down
52 changes: 52 additions & 0 deletions android/src/main/cpp/FrameProcessorPluginHostObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Created by Marc Rousavy on 21.07.23.
//

#include "FrameProcessorPluginHostObject.h"
#include <vector>
#include "FrameHostObject.h"
#include "JSIJNIConversion.h"

namespace vision {

using namespace facebook;

std::vector<jsi::PropNameID> FrameProcessorPluginHostObject::getPropertyNames(jsi::Runtime &runtime) {
std::vector<jsi::PropNameID> result;
result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("call")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Add #include for string [build/include_what_you_use] [4]

return result;
}

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 {
// Frame is first argument
auto frameHostObject = arguments[0].asObject(runtime).asHostObject<FrameHostObject>(runtime);
auto frame = frameHostObject->frame;

// Options are second argument (possibly undefined)
jobject options = nullptr;
if (count > 1) {
options = JSIJNIConversion::convertJSIValueToJNIObject(runtime, arguments[1]);
}

// Call actual plugin
auto result = _plugin->callback(frame, options);

// Convert result value to jsi::Value (possibly undefined)
return JSIJNIConversion::convertJNIObjectToJSIValue(runtime, result);
});
}

return jsi::Value::undefined();
}

} // namespace vision
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]

31 changes: 31 additions & 0 deletions android/src/main/cpp/FrameProcessorPluginHostObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by Marc Rousavy on 21.07.23.
//

#pragma once

#include <jsi/jsi.h>
#include "java-bindings/JFrameProcessorPlugin.h"
#include <memory>
#include <ReactCommon/CallInvoker.h>
#include <fbjni/fbjni.h>

namespace vision {

using namespace facebook;

class FrameProcessorPluginHostObject: public jsi::HostObject {
public:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
public: should be indented +1 space inside class FrameProcessorPluginHostObject [whitespace/indent] [3]

explicit FrameProcessorPluginHostObject(jni::alias_ref<JFrameProcessorPlugin::javaobject> plugin):
_plugin(make_global(plugin)) { }
~FrameProcessorPluginHostObject() { }

public:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
public: should be indented +1 space inside class FrameProcessorPluginHostObject [whitespace/indent] [3]

std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Add #include for vector<> [build/include_what_you_use] [4]

jsi::Value get(jsi::Runtime& runtime, const jsi::PropNameID& name) override;

private:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
private: should be indented +1 space inside class FrameProcessorPluginHostObject [whitespace/indent] [3]

jni::global_ref<JFrameProcessorPlugin::javaobject> _plugin;
};

} // namespace vision
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]

Loading
Loading