Internal change

PiperOrigin-RevId: 570745425
This commit is contained in:
Daniel Cheng
2023-10-04 11:09:36 -07:00
committed by Copybara-Service
parent 3b99f8d9dd
commit d2baba6dbb
162 changed files with 961 additions and 919 deletions
@@ -175,7 +175,8 @@ StatusOr<int> FindExtensionIndex(const FieldData& message_data,
}
std::string& extension_type = entry->extension_type;
std::vector<FieldData> field_values;
ASSIGN_OR_RETURN(field_values, GetFieldValues(message_data, *entry->field));
MP_ASSIGN_OR_RETURN(field_values,
GetFieldValues(message_data, *entry->field));
for (int i = 0; i < field_values.size(); ++i) {
FieldData extension = ParseProtobufAny(field_values[i]);
if (extension_type == "*" ||
@@ -275,7 +276,7 @@ absl::Status FindExtension(const FieldData& message_data,
}
// For repeated protobuf::Any, find the index for the extension_type.
ASSIGN_OR_RETURN(int index, FindExtensionIndex(message_data, entry));
MP_ASSIGN_OR_RETURN(int index, FindExtensionIndex(message_data, entry));
if (index != -1) {
entry->index = index;
return absl::OkStatus();
@@ -367,7 +368,7 @@ absl::StatusOr<std::vector<FieldData>> GetFieldValues(
MP_RETURN_IF_ERROR(FindExtension(message_data, &head));
}
RET_CHECK_NE(head.field, nullptr);
ASSIGN_OR_RETURN(results, GetFieldValues(message_data, *head.field));
MP_ASSIGN_OR_RETURN(results, GetFieldValues(message_data, *head.field));
if (IsProtobufAny(head.field)) {
for (int i = 0; i < results.size(); ++i) {
results[i] = ParseProtobufAny(results[i]);
@@ -381,7 +382,7 @@ absl::StatusOr<std::vector<FieldData>> GetFieldValues(
}
if (!tail.empty()) {
FieldData child = results.at(index);
ASSIGN_OR_RETURN(results, GetFieldValues(child, tail));
MP_ASSIGN_OR_RETURN(results, GetFieldValues(child, tail));
} else if (index > -1) {
FieldData child = results.at(index);
results.clear();
@@ -394,7 +395,7 @@ absl::StatusOr<std::vector<FieldData>> GetFieldValues(
absl::StatusOr<FieldData> GetField(const FieldData& message_data,
const FieldPath& field_path) {
std::vector<FieldData> results;
ASSIGN_OR_RETURN(results, GetFieldValues(message_data, field_path));
MP_ASSIGN_OR_RETURN(results, GetFieldValues(message_data, field_path));
if (results.empty()) {
FieldPathEntry tail = field_path.back();
return absl::OutOfRangeError(absl::StrCat(
@@ -452,12 +453,12 @@ absl::Status MergeFieldValues(FieldData& message_data,
: field_path.back().field->type();
std::vector<FieldData> results = values;
std::vector<FieldData> prevs;
ASSIGN_OR_RETURN(prevs, GetFieldValues(message_data, field_path));
MP_ASSIGN_OR_RETURN(prevs, GetFieldValues(message_data, field_path));
if (field_type == FieldType::TYPE_MESSAGE) {
for (int i = 0; i < std::min(values.size(), prevs.size()); ++i) {
FieldData& v = results[i];
FieldData& b = prevs[i];
ASSIGN_OR_RETURN(v, MergeMessages(b, v));
MP_ASSIGN_OR_RETURN(v, MergeMessages(b, v));
}
}
status.Update(SetFieldValues(message_data, field_path, results));
+6 -5
View File
@@ -88,11 +88,11 @@ absl::Status CopyLiteralOptions(CalculatorGraphConfig::Node parent_node,
FieldData parent_options;
ASSIGN_IF_OK(parent_options,
GetNodeOptions(parent_data, graph_extension_type));
ASSIGN_OR_RETURN(graph_options,
MergeMessages(graph_options, parent_options));
MP_ASSIGN_OR_RETURN(graph_options,
MergeMessages(graph_options, parent_options));
FieldData node_options;
ASSIGN_OR_RETURN(node_options,
GetNodeOptions(node_data, node_extension_type));
MP_ASSIGN_OR_RETURN(node_options,
GetNodeOptions(node_data, node_extension_type));
if (!node_options.has_message_value() ||
!graph_options.has_message_value()) {
continue;
@@ -100,7 +100,8 @@ absl::Status CopyLiteralOptions(CalculatorGraphConfig::Node parent_node,
FieldPath graph_path = GetPath(graph_tag, MessageType(graph_options));
FieldPath node_path = GetPath(node_tag, MessageType(node_options));
std::vector<FieldData> packet_data;
ASSIGN_OR_RETURN(packet_data, GetFieldValues(graph_options, graph_path));
MP_ASSIGN_OR_RETURN(packet_data,
GetFieldValues(graph_options, graph_path));
MP_RETURN_IF_ERROR(
MergeFieldValues(node_options, node_path, packet_data));
options_field_util::SetOptionsMessage(node_options, &node);
@@ -338,8 +338,8 @@ absl::Status Equals(std::vector<FieldData> b1, std::vector<FieldData> b2) {
using tool::options_field_util::AsPacket;
RET_CHECK_EQ(b1.size(), b2.size());
for (int i = 0; i < b1.size(); ++i) {
ASSIGN_OR_RETURN(Packet p1, AsPacket(b1.at(i)));
ASSIGN_OR_RETURN(Packet p2, AsPacket(b2.at(i)));
MP_ASSIGN_OR_RETURN(Packet p1, AsPacket(b1.at(i)));
MP_ASSIGN_OR_RETURN(Packet p2, AsPacket(b2.at(i)));
MP_RETURN_IF_ERROR(Equals(p1.Get<FieldType>(), p2.Get<FieldType>()));
}
return absl::OkStatus();
@@ -15,10 +15,10 @@ absl::Status PacketGeneratorWrapperCalculator::GetContract(
CalculatorContract* cc) {
const auto& options =
cc->Options<::mediapipe::PacketGeneratorWrapperCalculatorOptions>();
ASSIGN_OR_RETURN(auto static_access,
mediapipe::internal::StaticAccessToGeneratorRegistry::
CreateByNameInNamespace(options.package(),
options.packet_generator()));
MP_ASSIGN_OR_RETURN(auto static_access,
mediapipe::internal::StaticAccessToGeneratorRegistry::
CreateByNameInNamespace(options.package(),
options.packet_generator()));
MP_RETURN_IF_ERROR(static_access->FillExpectations(options.options(),
&cc->InputSidePackets(),
&cc->OutputSidePackets()))
@@ -30,10 +30,10 @@ absl::Status PacketGeneratorWrapperCalculator::GetContract(
absl::Status PacketGeneratorWrapperCalculator::Open(CalculatorContext* cc) {
const auto& options =
cc->Options<::mediapipe::PacketGeneratorWrapperCalculatorOptions>();
ASSIGN_OR_RETURN(auto static_access,
mediapipe::internal::StaticAccessToGeneratorRegistry::
CreateByNameInNamespace(options.package(),
options.packet_generator()));
MP_ASSIGN_OR_RETURN(auto static_access,
mediapipe::internal::StaticAccessToGeneratorRegistry::
CreateByNameInNamespace(options.package(),
options.packet_generator()));
mediapipe::PacketSet output_packets(cc->OutputSidePackets().TagMap());
MP_RETURN_IF_ERROR(static_access->Generate(options.options(),
cc->InputSidePackets(),
+3 -3
View File
@@ -196,7 +196,7 @@ absl::Status ProtoUtilLite::ReplaceFieldRange(
proto_path.erase(proto_path.begin());
FieldType type =
!proto_path.empty() ? WireFormatLite::TYPE_MESSAGE : field_type;
ASSIGN_OR_RETURN(auto r, AccessField(entry, type, *message));
MP_ASSIGN_OR_RETURN(auto r, AccessField(entry, type, *message));
FieldAccess& access = r.first;
int index = r.second;
std::vector<FieldValue>& v = *access.mutable_field_values();
@@ -223,7 +223,7 @@ absl::Status ProtoUtilLite::GetFieldRange(
proto_path.erase(proto_path.begin());
FieldType type =
!proto_path.empty() ? WireFormatLite::TYPE_MESSAGE : field_type;
ASSIGN_OR_RETURN(auto r, AccessField(entry, type, message));
MP_ASSIGN_OR_RETURN(auto r, AccessField(entry, type, message));
FieldAccess& access = r.first;
int index = r.second;
std::vector<FieldValue>& v = *access.mutable_field_values();
@@ -252,7 +252,7 @@ absl::Status ProtoUtilLite::GetFieldCount(const FieldValue& message,
proto_path.erase(proto_path.begin());
FieldType type =
!proto_path.empty() ? WireFormatLite::TYPE_MESSAGE : field_type;
ASSIGN_OR_RETURN(auto r, AccessField(entry, type, message));
MP_ASSIGN_OR_RETURN(auto r, AccessField(entry, type, message));
FieldAccess& access = r.first;
int index = r.second;
std::vector<FieldValue>& v = *access.mutable_field_values();
@@ -62,8 +62,8 @@ absl::Status FindIgnoredStreams(
const proto_ns::RepeatedPtrField<ProtoString>& src_streams,
const proto_ns::RepeatedPtrField<ProtoString>& dst_streams,
std::set<std::string>* result) {
ASSIGN_OR_RETURN(auto src_map, tool::TagMap::Create(src_streams));
ASSIGN_OR_RETURN(auto dst_map, tool::TagMap::Create(dst_streams));
MP_ASSIGN_OR_RETURN(auto src_map, tool::TagMap::Create(src_streams));
MP_ASSIGN_OR_RETURN(auto dst_map, tool::TagMap::Create(dst_streams));
for (auto id = src_map->BeginId(); id < src_map->EndId(); ++id) {
std::pair<std::string, int> tag_index = src_map->TagAndIndexFromId(id);
if (!dst_map->GetId(tag_index.first, tag_index.second).IsValid()) {
@@ -149,8 +149,8 @@ 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) {
ASSIGN_OR_RETURN(auto src_map, tool::TagMap::Create(src_streams));
ASSIGN_OR_RETURN(auto dst_map, tool::TagMap::Create(dst_streams));
MP_ASSIGN_OR_RETURN(auto src_map, tool::TagMap::Create(src_streams));
MP_ASSIGN_OR_RETURN(auto dst_map, tool::TagMap::Create(dst_streams));
for (const auto& it : dst_map->Mapping()) {
const std::string& tag = it.first;
const TagMap::TagData* src_tag_data =
@@ -299,9 +299,10 @@ absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
std::string node_name = CanonicalNodeName(*config, node_id);
MP_RETURN_IF_ERROR(ValidateSubgraphFields(node));
SubgraphContext subgraph_context(&node, service_manager);
ASSIGN_OR_RETURN(auto subgraph, graph_registry->CreateByName(
config->package(), node.calculator(),
&subgraph_context));
MP_ASSIGN_OR_RETURN(
auto subgraph,
graph_registry->CreateByName(config->package(), node.calculator(),
&subgraph_context));
MP_RETURN_IF_ERROR(mediapipe::tool::DefineGraphOptions(node, &subgraph));
MP_RETURN_IF_ERROR(PrefixNames(node_name, &subgraph));
MP_RETURN_IF_ERROR(ConnectSubgraphStreams(node, &subgraph));
@@ -8,10 +8,10 @@ namespace mediapipe {
absl::Status GraphProcessor::Initialize(CalculatorGraphConfig graph_config) {
graph_config_ = graph_config;
ASSIGN_OR_RETURN(graph_input_map_,
tool::TagMap::Create(graph_config_.input_stream()));
ASSIGN_OR_RETURN(graph_output_map_,
tool::TagMap::Create(graph_config_.output_stream()));
MP_ASSIGN_OR_RETURN(graph_input_map_,
tool::TagMap::Create(graph_config_.input_stream()));
MP_ASSIGN_OR_RETURN(graph_output_map_,
tool::TagMap::Create(graph_config_.output_stream()));
return absl::OkStatus();
}
+1 -1
View File
@@ -53,7 +53,7 @@ class TagMap {
// Create a TagMap from a repeated string proto field of TAG:<index>:name.
// This is the most common usage:
// ASSIGN_OR_RETURN(std::shared_ptr<TagMap> tag_map,
// MP_ASSIGN_OR_RETURN(std::shared_ptr<TagMap> tag_map,
// tool::TagMap::Create(node.input_streams()));
static absl::StatusOr<std::shared_ptr<TagMap>> Create(
const proto_ns::RepeatedPtrField<ProtoString>& tag_index_names) {
+6 -4
View File
@@ -215,22 +215,24 @@ bool CompareImageFrames(const ImageFrame& image1, const ImageFrame& image2,
absl::Status CompareAndSaveImageOutput(
absl::string_view golden_image_path, const ImageFrame& actual,
const ImageFrameComparisonOptions& options) {
ASSIGN_OR_RETURN(auto output_img_path, SavePngTestOutput(actual, "output"));
MP_ASSIGN_OR_RETURN(auto output_img_path,
SavePngTestOutput(actual, "output"));
auto expected =
LoadTestImage(GetTestFilePath(golden_image_path), ImageFormat::UNKNOWN);
if (!expected.ok()) {
return expected.status();
}
ASSIGN_OR_RETURN(auto expected_img_path,
SavePngTestOutput(**expected, "expected"));
MP_ASSIGN_OR_RETURN(auto expected_img_path,
SavePngTestOutput(**expected, "expected"));
std::unique_ptr<ImageFrame> diff_img;
auto status = CompareImageFrames(**expected, actual, options.max_color_diff,
options.max_alpha_diff, options.max_avg_diff,
diff_img);
if (diff_img) {
ASSIGN_OR_RETURN(auto diff_img_path, SavePngTestOutput(*diff_img, "diff"));
MP_ASSIGN_OR_RETURN(auto diff_img_path,
SavePngTestOutput(*diff_img, "diff"));
}
return status;
+2 -2
View File
@@ -46,7 +46,7 @@ absl::Status RunGeneratorFillExpectations(
// side packet.
PacketGeneratorConfig config = input_config;
ASSIGN_OR_RETURN(
MP_ASSIGN_OR_RETURN(
auto static_access,
internal::StaticAccessToGeneratorRegistry::CreateByNameInNamespace(
package, config.packet_generator()),
@@ -81,7 +81,7 @@ absl::Status RunGenerateAndValidateTypes(
const std::string& package) {
ABSL_CHECK(output_side_packets);
// Get static access to functions.
ASSIGN_OR_RETURN(
MP_ASSIGN_OR_RETURN(
auto static_access,
internal::StaticAccessToGeneratorRegistry::CreateByNameInNamespace(
package, packet_generator_name),