| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | //  FrameProcessorPluginRegistry.m
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | //  VisionCamera
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 24.03.21.
 | 
					
						
							| 
									
										
										
										
											2021-06-01 13:07:57 +02:00
										 |  |  | //  Copyright © 2021 mrousavy. All rights reserved.
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #import "FrameProcessorPluginRegistry.h"
 | 
					
						
							|  |  |  | #import <Foundation/Foundation.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation FrameProcessorPluginRegistry
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | + (NSMutableDictionary<NSString*, PluginInitializerFunction>*)frameProcessorPlugins {
 | 
					
						
							|  |  |  |   static NSMutableDictionary<NSString*, PluginInitializerFunction>* plugins = nil;
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  |   if (plugins == nil) {
 | 
					
						
							|  |  |  |     plugins = [[NSMutableDictionary alloc] init];
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  |   return plugins;
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  | + (void)addFrameProcessorPlugin:(NSString*)name withInitializer:(PluginInitializerFunction)pluginInitializer {
 | 
					
						
							|  |  |  |   BOOL alreadyExists = [[FrameProcessorPluginRegistry frameProcessorPlugins] valueForKey:name] != nil;
 | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02: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 13:07:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |   [[FrameProcessorPluginRegistry frameProcessorPlugins] setValue:pluginInitializer forKey:name];
 | 
					
						
							| 
									
										
										
										
											2023-10-16 17:51:18 +02:00
										 |  |  |   NSLog(@"Successfully registered Frame Processor Plugin \"%@\"!", name);
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  | + (FrameProcessorPlugin*)getPlugin:(NSString* _Nonnull)name
 | 
					
						
							|  |  |  |                          withProxy:(VisionCameraProxyHolder* _Nonnull)proxy
 | 
					
						
							|  |  |  |                        withOptions:(NSDictionary* _Nullable)options {
 | 
					
						
							| 
									
										
										
										
											2023-10-16 17:51:18 +02:00
										 |  |  |   NSLog(@"Looking up Frame Processor Plugin \"%@\"...", name);
 | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  |   PluginInitializerFunction initializer = [[FrameProcessorPluginRegistry frameProcessorPlugins] objectForKey:name];
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |   if (initializer == nil) {
 | 
					
						
							| 
									
										
										
										
											2023-10-16 17:51:18 +02:00
										 |  |  |     NSLog(@"Frame Processor Plugin \"%@\" does not exist!", name);
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |     return nil;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 17:51:18 +02:00
										 |  |  |   NSLog(@"Frame Processor Plugin \"%@\" found! Initializing...", name);
 | 
					
						
							| 
									
										
										
										
											2024-01-12 16:00:36 +01:00
										 |  |  |   return initializer(proxy, options);
 | 
					
						
							| 
									
										
										
										
											2021-05-06 14:11:55 +02:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @end
 |