Project import generated by Copybara.

GitOrigin-RevId: 1138530ad1578c5d6615b3e3d041775c75d310c4
This commit is contained in:
MediaPipe Team
2019-09-11 14:29:38 -07:00
committed by jqtang
parent 423c21b454
commit 61bc4556af
173 changed files with 1806 additions and 1824 deletions
+2 -5
View File
@@ -82,10 +82,7 @@ mediapipe_cc_proto_library(
"//mediapipe/framework:calculator_cc_proto",
"//mediapipe/framework/deps:proto_descriptor_cc_proto",
],
visibility = [
"//mediapipe/framework:__subpackages__",
"//mediapipe/java/com/google/mediapipe/framework:__subpackages__",
],
visibility = ["//visibility:public"],
deps = [":calculator_graph_template_proto"],
)
@@ -93,7 +90,7 @@ mediapipe_cc_proto_library(
name = "source_cc_proto",
srcs = ["source.proto"],
cc_deps = ["//mediapipe/framework:calculator_cc_proto"],
visibility = ["//mediapipe/framework:__subpackages__"],
visibility = ["//visibility:public"],
deps = [":source_proto"],
)
@@ -45,7 +45,7 @@ TEST(FillPacketSetTest, Success) {
.Set<double>(
// double2
);
MEDIAPIPE_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
MP_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
std::map<std::string, Packet> all_side_packets;
all_side_packets["side_packet1"] = MakePacket<int>(70);
@@ -87,7 +87,7 @@ TEST(FillPacketSetTest, MissingSidePacketError) {
.Set<double>(
// double2
);
MEDIAPIPE_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
MP_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
std::map<std::string, Packet> all_side_packets;
all_side_packets["side_packet1"] = MakePacket<int>(70);
@@ -125,7 +125,7 @@ TEST(FillPacketSetTest, MissingSidePacketOk) {
.Set<double>(
// double2
);
MEDIAPIPE_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
MP_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
std::map<std::string, Packet> all_side_packets;
all_side_packets["side_packet1"] = MakePacket<int>(70);
@@ -169,7 +169,7 @@ TEST(FillPacketSetTest, WrongSidePacketType) {
.Set<double>(
// double2
);
MEDIAPIPE_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
MP_EXPECT_OK(ValidatePacketTypeSet(input_side_packet_types));
std::map<std::string, Packet> all_side_packets;
all_side_packets["side_packet1"] = MakePacket<float>(3.0f); // Wrong Type.
+11 -11
View File
@@ -72,7 +72,7 @@ bool IsLengthDelimited(WireFormatLite::WireType wire_type) {
uint32 fake_tag = WireFormatLite::MakeTag(1, wire_type);
while (data_size > 0) {
std::string number;
RETURN_IF_ERROR(ReadFieldValue(fake_tag, in, &number));
MP_RETURN_IF_ERROR(ReadFieldValue(fake_tag, in, &number));
RET_CHECK_LE(number.size(), data_size);
field_values->push_back(number);
data_size -= number.size();
@@ -92,10 +92,10 @@ bool IsLengthDelimited(WireFormatLite::WireType wire_type) {
if (field_number == field_id) {
if (!IsLengthDelimited(wire_type) &&
IsLengthDelimited(WireFormatLite::GetTagWireType(tag))) {
RETURN_IF_ERROR(ReadPackedValues(wire_type, in, field_values));
MP_RETURN_IF_ERROR(ReadPackedValues(wire_type, in, field_values));
} else {
std::string value;
RETURN_IF_ERROR(ReadFieldValue(tag, in, &value));
MP_RETURN_IF_ERROR(ReadFieldValue(tag, in, &value));
field_values->push_back(value);
}
} else {
@@ -155,12 +155,12 @@ std::vector<FieldValue>* FieldAccess::mutable_field_values() {
FieldAccess access(field_id, !proto_path.empty()
? WireFormatLite::TYPE_MESSAGE
: field_type);
RETURN_IF_ERROR(access.SetMessage(*message));
MP_RETURN_IF_ERROR(access.SetMessage(*message));
std::vector<std::string>& v = *access.mutable_field_values();
if (!proto_path.empty()) {
RET_CHECK(index >= 0 && index < v.size());
RETURN_IF_ERROR(ReplaceFieldRange(&v[index], proto_path, length, field_type,
field_values));
MP_RETURN_IF_ERROR(ReplaceFieldRange(&v[index], proto_path, length,
field_type, field_values));
} else {
RET_CHECK(index >= 0 && index <= v.size());
RET_CHECK(index + length >= 0 && index + length <= v.size());
@@ -182,11 +182,11 @@ std::vector<FieldValue>* FieldAccess::mutable_field_values() {
FieldAccess access(field_id, !proto_path.empty()
? WireFormatLite::TYPE_MESSAGE
: field_type);
RETURN_IF_ERROR(access.SetMessage(message));
MP_RETURN_IF_ERROR(access.SetMessage(message));
std::vector<std::string>& v = *access.mutable_field_values();
if (!proto_path.empty()) {
RET_CHECK(index >= 0 && index < v.size());
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
GetFieldRange(v[index], proto_path, length, field_type, field_values));
} else {
RET_CHECK(index >= 0 && index <= v.size());
@@ -243,7 +243,7 @@ template <typename T>
void (*writer)(T, proto_ns::io::CodedOutputStream*),
const std::string& text, CodedOutputStream* out) {
T value;
RETURN_IF_ERROR(ParseValue<T>(text, &value));
MP_RETURN_IF_ERROR(ParseValue<T>(text, &value));
(*writer)(value, out);
return ::mediapipe::OkStatus();
}
@@ -370,7 +370,7 @@ static ::mediapipe::Status DeserializeValue(const FieldValue& bytes,
result->reserve(text_values.size());
for (const std::string& text_value : text_values) {
FieldValue field_value;
RETURN_IF_ERROR(SerializeValue(text_value, field_type, &field_value));
MP_RETURN_IF_ERROR(SerializeValue(text_value, field_type, &field_value));
result->push_back(field_value);
}
return ::mediapipe::OkStatus();
@@ -383,7 +383,7 @@ static ::mediapipe::Status DeserializeValue(const FieldValue& bytes,
result->reserve(field_values.size());
for (const FieldValue& field_value : field_values) {
std::string text_value;
RETURN_IF_ERROR(DeserializeValue(field_value, field_type, &text_value));
MP_RETURN_IF_ERROR(DeserializeValue(field_value, field_type, &text_value));
result->push_back(text_value);
}
return ::mediapipe::OkStatus();
@@ -92,7 +92,7 @@ class SimulationClockTest : public ::testing::Test {
auto executor = std::make_shared<SimulationClockExecutor>(4);
simulation_clock_ = executor->GetClock();
clock_ = simulation_clock_.get();
MEDIAPIPE_ASSERT_OK(graph_.SetExecutor("", executor));
MP_ASSERT_OK(graph_.SetExecutor("", executor));
}
// Initialize the test clock as a RealClock.
@@ -213,20 +213,20 @@ TEST_F(SimulationClockTest, InFlight) {
SetUpInFlightGraph();
std::vector<Packet> out_packets;
tool::AddVectorSink("output_packets_0", &graph_config_, &out_packets);
MEDIAPIPE_ASSERT_OK(graph_.Initialize(
graph_config_, {
{"max_in_flight", MakePacket<int>(2)},
{"callback_0", Adopt(new auto(wait_0))},
{"callback_1", Adopt(new auto(wait_1))},
}));
MEDIAPIPE_ASSERT_OK(graph_.StartRun({}));
MP_ASSERT_OK(graph_.Initialize(graph_config_,
{
{"max_in_flight", MakePacket<int>(2)},
{"callback_0", Adopt(new auto(wait_0))},
{"callback_1", Adopt(new auto(wait_1))},
}));
MP_ASSERT_OK(graph_.StartRun({}));
simulation_clock_->ThreadStart();
// Add 10 input packets to the graph, one each 10 ms, starting after 11 ms
// of clock time. Timestamps lag clock times by 1 ms.
clock_->Sleep(absl::Microseconds(11000));
for (uint64 ts = 10000; ts <= 100000; ts += 10000) {
MEDIAPIPE_EXPECT_OK(graph_.AddPacketToInputStream(
MP_EXPECT_OK(graph_.AddPacketToInputStream(
"input_packets_0", MakePacket<uint64>(ts).At(Timestamp(ts))));
clock_->Sleep(absl::Microseconds(10000));
}
@@ -234,8 +234,8 @@ TEST_F(SimulationClockTest, InFlight) {
// Wait for 100 ms of clock time, then close the graph.
clock_->Sleep(absl::Microseconds(100000));
simulation_clock_->ThreadFinish();
MEDIAPIPE_ASSERT_OK(graph_.CloseAllInputStreams());
MEDIAPIPE_ASSERT_OK(graph_.WaitUntilDone());
MP_ASSERT_OK(graph_.CloseAllInputStreams());
MP_ASSERT_OK(graph_.WaitUntilDone());
// Validate the graph run.
EXPECT_THAT(TimestampValues(out_packets),
+18 -18
View File
@@ -58,14 +58,14 @@ TEST(CallbackFromGeneratorTest, TestAddVectorSink) {
tool::AddVectorSink("input_packets", &graph_config, &dumped_data);
graph_config.add_input_stream("input_packets");
CalculatorGraph graph(graph_config);
MEDIAPIPE_ASSERT_OK(graph.StartRun({}));
MP_ASSERT_OK(graph.StartRun({}));
for (int i = 0; i < 10; ++i) {
MEDIAPIPE_ASSERT_OK(graph.AddPacketToInputStream(
MP_ASSERT_OK(graph.AddPacketToInputStream(
"input_packets", MakePacket<int>(i).At(Timestamp(i))));
MEDIAPIPE_ASSERT_OK(graph.WaitUntilIdle());
MP_ASSERT_OK(graph.WaitUntilIdle());
}
MEDIAPIPE_ASSERT_OK(graph.CloseInputStream("input_packets"));
MEDIAPIPE_ASSERT_OK(graph.WaitUntilDone());
MP_ASSERT_OK(graph.CloseInputStream("input_packets"));
MP_ASSERT_OK(graph.WaitUntilDone());
ASSERT_EQ(10, dumped_data.size());
for (int i = 0; i < 10; ++i) {
EXPECT_EQ(Timestamp(i), dumped_data[i].Timestamp());
@@ -87,18 +87,18 @@ TEST(CalculatorGraph, OutputSummarySidePacketInClose) {
Packet summary_packet;
tool::AddSidePacketSink("num_of_packets", &config, &summary_packet);
CalculatorGraph graph;
MEDIAPIPE_ASSERT_OK(graph.Initialize(config));
MP_ASSERT_OK(graph.Initialize(config));
// Run the graph twice.
int max_count = 100;
for (int run = 0; run < 1; ++run) {
MEDIAPIPE_ASSERT_OK(graph.StartRun({}));
MP_ASSERT_OK(graph.StartRun({}));
for (int i = 0; i < max_count; ++i) {
MEDIAPIPE_ASSERT_OK(graph.AddPacketToInputStream(
MP_ASSERT_OK(graph.AddPacketToInputStream(
"input_packets", MakePacket<int>(i).At(Timestamp(i))));
}
MEDIAPIPE_ASSERT_OK(graph.CloseInputStream("input_packets"));
MEDIAPIPE_ASSERT_OK(graph.WaitUntilDone());
MP_ASSERT_OK(graph.CloseInputStream("input_packets"));
MP_ASSERT_OK(graph.WaitUntilDone());
EXPECT_EQ(max_count, summary_packet.Get<int>());
EXPECT_EQ(Timestamp::PostStream(), summary_packet.Timestamp());
}
@@ -124,24 +124,24 @@ TEST(CallbackTest, TestAddMultiStreamCallback) {
&graph_config, &cb_packet);
CalculatorGraph graph(graph_config);
MEDIAPIPE_ASSERT_OK(graph.StartRun({cb_packet}));
MP_ASSERT_OK(graph.StartRun({cb_packet}));
MEDIAPIPE_ASSERT_OK(graph.AddPacketToInputStream(
MP_ASSERT_OK(graph.AddPacketToInputStream(
"foo", MakePacket<int>(10).At(Timestamp(1))));
MEDIAPIPE_ASSERT_OK(
MP_ASSERT_OK(
graph.AddPacketToInputStream("bar", MakePacket<int>(5).At(Timestamp(1))));
MEDIAPIPE_ASSERT_OK(
MP_ASSERT_OK(
graph.AddPacketToInputStream("foo", MakePacket<int>(7).At(Timestamp(2))));
// no bar input at 2
MEDIAPIPE_ASSERT_OK(
MP_ASSERT_OK(
graph.AddPacketToInputStream("foo", MakePacket<int>(4).At(Timestamp(3))));
MEDIAPIPE_ASSERT_OK(
MP_ASSERT_OK(
graph.AddPacketToInputStream("bar", MakePacket<int>(5).At(Timestamp(3))));
MEDIAPIPE_ASSERT_OK(graph.CloseAllInputStreams());
MEDIAPIPE_ASSERT_OK(graph.WaitUntilDone());
MP_ASSERT_OK(graph.CloseAllInputStreams());
MP_ASSERT_OK(graph.WaitUntilDone());
EXPECT_THAT(sums, testing::ElementsAre(15, 7, 9));
}
+2 -2
View File
@@ -79,10 +79,10 @@ TEST(StatusTest, CombinedStatus) {
errors.clear();
errors.emplace_back(::mediapipe::StatusCode::kOk, "error_with_this_string");
errors.emplace_back(::mediapipe::StatusCode::kOk, "error_with_that_string");
MEDIAPIPE_EXPECT_OK(tool::CombinedStatus(prefix_error_message, errors));
MP_EXPECT_OK(tool::CombinedStatus(prefix_error_message, errors));
errors.clear();
MEDIAPIPE_EXPECT_OK(tool::CombinedStatus(prefix_error_message, errors));
MP_EXPECT_OK(tool::CombinedStatus(prefix_error_message, errors));
}
// Verify tool::StatusInvalid() and tool::StatusFail() and the alternatives
+28 -27
View File
@@ -60,14 +60,14 @@ namespace tool {
{config->mutable_input_stream(), config->mutable_output_stream(),
config->mutable_input_side_packet(),
config->mutable_output_side_packet()}) {
RETURN_IF_ERROR(TransformStreamNames(streams, transform));
MP_RETURN_IF_ERROR(TransformStreamNames(streams, transform));
}
for (auto& node : *config->mutable_node()) {
for (auto* streams :
{node.mutable_input_stream(), node.mutable_output_stream(),
node.mutable_input_side_packet(),
node.mutable_output_side_packet()}) {
RETURN_IF_ERROR(TransformStreamNames(streams, transform));
MP_RETURN_IF_ERROR(TransformStreamNames(streams, transform));
}
if (!node.name().empty()) {
node.set_name(transform(node.name()));
@@ -76,11 +76,11 @@ namespace tool {
for (auto& generator : *config->mutable_packet_generator()) {
for (auto* streams : {generator.mutable_input_side_packet(),
generator.mutable_output_side_packet()}) {
RETURN_IF_ERROR(TransformStreamNames(streams, transform));
MP_RETURN_IF_ERROR(TransformStreamNames(streams, transform));
}
}
for (auto& status_handler : *config->mutable_status_handler()) {
RETURN_IF_ERROR(TransformStreamNames(
MP_RETURN_IF_ERROR(TransformStreamNames(
status_handler.mutable_input_side_packet(), transform));
}
return ::mediapipe::OkStatus();
@@ -164,28 +164,29 @@ static ::mediapipe::Status PrefixNames(int subgraph_index,
const CalculatorGraphConfig::Node& subgraph_node,
CalculatorGraphConfig* subgraph_config) {
std::map<std::string, std::string> stream_map;
RETURN_IF_ERROR(FindCorrespondingStreams(&stream_map,
subgraph_config->input_stream(),
subgraph_node.input_stream()))
MP_RETURN_IF_ERROR(FindCorrespondingStreams(&stream_map,
subgraph_config->input_stream(),
subgraph_node.input_stream()))
.SetPrepend()
<< "while processing the input streams of subgraph node "
<< subgraph_node.calculator() << ": ";
RETURN_IF_ERROR(FindCorrespondingStreams(&stream_map,
subgraph_config->output_stream(),
subgraph_node.output_stream()))
MP_RETURN_IF_ERROR(FindCorrespondingStreams(&stream_map,
subgraph_config->output_stream(),
subgraph_node.output_stream()))
.SetPrepend()
<< "while processing the output streams of subgraph node "
<< subgraph_node.calculator() << ": ";
std::map<std::string, std::string> side_packet_map;
RETURN_IF_ERROR(FindCorrespondingStreams(&side_packet_map,
subgraph_config->input_side_packet(),
subgraph_node.input_side_packet()))
MP_RETURN_IF_ERROR(FindCorrespondingStreams(
&side_packet_map, subgraph_config->input_side_packet(),
subgraph_node.input_side_packet()))
.SetPrepend()
<< "while processing the input side packets of subgraph node "
<< subgraph_node.calculator() << ": ";
RETURN_IF_ERROR(FindCorrespondingStreams(
&side_packet_map, subgraph_config->output_side_packet(),
subgraph_node.output_side_packet()))
MP_RETURN_IF_ERROR(
FindCorrespondingStreams(&side_packet_map,
subgraph_config->output_side_packet(),
subgraph_node.output_side_packet()))
.SetPrepend()
<< "while processing the output side packets of subgraph node "
<< subgraph_node.calculator() << ": ";
@@ -197,22 +198,22 @@ static ::mediapipe::Status PrefixNames(int subgraph_index,
};
for (auto& node : *subgraph_config->mutable_node()) {
name_map = &stream_map;
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
TransformStreamNames(node.mutable_input_stream(), replace_names));
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
TransformStreamNames(node.mutable_output_stream(), replace_names));
name_map = &side_packet_map;
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
TransformStreamNames(node.mutable_input_side_packet(), replace_names));
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
TransformStreamNames(node.mutable_output_side_packet(), replace_names));
}
name_map = &side_packet_map;
for (auto& generator : *subgraph_config->mutable_packet_generator()) {
RETURN_IF_ERROR(TransformStreamNames(generator.mutable_input_side_packet(),
replace_names));
RETURN_IF_ERROR(TransformStreamNames(generator.mutable_output_side_packet(),
replace_names));
MP_RETURN_IF_ERROR(TransformStreamNames(
generator.mutable_input_side_packet(), replace_names));
MP_RETURN_IF_ERROR(TransformStreamNames(
generator.mutable_output_side_packet(), replace_names));
}
return ::mediapipe::OkStatus();
}
@@ -235,12 +236,12 @@ static ::mediapipe::Status PrefixNames(int subgraph_index,
std::vector<CalculatorGraphConfig> subgraphs;
for (auto it = subgraph_nodes_start; it != nodes->end(); ++it) {
const auto& node = *it;
RETURN_IF_ERROR(ValidateSubgraphFields(node));
MP_RETURN_IF_ERROR(ValidateSubgraphFields(node));
ASSIGN_OR_RETURN(auto subgraph, graph_registry->CreateByName(
config->package(), node.calculator(),
&node.options()));
RETURN_IF_ERROR(PrefixNames(subgraph_counter++, &subgraph));
RETURN_IF_ERROR(ConnectSubgraphStreams(node, &subgraph));
MP_RETURN_IF_ERROR(PrefixNames(subgraph_counter++, &subgraph));
MP_RETURN_IF_ERROR(ConnectSubgraphStreams(node, &subgraph));
subgraphs.push_back(subgraph);
}
nodes->erase(subgraph_nodes_start, nodes->end());
@@ -213,7 +213,7 @@ TEST(SubgraphExpansionTest, TransformStreamNames) {
}
)");
auto add_foo = [](absl::string_view s) { return absl::StrCat(s, "_foo"); };
MEDIAPIPE_EXPECT_OK(tool::TransformStreamNames(
MP_EXPECT_OK(tool::TransformStreamNames(
(*config.mutable_node())[0].mutable_input_stream(), add_foo));
EXPECT_THAT(config, mediapipe::EqualsProto(expected_config));
}
@@ -258,7 +258,7 @@ TEST(SubgraphExpansionTest, TransformNames) {
auto add_prefix = [](absl::string_view s) {
return absl::StrCat("__sg0_", s);
};
MEDIAPIPE_EXPECT_OK(tool::TransformNames(&config, add_prefix));
MP_EXPECT_OK(tool::TransformNames(&config, add_prefix));
EXPECT_THAT(config, mediapipe::EqualsProto(expected_config));
}
@@ -281,7 +281,7 @@ TEST(SubgraphExpansionTest, FindCorrespondingStreams) {
}
)");
std::map<std::string, std::string> stream_map;
MEDIAPIPE_EXPECT_OK(tool::FindCorrespondingStreams(
MP_EXPECT_OK(tool::FindCorrespondingStreams(
&stream_map, config1.input_stream(), config2.node()[0].input_stream()));
EXPECT_THAT(stream_map,
testing::UnorderedElementsAre(testing::Pair("input_1", "foo"),
@@ -416,8 +416,7 @@ TEST(SubgraphExpansionTest, ConnectSubgraphStreams) {
output_side_packet: "flop"
}
)");
MEDIAPIPE_EXPECT_OK(
tool::ConnectSubgraphStreams(supergraph.node()[0], &subgraph));
MP_EXPECT_OK(tool::ConnectSubgraphStreams(supergraph.node()[0], &subgraph));
EXPECT_THAT(subgraph, mediapipe::EqualsProto(expected_subgraph));
}
@@ -455,7 +454,7 @@ TEST(SubgraphExpansionTest, ExpandSubgraphs) {
output_side_packet: "__sg0_side"
}
)");
MEDIAPIPE_EXPECT_OK(tool::ExpandSubgraphs(&supergraph));
MP_EXPECT_OK(tool::ExpandSubgraphs(&supergraph));
EXPECT_THAT(supergraph, mediapipe::EqualsProto(expected_graph));
}
@@ -521,7 +520,7 @@ TEST(SubgraphExpansionTest, ExecutorFieldOfNodeInSubgraphPreserved) {
executor: "custom_thread_pool"
}
)");
MEDIAPIPE_EXPECT_OK(tool::ExpandSubgraphs(&supergraph));
MP_EXPECT_OK(tool::ExpandSubgraphs(&supergraph));
EXPECT_THAT(supergraph, mediapipe::EqualsProto(expected_graph));
}
+1 -1
View File
@@ -44,7 +44,7 @@ void TagMap::InitializeNames(
std::string tag;
int index;
std::string name;
RETURN_IF_ERROR(ParseTagIndexName(tag_index_name, &tag, &index, &name));
MP_RETURN_IF_ERROR(ParseTagIndexName(tag_index_name, &tag, &index, &name));
// Get a reference to the tag data (possibly creating it).
TagData& tag_data = mapping_[tag];
+2 -2
View File
@@ -56,7 +56,7 @@ class TagMap {
static ::mediapipe::StatusOr<std::shared_ptr<TagMap>> Create(
const proto_ns::RepeatedPtrField<ProtoString>& tag_index_names) {
std::shared_ptr<TagMap> output(new TagMap());
RETURN_IF_ERROR(output->Initialize(tag_index_names));
MP_RETURN_IF_ERROR(output->Initialize(tag_index_names));
return std::move(output);
}
@@ -67,7 +67,7 @@ class TagMap {
static ::mediapipe::StatusOr<std::shared_ptr<TagMap>> Create(
const TagAndNameInfo& info) {
std::shared_ptr<TagMap> output(new TagMap());
RETURN_IF_ERROR(output->Initialize(info));
MP_RETURN_IF_ERROR(output->Initialize(info));
return std::move(output);
}
+26 -28
View File
@@ -26,37 +26,35 @@ namespace {
TEST(TagMapTest, Create) {
// Create using tags.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMapFromTags({}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMapFromTags({"BLAH"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMapFromTags({"BLAH1", "BLAH2"}));
MP_EXPECT_OK(tool::CreateTagMapFromTags({}));
MP_EXPECT_OK(tool::CreateTagMapFromTags({"BLAH"}));
MP_EXPECT_OK(tool::CreateTagMapFromTags({"BLAH1", "BLAH2"}));
// Tags must be uppercase.
EXPECT_FALSE(tool::CreateTagMapFromTags({"blah1", "BLAH2"}).ok());
// Create with TAG:<index>:names.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"blah"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"blah1", "blah2"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"BLAH:blah"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"BLAH1:blah1", "BLAH2:blah2"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"BLAH:0:blah1", "BLAH:1:blah2"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"BLAH:blah1", "BLAH:1:blah2"}));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap(
MP_EXPECT_OK(tool::CreateTagMap({}));
MP_EXPECT_OK(tool::CreateTagMap({"blah"}));
MP_EXPECT_OK(tool::CreateTagMap({"blah1", "blah2"}));
MP_EXPECT_OK(tool::CreateTagMap({"BLAH:blah"}));
MP_EXPECT_OK(tool::CreateTagMap({"BLAH1:blah1", "BLAH2:blah2"}));
MP_EXPECT_OK(tool::CreateTagMap({"BLAH:0:blah1", "BLAH:1:blah2"}));
MP_EXPECT_OK(tool::CreateTagMap({"BLAH:blah1", "BLAH:1:blah2"}));
MP_EXPECT_OK(tool::CreateTagMap(
{"A:2:a2", "B:1:b1", "C:c0", "A:0:a0", "B:b0", "A:1:a1"}));
MEDIAPIPE_EXPECT_OK(
tool::CreateTagMap({"w", "A:2:a2", "x", "B:1:b1", "C:c0", "y", "A:0:a0",
"B:b0", "z", "A:1:a1"}));
MEDIAPIPE_EXPECT_OK(
tool::CreateTagMap({"A:2:a2", "w", "x", "B:1:b1", "C:c0", "y", "A:0:a0",
"B:b0", "z", "A:1:a1"}));
MP_EXPECT_OK(tool::CreateTagMap({"w", "A:2:a2", "x", "B:1:b1", "C:c0", "y",
"A:0:a0", "B:b0", "z", "A:1:a1"}));
MP_EXPECT_OK(tool::CreateTagMap({"A:2:a2", "w", "x", "B:1:b1", "C:c0", "y",
"A:0:a0", "B:b0", "z", "A:1:a1"}));
// Reuse name.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"a", "A:a"}));
MP_EXPECT_OK(tool::CreateTagMap({"a", "A:a"}));
// Reuse name.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"a", "a"}));
MP_EXPECT_OK(tool::CreateTagMap({"a", "a"}));
// Reuse name.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"C:c", "a", "a"}));
MP_EXPECT_OK(tool::CreateTagMap({"C:c", "a", "a"}));
// Reuse name.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap({"A:a", "B:a"}));
MP_EXPECT_OK(tool::CreateTagMap({"A:a", "B:a"}));
// Reuse same tag.
EXPECT_FALSE(tool::CreateTagMap({"BLAH:blah1", "BLAH:blah2"}).ok());
@@ -71,20 +69,20 @@ TEST(TagMapTest, Create) {
tool::CreateTagMap({"blah0", "BLAH:1:blah1", "BLAH:2:blah2"}).ok());
// Create using an index.
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap(0));
MEDIAPIPE_EXPECT_OK(tool::CreateTagMap(3));
MP_EXPECT_OK(tool::CreateTagMap(0));
MP_EXPECT_OK(tool::CreateTagMap(3));
// Negative number of entries.
EXPECT_FALSE(tool::CreateTagMap(-1).ok());
// Create using a TagAndNameInfo.
tool::TagAndNameInfo info;
info.names = {"blah1", "blah2"};
MEDIAPIPE_EXPECT_OK(tool::TagMap::Create(info));
MP_EXPECT_OK(tool::TagMap::Create(info));
info.tags = {"BLAH1", "BLAH2", "BLAH3"};
// Number of tags and names do not match.
EXPECT_FALSE(tool::TagMap::Create(info).ok());
info.names.push_back("blah3");
MEDIAPIPE_EXPECT_OK(tool::TagMap::Create(info));
MP_EXPECT_OK(tool::TagMap::Create(info));
}
void TestSuccessTagMap(const std::vector<std::string>& tag_index_names,
@@ -296,11 +294,11 @@ TEST(TagMapTest, SameAs) {
if (std::get<1>(parameters)) {
auto statusor_tag_map =
tool::CreateTagMapFromTags(std::get<2>(parameters));
MEDIAPIPE_ASSERT_OK(statusor_tag_map);
MP_ASSERT_OK(statusor_tag_map);
tag_maps.push_back(std::move(statusor_tag_map.ValueOrDie()));
} else {
auto statusor_tag_map = tool::CreateTagMap(std::get<2>(parameters));
MEDIAPIPE_ASSERT_OK(statusor_tag_map);
MP_ASSERT_OK(statusor_tag_map);
tag_maps.push_back(std::move(statusor_tag_map.ValueOrDie()));
}
}
@@ -327,7 +325,7 @@ void TestDebugString(const ::mediapipe::StatusOr<std::shared_ptr<tool::TagMap>>&
statusor_tag_map,
const std::vector<std::string>& canonical_entries,
Matcher short_string_matcher) {
MEDIAPIPE_ASSERT_OK(statusor_tag_map);
MP_ASSERT_OK(statusor_tag_map);
tool::TagMap& tag_map = *statusor_tag_map.ValueOrDie();
std::string debug_string = tag_map.DebugString();
std::string short_string = tag_map.ShortDebugString();
@@ -604,7 +604,8 @@ class TemplateExpanderImpl {
? mediapipe::SimpleDtoa(args[i].num())
: args[i].str();
std::vector<FieldValue> r;
RETURN_IF_ERROR(ProtoUtilLite::Serialize({text_value}, field_type, &r));
MP_RETURN_IF_ERROR(
ProtoUtilLite::Serialize({text_value}, field_type, &r));
result->push_back(r[0]);
}
}
@@ -72,7 +72,7 @@ mediapipe::Status ReadFile(const std::string& proto_source, bool read_text,
proto_ns::Message* result) {
std::ifstream ifs(proto_source);
proto_ns::io::IstreamInputStream in(&ifs);
RETURN_IF_ERROR(ReadProto(&in, read_text, proto_source, result));
MP_RETURN_IF_ERROR(ReadProto(&in, read_text, proto_source, result));
return mediapipe::OkStatus();
}
@@ -81,7 +81,7 @@ mediapipe::Status WriteFile(const std::string& proto_output, bool write_text,
const proto_ns::Message& message) {
std::ofstream ofs(proto_output, std::ofstream::out | std::ofstream::trunc);
proto_ns::io::OstreamOutputStream out(&ofs);
RETURN_IF_ERROR(WriteProto(message, write_text, proto_output, &out));
MP_RETURN_IF_ERROR(WriteProto(message, write_text, proto_output, &out));
return mediapipe::OkStatus();
}
+1 -1
View File
@@ -28,7 +28,7 @@ namespace tool {
::mediapipe::Status ValidateInput(const InputCollection& input_collection) {
if (!input_collection.name().empty()) {
RETURN_IF_ERROR(tool::ValidateName(input_collection.name())).SetPrepend()
MP_RETURN_IF_ERROR(tool::ValidateName(input_collection.name())).SetPrepend()
<< "InputCollection " << input_collection.name()
<< " has improperly specified name: ";
}
+4 -4
View File
@@ -50,7 +50,7 @@ namespace tool {
for (const auto& tag_and_name : tags_and_names) {
std::string tag;
std::string name;
RETURN_IF_ERROR(ParseTagAndName(tag_and_name, &tag, &name));
MP_RETURN_IF_ERROR(ParseTagAndName(tag_and_name, &tag, &name));
if (!tag.empty()) {
info->tags.push_back(tag);
}
@@ -73,7 +73,7 @@ namespace tool {
tags_and_names->Clear();
if (info.tags.empty()) {
for (const auto& name : info.names) {
RETURN_IF_ERROR(ValidateName(name));
MP_RETURN_IF_ERROR(ValidateName(name));
*tags_and_names->Add() = name;
}
} else {
@@ -83,8 +83,8 @@ namespace tool {
<< " does not match the number of tags " << info.tags.size();
}
for (int i = 0; i < info.tags.size(); ++i) {
RETURN_IF_ERROR(ValidateTag(info.tags[i]));
RETURN_IF_ERROR(ValidateName(info.names[i]));
MP_RETURN_IF_ERROR(ValidateTag(info.tags[i]));
MP_RETURN_IF_ERROR(ValidateName(info.names[i]));
*tags_and_names->Add() = absl::StrCat(info.tags[i], ":", info.names[i]);
}
}
+28 -31
View File
@@ -27,12 +27,12 @@ namespace mediapipe {
namespace {
TEST(ValidateNameTest, ValidateName) {
MEDIAPIPE_EXPECT_OK(tool::ValidateName("humphrey"));
MEDIAPIPE_EXPECT_OK(tool::ValidateName("humphrey_bogart"));
MEDIAPIPE_EXPECT_OK(tool::ValidateName("humphrey_bogart_1899"));
MEDIAPIPE_EXPECT_OK(tool::ValidateName("aa"));
MEDIAPIPE_EXPECT_OK(tool::ValidateName("b1"));
MEDIAPIPE_EXPECT_OK(tool::ValidateName("_1"));
MP_EXPECT_OK(tool::ValidateName("humphrey"));
MP_EXPECT_OK(tool::ValidateName("humphrey_bogart"));
MP_EXPECT_OK(tool::ValidateName("humphrey_bogart_1899"));
MP_EXPECT_OK(tool::ValidateName("aa"));
MP_EXPECT_OK(tool::ValidateName("b1"));
MP_EXPECT_OK(tool::ValidateName("_1"));
EXPECT_FALSE(tool::ValidateName("").ok());
EXPECT_FALSE(tool::ValidateName("humphrey bogart").ok());
EXPECT_FALSE(tool::ValidateName("humphreyBogart").ok());
@@ -54,12 +54,12 @@ TEST(ValidateNameTest, ValidateName) {
}
TEST(ValidateNameTest, ValidateTag) {
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("MALE"));
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("MALE_ACTOR"));
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("ACTOR_1899"));
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("AA"));
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("B1"));
MEDIAPIPE_EXPECT_OK(tool::ValidateTag("_1"));
MP_EXPECT_OK(tool::ValidateTag("MALE"));
MP_EXPECT_OK(tool::ValidateTag("MALE_ACTOR"));
MP_EXPECT_OK(tool::ValidateTag("ACTOR_1899"));
MP_EXPECT_OK(tool::ValidateTag("AA"));
MP_EXPECT_OK(tool::ValidateTag("B1"));
MP_EXPECT_OK(tool::ValidateTag("_1"));
EXPECT_FALSE(tool::ValidateTag("").ok());
EXPECT_FALSE(tool::ValidateTag("MALE ACTOR").ok());
EXPECT_FALSE(tool::ValidateTag("MALEaCTOR").ok());
@@ -82,24 +82,22 @@ TEST(ValidateNameTest, ParseTagAndName) {
std::string name;
tag = "blah";
name = "blah";
MEDIAPIPE_EXPECT_OK(tool::ParseTagAndName("MALE:humphrey", &tag, &name));
MP_EXPECT_OK(tool::ParseTagAndName("MALE:humphrey", &tag, &name));
EXPECT_EQ("MALE", tag);
EXPECT_EQ("humphrey", name);
tag = "blah";
name = "blah";
MEDIAPIPE_EXPECT_OK(
tool::ParseTagAndName("ACTOR:humphrey_bogart", &tag, &name));
MP_EXPECT_OK(tool::ParseTagAndName("ACTOR:humphrey_bogart", &tag, &name));
EXPECT_EQ("ACTOR", tag);
EXPECT_EQ("humphrey_bogart", name);
tag = "blah";
name = "blah";
MEDIAPIPE_EXPECT_OK(
tool::ParseTagAndName("ACTOR_1899:humphrey_1899", &tag, &name));
MP_EXPECT_OK(tool::ParseTagAndName("ACTOR_1899:humphrey_1899", &tag, &name));
EXPECT_EQ("ACTOR_1899", tag);
EXPECT_EQ("humphrey_1899", name);
tag = "blah";
name = "blah";
MEDIAPIPE_EXPECT_OK(tool::ParseTagAndName("humphrey_bogart", &tag, &name));
MP_EXPECT_OK(tool::ParseTagAndName("humphrey_bogart", &tag, &name));
EXPECT_EQ("", tag);
EXPECT_EQ("humphrey_bogart", name);
@@ -122,7 +120,7 @@ TEST(ValidateNameTest, ParseTagAndName) {
EXPECT_EQ("", name);
tag = "blah";
name = "blah";
MEDIAPIPE_EXPECT_OK(tool::ParseTagAndName("ACTOR:humphrey", &tag, &name));
MP_EXPECT_OK(tool::ParseTagAndName("ACTOR:humphrey", &tag, &name));
EXPECT_EQ("ACTOR", tag);
EXPECT_EQ("humphrey", name);
@@ -166,8 +164,8 @@ void TestPassParseTagIndexName(const std::string& tag_index_name,
std::string actual_tag = "UNTOUCHED";
int actual_index = -100;
std::string actual_name = "untouched";
MEDIAPIPE_ASSERT_OK(tool::ParseTagIndexName(tag_index_name, &actual_tag,
&actual_index, &actual_name))
MP_ASSERT_OK(tool::ParseTagIndexName(tag_index_name, &actual_tag,
&actual_index, &actual_name))
<< "With tag_index_name " << tag_index_name;
EXPECT_EQ(expected_tag, actual_tag)
<< "With tag_index_name " << tag_index_name;
@@ -280,8 +278,7 @@ void TestPassParseTagIndex(const std::string& tag_index,
const int expected_index) {
std::string actual_tag = "UNTOUCHED";
int actual_index = -100;
MEDIAPIPE_ASSERT_OK(
tool::ParseTagIndex(tag_index, &actual_tag, &actual_index))
MP_ASSERT_OK(tool::ParseTagIndex(tag_index, &actual_tag, &actual_index))
<< "With tag_index" << tag_index;
EXPECT_EQ(expected_tag, actual_tag) << "With tag_index " << tag_index;
EXPECT_EQ(expected_index, actual_index) << "With tag_index " << tag_index;
@@ -360,22 +357,22 @@ TEST(ValidateNameTest, GetTagAndNameInfo) {
fields.Clear();
fields.Add()->assign("transcoded_input_file");
tool::TagAndNameInfo info;
MEDIAPIPE_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
MP_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
ASSERT_EQ(0, info.tags.size());
ASSERT_EQ(1, info.names.size());
EXPECT_EQ(fields.Get(0), info.names[0]);
MEDIAPIPE_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
MP_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
EXPECT_THAT(node_config2, EqualsProto(node_config1));
// Single input using tags.
fields.Clear();
fields.Add()->assign("FILE:transcoded_input_file");
MEDIAPIPE_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
MP_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
ASSERT_EQ(1, info.tags.size());
ASSERT_EQ(1, info.names.size());
EXPECT_EQ("FILE", info.tags[0]);
EXPECT_EQ("transcoded_input_file", info.names[0]);
MEDIAPIPE_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
MP_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
EXPECT_THAT(node_config2, EqualsProto(node_config1));
// Mixing indexes and tags.
@@ -390,7 +387,7 @@ TEST(ValidateNameTest, GetTagAndNameInfo) {
fields.Add()->assign("TAG2:input2");
fields.Add()->assign("TAG3:input3");
fields.Add()->assign("TAG4:input4");
MEDIAPIPE_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
MP_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
ASSERT_EQ(4, info.tags.size());
ASSERT_EQ(4, info.names.size());
EXPECT_EQ("TAG1", info.tags[0]);
@@ -401,7 +398,7 @@ TEST(ValidateNameTest, GetTagAndNameInfo) {
EXPECT_EQ("input2", info.names[1]);
EXPECT_EQ("input3", info.names[2]);
EXPECT_EQ("input4", info.names[3]);
MEDIAPIPE_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
MP_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
EXPECT_THAT(node_config2, EqualsProto(node_config1));
// Valid configuration with more than one input using indexes.
@@ -410,14 +407,14 @@ TEST(ValidateNameTest, GetTagAndNameInfo) {
fields.Add()->assign("input2");
fields.Add()->assign("input3");
fields.Add()->assign("input4");
MEDIAPIPE_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
MP_ASSERT_OK(tool::GetTagAndNameInfo(fields, &info));
ASSERT_EQ(0, info.tags.size());
ASSERT_EQ(4, info.names.size());
EXPECT_EQ("input1", info.names[0]);
EXPECT_EQ("input2", info.names[1]);
EXPECT_EQ("input3", info.names[2]);
EXPECT_EQ("input4", info.names[3]);
MEDIAPIPE_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
MP_ASSERT_OK(tool::SetFromTagAndNameInfo(info, &fields_copy));
EXPECT_THAT(node_config2, EqualsProto(node_config1));
// Add an invalid character into the name.
+13 -13
View File
@@ -52,13 +52,13 @@ namespace tool {
<< " is not a registered packet generator.");
CalculatorContract contract;
RETURN_IF_ERROR(contract.Initialize(config));
MP_RETURN_IF_ERROR(contract.Initialize(config));
{
LegacyCalculatorSupport::Scoped<CalculatorContract> s(&contract);
RETURN_IF_ERROR(static_access->FillExpectations(
config.options(), &contract.InputSidePackets(),
&contract.OutputSidePackets()))
MP_RETURN_IF_ERROR(static_access->FillExpectations(
config.options(), &contract.InputSidePackets(),
&contract.OutputSidePackets()))
.SetPrepend()
<< config.packet_generator() << "::FillExpectations failed: ";
}
@@ -89,30 +89,30 @@ namespace tool {
PacketTypeSet output_side_packet_types(output_side_packets->TagMap());
// Fill the PacketTypeSets with type information.
RETURN_IF_ERROR(static_access->FillExpectations(extendable_options,
&input_side_packet_types,
&output_side_packet_types))
MP_RETURN_IF_ERROR(static_access->FillExpectations(extendable_options,
&input_side_packet_types,
&output_side_packet_types))
.SetPrepend()
<< packet_generator_name << "::FillExpectations failed: ";
// Check that the types were filled well.
std::vector<::mediapipe::Status> statuses;
statuses.push_back(ValidatePacketTypeSet(input_side_packet_types));
statuses.push_back(ValidatePacketTypeSet(output_side_packet_types));
RETURN_IF_ERROR(tool::CombinedStatus(
MP_RETURN_IF_ERROR(tool::CombinedStatus(
absl::StrCat(packet_generator_name, "::FillExpectations failed: "),
statuses));
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
ValidatePacketSet(input_side_packet_types, input_side_packets))
.SetPrepend()
<< packet_generator_name
<< "::FillExpectations expected different input type than those given: ";
RETURN_IF_ERROR(static_access->Generate(extendable_options,
input_side_packets,
output_side_packets))
MP_RETURN_IF_ERROR(static_access->Generate(extendable_options,
input_side_packets,
output_side_packets))
.SetPrepend()
<< packet_generator_name << "::Generate failed: ";
RETURN_IF_ERROR(
MP_RETURN_IF_ERROR(
ValidatePacketSet(output_side_packet_types, *output_side_packets))
.SetPrepend()
<< packet_generator_name