25
25
#include " mediapipe/framework/port/status.h"
26
26
#include " mediapipe/framework/port/status_matchers.h"
27
27
28
- namespace mediapipe {
28
+ namespace mediapipe
29
+ {
29
30
30
- namespace {
31
+ namespace
32
+ {
31
33
32
- // A graph with using a BypassCalculator to pass through and ignore
33
- // most of its inputs and outputs.
34
- constexpr char kTestGraphConfig1 [] = R"pb(
34
+ // A graph with using a BypassCalculator to pass through and ignore
35
+ // most of its inputs and outputs.
36
+ constexpr char kTestGraphConfig1 [] = R"pb(
35
37
type: "AppearancesPassThroughSubgraph"
36
38
input_stream: "APPEARANCES:appearances"
37
39
input_stream: "VIDEO:video_frame"
@@ -55,9 +57,9 @@ constexpr char kTestGraphConfig1[] = R"pb(
55
57
}
56
58
)pb" ;
57
59
58
- // A graph with using AppearancesPassThroughSubgraph as a do-nothing channel
59
- // for input frames and appearances.
60
- constexpr char kTestGraphConfig2 [] = R"pb(
60
+ // A graph with using AppearancesPassThroughSubgraph as a do-nothing channel
61
+ // for input frames and appearances.
62
+ constexpr char kTestGraphConfig2 [] = R"pb(
61
63
input_stream: "VIDEO_FULL_RES:video_frame"
62
64
input_stream: "APPEARANCES:input_appearances"
63
65
input_stream: "FEATURE_CONFIG:feature_config"
@@ -82,9 +84,9 @@ constexpr char kTestGraphConfig2[] = R"pb(
82
84
}
83
85
)pb" ;
84
86
85
- // A graph with using BypassCalculator as a do-nothing channel
86
- // for input frames and appearances.
87
- constexpr char kTestGraphConfig3 [] = R"pb(
87
+ // A graph with using BypassCalculator as a do-nothing channel
88
+ // for input frames and appearances.
89
+ constexpr char kTestGraphConfig3 [] = R"pb(
88
90
input_stream: "VIDEO_FULL_RES:video_frame"
89
91
input_stream: "APPEARANCES:input_appearances"
90
92
input_stream: "FEATURE_CONFIG:feature_config"
@@ -117,9 +119,9 @@ constexpr char kTestGraphConfig3[] = R"pb(
117
119
}
118
120
)pb" ;
119
121
120
- // A graph with using BypassCalculator as a disabled-gate
121
- // for input frames and appearances.
122
- constexpr char kTestGraphConfig4 [] = R"pb(
122
+ // A graph with using BypassCalculator as a disabled-gate
123
+ // for input frames and appearances.
124
+ constexpr char kTestGraphConfig4 [] = R"pb(
123
125
input_stream: "VIDEO_FULL_RES:video_frame"
124
126
input_stream: "APPEARANCES:input_appearances"
125
127
input_stream: "FEATURE_CONFIG:feature_config"
@@ -145,127 +147,137 @@ constexpr char kTestGraphConfig4[] = R"pb(
145
147
}
146
148
)pb" ;
147
149
148
- // Reports packet timestamp and string contents, or "<empty>"".
149
- std::string DebugString (Packet p) {
150
- return absl::StrCat (p.Timestamp ().DebugString (), " :" ,
151
- p.IsEmpty () ? " <empty>" : p.Get <std::string>());
152
- }
153
-
154
- // Shows a bypass subgraph that passes through one stream.
155
- TEST (BypassCalculatorTest, SubgraphChannel) {
156
- CalculatorGraphConfig config_1 =
157
- mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig1 );
158
- CalculatorGraphConfig config_2 =
159
- mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig2 );
160
- CalculatorGraph graph;
161
- MP_ASSERT_OK (graph.Initialize ({config_1, config_2}, {}));
162
-
163
- std::vector<std::string> analyzed_appearances;
164
- MP_ASSERT_OK (graph.ObserveOutputStream (
165
- " analyzed_appearances" ,
166
- [&](const Packet& p) {
167
- analyzed_appearances.push_back (DebugString (p));
168
- return absl::OkStatus ();
169
- },
170
- true ));
171
- std::vector<std::string> federated_gaze_output;
172
- MP_ASSERT_OK (graph.ObserveOutputStream (
173
- " federated_gaze_output" ,
174
- [&](const Packet& p) {
175
- federated_gaze_output.push_back (DebugString (p));
176
- return absl::OkStatus ();
177
- },
178
- true ));
179
- MP_ASSERT_OK (graph.StartRun ({}));
180
-
181
- MP_ASSERT_OK (graph.AddPacketToInputStream (
182
- " input_appearances" , MakePacket<std::string>(" a1" ).At (Timestamp (200 ))));
183
- MP_ASSERT_OK (graph.AddPacketToInputStream (
184
- " video_frame" , MakePacket<std::string>(" v1" ).At (Timestamp (200 ))));
185
- MP_ASSERT_OK (graph.AddPacketToInputStream (
186
- " feature_config" , MakePacket<std::string>(" f1" ).At (Timestamp (200 ))));
187
- MP_ASSERT_OK (graph.WaitUntilIdle ());
188
-
189
- EXPECT_THAT (analyzed_appearances, testing::ElementsAre (" 200:a1" ));
190
- EXPECT_THAT (federated_gaze_output, testing::ElementsAre (" 200:<empty>" ));
191
-
192
- MP_ASSERT_OK (graph.CloseAllInputStreams ());
193
- MP_ASSERT_OK (graph.WaitUntilDone ());
194
- }
195
-
196
- // Shows a BypassCalculator that passes through one stream.
197
- TEST (BypassCalculatorTest, CalculatorChannel) {
198
- CalculatorGraphConfig config_3 =
199
- mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig3 );
200
- CalculatorGraph graph;
201
- MP_ASSERT_OK (graph.Initialize ({config_3}, {}));
202
-
203
- std::vector<std::string> analyzed_appearances;
204
- MP_ASSERT_OK (graph.ObserveOutputStream (
205
- " analyzed_appearances" ,
206
- [&](const Packet& p) {
207
- analyzed_appearances.push_back (DebugString (p));
208
- return absl::OkStatus ();
209
- },
210
- true ));
211
- std::vector<std::string> federated_gaze_output;
212
- MP_ASSERT_OK (graph.ObserveOutputStream (
213
- " federated_gaze_output" ,
214
- [&](const Packet& p) {
215
- federated_gaze_output.push_back (DebugString (p));
216
- return absl::OkStatus ();
217
- },
218
- true ));
219
- MP_ASSERT_OK (graph.StartRun ({}));
220
-
221
- MP_ASSERT_OK (graph.AddPacketToInputStream (
222
- " input_appearances" , MakePacket<std::string>(" a1" ).At (Timestamp (200 ))));
223
- MP_ASSERT_OK (graph.AddPacketToInputStream (
224
- " video_frame" , MakePacket<std::string>(" v1" ).At (Timestamp (200 ))));
225
- MP_ASSERT_OK (graph.AddPacketToInputStream (
226
- " feature_config" , MakePacket<std::string>(" f1" ).At (Timestamp (200 ))));
227
- MP_ASSERT_OK (graph.WaitUntilIdle ());
150
+ // Reports packet timestamp and string contents, or "<empty>"".
151
+ std::string DebugString (Packet p)
152
+ {
153
+ return absl::StrCat (p.Timestamp ().DebugString (), " :" ,
154
+ p.IsEmpty () ? " <empty>" : p.Get <std::string>());
155
+ }
228
156
229
- EXPECT_THAT (analyzed_appearances, testing::ElementsAre (" 200:a1" ));
230
- EXPECT_THAT (federated_gaze_output, testing::ElementsAre (" 200:<empty>" ));
157
+ // Shows a bypass subgraph that passes through one stream.
158
+ TEST (BypassCalculatorTest, SubgraphChannel)
159
+ {
160
+ CalculatorGraphConfig config_1 =
161
+ mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig1 );
162
+ CalculatorGraphConfig config_2 =
163
+ mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig2 );
164
+ CalculatorGraph graph;
165
+ MP_ASSERT_OK (graph.Initialize ({config_1, config_2}, {}));
166
+
167
+ std::vector<std::string> analyzed_appearances;
168
+ MP_ASSERT_OK (graph.ObserveOutputStream (
169
+ " analyzed_appearances" ,
170
+ [&](const Packet &p)
171
+ {
172
+ analyzed_appearances.push_back (DebugString (p));
173
+ return absl::OkStatus ();
174
+ },
175
+ true ));
176
+ std::vector<std::string> federated_gaze_output;
177
+ MP_ASSERT_OK (graph.ObserveOutputStream (
178
+ " federated_gaze_output" ,
179
+ [&](const Packet &p)
180
+ {
181
+ federated_gaze_output.push_back (DebugString (p));
182
+ return absl::OkStatus ();
183
+ },
184
+ true ));
185
+ MP_ASSERT_OK (graph.StartRun ({}));
186
+
187
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
188
+ " input_appearances" , MakePacket<std::string>(" a1" ).At (Timestamp (200 ))));
189
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
190
+ " video_frame" , MakePacket<std::string>(" v1" ).At (Timestamp (200 ))));
191
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
192
+ " feature_config" , MakePacket<std::string>(" f1" ).At (Timestamp (200 ))));
193
+ MP_ASSERT_OK (graph.WaitUntilIdle ());
194
+
195
+ EXPECT_THAT (analyzed_appearances, testing::ElementsAre (" 200:a1" ));
196
+ EXPECT_THAT (federated_gaze_output, testing::ElementsAre (" 200:<empty>" ));
197
+
198
+ MP_ASSERT_OK (graph.CloseAllInputStreams ());
199
+ MP_ASSERT_OK (graph.WaitUntilDone ());
200
+ }
231
201
232
- MP_ASSERT_OK (graph.CloseAllInputStreams ());
233
- MP_ASSERT_OK (graph.WaitUntilDone ());
234
- }
235
-
236
- // Shows a BypassCalculator that discards all inputs when ENABLED is false.
237
- TEST (BypassCalculatorTest, GatedChannel) {
238
- CalculatorGraphConfig config_3 =
239
- mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig4 );
240
- CalculatorGraph graph;
241
- MP_ASSERT_OK (graph.Initialize ({config_3}, {}));
242
-
243
- std::vector<std::string> analyzed_appearances;
244
- MP_ASSERT_OK (graph.ObserveOutputStream (
245
- " analyzed_appearances" ,
246
- [&](const Packet& p) {
247
- analyzed_appearances.push_back (DebugString (p));
248
- return absl::OkStatus ();
249
- },
250
- true ));
251
- std::vector<std::string> video_frame;
252
- MP_ASSERT_OK (graph.ObserveOutputStream (
253
- " video_frame_out" ,
254
- [&](const Packet& p) {
255
- video_frame.push_back (DebugString (p));
256
- return absl::OkStatus ();
257
- },
258
- true ));
259
- MP_ASSERT_OK (graph.StartRun ({}));
260
-
261
- // Close the gate.
262
- MP_ASSERT_OK (graph.AddPacketToInputStream (
263
- " gaze_enabled" , MakePacket<bool >(false ).At (Timestamp (200 ))));
264
- MP_ASSERT_OK (graph.WaitUntilIdle ());
202
+ // Shows a BypassCalculator that passes through one stream.
203
+ TEST (BypassCalculatorTest, CalculatorChannel)
204
+ {
205
+ CalculatorGraphConfig config_3 =
206
+ mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig3 );
207
+ CalculatorGraph graph;
208
+ MP_ASSERT_OK (graph.Initialize ({config_3}, {}));
209
+
210
+ std::vector<std::string> analyzed_appearances;
211
+ MP_ASSERT_OK (graph.ObserveOutputStream (
212
+ " analyzed_appearances" ,
213
+ [&](const Packet &p)
214
+ {
215
+ analyzed_appearances.push_back (DebugString (p));
216
+ return absl::OkStatus ();
217
+ },
218
+ true ));
219
+ std::vector<std::string> federated_gaze_output;
220
+ MP_ASSERT_OK (graph.ObserveOutputStream (
221
+ " federated_gaze_output" ,
222
+ [&](const Packet &p)
223
+ {
224
+ federated_gaze_output.push_back (DebugString (p));
225
+ return absl::OkStatus ();
226
+ },
227
+ true ));
228
+ MP_ASSERT_OK (graph.StartRun ({}));
229
+
230
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
231
+ " input_appearances" , MakePacket<std::string>(" a1" ).At (Timestamp (200 ))));
232
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
233
+ " video_frame" , MakePacket<std::string>(" v1" ).At (Timestamp (200 ))));
234
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
235
+ " feature_config" , MakePacket<std::string>(" f1" ).At (Timestamp (200 ))));
236
+ MP_ASSERT_OK (graph.WaitUntilIdle ());
237
+
238
+ EXPECT_THAT (analyzed_appearances, testing::ElementsAre (" 200:a1" ));
239
+ EXPECT_THAT (federated_gaze_output, testing::ElementsAre (" 200:<empty>" ));
240
+
241
+ MP_ASSERT_OK (graph.CloseAllInputStreams ());
242
+ MP_ASSERT_OK (graph.WaitUntilDone ());
243
+ }
265
244
266
- // Send packets at timestamp 200.
245
+ // Shows a BypassCalculator that discards all inputs when ENABLED is false.
246
+ TEST (BypassCalculatorTest, GatedChannel)
247
+ {
248
+ CalculatorGraphConfig config_3 =
249
+ mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(kTestGraphConfig4 );
250
+ CalculatorGraph graph;
251
+ MP_ASSERT_OK (graph.Initialize ({config_3}, {}));
252
+
253
+ std::vector<std::string> analyzed_appearances;
254
+ MP_ASSERT_OK (graph.ObserveOutputStream (
255
+ " analyzed_appearances" ,
256
+ [&](const Packet &p)
257
+ {
258
+ analyzed_appearances.push_back (DebugString (p));
259
+ return absl::OkStatus ();
260
+ },
261
+ true ));
262
+ std::vector<std::string> video_frame;
263
+ MP_ASSERT_OK (graph.ObserveOutputStream (
264
+ " video_frame_out" ,
265
+ [&](const Packet &p)
266
+ {
267
+ video_frame.push_back (DebugString (p));
268
+ return absl::OkStatus ();
269
+ },
270
+ true ));
271
+ MP_ASSERT_OK (graph.StartRun ({}));
272
+
273
+ // Close the gate.
274
+ MP_ASSERT_OK (graph.AddPacketToInputStream (
275
+ " gaze_enabled" , MakePacket<bool >(false ).At (Timestamp (200 ))));
276
+ MP_ASSERT_OK (graph.WaitUntilIdle ());
277
+
278
+ // Send packets at timestamp 200.
267
279
MP_ASSERT_OK (graph.AddPacketToInputStream (
268
- " input_appearances" , MakePacket<std::string>(" a1" ). At ( Timestamp (200 ))));
280
+ " input_appearances" , MakePacket<std::string>(" a1" )Timestamp (200 ))));
269
281
MP_ASSERT_OK (graph.AddPacketToInputStream (
270
282
" video_frame" , MakePacket<std::string>(" v1" ).At (Timestamp (200 ))));
271
283
MP_ASSERT_OK (graph.AddPacketToInputStream (
@@ -297,8 +309,8 @@ TEST(BypassCalculatorTest, GatedChannel) {
297
309
298
310
MP_ASSERT_OK (graph.CloseAllInputStreams ());
299
311
MP_ASSERT_OK (graph.WaitUntilDone ());
300
- }
312
+ }
301
313
302
- } // namespace
314
+ } // namespace
303
315
304
- } // namespace mediapipe
316
+ } // namespace mediapipe
0 commit comments