From 849cde78be7c03b5067840688339027f6d0ff27d Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 17 Jan 2024 18:51:35 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 599352853 --- mediapipe/tasks/cc/core/task_api_factory.h | 13 ++----------- mediapipe/tasks/cc/core/task_runner.cc | 15 ++++----------- mediapipe/tasks/cc/core/task_runner.h | 17 ++++++++--------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/mediapipe/tasks/cc/core/task_api_factory.h b/mediapipe/tasks/cc/core/task_api_factory.h index a11a23fcfd..315a19bf21 100644 --- a/mediapipe/tasks/cc/core/task_api_factory.h +++ b/mediapipe/tasks/cc/core/task_api_factory.h @@ -57,8 +57,7 @@ class TaskApiFactory { std::unique_ptr resolver, PacketsCallback packets_callback = nullptr, std::shared_ptr default_executor = nullptr, - std::optional input_side_packets = std::nullopt, - std::optional error_fn = std::nullopt) { + std::optional input_side_packets = std::nullopt) { bool found_task_subgraph = false; // This for-loop ensures there's only one subgraph besides // FlowLimiterCalculator. @@ -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(std::move(runner)); } diff --git a/mediapipe/tasks/cc/core/task_runner.cc b/mediapipe/tasks/cc/core/task_runner.cc index e02b3a466e..a0eb1de43c 100644 --- a/mediapipe/tasks/cc/core/task_runner.cc +++ b/mediapipe/tasks/cc/core/task_runner.cc @@ -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" @@ -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" @@ -101,21 +99,19 @@ absl::StatusOr> TaskRunner::Create( PacketsCallback packets_callback, std::shared_ptr default_executor, std::optional input_side_packets, - std::shared_ptr<::mediapipe::GpuResources> resources, - std::optional error_fn) { + std::shared_ptr<::mediapipe::GpuResources> resources) { #else absl::StatusOr> TaskRunner::Create( CalculatorGraphConfig config, std::unique_ptr op_resolver, PacketsCallback packets_callback, std::shared_ptr default_executor, - std::optional input_side_packets, - std::optional error_fn) { + std::optional 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) { @@ -132,8 +128,7 @@ absl::Status TaskRunner::Initialize( CalculatorGraphConfig config, std::unique_ptr op_resolver, std::shared_ptr default_executor, - std::optional input_side_packets, - std::optional error_fn) { + std::optional input_side_packets) { if (initialized_) { return CreateStatusWithPayload( absl::StatusCode::kInvalidArgument, @@ -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(std::move(op_resolver)); MP_RETURN_IF_ERROR( diff --git a/mediapipe/tasks/cc/core/task_runner.h b/mediapipe/tasks/cc/core/task_runner.h index ae34e459b9..ef48bef55d 100644 --- a/mediapipe/tasks/cc/core/task_runner.h +++ b/mediapipe/tasks/cc/core/task_runner.h @@ -29,12 +29,16 @@ limitations under the License. #include #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 { @@ -46,8 +50,6 @@ class GpuResources; namespace tasks { namespace core { -using ErrorFn = std::function; - // Mapping from the MediaPipe calculator graph stream/side packet names to the // packets. using PacketMap = std::map; @@ -82,16 +84,14 @@ class TaskRunner { PacketsCallback packets_callback = nullptr, std::shared_ptr default_executor = nullptr, std::optional input_side_packets = std::nullopt, - std::shared_ptr<::mediapipe::GpuResources> resources = nullptr, - std::optional error_fn = std::nullopt); + std::shared_ptr<::mediapipe::GpuResources> resources = nullptr); #else static absl::StatusOr> Create( CalculatorGraphConfig config, std::unique_ptr op_resolver = nullptr, PacketsCallback packets_callback = nullptr, std::shared_ptr default_executor = nullptr, - std::optional input_side_packets = std::nullopt, - std::optional error_fn = std::nullopt); + std::optional input_side_packets = std::nullopt); #endif // !MEDIAPIPE_DISABLE_GPU // TaskRunner is neither copyable nor movable. @@ -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 @@ -146,8 +146,7 @@ class TaskRunner { CalculatorGraphConfig config, std::unique_ptr op_resolver = nullptr, std::shared_ptr default_executor = nullptr, - std::optional input_side_packets = std::nullopt, - std::optional error_fn = std::nullopt); + std::optional 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