Updated formatting

This commit is contained in:
Prianka Liz Kariat 2023-05-04 01:02:27 +05:30
parent 4558486459
commit 4401b11c3a
2 changed files with 20 additions and 18 deletions

View File

@ -90,8 +90,11 @@ static NSString *const kTaskName = @"imageClassifier";
// Capturing `self` as weak in order to avoid `self` being kept in memory // Capturing `self` as weak in order to avoid `self` being kept in memory
// and cause a retain cycle, after self is set to `nil`. // and cause a retain cycle, after self is set to `nil`.
MPPImageClassifier *__weak weakSelf = self; MPPImageClassifier *__weak weakSelf = self;
// Create a private serial dispatch queue in which the deleagte method will be called asynchronously. This is to ensure that if the client performs a long running operation in the delegate method, the queue on which the C++ callbacks is invoked is not blocked and is freed up to continue with its operations. // Create a private serial dispatch queue in which the deleagte method will be called
// asynchronously. This is to ensure that if the client performs a long running operation in
// the delegate method, the queue on which the C++ callbacks is invoked is not blocked and is
// freed up to continue with its operations.
const char *queueName = [MPPVisionTaskRunner uniqueQueueNameWithTaskName:kTaskName]; const char *queueName = [MPPVisionTaskRunner uniqueQueueNameWithTaskName:kTaskName];
dispatch_queue_t callbackQueue = dispatch_queue_create(queueName, NULL); dispatch_queue_t callbackQueue = dispatch_queue_create(queueName, NULL);
packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) { packetsCallback = [=](absl::StatusOr<PacketMap> status_or_packets) {
@ -108,10 +111,10 @@ static NSString *const kTaskName = @"imageClassifier";
NSError *callbackError = nil; NSError *callbackError = nil;
if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) { if (![MPPCommonUtils checkCppError:status_or_packets.status() toError:&callbackError]) {
dispatch_async(callbackQueue, ^{ dispatch_async(callbackQueue, ^{
[weakSelf.imageClassifierDelegate imageClassifier:weakSelf [weakSelf.imageClassifierDelegate imageClassifier:weakSelf
didFinishClassificationWithResult:nil didFinishClassificationWithResult:nil
timestampInMilliseconds:Timestamp::Unset().Value() timestampInMilliseconds:Timestamp::Unset().Value()
error:callbackError]; error:callbackError];
}); });
return; return;
} }
@ -123,17 +126,16 @@ static NSString *const kTaskName = @"imageClassifier";
MPPImageClassifierResult *result = MPPImageClassifierResult *result =
[MPPImageClassifierResult imageClassifierResultWithClassificationsPacket: [MPPImageClassifierResult imageClassifierResultWithClassificationsPacket:
outputPacketMap[kClassificationsStreamName.cppString]]; outputPacketMap[kClassificationsStreamName.cppString]];
NSInteger timeStampInMilliseconds = outputPacketMap[kImageOutStreamName.cppString] NSInteger timeStampInMilliseconds =
.Timestamp() outputPacketMap[kImageOutStreamName.cppString].Timestamp().Value() /
.Value() / kMicroSecondsPerMilliSecond;
kMicroSecondsPerMilliSecond;
dispatch_async(callbackQueue, ^{ dispatch_async(callbackQueue, ^{
[weakSelf.imageClassifierDelegate imageClassifier:weakSelf [weakSelf.imageClassifierDelegate imageClassifier:weakSelf
didFinishClassificationWithResult:result didFinishClassificationWithResult:result
timestampInMilliseconds:timeStampInMilliseconds timestampInMilliseconds:timeStampInMilliseconds
error:callbackError]; error:callbackError];
}); });
}; };
} }

View File

@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* This protocol defines an interface for the delegates of `MPPImageClassifier` object to receive * This protocol defines an interface for the delegates of `MPPImageClassifier` object to receive
* results of asynchronous classification of images * results of asynchronous classification of images
* (i.e, when `runningMode = MPPRunningModeLiveStream`). * (i.e, when `runningMode = MPPRunningModeLiveStream`).
* *
* The delegate of `MPPImageClassifier` must adopt `MPPImageClassifierDelegate` protocol. * The delegate of `MPPImageClassifier` must adopt `MPPImageClassifierDelegate` protocol.
@ -37,12 +37,12 @@ NS_SWIFT_NAME(ImageClassifierDelegate)
/** /**
* This method notifies a delegate that the results of asynchronous classification of * This method notifies a delegate that the results of asynchronous classification of
* an image submitted to the `MPPImageClassifier` is available. * an image submitted to the `MPPImageClassifier` is available.
* *
* This method is called on a private serial queue created by the `MPPImageClassifier` * This method is called on a private serial queue created by the `MPPImageClassifier`
* for performing the asynchronous delegates calls. * for performing the asynchronous delegates calls.
* *
* @param imageClassifier The image classifier which performed the classification. * @param imageClassifier The image classifier which performed the classification.
* This is useful to test equality when there are multiple instances of `MPPImageClassifier`. * This is useful to test equality when there are multiple instances of `MPPImageClassifier`.
* @param result An `MPPImageClassifierResult` object that contains a list of image classifications. * @param result An `MPPImageClassifierResult` object that contains a list of image classifications.
* @param timestampInMilliseconds The timestamp (in milliseconds) which indicates when the input * @param timestampInMilliseconds The timestamp (in milliseconds) which indicates when the input
* image was sent to the image classifier. * image was sent to the image classifier.