diff --git a/mediapipe/calculators/tensor/BUILD b/mediapipe/calculators/tensor/BUILD index aaa08c934..c378df7d0 100644 --- a/mediapipe/calculators/tensor/BUILD +++ b/mediapipe/calculators/tensor/BUILD @@ -298,6 +298,7 @@ cc_library( hdrs = ["inference_calculator_utils.h"], deps = [ ":inference_calculator_cc_proto", + "//mediapipe/framework:port", ] + select({ "//conditions:default": [ "//mediapipe/util:cpu_util", diff --git a/mediapipe/calculators/tensor/inference_calculator_utils.cc b/mediapipe/calculators/tensor/inference_calculator_utils.cc index da18ea6fa..11ded02bc 100644 --- a/mediapipe/calculators/tensor/inference_calculator_utils.cc +++ b/mediapipe/calculators/tensor/inference_calculator_utils.cc @@ -15,6 +15,7 @@ #include "mediapipe/calculators/tensor/inference_calculator_utils.h" #include "mediapipe/calculators/tensor/inference_calculator.pb.h" +#include "mediapipe/framework/port.h" // NOLINT: provides MEDIAPIPE_ANDROID/IOS #if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__) #include "mediapipe/util/cpu_util.h" diff --git a/mediapipe/framework/api2/builder_test.cc b/mediapipe/framework/api2/builder_test.cc index e2c1820e7..28e42da97 100644 --- a/mediapipe/framework/api2/builder_test.cc +++ b/mediapipe/framework/api2/builder_test.cc @@ -324,6 +324,63 @@ TEST(BuilderTest, GraphIndexes) { EXPECT_THAT(graph.GetConfig(), EqualsProto(expected)); } +class AnyAndSameTypeCalculator : public NodeIntf { + public: + static constexpr Input kAnyTypeInput{"INPUT"}; + static constexpr Output kAnyTypeOutput{"ANY_OUTPUT"}; + static constexpr Output> kSameTypeOutput{ + "SAME_OUTPUT"}; + + static constexpr Input kIntInput{"INT_INPUT"}; + // `SameType` usage for this output is only for testing purposes. + // + // `SameType` is designed to work with inputs of `AnyType` and, normally, you + // would not use `Output>` in a real calculator. You + // should write `Output` instead, since the type is known. + static constexpr Output> kSameIntOutput{ + "SAME_INT_OUTPUT"}; + + MEDIAPIPE_NODE_INTERFACE(AnyTypeCalculator, kAnyTypeInput, kAnyTypeOutput, + kSameTypeOutput); +}; + +TEST(BuilderTest, AnyAndSameTypeHandledProperly) { + builder::Graph graph; + builder::Source any_input = + graph[Input{"GRAPH_ANY_INPUT"}]; + builder::Source int_input = graph[Input{"GRAPH_INT_INPUT"}]; + + auto& node = graph.AddNode("AnyAndSameTypeCalculator"); + any_input >> node[AnyAndSameTypeCalculator::kAnyTypeInput]; + int_input >> node[AnyAndSameTypeCalculator::kIntInput]; + + builder::Source any_type_output = + node[AnyAndSameTypeCalculator::kAnyTypeOutput]; + any_type_output.SetName("any_type_output"); + + builder::Source same_type_output = + node[AnyAndSameTypeCalculator::kSameTypeOutput]; + same_type_output.SetName("same_type_output"); + builder::Source same_int_output = + node[AnyAndSameTypeCalculator::kSameIntOutput]; + same_int_output.SetName("same_int_output"); + + CalculatorGraphConfig expected = + mediapipe::ParseTextProtoOrDie(R"pb( + node { + calculator: "AnyAndSameTypeCalculator" + input_stream: "INPUT:__stream_0" + input_stream: "INT_INPUT:__stream_1" + output_stream: "ANY_OUTPUT:any_type_output" + output_stream: "SAME_INT_OUTPUT:same_int_output" + output_stream: "SAME_OUTPUT:same_type_output" + } + input_stream: "GRAPH_ANY_INPUT:__stream_0" + input_stream: "GRAPH_INT_INPUT:__stream_1" + )pb"); + EXPECT_THAT(graph.GetConfig(), EqualsProto(expected)); +} + } // namespace test } // namespace api2 } // namespace mediapipe diff --git a/mediapipe/framework/api2/packet.h b/mediapipe/framework/api2/packet.h index 80d2307ae..4ff726da0 100644 --- a/mediapipe/framework/api2/packet.h +++ b/mediapipe/framework/api2/packet.h @@ -27,6 +27,12 @@ using HolderBase = mediapipe::packet_internal::HolderBase; template class Packet; +struct DynamicType {}; + +struct AnyType : public DynamicType { + AnyType() = delete; +}; + // Type-erased packet. class PacketBase { public: @@ -148,9 +154,8 @@ inline void CheckCompatibleType(const HolderBase& holder, << " was requested."; } -struct Generic { - Generic() = delete; -}; +// TODO: remove usage of internal::Generic and simply use AnyType. +using Generic = ::mediapipe::api2::AnyType; template struct IsCompatibleType : std::false_type {}; diff --git a/mediapipe/framework/api2/port.h b/mediapipe/framework/api2/port.h index b972359e9..a408831bc 100644 --- a/mediapipe/framework/api2/port.h +++ b/mediapipe/framework/api2/port.h @@ -77,10 +77,6 @@ struct NoneType { NoneType() = delete; }; -struct DynamicType {}; - -struct AnyType : public DynamicType {}; - template class SameType : public DynamicType { public: diff --git a/mediapipe/objc/MPPCameraInputSource.h b/mediapipe/objc/MPPCameraInputSource.h index 9bb7439b5..3438b3aeb 100644 --- a/mediapipe/objc/MPPCameraInputSource.h +++ b/mediapipe/objc/MPPCameraInputSource.h @@ -23,7 +23,7 @@ @property(nonatomic, getter=isAuthorized, readonly) BOOL authorized; /// Session preset to use for capturing. -@property(nonatomic) NSString *sessionPreset; +@property(nonatomic, nullable) NSString *sessionPreset; /// Which camera on an iOS device to use, assuming iOS device with more than one camera. @property(nonatomic) AVCaptureDevicePosition cameraPosition;