Updated comments of MPPCommonUtils

This commit is contained in:
Prianka Liz Kariat 2023-01-13 21:18:01 +05:30
parent 2a53d78ae4
commit c4c07acc1e

View File

@ -26,7 +26,7 @@
NSString *const MPPTasksErrorDomain = @"com.google.mediapipe.tasks"; NSString *const MPPTasksErrorDomain = @"com.google.mediapipe.tasks";
namespace { namespace {
using absl::StatusCode; using absl::StatusCode;
} }
@implementation MPPCommonUtils @implementation MPPCommonUtils
@ -72,42 +72,17 @@ namespace {
return YES; return YES;
} }
// Creates the NSEror with the appropriate error /** Converts the absl status message to an NSString. */
// MPPTasksErrorCode and message. MPPTasksErrorCode has a one to one
// mapping with MediaPipeTasksStatus starting from the value 1(MPPTasksErrorCodeError)
// and hence will be correctly initialized if directly cast from the integer code derived from
// MediaPipeTasksStatus stored in its payload. MPPTasksErrorCode omits kOk = 0 of
// MediaPipeTasksStatusx.
//
// Stores a string including absl status code and message(if non empty) as the
// error message See
// https://github.com/abseil/abseil-cpp/blob/master/absl/status/status.h#L514
// for explanation. absl::Status::message() can also be used but not always
// guaranteed to be non empty.
NSString *description = [NSString NSString *description = [NSString
stringWithCString:status.ToString(absl::StatusToStringMode::kWithNoExtraData).c_str() stringWithCString:status.ToString(absl::StatusToStringMode::kWithNoExtraData).c_str()
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
// Payload of absl::Status created by the MediaPipe task library stores an appropriate value of
// the enum MediaPipeTasksStatus. The integer value corresponding to the MediaPipeTasksStatus enum
// stored in the payload is extracted here to later map to the appropriate error code to be
// returned. In cases where the enum is not stored in (payload is NULL or the payload string
// cannot be converted to an integer), we set the error code value to be 1
// (MPPTasksErrorCodeError of MPPTasksErrorCode used in the iOS library to signify
// any errors not falling into other categories.) Since payload is of type absl::Cord that can be
// type cast into an absl::optional<std::string>, we use the std::stoi function to convert it into
// an integer code if possible.
MPPTasksErrorCode genericErrorCode = MPPTasksErrorCodeUnknownError; MPPTasksErrorCode genericErrorCode = MPPTasksErrorCodeUnknownError;
MPPTasksErrorCode errorCode = genericErrorCode; MPPTasksErrorCode errorCode = genericErrorCode;
// If errorCode is outside the range of enum values possible or is /** Maps the absl::StatusCode to the appropriate MPPTasksErrorCode. Note: MPPTasksErrorCode omits
// MPPTasksErrorCodeError, we try to map the absl::Status::code() to assign * absl::StatusCode::kOk. */
// appropriate MPPTasksErrorCode in default cases. Note:
// 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
// MPPTasksErrorCode. This can happen when absl::Status returned by TFLite library are in turn
// returned without modification by MediaPipe cc library methods.
switch (status.code()) { switch (status.code()) {
case StatusCode::kCancelled: case StatusCode::kCancelled:
errorCode = MPPTasksErrorCodeCancelledError; errorCode = MPPTasksErrorCodeCancelledError;