From 1e35a8b51765ff4a994eacadb8f7627fc2329401 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 10:21:47 +0200 Subject: [PATCH 01/22] feat: Separate VisionCamera into two subspecs --- package/VisionCamera.podspec | 67 ++++++++++++++++---------------- package/example/ios/Podfile.lock | 19 +++++++-- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 1cf89644f2..51c0b2f6be 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -38,47 +38,46 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) VISION_CAMERA_ENABLE_FRAME_PROCESSORS=#{hasWorklets}", "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{hasWorklets ? "VISION_CAMERA_ENABLE_FRAME_PROCESSORS" : ""} #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** " } s.requires_arc = true - # All source files that should be publicly visible - # Note how this does not include headers, since those can nameclash. - s.source_files = [ - # Core - "ios/*.{m,mm,swift}", - "ios/Core/*.{m,mm,swift}", - "ios/Extensions/*.{m,mm,swift}", - "ios/Parsers/*.{m,mm,swift}", - "ios/React Utils/*.{m,mm,swift}", - "ios/Types/*.{m,mm,swift}", - "ios/CameraBridge.h", - - # Frame Processors - hasWorklets ? "ios/Frame Processor/*.{m,mm,swift}" : "", - hasWorklets ? "ios/Frame Processor/Frame.h" : "", - hasWorklets ? "ios/Frame Processor/FrameProcessor.h" : "", - hasWorklets ? "ios/Frame Processor/FrameProcessorPlugin.h" : "", - hasWorklets ? "ios/Frame Processor/FrameProcessorPluginRegistry.h" : "", - hasWorklets ? "ios/Frame Processor/SharedArray.h" : "", - hasWorklets ? "ios/Frame Processor/VisionCameraProxy.h" : "", - hasWorklets ? "cpp/**/*.{cpp}" : "", - ] - # Any private headers that are not globally unique should be mentioned here. - # Otherwise there will be a nameclash, since CocoaPods flattens out any header directories - # See https://github.com/firebase/firebase-ios-sdk/issues/4035 for more details. - s.preserve_paths = [ - "cpp/**/*.h", - "ios/**/*.h" - ] - s.dependency "React" s.dependency "React-Core" s.dependency "React-callinvoker" - if hasWorklets - s.dependency "react-native-worklets-core" + s.subspec 'Core' do |core| + # VisionCamera Core Swift codebase + core.source_files = [ + "ios/*.{m,mm,swift}", + "ios/Core/*.{m,mm,swift}", + "ios/Extensions/*.{m,mm,swift}", + "ios/Parsers/*.{m,mm,swift}", + "ios/React Utils/*.{m,mm,swift}", + "ios/Types/*.{m,mm,swift}", + "ios/CameraBridge.h", + ] + s.preserve_paths = "ios/**/*.h" + end + + s.subspec 'FrameProcessors' do |fp| + # VisionCamera Frame Processors C++ codebase (optional) + fp.dependency "VisionCamera/Core" + fp.dependency "react-native-worklets-core" + + fp.source_files = [ + "ios/Frame Processor/*.{h,m,mm}", + "cpp/**/*.{h,cpp}" + ] + + fp.preserve_paths = [ + "cpp/**/*.h", + "ios/Frame Processor/*.h" + ] + + fp.pod_target_xcconfig = { + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", + "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** " + } end end diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index ffe725686e..c1d3de5aea 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -467,11 +467,22 @@ PODS: - RCT-Folly (= 2021.07.22.00) - React-Core - SocketRocket (0.6.1) - - VisionCamera (4.0.0-beta.15): + - VisionCamera (4.0.0-beta.16): + - React + - React-callinvoker + - React-Core + - VisionCamera/Core (= 4.0.0-beta.16) + - VisionCamera/FrameProcessors (= 4.0.0-beta.16) + - VisionCamera/Core (4.0.0-beta.16): + - React + - React-callinvoker + - React-Core + - VisionCamera/FrameProcessors (4.0.0-beta.16): - React - React-callinvoker - React-Core - react-native-worklets-core + - VisionCamera/Core - Yoga (1.14.0) DEPENDENCIES: @@ -701,9 +712,9 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: e31119ce6f25cf982100e62db2846bee6653f52b + VisionCamera: 59ebb9b8531a3f35028a247fa994cf23286f4b26 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 -PODFILE CHECKSUM: 299b350392623e1b01615935e236438d90fd2cff +PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e -COCOAPODS: 1.11.3 +COCOAPODS: 1.14.3 From 8cc4c7df28841076d9871e0581b515369899d763 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 10:24:17 +0200 Subject: [PATCH 02/22] Swift --- package/VisionCamera.podspec | 9 ++++++--- package/example/ios/Podfile.lock | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 51c0b2f6be..69305668db 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -37,7 +37,7 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) VISION_CAMERA_ENABLE_FRAME_PROCESSORS=#{hasWorklets}", - "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{hasWorklets ? "VISION_CAMERA_ENABLE_FRAME_PROCESSORS" : ""} #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", + "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{hasWorklets ? "VISION_CAMERA_ENABLE_FRAME_PROCESSORS" : ""}", } s.requires_arc = true @@ -57,7 +57,11 @@ Pod::Spec.new do |s| "ios/Types/*.{m,mm,swift}", "ios/CameraBridge.h", ] - s.preserve_paths = "ios/**/*.h" + core.preserve_paths = "ios/**/*.h" + + core.pod_target_xcconfig = { + "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", + } end s.subspec 'FrameProcessors' do |fp| @@ -69,7 +73,6 @@ Pod::Spec.new do |s| "ios/Frame Processor/*.{h,m,mm}", "cpp/**/*.{h,cpp}" ] - fp.preserve_paths = [ "cpp/**/*.h", "ios/Frame Processor/*.h" diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index c1d3de5aea..261145f6e1 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -712,7 +712,7 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: 59ebb9b8531a3f35028a247fa994cf23286f4b26 + VisionCamera: 6fb338d0b715181e675f91f0dfc337863003b15e Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e From 305b9bc32c5ea6309c73787dacadaa38194e149c Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 10:29:41 +0200 Subject: [PATCH 03/22] update podspec --- package/VisionCamera.podspec | 4 ++-- package/example/ios/Podfile.lock | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 69305668db..a47d4c4218 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -42,9 +42,7 @@ Pod::Spec.new do |s| s.requires_arc = true - s.dependency "React" s.dependency "React-Core" - s.dependency "React-callinvoker" s.subspec 'Core' do |core| # VisionCamera Core Swift codebase @@ -66,6 +64,8 @@ Pod::Spec.new do |s| s.subspec 'FrameProcessors' do |fp| # VisionCamera Frame Processors C++ codebase (optional) + fp.dependency "React" + fp.dependency "React-callinvoker" fp.dependency "VisionCamera/Core" fp.dependency "react-native-worklets-core" diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 261145f6e1..80bfa3709a 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -468,14 +468,10 @@ PODS: - React-Core - SocketRocket (0.6.1) - VisionCamera (4.0.0-beta.16): - - React - - React-callinvoker - React-Core - VisionCamera/Core (= 4.0.0-beta.16) - VisionCamera/FrameProcessors (= 4.0.0-beta.16) - VisionCamera/Core (4.0.0-beta.16): - - React - - React-callinvoker - React-Core - VisionCamera/FrameProcessors (4.0.0-beta.16): - React @@ -712,7 +708,7 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: 6fb338d0b715181e675f91f0dfc337863003b15e + VisionCamera: e5369740bf7fedb9dde7a071f91747a418fe1d25 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e From f55f7c28da3c340bc4c50e7e17b2c5d46d33899d Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:00:31 +0200 Subject: [PATCH 04/22] fix: Refactor --- ...iewManager+VisionCameraProxyDelegate.swift | 36 ++++++++ package/VisionCamera.podspec | 7 +- package/example/ios/Podfile.lock | 4 +- package/ios/CameraBridge.h | 4 +- package/ios/CameraViewManager.swift | 2 +- .../Frame Processor/VisionCameraInstaller.h | 23 +++++ .../Frame Processor/VisionCameraInstaller.mm | 35 ++++++++ .../ios/Frame Processor/VisionCameraProxy.h | 33 ++----- .../ios/Frame Processor/VisionCameraProxy.mm | 86 +++++-------------- .../VisionCameraProxyDelegate.h | 29 +++++++ .../Frame Processor/VisionCameraProxyHolder.h | 32 +++++++ .../VisionCameraProxyHolder.mm | 27 ++++++ 12 files changed, 224 insertions(+), 94 deletions(-) create mode 100644 package/CameraViewManager+VisionCameraProxyDelegate.swift create mode 100644 package/ios/Frame Processor/VisionCameraInstaller.h create mode 100644 package/ios/Frame Processor/VisionCameraInstaller.mm create mode 100644 package/ios/Frame Processor/VisionCameraProxyDelegate.h create mode 100644 package/ios/Frame Processor/VisionCameraProxyHolder.h create mode 100644 package/ios/Frame Processor/VisionCameraProxyHolder.mm diff --git a/package/CameraViewManager+VisionCameraProxyDelegate.swift b/package/CameraViewManager+VisionCameraProxyDelegate.swift new file mode 100644 index 0000000000..c8eaa0c14f --- /dev/null +++ b/package/CameraViewManager+VisionCameraProxyDelegate.swift @@ -0,0 +1,36 @@ +// +// CameraViewManager+VisionCameraProxyDelegate.swift +// VisionCamera +// +// Created by Marc Rousavy on 20.04.24. +// + +import Foundation + +#if VISION_CAMERA_ENABLE_FRAME_PROCESSORS + +extension CameraViewManager: VisionCameraProxyDelegate { + func getDispatchQueue() -> dispatch_queue_t { + return CameraQueues.videoQueue + } + + func getBridge() -> RCTBridge { + return bridge + } + + func setFrameProcessor(_ frameProcessor: FrameProcessor, forView viewTag: NSNumber) { + DispatchQueue.main.async { + let view = self.getCameraView(withTag: viewTag) + view.frameProcessor = frameProcessor + } + } + + func removeFrameProcessor(forView viewTag: NSNumber) { + DispatchQueue.main.async { + let view = self.getCameraView(withTag: viewTag) + view.frameProcessor = nil + } + } +} + +#endif diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index a47d4c4218..e6b00b2ae2 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -60,13 +60,16 @@ Pod::Spec.new do |s| core.pod_target_xcconfig = { "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", } + + if hasWorklets + core.dependency "VisionCamera/FrameProcessors" + end end s.subspec 'FrameProcessors' do |fp| # VisionCamera Frame Processors C++ codebase (optional) fp.dependency "React" fp.dependency "React-callinvoker" - fp.dependency "VisionCamera/Core" fp.dependency "react-native-worklets-core" fp.source_files = [ @@ -80,7 +83,7 @@ Pod::Spec.new do |s| fp.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp/\"/** " + "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/cpp/\"/** " } end end diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 80bfa3709a..07657d4f12 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -473,12 +473,12 @@ PODS: - VisionCamera/FrameProcessors (= 4.0.0-beta.16) - VisionCamera/Core (4.0.0-beta.16): - React-Core + - VisionCamera/FrameProcessors - VisionCamera/FrameProcessors (4.0.0-beta.16): - React - React-callinvoker - React-Core - react-native-worklets-core - - VisionCamera/Core - Yoga (1.14.0) DEPENDENCIES: @@ -708,7 +708,7 @@ SPEC CHECKSUMS: RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8 RNVectorIcons: 23b6e11af4aaf104d169b1b0afa7e5cf96c676ce SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: e5369740bf7fedb9dde7a071f91747a418fe1d25 + VisionCamera: fb3c4c3cf0cd3f8911ebb53a488d091e29e30568 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e diff --git a/package/ios/CameraBridge.h b/package/ios/CameraBridge.h index 17a10b7623..c369a51a87 100644 --- a/package/ios/CameraBridge.h +++ b/package/ios/CameraBridge.h @@ -20,5 +20,7 @@ #import "Frame.h" #import "FrameProcessor.h" #import "SharedArray.h" -#import "VisionCameraProxy.h" +#import "VisionCameraProxyDelegate.h" +#import "VisionCameraProxyHolder.h" +#import "VisionCameraProxyInstaller.h" #endif diff --git a/package/ios/CameraViewManager.swift b/package/ios/CameraViewManager.swift index 6a3704ff88..c1b890a519 100644 --- a/package/ios/CameraViewManager.swift +++ b/package/ios/CameraViewManager.swift @@ -148,7 +148,7 @@ final class CameraViewManager: RCTViewManager { // MARK: Private - private func getCameraView(withTag tag: NSNumber) -> CameraView { + internal func getCameraView(withTag tag: NSNumber) -> CameraView { // swiftlint:disable force_cast return bridge.uiManager.view(forReactTag: tag) as! CameraView // swiftlint:enable force_cast diff --git a/package/ios/Frame Processor/VisionCameraInstaller.h b/package/ios/Frame Processor/VisionCameraInstaller.h new file mode 100644 index 0000000000..b6c02cd79e --- /dev/null +++ b/package/ios/Frame Processor/VisionCameraInstaller.h @@ -0,0 +1,23 @@ +// +// VisionCameraInstaller.h +// Pods +// +// Created by Marc Rousavy on 20.04.24. +// + +#pragma once + +#import "VisionCameraProxyDelegate.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + A static class to install/inject the VisionCameraProxy into the global JS runtime. + */ +@interface VisionCameraInstaller : NSObject + ++ (BOOL)installWithDelegate:(id)delegate; + +@end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/VisionCameraInstaller.mm b/package/ios/Frame Processor/VisionCameraInstaller.mm new file mode 100644 index 0000000000..8fb01774bc --- /dev/null +++ b/package/ios/Frame Processor/VisionCameraInstaller.mm @@ -0,0 +1,35 @@ +// +// VisionCameraInstaller.mm +// DoubleConversion +// +// Created by Marc Rousavy on 20.04.24. +// + +#import +#import "VisionCameraInstaller.h" +#import "VisionCameraProxy.h" + +#import +#import +#import + +@implementation VisionCameraInstaller + ++ (BOOL)installWithDelegate:(id)delegate { + // TODO: Migrate away from RCTBridge to support new arch. + RCTBridge* bridge = delegate.getBridge; + RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge; + if (!cxxBridge.runtime) { + return NO; + } + + jsi::Runtime& runtime = *(jsi::Runtime*)cxxBridge.runtime; + + // global.VisionCameraProxy + auto visionCameraProxy = std::make_shared(runtime, bridge.jsCallInvoker, delegate); + runtime.global().setProperty(runtime, "VisionCameraProxy", jsi::Object::createFromHostObject(runtime, visionCameraProxy)); + + return YES; +} + +@end diff --git a/package/ios/Frame Processor/VisionCameraProxy.h b/package/ios/Frame Processor/VisionCameraProxy.h index 08a5c1139a..e63e049cbe 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.h +++ b/package/ios/Frame Processor/VisionCameraProxy.h @@ -8,19 +8,24 @@ #pragma once +#ifndef __cplusplus +#error VisionCameraProxy.h has to be compiled with C++! +#endif + #import -#import -#ifdef __cplusplus #import "WKTJsiWorkletContext.h" #import #import +#import "VisionCameraProxyDelegate.h" using namespace facebook; class VisionCameraProxy : public jsi::HostObject { public: - explicit VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr callInvoker); + explicit VisionCameraProxy(jsi::Runtime& runtime, + std::shared_ptr callInvoker, + id delegate); ~VisionCameraProxy(); public: @@ -39,25 +44,5 @@ class VisionCameraProxy : public jsi::HostObject { private: std::shared_ptr _workletContext; std::shared_ptr _callInvoker; + id _delegate; }; -#endif - -NS_ASSUME_NONNULL_BEGIN - -@interface VisionCameraProxyHolder : NSObject - -- (_Nonnull instancetype)initWithProxy:(void*)proxy; - -#ifdef __cplusplus -- (VisionCameraProxy*)proxy; -#endif - -@end - -@interface VisionCameraInstaller : NSObject - -+ (BOOL)installToBridge:(RCTBridge*)bridge; - -@end - -NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/VisionCameraProxy.mm b/package/ios/Frame Processor/VisionCameraProxy.mm index 310c2ca08b..bed3081679 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.mm +++ b/package/ios/Frame Processor/VisionCameraProxy.mm @@ -10,6 +10,7 @@ #import #import +#import "VisionCameraProxyHolder.h" #import "FrameHostObject.h" #import "FrameProcessor.h" #import "FrameProcessorPluginHostObject.h" @@ -17,36 +18,22 @@ #import "JSINSObjectConversion.h" #import "WKTJsiWorklet.h" -#import -#import -#import -#import -#import - -// Swift forward-declarations -__attribute__((objc_runtime_name("_TtC12VisionCamera12CameraQueues"))) -@interface CameraQueues : NSObject -@property(nonatomic, class, readonly, strong) dispatch_queue_t _Nonnull videoQueue; -@end - -__attribute__((objc_runtime_name("_TtC12VisionCamera10CameraView"))) -@interface CameraView : UIView -@property(nonatomic, copy) FrameProcessor* _Nullable frameProcessor; -@end - using namespace facebook; -VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr callInvoker) { +VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime, + std::shared_ptr callInvoker, + id delegate) { _callInvoker = callInvoker; + _delegate = delegate; NSLog(@"VisionCameraProxy: Creating Worklet Context..."); auto runOnJS = [callInvoker](std::function&& f) { // Run on React JS Runtime callInvoker->invokeAsync(std::move(f)); }; - auto runOnWorklet = [](std::function&& f) { + auto runOnWorklet = [delegate](std::function&& f) { // Run on Frame Processor Worklet Runtime - dispatch_async(CameraQueues.videoQueue, [f = std::move(f)]() { f(); }); + dispatch_async(delegate.dispatchQueue, [f = std::move(f)]() { f(); }); }; _workletContext = std::make_shared("VisionCamera", &runtime, runOnJS, runOnWorklet); @@ -67,8 +54,6 @@ @interface CameraView : UIView } void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag, const std::shared_ptr& function) { - auto worklet = std::make_shared(runtime, function); - FrameProcessor* frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet context:_workletContext]; RCTExecuteOnMainQueue(^{ auto currentBridge = [RCTBridge currentBridge]; @@ -114,18 +99,27 @@ @interface CameraView : UIView return jsi::Function::createFromHostFunction( runtime, jsi::PropNameID::forUtf8(runtime, "setFrameProcessor"), 1, [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { - auto viewTag = arguments[0].asNumber(); - auto frameProcessor = arguments[1].asObject(runtime).asFunction(runtime); - auto sharedFunction = std::make_shared(std::move(frameProcessor)); - this->setFrameProcessor(runtime, static_cast(viewTag), sharedFunction); + auto jsViewTag = arguments[0].asNumber(); + auto jsWorklet = arguments[1].asObject(runtime).asFunction(runtime); + auto worklet = std::make_shared(runtime, jsWorklet); + + // Call Swift delegate to set the Frame Processor (maybe on UI Thread) + FrameProcessor* frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet context:_workletContext]; + NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; + [_delegate setFrameProcessor:frameProcessor forView:viewTag]; + return jsi::Value::undefined(); }); } else if (name == "removeFrameProcessor") { return jsi::Function::createFromHostFunction( runtime, jsi::PropNameID::forUtf8(runtime, "removeFrameProcessor"), 1, [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { - auto viewTag = arguments[0].asNumber(); - this->removeFrameProcessor(runtime, static_cast(viewTag)); + auto jsViewTag = arguments[0].asNumber(); + + // Call Swift delegate to remove Frame Processor (maybe on UI Thread) + NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; + [_delegate removeFrameProcessorForView:viewTag]; + return jsi::Value::undefined(); }); } else if (name == "initFrameProcessorPlugin") { @@ -146,39 +140,3 @@ @interface CameraView : UIView return jsi::Value::undefined(); } - -@implementation VisionCameraProxyHolder { - VisionCameraProxy* _proxy; -} - -- (instancetype)initWithProxy:(void*)proxy { - if (self = [super init]) { - _proxy = (VisionCameraProxy*)proxy; - } - return self; -} - -- (VisionCameraProxy*)proxy { - return _proxy; -} - -@end - -@implementation VisionCameraInstaller - -+ (BOOL)installToBridge:(RCTBridge* _Nonnull)bridge { - RCTCxxBridge* cxxBridge = (RCTCxxBridge*)[RCTBridge currentBridge]; - if (!cxxBridge.runtime) { - return NO; - } - - jsi::Runtime& runtime = *(jsi::Runtime*)cxxBridge.runtime; - - // global.VisionCameraProxy - auto visionCameraProxy = std::make_shared(runtime, bridge.jsCallInvoker); - runtime.global().setProperty(runtime, "VisionCameraProxy", jsi::Object::createFromHostObject(runtime, visionCameraProxy)); - - return YES; -} - -@end diff --git a/package/ios/Frame Processor/VisionCameraProxyDelegate.h b/package/ios/Frame Processor/VisionCameraProxyDelegate.h new file mode 100644 index 0000000000..ef206635bb --- /dev/null +++ b/package/ios/Frame Processor/VisionCameraProxyDelegate.h @@ -0,0 +1,29 @@ +// +// VisionCameraProxyDelegate.h +// Pods +// +// Created by Marc Rousavy on 20.04.24. +// + +#pragma once + +#import +#import "FrameProcessor.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + A delegate to implement which will be used by the VisionCameraProxy. + */ +@protocol VisionCameraProxyDelegate + +- (void)setFrameProcessor:(FrameProcessor*)frameProcessor forView:(NSNumber*)viewTag; +- (void)removeFrameProcessorForView:(NSNumber*)viewTag; + +- (dispatch_queue_t)getDispatchQueue; +- (RCTBridge*)getBridge; + +@end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.h b/package/ios/Frame Processor/VisionCameraProxyHolder.h new file mode 100644 index 0000000000..3cc56353b5 --- /dev/null +++ b/package/ios/Frame Processor/VisionCameraProxyHolder.h @@ -0,0 +1,32 @@ +// +// VisionCameraProxyHolder.h +// Pods +// +// Created by Marc Rousavy on 20.04.24. +// + +#pragma once + +#import +#import "FrameProcessor.h" + +#ifdef __cplusplus +#import "VisionCameraProxy.h" +#endif + +NS_ASSUME_NONNULL_BEGIN + +/** + An Objective-C/Swift class that holds the C++ VisionCameraProxy. + */ +@interface VisionCameraProxyHolder : NSObject + +- (_Nonnull instancetype)initWithProxy:(void*)proxy; + +#ifdef __cplusplus +- (VisionCameraProxy*)proxy; +#endif + +@end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.mm b/package/ios/Frame Processor/VisionCameraProxyHolder.mm new file mode 100644 index 0000000000..e0e5db0ee9 --- /dev/null +++ b/package/ios/Frame Processor/VisionCameraProxyHolder.mm @@ -0,0 +1,27 @@ +// +// VisionCameraProxyHolder.mm +// DoubleConversion +// +// Created by Marc Rousavy on 20.04.24. +// + +#import +#import "VisionCameraProxyHolder.h" +#import "VisionCameraProxy.h" + +@implementation VisionCameraProxyHolder { + VisionCameraProxy* _proxy; +} + +- (instancetype)initWithProxy:(void*)proxy { + if (self = [super init]) { + _proxy = (VisionCameraProxy*)proxy; + } + return self; +} + +- (VisionCameraProxy*)proxy { + return _proxy; +} + +@end From f807b1b38693d441d7167e62713d73aaaebf9c2f Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:03:37 +0200 Subject: [PATCH 05/22] some fixes --- package/VisionCamera.podspec | 4 ++-- package/ios/CameraBridge.h | 2 +- package/ios/CameraViewManager.swift | 2 +- package/ios/Frame Processor/SharedArray.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index e6b00b2ae2..ef18f1b002 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -73,12 +73,12 @@ Pod::Spec.new do |s| fp.dependency "react-native-worklets-core" fp.source_files = [ - "ios/Frame Processor/*.{h,m,mm}", + "ios/Frame Processor/*.{h,m,mm,cpp}", "cpp/**/*.{h,cpp}" ] fp.preserve_paths = [ - "cpp/**/*.h", "ios/Frame Processor/*.h" + "cpp/**/*.h", ] fp.pod_target_xcconfig = { diff --git a/package/ios/CameraBridge.h b/package/ios/CameraBridge.h index c369a51a87..78f5d3c283 100644 --- a/package/ios/CameraBridge.h +++ b/package/ios/CameraBridge.h @@ -22,5 +22,5 @@ #import "SharedArray.h" #import "VisionCameraProxyDelegate.h" #import "VisionCameraProxyHolder.h" -#import "VisionCameraProxyInstaller.h" +#import "VisionCameraInstaller.h" #endif diff --git a/package/ios/CameraViewManager.swift b/package/ios/CameraViewManager.swift index c1b890a519..5789f11ba6 100644 --- a/package/ios/CameraViewManager.swift +++ b/package/ios/CameraViewManager.swift @@ -32,7 +32,7 @@ final class CameraViewManager: RCTViewManager { final func installFrameProcessorBindings() -> NSNumber { #if VISION_CAMERA_ENABLE_FRAME_PROCESSORS // Called on JS Thread (blocking sync method) - let result = VisionCameraInstaller.install(to: bridge) + let result = VisionCameraInstaller.install(with: self) return NSNumber(value: result) #else return false as NSNumber diff --git a/package/ios/Frame Processor/SharedArray.h b/package/ios/Frame Processor/SharedArray.h index 132cb4effb..44d6992966 100644 --- a/package/ios/Frame Processor/SharedArray.h +++ b/package/ios/Frame Processor/SharedArray.h @@ -8,7 +8,7 @@ #pragma once -#import "VisionCameraProxy.h" +#import "VisionCameraProxyHolder.h" #import #ifdef __cplusplus From 1b18c1f5d50ecd76fb30acdb098f7a29ab49e929 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:05:14 +0200 Subject: [PATCH 06/22] hmm --- package/ios/Frame Processor/JSINSObjectConversion.mm | 6 +++--- package/ios/Frame Processor/VisionCameraProxy.mm | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package/ios/Frame Processor/JSINSObjectConversion.mm b/package/ios/Frame Processor/JSINSObjectConversion.mm index 9ddeb4891e..222d8155dd 100644 --- a/package/ios/Frame Processor/JSINSObjectConversion.mm +++ b/package/ios/Frame Processor/JSINSObjectConversion.mm @@ -16,9 +16,9 @@ // #import "JSINSObjectConversion.h" -#import "../Frame Processor/Frame.h" -#import "../Frame Processor/FrameHostObject.h" -#import "../Frame Processor/SharedArray.h" +#import "Frame.h" +#import "FrameHostObject.h" +#import "SharedArray.h" #import #import #import diff --git a/package/ios/Frame Processor/VisionCameraProxy.mm b/package/ios/Frame Processor/VisionCameraProxy.mm index bed3081679..cde14d42ca 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.mm +++ b/package/ios/Frame Processor/VisionCameraProxy.mm @@ -11,7 +11,6 @@ #import #import "VisionCameraProxyHolder.h" -#import "FrameHostObject.h" #import "FrameProcessor.h" #import "FrameProcessorPluginHostObject.h" #import "FrameProcessorPluginRegistry.h" @@ -102,12 +101,12 @@ auto jsViewTag = arguments[0].asNumber(); auto jsWorklet = arguments[1].asObject(runtime).asFunction(runtime); auto worklet = std::make_shared(runtime, jsWorklet); - + // Call Swift delegate to set the Frame Processor (maybe on UI Thread) FrameProcessor* frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet context:_workletContext]; NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; [_delegate setFrameProcessor:frameProcessor forView:viewTag]; - + return jsi::Value::undefined(); }); } else if (name == "removeFrameProcessor") { @@ -115,11 +114,11 @@ runtime, jsi::PropNameID::forUtf8(runtime, "removeFrameProcessor"), 1, [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { auto jsViewTag = arguments[0].asNumber(); - + // Call Swift delegate to remove Frame Processor (maybe on UI Thread) NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; [_delegate removeFrameProcessorForView:viewTag]; - + return jsi::Value::undefined(); }); } else if (name == "initFrameProcessorPlugin") { From b066f9d32d14f436f065b744a7a1c49ed922a28e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:08:36 +0200 Subject: [PATCH 07/22] fix: Only export ObjC/Swift visible headers --- package/VisionCamera.podspec | 14 +++++++++++--- package/example/ios/Podfile.lock | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index ef18f1b002..cbf1186d9e 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -73,11 +73,19 @@ Pod::Spec.new do |s| fp.dependency "react-native-worklets-core" fp.source_files = [ - "ios/Frame Processor/*.{h,m,mm,cpp}", - "cpp/**/*.{h,cpp}" + # C++ sources + "ios/Frame Processor/*.{m,mm,cpp}", + "cpp/**/*.{h,cpp}", + # Swift/Objective-C visible headers + "ios/Frame Processor/Frame.h", + "ios/Frame Processor/FrameProcessor.h", + "ios/Frame Processor/SharedArray.h", + "ios/Frame Processor/VisionCameraProxyDelegate.h", + "ios/Frame Processor/VisionCameraProxyHolder.h", + "ios/Frame Processor/VisionCameraInstaller.h", ] fp.preserve_paths = [ - "ios/Frame Processor/*.h" + "ios/Frame Processor/*.h", "cpp/**/*.h", ] diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 07657d4f12..73730055c0 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: fb3c4c3cf0cd3f8911ebb53a488d091e29e30568 + VisionCamera: 6813f638890ba0be3b7bd82f29c62fa7920d90c2 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e From 6d3c5e8371881a0d3dc0e2b63bda729cd2f6d471 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:09:22 +0200 Subject: [PATCH 08/22] fix: Also drop C++ sources --- package/VisionCamera.podspec | 2 +- package/example/ios/Podfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index cbf1186d9e..74c2c6c50c 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -75,7 +75,7 @@ Pod::Spec.new do |s| fp.source_files = [ # C++ sources "ios/Frame Processor/*.{m,mm,cpp}", - "cpp/**/*.{h,cpp}", + "cpp/**/*.{cpp}", # Swift/Objective-C visible headers "ios/Frame Processor/Frame.h", "ios/Frame Processor/FrameProcessor.h", diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 73730055c0..986e702e9d 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: 6813f638890ba0be3b7bd82f29c62fa7920d90c2 + VisionCamera: b319aba731a1372d60721662559fc1102d8c65d4 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e From f96a68da37e2c2803496716b27d0b86e63a6c5e2 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:12:34 +0200 Subject: [PATCH 09/22] fix: Move to correct folder --- .../{ => ios}/CameraViewManager+VisionCameraProxyDelegate.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename package/{ => ios}/CameraViewManager+VisionCameraProxyDelegate.swift (100%) diff --git a/package/CameraViewManager+VisionCameraProxyDelegate.swift b/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift similarity index 100% rename from package/CameraViewManager+VisionCameraProxyDelegate.swift rename to package/ios/CameraViewManager+VisionCameraProxyDelegate.swift From 30151610c393f21891594039ce977f752bf97a0e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:20:14 +0200 Subject: [PATCH 10/22] fix: Fix any remaining C++ includes --- .../Frame Processor/FrameProcessorPlugin.h | 2 +- .../FrameProcessorPluginRegistry.h | 2 +- .../ios/Frame Processor/VisionCameraProxy.h | 6 +-- .../ios/Frame Processor/VisionCameraProxy.mm | 48 ++++++++----------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/package/ios/Frame Processor/FrameProcessorPlugin.h b/package/ios/Frame Processor/FrameProcessorPlugin.h index 06834451d1..3f19193c08 100644 --- a/package/ios/Frame Processor/FrameProcessorPlugin.h +++ b/package/ios/Frame Processor/FrameProcessorPlugin.h @@ -9,7 +9,7 @@ #pragma once #import "Frame.h" -#import "VisionCameraProxy.h" +#import "VisionCameraProxyHolder.h" #import NS_ASSUME_NONNULL_BEGIN diff --git a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h index 9b766b2e56..4317d6c36b 100644 --- a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h +++ b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h @@ -10,7 +10,7 @@ #import "Frame.h" #import "FrameProcessorPlugin.h" -#import "VisionCameraProxy.h" +#import "VisionCameraProxyHolder.h" #import NS_ASSUME_NONNULL_BEGIN diff --git a/package/ios/Frame Processor/VisionCameraProxy.h b/package/ios/Frame Processor/VisionCameraProxy.h index e63e049cbe..4902c092b6 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.h +++ b/package/ios/Frame Processor/VisionCameraProxy.h @@ -37,9 +37,9 @@ class VisionCameraProxy : public jsi::HostObject { } private: - void setFrameProcessor(jsi::Runtime& runtime, int viewTag, const std::shared_ptr& frameProcessor); - void removeFrameProcessor(jsi::Runtime& runtime, int viewTag); - jsi::Value initFrameProcessorPlugin(jsi::Runtime& runtime, std::string name, const jsi::Object& options); + void setFrameProcessor(jsi::Runtime& runtime, double viewTag, jsi::Function&& frameProcessor); + void removeFrameProcessor(jsi::Runtime& runtime, double viewTag); + jsi::Value initFrameProcessorPlugin(jsi::Runtime& runtime, const jsi::String& name, const jsi::Object& options); private: std::shared_ptr _workletContext; diff --git a/package/ios/Frame Processor/VisionCameraProxy.mm b/package/ios/Frame Processor/VisionCameraProxy.mm index cde14d42ca..f9dab5e60d 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.mm +++ b/package/ios/Frame Processor/VisionCameraProxy.mm @@ -32,7 +32,7 @@ }; auto runOnWorklet = [delegate](std::function&& f) { // Run on Frame Processor Worklet Runtime - dispatch_async(delegate.dispatchQueue, [f = std::move(f)]() { f(); }); + dispatch_async(delegate.getDispatchQueue, [f = std::move(f)]() { f(); }); }; _workletContext = std::make_shared("VisionCamera", &runtime, runOnJS, runOnWorklet); @@ -52,27 +52,24 @@ return result; } -void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, int viewTag, const std::shared_ptr& function) { +void VisionCameraProxy::setFrameProcessor(jsi::Runtime& runtime, double jsViewTag, jsi::Function&& function) { + auto sharedFunction = std::make_shared(std::move(function)); + auto worklet = std::make_shared(runtime, sharedFunction); - RCTExecuteOnMainQueue(^{ - auto currentBridge = [RCTBridge currentBridge]; - auto anonymousView = [currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]]; - auto view = static_cast(anonymousView); - view.frameProcessor = frameProcessor; - }); + // Call Swift delegate to set the Frame Processor (maybe on UI Thread) + FrameProcessor* frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet context:_workletContext]; + NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; + [_delegate setFrameProcessor:frameProcessor forView:viewTag]; } -void VisionCameraProxy::removeFrameProcessor(jsi::Runtime& runtime, int viewTag) { - RCTExecuteOnMainQueue(^{ - auto currentBridge = [RCTBridge currentBridge]; - auto anonymousView = [currentBridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewTag]]; - auto view = static_cast(anonymousView); - view.frameProcessor = nil; - }); +void VisionCameraProxy::removeFrameProcessor(jsi::Runtime& runtime, double jsViewTag) { + NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; + [_delegate removeFrameProcessorForView:viewTag]; } -jsi::Value VisionCameraProxy::initFrameProcessorPlugin(jsi::Runtime& runtime, std::string name, const jsi::Object& options) { - NSString* key = [NSString stringWithUTF8String:name.c_str()]; +jsi::Value VisionCameraProxy::initFrameProcessorPlugin(jsi::Runtime& runtime, const jsi::String& name, const jsi::Object& options) { + std::string nameString = name.utf8(runtime); + NSString* key = [NSString stringWithUTF8String:nameString.c_str()]; NSDictionary* optionsObjc = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, options, _callInvoker); VisionCameraProxyHolder* proxy = [[VisionCameraProxyHolder alloc] initWithProxy:this]; @@ -98,14 +95,12 @@ return jsi::Function::createFromHostFunction( runtime, jsi::PropNameID::forUtf8(runtime, "setFrameProcessor"), 1, [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { + if (count != 2) { + throw jsi::JSError(runtime, "setFrameProcessor expected 2 arguments, but received " + std::to_string(count)); + } auto jsViewTag = arguments[0].asNumber(); auto jsWorklet = arguments[1].asObject(runtime).asFunction(runtime); - auto worklet = std::make_shared(runtime, jsWorklet); - - // Call Swift delegate to set the Frame Processor (maybe on UI Thread) - FrameProcessor* frameProcessor = [[FrameProcessor alloc] initWithWorklet:worklet context:_workletContext]; - NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; - [_delegate setFrameProcessor:frameProcessor forView:viewTag]; + setFrameProcessor(runtime, jsViewTag, std::move(jsWorklet)); return jsi::Value::undefined(); }); @@ -114,10 +109,7 @@ runtime, jsi::PropNameID::forUtf8(runtime, "removeFrameProcessor"), 1, [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { auto jsViewTag = arguments[0].asNumber(); - - // Call Swift delegate to remove Frame Processor (maybe on UI Thread) - NSNumber* viewTag = [NSNumber numberWithDouble:jsViewTag]; - [_delegate removeFrameProcessorForView:viewTag]; + removeFrameProcessor(runtime, jsViewTag); return jsi::Value::undefined(); }); @@ -128,7 +120,7 @@ if (count < 1 || !arguments[0].isString()) { throw jsi::JSError(runtime, "First argument needs to be a string (pluginName)!"); } - auto pluginName = arguments[0].asString(runtime).utf8(runtime); + auto pluginName = arguments[0].asString(runtime); auto options = count > 1 ? arguments[1].asObject(runtime) : jsi::Object(runtime); return this->initFrameProcessorPlugin(runtime, pluginName, options); From 3ea4664f305e82a1bd1d33d4ac3609fea89fc335 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:20:27 +0200 Subject: [PATCH 11/22] chore: Format --- package/ios/CameraBridge.h | 2 +- ...iewManager+VisionCameraProxyDelegate.swift | 40 +++++++++---------- package/ios/CameraViewManager.swift | 2 +- .../Frame Processor/VisionCameraInstaller.mm | 2 +- .../ios/Frame Processor/VisionCameraProxy.h | 5 +-- .../ios/Frame Processor/VisionCameraProxy.mm | 5 +-- .../VisionCameraProxyDelegate.h | 2 +- .../Frame Processor/VisionCameraProxyHolder.h | 2 +- .../VisionCameraProxyHolder.mm | 2 +- 9 files changed, 30 insertions(+), 32 deletions(-) diff --git a/package/ios/CameraBridge.h b/package/ios/CameraBridge.h index 78f5d3c283..a078449feb 100644 --- a/package/ios/CameraBridge.h +++ b/package/ios/CameraBridge.h @@ -20,7 +20,7 @@ #import "Frame.h" #import "FrameProcessor.h" #import "SharedArray.h" +#import "VisionCameraInstaller.h" #import "VisionCameraProxyDelegate.h" #import "VisionCameraProxyHolder.h" -#import "VisionCameraInstaller.h" #endif diff --git a/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift b/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift index c8eaa0c14f..41be63b948 100644 --- a/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift +++ b/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift @@ -9,28 +9,28 @@ import Foundation #if VISION_CAMERA_ENABLE_FRAME_PROCESSORS -extension CameraViewManager: VisionCameraProxyDelegate { - func getDispatchQueue() -> dispatch_queue_t { - return CameraQueues.videoQueue - } - - func getBridge() -> RCTBridge { - return bridge - } - - func setFrameProcessor(_ frameProcessor: FrameProcessor, forView viewTag: NSNumber) { - DispatchQueue.main.async { - let view = self.getCameraView(withTag: viewTag) - view.frameProcessor = frameProcessor + extension CameraViewManager: VisionCameraProxyDelegate { + func getDispatchQueue() -> dispatch_queue_t { + return CameraQueues.videoQueue } - } - - func removeFrameProcessor(forView viewTag: NSNumber) { - DispatchQueue.main.async { - let view = self.getCameraView(withTag: viewTag) - view.frameProcessor = nil + + func getBridge() -> RCTBridge { + return bridge + } + + func setFrameProcessor(_ frameProcessor: FrameProcessor, forView viewTag: NSNumber) { + DispatchQueue.main.async { + let view = self.getCameraView(withTag: viewTag) + view.frameProcessor = frameProcessor + } + } + + func removeFrameProcessor(forView viewTag: NSNumber) { + DispatchQueue.main.async { + let view = self.getCameraView(withTag: viewTag) + view.frameProcessor = nil + } } } -} #endif diff --git a/package/ios/CameraViewManager.swift b/package/ios/CameraViewManager.swift index 5789f11ba6..f7bd9e8d0e 100644 --- a/package/ios/CameraViewManager.swift +++ b/package/ios/CameraViewManager.swift @@ -148,7 +148,7 @@ final class CameraViewManager: RCTViewManager { // MARK: Private - internal func getCameraView(withTag tag: NSNumber) -> CameraView { + func getCameraView(withTag tag: NSNumber) -> CameraView { // swiftlint:disable force_cast return bridge.uiManager.view(forReactTag: tag) as! CameraView // swiftlint:enable force_cast diff --git a/package/ios/Frame Processor/VisionCameraInstaller.mm b/package/ios/Frame Processor/VisionCameraInstaller.mm index 8fb01774bc..f27c043fc6 100644 --- a/package/ios/Frame Processor/VisionCameraInstaller.mm +++ b/package/ios/Frame Processor/VisionCameraInstaller.mm @@ -5,9 +5,9 @@ // Created by Marc Rousavy on 20.04.24. // -#import #import "VisionCameraInstaller.h" #import "VisionCameraProxy.h" +#import #import #import diff --git a/package/ios/Frame Processor/VisionCameraProxy.h b/package/ios/Frame Processor/VisionCameraProxy.h index 4902c092b6..fbadd52d39 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.h +++ b/package/ios/Frame Processor/VisionCameraProxy.h @@ -14,17 +14,16 @@ #import +#import "VisionCameraProxyDelegate.h" #import "WKTJsiWorkletContext.h" #import #import -#import "VisionCameraProxyDelegate.h" using namespace facebook; class VisionCameraProxy : public jsi::HostObject { public: - explicit VisionCameraProxy(jsi::Runtime& runtime, - std::shared_ptr callInvoker, + explicit VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr callInvoker, id delegate); ~VisionCameraProxy(); diff --git a/package/ios/Frame Processor/VisionCameraProxy.mm b/package/ios/Frame Processor/VisionCameraProxy.mm index f9dab5e60d..378ba3e65e 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.mm +++ b/package/ios/Frame Processor/VisionCameraProxy.mm @@ -10,17 +10,16 @@ #import #import -#import "VisionCameraProxyHolder.h" #import "FrameProcessor.h" #import "FrameProcessorPluginHostObject.h" #import "FrameProcessorPluginRegistry.h" #import "JSINSObjectConversion.h" +#import "VisionCameraProxyHolder.h" #import "WKTJsiWorklet.h" using namespace facebook; -VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime, - std::shared_ptr callInvoker, +VisionCameraProxy::VisionCameraProxy(jsi::Runtime& runtime, std::shared_ptr callInvoker, id delegate) { _callInvoker = callInvoker; _delegate = delegate; diff --git a/package/ios/Frame Processor/VisionCameraProxyDelegate.h b/package/ios/Frame Processor/VisionCameraProxyDelegate.h index ef206635bb..b5ded8b16f 100644 --- a/package/ios/Frame Processor/VisionCameraProxyDelegate.h +++ b/package/ios/Frame Processor/VisionCameraProxyDelegate.h @@ -7,8 +7,8 @@ #pragma once -#import #import "FrameProcessor.h" +#import #import NS_ASSUME_NONNULL_BEGIN diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.h b/package/ios/Frame Processor/VisionCameraProxyHolder.h index 3cc56353b5..4c0b8c95df 100644 --- a/package/ios/Frame Processor/VisionCameraProxyHolder.h +++ b/package/ios/Frame Processor/VisionCameraProxyHolder.h @@ -7,8 +7,8 @@ #pragma once -#import #import "FrameProcessor.h" +#import #ifdef __cplusplus #import "VisionCameraProxy.h" diff --git a/package/ios/Frame Processor/VisionCameraProxyHolder.mm b/package/ios/Frame Processor/VisionCameraProxyHolder.mm index e0e5db0ee9..3fd753b594 100644 --- a/package/ios/Frame Processor/VisionCameraProxyHolder.mm +++ b/package/ios/Frame Processor/VisionCameraProxyHolder.mm @@ -5,9 +5,9 @@ // Created by Marc Rousavy on 20.04.24. // -#import #import "VisionCameraProxyHolder.h" #import "VisionCameraProxy.h" +#import @implementation VisionCameraProxyHolder { VisionCameraProxy* _proxy; From e66daad11cd757f2acfd1db161db518bbd7939a3 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:21:28 +0200 Subject: [PATCH 12/22] fix: Fix missingg Swift include --- package/VisionCamera.podspec | 1 + package/example/ios/Podfile.lock | 2 +- package/ios/CameraBridge.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 74c2c6c50c..74c5981dc5 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -79,6 +79,7 @@ Pod::Spec.new do |s| # Swift/Objective-C visible headers "ios/Frame Processor/Frame.h", "ios/Frame Processor/FrameProcessor.h", + "ios/Frame Processor/FrameProcessorPlugin.h", "ios/Frame Processor/SharedArray.h", "ios/Frame Processor/VisionCameraProxyDelegate.h", "ios/Frame Processor/VisionCameraProxyHolder.h", diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 986e702e9d..a73dcedd07 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: b319aba731a1372d60721662559fc1102d8c65d4 + VisionCamera: d9ddc2e0114b6a3aa625ba9ab76e348a7bba8d65 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e diff --git a/package/ios/CameraBridge.h b/package/ios/CameraBridge.h index a078449feb..9c05bc64f7 100644 --- a/package/ios/CameraBridge.h +++ b/package/ios/CameraBridge.h @@ -19,6 +19,7 @@ #if VISION_CAMERA_ENABLE_FRAME_PROCESSORS #import "Frame.h" #import "FrameProcessor.h" +#import "FrameProcessorPlugin.h" #import "SharedArray.h" #import "VisionCameraInstaller.h" #import "VisionCameraProxyDelegate.h" From 8c6e444a57c2d7be49f4dcfa8bd11455eff4ea97 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:23:22 +0200 Subject: [PATCH 13/22] fix: Add PluginRegistry Swift include --- package/VisionCamera.podspec | 1 + .../Example Plugin/ExampleFrameProcessorPlugin.m | 1 - package/example/ios/Podfile.lock | 2 +- package/ios/CameraBridge.h | 2 +- package/ios/Frame Processor/FrameProcessorPlugin.h | 1 + 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 74c5981dc5..0c216cc118 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -80,6 +80,7 @@ Pod::Spec.new do |s| "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", diff --git a/package/example/ios/Frame Processor Plugins/Example Plugin/ExampleFrameProcessorPlugin.m b/package/example/ios/Frame Processor Plugins/Example Plugin/ExampleFrameProcessorPlugin.m index 9a66b1035c..9233113d09 100644 --- a/package/example/ios/Frame Processor Plugins/Example Plugin/ExampleFrameProcessorPlugin.m +++ b/package/example/ios/Frame Processor Plugins/Example Plugin/ExampleFrameProcessorPlugin.m @@ -8,7 +8,6 @@ #if __has_include() #import #import -#import #import #import diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index a73dcedd07..c24e3d85b4 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: d9ddc2e0114b6a3aa625ba9ab76e348a7bba8d65 + VisionCamera: 117a4591c12bc6344cb90f21c6cb09d06a75c6ed Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e diff --git a/package/ios/CameraBridge.h b/package/ios/CameraBridge.h index 9c05bc64f7..ae02876246 100644 --- a/package/ios/CameraBridge.h +++ b/package/ios/CameraBridge.h @@ -12,7 +12,6 @@ #import #import -#import #import #import @@ -20,6 +19,7 @@ #import "Frame.h" #import "FrameProcessor.h" #import "FrameProcessorPlugin.h" +#import "FrameProcessorPluginRegistry.h" #import "SharedArray.h" #import "VisionCameraInstaller.h" #import "VisionCameraProxyDelegate.h" diff --git a/package/ios/Frame Processor/FrameProcessorPlugin.h b/package/ios/Frame Processor/FrameProcessorPlugin.h index 3f19193c08..4fe0ee4802 100644 --- a/package/ios/Frame Processor/FrameProcessorPlugin.h +++ b/package/ios/Frame Processor/FrameProcessorPlugin.h @@ -9,6 +9,7 @@ #pragma once #import "Frame.h" +#import "FrameProcessorPluginRegistry.h" #import "VisionCameraProxyHolder.h" #import From bd368d714ee477cbf37fc2f25d70fc5df76459a0 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:26:33 +0200 Subject: [PATCH 14/22] Update FrameProcessorPluginRegistry.h --- package/ios/Frame Processor/FrameProcessorPluginRegistry.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h index 4317d6c36b..f3990bb035 100644 --- a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h +++ b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h @@ -15,6 +15,9 @@ NS_ASSUME_NONNULL_BEGIN +// forward-declare the Plugin - caller should always include anyways. +@class FrameProcessorPlugin; + @interface FrameProcessorPluginRegistry : NSObject typedef FrameProcessorPlugin* _Nonnull (^PluginInitializerFunction)(VisionCameraProxyHolder* proxy, NSDictionary* _Nullable options); From b022dbc76130fef3984bd5432c217ca8a4adb0e9 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:29:25 +0200 Subject: [PATCH 15/22] fix: Disable location --- package/ios/Core/LocationProvider.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/package/ios/Core/LocationProvider.swift b/package/ios/Core/LocationProvider.swift index a3c1968736..e84fb9bd88 100644 --- a/package/ios/Core/LocationProvider.swift +++ b/package/ios/Core/LocationProvider.swift @@ -23,11 +23,15 @@ class LocationProvider { } private var authorizationStatus: CLAuthorizationStatus { - if #available(iOS 14.0, *) { - return locationManager.authorizationStatus - } else { - return CLLocationManager.authorizationStatus() - } + #if VISION_CAMERA_ENABLE_LOCATION + if #available(iOS 14.0, *) { + return locationManager.authorizationStatus + } else { + return CLLocationManager.authorizationStatus() + } + #else + return .restricted + #endif } var hasPermission: Bool { From 87dc994766f1f07ea31fe5da8b12b98dfd223010 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:34:18 +0200 Subject: [PATCH 16/22] fix: Use `public_header_files` instead of `preserve_paths` --- package/VisionCamera.podspec | 11 ++++------- package/example/ios/Podfile.lock | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 0c216cc118..0ce8fddf3a 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -55,7 +55,6 @@ Pod::Spec.new do |s| "ios/Types/*.{m,mm,swift}", "ios/CameraBridge.h", ] - core.preserve_paths = "ios/**/*.h" core.pod_target_xcconfig = { "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", @@ -74,8 +73,10 @@ Pod::Spec.new do |s| fp.source_files = [ # C++ sources - "ios/Frame Processor/*.{m,mm,cpp}", - "cpp/**/*.{cpp}", + "ios/Frame Processor/*.{h,m,mm,cpp}", + "cpp/**/*.{h,cpp}", + ] + fp.public_header_files = [ # Swift/Objective-C visible headers "ios/Frame Processor/Frame.h", "ios/Frame Processor/FrameProcessor.h", @@ -86,10 +87,6 @@ Pod::Spec.new do |s| "ios/Frame Processor/VisionCameraProxyHolder.h", "ios/Frame Processor/VisionCameraInstaller.h", ] - fp.preserve_paths = [ - "ios/Frame Processor/*.h", - "cpp/**/*.h", - ] fp.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index c24e3d85b4..140b4de631 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: 117a4591c12bc6344cb90f21c6cb09d06a75c6ed + VisionCamera: 129f7e33050d9f45660e4510565ebbd1a0c15126 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e From 9a7ad070b4d66274469109be46b5802b424ab078 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:41:14 +0200 Subject: [PATCH 17/22] Disable FP if needed --- package/VisionCamera.podspec | 71 ++++++++++++++++++-------------- package/example/ios/Podfile.lock | 2 +- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 0ce8fddf3a..0b0e4e64ae 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -20,8 +20,13 @@ end Pod::UI.puts("[VisionCamera] node modules #{Dir.exist?(nodeModules) ? "found at #{nodeModules}" : "not found!"}") workletsPath = File.join(nodeModules, "react-native-worklets-core") -hasWorklets = File.exist?(workletsPath) && enableFrameProcessors -Pod::UI.puts("[VisionCamera] react-native-worklets-core #{hasWorklets ? "found" : "not found"}, Frame Processors #{hasWorklets ? "enabled" : "disabled"}!") +hasWorklets = File.exist?(workletsPath) +if hasWorklets + Pod::UI.puts("[VisionCamera] react-native-worklets-core found, Frame Processors #{enableFrameProcessors ? "enabled" : "disabled"}!") +else + Pod::UI.puts("[VisionCamera] react-native-worklets-core not found - Frame Processors are #{hasWorklets ? "enabled" : "disabled"}!") + enableFrameProcessors = false +end Pod::Spec.new do |s| s.name = "VisionCamera" @@ -36,8 +41,8 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/mrousavy/react-native-vision-camera.git", :tag => "#{s.version}" } s.pod_target_xcconfig = { - "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) VISION_CAMERA_ENABLE_FRAME_PROCESSORS=#{hasWorklets}", - "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{hasWorklets ? "VISION_CAMERA_ENABLE_FRAME_PROCESSORS" : ""}", + "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) VISION_CAMERA_ENABLE_FRAME_PROCESSORS=#{enableFrameProcessors}", + "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableFrameProcessors ? "VISION_CAMERA_ENABLE_FRAME_PROCESSORS" : ""}", } s.requires_arc = true @@ -60,37 +65,39 @@ Pod::Spec.new do |s| "SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) #{enableLocation ? "VISION_CAMERA_ENABLE_LOCATION" : ""}", } - if hasWorklets + if enableFrameProcessors core.dependency "VisionCamera/FrameProcessors" end end - s.subspec 'FrameProcessors' do |fp| - # VisionCamera Frame Processors C++ codebase (optional) - fp.dependency "React" - fp.dependency "React-callinvoker" - fp.dependency "react-native-worklets-core" - - fp.source_files = [ - # C++ sources - "ios/Frame Processor/*.{h,m,mm,cpp}", - "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", - ] - - fp.pod_target_xcconfig = { - "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/cpp/\"/** " - } + if enableFrameProcessors + s.subspec 'FrameProcessors' do |fp| + # VisionCamera Frame Processors C++ codebase (optional) + fp.dependency "React" + fp.dependency "React-callinvoker" + fp.dependency "react-native-worklets-core" + + fp.source_files = [ + # C++ sources + "ios/Frame Processor/*.{h,m,mm,cpp}", + "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", + ] + + fp.pod_target_xcconfig = { + "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", + "HEADER_SEARCH_PATHS" => "$(inherited) \"$(PODS_TARGET_SRCROOT)/cpp/\"/** " + } + end end end diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 140b4de631..bc8c4584ea 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -711,6 +711,6 @@ SPEC CHECKSUMS: VisionCamera: 129f7e33050d9f45660e4510565ebbd1a0c15126 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 -PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e +PODFILE CHECKSUM: c9290600bb51f27b62e5130c6448d295a8b25cb9 COCOAPODS: 1.14.3 From 20c595df3707ff41a2246a09d07bd6e73ba10125 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sat, 20 Apr 2024 11:45:12 +0200 Subject: [PATCH 18/22] fix Podfile --- package/VisionCamera.podspec | 16 ++++++++++------ package/example/ios/Podfile.lock | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package/VisionCamera.podspec b/package/VisionCamera.podspec index 0b0e4e64ae..fee1c1fd12 100644 --- a/package/VisionCamera.podspec +++ b/package/VisionCamera.podspec @@ -4,18 +4,22 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json"))) nodeModules = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..') -enableFrameProcessors = true -if defined?($VCEnableFrameProcessors) - Pod::UI.puts "[VisionCamera] $VCEnableFrameProcessors is set to #{$VCEnableFrameProcessors}!" - enableFrameProcessors = $VCEnableFrameProcessors -end +Pod::UI.puts "[VisionCamera] Thank you for using VisionCamera ❤️" enableLocation = true if defined?($VCEnableLocation) Pod::UI.puts "[VisionCamera] $VCEnableLocation is set to #{$VCEnableLocation}!" enableLocation = $VCEnableLocation else - Pod::UI.puts "[VisionCamera] Building with CLLocation APIs as $VCEnableLocation is not set.." + Pod::UI.puts "[VisionCamera] $VCEnableLocation is not set, enabling CLLocation APIs by default..." +end + +enableFrameProcessors = true +if defined?($VCEnableFrameProcessors) + Pod::UI.puts "[VisionCamera] $VCEnableFrameProcessors is set to #{$VCEnableFrameProcessors}!" + enableFrameProcessors = $VCEnableFrameProcessors +else + Pod::UI.puts "[VisionCamera] $VCEnableFrameProcessors is not set, enabling Frame Processors if Worklets is installed..." end Pod::UI.puts("[VisionCamera] node modules #{Dir.exist?(nodeModules) ? "found at #{nodeModules}" : "not found!"}") diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index bc8c4584ea..140b4de631 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -711,6 +711,6 @@ SPEC CHECKSUMS: VisionCamera: 129f7e33050d9f45660e4510565ebbd1a0c15126 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 -PODFILE CHECKSUM: c9290600bb51f27b62e5130c6448d295a8b25cb9 +PODFILE CHECKSUM: 29d07573cd9f2aa1ecf53c481819da07fd66822e COCOAPODS: 1.14.3 From e114ef41fdeb54f21c547e50ef410b13eefaf67f Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 14:05:28 +0200 Subject: [PATCH 19/22] fix: Fix `dispatch_queue_t` in Swift --- package/ios/CameraViewManager+VisionCameraProxyDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift b/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift index 41be63b948..d2eb45e5fc 100644 --- a/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift +++ b/package/ios/CameraViewManager+VisionCameraProxyDelegate.swift @@ -10,7 +10,7 @@ import Foundation #if VISION_CAMERA_ENABLE_FRAME_PROCESSORS extension CameraViewManager: VisionCameraProxyDelegate { - func getDispatchQueue() -> dispatch_queue_t { + func getDispatchQueue() -> DispatchQueue { return CameraQueues.videoQueue } From 82cb56047b1e0458a3fd7b1acfaa1b25dcbddd4e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 14:20:09 +0200 Subject: [PATCH 20/22] fix: Disable FPs if not built --- package/example/ios/Podfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/package/example/ios/Podfile b/package/example/ios/Podfile index 1d6be476a5..eaab4d345c 100644 --- a/package/example/ios/Podfile +++ b/package/example/ios/Podfile @@ -1,3 +1,4 @@ +require 'cocoapods' # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( @@ -47,5 +48,28 @@ target 'VisionCameraExample' do :mac_catalyst_enabled => false ) __apply_Xcode_12_5_M1_post_install_workaround(installer) + + # Enable or disable our Example FP Plugins depending on FPs are enabled or not. + # In CI, we disable FPs to test if everything builds without FPs, so we also need to + # disable the FP plugins there. + podspec_path = File.join(__dir__, '../../VisionCamera.podspec') + podspec = Pod::Specification.from_file(podspec_path) + enableFrameProcessors = false + begin + podspec.subspec_by_name('VisionCamera/FrameProcessors') + Pod::UI.puts "Frame Processors are enabled." + enableFrameProcessors = true + rescue => e + Pod::UI.puts "Frame Processors are not enabled." + enableFrameProcessors = false + end + installer.generated_projects.each do |project| + project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] ||= '' + config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] << ' VISION_CAMERA_ENABLE_FRAME_PROCESSORS' + end + end + end end end From 96992a025089da9f619c399a3f62311536989fd1 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 14:27:44 +0200 Subject: [PATCH 21/22] Revert "fix: Disable FPs if not built" This reverts commit 82cb56047b1e0458a3fd7b1acfaa1b25dcbddd4e. --- package/example/ios/Podfile | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/package/example/ios/Podfile b/package/example/ios/Podfile index eaab4d345c..1d6be476a5 100644 --- a/package/example/ios/Podfile +++ b/package/example/ios/Podfile @@ -1,4 +1,3 @@ -require 'cocoapods' # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( @@ -48,28 +47,5 @@ target 'VisionCameraExample' do :mac_catalyst_enabled => false ) __apply_Xcode_12_5_M1_post_install_workaround(installer) - - # Enable or disable our Example FP Plugins depending on FPs are enabled or not. - # In CI, we disable FPs to test if everything builds without FPs, so we also need to - # disable the FP plugins there. - podspec_path = File.join(__dir__, '../../VisionCamera.podspec') - podspec = Pod::Specification.from_file(podspec_path) - enableFrameProcessors = false - begin - podspec.subspec_by_name('VisionCamera/FrameProcessors') - Pod::UI.puts "Frame Processors are enabled." - enableFrameProcessors = true - rescue => e - Pod::UI.puts "Frame Processors are not enabled." - enableFrameProcessors = false - end - installer.generated_projects.each do |project| - project.targets.each do |target| - target.build_configurations.each do |config| - config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] ||= '' - config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] << ' VISION_CAMERA_ENABLE_FRAME_PROCESSORS' - end - end - end end end From d27ff71fb8e26b87839d84849d52e882d31b3386 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Sun, 21 Apr 2024 14:29:02 +0200 Subject: [PATCH 22/22] Remove Example Plugins from source code --- .github/workflows/build-ios.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index d805a5f6ce..93101d808e 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -100,6 +100,8 @@ jobs: run: yarn install --frozen-lockfile --cwd .. - name: Remove worklets, skia and reanimated run: yarn remove react-native-worklets-core @shopify/react-native-skia react-native-reanimated --cwd .. + - name: Remove Example Plugins + run: rm -rf "Frame Processor Plugins/" - name: Restore buildcache uses: mikehardy/buildcache-action@v2