Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[V2] Correct Frame Processor loading between Objc/Swift #2025

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ @implementation ExampleFrameProcessorPlugin
static inline id example_plugin(Frame* frame, NSArray* arguments) {
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
NSLog(@"ExamplePlugin: %zu x %zu Image. Logging %lu parameters:", CVPixelBufferGetWidth(imageBuffer), CVPixelBufferGetHeight(imageBuffer), (unsigned long)arguments.count);

for (id param in arguments) {
NSLog(@"ExamplePlugin: -> %@ (%@)", param == nil ? @"(nil)" : [param description], NSStringFromClass([param classForCoder]));
}

return @{
@"type": @"objc",
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved
@"example_str": @"Test",
@"example_bool": @true,
@"example_double": @5.3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ExamplePluginSwift: NSObject, FrameProcessorPluginBase {
}

return [
"type": "swift",
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved
"example_str": "Test",
"example_bool": true,
"example_double": 5.3,
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ PODS:
- React-Core
- RNVectorIcons (9.2.0):
- React-Core
- VisionCamera (2.16.0):
- VisionCamera (2.16.3):
- React
- React-callinvoker
- React-Core
Expand Down Expand Up @@ -599,9 +599,9 @@ SPEC CHECKSUMS:
RNScreens: 6a8a3c6b808aa48dca1780df7b73ea524f602c63
RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
VisionCamera: 46a12d82bb9ac6c03b3a54c3530a810496112d96
VisionCamera: 38fb9fae2d3e2fccac46a365e675c045b4e52d0f
Yoga: 39310a10944fc864a7550700de349183450f8aaa

PODFILE CHECKSUM: c9a6f4676a612af372440732ecc8fae75b559be7

COCOAPODS: 1.12.1
COCOAPODS: 1.11.2
7 changes: 5 additions & 2 deletions example/src/CameraPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CaptureButton } from './views/CaptureButton';
import { PressableOpacity } from 'react-native-pressable-opacity';
import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import IonIcon from 'react-native-vector-icons/Ionicons';
import { examplePlugin } from './frame-processors/ExamplePlugin';
import { examplePlugin, examplePluginSwift } from './frame-processors/ExamplePlugin';
import type { Routes } from './Routes';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { useIsFocused } from '@react-navigation/core';
Expand Down Expand Up @@ -200,7 +200,10 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
const frameProcessor = useFrameProcessor((frame) => {
'worklet';
const values = examplePlugin(frame);
console.log(`Return Values: ${JSON.stringify(values)}`);
const valuesSwift = examplePluginSwift(frame);

console.log(`Return OBJC Values: ${JSON.stringify(values)}`);
console.log(`Return Swift Values: ${JSON.stringify(valuesSwift)}`);
iBotPeaches marked this conversation as resolved.
Show resolved Hide resolved
}, []);

const onFrameProcessorSuggestionAvailable = useCallback((suggestion: FrameProcessorPerformanceSuggestion) => {
Expand Down
12 changes: 5 additions & 7 deletions ios/Frame Processor/FrameProcessorPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
#define VISION_EXPORT_FRAME_PROCESSOR(frame_processor) \
\
+(void)initialize \
+(void)load \
Copy link
Owner

Choose a reason for hiding this comment

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

Great!

{ \
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #frame_processor callback:^id(Frame* frame, NSArray<id>* args) { \
return frame_processor(frame, args); \
Expand All @@ -53,13 +53,11 @@ objc_name : NSObject<FrameProcessorPluginBase>
@end \
@implementation objc_name (FrameProcessorPlugin) \
\
+(void)initialize \
__attribute__((constructor)) static void VISION_CONCAT(initialize_, objc_name)() \
Copy link
Owner

Choose a reason for hiding this comment

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

Ahh, yea I forgot about that lol. I dont know why I reverted that

{ \
if (self == [objc_name class]) { \
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) { \
return [objc_name callback:frame withArgs:args]; \
}]; \
} \
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"__" @ #name callback:^id(Frame* frame, NSArray<id>* args) { \
return [objc_name callback:frame withArgs:args]; \
}]; \
}

#endif /* FrameProcessorPlugin_h */
Loading