From 773f278df8094251a53af86911fbac9de7f0693a Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 16 Jan 2024 20:02:03 +0100 Subject: [PATCH] fix: Use property accessors on `Frame` (#2400) * fix: Use property accessors on `Frame` * Format * Use `_Nonnull` * fix: Assume nonnull * Use `NS_ASSUME_NONNULL_BEGIN` more * Format C++ --- package/example/ios/Podfile.lock | 4 +-- package/ios/Frame Processor/Frame.h | 26 ++++++++++--------- package/ios/Frame Processor/Frame.m | 15 +++++++---- package/ios/Frame Processor/FrameProcessor.h | 6 ++++- .../Frame Processor/FrameProcessorPlugin.h | 9 +++++-- .../FrameProcessorPluginRegistry.h | 13 ++++++---- package/ios/Frame Processor/SharedArray.h | 11 +++++--- .../ios/Frame Processor/VisionCameraProxy.h | 10 ++++--- 8 files changed, 60 insertions(+), 34 deletions(-) diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index fb57137..c27028b 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -484,7 +484,7 @@ PODS: - libwebp (~> 1.0) - SDWebImage/Core (~> 5.10) - SocketRocket (0.6.1) - - VisionCamera (3.7.1): + - VisionCamera (3.8.0): - React - React-callinvoker - React-Core @@ -724,7 +724,7 @@ SPEC CHECKSUMS: SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: ac444079a315b38ec664cf77ed548c384554f0ca + VisionCamera: 8e3454abf4baa43a2b9ad9cfc9723d1cc89d9eb6 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: 27f53791141a3303d814e09b55770336416ff4eb diff --git a/package/ios/Frame Processor/Frame.h b/package/ios/Frame Processor/Frame.h index 5f53525..8aa615d 100644 --- a/package/ios/Frame Processor/Frame.h +++ b/package/ios/Frame Processor/Frame.h @@ -12,23 +12,25 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @interface Frame : NSObject -- (instancetype _Nonnull)initWithBuffer:(CMSampleBufferRef _Nonnull)buffer orientation:(UIImageOrientation)orientation; - +- (instancetype)initWithBuffer:(CMSampleBufferRef)buffer orientation:(UIImageOrientation)orientation; - (instancetype)init NS_UNAVAILABLE; -@property(nonatomic, readonly) CMSampleBufferRef _Nonnull buffer; +@property(nonatomic, readonly) CMSampleBufferRef buffer; @property(nonatomic, readonly) UIImageOrientation orientation; -// Getters -- (NSString* _Nonnull)pixelFormat; -- (BOOL)isMirrored; -- (BOOL)isValid; -- (size_t)width; -- (size_t)height; -- (double)timestamp; -- (size_t)bytesPerRow; -- (size_t)planesCount; +@property(nonatomic, readonly) NSString* pixelFormat; +@property(nonatomic, readonly) BOOL isMirrored; +@property(nonatomic, readonly) BOOL isValid; +@property(nonatomic, readonly) size_t width; +@property(nonatomic, readonly) size_t height; +@property(nonatomic, readonly) double timestamp; +@property(nonatomic, readonly) size_t bytesPerRow; +@property(nonatomic, readonly) size_t planesCount; @end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/Frame.m b/package/ios/Frame Processor/Frame.m index a441f2d..e0d3150 100644 --- a/package/ios/Frame Processor/Frame.m +++ b/package/ios/Frame Processor/Frame.m @@ -11,11 +11,11 @@ #import @implementation Frame { - CMSampleBufferRef _Nonnull buffer; - UIImageOrientation orientation; + CMSampleBufferRef _Nonnull _buffer; + UIImageOrientation _orientation; } -- (instancetype)initWithBuffer:(CMSampleBufferRef _Nonnull)buffer orientation:(UIImageOrientation)orientation { +- (instancetype)initWithBuffer:(CMSampleBufferRef)buffer orientation:(UIImageOrientation)orientation { self = [super init]; if (self) { _buffer = buffer; @@ -29,8 +29,13 @@ CFRelease(_buffer); } -@synthesize buffer = _buffer; -@synthesize orientation = _orientation; +- (CMSampleBufferRef)buffer { + return _buffer; +} + +- (UIImageOrientation)orientation { + return _orientation; +} - (NSString*)pixelFormat { CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(_buffer); diff --git a/package/ios/Frame Processor/FrameProcessor.h b/package/ios/Frame Processor/FrameProcessor.h index 55fd364..6729c4a 100644 --- a/package/ios/Frame Processor/FrameProcessor.h +++ b/package/ios/Frame Processor/FrameProcessor.h @@ -19,6 +19,8 @@ #import #endif +NS_ASSUME_NONNULL_BEGIN + @interface FrameProcessor : NSObject - (instancetype)init NS_UNAVAILABLE; @@ -30,6 +32,8 @@ - (void)callWithFrameHostObject:(std::shared_ptr)frameHostObject; #endif -- (void)call:(Frame* _Nonnull)frame; +- (void)call:(Frame*)frame; @end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/FrameProcessorPlugin.h b/package/ios/Frame Processor/FrameProcessorPlugin.h index 560455c..0683445 100644 --- a/package/ios/Frame Processor/FrameProcessorPlugin.h +++ b/package/ios/Frame Processor/FrameProcessorPlugin.h @@ -12,6 +12,8 @@ #import "VisionCameraProxy.h" #import +NS_ASSUME_NONNULL_BEGIN + /** * The base class of a native Frame Processor Plugin. * @@ -32,7 +34,7 @@ * - proxy: The VisionCameraProxy instance for using the Frame Processor Context, e.g. to initialize SharedArrays. * - options: An options dictionary passed from the JS side, or `nil` if none. */ -- (instancetype _Nonnull)initWithProxy:(VisionCameraProxyHolder* _Nonnull)proxy +- (instancetype _Nonnull)initWithProxy:(VisionCameraProxyHolder*)proxy withOptions:(NSDictionary* _Nullable)options NS_SWIFT_NAME(init(proxy:options:)); - (instancetype _Nonnull)init NS_UNAVAILABLE; @@ -44,14 +46,17 @@ * * - Parameters: * - frame: The Frame from the Camera. Don't do any ref-counting on this, as VisionCamera handles that. + * - arguments: An options dictionary passed from the JS side, or `nil` if none. * - Returns: You can return any primitive, map or array you want. * See the Types * table for a list of supported types. */ -- (id _Nullable)callback:(Frame* _Nonnull)frame withArguments:(NSDictionary* _Nullable)arguments; +- (id _Nullable)callback:(Frame*)frame withArguments:(NSDictionary* _Nullable)arguments; @end +NS_ASSUME_NONNULL_END + #define VISION_CONCAT2(A, B) A##B #define VISION_CONCAT(A, B) VISION_CONCAT2(A, B) diff --git a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h index 975275b..9b766b2 100644 --- a/package/ios/Frame Processor/FrameProcessorPluginRegistry.h +++ b/package/ios/Frame Processor/FrameProcessorPluginRegistry.h @@ -13,15 +13,18 @@ #import "VisionCameraProxy.h" #import +NS_ASSUME_NONNULL_BEGIN + @interface FrameProcessorPluginRegistry : NSObject -typedef FrameProcessorPlugin* _Nonnull (^PluginInitializerFunction)(VisionCameraProxyHolder* _Nonnull proxy, - NSDictionary* _Nullable options); +typedef FrameProcessorPlugin* _Nonnull (^PluginInitializerFunction)(VisionCameraProxyHolder* proxy, NSDictionary* _Nullable options); -+ (void)addFrameProcessorPlugin:(NSString* _Nonnull)name withInitializer:(PluginInitializerFunction _Nonnull)pluginInitializer; ++ (void)addFrameProcessorPlugin:(NSString*)name withInitializer:(PluginInitializerFunction)pluginInitializer; -+ (FrameProcessorPlugin* _Nullable)getPlugin:(NSString* _Nonnull)name - withProxy:(VisionCameraProxyHolder* _Nonnull)proxy ++ (FrameProcessorPlugin* _Nullable)getPlugin:(NSString*)name + withProxy:(VisionCameraProxyHolder*)proxy withOptions:(NSDictionary* _Nullable)options; @end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/SharedArray.h b/package/ios/Frame Processor/SharedArray.h index 4bac9d3..81193ba 100644 --- a/package/ios/Frame Processor/SharedArray.h +++ b/package/ios/Frame Processor/SharedArray.h @@ -34,14 +34,15 @@ typedef NS_ENUM(NSInteger, SharedArrayType) { Float64Array, }; +NS_ASSUME_NONNULL_BEGIN + @interface SharedArray : NSObject -- (instancetype _Nonnull)init NS_UNAVAILABLE; - -- (instancetype _Nonnull)initWithProxy:(VisionCameraProxyHolder* _Nonnull)proxy type:(SharedArrayType)type size:(NSInteger)size; +- (instancetype)init NS_UNAVAILABLE; +- (instancetype)initWithProxy:(VisionCameraProxyHolder*)proxy type:(SharedArrayType)type size:(NSInteger)size; #ifdef __cplusplus -- (instancetype _Nonnull)initWithRuntime:(jsi::Runtime&)runtime typedArray:(std::shared_ptr)typedArray; +- (instancetype)initWithRuntime:(jsi::Runtime&)runtime typedArray:(std::shared_ptr)typedArray; - (std::shared_ptr)typedArray; #endif @@ -50,3 +51,5 @@ typedef NS_ENUM(NSInteger, SharedArrayType) { @property(nonatomic, readonly) NSInteger count; @end + +NS_ASSUME_NONNULL_END diff --git a/package/ios/Frame Processor/VisionCameraProxy.h b/package/ios/Frame Processor/VisionCameraProxy.h index 8c18bc0..3572035 100644 --- a/package/ios/Frame Processor/VisionCameraProxy.h +++ b/package/ios/Frame Processor/VisionCameraProxy.h @@ -42,18 +42,22 @@ private: }; #endif +NS_ASSUME_NONNULL_BEGIN + @interface VisionCameraProxyHolder : NSObject -- (_Nonnull instancetype)initWithProxy:(void* _Nonnull)proxy; +- (_Nonnull instancetype)initWithProxy:(void*)proxy; #ifdef __cplusplus -- (VisionCameraProxy* _Nonnull)proxy; +- (VisionCameraProxy*)proxy; #endif @end @interface VisionCameraInstaller : NSObject -+ (BOOL)installToBridge:(RCTBridge* _Nonnull)bridge; ++ (BOOL)installToBridge:(RCTBridge*)bridge; @end + +NS_ASSUME_NONNULL_END