Added iOS task runner
This commit is contained in:
parent
64cf5e9b4e
commit
e9fc3713f0
47
mediapipe/tasks/ios/core/sources/MPPTaskRunner.h
Normal file
47
mediapipe/tasks/ios/core/sources/MPPTaskRunner.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2022 The MediaPipe Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/tasks/cc/core/task_runner.h"
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* This class is used to create and call appropriate methods on the C++ Task Runner.
|
||||
*/
|
||||
@interface MPPTaskRunner : NSObject
|
||||
/**
|
||||
* Initializes a new `MPPTaskRunner` with the mediapipe task graph config proto.
|
||||
*
|
||||
* @param graphConfig A mediapipe task graph config proto.
|
||||
*
|
||||
* @return An instance of `MPPTaskRunner` initialized to the given graph config proto.
|
||||
*/
|
||||
- (instancetype)initWithCalculatorGraphConfig:(mediapipe::CalculatorGraphConfig)graphConfig
|
||||
error:(NSError **)error;
|
||||
|
||||
- (absl::StatusOr<mediapipe::tasks::core::PacketMap>)process:(const mediapipe::tasks::core::PacketMap&)packetMap error:(NSError **)error;
|
||||
|
||||
- (void)close;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
56
mediapipe/tasks/ios/core/sources/MPPTaskRunner.mm
Normal file
56
mediapipe/tasks/ios/core/sources/MPPTaskRunner.mm
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2022 The MediaPipe Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import "mediapipe/tasks/ios/core/sources/MPPTaskRunner.h"
|
||||
#import "mediapipe/tasks/ios/common/utils/sources/MPPCommonUtils.h"
|
||||
|
||||
namespace {
|
||||
using ::mediapipe::CalculatorGraphConfig;
|
||||
using ::mediapipe::Packet;
|
||||
using ::mediapipe::tasks::core::PacketMap;
|
||||
using TaskRunnerCpp = ::mediapipe::tasks::core::TaskRunner;
|
||||
} // namespace
|
||||
|
||||
@interface MPPTaskRunner () {
|
||||
// Cpp Task Runner
|
||||
std::unique_ptr<TaskRunnerCpp> _cppTaskRunner;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MPPTaskRunner
|
||||
|
||||
- (instancetype)initWithCalculatorGraphConfig:(CalculatorGraphConfig)graphConfig
|
||||
error:(NSError **)error {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
auto taskRunnerResult = TaskRunnerCpp::Create(std::move(graphConfig));
|
||||
|
||||
if (![MPPCommonUtils checkCppError:taskRunnerResult.status() toError:error]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_cppTaskRunner = std::move(taskRunnerResult.value());
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (absl::StatusOr<PacketMap>)process:(const PacketMap&)packetMap {
|
||||
return _cppTaskRunner->Process(packetMap);
|
||||
}
|
||||
|
||||
- (void)close {
|
||||
_cppTaskRunner->Close();
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue
Block a user