Project import generated by Copybara.
GitOrigin-RevId: d073f8e21be2fcc0e503cb97c6695078b6b75310
This commit is contained in:
@@ -96,6 +96,7 @@ cc_library(
|
||||
":validate_name",
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework/port:map_util",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
],
|
||||
@@ -128,16 +129,24 @@ cc_test(
|
||||
|
||||
cc_library(
|
||||
name = "options_util",
|
||||
srcs = ["options_util.cc"],
|
||||
hdrs = ["options_util.h"],
|
||||
visibility = ["//mediapipe/framework:mediapipe_internal"],
|
||||
deps = [
|
||||
":proto_util_lite",
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework:collection",
|
||||
"//mediapipe/framework:input_stream_shard",
|
||||
"//mediapipe/framework:output_side_packet",
|
||||
"//mediapipe/framework:packet",
|
||||
"//mediapipe/framework:packet_generator_cc_proto",
|
||||
"//mediapipe/framework:packet_set",
|
||||
"//mediapipe/framework:packet_type",
|
||||
"//mediapipe/framework:timestamp",
|
||||
"//mediapipe/framework/port:advanced_proto",
|
||||
"//mediapipe/framework/port:any_proto",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/tool:type_util",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -280,7 +289,6 @@ cc_library(
|
||||
|
||||
cc_library(
|
||||
name = "tag_map_helper",
|
||||
testonly = 1,
|
||||
srcs = ["tag_map_helper.cc"],
|
||||
hdrs = ["tag_map_helper.h"],
|
||||
visibility = ["//visibility:public"],
|
||||
@@ -578,26 +586,16 @@ cc_library(
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework/deps:file_path",
|
||||
"//mediapipe/framework/deps:no_destructor",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/port:advanced_proto",
|
||||
"//mediapipe/framework/port:file_helpers",
|
||||
"//mediapipe/framework/port:gtest",
|
||||
"//mediapipe/framework/port:logging",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework/deps:no_destructor",
|
||||
"//mediapipe/framework/port:logging",
|
||||
] + select({
|
||||
"//conditions:default": [
|
||||
"//mediapipe/framework/port:file_helpers",
|
||||
],
|
||||
"//mediapipe:android": [
|
||||
"//mediapipe/util/android/file/base",
|
||||
],
|
||||
"//mediapipe:ios": [],
|
||||
"//mediapipe:macos": [
|
||||
"//mediapipe/framework/port:file_helpers",
|
||||
],
|
||||
}),
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
||||
@@ -12,7 +12,7 @@ std::string ChannelTag(const std::string& tag, int channel) {
|
||||
// Parses a tag name starting with a channel prefix, like "C2__".
|
||||
bool ParseChannelTag(const std::string& channel_name, std::string* name,
|
||||
std::string* num) {
|
||||
int pos = channel_name.find("C");
|
||||
int pos = channel_name.find('C');
|
||||
int sep = channel_name.find("__");
|
||||
if (pos != 0 || sep == std::string::npos) {
|
||||
return false;
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
namespace mediapipe {
|
||||
namespace tool {
|
||||
|
||||
mediapipe::StatusOr<std::unique_ptr<PacketSet>> FillPacketSet(
|
||||
absl::StatusOr<std::unique_ptr<PacketSet>> FillPacketSet(
|
||||
const PacketTypeSet& input_side_packet_types,
|
||||
const std::map<std::string, Packet>& input_side_packets,
|
||||
int* missing_packet_count_ptr) {
|
||||
if (missing_packet_count_ptr != nullptr) {
|
||||
*missing_packet_count_ptr = 0;
|
||||
}
|
||||
std::vector<mediapipe::Status> errors;
|
||||
std::vector<absl::Status> errors;
|
||||
auto packet_set =
|
||||
absl::make_unique<PacketSet>(input_side_packet_types.TagMap());
|
||||
const auto& names = input_side_packet_types.TagMap()->Names();
|
||||
@@ -51,7 +51,7 @@ mediapipe::StatusOr<std::unique_ptr<PacketSet>> FillPacketSet(
|
||||
}
|
||||
packet_set->Get(id) = iter->second;
|
||||
// Check the type.
|
||||
mediapipe::Status status =
|
||||
absl::Status status =
|
||||
input_side_packet_types.Get(id).Validate(iter->second);
|
||||
if (!status.ok()) {
|
||||
std::pair<std::string, int> tag_index =
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace tool {
|
||||
// missing_packet_count_ptr is not null, the number of missing packets
|
||||
// is returned in *missing_packet_count_ptr. Otherwise, an error is
|
||||
// returned if any packets are missing.
|
||||
mediapipe::StatusOr<std::unique_ptr<PacketSet>> FillPacketSet(
|
||||
absl::StatusOr<std::unique_ptr<PacketSet>> FillPacketSet(
|
||||
const PacketTypeSet& input_side_packet_types,
|
||||
const std::map<std::string, Packet>& input_side_packets,
|
||||
int* missing_packet_count_ptr);
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST(FillPacketSetTest, Success) {
|
||||
node.add_input_side_packet("DOUBLE:1:side_packet4");
|
||||
|
||||
PacketTypeSet input_side_packet_types(
|
||||
tool::TagMap::Create(node.input_side_packet()).ValueOrDie());
|
||||
tool::TagMap::Create(node.input_side_packet()).value());
|
||||
input_side_packet_types.Index(0).Set<int>(
|
||||
// An age
|
||||
);
|
||||
@@ -57,7 +57,7 @@ TEST(FillPacketSetTest, Success) {
|
||||
|
||||
std::unique_ptr<PacketSet> input_side_packets =
|
||||
tool::FillPacketSet(input_side_packet_types, all_side_packets, nullptr)
|
||||
.ValueOrDie();
|
||||
.value();
|
||||
ASSERT_EQ(4, input_side_packets->NumEntries());
|
||||
EXPECT_EQ(input_side_packets->Index(0).Get<int>(), 70);
|
||||
EXPECT_EQ(input_side_packets->Index(1).Get<std::string>(), "Dennis Ritchie");
|
||||
@@ -73,7 +73,7 @@ TEST(FillPacketSetTest, MissingSidePacketError) {
|
||||
node.add_input_side_packet("DOUBLE:1:side_packet4");
|
||||
|
||||
PacketTypeSet input_side_packet_types(
|
||||
tool::TagMap::Create(node.input_side_packet()).ValueOrDie());
|
||||
tool::TagMap::Create(node.input_side_packet()).value());
|
||||
input_side_packet_types.Index(0).Set<int>(
|
||||
// An age
|
||||
);
|
||||
@@ -111,7 +111,7 @@ TEST(FillPacketSetTest, MissingSidePacketOk) {
|
||||
node.add_input_side_packet("DOUBLE:1:side_packet4");
|
||||
|
||||
PacketTypeSet input_side_packet_types(
|
||||
tool::TagMap::Create(node.input_side_packet()).ValueOrDie());
|
||||
tool::TagMap::Create(node.input_side_packet()).value());
|
||||
input_side_packet_types.Index(0).Set<int>(
|
||||
// An age
|
||||
);
|
||||
@@ -138,7 +138,7 @@ TEST(FillPacketSetTest, MissingSidePacketOk) {
|
||||
std::unique_ptr<PacketSet> input_side_packets =
|
||||
tool::FillPacketSet(input_side_packet_types, all_side_packets,
|
||||
&missing_packet_count)
|
||||
.ValueOrDie();
|
||||
.value();
|
||||
ASSERT_EQ(4, input_side_packets->NumEntries());
|
||||
EXPECT_EQ(1, missing_packet_count);
|
||||
EXPECT_EQ(input_side_packets->Index(0).Get<int>(), 70);
|
||||
@@ -155,7 +155,7 @@ TEST(FillPacketSetTest, WrongSidePacketType) {
|
||||
node.add_input_side_packet("DOUBLE:1:side_packet4");
|
||||
|
||||
PacketTypeSet input_side_packet_types(
|
||||
tool::TagMap::Create(node.input_side_packet()).ValueOrDie());
|
||||
tool::TagMap::Create(node.input_side_packet()).value());
|
||||
input_side_packet_types.Index(0).Set<int>(
|
||||
// An age
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "mediapipe/framework/port/map_util.h"
|
||||
@@ -47,16 +48,14 @@ std::string GetUnusedNodeName(const CalculatorGraphConfig& config,
|
||||
std::string GetUnusedSidePacketName(
|
||||
const CalculatorGraphConfig& config,
|
||||
const std::string& input_side_packet_name_base) {
|
||||
std::unordered_map<std::string,
|
||||
std::vector<::mediapipe::CalculatorGraphConfig::Node>>
|
||||
input_side_packets;
|
||||
absl::flat_hash_set<std::string> input_side_packets;
|
||||
for (const ::mediapipe::CalculatorGraphConfig::Node& node : config.node()) {
|
||||
for (const auto& tag_and_name : node.input_side_packet()) {
|
||||
std::string tag;
|
||||
std::string name;
|
||||
int index;
|
||||
MEDIAPIPE_CHECK_OK(ParseTagIndexName(tag_and_name, &tag, &index, &name));
|
||||
input_side_packets[name].push_back(node);
|
||||
input_side_packets.insert(name);
|
||||
}
|
||||
}
|
||||
std::string candidate = input_side_packet_name_base;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
#include "mediapipe/framework/tool/options_util.h"
|
||||
|
||||
#include "mediapipe/framework/port/proto_ns.h"
|
||||
|
||||
namespace mediapipe {
|
||||
namespace tool {
|
||||
|
||||
// TODO: Return registered protobuf Descriptors when available.
|
||||
const proto_ns::Descriptor* GetProtobufDescriptor(
|
||||
const std::string& type_name) {
|
||||
return proto_ns::DescriptorPool::generated_pool()->FindMessageTypeByName(
|
||||
type_name);
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/framework/input_stream_shard.h"
|
||||
#include "mediapipe/framework/packet.h"
|
||||
#include "mediapipe/framework/packet_generator.pb.h"
|
||||
#include "mediapipe/framework/packet_set.h"
|
||||
#include "mediapipe/framework/port/any_proto.h"
|
||||
#include "mediapipe/framework/tool/type_util.h"
|
||||
@@ -162,6 +161,9 @@ class OptionsMap {
|
||||
TypeMap options_;
|
||||
};
|
||||
|
||||
// Finds the descriptor for a protobuf.
|
||||
const proto_ns::Descriptor* GetProtobufDescriptor(const std::string& type_name);
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "mediapipe/framework/calculator_framework.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/framework/port/parse_text_proto.h"
|
||||
#include "mediapipe/framework/port/status_matchers.h"
|
||||
|
||||
namespace mediapipe {
|
||||
namespace {
|
||||
|
||||
// Tests for calculator and graph options.
|
||||
//
|
||||
class OptionsUtilTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
// Retrieves the description of a protobuf.
|
||||
TEST_F(OptionsUtilTest, GetProtobufDescriptor) {
|
||||
const proto_ns::Descriptor* descriptor =
|
||||
tool::GetProtobufDescriptor("mediapipe.CalculatorGraphConfig");
|
||||
#ifndef MEDIAPIPE_MOBILE
|
||||
EXPECT_NE(nullptr, descriptor);
|
||||
#else
|
||||
EXPECT_EQ(nullptr, descriptor);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediapipe
|
||||
@@ -42,8 +42,8 @@ bool IsLengthDelimited(WireFormatLite::WireType wire_type) {
|
||||
}
|
||||
|
||||
// Reads a single data value for a wire type.
|
||||
mediapipe::Status ReadFieldValue(uint32 tag, CodedInputStream* in,
|
||||
std::string* result) {
|
||||
absl::Status ReadFieldValue(uint32 tag, CodedInputStream* in,
|
||||
std::string* result) {
|
||||
WireFormatLite::WireType wire_type = WireFormatLite::GetTagWireType(tag);
|
||||
if (IsLengthDelimited(wire_type)) {
|
||||
uint32 length;
|
||||
@@ -59,13 +59,13 @@ mediapipe::Status ReadFieldValue(uint32 tag, CodedInputStream* in,
|
||||
cos.Trim();
|
||||
result->assign(field_data, tag_size, std::string::npos);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Reads the packed sequence of data values for a wire type.
|
||||
mediapipe::Status ReadPackedValues(WireFormatLite::WireType wire_type,
|
||||
CodedInputStream* in,
|
||||
std::vector<std::string>* field_values) {
|
||||
absl::Status ReadPackedValues(WireFormatLite::WireType wire_type,
|
||||
CodedInputStream* in,
|
||||
std::vector<std::string>* field_values) {
|
||||
uint32 data_size;
|
||||
RET_CHECK(in->ReadVarint32(&data_size));
|
||||
// fake_tag encodes the wire-type for calls to WireFormatLite::SkipField.
|
||||
@@ -77,15 +77,14 @@ mediapipe::Status ReadPackedValues(WireFormatLite::WireType wire_type,
|
||||
field_values->push_back(number);
|
||||
data_size -= number.size();
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Extracts the data value(s) for one field from a serialized message.
|
||||
// The message with these field values removed is written to |out|.
|
||||
mediapipe::Status GetFieldValues(uint32 field_id,
|
||||
WireFormatLite::WireType wire_type,
|
||||
CodedInputStream* in, CodedOutputStream* out,
|
||||
std::vector<std::string>* field_values) {
|
||||
absl::Status GetFieldValues(uint32 field_id, WireFormatLite::WireType wire_type,
|
||||
CodedInputStream* in, CodedOutputStream* out,
|
||||
std::vector<std::string>* field_values) {
|
||||
uint32 tag;
|
||||
while ((tag = in->ReadTag()) != 0) {
|
||||
int field_number = WireFormatLite::GetTagFieldNumber(tag);
|
||||
@@ -102,7 +101,7 @@ mediapipe::Status GetFieldValues(uint32 field_id,
|
||||
RET_CHECK(WireFormatLite::SkipField(in, tag, out));
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Injects the data value(s) for one field into a serialized message.
|
||||
@@ -122,7 +121,7 @@ void SetFieldValues(uint32 field_id, WireFormatLite::WireType wire_type,
|
||||
FieldAccess::FieldAccess(uint32 field_id, FieldType field_type)
|
||||
: field_id_(field_id), field_type_(field_type) {}
|
||||
|
||||
mediapipe::Status FieldAccess::SetMessage(const std::string& message) {
|
||||
absl::Status FieldAccess::SetMessage(const std::string& message) {
|
||||
ArrayInputStream ais(message.data(), message.size());
|
||||
CodedInputStream in(&ais);
|
||||
StringOutputStream sos(&message_);
|
||||
@@ -146,7 +145,7 @@ std::vector<FieldValue>* FieldAccess::mutable_field_values() {
|
||||
}
|
||||
|
||||
// Replaces a range of field values for one field nested within a protobuf.
|
||||
mediapipe::Status ProtoUtilLite::ReplaceFieldRange(
|
||||
absl::Status ProtoUtilLite::ReplaceFieldRange(
|
||||
FieldValue* message, ProtoPath proto_path, int length, FieldType field_type,
|
||||
const std::vector<FieldValue>& field_values) {
|
||||
int field_id, index;
|
||||
@@ -169,11 +168,11 @@ mediapipe::Status ProtoUtilLite::ReplaceFieldRange(
|
||||
}
|
||||
message->clear();
|
||||
access.GetMessage(message);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Returns a range of field values from one field nested within a protobuf.
|
||||
mediapipe::Status ProtoUtilLite::GetFieldRange(
|
||||
absl::Status ProtoUtilLite::GetFieldRange(
|
||||
const FieldValue& message, ProtoPath proto_path, int length,
|
||||
FieldType field_type, std::vector<FieldValue>* field_values) {
|
||||
int field_id, index;
|
||||
@@ -194,40 +193,40 @@ mediapipe::Status ProtoUtilLite::GetFieldRange(
|
||||
field_values->insert(field_values->begin(), v.begin() + index,
|
||||
v.begin() + index + length);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// If ok, returns OkStatus, otherwise returns InvalidArgumentError.
|
||||
template <typename T>
|
||||
mediapipe::Status SyntaxStatus(bool ok, const std::string& text, T* result) {
|
||||
return ok ? mediapipe::OkStatus()
|
||||
: mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
absl::Status SyntaxStatus(bool ok, const std::string& text, T* result) {
|
||||
return ok ? absl::OkStatus()
|
||||
: absl::InvalidArgumentError(absl::StrCat(
|
||||
"Syntax error: \"", text, "\"",
|
||||
" for type: ", MediaPipeTypeStringOrDemangled<T>(), "."));
|
||||
}
|
||||
|
||||
// Templated parsing of a std::string value.
|
||||
template <typename T>
|
||||
mediapipe::Status ParseValue(const std::string& text, T* result) {
|
||||
absl::Status ParseValue(const std::string& text, T* result) {
|
||||
return SyntaxStatus(absl::SimpleAtoi(text, result), text, result);
|
||||
}
|
||||
template <>
|
||||
mediapipe::Status ParseValue<double>(const std::string& text, double* result) {
|
||||
absl::Status ParseValue<double>(const std::string& text, double* result) {
|
||||
return SyntaxStatus(absl::SimpleAtod(text, result), text, result);
|
||||
}
|
||||
template <>
|
||||
mediapipe::Status ParseValue<float>(const std::string& text, float* result) {
|
||||
absl::Status ParseValue<float>(const std::string& text, float* result) {
|
||||
return SyntaxStatus(absl::SimpleAtof(text, result), text, result);
|
||||
}
|
||||
template <>
|
||||
mediapipe::Status ParseValue<bool>(const std::string& text, bool* result) {
|
||||
absl::Status ParseValue<bool>(const std::string& text, bool* result) {
|
||||
return SyntaxStatus(absl::SimpleAtob(text, result), text, result);
|
||||
}
|
||||
template <>
|
||||
mediapipe::Status ParseValue<std::string>(const std::string& text,
|
||||
std::string* result) {
|
||||
absl::Status ParseValue<std::string>(const std::string& text,
|
||||
std::string* result) {
|
||||
*result = text;
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Templated formatting of a primitive value.
|
||||
@@ -238,20 +237,19 @@ std::string FormatValue(T v) {
|
||||
|
||||
// A helper function to parse and serialize one primtive value.
|
||||
template <typename T>
|
||||
mediapipe::Status WritePrimitive(
|
||||
void (*writer)(T, proto_ns::io::CodedOutputStream*),
|
||||
const std::string& text, CodedOutputStream* out) {
|
||||
absl::Status WritePrimitive(void (*writer)(T, proto_ns::io::CodedOutputStream*),
|
||||
const std::string& text, CodedOutputStream* out) {
|
||||
T value;
|
||||
MP_RETURN_IF_ERROR(ParseValue<T>(text, &value));
|
||||
(*writer)(value, out);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Serializes a protobuf FieldValue.
|
||||
static mediapipe::Status SerializeValue(const std::string& text,
|
||||
FieldType field_type,
|
||||
FieldValue* field_value) {
|
||||
mediapipe::Status status;
|
||||
static absl::Status SerializeValue(const std::string& text,
|
||||
FieldType field_type,
|
||||
FieldValue* field_value) {
|
||||
absl::Status status;
|
||||
StringOutputStream sos(field_value);
|
||||
CodedOutputStream out(&sos);
|
||||
|
||||
@@ -277,11 +275,11 @@ static mediapipe::Status SerializeValue(const std::string& text,
|
||||
case W::TYPE_BYTES:
|
||||
case W::TYPE_STRING: {
|
||||
out.WriteRaw(text.data(), text.size());
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
case W::TYPE_GROUP:
|
||||
case W::TYPE_MESSAGE:
|
||||
return mediapipe::UnimplementedError(
|
||||
return absl::UnimplementedError(
|
||||
"SerializeValue cannot serialize a Message.");
|
||||
case W::TYPE_UINT32:
|
||||
return WritePrimitive(W::WriteUInt32NoTag, text, &out);
|
||||
@@ -296,27 +294,27 @@ static mediapipe::Status SerializeValue(const std::string& text,
|
||||
case W::TYPE_SINT64:
|
||||
return WritePrimitive(W::WriteSInt64NoTag, text, &out);
|
||||
}
|
||||
return mediapipe::UnimplementedError("SerializeValue unimplemented type.");
|
||||
return absl::UnimplementedError("SerializeValue unimplemented type.");
|
||||
}
|
||||
|
||||
// A helper function for deserializing one text value.
|
||||
template <typename CType, FieldType DeclaredType>
|
||||
static mediapipe::Status ReadPrimitive(CodedInputStream* input,
|
||||
std::string* result) {
|
||||
static absl::Status ReadPrimitive(CodedInputStream* input,
|
||||
std::string* result) {
|
||||
CType value;
|
||||
if (!WireFormatLite::ReadPrimitive<CType, DeclaredType>(input, &value)) {
|
||||
return mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
return absl::InvalidArgumentError(absl::StrCat(
|
||||
"Bad serialized value: ", MediaPipeTypeStringOrDemangled<CType>(),
|
||||
"."));
|
||||
}
|
||||
*result = FormatValue(value);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Deserializes a protobuf FieldValue.
|
||||
static mediapipe::Status DeserializeValue(const FieldValue& bytes,
|
||||
FieldType field_type,
|
||||
std::string* result) {
|
||||
static absl::Status DeserializeValue(const FieldValue& bytes,
|
||||
FieldType field_type,
|
||||
std::string* result) {
|
||||
ArrayInputStream ais(bytes.data(), bytes.size());
|
||||
CodedInputStream input(&ais);
|
||||
typedef WireFormatLite W;
|
||||
@@ -340,7 +338,7 @@ static mediapipe::Status DeserializeValue(const FieldValue& bytes,
|
||||
case W::TYPE_BYTES:
|
||||
case W::TYPE_STRING: {
|
||||
*result = bytes;
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
case W::TYPE_GROUP:
|
||||
case W::TYPE_MESSAGE:
|
||||
@@ -358,10 +356,10 @@ static mediapipe::Status DeserializeValue(const FieldValue& bytes,
|
||||
case W::TYPE_SINT64:
|
||||
return ReadPrimitive<proto_int64, W::TYPE_SINT64>(&input, result);
|
||||
}
|
||||
return mediapipe::UnimplementedError("DeserializeValue unimplemented type.");
|
||||
return absl::UnimplementedError("DeserializeValue unimplemented type.");
|
||||
}
|
||||
|
||||
mediapipe::Status ProtoUtilLite::Serialize(
|
||||
absl::Status ProtoUtilLite::Serialize(
|
||||
const std::vector<std::string>& text_values, FieldType field_type,
|
||||
std::vector<FieldValue>* result) {
|
||||
result->clear();
|
||||
@@ -371,10 +369,10 @@ mediapipe::Status ProtoUtilLite::Serialize(
|
||||
MP_RETURN_IF_ERROR(SerializeValue(text_value, field_type, &field_value));
|
||||
result->push_back(field_value);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ProtoUtilLite::Deserialize(
|
||||
absl::Status ProtoUtilLite::Deserialize(
|
||||
const std::vector<FieldValue>& field_values, FieldType field_type,
|
||||
std::vector<std::string>* result) {
|
||||
result->clear();
|
||||
@@ -384,7 +382,7 @@ mediapipe::Status ProtoUtilLite::Deserialize(
|
||||
MP_RETURN_IF_ERROR(DeserializeValue(field_value, field_type, &text_value));
|
||||
result->push_back(text_value);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -47,7 +47,7 @@ class ProtoUtilLite {
|
||||
FieldAccess(uint32 field_id, FieldType field_type);
|
||||
|
||||
// Specifies the original serialized protobuf message.
|
||||
mediapipe::Status SetMessage(const FieldValue& message);
|
||||
absl::Status SetMessage(const FieldValue& message);
|
||||
|
||||
// Returns the serialized protobuf message with updated field values.
|
||||
void GetMessage(FieldValue* result);
|
||||
@@ -64,26 +64,26 @@ class ProtoUtilLite {
|
||||
|
||||
// Replace a range of field values nested within a protobuf.
|
||||
// Starting at the proto_path index, "length" values are replaced.
|
||||
static mediapipe::Status ReplaceFieldRange(
|
||||
static absl::Status ReplaceFieldRange(
|
||||
FieldValue* message, ProtoPath proto_path, int length,
|
||||
FieldType field_type, const std::vector<FieldValue>& field_values);
|
||||
|
||||
// Retrieve a range of field values nested within a protobuf.
|
||||
// Starting at the proto_path index, "length" values are retrieved.
|
||||
static mediapipe::Status GetFieldRange(const FieldValue& message,
|
||||
ProtoPath proto_path, int length,
|
||||
FieldType field_type,
|
||||
std::vector<FieldValue>* field_values);
|
||||
static absl::Status GetFieldRange(const FieldValue& message,
|
||||
ProtoPath proto_path, int length,
|
||||
FieldType field_type,
|
||||
std::vector<FieldValue>* field_values);
|
||||
|
||||
// Serialize one or more protobuf field values from text.
|
||||
static mediapipe::Status Serialize(
|
||||
const std::vector<std::string>& text_values, FieldType field_type,
|
||||
std::vector<FieldValue>* result);
|
||||
static absl::Status Serialize(const std::vector<std::string>& text_values,
|
||||
FieldType field_type,
|
||||
std::vector<FieldValue>* result);
|
||||
|
||||
// Deserialize one or more protobuf field values to text.
|
||||
static mediapipe::Status Deserialize(
|
||||
const std::vector<FieldValue>& field_values, FieldType field_type,
|
||||
std::vector<std::string>* result);
|
||||
static absl::Status Deserialize(const std::vector<FieldValue>& field_values,
|
||||
FieldType field_type,
|
||||
std::vector<std::string>* result);
|
||||
};
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -20,24 +20,26 @@
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
// clang-format off
|
||||
static const char binary_graph[] =
|
||||
#include "{{SUBGRAPH_INC_FILE_PATH}}"
|
||||
; // NOLINT(whitespace/semicolon)
|
||||
|
||||
class {{SUBGRAPH_CLASS_NAME}} : public Subgraph {
|
||||
public:
|
||||
::mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& /*options*/) {
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& /*options*/) {
|
||||
CalculatorGraphConfig config;
|
||||
// Note: this is a binary protobuf serialization, and may include NUL
|
||||
// bytes. The trailing NUL added to the std::string literal should be excluded.
|
||||
if (config.ParseFromArray(binary_graph, sizeof(binary_graph) - 1)) {
|
||||
return config;
|
||||
} else {
|
||||
return ::mediapipe::InternalError("Could not parse subgraph.");
|
||||
return absl::InternalError("Could not parse subgraph.");
|
||||
}
|
||||
}
|
||||
};
|
||||
REGISTER_MEDIAPIPE_GRAPH({{SUBGRAPH_CLASS_NAME}});
|
||||
// clang-format on
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -177,19 +177,19 @@ TEST_F(SimulationClockTest, DuplicateWakeTimes) {
|
||||
}
|
||||
|
||||
// A Calculator::Process callback function.
|
||||
typedef std::function<mediapipe::Status(const InputStreamShardSet&,
|
||||
OutputStreamShardSet*)>
|
||||
typedef std::function<absl::Status(const InputStreamShardSet&,
|
||||
OutputStreamShardSet*)>
|
||||
ProcessFunction;
|
||||
|
||||
// A testing callback function that passes through all packets.
|
||||
mediapipe::Status PassThrough(const InputStreamShardSet& inputs,
|
||||
OutputStreamShardSet* outputs) {
|
||||
absl::Status PassThrough(const InputStreamShardSet& inputs,
|
||||
OutputStreamShardSet* outputs) {
|
||||
for (int i = 0; i < inputs.NumEntries(); ++i) {
|
||||
if (!inputs.Index(i).Value().IsEmpty()) {
|
||||
outputs->Index(i).AddPacket(inputs.Index(i).Value());
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// This test shows sim clock synchronizing a bunch of parallel tasks.
|
||||
@@ -267,7 +267,7 @@ TEST_F(SimulationClockTest, DestroyClock) {
|
||||
if (++input_count < 4) {
|
||||
outputs->Index(0).AddPacket(
|
||||
MakePacket<uint64>(input_count).At(Timestamp(input_count)));
|
||||
return ::mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
} else {
|
||||
return tool::StatusStop();
|
||||
}
|
||||
@@ -279,7 +279,7 @@ TEST_F(SimulationClockTest, DestroyClock) {
|
||||
};
|
||||
|
||||
std::vector<Packet> out_packets;
|
||||
::mediapipe::Status status;
|
||||
absl::Status status;
|
||||
{
|
||||
CalculatorGraph graph;
|
||||
auto executor = std::make_shared<SimulationClockExecutor>(4);
|
||||
|
||||
@@ -45,20 +45,20 @@ namespace {
|
||||
class MediaPipeInternalSidePacketToPacketStreamCalculator
|
||||
: public CalculatorBase {
|
||||
public:
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
cc->InputSidePackets().Index(0).SetAny();
|
||||
cc->Outputs().Index(0).SetSameAs(&cc->InputSidePackets().Index(0));
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) final {
|
||||
absl::Status Open(CalculatorContext* cc) final {
|
||||
cc->Outputs().Index(0).AddPacket(
|
||||
cc->InputSidePackets().Index(0).At(Timestamp::PostStream()));
|
||||
cc->Outputs().Index(0).Close();
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Process(CalculatorContext* cc) final {
|
||||
absl::Status Process(CalculatorContext* cc) final {
|
||||
// The framework treats this calculator as a source calculator.
|
||||
return mediapipe::tool::StatusStop();
|
||||
}
|
||||
@@ -222,7 +222,7 @@ void AddCallbackWithHeaderCalculator(const std::string& stream_name,
|
||||
// CallbackCalculator
|
||||
|
||||
// static
|
||||
mediapipe::Status CallbackCalculator::GetContract(CalculatorContract* cc) {
|
||||
absl::Status CallbackCalculator::GetContract(CalculatorContract* cc) {
|
||||
bool allow_multiple_streams = false;
|
||||
// If the input side packet is specified using tag "CALLBACK" it must contain
|
||||
// a std::function, which may be generated by CallbackPacketCalculator.
|
||||
@@ -246,10 +246,10 @@ mediapipe::Status CallbackCalculator::GetContract(CalculatorContract* cc) {
|
||||
cc->Inputs().Index(i).SetAny();
|
||||
}
|
||||
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status CallbackCalculator::Open(CalculatorContext* cc) {
|
||||
absl::Status CallbackCalculator::Open(CalculatorContext* cc) {
|
||||
if (cc->InputSidePackets().HasTag("CALLBACK")) {
|
||||
callback_ = cc->InputSidePackets()
|
||||
.Tag("CALLBACK")
|
||||
@@ -266,10 +266,10 @@ mediapipe::Status CallbackCalculator::Open(CalculatorContext* cc) {
|
||||
return mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
|
||||
<< "missing callback.";
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status CallbackCalculator::Process(CalculatorContext* cc) {
|
||||
absl::Status CallbackCalculator::Process(CalculatorContext* cc) {
|
||||
if (callback_) {
|
||||
callback_(cc->Inputs().Index(0).Value());
|
||||
} else if (vector_callback_) {
|
||||
@@ -281,7 +281,7 @@ mediapipe::Status CallbackCalculator::Process(CalculatorContext* cc) {
|
||||
}
|
||||
vector_callback_(packets);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
REGISTER_CALCULATOR(CallbackCalculator);
|
||||
@@ -289,8 +289,7 @@ REGISTER_CALCULATOR(CallbackCalculator);
|
||||
// CallbackWithHeaderCalculator
|
||||
|
||||
// static
|
||||
mediapipe::Status CallbackWithHeaderCalculator::GetContract(
|
||||
CalculatorContract* cc) {
|
||||
absl::Status CallbackWithHeaderCalculator::GetContract(CalculatorContract* cc) {
|
||||
cc->Inputs().Tag("INPUT").SetAny();
|
||||
cc->Inputs().Tag("HEADER").SetAny();
|
||||
|
||||
@@ -303,10 +302,10 @@ mediapipe::Status CallbackWithHeaderCalculator::GetContract(
|
||||
return mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
|
||||
<< "InputSidePackets must use tags.";
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status CallbackWithHeaderCalculator::Open(CalculatorContext* cc) {
|
||||
absl::Status CallbackWithHeaderCalculator::Open(CalculatorContext* cc) {
|
||||
if (cc->InputSidePackets().UsesTags()) {
|
||||
callback_ = cc->InputSidePackets()
|
||||
.Tag("CALLBACK")
|
||||
@@ -333,10 +332,10 @@ mediapipe::Status CallbackWithHeaderCalculator::Open(CalculatorContext* cc) {
|
||||
if (!cc->Inputs().Tag("INPUT").Header().IsEmpty()) {
|
||||
header_packet_ = cc->Inputs().Tag("INPUT").Header();
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status CallbackWithHeaderCalculator::Process(CalculatorContext* cc) {
|
||||
absl::Status CallbackWithHeaderCalculator::Process(CalculatorContext* cc) {
|
||||
if (!cc->Inputs().Tag("INPUT").Value().IsEmpty() &&
|
||||
header_packet_.IsEmpty()) {
|
||||
// Header packet should be available before we receive any normal input
|
||||
@@ -351,7 +350,7 @@ mediapipe::Status CallbackWithHeaderCalculator::Process(CalculatorContext* cc) {
|
||||
if (!cc->Inputs().Tag("INPUT").Value().IsEmpty()) {
|
||||
callback_(cc->Inputs().Tag("INPUT").Value(), header_packet_);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
REGISTER_CALCULATOR(CallbackWithHeaderCalculator);
|
||||
|
||||
@@ -166,10 +166,10 @@ class CallbackCalculator : public CalculatorBase {
|
||||
|
||||
~CallbackCalculator() override {}
|
||||
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc);
|
||||
static absl::Status GetContract(CalculatorContract* cc);
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) override;
|
||||
mediapipe::Status Process(CalculatorContext* cc) override;
|
||||
absl::Status Open(CalculatorContext* cc) override;
|
||||
absl::Status Process(CalculatorContext* cc) override;
|
||||
|
||||
private:
|
||||
std::function<void(const Packet&)> callback_;
|
||||
@@ -185,10 +185,10 @@ class CallbackWithHeaderCalculator : public CalculatorBase {
|
||||
|
||||
~CallbackWithHeaderCalculator() override {}
|
||||
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc);
|
||||
static absl::Status GetContract(CalculatorContract* cc);
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) override;
|
||||
mediapipe::Status Process(CalculatorContext* cc) override;
|
||||
absl::Status Open(CalculatorContext* cc) override;
|
||||
absl::Status Process(CalculatorContext* cc) override;
|
||||
|
||||
private:
|
||||
std::function<void(const Packet&, const Packet&)> callback_;
|
||||
|
||||
@@ -31,21 +31,21 @@ namespace mediapipe {
|
||||
namespace {
|
||||
class CountAndOutputSummarySidePacketInCloseCalculator : public CalculatorBase {
|
||||
public:
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
cc->Inputs().Index(0).SetAny();
|
||||
cc->OutputSidePackets().Index(0).Set<int>();
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Process(CalculatorContext* cc) final {
|
||||
absl::Status Process(CalculatorContext* cc) final {
|
||||
++count_;
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Close(CalculatorContext* cc) final {
|
||||
absl::Status Close(CalculatorContext* cc) final {
|
||||
cc->OutputSidePackets().Index(0).Set(
|
||||
MakePacket<int>(count_).At(Timestamp::Unset()));
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
int count_ = 0;
|
||||
|
||||
@@ -43,19 +43,19 @@ class SidePacketsToStreamsCalculator : public CalculatorBase {
|
||||
const SidePacketsToStreamsCalculator&) = delete;
|
||||
~SidePacketsToStreamsCalculator() override {}
|
||||
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
auto& options = cc->Options<SidePacketsToStreamsCalculatorOptions>();
|
||||
if (options.has_num_inputs() &&
|
||||
(options.num_inputs() != cc->InputSidePackets().NumEntries() ||
|
||||
options.num_inputs() != cc->Outputs().NumEntries())) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"If num_inputs is specified it must be equal to the number of "
|
||||
"input side packets and output streams.");
|
||||
}
|
||||
if (!options.vectors_of_packets() &&
|
||||
options.set_timestamp() ==
|
||||
SidePacketsToStreamsCalculatorOptions::NONE) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"If set_timestamp is NONE, vectors_of_packets must not be false.");
|
||||
}
|
||||
for (int i = 0; i < cc->InputSidePackets().NumEntries(); ++i) {
|
||||
@@ -72,10 +72,10 @@ class SidePacketsToStreamsCalculator : public CalculatorBase {
|
||||
cc->Outputs().Index(i).SetSameAs(&cc->InputSidePackets().Index(i));
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Process(CalculatorContext* cc) final {
|
||||
absl::Status Process(CalculatorContext* cc) final {
|
||||
const auto& options = cc->Options<SidePacketsToStreamsCalculatorOptions>();
|
||||
// The i-th input side packet contains a vector of packets corresponding
|
||||
// to the values of this input for all batch elements.
|
||||
@@ -87,7 +87,7 @@ class SidePacketsToStreamsCalculator : public CalculatorBase {
|
||||
const auto& packets = input_side_packet.Get<std::vector<Packet>>();
|
||||
if (batch_size >= 0) {
|
||||
if (packets.size() != batch_size) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"The specified input side packets contain vectors of different "
|
||||
"sizes.");
|
||||
}
|
||||
|
||||
@@ -22,46 +22,44 @@
|
||||
namespace mediapipe {
|
||||
namespace tool {
|
||||
|
||||
mediapipe::Status StatusInvalid(const std::string& message) {
|
||||
return mediapipe::Status(mediapipe::StatusCode::kInvalidArgument, message);
|
||||
absl::Status StatusInvalid(const std::string& message) {
|
||||
return absl::Status(absl::StatusCode::kInvalidArgument, message);
|
||||
}
|
||||
|
||||
mediapipe::Status StatusFail(const std::string& message) {
|
||||
return mediapipe::Status(mediapipe::StatusCode::kUnknown, message);
|
||||
absl::Status StatusFail(const std::string& message) {
|
||||
return absl::Status(absl::StatusCode::kUnknown, message);
|
||||
}
|
||||
|
||||
mediapipe::Status StatusStop() {
|
||||
return mediapipe::Status(mediapipe::StatusCode::kOutOfRange,
|
||||
"mediapipe::tool::StatusStop()");
|
||||
absl::Status StatusStop() {
|
||||
return absl::Status(absl::StatusCode::kOutOfRange,
|
||||
"mediapipe::tool::StatusStop()");
|
||||
}
|
||||
|
||||
mediapipe::Status AddStatusPrefix(const std::string& prefix,
|
||||
const mediapipe::Status& status) {
|
||||
return mediapipe::Status(status.code(),
|
||||
absl::StrCat(prefix, status.message()));
|
||||
absl::Status AddStatusPrefix(const std::string& prefix,
|
||||
const absl::Status& status) {
|
||||
return absl::Status(status.code(), absl::StrCat(prefix, status.message()));
|
||||
}
|
||||
|
||||
mediapipe::Status CombinedStatus(
|
||||
const std::string& general_comment,
|
||||
const std::vector<mediapipe::Status>& statuses) {
|
||||
// The final error code is mediapipe::StatusCode::kUnknown if not all
|
||||
absl::Status CombinedStatus(const std::string& general_comment,
|
||||
const std::vector<absl::Status>& statuses) {
|
||||
// The final error code is absl::StatusCode::kUnknown if not all
|
||||
// the error codes are the same. Otherwise it is the same error code
|
||||
// as all of the (non-OK) statuses. If statuses is empty or they are
|
||||
// all OK, then mediapipe::OkStatus() is returned.
|
||||
mediapipe::StatusCode error_code = mediapipe::StatusCode::kOk;
|
||||
// all OK, then absl::OkStatus() is returned.
|
||||
absl::StatusCode error_code = absl::StatusCode::kOk;
|
||||
std::vector<std::string> errors;
|
||||
for (const mediapipe::Status& status : statuses) {
|
||||
for (const absl::Status& status : statuses) {
|
||||
if (!status.ok()) {
|
||||
errors.emplace_back(status.message());
|
||||
if (error_code == mediapipe::StatusCode::kOk) {
|
||||
if (error_code == absl::StatusCode::kOk) {
|
||||
error_code = status.code();
|
||||
} else if (error_code != status.code()) {
|
||||
error_code = mediapipe::StatusCode::kUnknown;
|
||||
error_code = absl::StatusCode::kUnknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error_code == StatusCode::kOk) return OkStatus();
|
||||
Status combined = mediapipe::Status(
|
||||
Status combined = absl::Status(
|
||||
error_code,
|
||||
absl::StrCat(general_comment, "\n", absl::StrJoin(errors, "\n")));
|
||||
return combined;
|
||||
|
||||
@@ -29,31 +29,30 @@ namespace tool {
|
||||
// be called on it again). When returned from a non-source Calculator
|
||||
// it signals that the graph should be cancelled (which is handled by
|
||||
// closing all source Calculators and waiting for the graph to finish).
|
||||
mediapipe::Status StatusStop();
|
||||
absl::Status StatusStop();
|
||||
|
||||
// Return a status which signals an invalid initial condition (for
|
||||
// example an InputSidePacket does not include all necessary fields).
|
||||
ABSL_DEPRECATED("Use mediapipe::InvalidArgumentError(error_message) instead.")
|
||||
mediapipe::Status StatusInvalid(const std::string& error_message);
|
||||
ABSL_DEPRECATED("Use absl::InvalidArgumentError(error_message) instead.")
|
||||
absl::Status StatusInvalid(const std::string& error_message);
|
||||
|
||||
// Return a status which signals that something unexpectedly failed.
|
||||
ABSL_DEPRECATED("Use mediapipe::UnknownError(error_message) instead.")
|
||||
mediapipe::Status StatusFail(const std::string& error_message);
|
||||
ABSL_DEPRECATED("Use absl::UnknownError(error_message) instead.")
|
||||
absl::Status StatusFail(const std::string& error_message);
|
||||
|
||||
// Prefixes the given std::string to the error message in status.
|
||||
// This function should be considered internal to the framework.
|
||||
// TODO Replace usage of AddStatusPrefix with util::Annotate().
|
||||
mediapipe::Status AddStatusPrefix(const std::string& prefix,
|
||||
const mediapipe::Status& status);
|
||||
absl::Status AddStatusPrefix(const std::string& prefix,
|
||||
const absl::Status& status);
|
||||
|
||||
// Combine a vector of mediapipe::Status into a single composite status.
|
||||
// If statuses is empty or all statuses are OK then mediapipe::OkStatus()
|
||||
// Combine a vector of absl::Status into a single composite status.
|
||||
// If statuses is empty or all statuses are OK then absl::OkStatus()
|
||||
// will be returned.
|
||||
// This function should be considered internal to the framework.
|
||||
// TODO Move this function to somewhere with less visibility.
|
||||
mediapipe::Status CombinedStatus(
|
||||
const std::string& general_comment,
|
||||
const std::vector<mediapipe::Status>& statuses);
|
||||
absl::Status CombinedStatus(const std::string& general_comment,
|
||||
const std::vector<absl::Status>& statuses);
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -36,24 +36,24 @@ TEST(StatusTest, StatusStopIsNotOk) { EXPECT_FALSE(tool::StatusStop().ok()); }
|
||||
TEST(StatusTest, Prefix) {
|
||||
const std::string base_error_message("error_with_this_string");
|
||||
const std::string prefix_error_message("error_with_prefix: ");
|
||||
mediapipe::Status base_status = mediapipe::Status(
|
||||
mediapipe::StatusCode::kInvalidArgument, base_error_message);
|
||||
mediapipe::Status status =
|
||||
absl::Status base_status =
|
||||
absl::Status(absl::StatusCode::kInvalidArgument, base_error_message);
|
||||
absl::Status status =
|
||||
tool::AddStatusPrefix(prefix_error_message, base_status);
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(base_error_message));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(prefix_error_message));
|
||||
EXPECT_EQ(mediapipe::StatusCode::kInvalidArgument, status.code());
|
||||
EXPECT_EQ(absl::StatusCode::kInvalidArgument, status.code());
|
||||
}
|
||||
|
||||
TEST(StatusTest, CombinedStatus) {
|
||||
std::vector<mediapipe::Status> errors;
|
||||
std::vector<absl::Status> errors;
|
||||
const std::string prefix_error_message("error_with_prefix: ");
|
||||
mediapipe::Status status;
|
||||
absl::Status status;
|
||||
|
||||
errors.clear();
|
||||
errors.emplace_back(mediapipe::StatusCode::kInvalidArgument,
|
||||
errors.emplace_back(absl::StatusCode::kInvalidArgument,
|
||||
"error_with_this_string");
|
||||
errors.emplace_back(mediapipe::StatusCode::kInvalidArgument,
|
||||
errors.emplace_back(absl::StatusCode::kInvalidArgument,
|
||||
"error_with_that_string");
|
||||
errors.back().SetPayload("test payload type",
|
||||
absl::Cord(absl::string_view("hello")));
|
||||
@@ -61,30 +61,29 @@ TEST(StatusTest, CombinedStatus) {
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(std::string(errors[0].message())));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(std::string(errors[1].message())));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(prefix_error_message));
|
||||
EXPECT_EQ(mediapipe::StatusCode::kInvalidArgument, status.code());
|
||||
EXPECT_EQ(absl::StatusCode::kInvalidArgument, status.code());
|
||||
|
||||
errors.clear();
|
||||
errors.emplace_back(mediapipe::StatusCode::kNotFound,
|
||||
"error_with_this_string");
|
||||
errors.emplace_back(mediapipe::StatusCode::kInvalidArgument,
|
||||
errors.emplace_back(absl::StatusCode::kNotFound, "error_with_this_string");
|
||||
errors.emplace_back(absl::StatusCode::kInvalidArgument,
|
||||
"error_with_that_string");
|
||||
status = tool::CombinedStatus(prefix_error_message, errors);
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(std::string(errors[0].message())));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(std::string(errors[1].message())));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(prefix_error_message));
|
||||
EXPECT_EQ(mediapipe::StatusCode::kUnknown, status.code());
|
||||
EXPECT_EQ(absl::StatusCode::kUnknown, status.code());
|
||||
errors.clear();
|
||||
errors.emplace_back(mediapipe::StatusCode::kOk, "error_with_this_string");
|
||||
errors.emplace_back(mediapipe::StatusCode::kInvalidArgument,
|
||||
errors.emplace_back(absl::StatusCode::kOk, "error_with_this_string");
|
||||
errors.emplace_back(absl::StatusCode::kInvalidArgument,
|
||||
"error_with_that_string");
|
||||
status = tool::CombinedStatus(prefix_error_message, errors);
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(std::string(errors[1].message())));
|
||||
EXPECT_THAT(status.ToString(), HasSubstr(prefix_error_message));
|
||||
EXPECT_EQ(mediapipe::StatusCode::kInvalidArgument, status.code());
|
||||
EXPECT_EQ(absl::StatusCode::kInvalidArgument, status.code());
|
||||
|
||||
errors.clear();
|
||||
errors.emplace_back(mediapipe::StatusCode::kOk, "error_with_this_string");
|
||||
errors.emplace_back(mediapipe::StatusCode::kOk, "error_with_that_string");
|
||||
errors.emplace_back(absl::StatusCode::kOk, "error_with_this_string");
|
||||
errors.emplace_back(absl::StatusCode::kOk, "error_with_that_string");
|
||||
MP_EXPECT_OK(tool::CombinedStatus(prefix_error_message, errors));
|
||||
|
||||
errors.clear();
|
||||
@@ -93,13 +92,13 @@ TEST(StatusTest, CombinedStatus) {
|
||||
|
||||
// Verify tool::StatusInvalid() and tool::StatusFail() and the alternatives
|
||||
// recommended by their ABSL_DEPRECATED messages return the same
|
||||
// mediapipe::Status objects.
|
||||
// absl::Status objects.
|
||||
TEST(StatusTest, Deprecated) {
|
||||
const std::string error_message = "an error message";
|
||||
EXPECT_EQ(tool::StatusInvalid(error_message), // NOLINT
|
||||
mediapipe::InvalidArgumentError(error_message));
|
||||
absl::InvalidArgumentError(error_message));
|
||||
EXPECT_EQ(tool::StatusFail(error_message), // NOLINT
|
||||
mediapipe::UnknownError(error_message));
|
||||
absl::UnknownError(error_message));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -42,22 +42,22 @@ namespace mediapipe {
|
||||
|
||||
namespace tool {
|
||||
|
||||
mediapipe::Status TransformStreamNames(
|
||||
absl::Status TransformStreamNames(
|
||||
proto_ns::RepeatedPtrField<ProtoString>* streams,
|
||||
const std::function<std::string(absl::string_view)>& transform) {
|
||||
for (auto& stream : *streams) {
|
||||
absl::string_view port_and_name(stream);
|
||||
auto colon_pos = port_and_name.find_last_of(":");
|
||||
auto colon_pos = port_and_name.find_last_of(':');
|
||||
auto name_pos = colon_pos == absl::string_view::npos ? 0 : colon_pos + 1;
|
||||
stream =
|
||||
absl::StrCat(port_and_name.substr(0, name_pos),
|
||||
transform(absl::ClippedSubstr(port_and_name, name_pos)));
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Returns subgraph streams not requested by a subgraph-node.
|
||||
mediapipe::Status FindIgnoredStreams(
|
||||
absl::Status FindIgnoredStreams(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& src_streams,
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& dst_streams,
|
||||
std::set<std::string>* result) {
|
||||
@@ -69,11 +69,11 @@ mediapipe::Status FindIgnoredStreams(
|
||||
result->insert(src_map->Names()[id.value()]);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Removes subgraph streams not requested by a subgraph-node.
|
||||
mediapipe::Status RemoveIgnoredStreams(
|
||||
absl::Status RemoveIgnoredStreams(
|
||||
proto_ns::RepeatedPtrField<ProtoString>* streams,
|
||||
const std::set<std::string>& missing_streams) {
|
||||
for (int i = streams->size() - 1; i >= 0; --i) {
|
||||
@@ -84,10 +84,10 @@ mediapipe::Status RemoveIgnoredStreams(
|
||||
streams->DeleteSubrange(i, 1);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status TransformNames(
|
||||
absl::Status TransformNames(
|
||||
CalculatorGraphConfig* config,
|
||||
const std::function<std::string(absl::string_view)>& transform) {
|
||||
RET_CHECK_EQ(config->packet_factory().size(), 0);
|
||||
@@ -122,7 +122,7 @@ mediapipe::Status TransformNames(
|
||||
MP_RETURN_IF_ERROR(TransformStreamNames(
|
||||
status_handler.mutable_input_side_packet(), transform));
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Adds a prefix to the name of each stream, side packet and node in the
|
||||
@@ -131,8 +131,8 @@ mediapipe::Status TransformNames(
|
||||
// 2, { foo, bar } --PrefixNames-> { rsg__foo, rsg__bar }
|
||||
// This means that two copies of the same subgraph will not interfere with
|
||||
// each other.
|
||||
static mediapipe::Status PrefixNames(std::string prefix,
|
||||
CalculatorGraphConfig* config) {
|
||||
static absl::Status PrefixNames(std::string prefix,
|
||||
CalculatorGraphConfig* config) {
|
||||
std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::tolower);
|
||||
std::replace(prefix.begin(), prefix.end(), '.', '_');
|
||||
std::replace(prefix.begin(), prefix.end(), ' ', '_');
|
||||
@@ -144,7 +144,7 @@ static mediapipe::Status PrefixNames(std::string prefix,
|
||||
return TransformNames(config, add_prefix);
|
||||
}
|
||||
|
||||
mediapipe::Status FindCorrespondingStreams(
|
||||
absl::Status FindCorrespondingStreams(
|
||||
std::map<std::string, std::string>* stream_map,
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& src_streams,
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& dst_streams) {
|
||||
@@ -175,14 +175,14 @@ mediapipe::Status FindCorrespondingStreams(
|
||||
(*stream_map)[src_name] = dst_name;
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// The following fields can be used in a Node message for a subgraph:
|
||||
// name, calculator, input_stream, output_stream, input_side_packet,
|
||||
// output_side_packet, options.
|
||||
// All other fields are only applicable to calculators.
|
||||
mediapipe::Status ValidateSubgraphFields(
|
||||
absl::Status ValidateSubgraphFields(
|
||||
const CalculatorGraphConfig::Node& subgraph_node) {
|
||||
if (subgraph_node.source_layer() || subgraph_node.buffer_size_hint() ||
|
||||
subgraph_node.has_input_stream_handler() ||
|
||||
@@ -193,10 +193,10 @@ mediapipe::Status ValidateSubgraphFields(
|
||||
<< "Subgraph \"" << subgraph_node.name()
|
||||
<< "\" has a field that is only applicable to calculators.";
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ConnectSubgraphStreams(
|
||||
absl::Status ConnectSubgraphStreams(
|
||||
const CalculatorGraphConfig::Node& subgraph_node,
|
||||
CalculatorGraphConfig* subgraph_config) {
|
||||
std::map<std::string, std::string> stream_map;
|
||||
@@ -269,11 +269,11 @@ mediapipe::Status ConnectSubgraphStreams(
|
||||
MP_RETURN_IF_ERROR(RemoveIgnoredStreams(
|
||||
generator.mutable_input_side_packet(), ignored_input_side_packets));
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry) {
|
||||
absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry) {
|
||||
graph_registry =
|
||||
graph_registry ? graph_registry : &GraphRegistry::global_graph_registry;
|
||||
RET_CHECK(config);
|
||||
@@ -313,7 +313,7 @@ mediapipe::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
config->mutable_status_handler()));
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
CalculatorGraphConfig MakeSingleNodeGraph(CalculatorGraphConfig::Node node) {
|
||||
|
||||
@@ -29,13 +29,13 @@ namespace tool {
|
||||
|
||||
// Apply the given transformation function to the names of streams and
|
||||
// side packets.
|
||||
mediapipe::Status TransformStreamNames(
|
||||
absl::Status TransformStreamNames(
|
||||
proto_ns::RepeatedPtrField<ProtoString>* streams,
|
||||
const std::function<std::string(absl::string_view)>& transform);
|
||||
|
||||
// Apply the given transformation function to the names of streams,
|
||||
// side packets, and nodes.
|
||||
mediapipe::Status TransformNames(
|
||||
absl::Status TransformNames(
|
||||
CalculatorGraphConfig* config,
|
||||
const std::function<std::string(absl::string_view)>& transform);
|
||||
|
||||
@@ -48,7 +48,7 @@ mediapipe::Status TransformNames(
|
||||
// src: FOO:abc dst: FOO:bob
|
||||
// BAR:def
|
||||
// The entry 'abc' -> 'bob' is added to the map.
|
||||
mediapipe::Status FindCorrespondingStreams(
|
||||
absl::Status FindCorrespondingStreams(
|
||||
std::map<std::string, std::string>* stream_map,
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& src_streams,
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& dst_streams);
|
||||
@@ -56,21 +56,20 @@ mediapipe::Status FindCorrespondingStreams(
|
||||
// Validates the fields in the given Node message that specifies a subgraph.
|
||||
// Returns an error status if the Node message contains any field that is only
|
||||
// applicable to calculators.
|
||||
mediapipe::Status ValidateSubgraphFields(
|
||||
absl::Status ValidateSubgraphFields(
|
||||
const CalculatorGraphConfig::Node& subgraph_node);
|
||||
|
||||
// Renames the streams in a subgraph config to match the connections on the
|
||||
// wrapping node.
|
||||
mediapipe::Status ConnectSubgraphStreams(
|
||||
absl::Status ConnectSubgraphStreams(
|
||||
const CalculatorGraphConfig::Node& subgraph_node,
|
||||
CalculatorGraphConfig* subgraph_config);
|
||||
|
||||
// Replaces subgraph nodes in the given config with the contents of the
|
||||
// corresponding subgraphs. Nested subgraphs are retrieved from the
|
||||
// graph registry and expanded recursively.
|
||||
mediapipe::Status ExpandSubgraphs(
|
||||
CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry = nullptr);
|
||||
absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry = nullptr);
|
||||
|
||||
// Creates a graph wrapping the provided node and exposing all of its
|
||||
// connections
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace {
|
||||
|
||||
class SimpleTestCalculator : public CalculatorBase {
|
||||
public:
|
||||
mediapipe::Status Process(CalculatorContext* cc) override {
|
||||
return mediapipe::OkStatus();
|
||||
absl::Status Process(CalculatorContext* cc) override {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
for (PacketType& type : cc->Inputs()) {
|
||||
type.Set<int>();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class SimpleTestCalculator : public CalculatorBase {
|
||||
for (PacketType& type : cc->InputSidePackets()) {
|
||||
type.Set<int>();
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
};
|
||||
REGISTER_CALCULATOR(SimpleTestCalculator);
|
||||
@@ -66,7 +66,7 @@ REGISTER_CALCULATOR(SomeAggregator);
|
||||
|
||||
class TestSubgraph : public Subgraph {
|
||||
public:
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& /*options*/) override {
|
||||
CalculatorGraphConfig config =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
@@ -95,7 +95,7 @@ REGISTER_MEDIAPIPE_GRAPH(TestSubgraph);
|
||||
|
||||
class PacketFactoryTestSubgraph : public Subgraph {
|
||||
public:
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& /*options*/) override {
|
||||
CalculatorGraphConfig config =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
@@ -126,7 +126,7 @@ REGISTER_MEDIAPIPE_GRAPH(PacketFactoryTestSubgraph);
|
||||
// and the number of copies of the node are specified in subgraph options.
|
||||
class NodeChainSubgraph : public Subgraph {
|
||||
public:
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& options) override {
|
||||
auto opts =
|
||||
Subgraph::GetOptions<mediapipe::NodeChainSubgraphOptions>(options);
|
||||
@@ -152,7 +152,7 @@ REGISTER_MEDIAPIPE_GRAPH(NodeChainSubgraph);
|
||||
// subgraph contains a node with the executor field "custom_thread_pool".
|
||||
class NodeWithExecutorSubgraph : public Subgraph {
|
||||
public:
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& options) override {
|
||||
CalculatorGraphConfig config =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
@@ -174,7 +174,7 @@ REGISTER_MEDIAPIPE_GRAPH(NodeWithExecutorSubgraph);
|
||||
// subgraph contains a NodeWithExecutorSubgraph.
|
||||
class EnclosingSubgraph : public Subgraph {
|
||||
public:
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const SubgraphOptions& options) override {
|
||||
CalculatorGraphConfig config =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
@@ -474,12 +474,12 @@ TEST(SubgraphExpansionTest, ValidateSubgraphFields) {
|
||||
buffer_size_hint: -1 # This field is only applicable to calculators.
|
||||
}
|
||||
)");
|
||||
mediapipe::Status s1 = tool::ValidateSubgraphFields(supergraph.node(1));
|
||||
EXPECT_EQ(s1.code(), mediapipe::StatusCode::kInvalidArgument);
|
||||
absl::Status s1 = tool::ValidateSubgraphFields(supergraph.node(1));
|
||||
EXPECT_EQ(s1.code(), absl::StatusCode::kInvalidArgument);
|
||||
EXPECT_THAT(s1.message(), testing::HasSubstr("foo_subgraph"));
|
||||
|
||||
mediapipe::Status s2 = tool::ExpandSubgraphs(&supergraph);
|
||||
EXPECT_EQ(s2.code(), mediapipe::StatusCode::kInvalidArgument);
|
||||
absl::Status s2 = tool::ExpandSubgraphs(&supergraph);
|
||||
EXPECT_EQ(s2.code(), absl::StatusCode::kInvalidArgument);
|
||||
EXPECT_THAT(s2.message(), testing::HasSubstr("foo_subgraph"));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ using mediapipe::SwitchContainerOptions;
|
||||
class SwitchContainer : public Subgraph {
|
||||
public:
|
||||
SwitchContainer() = default;
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
const Subgraph::SubgraphOptions& options) override;
|
||||
};
|
||||
REGISTER_MEDIAPIPE_GRAPH(SwitchContainer);
|
||||
@@ -157,7 +157,7 @@ void GetContainerNodeStreams(const CalculatorGraphConfig::Node& node,
|
||||
}
|
||||
|
||||
// Validate all subgraph inputs and outputs.
|
||||
mediapipe::Status ValidateContract(
|
||||
absl::Status ValidateContract(
|
||||
const CalculatorGraphConfig::Node& subgraph_node,
|
||||
const Subgraph::SubgraphOptions& subgraph_options) {
|
||||
auto options =
|
||||
@@ -166,20 +166,20 @@ mediapipe::Status ValidateContract(
|
||||
ParseTags(subgraph_node.input_stream(), &input_tags);
|
||||
ParseTags(subgraph_node.input_side_packet(), &side_tags);
|
||||
if (options.has_select() && options.has_enable()) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"Only one of SwitchContainer options 'enable' and 'select' can be "
|
||||
"specified");
|
||||
}
|
||||
if (side_tags.count({"SELECT", 0}) + side_tags.count({"ENABLE", 0}) > 1 ||
|
||||
input_tags.count({"SELECT", 0}) + input_tags.count({"ENABLE", 0}) > 1) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"Only one of SwitchContainer inputs 'ENABLE' and 'SELECT' can be "
|
||||
"specified");
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::StatusOr<CalculatorGraphConfig> SwitchContainer::GetConfig(
|
||||
absl::StatusOr<CalculatorGraphConfig> SwitchContainer::GetConfig(
|
||||
const Subgraph::SubgraphOptions& options) {
|
||||
CalculatorGraphConfig config;
|
||||
std::vector<CalculatorGraphConfig::Node*> subnodes;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace {
|
||||
// It also accepts a side packet tagged "TIMEZONE", but doesn't use it.
|
||||
class TripleIntCalculator : public CalculatorBase {
|
||||
public:
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
cc->Inputs().Index(0).Set<int>().Optional();
|
||||
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0)).Optional();
|
||||
cc->InputSidePackets().Index(0).Set<int>().Optional();
|
||||
@@ -43,22 +43,22 @@ class TripleIntCalculator : public CalculatorBase {
|
||||
.SetSameAs(&cc->InputSidePackets().Index(0))
|
||||
.Optional();
|
||||
cc->InputSidePackets().Tag("TIMEZONE").Set<int>().Optional();
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) final {
|
||||
absl::Status Open(CalculatorContext* cc) final {
|
||||
cc->SetOffset(TimestampDiff(0));
|
||||
if (cc->OutputSidePackets().HasTag("")) {
|
||||
cc->OutputSidePackets().Index(0).Set(
|
||||
MakePacket<int>(cc->InputSidePackets().Index(0).Get<int>() * 3));
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status Process(CalculatorContext* cc) final {
|
||||
absl::Status Process(CalculatorContext* cc) final {
|
||||
int value = cc->Inputs().Index(0).Value().Get<int>();
|
||||
cc->Outputs().Index(0).Add(new int(3 * value), cc->InputTimestamp());
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
};
|
||||
REGISTER_CALCULATOR(TripleIntCalculator);
|
||||
@@ -188,7 +188,7 @@ void RunTestSideContainer(CalculatorGraphConfig supergraph) {
|
||||
}));
|
||||
MP_ASSERT_OK(graph.CloseAllInputStreams());
|
||||
MP_ASSERT_OK(graph.WaitUntilDone());
|
||||
Packet side_output = graph.GetOutputSidePacket("output_bar").ValueOrDie();
|
||||
Packet side_output = graph.GetOutputSidePacket("output_bar").value();
|
||||
EXPECT_EQ(side_output.Get<int>(), 12);
|
||||
|
||||
MP_ASSERT_OK(graph.StartRun({
|
||||
@@ -197,7 +197,7 @@ void RunTestSideContainer(CalculatorGraphConfig supergraph) {
|
||||
}));
|
||||
MP_ASSERT_OK(graph.CloseAllInputStreams());
|
||||
MP_ASSERT_OK(graph.WaitUntilDone());
|
||||
side_output = graph.GetOutputSidePacket("output_bar").ValueOrDie();
|
||||
side_output = graph.GetOutputSidePacket("output_bar").value();
|
||||
EXPECT_EQ(side_output.Get<int>(), 4);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ TEST(SwitchContainerTest, ValidateSideInputs) {
|
||||
)");
|
||||
auto status = tool::ExpandSubgraphs(&supergraph);
|
||||
EXPECT_EQ(std::pair(status.code(), std::string(status.message())),
|
||||
std::pair(mediapipe::StatusCode::kInvalidArgument,
|
||||
std::pair(absl::StatusCode::kInvalidArgument,
|
||||
std::string("Only one of SwitchContainer inputs "
|
||||
"'ENABLE' and 'SELECT' can be specified")));
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ class SwitchDemuxCalculator : public CalculatorBase {
|
||||
static constexpr char kEnableTag[] = "ENABLE";
|
||||
|
||||
public:
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc);
|
||||
static absl::Status GetContract(CalculatorContract* cc);
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) override;
|
||||
mediapipe::Status Process(CalculatorContext* cc) override;
|
||||
absl::Status Open(CalculatorContext* cc) override;
|
||||
absl::Status Process(CalculatorContext* cc) override;
|
||||
|
||||
private:
|
||||
int channel_index_;
|
||||
@@ -68,7 +68,7 @@ class SwitchDemuxCalculator : public CalculatorBase {
|
||||
};
|
||||
REGISTER_CALCULATOR(SwitchDemuxCalculator);
|
||||
|
||||
mediapipe::Status SwitchDemuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
absl::Status SwitchDemuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
// Allow any one of kSelectTag, kEnableTag.
|
||||
if (cc->Inputs().HasTag(kSelectTag)) {
|
||||
cc->Inputs().Tag(kSelectTag).Set<int>();
|
||||
@@ -121,10 +121,10 @@ mediapipe::Status SwitchDemuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
}
|
||||
cc->SetInputStreamHandler("ImmediateInputStreamHandler");
|
||||
cc->SetProcessTimestampBounds(true);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status SwitchDemuxCalculator::Open(CalculatorContext* cc) {
|
||||
absl::Status SwitchDemuxCalculator::Open(CalculatorContext* cc) {
|
||||
channel_index_ = tool::GetChannelIndex(*cc, channel_index_);
|
||||
channel_tags_ = ChannelTags(cc->Outputs().TagMap());
|
||||
|
||||
@@ -145,10 +145,10 @@ mediapipe::Status SwitchDemuxCalculator::Open(CalculatorContext* cc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status SwitchDemuxCalculator::Process(CalculatorContext* cc) {
|
||||
absl::Status SwitchDemuxCalculator::Process(CalculatorContext* cc) {
|
||||
// Update the input channel index if specified.
|
||||
channel_index_ = tool::GetChannelIndex(*cc, channel_index_);
|
||||
|
||||
@@ -164,7 +164,7 @@ mediapipe::Status SwitchDemuxCalculator::Process(CalculatorContext* cc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -60,10 +60,10 @@ class SwitchMuxCalculator : public CalculatorBase {
|
||||
static constexpr char kEnableTag[] = "ENABLE";
|
||||
|
||||
public:
|
||||
static mediapipe::Status GetContract(CalculatorContract* cc);
|
||||
static absl::Status GetContract(CalculatorContract* cc);
|
||||
|
||||
mediapipe::Status Open(CalculatorContext* cc) override;
|
||||
mediapipe::Status Process(CalculatorContext* cc) override;
|
||||
absl::Status Open(CalculatorContext* cc) override;
|
||||
absl::Status Process(CalculatorContext* cc) override;
|
||||
|
||||
private:
|
||||
int channel_index_;
|
||||
@@ -71,7 +71,7 @@ class SwitchMuxCalculator : public CalculatorBase {
|
||||
};
|
||||
REGISTER_CALCULATOR(SwitchMuxCalculator);
|
||||
|
||||
mediapipe::Status SwitchMuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
absl::Status SwitchMuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
// Allow any one of kSelectTag, kEnableTag.
|
||||
if (cc->Inputs().HasTag(kSelectTag)) {
|
||||
cc->Inputs().Tag(kSelectTag).Set<int>();
|
||||
@@ -124,10 +124,10 @@ mediapipe::Status SwitchMuxCalculator::GetContract(CalculatorContract* cc) {
|
||||
}
|
||||
cc->SetInputStreamHandler("ImmediateInputStreamHandler");
|
||||
cc->SetProcessTimestampBounds(true);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status SwitchMuxCalculator::Open(CalculatorContext* cc) {
|
||||
absl::Status SwitchMuxCalculator::Open(CalculatorContext* cc) {
|
||||
channel_index_ = tool::GetChannelIndex(*cc, channel_index_);
|
||||
channel_tags_ = ChannelTags(cc->Inputs().TagMap());
|
||||
|
||||
@@ -140,10 +140,10 @@ mediapipe::Status SwitchMuxCalculator::Open(CalculatorContext* cc) {
|
||||
cc->OutputSidePackets().Get(tag, index).Set(input);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status SwitchMuxCalculator::Process(CalculatorContext* cc) {
|
||||
absl::Status SwitchMuxCalculator::Process(CalculatorContext* cc) {
|
||||
// Update the input channel index if specified.
|
||||
channel_index_ = tool::GetChannelIndex(*cc, channel_index_);
|
||||
|
||||
@@ -156,7 +156,7 @@ mediapipe::Status SwitchMuxCalculator::Process(CalculatorContext* cc) {
|
||||
tool::Relay(input, &output);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -37,7 +37,7 @@ void TagMap::InitializeNames(
|
||||
}
|
||||
}
|
||||
|
||||
mediapipe::Status TagMap::Initialize(
|
||||
absl::Status TagMap::Initialize(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& tag_index_names) {
|
||||
std::map<std::string, std::vector<std::string>> tag_to_names;
|
||||
for (const auto& tag_index_name : tag_index_names) {
|
||||
@@ -100,10 +100,10 @@ mediapipe::Status TagMap::Initialize(
|
||||
num_entries_ = current_index;
|
||||
|
||||
InitializeNames(tag_to_names);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status TagMap::Initialize(const TagAndNameInfo& info) {
|
||||
absl::Status TagMap::Initialize(const TagAndNameInfo& info) {
|
||||
if (info.tags.empty()) {
|
||||
if (!info.names.empty()) {
|
||||
mapping_.emplace(
|
||||
@@ -115,7 +115,7 @@ mediapipe::Status TagMap::Initialize(const TagAndNameInfo& info) {
|
||||
} else {
|
||||
std::map<std::string, std::vector<std::string>> tag_to_names;
|
||||
if (info.tags.size() != info.names.size()) {
|
||||
return mediapipe::FailedPreconditionError(
|
||||
return absl::FailedPreconditionError(
|
||||
"Expected info.tags.size() == info.names.size()");
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ mediapipe::Status TagMap::Initialize(const TagAndNameInfo& info) {
|
||||
// Now create the names_ array in the correctly sorted order.
|
||||
InitializeNames(tag_to_names);
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
proto_ns::RepeatedPtrField<ProtoString> TagMap::CanonicalEntries() const {
|
||||
|
||||
@@ -53,7 +53,7 @@ class TagMap {
|
||||
// TAG:<index>:name. This is the most common usage:
|
||||
// ASSIGN_OR_RETURN(std::shared_ptr<TagMap> tag_map,
|
||||
// tool::TagMap::Create(node.input_streams()));
|
||||
static mediapipe::StatusOr<std::shared_ptr<TagMap>> Create(
|
||||
static absl::StatusOr<std::shared_ptr<TagMap>> Create(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& tag_index_names) {
|
||||
std::shared_ptr<TagMap> output(new TagMap());
|
||||
MP_RETURN_IF_ERROR(output->Initialize(tag_index_names));
|
||||
@@ -64,7 +64,7 @@ class TagMap {
|
||||
// TODO: Migrate callers and delete this method.
|
||||
ABSL_DEPRECATED(
|
||||
"Use mediapipe::tool::TagMap::Create(tag_index_names) instead.")
|
||||
static mediapipe::StatusOr<std::shared_ptr<TagMap>> Create(
|
||||
static absl::StatusOr<std::shared_ptr<TagMap>> Create(
|
||||
const TagAndNameInfo& info) {
|
||||
std::shared_ptr<TagMap> output(new TagMap());
|
||||
MP_RETURN_IF_ERROR(output->Initialize(info));
|
||||
@@ -108,12 +108,12 @@ class TagMap {
|
||||
|
||||
// Initialize the TagMap. Due to only having a factory function for
|
||||
// creation, there is no way for a user to have an uninitialized TagMap.
|
||||
mediapipe::Status Initialize(
|
||||
absl::Status Initialize(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& tag_index_names);
|
||||
|
||||
// Initialize from a TagAndNameInfo.
|
||||
ABSL_DEPRECATED("Use Initialize(tag_index_names) instead.")
|
||||
mediapipe::Status Initialize(const TagAndNameInfo& info);
|
||||
absl::Status Initialize(const TagAndNameInfo& info);
|
||||
|
||||
// Initialize names_ using a map from tag to the names for that tag.
|
||||
void InitializeNames(
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace mediapipe {
|
||||
namespace tool {
|
||||
|
||||
// Create using a vector of TAG:<index>:name.
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(
|
||||
const std::vector<std::string>& tag_index_names) {
|
||||
proto_ns::RepeatedPtrField<ProtoString> fields;
|
||||
for (const auto& tag_index_name : tag_index_names) {
|
||||
@@ -41,7 +41,7 @@ mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(
|
||||
}
|
||||
|
||||
// Create using an integer number of entries (for tag "").
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(int num_entries) {
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(int num_entries) {
|
||||
RET_CHECK_LE(0, num_entries);
|
||||
proto_ns::RepeatedPtrField<ProtoString> fields;
|
||||
for (int i = 0; i < num_entries; ++i) {
|
||||
@@ -51,7 +51,7 @@ mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(int num_entries) {
|
||||
}
|
||||
|
||||
// Create using a vector of just tag names.
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMapFromTags(
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMapFromTags(
|
||||
const std::vector<std::string>& tags) {
|
||||
proto_ns::RepeatedPtrField<ProtoString> fields;
|
||||
for (int i = 0; i < tags.size(); ++i) {
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace mediapipe {
|
||||
namespace tool {
|
||||
|
||||
// Create a TagMap using a vector of TAG:<index>:name.
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(
|
||||
const std::vector<std::string>& tag_index_names);
|
||||
|
||||
// Create a TagMap using an integer number of entries (for tag "").
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(int num_entries);
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMap(int num_entries);
|
||||
|
||||
// Create a TagMap using a vector of just tag names.
|
||||
mediapipe::StatusOr<std::shared_ptr<TagMap>> CreateTagMapFromTags(
|
||||
absl::StatusOr<std::shared_ptr<TagMap>> CreateTagMapFromTags(
|
||||
const std::vector<std::string>& tags);
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -91,9 +91,9 @@ void TestSuccessTagMap(const std::vector<std::string>& tag_index_names,
|
||||
const std::vector<std::string>& names) {
|
||||
std::shared_ptr<tool::TagMap> tag_map;
|
||||
if (create_from_tags) {
|
||||
tag_map = tool::CreateTagMapFromTags(tag_index_names).ValueOrDie();
|
||||
tag_map = tool::CreateTagMapFromTags(tag_index_names).value();
|
||||
} else {
|
||||
tag_map = tool::CreateTagMap(tag_index_names).ValueOrDie();
|
||||
tag_map = tool::CreateTagMap(tag_index_names).value();
|
||||
}
|
||||
|
||||
EXPECT_EQ(num_entries, tag_map->NumEntries())
|
||||
@@ -295,11 +295,11 @@ TEST(TagMapTest, SameAs) {
|
||||
auto statusor_tag_map =
|
||||
tool::CreateTagMapFromTags(std::get<2>(parameters));
|
||||
MP_ASSERT_OK(statusor_tag_map);
|
||||
tag_maps.push_back(std::move(statusor_tag_map.ValueOrDie()));
|
||||
tag_maps.push_back(std::move(statusor_tag_map.value()));
|
||||
} else {
|
||||
auto statusor_tag_map = tool::CreateTagMap(std::get<2>(parameters));
|
||||
MP_ASSERT_OK(statusor_tag_map);
|
||||
tag_maps.push_back(std::move(statusor_tag_map.ValueOrDie()));
|
||||
tag_maps.push_back(std::move(statusor_tag_map.value()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,11 +322,11 @@ TEST(TagMapTest, SameAs) {
|
||||
// debug std::string each satisfy a matcher.
|
||||
template <typename Matcher>
|
||||
void TestDebugString(
|
||||
const mediapipe::StatusOr<std::shared_ptr<tool::TagMap>>& statusor_tag_map,
|
||||
const absl::StatusOr<std::shared_ptr<tool::TagMap>>& statusor_tag_map,
|
||||
const std::vector<std::string>& canonical_entries,
|
||||
Matcher short_string_matcher) {
|
||||
MP_ASSERT_OK(statusor_tag_map);
|
||||
tool::TagMap& tag_map = *statusor_tag_map.ValueOrDie();
|
||||
tool::TagMap& tag_map = *statusor_tag_map.value();
|
||||
std::string debug_string = tag_map.DebugString();
|
||||
std::string short_string = tag_map.ShortDebugString();
|
||||
LOG(INFO) << "ShortDebugString:\n" << short_string << "\n";
|
||||
|
||||
@@ -86,8 +86,8 @@ std::unique_ptr<MessageLite> CloneMessage(const MessageLite& message) {
|
||||
|
||||
// Returns the (tag, index) pairs in a field path.
|
||||
// For example, returns {{1, 1}, {2, 1}, {3, 1}} for path "/1[1]/2[1]/3[1]".
|
||||
mediapipe::Status ProtoPathSplit(const std::string& path, ProtoPath* result) {
|
||||
mediapipe::Status status;
|
||||
absl::Status ProtoPathSplit(const std::string& path, ProtoPath* result) {
|
||||
absl::Status status;
|
||||
std::vector<std::string> ids = absl::StrSplit(path, '/');
|
||||
for (const std::string& id : ids) {
|
||||
if (id.length() > 0) {
|
||||
@@ -98,7 +98,7 @@ mediapipe::Status ProtoPathSplit(const std::string& path, ProtoPath* result) {
|
||||
bool ok = absl::SimpleAtoi(id_pair.first, &tag) &&
|
||||
absl::SimpleAtoi(id_pair.second, &index);
|
||||
if (!ok) {
|
||||
status.Update(mediapipe::InvalidArgumentError(path));
|
||||
status.Update(absl::InvalidArgumentError(path));
|
||||
}
|
||||
result->push_back(std::make_pair(tag, index));
|
||||
}
|
||||
@@ -146,7 +146,7 @@ int FieldCount(const FieldValue& base, ProtoPath field_path,
|
||||
// The default implementation for the mediapipe template rule interpreter.
|
||||
class TemplateExpanderImpl {
|
||||
public:
|
||||
explicit TemplateExpanderImpl(std::vector<mediapipe::Status>* errors)
|
||||
explicit TemplateExpanderImpl(std::vector<absl::Status>* errors)
|
||||
: errors_(errors) {}
|
||||
|
||||
// Applies the rules specified in a CalculatorGraphTemplate to a
|
||||
@@ -215,21 +215,21 @@ class TemplateExpanderImpl {
|
||||
}
|
||||
|
||||
// Return the field values addressed by a template rule.
|
||||
mediapipe::Status GetBaseValue(const std::string& base_path,
|
||||
const TemplateExpression& rule,
|
||||
const FieldValue& output,
|
||||
std::vector<FieldValue>* base) {
|
||||
absl::Status GetBaseValue(const std::string& base_path,
|
||||
const TemplateExpression& rule,
|
||||
const FieldValue& output,
|
||||
std::vector<FieldValue>* base) {
|
||||
if (!rule.has_path()) {
|
||||
base->push_back(output);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
if (rule.has_field_value()) {
|
||||
// For a non-repeated field, the field value is stored only in the rule.
|
||||
base->push_back(rule.field_value());
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
ProtoPath field_path;
|
||||
mediapipe::Status status =
|
||||
absl::Status status =
|
||||
ProtoPathSplit(ProtoPathRelative(rule.path(), base_path), &field_path);
|
||||
if (!status.ok()) return status;
|
||||
return ProtoUtilLite::GetFieldRange(output, field_path, 1,
|
||||
@@ -237,12 +237,13 @@ class TemplateExpanderImpl {
|
||||
}
|
||||
|
||||
// Replace the field values addressed by a template rule.
|
||||
mediapipe::Status ReplaceBaseValue(
|
||||
const std::string& base_path, const TemplateExpression& rule,
|
||||
const std::vector<FieldValue>& field_values, FieldValue* output) {
|
||||
absl::Status ReplaceBaseValue(const std::string& base_path,
|
||||
const TemplateExpression& rule,
|
||||
const std::vector<FieldValue>& field_values,
|
||||
FieldValue* output) {
|
||||
if (!rule.has_path()) {
|
||||
*output = field_values[0];
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
ProtoPath field_path;
|
||||
RET_CHECK_OK(
|
||||
@@ -252,7 +253,7 @@ class TemplateExpanderImpl {
|
||||
// For a non-repeated field, only one value can be specified.
|
||||
if (!field_values.empty() &&
|
||||
FieldCount(*output, field_path, GetFieldType(rule)) > 0) {
|
||||
return mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
return absl::InvalidArgumentError(absl::StrCat(
|
||||
"Multiple values specified for non-repeated field: ", rule.path()));
|
||||
}
|
||||
// For a non-repeated field, the field value is stored only in the rule.
|
||||
@@ -267,7 +268,7 @@ class TemplateExpanderImpl {
|
||||
bool ExpandNestedRules(int base_index, const std::string& base_path,
|
||||
const FieldValue& base_message,
|
||||
std::vector<FieldValue>* result) {
|
||||
mediapipe::Status status;
|
||||
absl::Status status;
|
||||
FieldValue output = base_message;
|
||||
|
||||
// Evaluate the rules nested below base_path in lexical order.
|
||||
@@ -280,7 +281,7 @@ class TemplateExpanderImpl {
|
||||
if (!status.ok()) break;
|
||||
std::vector<FieldValue> values;
|
||||
if (!ExpandTemplateRule(rules[i], base[0], &values)) {
|
||||
status = mediapipe::InternalError("ExpandTemplateRule failed");
|
||||
status = absl::InternalError("ExpandTemplateRule failed");
|
||||
break;
|
||||
}
|
||||
edits.push_back(values);
|
||||
@@ -348,7 +349,7 @@ class TemplateExpanderImpl {
|
||||
// Retrieve the var param and the range expression.
|
||||
const TemplateExpression& rule = template_rules_.rule().Get(base_index);
|
||||
if (rule.arg().empty() || rule.arg().size() > 2) {
|
||||
RecordError(mediapipe::InvalidArgumentError(
|
||||
RecordError(absl::InvalidArgumentError(
|
||||
"Param declaration must specify a parameter name and "
|
||||
"may specify a single default value."));
|
||||
}
|
||||
@@ -386,8 +387,8 @@ class TemplateExpanderImpl {
|
||||
const TemplateExpression& rule = template_rules_.rule().Get(base_index);
|
||||
TemplateArgument item = EvalExpression(rule);
|
||||
std::vector<FieldValue> values;
|
||||
mediapipe::Status status = AsFieldValues(
|
||||
std::vector<TemplateArgument>{item}, GetFieldType(rule), &values);
|
||||
absl::Status status = AsFieldValues(std::vector<TemplateArgument>{item},
|
||||
GetFieldType(rule), &values);
|
||||
if (!status.ok()) {
|
||||
RecordError(status);
|
||||
return false;
|
||||
@@ -400,8 +401,7 @@ class TemplateExpanderImpl {
|
||||
TemplateArgument EvalParam(const TemplateExpression& expr) {
|
||||
TemplateArgument* result = GetItem(&environment_, expr.param());
|
||||
if (result == nullptr) {
|
||||
RecordError(
|
||||
mediapipe::NotFoundError(absl::StrCat("param: ", expr.param())));
|
||||
RecordError(absl::NotFoundError(absl::StrCat("param: ", expr.param())));
|
||||
return AsArgument(0.0);
|
||||
}
|
||||
return *result;
|
||||
@@ -412,7 +412,7 @@ class TemplateExpanderImpl {
|
||||
TemplateArgument lhs = EvalExpression(expr.arg(0));
|
||||
TemplateArgument* result = GetItem(lhs.mutable_dict(), expr.arg(1).param());
|
||||
if (result == nullptr) {
|
||||
RecordError(mediapipe::NotFoundError(
|
||||
RecordError(absl::NotFoundError(
|
||||
absl::StrCat("param field: ", expr.arg(1).param())));
|
||||
return AsArgument(0.0);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class TemplateExpanderImpl {
|
||||
}
|
||||
if (value.has_str()) {
|
||||
if (!absl::SimpleAtod(value.str(), &result)) {
|
||||
RecordError(mediapipe::InvalidArgumentError(value.str()));
|
||||
RecordError(absl::InvalidArgumentError(value.str()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -452,7 +452,7 @@ class TemplateExpanderImpl {
|
||||
return value.num() != 0;
|
||||
} else if (value.has_str()) {
|
||||
if (!absl::SimpleAtob(value.str(), &result)) {
|
||||
RecordError(mediapipe::InvalidArgumentError(value.str()));
|
||||
RecordError(absl::InvalidArgumentError(value.str()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -462,7 +462,7 @@ class TemplateExpanderImpl {
|
||||
TemplateArgument AsDict(const std::vector<TemplateArgument>& args) {
|
||||
TemplateArgument result;
|
||||
if (args.size() % 2 != 0) {
|
||||
RecordError(mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
RecordError(absl::InvalidArgumentError(absl::StrCat(
|
||||
"Dict requires an even number of arguments, got: ", args.size())));
|
||||
return result;
|
||||
}
|
||||
@@ -595,9 +595,9 @@ class TemplateExpanderImpl {
|
||||
}
|
||||
|
||||
// Convert between a proto feild value and a template argument.
|
||||
mediapipe::Status AsFieldValues(const std::vector<TemplateArgument>& args,
|
||||
FieldType field_type,
|
||||
std::vector<FieldValue>* result) {
|
||||
absl::Status AsFieldValues(const std::vector<TemplateArgument>& args,
|
||||
FieldType field_type,
|
||||
std::vector<FieldValue>* result) {
|
||||
for (int i = 0; i < args.size(); ++i) {
|
||||
if (args[i].has_dict()) {
|
||||
FieldValue dict_bytes;
|
||||
@@ -613,11 +613,11 @@ class TemplateExpanderImpl {
|
||||
result->push_back(r[0]);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Record a Status if it indicates an error.
|
||||
void RecordError(const mediapipe::Status& status) {
|
||||
void RecordError(const absl::Status& status) {
|
||||
if (!status.ok()) {
|
||||
errors_->push_back(status);
|
||||
}
|
||||
@@ -631,23 +631,23 @@ class TemplateExpanderImpl {
|
||||
TemplateDict environment_;
|
||||
|
||||
// List of errors found in template parameters.
|
||||
std::vector<mediapipe::Status>* errors_;
|
||||
std::vector<absl::Status>* errors_;
|
||||
};
|
||||
|
||||
TemplateExpander::TemplateExpander() {}
|
||||
|
||||
// Expands template rules within a proto message.
|
||||
// Replaces template rules with expanded sub-messages.
|
||||
mediapipe::Status TemplateExpander::ExpandTemplates(
|
||||
absl::Status TemplateExpander::ExpandTemplates(
|
||||
const TemplateDict& args, const CalculatorGraphTemplate& templ,
|
||||
CalculatorGraphConfig* output) {
|
||||
errors_.clear();
|
||||
TemplateExpanderImpl expander(&errors_);
|
||||
if (!expander.ExpandTemplates(args, templ, output)) {
|
||||
errors_.push_back(mediapipe::InternalError("ExpandTemplates failed"));
|
||||
errors_.push_back(absl::InternalError("ExpandTemplates failed"));
|
||||
}
|
||||
mediapipe::Status status;
|
||||
for (const mediapipe::Status& error : errors_) {
|
||||
absl::Status status;
|
||||
for (const absl::Status& error : errors_) {
|
||||
LOG(ERROR) << error;
|
||||
status.Update(error);
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ class TemplateExpander {
|
||||
// Applies the rules specified in a CalculatorGraphTemplate to a
|
||||
// CalculatorGraphConfig. Each rule references a nested field-value or
|
||||
// message and defines zero or more replacement values for it.
|
||||
mediapipe::Status ExpandTemplates(const TemplateDict& args,
|
||||
const CalculatorGraphTemplate& templ,
|
||||
CalculatorGraphConfig* output);
|
||||
absl::Status ExpandTemplates(const TemplateDict& args,
|
||||
const CalculatorGraphTemplate& templ,
|
||||
CalculatorGraphConfig* output);
|
||||
|
||||
private:
|
||||
// List of errors found in template parameters.
|
||||
std::vector<mediapipe::Status> errors_;
|
||||
std::vector<absl::Status> errors_;
|
||||
};
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -1332,20 +1332,20 @@ bool IsFunctionOperator(const std::string& token) {
|
||||
// by the DynamicMessageFactory ("output"). These two Messages have
|
||||
// different Descriptors so Message::MergeFrom cannot be applied directly,
|
||||
// but they are expected to be equivalent.
|
||||
mediapipe::Status MergeFields(const Message& source, Message* dest) {
|
||||
absl::Status MergeFields(const Message& source, Message* dest) {
|
||||
std::unique_ptr<Message> temp(dest->New());
|
||||
std::string temp_str;
|
||||
RET_CHECK(TextFormat::PrintToString(source, &temp_str));
|
||||
RET_CHECK(TextFormat::ParseFromString(temp_str, temp.get()));
|
||||
dest->MergeFrom(*temp);
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Returns the (tag, index) pairs in a field path.
|
||||
// For example, returns {{1, 1}, {2, 1}, {3, 1}} for path "/1[1]/2[1]/3[1]".
|
||||
mediapipe::Status ProtoPathSplit(const std::string& path,
|
||||
ProtoUtilLite::ProtoPath* result) {
|
||||
mediapipe::Status status;
|
||||
absl::Status ProtoPathSplit(const std::string& path,
|
||||
ProtoUtilLite::ProtoPath* result) {
|
||||
absl::Status status;
|
||||
std::vector<std::string> ids = absl::StrSplit(path, '/');
|
||||
for (const std::string& id : ids) {
|
||||
if (id.length() > 0) {
|
||||
@@ -1356,7 +1356,7 @@ mediapipe::Status ProtoPathSplit(const std::string& path,
|
||||
bool ok = absl::SimpleAtoi(id_pair.first, &tag) &&
|
||||
absl::SimpleAtoi(id_pair.second, &index);
|
||||
if (!ok) {
|
||||
status.Update(mediapipe::InvalidArgumentError(path));
|
||||
status.Update(absl::InvalidArgumentError(path));
|
||||
}
|
||||
result->push_back(std::make_pair(tag, index));
|
||||
}
|
||||
|
||||
@@ -27,17 +27,10 @@
|
||||
#include "mediapipe/framework/deps/file_path.h"
|
||||
#include "mediapipe/framework/deps/no_destructor.h"
|
||||
#include "mediapipe/framework/port/advanced_proto_inc.h"
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#include "mediapipe/framework/port/logging.h"
|
||||
#include "mediapipe/framework/port/proto_ns.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#elif defined(__ANDROID__)
|
||||
#include "mediapipe/util/android/file/base/helpers.h"
|
||||
#else
|
||||
#include "mediapipe/framework/port/file_helpers.h"
|
||||
#endif
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
namespace {
|
||||
@@ -235,28 +228,18 @@ bool CompareImageFrames(const ImageFrame& image1, const ImageFrame& image2,
|
||||
}
|
||||
|
||||
std::string GetTestRootDir() {
|
||||
#ifdef __APPLE__
|
||||
char path[1024];
|
||||
CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||
Boolean success = CFURLGetFileSystemRepresentation(
|
||||
bundle_url, true, reinterpret_cast<UInt8*>(path), sizeof(path));
|
||||
CHECK(success);
|
||||
CFRelease(bundle_url);
|
||||
return path;
|
||||
#elif defined(__ANDROID__)
|
||||
#if defined(__ANDROID__)
|
||||
char path[1024];
|
||||
char* ptr = getcwd(path, sizeof(path));
|
||||
CHECK_EQ(ptr, path);
|
||||
return path;
|
||||
#else
|
||||
return ::mediapipe::file::JoinPath(std::getenv("TEST_SRCDIR"), "mediapipe");
|
||||
#endif // defined(__APPLE__)
|
||||
#endif // defined(__ANDROID__)
|
||||
}
|
||||
|
||||
std::string GetTestDataDir(const std::string& package_base_path) {
|
||||
#ifdef __APPLE__
|
||||
return ::mediapipe::file::JoinPath(GetTestRootDir(), "testdata/");
|
||||
#elif defined(__ANDROID__)
|
||||
#if defined(__ANDROID__)
|
||||
std::string data_dir = GetTestRootDir();
|
||||
std::string binary_dir = GetBinaryDirectory();
|
||||
// In Mobile Harness, the cwd is "/" and the run dir is "/data/local/tmp".
|
||||
|
||||
@@ -41,9 +41,8 @@ DEFINE_string(
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
mediapipe::Status ReadProto(proto_ns::io::ZeroCopyInputStream* in,
|
||||
bool read_text, const std::string& source,
|
||||
proto_ns::Message* result) {
|
||||
absl::Status ReadProto(proto_ns::io::ZeroCopyInputStream* in, bool read_text,
|
||||
const std::string& source, proto_ns::Message* result) {
|
||||
if (read_text) {
|
||||
RET_CHECK(proto_ns::TextFormat::Parse(in, result))
|
||||
<< "could not parse text proto: " << source;
|
||||
@@ -51,12 +50,12 @@ mediapipe::Status ReadProto(proto_ns::io::ZeroCopyInputStream* in,
|
||||
RET_CHECK(result->ParseFromZeroCopyStream(in))
|
||||
<< "could not parse binary proto: " << source;
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status WriteProto(const proto_ns::Message& message, bool write_text,
|
||||
const std::string& dest,
|
||||
proto_ns::io::ZeroCopyOutputStream* out) {
|
||||
absl::Status WriteProto(const proto_ns::Message& message, bool write_text,
|
||||
const std::string& dest,
|
||||
proto_ns::io::ZeroCopyOutputStream* out) {
|
||||
if (write_text) {
|
||||
RET_CHECK(proto_ns::TextFormat::Print(message, out))
|
||||
<< "could not write text proto to: " << dest;
|
||||
@@ -64,21 +63,21 @@ mediapipe::Status WriteProto(const proto_ns::Message& message, bool write_text,
|
||||
RET_CHECK(message.SerializeToZeroCopyStream(out))
|
||||
<< "could not write binary proto to: " << dest;
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Read a proto from a text or a binary file.
|
||||
mediapipe::Status ReadFile(const std::string& proto_source, bool read_text,
|
||||
proto_ns::Message* result) {
|
||||
absl::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);
|
||||
MP_RETURN_IF_ERROR(ReadProto(&in, read_text, proto_source, result));
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Write a proto to a text or a binary file.
|
||||
mediapipe::Status WriteFile(const std::string& proto_output, bool write_text,
|
||||
const proto_ns::Message& message) {
|
||||
absl::Status WriteFile(const std::string& proto_output, bool write_text,
|
||||
const proto_ns::Message& message) {
|
||||
std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc;
|
||||
if (!write_text) {
|
||||
mode |= std::ios_base::binary;
|
||||
@@ -86,7 +85,7 @@ mediapipe::Status WriteFile(const std::string& proto_output, bool write_text,
|
||||
std::ofstream ofs(proto_output, mode);
|
||||
proto_ns::io::OstreamOutputStream out(&ofs);
|
||||
MP_RETURN_IF_ERROR(WriteProto(message, write_text, proto_output, &out));
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
@@ -96,20 +95,22 @@ int main(int argc, char** argv) {
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
// Validate command line options.
|
||||
mediapipe::Status status;
|
||||
if (FLAGS_proto_source.empty()) {
|
||||
absl::Status status;
|
||||
if (absl::GetFlag(FLAGS_proto_source).empty()) {
|
||||
status.Update(
|
||||
mediapipe::InvalidArgumentError("--proto_source must be specified"));
|
||||
absl::InvalidArgumentError("--proto_source must be specified"));
|
||||
}
|
||||
if (FLAGS_proto_output.empty()) {
|
||||
if (absl::GetFlag(FLAGS_proto_output).empty()) {
|
||||
status.Update(
|
||||
mediapipe::InvalidArgumentError("--proto_output must be specified"));
|
||||
absl::InvalidArgumentError("--proto_output must be specified"));
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mediapipe::CalculatorGraphConfig config;
|
||||
EXIT_IF_ERROR(mediapipe::ReadFile(FLAGS_proto_source, true, &config));
|
||||
EXIT_IF_ERROR(mediapipe::WriteFile(FLAGS_proto_output, false, config));
|
||||
EXIT_IF_ERROR(
|
||||
mediapipe::ReadFile(absl::GetFlag(FLAGS_proto_source), true, &config));
|
||||
EXIT_IF_ERROR(
|
||||
mediapipe::WriteFile(absl::GetFlag(FLAGS_proto_output), false, config));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace mediapipe {
|
||||
|
||||
namespace tool {
|
||||
|
||||
mediapipe::Status ValidateInput(const InputCollection& input_collection) {
|
||||
absl::Status ValidateInput(const InputCollection& input_collection) {
|
||||
if (!input_collection.name().empty()) {
|
||||
MP_RETURN_IF_ERROR(tool::ValidateName(input_collection.name())).SetPrepend()
|
||||
<< "InputCollection " << input_collection.name()
|
||||
@@ -34,14 +34,14 @@ mediapipe::Status ValidateInput(const InputCollection& input_collection) {
|
||||
}
|
||||
if (input_collection.input_type() <= InputCollection::UNKNOWN ||
|
||||
input_collection.input_type() >= InputCollection::INVALID_UPPER_BOUND) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"InputCollection must specify a valid input_type.");
|
||||
}
|
||||
if (input_collection.file_name().empty()) {
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
"InputCollection must specify a file_name.");
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace mediapipe {
|
||||
|
||||
namespace tool {
|
||||
|
||||
// Returns mediapipe::OkStatus() if the InputCollection is valid. An input
|
||||
// Returns absl::OkStatus() if the InputCollection is valid. An input
|
||||
// collection is invalid if it does not have the proper fields set
|
||||
// depending on what its input_type field is. Furthermore, if it uses
|
||||
// INLINE, then the number of value fields in each inputs must match
|
||||
// the number of input_side_packet_name fields.
|
||||
mediapipe::Status ValidateInput(const InputCollection& input);
|
||||
absl::Status ValidateInput(const InputCollection& input);
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace tool {
|
||||
#define MEDIAPIPE_TAG_INDEX_REGEX \
|
||||
"(" MEDIAPIPE_TAG_REGEX ")?(:" MEDIAPIPE_NUMBER_REGEX ")?"
|
||||
|
||||
mediapipe::Status GetTagAndNameInfo(
|
||||
absl::Status GetTagAndNameInfo(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& tags_and_names,
|
||||
TagAndNameInfo* info) {
|
||||
RET_CHECK(info);
|
||||
@@ -59,15 +59,15 @@ mediapipe::Status GetTagAndNameInfo(
|
||||
if (info->tags.size() > 0 && info->names.size() != info->tags.size()) {
|
||||
info->tags.clear();
|
||||
info->names.clear();
|
||||
return mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
return absl::InvalidArgumentError(absl::StrCat(
|
||||
"Each set of names must use exclusively either tags or indexes. "
|
||||
"Encountered: \"",
|
||||
absl::StrJoin(tags_and_names, "\", \""), "\""));
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status SetFromTagAndNameInfo(
|
||||
absl::Status SetFromTagAndNameInfo(
|
||||
const TagAndNameInfo& info,
|
||||
proto_ns::RepeatedPtrField<ProtoString>* tags_and_names) {
|
||||
tags_and_names->Clear();
|
||||
@@ -88,52 +88,52 @@ mediapipe::Status SetFromTagAndNameInfo(
|
||||
*tags_and_names->Add() = absl::StrCat(info.tags[i], ":", info.names[i]);
|
||||
}
|
||||
}
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ValidateName(const std::string& name) {
|
||||
absl::Status ValidateName(const std::string& name) {
|
||||
return name.length() > 0 && (name[0] == '_' || islower(name[0])) &&
|
||||
std::all_of(name.begin() + 1, name.end(),
|
||||
[](char c) {
|
||||
return c == '_' || isdigit(c) || islower(c);
|
||||
})
|
||||
? mediapipe::OkStatus()
|
||||
: mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
? absl::OkStatus()
|
||||
: absl::InvalidArgumentError(absl::StrCat(
|
||||
"Name \"", absl::CEscape(name),
|
||||
"\" does not match \"" MEDIAPIPE_NAME_REGEX "\"."));
|
||||
}
|
||||
|
||||
mediapipe::Status ValidateNumber(const std::string& number) {
|
||||
absl::Status ValidateNumber(const std::string& number) {
|
||||
return (number.length() == 1 && isdigit(number[0])) ||
|
||||
(number.length() > 1 && isdigit(number[0]) &&
|
||||
number[0] != '0' &&
|
||||
std::all_of(number.begin() + 1, number.end(),
|
||||
[](char c) { return isdigit(c); }))
|
||||
? mediapipe::OkStatus()
|
||||
: mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
? absl::OkStatus()
|
||||
: absl::InvalidArgumentError(absl::StrCat(
|
||||
"Number \"", absl::CEscape(number),
|
||||
"\" does not match \"" MEDIAPIPE_NUMBER_REGEX "\"."));
|
||||
}
|
||||
|
||||
mediapipe::Status ValidateTag(const std::string& tag) {
|
||||
absl::Status ValidateTag(const std::string& tag) {
|
||||
return tag.length() > 0 && (tag[0] == '_' || isupper(tag[0])) &&
|
||||
std::all_of(tag.begin() + 1, tag.end(),
|
||||
[](char c) {
|
||||
return c == '_' || isdigit(c) || isupper(c);
|
||||
})
|
||||
? mediapipe::OkStatus()
|
||||
: mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
? absl::OkStatus()
|
||||
: absl::InvalidArgumentError(absl::StrCat(
|
||||
"Tag \"", absl::CEscape(tag),
|
||||
"\" does not match \"" MEDIAPIPE_TAG_REGEX "\"."));
|
||||
}
|
||||
|
||||
mediapipe::Status ParseTagAndName(const std::string& tag_and_name,
|
||||
std::string* tag, std::string* name) {
|
||||
absl::Status ParseTagAndName(const std::string& tag_and_name, std::string* tag,
|
||||
std::string* name) {
|
||||
// An optional tag and colon, followed by a name.
|
||||
RET_CHECK(tag);
|
||||
RET_CHECK(name);
|
||||
mediapipe::Status tag_status = mediapipe::OkStatus();
|
||||
mediapipe::Status name_status = mediapipe::UnknownError("");
|
||||
absl::Status tag_status = absl::OkStatus();
|
||||
absl::Status name_status = absl::UnknownError("");
|
||||
int name_index = 0;
|
||||
std::vector<std::string> v = absl::StrSplit(tag_and_name, ':');
|
||||
if (v.size() == 1) {
|
||||
@@ -144,11 +144,11 @@ mediapipe::Status ParseTagAndName(const std::string& tag_and_name,
|
||||
name_status = ValidateName(v[1]);
|
||||
name_index = 1;
|
||||
}
|
||||
if (name_index == -1 || tag_status != mediapipe::OkStatus() ||
|
||||
name_status != mediapipe::OkStatus()) {
|
||||
if (name_index == -1 || tag_status != absl::OkStatus() ||
|
||||
name_status != absl::OkStatus()) {
|
||||
tag->clear();
|
||||
name->clear();
|
||||
return mediapipe::InvalidArgumentError(
|
||||
return absl::InvalidArgumentError(
|
||||
absl::StrCat("\"tag and name\" is invalid, \"", tag_and_name,
|
||||
"\" does not match "
|
||||
"\"" MEDIAPIPE_TAG_AND_NAME_REGEX
|
||||
@@ -156,20 +156,20 @@ mediapipe::Status ParseTagAndName(const std::string& tag_and_name,
|
||||
}
|
||||
*tag = name_index == 1 ? v[0] : "";
|
||||
*name = v[name_index];
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ParseTagIndexName(const std::string& tag_index_name,
|
||||
std::string* tag, int* index,
|
||||
std::string* name) {
|
||||
absl::Status ParseTagIndexName(const std::string& tag_index_name,
|
||||
std::string* tag, int* index,
|
||||
std::string* name) {
|
||||
// An optional tag and colon, an optional index and color, followed by a name.
|
||||
RET_CHECK(tag);
|
||||
RET_CHECK(index);
|
||||
RET_CHECK(name);
|
||||
|
||||
mediapipe::Status tag_status = mediapipe::OkStatus();
|
||||
mediapipe::Status number_status = mediapipe::OkStatus();
|
||||
mediapipe::Status name_status = mediapipe::UnknownError("");
|
||||
absl::Status tag_status = absl::OkStatus();
|
||||
absl::Status number_status = absl::OkStatus();
|
||||
absl::Status name_status = absl::UnknownError("");
|
||||
int name_index = -1;
|
||||
int the_index = 0;
|
||||
std::vector<std::string> v = absl::StrSplit(tag_index_name, ':');
|
||||
@@ -195,7 +195,7 @@ mediapipe::Status ParseTagIndexName(const std::string& tag_index_name,
|
||||
} // else omitted, name_index == -1, triggering error.
|
||||
if (name_index == -1 || !tag_status.ok() || !number_status.ok() ||
|
||||
!name_status.ok()) {
|
||||
return mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
return absl::InvalidArgumentError(absl::StrCat(
|
||||
"TAG:index:name is invalid, \"", tag_index_name,
|
||||
"\" does not match "
|
||||
"\"" MEDIAPIPE_TAG_INDEX_NAME_REGEX
|
||||
@@ -204,16 +204,16 @@ mediapipe::Status ParseTagIndexName(const std::string& tag_index_name,
|
||||
*tag = name_index != 0 ? v[0] : "";
|
||||
*index = the_index;
|
||||
*name = v[name_index];
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
mediapipe::Status ParseTagIndex(const std::string& tag_index, std::string* tag,
|
||||
int* index) {
|
||||
absl::Status ParseTagIndex(const std::string& tag_index, std::string* tag,
|
||||
int* index) {
|
||||
RET_CHECK(tag);
|
||||
RET_CHECK(index);
|
||||
|
||||
mediapipe::Status tag_status = mediapipe::OkStatus();
|
||||
mediapipe::Status number_status = mediapipe::OkStatus();
|
||||
absl::Status tag_status = absl::OkStatus();
|
||||
absl::Status number_status = absl::OkStatus();
|
||||
int the_index = -1;
|
||||
std::vector<std::string> v = absl::StrSplit(tag_index, ':');
|
||||
if (v.size() == 1) {
|
||||
@@ -234,14 +234,14 @@ mediapipe::Status ParseTagIndex(const std::string& tag_index, std::string* tag,
|
||||
}
|
||||
} // else omitted, the_index == -1, triggering error.
|
||||
if (the_index == -1 || !tag_status.ok() || !number_status.ok()) {
|
||||
return mediapipe::InvalidArgumentError(absl::StrCat(
|
||||
return absl::InvalidArgumentError(absl::StrCat(
|
||||
"TAG:index is invalid, \"", tag_index,
|
||||
"\" does not match "
|
||||
"\"" MEDIAPIPE_TAG_INDEX_REGEX "\" (examples: \"TAG\" \"VIDEO:2\")."));
|
||||
}
|
||||
*tag = v[0];
|
||||
*index = the_index;
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
#undef MEDIAPIPE_NAME_REGEX
|
||||
|
||||
@@ -52,7 +52,7 @@ ABSL_DEPRECATED(
|
||||
"support the TAG:INDEX:name notation. You can use Create() to create the "
|
||||
"tag map, and then Names(), Mapping(), and other methods to access the "
|
||||
"tag, index and name information.")
|
||||
mediapipe::Status GetTagAndNameInfo(
|
||||
absl::Status GetTagAndNameInfo(
|
||||
const proto_ns::RepeatedPtrField<ProtoString>& tags_and_names,
|
||||
TagAndNameInfo* info);
|
||||
|
||||
@@ -62,7 +62,7 @@ ABSL_DEPRECATED(
|
||||
"Prefer using mediapipe::tool::TagMap instead, since this method does not "
|
||||
"support the TAG:INDEX:name notation. You can use CanonicalEntries() to "
|
||||
"translate a tag map to a RepeatedPtrField of tag and names.")
|
||||
mediapipe::Status SetFromTagAndNameInfo(
|
||||
absl::Status SetFromTagAndNameInfo(
|
||||
const TagAndNameInfo& info,
|
||||
proto_ns::RepeatedPtrField<ProtoString>* tags_and_names);
|
||||
|
||||
@@ -76,17 +76,17 @@ mediapipe::Status SetFromTagAndNameInfo(
|
||||
// trainer/calculator names.
|
||||
// (3) Because input side packet names end up in model directory names,
|
||||
// where lower case naming is the norm.
|
||||
mediapipe::Status ValidateName(const std::string& name);
|
||||
absl::Status ValidateName(const std::string& name);
|
||||
// The std::string is a valid tag name. Tags use only upper case letters,
|
||||
// numbers, and underscores.
|
||||
mediapipe::Status ValidateTag(const std::string& tag);
|
||||
absl::Status ValidateTag(const std::string& tag);
|
||||
|
||||
// Parse a "Tag and Name" std::string into a tag and a name.
|
||||
// The format is an optional tag and colon, followed by a name.
|
||||
// Example 1: "VIDEO:frames2" -> tag: "VIDEO", name: "frames2"
|
||||
// Example 2: "video_frames_1" -> tag: "", name: "video_frames_1"
|
||||
mediapipe::Status ParseTagAndName(const std::string& tag_and_name,
|
||||
std::string* tag, std::string* name);
|
||||
absl::Status ParseTagAndName(const std::string& tag_and_name, std::string* tag,
|
||||
std::string* name);
|
||||
|
||||
// Parse a generic TAG:index:name std::string. The format is a tag, then an
|
||||
// index, then a name. The tag and index are optional. If the index
|
||||
@@ -96,9 +96,8 @@ mediapipe::Status ParseTagAndName(const std::string& tag_and_name,
|
||||
// "VIDEO:frames2" -> tag: "VIDEO", index: 0, name: "frames2"
|
||||
// "VIDEO:1:frames" -> tag: "VIDEO", index: 1, name: "frames"
|
||||
// "raw_frames" -> tag: "", index: -1, name: "raw_frames"
|
||||
mediapipe::Status ParseTagIndexName(const std::string& tag_and_name,
|
||||
std::string* tag, int* index,
|
||||
std::string* name);
|
||||
absl::Status ParseTagIndexName(const std::string& tag_and_name,
|
||||
std::string* tag, int* index, std::string* name);
|
||||
|
||||
// Parse a generic TAG:index std::string. The format is a tag, then an index
|
||||
// with both being optional. If the tag is missing it is assumed to be
|
||||
@@ -109,8 +108,8 @@ mediapipe::Status ParseTagIndexName(const std::string& tag_and_name,
|
||||
// "VIDEO:1" -> tag: "VIDEO", index: 1
|
||||
// ":2" -> tag: "", index: 2
|
||||
// "" -> tag: "", index: 0
|
||||
mediapipe::Status ParseTagIndex(const std::string& tag_and_index,
|
||||
std::string* tag, int* index);
|
||||
absl::Status ParseTagIndex(const std::string& tag_and_index, std::string* tag,
|
||||
int* index);
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
namespace mediapipe {
|
||||
|
||||
namespace tool {
|
||||
mediapipe::Status RunGeneratorFillExpectations(
|
||||
absl::Status RunGeneratorFillExpectations(
|
||||
const PacketGeneratorConfig& input_config, const std::string& package) {
|
||||
// TODO Remove conversion after everyone uses input/output
|
||||
// side packet.
|
||||
@@ -65,7 +65,7 @@ mediapipe::Status RunGeneratorFillExpectations(
|
||||
}
|
||||
|
||||
// Check that everything got initialized.
|
||||
std::vector<mediapipe::Status> statuses;
|
||||
std::vector<absl::Status> statuses;
|
||||
statuses.push_back(ValidatePacketTypeSet(contract.InputSidePackets()));
|
||||
statuses.push_back(ValidatePacketTypeSet(contract.OutputSidePackets()));
|
||||
return tool::CombinedStatus(
|
||||
@@ -73,7 +73,7 @@ mediapipe::Status RunGeneratorFillExpectations(
|
||||
statuses);
|
||||
}
|
||||
|
||||
mediapipe::Status RunGenerateAndValidateTypes(
|
||||
absl::Status RunGenerateAndValidateTypes(
|
||||
const std::string& packet_generator_name,
|
||||
const PacketGeneratorOptions& extendable_options,
|
||||
const PacketSet& input_side_packets, PacketSet* output_side_packets,
|
||||
@@ -96,7 +96,7 @@ mediapipe::Status RunGenerateAndValidateTypes(
|
||||
.SetPrepend()
|
||||
<< packet_generator_name << "::FillExpectations failed: ";
|
||||
// Check that the types were filled well.
|
||||
std::vector<mediapipe::Status> statuses;
|
||||
std::vector<absl::Status> statuses;
|
||||
statuses.push_back(ValidatePacketTypeSet(input_side_packet_types));
|
||||
statuses.push_back(ValidatePacketTypeSet(output_side_packet_types));
|
||||
MP_RETURN_IF_ERROR(tool::CombinedStatus(
|
||||
@@ -119,7 +119,7 @@ mediapipe::Status RunGenerateAndValidateTypes(
|
||||
<< packet_generator_name
|
||||
<< "::FillExpectations expected different "
|
||||
"output type than those produced: ";
|
||||
return mediapipe::OkStatus();
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace mediapipe {
|
||||
|
||||
namespace tool {
|
||||
// Equivalent functions for PacketGenerators.
|
||||
mediapipe::Status RunGeneratorFillExpectations(
|
||||
absl::Status RunGeneratorFillExpectations(
|
||||
const PacketGeneratorConfig& config,
|
||||
const std::string& package = "mediapipe");
|
||||
|
||||
// Run PacketGenerator::Generate() on the given generator, options,
|
||||
// and inputs to produce outputs. Validate the types of the inputs and
|
||||
// outputs using PacketGenerator::FillExpectations.
|
||||
mediapipe::Status RunGenerateAndValidateTypes(
|
||||
absl::Status RunGenerateAndValidateTypes(
|
||||
const std::string& packet_generator_name,
|
||||
const PacketGeneratorOptions& extendable_options,
|
||||
const PacketSet& input_side_packets, PacketSet* output_side_packets,
|
||||
|
||||
Reference in New Issue
Block a user