feat: Make Frame Processor Plugins object-oriented on iOS as well (#1496)
* feat: Make Frame Processor Plugins object-oriented on iOS as well * Add Plugin in AppDelegate
This commit is contained in:
@@ -11,12 +11,16 @@
|
||||
|
||||
// Example for an Objective-C Frame Processor plugin
|
||||
|
||||
@interface ExampleFrameProcessorPlugin : NSObject
|
||||
@interface ExampleFrameProcessorPlugin : FrameProcessorPlugin
|
||||
@end
|
||||
|
||||
@implementation ExampleFrameProcessorPlugin
|
||||
|
||||
static inline id example_plugin(Frame* frame, NSArray* arguments) {
|
||||
- (NSString *)name {
|
||||
return @"example_plugin";
|
||||
}
|
||||
|
||||
- (id)callback:(Frame *)frame withArguments:(NSArray<id> *)arguments {
|
||||
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer);
|
||||
NSLog(@"ExamplePlugin: %zu x %zu Image. Logging %lu parameters:", CVPixelBufferGetWidth(imageBuffer), CVPixelBufferGetHeight(imageBuffer), (unsigned long)arguments.count);
|
||||
|
||||
@@ -36,6 +40,8 @@ static inline id example_plugin(Frame* frame, NSArray* arguments) {
|
||||
};
|
||||
}
|
||||
|
||||
VISION_EXPORT_FRAME_PROCESSOR(example_plugin)
|
||||
+ (void) load {
|
||||
[self registerPlugin:[[ExampleFrameProcessorPlugin alloc] init]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// ExamplePluginSwift.m
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 01.05.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <VisionCamera/FrameProcessorPlugin.h>
|
||||
|
||||
@interface VISION_EXPORT_SWIFT_FRAME_PROCESSOR(example_plugin_swift, ExamplePluginSwift)
|
||||
@end
|
@@ -9,34 +9,38 @@
|
||||
import AVKit
|
||||
import Vision
|
||||
|
||||
@objc(ExamplePluginSwift)
|
||||
public class ExamplePluginSwift: NSObject, FrameProcessorPluginBase {
|
||||
@objc
|
||||
public static func callback(_ frame: Frame!, withArgs args: [Any]!) -> Any! {
|
||||
guard let imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer) else {
|
||||
return nil
|
||||
}
|
||||
NSLog("ExamplePlugin: \(CVPixelBufferGetWidth(imageBuffer)) x \(CVPixelBufferGetHeight(imageBuffer)) Image. Logging \(args.count) parameters:")
|
||||
@objc
|
||||
public class ExamplePluginSwift : FrameProcessorPlugin {
|
||||
|
||||
override public func name() -> String! {
|
||||
return "example_plugin_swift"
|
||||
}
|
||||
|
||||
public override func callback(_ frame: Frame!, withArguments arguments: [Any]!) -> Any! {
|
||||
guard let imageBuffer = CMSampleBufferGetImageBuffer(frame.buffer) else {
|
||||
return nil
|
||||
}
|
||||
NSLog("ExamplePlugin: \(CVPixelBufferGetWidth(imageBuffer)) x \(CVPixelBufferGetHeight(imageBuffer)) Image. Logging \(arguments.count) parameters:")
|
||||
|
||||
args.forEach { arg in
|
||||
var string = "\(arg)"
|
||||
if let array = arg as? NSArray {
|
||||
string = (array as Array).description
|
||||
} else if let map = arg as? NSDictionary {
|
||||
string = (map as Dictionary).description
|
||||
}
|
||||
NSLog("ExamplePlugin: -> \(string) (\(type(of: arg)))")
|
||||
}
|
||||
arguments.forEach { arg in
|
||||
var string = "\(arg)"
|
||||
if let array = arg as? NSArray {
|
||||
string = (array as Array).description
|
||||
} else if let map = arg as? NSDictionary {
|
||||
string = (map as Dictionary).description
|
||||
}
|
||||
NSLog("ExamplePlugin: -> \(string) (\(type(of: arg)))")
|
||||
}
|
||||
|
||||
return [
|
||||
"example_str": "Test",
|
||||
"example_bool": true,
|
||||
"example_double": 5.3,
|
||||
"example_array": [
|
||||
"Hello",
|
||||
true,
|
||||
17.38,
|
||||
],
|
||||
]
|
||||
}
|
||||
return [
|
||||
"example_str": "Test",
|
||||
"example_bool": true,
|
||||
"example_double": 5.3,
|
||||
"example_array": [
|
||||
"Hello",
|
||||
true,
|
||||
17.38,
|
||||
],
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@@ -436,7 +436,7 @@ PODS:
|
||||
- React-Core
|
||||
- RNVectorIcons (9.2.0):
|
||||
- React-Core
|
||||
- VisionCamera (3.0.0-rc.1):
|
||||
- VisionCamera (3.0.0-rc.2):
|
||||
- React
|
||||
- React-callinvoker
|
||||
- React-Core
|
||||
@@ -644,7 +644,7 @@ SPEC CHECKSUMS:
|
||||
RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f
|
||||
RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8
|
||||
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
|
||||
VisionCamera: 0d154cd0ab9043a3c8a4908fb57ad65c9e1f3baf
|
||||
VisionCamera: e4f19a6c22cfa146736bdfe8df057e2ed5ca8dd3
|
||||
Yoga: 5ed1699acbba8863755998a4245daa200ff3817b
|
||||
|
||||
PODFILE CHECKSUM: d53724fe402c2547f1dd1cc571bbe77d9820e636
|
||||
|
@@ -11,10 +11,9 @@
|
||||
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
|
||||
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
|
||||
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
|
||||
B8DB3BD5263DE8B7004C18D7 /* BuildFile in Sources */ = {isa = PBXBuildFile; };
|
||||
B8DB3BD5263DE8B7004C18D7 /* (null) in Sources */ = {isa = PBXBuildFile; };
|
||||
B8DB3BDC263DEA31004C18D7 /* ExampleFrameProcessorPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = B8DB3BD8263DEA31004C18D7 /* ExampleFrameProcessorPlugin.m */; };
|
||||
B8DB3BDD263DEA31004C18D7 /* ExamplePluginSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DB3BDA263DEA31004C18D7 /* ExamplePluginSwift.swift */; };
|
||||
B8DB3BDE263DEA31004C18D7 /* ExamplePluginSwift.m in Sources */ = {isa = PBXBuildFile; fileRef = B8DB3BDB263DEA31004C18D7 /* ExamplePluginSwift.m */; };
|
||||
B8F0E10825E0199F00586F16 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8F0E10725E0199F00586F16 /* File.swift */; };
|
||||
C0B129659921D2EA967280B2 /* libPods-VisionCameraExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CDCFE89C25C89320B98945E /* libPods-VisionCameraExample.a */; };
|
||||
/* End PBXBuildFile section */
|
||||
@@ -31,7 +30,6 @@
|
||||
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = VisionCameraExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
B8DB3BD8263DEA31004C18D7 /* ExampleFrameProcessorPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleFrameProcessorPlugin.m; sourceTree = "<group>"; };
|
||||
B8DB3BDA263DEA31004C18D7 /* ExamplePluginSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExamplePluginSwift.swift; sourceTree = "<group>"; };
|
||||
B8DB3BDB263DEA31004C18D7 /* ExamplePluginSwift.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExamplePluginSwift.m; sourceTree = "<group>"; };
|
||||
B8F0E10625E0199F00586F16 /* VisionCameraExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VisionCameraExample-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
B8F0E10725E0199F00586F16 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
|
||||
C1D342AD8210E7627A632602 /* Pods-VisionCameraExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VisionCameraExample.debug.xcconfig"; path = "Target Support Files/Pods-VisionCameraExample/Pods-VisionCameraExample.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
@@ -138,7 +136,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B8DB3BDA263DEA31004C18D7 /* ExamplePluginSwift.swift */,
|
||||
B8DB3BDB263DEA31004C18D7 /* ExamplePluginSwift.m */,
|
||||
);
|
||||
path = "Example Plugin (Swift)";
|
||||
sourceTree = "<group>";
|
||||
@@ -383,11 +380,10 @@
|
||||
files = (
|
||||
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
|
||||
B8DB3BDC263DEA31004C18D7 /* ExampleFrameProcessorPlugin.m in Sources */,
|
||||
B8DB3BD5263DE8B7004C18D7 /* BuildFile in Sources */,
|
||||
B8DB3BD5263DE8B7004C18D7 /* (null) in Sources */,
|
||||
B8DB3BDD263DEA31004C18D7 /* ExamplePluginSwift.swift in Sources */,
|
||||
B8F0E10825E0199F00586F16 /* File.swift in Sources */,
|
||||
13B07FC11A68108700A75B9A /* main.m in Sources */,
|
||||
B8DB3BDE263DEA31004C18D7 /* ExamplePluginSwift.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import <React/RCTBundleURLProvider.h>
|
||||
#import "VisionCameraExample-Swift.h"
|
||||
#import <VisionCamera/FrameProcessorPlugin.h>
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
@@ -10,6 +12,8 @@
|
||||
// You can add your custom initial props in the dictionary below.
|
||||
// They will be passed down to the ViewController used by React Native.
|
||||
self.initialProps = @{};
|
||||
|
||||
[FrameProcessorPlugin registerPlugin:[[ExamplePluginSwift alloc] init]];
|
||||
|
||||
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
}
|
||||
|
Reference in New Issue
Block a user