From 8de81c0a37b63eb96e15a2b060413b37d4e85b86 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 23:03:16 +0200 Subject: [PATCH 1/5] `Frame Processor` -> `FrameProcessors` --- .../FRAME_PROCESSORS_CREATE_PLUGIN_CPP.mdx | 2 +- package/VisionCamera.podspec | 18 +++++++++--------- package/example/ios/Podfile.lock | 16 ++++++++-------- .../Frame.h | 0 .../Frame.m | 0 .../FrameHostObject.h | 0 .../FrameHostObject.mm | 0 .../FrameProcessor.h | 0 .../FrameProcessor.mm | 0 .../FrameProcessorPlugin.h | 0 .../FrameProcessorPlugin.m | 0 .../FrameProcessorPluginHostObject.h | 0 .../FrameProcessorPluginHostObject.mm | 0 .../FrameProcessorPluginRegistry.h | 0 .../FrameProcessorPluginRegistry.m | 0 .../JSINSObjectConversion.h | 2 +- .../JSINSObjectConversion.mm | 0 .../SharedArray.h | 0 .../SharedArray.mm | 0 .../UIImageOrientation+descriptor.h | 0 .../VisionCameraInstaller.h | 0 .../VisionCameraInstaller.mm | 0 .../VisionCameraProxy.h | 0 .../VisionCameraProxy.mm | 0 .../VisionCameraProxyDelegate.h | 0 .../VisionCameraProxyHolder.h | 0 .../VisionCameraProxyHolder.mm | 0 27 files changed, 19 insertions(+), 19 deletions(-) rename package/ios/{Frame Processor => FrameProcessors}/Frame.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/Frame.m (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameHostObject.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameHostObject.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessor.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessor.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPlugin.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPlugin.m (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPluginHostObject.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPluginHostObject.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPluginRegistry.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/FrameProcessorPluginRegistry.m (100%) rename package/ios/{Frame Processor => FrameProcessors}/JSINSObjectConversion.h (98%) rename package/ios/{Frame Processor => FrameProcessors}/JSINSObjectConversion.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/SharedArray.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/SharedArray.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/UIImageOrientation+descriptor.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraInstaller.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraInstaller.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraProxy.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraProxy.mm (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraProxyDelegate.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraProxyHolder.h (100%) rename package/ios/{Frame Processor => FrameProcessors}/VisionCameraProxyHolder.mm (100%) diff --git a/docs/docs/guides/FRAME_PROCESSORS_CREATE_PLUGIN_CPP.mdx b/docs/docs/guides/FRAME_PROCESSORS_CREATE_PLUGIN_CPP.mdx index dad7a792af..ff561d2e8c 100644 --- a/docs/docs/guides/FRAME_PROCESSORS_CREATE_PLUGIN_CPP.mdx +++ b/docs/docs/guides/FRAME_PROCESSORS_CREATE_PLUGIN_CPP.mdx @@ -74,7 +74,7 @@ s.dependency "VisionCamera" Then include it in your C++ code: ```cpp -#include "Frame Processor/FrameHostObject.h" +#include "FrameProcessors/FrameHostObject.h" ``` diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index e892c0eeec..879041243a 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -81,19 +81,19 @@ Pod::Spec.new do |s| # VisionCamera Frame Processors C++ codebase (optional) fp.source_files = [ # C++ sources - "ios/Frame Processor/**/*.{h,m,mm}", + "ios/FrameProcessors/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}", ] fp.public_header_files = [ # Swift/Objective-C visible headers - "ios/Frame Processor/Frame.h", - "ios/Frame Processor/FrameProcessor.h", - "ios/Frame Processor/FrameProcessorPlugin.h", - "ios/Frame Processor/FrameProcessorPluginRegistry.h", - "ios/Frame Processor/SharedArray.h", - "ios/Frame Processor/VisionCameraProxyDelegate.h", - "ios/Frame Processor/VisionCameraProxyHolder.h", - "ios/Frame Processor/VisionCameraInstaller.h", + "ios/FrameProcessors/Frame.h", + "ios/FrameProcessors/FrameProcessor.h", + "ios/FrameProcessors/FrameProcessorPlugin.h", + "ios/FrameProcessors/FrameProcessorPluginRegistry.h", + "ios/FrameProcessors/SharedArray.h", + "ios/FrameProcessors/VisionCameraProxyDelegate.h", + "ios/FrameProcessors/VisionCameraProxyHolder.h", + "ios/FrameProcessors/VisionCameraInstaller.h", ] fp.pod_target_xcconfig = { diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 6133f33a64..89ea96d101 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -467,16 +467,16 @@ PODS: - RCT-Folly (= 2021.07.22.00) - React-Core - SocketRocket (0.6.1) - - VisionCamera (4.0.0-beta.16): - - VisionCamera/Core (= 4.0.0-beta.16) - - VisionCamera/FrameProcessors (= 4.0.0-beta.16) - - VisionCamera/React (= 4.0.0-beta.16) - - VisionCamera/Core (4.0.0-beta.16) - - VisionCamera/FrameProcessors (4.0.0-beta.16): + - VisionCamera (4.0.0-beta.17): + - VisionCamera/Core (= 4.0.0-beta.17) + - VisionCamera/FrameProcessors (= 4.0.0-beta.17) + - VisionCamera/React (= 4.0.0-beta.17) + - VisionCamera/Core (4.0.0-beta.17) + - VisionCamera/FrameProcessors (4.0.0-beta.17): - React - React-callinvoker - react-native-worklets-core - - VisionCamera/React (4.0.0-beta.16): + - VisionCamera/React (4.0.0-beta.17): - React-Core - VisionCamera/FrameProcessors - Yoga (1.14.0) @@ -708,7 +708,7 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: f3bb394c7c842ff1ced88ee49294b329eb6d952f + VisionCamera: ed323347b53e0ec2631f1018185d3881e94512fa Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 66976ac26c778d788a06e6c1bab624e6a1233cdd diff --git a/package/ios/Frame Processor/Frame.h b/package/ios/FrameProcessors/Frame.h similarity index 100% rename from package/ios/Frame Processor/Frame.h rename to package/ios/FrameProcessors/Frame.h diff --git a/package/ios/Frame Processor/Frame.m b/package/ios/FrameProcessors/Frame.m similarity index 100% rename from package/ios/Frame Processor/Frame.m rename to package/ios/FrameProcessors/Frame.m diff --git a/package/ios/Frame Processor/FrameHostObject.h b/package/ios/FrameProcessors/FrameHostObject.h similarity index 100% rename from package/ios/Frame Processor/FrameHostObject.h rename to package/ios/FrameProcessors/FrameHostObject.h diff --git a/package/ios/Frame Processor/FrameHostObject.mm b/package/ios/FrameProcessors/FrameHostObject.mm similarity index 100% rename from package/ios/Frame Processor/FrameHostObject.mm rename to package/ios/FrameProcessors/FrameHostObject.mm diff --git a/package/ios/Frame Processor/FrameProcessor.h b/package/ios/FrameProcessors/FrameProcessor.h similarity index 100% rename from package/ios/Frame Processor/FrameProcessor.h rename to package/ios/FrameProcessors/FrameProcessor.h diff --git a/package/ios/Frame Processor/FrameProcessor.mm b/package/ios/FrameProcessors/FrameProcessor.mm similarity index 100% rename from package/ios/Frame Processor/FrameProcessor.mm rename to package/ios/FrameProcessors/FrameProcessor.mm diff --git a/package/ios/Frame Processor/FrameProcessorPlugin.h b/package/ios/FrameProcessors/FrameProcessorPlugin.h similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPlugin.h rename to package/ios/FrameProcessors/FrameProcessorPlugin.h diff --git a/package/ios/Frame Processor/FrameProcessorPlugin.m b/package/ios/FrameProcessors/FrameProcessorPlugin.m similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPlugin.m rename to package/ios/FrameProcessors/FrameProcessorPlugin.m diff --git a/package/ios/Frame Processor/FrameProcessorPluginHostObject.h b/package/ios/FrameProcessors/FrameProcessorPluginHostObject.h similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPluginHostObject.h rename to package/ios/FrameProcessors/FrameProcessorPluginHostObject.h diff --git a/package/ios/Frame Processor/FrameProcessorPluginHostObject.mm b/package/ios/FrameProcessors/FrameProcessorPluginHostObject.mm similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPluginHostObject.mm rename to package/ios/FrameProcessors/FrameProcessorPluginHostObject.mm diff --git a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h b/package/ios/FrameProcessors/FrameProcessorPluginRegistry.h similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPluginRegistry.h rename to package/ios/FrameProcessors/FrameProcessorPluginRegistry.h diff --git a/package/ios/Frame Processor/FrameProcessorPluginRegistry.m b/package/ios/FrameProcessors/FrameProcessorPluginRegistry.m similarity index 100% rename from package/ios/Frame Processor/FrameProcessorPluginRegistry.m rename to package/ios/FrameProcessors/FrameProcessorPluginRegistry.m diff --git a/package/ios/Frame Processor/JSINSObjectConversion.h b/package/ios/FrameProcessors/JSINSObjectConversion.h similarity index 98% rename from package/ios/Frame Processor/JSINSObjectConversion.h rename to package/ios/FrameProcessors/JSINSObjectConversion.h index a5dc059bb8..531be27020 100644 --- a/package/ios/Frame Processor/JSINSObjectConversion.h +++ b/package/ios/FrameProcessors/JSINSObjectConversion.h @@ -8,7 +8,7 @@ #pragma once -#import "../Frame Processor/SharedArray.h" +#import "SharedArray.h" #import #import #import diff --git a/package/ios/Frame Processor/JSINSObjectConversion.mm b/package/ios/FrameProcessors/JSINSObjectConversion.mm similarity index 100% rename from package/ios/Frame Processor/JSINSObjectConversion.mm rename to package/ios/FrameProcessors/JSINSObjectConversion.mm diff --git a/package/ios/Frame Processor/SharedArray.h b/package/ios/FrameProcessors/SharedArray.h similarity index 100% rename from package/ios/Frame Processor/SharedArray.h rename to package/ios/FrameProcessors/SharedArray.h diff --git a/package/ios/Frame Processor/SharedArray.mm b/package/ios/FrameProcessors/SharedArray.mm similarity index 100% rename from package/ios/Frame Processor/SharedArray.mm rename to package/ios/FrameProcessors/SharedArray.mm diff --git a/package/ios/Frame Processor/UIImageOrientation+descriptor.h b/package/ios/FrameProcessors/UIImageOrientation+descriptor.h similarity index 100% rename from package/ios/Frame Processor/UIImageOrientation+descriptor.h rename to package/ios/FrameProcessors/UIImageOrientation+descriptor.h diff --git a/package/ios/Frame Processor/VisionCameraInstaller.h b/package/ios/FrameProcessors/VisionCameraInstaller.h similarity index 100% rename from package/ios/Frame Processor/VisionCameraInstaller.h rename to package/ios/FrameProcessors/VisionCameraInstaller.h diff --git a/package/ios/Frame Processor/VisionCameraInstaller.mm b/package/ios/FrameProcessors/VisionCameraInstaller.mm similarity index 100% rename from package/ios/Frame Processor/VisionCameraInstaller.mm rename to package/ios/FrameProcessors/VisionCameraInstaller.mm diff --git a/package/ios/Frame Processor/VisionCameraProxy.h b/package/ios/FrameProcessors/VisionCameraProxy.h similarity index 100% rename from package/ios/Frame Processor/VisionCameraProxy.h rename to package/ios/FrameProcessors/VisionCameraProxy.h diff --git a/package/ios/Frame Processor/VisionCameraProxy.mm b/package/ios/FrameProcessors/VisionCameraProxy.mm similarity index 100% rename from package/ios/Frame Processor/VisionCameraProxy.mm rename to package/ios/FrameProcessors/VisionCameraProxy.mm diff --git a/package/ios/Frame Processor/VisionCameraProxyDelegate.h b/package/ios/FrameProcessors/VisionCameraProxyDelegate.h similarity index 100% rename from package/ios/Frame Processor/VisionCameraProxyDelegate.h rename to package/ios/FrameProcessors/VisionCameraProxyDelegate.h diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.h b/package/ios/FrameProcessors/VisionCameraProxyHolder.h similarity index 100% rename from package/ios/Frame Processor/VisionCameraProxyHolder.h rename to package/ios/FrameProcessors/VisionCameraProxyHolder.h diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.mm b/package/ios/FrameProcessors/VisionCameraProxyHolder.mm similarity index 100% rename from package/ios/Frame Processor/VisionCameraProxyHolder.mm rename to package/ios/FrameProcessors/VisionCameraProxyHolder.mm From 40c02ef38d25bd98b6edc0805a014a9d81e54c97 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 23:06:29 +0200 Subject: [PATCH 2/5] fix: Remove almost empty `cpp/` folder --- package/VisionCamera.podspec | 9 ++-- package/android/CMakeLists.txt | 3 -- .../src/main}/cpp/MutableRawBuffer.h | 20 +++++---- .../cpp/frameprocessors/FrameHostObject.cpp | 10 +++-- package/cpp/.clang-format | 26 ------------ package/cpp/FinalAction.h | 34 --------------- package/cpp/MutableRawBuffer.cpp | 38 ----------------- package/example/ios/Podfile.lock | 2 +- .../ios/FrameProcessors/MutableRawBuffer.h | 42 +++++++++++++++++++ 9 files changed, 66 insertions(+), 118 deletions(-) rename package/{ => android/src/main}/cpp/MutableRawBuffer.h (60%) delete mode 100644 package/cpp/.clang-format delete mode 100644 package/cpp/FinalAction.h delete mode 100644 package/cpp/MutableRawBuffer.cpp create mode 100644 package/ios/FrameProcessors/MutableRawBuffer.h diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 879041243a..23ddf8658a 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -53,7 +53,9 @@ Pod::Spec.new do |s| s.subspec 'Core' do |core| # VisionCamera Core Swift codebase - core.source_files = "ios/Core/**/*.swift" + core.source_files = [ + "ios/Core/**/*.swift" + ] core.pod_target_xcconfig = { "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", @@ -80,9 +82,7 @@ Pod::Spec.new do |s| s.subspec 'FrameProcessors' do |fp| # VisionCamera Frame Processors C++ codebase (optional) fp.source_files = [ - # C++ sources - "ios/FrameProcessors/**/*.{h,m,mm}", - "cpp/**/*.{h,cpp}", + "ios/FrameProcessors/**/*.{h,m,mm}" ] fp.public_header_files = [ # Swift/Objective-C visible headers @@ -98,7 +98,6 @@ Pod::Spec.new do |s| fp.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/cpp/\"/** " } fp.dependency "React" diff --git a/package/android/CMakeLists.txt b/package/android/CMakeLists.txt index 62745757fe..1460dbd772 100644 --- a/package/android/CMakeLists.txt +++ b/package/android/CMakeLists.txt @@ -26,8 +26,6 @@ endif() add_library( ${PACKAGE_NAME} SHARED - # Shared C++ - ../cpp/MutableRawBuffer.cpp # Java JNI src/main/cpp/VisionCamera.cpp src/main/cpp/MutableJByteBuffer.cpp @@ -48,7 +46,6 @@ add_library( target_include_directories( ${PACKAGE_NAME} PRIVATE - "../cpp" "src/main/cpp" "src/main/cpp/frameprocessors" "src/main/cpp/frameprocessors/java-bindings" diff --git a/package/cpp/MutableRawBuffer.h b/package/android/src/main/cpp/MutableRawBuffer.h similarity index 60% rename from package/cpp/MutableRawBuffer.h rename to package/android/src/main/cpp/MutableRawBuffer.h index a6adbf6689..36521d48f6 100644 --- a/package/cpp/MutableRawBuffer.h +++ b/package/android/src/main/cpp/MutableRawBuffer.h @@ -8,7 +8,6 @@ #pragma once -#include #include #include @@ -19,18 +18,25 @@ using namespace facebook; class MutableRawBuffer : public jsi::MutableBuffer { public: - explicit MutableRawBuffer(size_t size); - explicit MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc); - ~MutableRawBuffer(); + explicit MutableRawBuffer(size_t size) { + _size = size; + _data = new uint8_t[size]; + } + ~MutableRawBuffer() { + delete[] _data; + } public: - uint8_t* data() override; - size_t size() const override; + uint8_t* data() override { + return _data; + } + size_t size() const override { + return _size; + } private: uint8_t* _data; size_t _size; - bool _freeOnDealloc; }; } // namespace vision diff --git a/package/android/src/main/cpp/frameprocessors/FrameHostObject.cpp b/package/android/src/main/cpp/frameprocessors/FrameHostObject.cpp index 2d44c90fb3..10e7ba7383 100644 --- a/package/android/src/main/cpp/frameprocessors/FrameHostObject.cpp +++ b/package/android/src/main/cpp/frameprocessors/FrameHostObject.cpp @@ -15,8 +15,6 @@ #include #include -#include "FinalAction.h" - namespace vision { using namespace facebook; @@ -145,7 +143,6 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr #if __ANDROID_API__ >= 26 AHardwareBuffer* hardwareBuffer = this->frame->getHardwareBuffer(); AHardwareBuffer_acquire(hardwareBuffer); - finally([&]() { AHardwareBuffer_release(hardwareBuffer); }); AHardwareBuffer_Desc bufferDescription; AHardwareBuffer_describe(hardwareBuffer, &bufferDescription); @@ -176,12 +173,17 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr if (result != 0) { throw jsi::JSError(runtime, "Failed to lock HardwareBuffer for reading!"); } - finally([&]() { AHardwareBuffer_unlock(hardwareBuffer, nullptr); }); // directly write to C++ JSI ArrayBuffer auto destinationBuffer = arrayBuffer.data(runtime); memcpy(destinationBuffer, buffer, sizeof(uint8_t) * size); + // unlock read lock + AHardwareBuffer_unlock(hardwareBuffer, nullptr); + + // release JNI reference + AHardwareBuffer_release(hardwareBuffer); + return arrayBuffer; #else throw jsi::JSError(runtime, "Frame.toArrayBuffer() is only available if minSdkVersion is set to 26 or higher!"); diff --git a/package/cpp/.clang-format b/package/cpp/.clang-format deleted file mode 100644 index b654784ae4..0000000000 --- a/package/cpp/.clang-format +++ /dev/null @@ -1,26 +0,0 @@ -# Config for clang-format version 16 - -# Standard -BasedOnStyle: llvm -Standard: c++14 - -# Indentation -IndentWidth: 2 -ColumnLimit: 140 - -# Includes -SortIncludes: CaseSensitive -SortUsingDeclarations: true - -# Pointer and reference alignment -PointerAlignment: Left -ReferenceAlignment: Left -ReflowComments: true - -# Line breaking options -BreakBeforeBraces: Attach -BreakConstructorInitializers: BeforeColon -AllowShortFunctionsOnASingleLine: Empty -IndentCaseLabels: true -NamespaceIndentation: Inner - diff --git a/package/cpp/FinalAction.h b/package/cpp/FinalAction.h deleted file mode 100644 index 083e671495..0000000000 --- a/package/cpp/FinalAction.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// MutableRawBuffer.h -// VisionCamera -// -// Created by Marc Rousavy on 17.01.24. -// Copyright © 2024 mrousavy. All rights reserved. -// - -#pragma once - -namespace vision { - -template struct FinalAction { - -public: - FinalAction(F f) : clean_{f} {} - ~FinalAction() { - if (enabled_) - clean_(); - } - void disable() { - enabled_ = false; - }; - -private: - F clean_; - bool enabled_ = true; -}; - -} // namespace vision - -template vision::FinalAction finally(F f) { - return vision::FinalAction(std::move(f)); -} \ No newline at end of file diff --git a/package/cpp/MutableRawBuffer.cpp b/package/cpp/MutableRawBuffer.cpp deleted file mode 100644 index fdc7f31e6c..0000000000 --- a/package/cpp/MutableRawBuffer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -// MutableRawBuffer.cpp -// VisionCamera -// -// Created by Marc Rousavy on 17.01.24. -// Copyright © 2024 mrousavy. All rights reserved. -// - -#include "MutableRawBuffer.h" -#include -#include - -namespace vision { - -MutableRawBuffer::MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc) - : _data(data), _size(size), _freeOnDealloc(freeOnDealloc) {} - -MutableRawBuffer::MutableRawBuffer(size_t size) { - _size = size; - _data = (uint8_t*)malloc(size * sizeof(uint8_t)); - _freeOnDealloc = true; -} - -MutableRawBuffer::~MutableRawBuffer() { - if (_freeOnDealloc) { - free(_data); - } -} - -size_t MutableRawBuffer::size() const { - return _size; -} - -uint8_t* MutableRawBuffer::data() { - return _data; -} - -} // namespace vision diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 89ea96d101..98bf82fbf9 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -708,7 +708,7 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: ed323347b53e0ec2631f1018185d3881e94512fa + VisionCamera: 63c688c266a44e2ef20b998e05021f582812b0c2 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 66976ac26c778d788a06e6c1bab624e6a1233cdd diff --git a/package/ios/FrameProcessors/MutableRawBuffer.h b/package/ios/FrameProcessors/MutableRawBuffer.h new file mode 100644 index 0000000000..36521d48f6 --- /dev/null +++ b/package/ios/FrameProcessors/MutableRawBuffer.h @@ -0,0 +1,42 @@ +// +// MutableRawBuffer.h +// VisionCamera +// +// Created by Marc Rousavy on 17.01.24. +// Copyright © 2024 mrousavy. All rights reserved. +// + +#pragma once + +#include +#include + +namespace vision { + +using namespace facebook; + +class MutableRawBuffer : public jsi::MutableBuffer { + +public: + explicit MutableRawBuffer(size_t size) { + _size = size; + _data = new uint8_t[size]; + } + ~MutableRawBuffer() { + delete[] _data; + } + +public: + uint8_t* data() override { + return _data; + } + size_t size() const override { + return _size; + } + +private: + uint8_t* _data; + size_t _size; +}; + +} // namespace vision From 82277623e1776bca38612569df585090476af8cf Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 23:11:37 +0200 Subject: [PATCH 3/5] fix: Add wrap ctor to `MutableRawBuffer` --- package/android/src/main/cpp/MutableRawBuffer.h | 12 +++++++++--- package/ios/FrameProcessors/MutableRawBuffer.h | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package/android/src/main/cpp/MutableRawBuffer.h b/package/android/src/main/cpp/MutableRawBuffer.h index 36521d48f6..fddd28dc89 100644 --- a/package/android/src/main/cpp/MutableRawBuffer.h +++ b/package/android/src/main/cpp/MutableRawBuffer.h @@ -18,12 +18,17 @@ using namespace facebook; class MutableRawBuffer : public jsi::MutableBuffer { public: - explicit MutableRawBuffer(size_t size) { + explicit MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc) { _size = size; - _data = new uint8_t[size]; + _data = data; + _freeOnDealloc = freeOnDealloc; } + explicit MutableRawBuffer(size_t size): MutableRawBuffer(new uint8_t[size], size, true) { } + ~MutableRawBuffer() { - delete[] _data; + if (_freeOnDealloc) { + delete[] _data; + } } public: @@ -37,6 +42,7 @@ class MutableRawBuffer : public jsi::MutableBuffer { private: uint8_t* _data; size_t _size; + bool _freeOnDealloc; }; } // namespace vision diff --git a/package/ios/FrameProcessors/MutableRawBuffer.h b/package/ios/FrameProcessors/MutableRawBuffer.h index 36521d48f6..fddd28dc89 100644 --- a/package/ios/FrameProcessors/MutableRawBuffer.h +++ b/package/ios/FrameProcessors/MutableRawBuffer.h @@ -18,12 +18,17 @@ using namespace facebook; class MutableRawBuffer : public jsi::MutableBuffer { public: - explicit MutableRawBuffer(size_t size) { + explicit MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc) { _size = size; - _data = new uint8_t[size]; + _data = data; + _freeOnDealloc = freeOnDealloc; } + explicit MutableRawBuffer(size_t size): MutableRawBuffer(new uint8_t[size], size, true) { } + ~MutableRawBuffer() { - delete[] _data; + if (_freeOnDealloc) { + delete[] _data; + } } public: @@ -37,6 +42,7 @@ class MutableRawBuffer : public jsi::MutableBuffer { private: uint8_t* _data; size_t _size; + bool _freeOnDealloc; }; } // namespace vision From 916a797a2c392da4b2b7c7ad22e7f5b825849f0d Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 23:35:26 +0200 Subject: [PATCH 4/5] fix: Add `.clang-format` file again --- .github/workflows/validate-cpp.yml | 2 +- package/.clang-format | 25 +++++++++++++++++++++++++ package/scripts/clang-format.sh | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 package/.clang-format diff --git a/.github/workflows/validate-cpp.yml b/.github/workflows/validate-cpp.yml index f032c18b49..907fda78dc 100644 --- a/.github/workflows/validate-cpp.yml +++ b/.github/workflows/validate-cpp.yml @@ -33,5 +33,5 @@ jobs: with: clang-format-version: '16' check-path: ${{ matrix.path }} - clang-format-style-path: package/cpp/.clang-format + clang-format-style-path: package/.clang-format diff --git a/package/.clang-format b/package/.clang-format new file mode 100644 index 0000000000..bd04303aa9 --- /dev/null +++ b/package/.clang-format @@ -0,0 +1,25 @@ +# Config for clang-format version 16 + +# Standard +BasedOnStyle: llvm +Standard: c++14 + +# Indentation +IndentWidth: 2 +ColumnLimit: 140 + +# Includes +SortIncludes: CaseSensitive +SortUsingDeclarations: true + +# Pointer and reference alignment +PointerAlignment: Left +ReferenceAlignment: Left +ReflowComments: true + +# Line breaking options +BreakBeforeBraces: Attach +BreakConstructorInitializers: BeforeColon +AllowShortFunctionsOnASingleLine: Empty +IndentCaseLabels: true +NamespaceIndentation: Inner diff --git a/package/scripts/clang-format.sh b/package/scripts/clang-format.sh index 1d6cea46c1..dc4fe9f81f 100755 --- a/package/scripts/clang-format.sh +++ b/package/scripts/clang-format.sh @@ -2,7 +2,7 @@ if which clang-format >/dev/null; then find cpp ios android/src/main/cpp -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do - clang-format -style=file:./cpp/.clang-format -i "$file" + clang-format -style=file:./.clang-format -i "$file" done else echo "error: clang-format not installed, install with 'brew install clang-format' (or manually from https://clang.llvm.org/docs/ClangFormat.html)" From d442340a29bdf4f00900960b00339a240d405e56 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 23:36:59 +0200 Subject: [PATCH 5/5] fix: Remove `cpp` folder references from everywhere --- .github/workflows/build-android.yml | 2 -- .github/workflows/build-ios.yml | 2 -- .github/workflows/validate-cpp.yml | 3 --- package/android/src/main/cpp/MutableRawBuffer.h | 4 ++-- package/ios/FrameProcessors/MutableRawBuffer.h | 4 ++-- package/package.json | 2 -- package/scripts/clang-format.sh | 2 +- 7 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index 36b7ef2854..2e2a89ca22 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -6,7 +6,6 @@ on: - main paths: - '.github/workflows/build-android.yml' - - 'package/cpp/**' - 'package/android/**' - 'package/example/android/**' - 'package/yarn.lock' @@ -14,7 +13,6 @@ on: pull_request: paths: - '.github/workflows/build-android.yml' - - 'package/cpp/**' - 'package/android/**' - 'package/example/android/**' - 'package/yarn.lock' diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index d805a5f6ce..d41695d491 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -6,14 +6,12 @@ on: - main paths: - '.github/workflows/build-ios.yml' - - 'package/cpp/**' - 'package/ios/**' - 'package/*.podspec' - 'package/example/ios/**' pull_request: paths: - '.github/workflows/build-ios.yml' - - 'package/cpp/**' - 'package/ios/**' - 'package/*.podspec' - 'package/example/ios/**' diff --git a/.github/workflows/validate-cpp.yml b/.github/workflows/validate-cpp.yml index 907fda78dc..b73832a024 100644 --- a/.github/workflows/validate-cpp.yml +++ b/.github/workflows/validate-cpp.yml @@ -6,13 +6,11 @@ on: - main paths: - '.github/workflows/validate-cpp.yml' - - 'package/cpp/**' - 'package/android/src/main/cpp/**' - 'package/ios/**' pull_request: paths: - '.github/workflows/validate-cpp.yml' - - 'package/cpp/**' - 'package/android/src/main/cpp/**' - 'package/ios/**' @@ -23,7 +21,6 @@ jobs: strategy: matrix: path: - - 'package/cpp' - 'package/android/src/main/cpp' - 'package/ios' steps: diff --git a/package/android/src/main/cpp/MutableRawBuffer.h b/package/android/src/main/cpp/MutableRawBuffer.h index fddd28dc89..43121c2b65 100644 --- a/package/android/src/main/cpp/MutableRawBuffer.h +++ b/package/android/src/main/cpp/MutableRawBuffer.h @@ -23,8 +23,8 @@ class MutableRawBuffer : public jsi::MutableBuffer { _data = data; _freeOnDealloc = freeOnDealloc; } - explicit MutableRawBuffer(size_t size): MutableRawBuffer(new uint8_t[size], size, true) { } - + explicit MutableRawBuffer(size_t size) : MutableRawBuffer(new uint8_t[size], size, true) {} + ~MutableRawBuffer() { if (_freeOnDealloc) { delete[] _data; diff --git a/package/ios/FrameProcessors/MutableRawBuffer.h b/package/ios/FrameProcessors/MutableRawBuffer.h index fddd28dc89..43121c2b65 100644 --- a/package/ios/FrameProcessors/MutableRawBuffer.h +++ b/package/ios/FrameProcessors/MutableRawBuffer.h @@ -23,8 +23,8 @@ class MutableRawBuffer : public jsi::MutableBuffer { _data = data; _freeOnDealloc = freeOnDealloc; } - explicit MutableRawBuffer(size_t size): MutableRawBuffer(new uint8_t[size], size, true) { } - + explicit MutableRawBuffer(size_t size) : MutableRawBuffer(new uint8_t[size], size, true) {} + ~MutableRawBuffer() { if (_freeOnDealloc) { delete[] _data; diff --git a/package/package.json b/package/package.json index 64ba35c975..f264215c58 100644 --- a/package/package.json +++ b/package/package.json @@ -12,8 +12,6 @@ "lib/commonjs", "lib/module", "lib/typescript", - "cpp/**/*.h", - "cpp/**/*.cpp", "android/build.gradle", "android/gradle.properties", "android/CMakeLists.txt", diff --git a/package/scripts/clang-format.sh b/package/scripts/clang-format.sh index dc4fe9f81f..a63e171e58 100755 --- a/package/scripts/clang-format.sh +++ b/package/scripts/clang-format.sh @@ -1,7 +1,7 @@ #!/bin/bash if which clang-format >/dev/null; then - find cpp ios android/src/main/cpp -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do + find ios android/src/main/cpp -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do clang-format -style=file:./.clang-format -i "$file" done else