Port StreamToSidePacketCalculator to api2

PiperOrigin-RevId: 538109898
This commit is contained in:
MediaPipe Team 2023-06-06 01:32:39 -07:00 committed by Copybara-Service
parent ab72fccca7
commit 37290f0224
2 changed files with 13 additions and 10 deletions

View File

@ -1138,6 +1138,7 @@ cc_library(
deps = [ deps = [
"//mediapipe/framework:calculator_framework", "//mediapipe/framework:calculator_framework",
"//mediapipe/framework:timestamp", "//mediapipe/framework:timestamp",
"//mediapipe/framework/api2:node",
"//mediapipe/framework/port:status", "//mediapipe/framework/port:status",
], ],
alwayslink = 1, alwayslink = 1,

View File

@ -12,11 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "mediapipe/framework/api2/node.h"
#include "mediapipe/framework/calculator_framework.h" #include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/port/status.h" #include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/timestamp.h" #include "mediapipe/framework/timestamp.h"
namespace mediapipe { namespace mediapipe {
namespace api2 {
// A calculator that takes a packet of an input stream and converts it to an // 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 // output side packet. This calculator only works under the assumption that the
@ -28,21 +30,21 @@ namespace mediapipe {
// input_stream: "stream" // input_stream: "stream"
// output_side_packet: "side_packet" // output_side_packet: "side_packet"
// } // }
class StreamToSidePacketCalculator : public mediapipe::CalculatorBase { class StreamToSidePacketCalculator : public Node {
public: public:
static absl::Status GetContract(mediapipe::CalculatorContract* cc) { static constexpr Input<AnyType>::Optional kIn{""};
cc->Inputs().Index(0).SetAny(); static constexpr SideOutput<SameType<kIn>> kOut{""};
cc->OutputSidePackets().Index(0).SetAny();
return absl::OkStatus(); MEDIAPIPE_NODE_CONTRACT(kIn, kOut);
}
absl::Status Process(mediapipe::CalculatorContext* cc) override { absl::Status Process(mediapipe::CalculatorContext* cc) override {
mediapipe::Packet& packet = cc->Inputs().Index(0).Value(); kOut(cc).Set(
cc->OutputSidePackets().Index(0).Set( kIn(cc).packet().As<AnyType>().At(mediapipe::Timestamp::Unset()));
packet.At(mediapipe::Timestamp::Unset()));
return absl::OkStatus(); return absl::OkStatus();
} }
}; };
REGISTER_CALCULATOR(StreamToSidePacketCalculator);
MEDIAPIPE_REGISTER_NODE(StreamToSidePacketCalculator);
} // namespace api2
} // namespace mediapipe } // namespace mediapipe