Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599352853
  • Loading branch information
MediaPipe Team authored and copybara-github committed Jan 18, 2024
1 parent 4369555 commit 849cde7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
13 changes: 2 additions & 11 deletions mediapipe/tasks/cc/core/task_api_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class TaskApiFactory {
std::unique_ptr<tflite::OpResolver> resolver,
PacketsCallback packets_callback = nullptr,
std::shared_ptr<Executor> default_executor = nullptr,
std::optional<PacketMap> input_side_packets = std::nullopt,
std::optional<ErrorFn> error_fn = std::nullopt) {
std::optional<PacketMap> input_side_packets = std::nullopt) {
bool found_task_subgraph = false;
// This for-loop ensures there's only one subgraph besides
// FlowLimiterCalculator.
Expand All @@ -78,18 +77,10 @@ class TaskApiFactory {
}
MP_ASSIGN_OR_RETURN(
auto runner,
#if !MEDIAPIPE_DISABLE_GPU
core::TaskRunner::Create(std::move(graph_config), std::move(resolver),
std::move(packets_callback),
std::move(default_executor),
std::move(input_side_packets),
/*resources=*/nullptr, std::move(error_fn)));
#else
core::TaskRunner::Create(
std::move(graph_config), std::move(resolver),
std::move(packets_callback), std::move(default_executor),
std::move(input_side_packets), std::move(error_fn)));
#endif
std::move(input_side_packets)));
return std::make_unique<T>(std::move(runner));
}

Expand Down
15 changes: 4 additions & 11 deletions mediapipe/tasks/cc/core/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ limitations under the License.
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
#include "mediapipe/framework/calculator.pb.h"
Expand All @@ -39,7 +38,6 @@ limitations under the License.
#include "mediapipe/framework/tool/name_util.h"
#include "mediapipe/tasks/cc/common.h"
#include "mediapipe/tasks/cc/core/model_resources_cache.h"
#include "tensorflow/lite/core/api/op_resolver.h"

#if !MEDIAPIPE_DISABLE_GPU
#include "mediapipe/gpu/gpu_shared_data_internal.h"
Expand Down Expand Up @@ -101,21 +99,19 @@ absl::StatusOr<std::unique_ptr<TaskRunner>> TaskRunner::Create(
PacketsCallback packets_callback,
std::shared_ptr<Executor> default_executor,
std::optional<PacketMap> input_side_packets,
std::shared_ptr<::mediapipe::GpuResources> resources,
std::optional<ErrorFn> error_fn) {
std::shared_ptr<::mediapipe::GpuResources> resources) {
#else
absl::StatusOr<std::unique_ptr<TaskRunner>> TaskRunner::Create(
CalculatorGraphConfig config,
std::unique_ptr<tflite::OpResolver> op_resolver,
PacketsCallback packets_callback,
std::shared_ptr<Executor> default_executor,
std::optional<PacketMap> input_side_packets,
std::optional<ErrorFn> error_fn) {
std::optional<PacketMap> input_side_packets) {
#endif // !MEDIAPIPE_DISABLE_GPU
auto task_runner = absl::WrapUnique(new TaskRunner(packets_callback));
MP_RETURN_IF_ERROR(task_runner->Initialize(
std::move(config), std::move(op_resolver), std::move(default_executor),
std::move(input_side_packets), std::move(error_fn)));
std::move(input_side_packets)));

#if !MEDIAPIPE_DISABLE_GPU
if (resources) {
Expand All @@ -132,8 +128,7 @@ absl::Status TaskRunner::Initialize(
CalculatorGraphConfig config,
std::unique_ptr<tflite::OpResolver> op_resolver,
std::shared_ptr<Executor> default_executor,
std::optional<PacketMap> input_side_packets,
std::optional<ErrorFn> error_fn) {
std::optional<PacketMap> input_side_packets) {
if (initialized_) {
return CreateStatusWithPayload(
absl::StatusCode::kInvalidArgument,
Expand Down Expand Up @@ -186,8 +181,6 @@ absl::Status TaskRunner::Initialize(
MP_RETURN_IF_ERROR(graph_.SetExecutor("", std::move(default_executor)));
}

if (error_fn) MP_RETURN_IF_ERROR(graph_.SetErrorCallback(*error_fn));

auto model_resources_cache =
std::make_shared<ModelResourcesCache>(std::move(op_resolver));
MP_RETURN_IF_ERROR(
Expand Down
17 changes: 8 additions & 9 deletions mediapipe/tasks/cc/core/task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ limitations under the License.
#include <vector>

#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/executor.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/tasks/cc/core/model_resources.h"
#include "mediapipe/tasks/cc/core/model_resources_cache.h"
#include "tensorflow/lite/core/api/op_resolver.h"

namespace mediapipe {
Expand All @@ -46,8 +50,6 @@ class GpuResources;
namespace tasks {
namespace core {

using ErrorFn = std::function<void(absl::Status)>;

// Mapping from the MediaPipe calculator graph stream/side packet names to the
// packets.
using PacketMap = std::map<std::string, Packet>;
Expand Down Expand Up @@ -82,16 +84,14 @@ class TaskRunner {
PacketsCallback packets_callback = nullptr,
std::shared_ptr<Executor> default_executor = nullptr,
std::optional<PacketMap> input_side_packets = std::nullopt,
std::shared_ptr<::mediapipe::GpuResources> resources = nullptr,
std::optional<ErrorFn> error_fn = std::nullopt);
std::shared_ptr<::mediapipe::GpuResources> resources = nullptr);
#else
static absl::StatusOr<std::unique_ptr<TaskRunner>> Create(
CalculatorGraphConfig config,
std::unique_ptr<tflite::OpResolver> op_resolver = nullptr,
PacketsCallback packets_callback = nullptr,
std::shared_ptr<Executor> default_executor = nullptr,
std::optional<PacketMap> input_side_packets = std::nullopt,
std::optional<ErrorFn> error_fn = std::nullopt);
std::optional<PacketMap> input_side_packets = std::nullopt);
#endif // !MEDIAPIPE_DISABLE_GPU

// TaskRunner is neither copyable nor movable.
Expand Down Expand Up @@ -135,7 +135,7 @@ class TaskRunner {
private:
// Constructor.
// Creates a TaskRunner instance with an optional PacketsCallback method.
explicit TaskRunner(PacketsCallback packets_callback = nullptr)
TaskRunner(PacketsCallback packets_callback = nullptr)
: packets_callback_(packets_callback) {}

// Initializes the task runner. Returns an ok status to indicate that the
Expand All @@ -146,8 +146,7 @@ class TaskRunner {
CalculatorGraphConfig config,
std::unique_ptr<tflite::OpResolver> op_resolver = nullptr,
std::shared_ptr<Executor> default_executor = nullptr,
std::optional<PacketMap> input_side_packets = std::nullopt,
std::optional<ErrorFn> error_fn = std::nullopt);
std::optional<PacketMap> input_side_packets = std::nullopt);

// Starts the task runner. Returns an ok status to indicate that the
// runner is ready to accept input data. Otherwise, returns an error status to
Expand Down

0 comments on commit 849cde7

Please sign in to comment.