Project import generated by Copybara.
GitOrigin-RevId: f7d09ed033907b893638a8eb4148efa11c0f09a6
This commit is contained in:
@@ -132,6 +132,7 @@ cc_library(
|
||||
visibility = ["//mediapipe/framework:mediapipe_internal"],
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework:input_stream_shard",
|
||||
"//mediapipe/framework:packet",
|
||||
"//mediapipe/framework:packet_generator_cc_proto",
|
||||
"//mediapipe/framework:packet_set",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define MEDIAPIPE_FRAMEWORK_TOOL_OPTIONS_UTIL_H_
|
||||
|
||||
#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"
|
||||
@@ -96,21 +97,42 @@ void GetNodeOptions(const CalculatorGraphConfig::Node& node_config, T* result) {
|
||||
// packet can hold either the specified options type T or CalculatorOptions.
|
||||
// Fields are either replaced or merged depending on field merge_fields.
|
||||
template <typename T>
|
||||
inline T RetrieveOptions(const T& base, const PacketSet& packet_set,
|
||||
const std::string& tag_name) {
|
||||
if (packet_set.HasTag(tag_name)) {
|
||||
const Packet& packet = packet_set.Tag(tag_name);
|
||||
inline T RetrieveOptions(const T& base, const Packet& options_packet) {
|
||||
if (!options_packet.IsEmpty()) {
|
||||
T packet_options;
|
||||
if (packet.ValidateAsType<T>().ok()) {
|
||||
packet_options = packet.Get<T>();
|
||||
} else if (packet.ValidateAsType<CalculatorOptions>().ok()) {
|
||||
GetExtension<T>(packet.Get<CalculatorOptions>(), &packet_options);
|
||||
if (options_packet.ValidateAsType<T>().ok()) {
|
||||
packet_options = options_packet.Get<T>();
|
||||
} else if (options_packet.ValidateAsType<CalculatorOptions>().ok()) {
|
||||
GetExtension<T>(options_packet.Get<CalculatorOptions>(), &packet_options);
|
||||
}
|
||||
return tool::MergeOptions(base, packet_options);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
// Combine a base options message with an optional side packet from
|
||||
// a PacketSet such as a calculator's input-side-packets.
|
||||
template <typename T>
|
||||
inline T RetrieveOptions(const T& base, const PacketSet& packet_set,
|
||||
const std::string& tag_name = "OPTIONS") {
|
||||
if (packet_set.HasTag(tag_name)) {
|
||||
return tool::RetrieveOptions(base, packet_set.Tag(tag_name));
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
// Combine a base options message with an optional input packet from
|
||||
// an InputStreamShardSet such as a calculator's input streams.
|
||||
template <typename T>
|
||||
inline T RetrieveOptions(const T& base, const InputStreamShardSet& stream_set,
|
||||
const std::string& tag_name = "OPTIONS") {
|
||||
if (stream_set.HasTag(tag_name)) {
|
||||
Packet options_packet = stream_set.Tag(tag_name).Value();
|
||||
return tool::RetrieveOptions(base, options_packet);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
// Extracts the options message of a specified type from a
|
||||
// CalculatorGraphConfig::Node.
|
||||
class OptionsMap {
|
||||
|
||||
Reference in New Issue
Block a user