From 37290f0224667c02ccc8a4301b08f194d95d88c7 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Tue, 6 Jun 2023 01:32:39 -0700 Subject: [PATCH] Port StreamToSidePacketCalculator to api2 PiperOrigin-RevId: 538109898 --- mediapipe/calculators/core/BUILD | 1 + .../core/stream_to_side_packet_calculator.cc | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mediapipe/calculators/core/BUILD b/mediapipe/calculators/core/BUILD index d773bef36..d3e63e38f 100644 --- a/mediapipe/calculators/core/BUILD +++ b/mediapipe/calculators/core/BUILD @@ -1138,6 +1138,7 @@ cc_library( deps = [ "//mediapipe/framework:calculator_framework", "//mediapipe/framework:timestamp", + "//mediapipe/framework/api2:node", "//mediapipe/framework/port:status", ], alwayslink = 1, diff --git a/mediapipe/calculators/core/stream_to_side_packet_calculator.cc b/mediapipe/calculators/core/stream_to_side_packet_calculator.cc index 9dc25142a..72e812255 100644 --- a/mediapipe/calculators/core/stream_to_side_packet_calculator.cc +++ b/mediapipe/calculators/core/stream_to_side_packet_calculator.cc @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "mediapipe/framework/api2/node.h" #include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/port/status.h" #include "mediapipe/framework/timestamp.h" namespace mediapipe { +namespace api2 { // A calculator that takes a packet of an input stream and converts it to an // output side packet. This calculator only works under the assumption that the @@ -28,21 +30,21 @@ namespace mediapipe { // input_stream: "stream" // output_side_packet: "side_packet" // } -class StreamToSidePacketCalculator : public mediapipe::CalculatorBase { +class StreamToSidePacketCalculator : public Node { public: - static absl::Status GetContract(mediapipe::CalculatorContract* cc) { - cc->Inputs().Index(0).SetAny(); - cc->OutputSidePackets().Index(0).SetAny(); - return absl::OkStatus(); - } + static constexpr Input::Optional kIn{""}; + static constexpr SideOutput> kOut{""}; + + MEDIAPIPE_NODE_CONTRACT(kIn, kOut); absl::Status Process(mediapipe::CalculatorContext* cc) override { - mediapipe::Packet& packet = cc->Inputs().Index(0).Value(); - cc->OutputSidePackets().Index(0).Set( - packet.At(mediapipe::Timestamp::Unset())); + kOut(cc).Set( + kIn(cc).packet().As().At(mediapipe::Timestamp::Unset())); return absl::OkStatus(); } }; -REGISTER_CALCULATOR(StreamToSidePacketCalculator); +MEDIAPIPE_REGISTER_NODE(StreamToSidePacketCalculator); + +} // namespace api2 } // namespace mediapipe