Added method to create unique dispatch queue names in MPPVisionTaskRunner
This commit is contained in:
parent
c6e3f08282
commit
1323a5271c
|
@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (NSString *)stringWithCppString:(std::string)text;
|
||||
|
||||
+ (NSString *)uuidString;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -24,4 +24,8 @@
|
|||
return [NSString stringWithCString:text.c_str() encoding:[NSString defaultCStringEncoding]];
|
||||
}
|
||||
|
||||
+ (NSString *)uuidString{
|
||||
return [[NSUUID UUID] UUIDString];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -58,6 +58,7 @@ objc_library(
|
|||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/tasks/ios/common:MPPCommon",
|
||||
"//mediapipe/tasks/ios/common/utils:MPPCommonUtils",
|
||||
"//mediapipe/tasks/ios/common/utils:NSStringHelpers",
|
||||
"//mediapipe/tasks/ios/core:MPPTaskRunner",
|
||||
"//third_party/apple_frameworks:UIKit",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
|
|
|
@ -141,6 +141,20 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
(mediapipe::tasks::core::PacketsCallback)packetsCallback
|
||||
error:(NSError **)error NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* This method returns a unique dispatch queue name by adding the given suffix and a `UUID` to the
|
||||
* pre-defined queue name prefix for vision tasks. The vision tasks can use this method to get
|
||||
* unique dispatch queue names which are consistent with other vision tasks.
|
||||
* Dispatch queue names need not be unique, but for easy debugging we ensure that the queue names
|
||||
* are unique.
|
||||
*
|
||||
* @param suffix A suffix that identifies a dispatch queue's functionality.
|
||||
*
|
||||
* @return A unique dispatch queue name by adding the given suffix and a `UUID` to the pre-defined
|
||||
* queue name prefix for vision tasks.
|
||||
*/
|
||||
+ (const char *)uniqueDispatchQueueNameWithSuffix:(NSString *)suffix;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#import "mediapipe/tasks/ios/common/sources/MPPCommon.h"
|
||||
#import "mediapipe/tasks/ios/common/utils/sources/MPPCommonUtils.h"
|
||||
#import "mediapipe/tasks/ios/common/utils/sources/NSString+Helpers.h"
|
||||
|
||||
#include "absl/status/statusor.h"
|
||||
|
||||
|
@ -37,6 +38,8 @@ static const NSInteger kMPPOrientationDegreesDown = -180;
|
|||
/** Rotation degrees for a 90 degree rotation to the left. */
|
||||
static const NSInteger kMPPOrientationDegreesLeft = -270;
|
||||
|
||||
static NSString *const kTaskPrefix = @"com.mediapipe.tasks.vision";
|
||||
|
||||
@interface MPPVisionTaskRunner () {
|
||||
MPPRunningMode _runningMode;
|
||||
}
|
||||
|
@ -54,18 +57,21 @@ static const NSInteger kMPPOrientationDegreesLeft = -270;
|
|||
if (packetsCallback) {
|
||||
[MPPCommonUtils createCustomError:error
|
||||
withCode:MPPTasksErrorCodeInvalidArgumentError
|
||||
description:@"The vision task is in image or video mode, a "
|
||||
@"user-defined result callback should not be provided."];
|
||||
description:@"The vision task is in image or video mode. The "
|
||||
@"delegate must not be set in the task's options."];
|
||||
return nil;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MPPRunningModeLiveStream: {
|
||||
if (!packetsCallback) {
|
||||
[MPPCommonUtils createCustomError:error
|
||||
[MPPCommonUtils
|
||||
createCustomError:error
|
||||
withCode:MPPTasksErrorCodeInvalidArgumentError
|
||||
description:@"The vision task is in live stream mode, a user-defined "
|
||||
@"result callback must be provided."];
|
||||
description:
|
||||
@"The vision task is in live stream mode. An object must be set as the "
|
||||
@"delegate of the task in its options to ensure asynchronous delivery of "
|
||||
@"results."];
|
||||
return nil;
|
||||
}
|
||||
break;
|
||||
|
@ -197,4 +203,9 @@ static const NSInteger kMPPOrientationDegreesLeft = -270;
|
|||
return [self sendPacketMap:packetMap error:error];
|
||||
}
|
||||
|
||||
+ (const char *)uniqueDispatchQueueNameWithSuffix:(NSString *)suffix {
|
||||
return [NSString stringWithFormat:@"%@.%@_%@", kTaskPrefix, suffix, [NSString uuidString]]
|
||||
.UTF8String;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue
Block a user