Merge pull request #3974 from priankakariatyml:ios-task-updates
PiperOrigin-RevId: 500323180
This commit is contained in:
		
						commit
						e11ba95adf
					
				|  | @ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * @enum MPPTasksErrorCode |  * @enum MPPTasksErrorCode | ||||||
|  * This enum specifies  error codes for Mediapipe Task Library. |  * This enum specifies  error codes for MediaPipe Task Library. | ||||||
|  * It maintains a 1:1 mapping to MediaPipeTasksStatus of the C ++libray. |  * It maintains a 1:1 mapping to MediaPipeTasksStatus of the C ++libray. | ||||||
|  */ |  */ | ||||||
| typedef NS_ENUM(NSUInteger, MPPTasksErrorCode) { | typedef NS_ENUM(NSUInteger, MPPTasksErrorCode) { | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ | ||||||
| 
 | 
 | ||||||
| NS_ASSUME_NONNULL_BEGIN | NS_ASSUME_NONNULL_BEGIN | ||||||
| 
 | 
 | ||||||
| /** Error domain of Mediapipe Task related errors. */ | /** Error domain of MediaPipe Task related errors. */ | ||||||
| extern NSString *const MPPTasksErrorDomain; | extern NSString *const MPPTasksErrorDomain; | ||||||
| 
 | 
 | ||||||
| /** Helper utility for the all tasks which encapsulates common functionality. */ | /** Helper utility for the all tasks which encapsulates common functionality. */ | ||||||
|  |  | ||||||
|  | @ -96,7 +96,7 @@ NSString *const MPPTasksErrorDomain = @"com.google.mediapipe.tasks"; | ||||||
|   // The mapping to absl::Status::code() is done to generate a more specific error code than |   // The mapping to absl::Status::code() is done to generate a more specific error code than | ||||||
|   // MPPTasksErrorCodeError in cases when the payload can't be mapped to |   // MPPTasksErrorCodeError in cases when the payload can't be mapped to | ||||||
|   // MPPTasksErrorCode. This can happen when absl::Status returned by TFLite library are in turn |   // MPPTasksErrorCode. This can happen when absl::Status returned by TFLite library are in turn | ||||||
|   // returned without modification by Mediapipe cc library methods. |   // returned without modification by MediaPipe cc library methods. | ||||||
|   if (errorCode > MPPTasksErrorCodeLast || errorCode <= MPPTasksErrorCodeFirst) { |   if (errorCode > MPPTasksErrorCodeLast || errorCode <= MPPTasksErrorCodeFirst) { | ||||||
|     switch (status.code()) { |     switch (status.code()) { | ||||||
|       case absl::StatusCode::kInternal: |       case absl::StatusCode::kInternal: | ||||||
|  |  | ||||||
|  | @ -69,59 +69,59 @@ using ::mediapipe::InputStreamInfo; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| - (CalculatorGraphConfig)generateGraphConfig { | - (CalculatorGraphConfig)generateGraphConfig { | ||||||
|   CalculatorGraphConfig graph_config; |   CalculatorGraphConfig graphConfig; | ||||||
| 
 | 
 | ||||||
|   Node *task_subgraph_node = graph_config.add_node(); |   Node *taskSubgraphNode = graphConfig.add_node(); | ||||||
|   task_subgraph_node->set_calculator(self.taskGraphName.cppString); |   taskSubgraphNode->set_calculator(self.taskGraphName.cppString); | ||||||
|   [self.taskOptions copyToProto:task_subgraph_node->mutable_options()]; |   [self.taskOptions copyToProto:taskSubgraphNode->mutable_options()]; | ||||||
| 
 | 
 | ||||||
|   for (NSString *outputStream in self.outputStreams) { |   for (NSString *outputStream in self.outputStreams) { | ||||||
|     auto cpp_output_stream = std::string(outputStream.cppString); |     auto cppOutputStream = std::string(outputStream.cppString); | ||||||
|     task_subgraph_node->add_output_stream(cpp_output_stream); |     taskSubgraphNode->add_output_stream(cppOutputStream); | ||||||
|     graph_config.add_output_stream(cpp_output_stream); |     graphConfig.add_output_stream(cppOutputStream); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (!self.enableFlowLimiting) { |   if (!self.enableFlowLimiting) { | ||||||
|     for (NSString *inputStream in self.inputStreams) { |     for (NSString *inputStream in self.inputStreams) { | ||||||
|       auto cpp_input_stream = inputStream.cppString; |       auto cppInputStream = inputStream.cppString; | ||||||
|       task_subgraph_node->add_input_stream(cpp_input_stream); |       taskSubgraphNode->add_input_stream(cppInputStream); | ||||||
|       graph_config.add_input_stream(cpp_input_stream); |       graphConfig.add_input_stream(cppInputStream); | ||||||
|     } |     } | ||||||
|     return graph_config; |     return graphConfig; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Node *flow_limit_calculator_node = graph_config.add_node(); |   Node *flowLimitCalculatorNode = graphConfig.add_node(); | ||||||
| 
 | 
 | ||||||
|   flow_limit_calculator_node->set_calculator("FlowLimiterCalculator"); |   flowLimitCalculatorNode->set_calculator("FlowLimiterCalculator"); | ||||||
| 
 | 
 | ||||||
|   InputStreamInfo *input_stream_info = flow_limit_calculator_node->add_input_stream_info(); |   InputStreamInfo *inputStreamInfo = flowLimitCalculatorNode->add_input_stream_info(); | ||||||
|   input_stream_info->set_tag_index("FINISHED"); |   inputStreamInfo->set_tag_index("FINISHED"); | ||||||
|   input_stream_info->set_back_edge(true); |   inputStreamInfo->set_back_edge(true); | ||||||
| 
 | 
 | ||||||
|   FlowLimiterCalculatorOptions *flow_limit_calculator_options = |   FlowLimiterCalculatorOptions *flowLimitCalculatorOptions = | ||||||
|       flow_limit_calculator_node->mutable_options()->MutableExtension( |       flowLimitCalculatorNode->mutable_options()->MutableExtension( | ||||||
|           FlowLimiterCalculatorOptions::ext); |           FlowLimiterCalculatorOptions::ext); | ||||||
|   flow_limit_calculator_options->set_max_in_flight(1); |   flowLimitCalculatorOptions->set_max_in_flight(1); | ||||||
|   flow_limit_calculator_options->set_max_in_queue(1); |   flowLimitCalculatorOptions->set_max_in_queue(1); | ||||||
| 
 | 
 | ||||||
|   for (NSString *inputStream in self.inputStreams) { |   for (NSString *inputStream in self.inputStreams) { | ||||||
|     graph_config.add_input_stream(inputStream.cppString); |     graphConfig.add_input_stream(inputStream.cppString); | ||||||
| 
 | 
 | ||||||
|     NSString *strippedInputStream = [MPPTaskInfo stripTagIndex:inputStream]; |     NSString *strippedInputStream = [MPPTaskInfo stripTagIndex:inputStream]; | ||||||
|     flow_limit_calculator_node->add_input_stream(strippedInputStream.cppString); |     flowLimitCalculatorNode->add_input_stream(strippedInputStream.cppString); | ||||||
| 
 | 
 | ||||||
|     NSString *taskInputStream = [MPPTaskInfo addStreamNamePrefix:inputStream]; |     NSString *taskInputStream = [MPPTaskInfo addStreamNamePrefix:inputStream]; | ||||||
|     task_subgraph_node->add_input_stream(taskInputStream.cppString); |     taskSubgraphNode->add_input_stream(taskInputStream.cppString); | ||||||
| 
 | 
 | ||||||
|     NSString *strippedTaskInputStream = [MPPTaskInfo stripTagIndex:taskInputStream]; |     NSString *strippedTaskInputStream = [MPPTaskInfo stripTagIndex:taskInputStream]; | ||||||
|     flow_limit_calculator_node->add_output_stream(strippedTaskInputStream.cppString); |     flowLimitCalculatorNode->add_output_stream(strippedTaskInputStream.cppString); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   NSString *firstOutputStream = self.outputStreams[0]; |   NSString *firstOutputStream = self.outputStreams[0]; | ||||||
|   auto finished_output_stream = "FINISHED:" + firstOutputStream.cppString; |   auto finishedOutputStream = "FINISHED:" + firstOutputStream.cppString; | ||||||
|   flow_limit_calculator_node->add_input_stream(finished_output_stream); |   flowLimitCalculatorNode->add_input_stream(finishedOutputStream); | ||||||
| 
 | 
 | ||||||
|   return graph_config; |   return graphConfig; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| + (NSString *)stripTagIndex:(NSString *)tagIndexName { | + (NSString *)stripTagIndex:(NSString *)tagIndexName { | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ NS_SWIFT_NAME(TaskOptions) | ||||||
| 
 | 
 | ||||||
| @interface MPPTaskOptions : NSObject <NSCopying> | @interface MPPTaskOptions : NSObject <NSCopying> | ||||||
| /**
 | /**
 | ||||||
|  * Base options for configuring the Mediapipe task. |  * Base options for configuring the MediaPipe task. | ||||||
|  */ |  */ | ||||||
| @property(nonatomic, copy) MPPBaseOptions *baseOptions; | @property(nonatomic, copy) MPPBaseOptions *baseOptions; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -26,11 +26,11 @@ NS_SWIFT_NAME(TaskResult) | ||||||
| /**
 | /**
 | ||||||
|  * Timestamp that is associated with the task result object. |  * Timestamp that is associated with the task result object. | ||||||
|  */ |  */ | ||||||
| @property(nonatomic, assign, readonly) long timestamp; | @property(nonatomic, assign, readonly) NSInteger timestampMs; | ||||||
| 
 | 
 | ||||||
| - (instancetype)init NS_UNAVAILABLE; | - (instancetype)init NS_UNAVAILABLE; | ||||||
| 
 | 
 | ||||||
| - (instancetype)initWithTimestamp:(long)timestamp NS_DESIGNATED_INITIALIZER; | - (instancetype)initWithTimestampMs:(NSInteger)timestampMs NS_DESIGNATED_INITIALIZER; | ||||||
| 
 | 
 | ||||||
| @end | @end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,16 +16,16 @@ | ||||||
| 
 | 
 | ||||||
| @implementation MPPTaskResult | @implementation MPPTaskResult | ||||||
| 
 | 
 | ||||||
| - (instancetype)initWithTimestamp:(long)timestamp { | - (instancetype)initWithTimestampMs:(NSInteger)timestampMs { | ||||||
|   self = [super init]; |   self = [super init]; | ||||||
|   if (self) { |   if (self) { | ||||||
|     _timestamp = timestamp; |     _timestampMs = timestampMs; | ||||||
|   } |   } | ||||||
|   return self; |   return self; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| - (id)copyWithZone:(NSZone *)zone { | - (id)copyWithZone:(NSZone *)zone { | ||||||
|   return [[MPPTaskResult alloc] initWithTimestamp:self.timestamp]; |   return [[MPPTaskResult alloc] initWithTimestampMs:self.timestampMs]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @end | @end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user