unlimited_io_connection_test.cpp
Go to the documentation of this file.
1 #include <catch2/catch_all.hpp>
2 
3 // Include depthai library
4 #include <depthai/depthai.hpp>
5 
6 // Number of IO to test
7 constexpr auto NUM_CONN = 16;
8 
9 // Using
10 using namespace std;
11 using namespace dai;
12 using namespace std::chrono;
13 using namespace std::chrono_literals;
14 
15 TEST_CASE("Test many IO connections after crossing Leon processors") {
16  Pipeline pipeline;
17  auto camRgb = pipeline.create<node::ColorCamera>();
18  camRgb->setInterleaved(true);
19 
20  for(int i = 0; i < NUM_CONN; i++) {
21  string out = "out" + to_string(i);
22  auto xout = pipeline.create<node::XLinkOut>();
23  xout->setStreamName(out);
24  camRgb->preview.link(xout->input);
25  }
26 
27  Device device(pipeline);
28 
29  this_thread::sleep_for(5s);
30 
31  // Set queues to non-blocking
32  std::unordered_map<string, int> numFrames;
33  for(int i = 0; i < NUM_CONN; i++) {
34  string out = "out" + to_string(i);
35  device.getOutputQueue(out, 9, false);
36  numFrames[out] = 0;
37  }
38 
39  // Retrieve at least 10 frames of each, without errors
40  constexpr auto NUM_FRAMES_REQUIRED = 10;
41 
42  bool receivedEnoughFrames = true;
43  auto t1 = steady_clock::now();
44  do {
45  receivedEnoughFrames = true;
46  // Set queues to non-blocking
47  for(int i = 0; i < NUM_CONN; i++) {
48  string out = "out" + to_string(i);
49 
50  auto frame = device.getOutputQueue(out, 9, false)->tryGet();
51  if(frame != nullptr) {
52  numFrames[out]++;
53  }
54 
55  // Check
56  if(numFrames[out] < NUM_FRAMES_REQUIRED) {
57  receivedEnoughFrames = false;
58  }
59  }
60 
61  if(receivedEnoughFrames) {
62  break;
63  }
64  } while(steady_clock::now() - t1 < 5s);
65 
66  cout << "numFrames: ";
67  for(int i = 0; i < NUM_CONN; i++) {
68  string out = "out" + to_string(i);
69  cout << numFrames[out] << ", ";
70  }
71  cout << "\n";
72 
73  REQUIRE(receivedEnoughFrames == true);
74 }
75 
76 TEST_CASE("Test many IO connections before crossing Leon processors") {
77  Pipeline pipeline;
78  auto camRgb = pipeline.create<node::ColorCamera>();
79  camRgb->setInterleaved(false);
80 
81  for(int i = 0; i < NUM_CONN; i++) {
82  string out = "out" + to_string(i);
83  auto manip = pipeline.create<node::ImageManip>();
84  camRgb->preview.link(manip->inputImage);
85  auto xout = pipeline.create<node::XLinkOut>();
86  xout->setStreamName(out);
87  manip->out.link(xout->input);
88  }
89 
90  Device device(pipeline);
91 
92  // Set queues to non-blocking
93  std::unordered_map<string, int> numFrames;
94  for(int i = 0; i < NUM_CONN; i++) {
95  string out = "out" + to_string(i);
96  device.getOutputQueue(out, 9, false);
97  numFrames[out] = 0;
98  }
99 
100  // Retrieve at least 10 frames of each, without errors
101  constexpr auto NUM_FRAMES_REQUIRED = 10;
102 
103  bool receivedEnoughFrames = false;
104  auto t1 = steady_clock::now();
105  do {
106  receivedEnoughFrames = true;
107  // Set queues to non-blocking
108  for(int i = 0; i < NUM_CONN; i++) {
109  string out = "out" + to_string(i);
110  auto frame = device.getOutputQueue(out, 9, false)->tryGet();
111  if(frame != nullptr) {
112  numFrames[out]++;
113  }
114 
115  // Check
116  if(numFrames[out] < NUM_FRAMES_REQUIRED) {
117  receivedEnoughFrames = false;
118  }
119  }
120 
121  if(receivedEnoughFrames) {
122  break;
123  }
124 
125  } while(steady_clock::now() - t1 < 5s);
126 
127  cout << "numFrames: ";
128  for(int i = 0; i < NUM_CONN; i++) {
129  string out = "out" + to_string(i);
130  cout << numFrames[out] << ", ";
131  }
132  cout << "\n";
133 
134  REQUIRE(receivedEnoughFrames == true);
135 }
dai::node::XLinkOut
XLinkOut node. Sends messages over XLink.
Definition: XLinkOut.hpp:14
dai::Pipeline
Represents the pipeline, set of nodes and connections between them.
Definition: Pipeline.hpp:100
dai::node::ColorCamera
ColorCamera node. For use with color sensors.
Definition: ColorCamera.hpp:16
NUM_CONN
constexpr auto NUM_CONN
Definition: unlimited_io_connection_test.cpp:7
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
depthai.hpp
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
nanorpc::core::exception::to_string
std::string to_string(std::exception const &e)
Definition: exception.h:46
dai::node::ImageManip
ImageManip node. Capability to crop, resize, warp, ... incoming image frames.
Definition: ImageManip.hpp:15
dai::node::ColorCamera::setInterleaved
void setInterleaved(bool interleaved)
Set planar or interleaved data of preview output frames.
Definition: ColorCamera.cpp:101
dai::Device
Definition: Device.hpp:21
std
Definition: Node.hpp:366
TEST_CASE
TEST_CASE("Test many IO connections after crossing Leon processors")
Definition: unlimited_io_connection_test.cpp:15
dai::node::XLinkOut::setStreamName
void setStreamName(const std::string &name)
Definition: XLinkOut.cpp:13
dai
Definition: CameraExposureOffset.hpp:6


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19