Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 777962478d88650e311af635e3ac3fa58e5a530b
  • Loading branch information
MediaPipe Team authored and Sebastian Schmidt committed Sep 9, 2022
1 parent 06c30f1 commit b65602f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions mediapipe/calculators/tensor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions mediapipe/calculators/tensor/inference_calculator_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 57 additions & 0 deletions mediapipe/framework/api2/builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,63 @@ TEST(BuilderTest, GraphIndexes) {
EXPECT_THAT(graph.GetConfig(), EqualsProto(expected));
}

class AnyAndSameTypeCalculator : public NodeIntf {
public:
static constexpr Input<AnyType> kAnyTypeInput{"INPUT"};
static constexpr Output<AnyType> kAnyTypeOutput{"ANY_OUTPUT"};
static constexpr Output<SameType<kAnyTypeInput>> kSameTypeOutput{
"SAME_OUTPUT"};

static constexpr Input<int> 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<SameType<kIntInput>>` in a real calculator. You
// should write `Output<int>` instead, since the type is known.
static constexpr Output<SameType<kIntInput>> kSameIntOutput{
"SAME_INT_OUTPUT"};

MEDIAPIPE_NODE_INTERFACE(AnyTypeCalculator, kAnyTypeInput, kAnyTypeOutput,
kSameTypeOutput);
};

TEST(BuilderTest, AnyAndSameTypeHandledProperly) {
builder::Graph graph;
builder::Source<internal::Generic> any_input =
graph[Input<AnyType>{"GRAPH_ANY_INPUT"}];
builder::Source<int> int_input = graph[Input<int>{"GRAPH_INT_INPUT"}];

auto& node = graph.AddNode("AnyAndSameTypeCalculator");
any_input >> node[AnyAndSameTypeCalculator::kAnyTypeInput];
int_input >> node[AnyAndSameTypeCalculator::kIntInput];

builder::Source<internal::Generic> any_type_output =
node[AnyAndSameTypeCalculator::kAnyTypeOutput];
any_type_output.SetName("any_type_output");

builder::Source<internal::Generic> same_type_output =
node[AnyAndSameTypeCalculator::kSameTypeOutput];
same_type_output.SetName("same_type_output");
builder::Source<internal::Generic> same_int_output =
node[AnyAndSameTypeCalculator::kSameIntOutput];
same_int_output.SetName("same_int_output");

CalculatorGraphConfig expected =
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(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
11 changes: 8 additions & 3 deletions mediapipe/framework/api2/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ using HolderBase = mediapipe::packet_internal::HolderBase;
template <typename T>
class Packet;

struct DynamicType {};

struct AnyType : public DynamicType {
AnyType() = delete;
};

// Type-erased packet.
class PacketBase {
public:
Expand Down Expand Up @@ -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 <class V, class U>
struct IsCompatibleType : std::false_type {};
Expand Down
4 changes: 0 additions & 4 deletions mediapipe/framework/api2/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ struct NoneType {
NoneType() = delete;
};

struct DynamicType {};

struct AnyType : public DynamicType {};

template <auto& P>
class SameType : public DynamicType {
public:
Expand Down
2 changes: 1 addition & 1 deletion mediapipe/objc/MPPCameraInputSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b65602f

Please sign in to comment.