2021-05-06 06:11:55 -06:00
|
|
|
//
|
2023-07-21 09:52:30 -06:00
|
|
|
// FrameProcessorPluginRegistry.m
|
2021-05-06 06:11:55 -06:00
|
|
|
// VisionCamera
|
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 24.03.21.
|
2021-06-01 05:07:57 -06:00
|
|
|
// Copyright © 2021 mrousavy. All rights reserved.
|
2021-05-06 06:11:55 -06:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "FrameProcessorPluginRegistry.h"
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
@implementation FrameProcessorPluginRegistry
|
|
|
|
|
2023-07-21 09:52:30 -06:00
|
|
|
+ (NSMutableDictionary<NSString*, PluginInitializerFunction>*)frameProcessorPlugins {
|
|
|
|
static NSMutableDictionary<NSString*, PluginInitializerFunction>* plugins = nil;
|
2021-05-06 06:11:55 -06:00
|
|
|
if (plugins == nil) {
|
|
|
|
plugins = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
return plugins;
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:39:25 -06:00
|
|
|
+ (void)addFrameProcessorPlugin:(NSString*)name withInitializer:(PluginInitializerFunction)pluginInitializer {
|
|
|
|
BOOL alreadyExists = [[FrameProcessorPluginRegistry frameProcessorPlugins] valueForKey:name] != nil;
|
2023-09-01 04:58:32 -06:00
|
|
|
NSAssert(!alreadyExists,
|
|
|
|
@"Tried to add a Frame Processor Plugin with a name that already exists! Either choose "
|
|
|
|
@"unique names, or "
|
|
|
|
@"remove the unused plugin. Name: %@",
|
|
|
|
name);
|
2021-06-01 05:07:57 -06:00
|
|
|
|
2023-07-21 09:52:30 -06:00
|
|
|
[[FrameProcessorPluginRegistry frameProcessorPlugins] setValue:pluginInitializer forKey:name];
|
2023-10-16 09:51:18 -06:00
|
|
|
NSLog(@"Successfully registered Frame Processor Plugin \"%@\"!", name);
|
2023-07-21 09:52:30 -06:00
|
|
|
}
|
|
|
|
|
2023-09-01 11:39:25 -06:00
|
|
|
+ (FrameProcessorPlugin*)getPlugin:(NSString* _Nonnull)name withOptions:(NSDictionary* _Nullable)options {
|
2023-10-16 09:51:18 -06:00
|
|
|
NSLog(@"Looking up Frame Processor Plugin \"%@\"...", name);
|
2023-09-01 11:39:25 -06:00
|
|
|
PluginInitializerFunction initializer = [[FrameProcessorPluginRegistry frameProcessorPlugins] objectForKey:name];
|
2023-07-21 09:52:30 -06:00
|
|
|
if (initializer == nil) {
|
2023-10-16 09:51:18 -06:00
|
|
|
NSLog(@"Frame Processor Plugin \"%@\" does not exist!", name);
|
2023-07-21 09:52:30 -06:00
|
|
|
return nil;
|
|
|
|
}
|
2023-09-01 04:58:32 -06:00
|
|
|
|
2023-10-16 09:51:18 -06:00
|
|
|
NSLog(@"Frame Processor Plugin \"%@\" found! Initializing...", name);
|
2023-07-21 09:52:30 -06:00
|
|
|
return initializer(options);
|
2021-05-06 06:11:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|