Add stream API presence utils.
PiperOrigin-RevId: 570901832
This commit is contained in:
parent
2dd20822be
commit
7ab3d70aa4
|
@ -237,6 +237,28 @@ cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "presence",
|
||||
hdrs = ["presence.h"],
|
||||
deps = [
|
||||
"//mediapipe/calculators/core:packet_presence_calculator",
|
||||
"//mediapipe/framework/api2:builder",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "presence_test",
|
||||
srcs = ["presence_test.cc"],
|
||||
deps = [
|
||||
":presence",
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework/api2:builder",
|
||||
"//mediapipe/framework/port:gtest",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"//mediapipe/framework/port:parse_text_proto",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rect_transformation",
|
||||
srcs = ["rect_transformation.cc"],
|
||||
|
|
19
mediapipe/framework/api2/stream/presence.h
Normal file
19
mediapipe/framework/api2/stream/presence.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef MEDIAPIPE_FRAMEWORK_API2_STREAM_PRESENCE_H_
|
||||
#define MEDIAPIPE_FRAMEWORK_API2_STREAM_PRESENCE_H_
|
||||
|
||||
#include "mediapipe/framework/api2/builder.h"
|
||||
|
||||
namespace mediapipe::api2::builder {
|
||||
|
||||
// Updates @graph to emit a stream containing `bool` packets, where each packet
|
||||
// indicates whether @stream has a packet with corresponding timestamp or not.
|
||||
template <typename T>
|
||||
Stream<bool> IsPresent(Stream<T> stream, Graph& graph) {
|
||||
auto& presence_node = graph.AddNode("PacketPresenceCalculator");
|
||||
stream.ConnectTo(presence_node.In("PACKET"));
|
||||
return presence_node.Out("PRESENCE").Cast<bool>();
|
||||
}
|
||||
|
||||
} // namespace mediapipe::api2::builder
|
||||
|
||||
#endif // MEDIAPIPE_FRAMEWORK_API2_STREAM_PRESENCE_H_
|
33
mediapipe/framework/api2/stream/presence_test.cc
Normal file
33
mediapipe/framework/api2/stream/presence_test.cc
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "mediapipe/framework/api2/stream/presence.h"
|
||||
|
||||
#include "mediapipe/framework/api2/builder.h"
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/framework/port/gmock.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/framework/port/parse_text_proto.h"
|
||||
|
||||
namespace mediapipe::api2::builder {
|
||||
namespace {
|
||||
|
||||
TEST(Presence, VerifyConfig) {
|
||||
Graph graph;
|
||||
|
||||
Stream<int> stream = graph.In("STREAM").Cast<int>();
|
||||
stream.SetName("stream_to_check");
|
||||
Stream<bool> is_present_stream = IsPresent(stream, graph);
|
||||
is_present_stream.SetName("is_present_stream");
|
||||
|
||||
EXPECT_THAT(
|
||||
graph.GetConfig(),
|
||||
EqualsProto(mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
|
||||
node {
|
||||
calculator: "PacketPresenceCalculator"
|
||||
input_stream: "PACKET:stream_to_check"
|
||||
output_stream: "PRESENCE:is_present_stream"
|
||||
}
|
||||
input_stream: "STREAM:stream_to_check"
|
||||
)pb")));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediapipe::api2::builder
|
Loading…
Reference in New Issue
Block a user