From 66634bbef88c390ccd5c85774b839a81ea73240f Mon Sep 17 00:00:00 2001 From: Hadon Nash Date: Wed, 18 Jan 2023 16:36:09 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 503011674 --- mediapipe/framework/tool/switch/BUILD | 34 +++++++ .../framework/tool/switch/packet_processor.h | 88 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 mediapipe/framework/tool/switch/BUILD create mode 100644 mediapipe/framework/tool/switch/packet_processor.h diff --git a/mediapipe/framework/tool/switch/BUILD b/mediapipe/framework/tool/switch/BUILD new file mode 100644 index 000000000..62f9095ef --- /dev/null +++ b/mediapipe/framework/tool/switch/BUILD @@ -0,0 +1,34 @@ +# Copyright 2023 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. +# + +licenses(["notice"]) + +package(default_visibility = ["//visibility:private"]) + +cc_library( + name = "packet_processor", + hdrs = ["packet_processor.h"], + visibility = [ + "//visibility:public", + ], + deps = [ + "//mediapipe/framework:calculator_contract", + "//mediapipe/framework:collection_item_id", + "//mediapipe/framework:packet", + "//mediapipe/framework/port:logging", + "//mediapipe/framework/port:ret_check", + "//mediapipe/framework/port:status", + ], +) diff --git a/mediapipe/framework/tool/switch/packet_processor.h b/mediapipe/framework/tool/switch/packet_processor.h new file mode 100644 index 000000000..1789a46c5 --- /dev/null +++ b/mediapipe/framework/tool/switch/packet_processor.h @@ -0,0 +1,88 @@ +// 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. + +#ifndef MEDIAPIPE_FRAMEWORK_TOOL_PACKET_PROCESSOR_H_ +#define MEDIAPIPE_FRAMEWORK_TOOL_PACKET_PROCESSOR_H_ + +#include + +#include "mediapipe/framework/collection_item_id.h" +#include "mediapipe/framework/packet.h" +#include "mediapipe/framework/port/status.h" + +namespace mediapipe { + +// PacketConsumer accepts several tagged streams of packets. +class PacketConsumer { + public: + virtual ~PacketConsumer() = default; + + // Accepts a tagged input packet. + virtual absl::Status AddPacket(CollectionItemId id, Packet packet) = 0; + + // Returns the id for each input tag. + virtual std::shared_ptr InputTags() = 0; +}; + +// PacketConsumer delivers several tagged streams of packets. +class PacketProducer { + public: + virtual ~PacketProducer() = default; + + // Connects a consumer to recieve packets from this producer. + virtual void SetConsumer(PacketConsumer* consumer) = 0; +}; + +// SidePacketConsumer accepts several tagged constant packets. +class SidePacketConsumer { + public: + virtual ~SidePacketConsumer() = default; + + // Accepts a tagged input side-packet. + virtual absl::Status SetSidePacket(CollectionItemId id, Packet packet) = 0; + + // Returns the id for each input side-packet tag. + virtual std::shared_ptr SideInputTags() = 0; +}; + +// SidePacketProducer deleivers several tagged constant packets. +class SidePacketProducer { + public: + virtual ~SidePacketProducer() = default; + + // Connects a consumer to recieve packets from this producer. + virtual void SetSideConsumer(SidePacketConsumer* consumer) = 0; +}; + +// PacketProcessor consumes and produces packet streams and constant packets. +class PacketProcessor : public PacketConsumer, + public PacketProducer, + public SidePacketConsumer, + public SidePacketProducer { + public: + virtual ~PacketProcessor() = default; + + // Activate this PacketProcessor. + virtual absl::Status Start() = 0; + + // Block until this PacketProcessor has no remaining work to do. + virtual absl::Status WaitUntilIdle() = 0; + + // Deactivate this PacketProcessor. + virtual absl::Status Shutdown() = 0; +}; + +} // namespace mediapipe + +#endif // MEDIAPIPE_FRAMEWORK_TOOL_PACKET_PROCESSOR_H_