xlink_roundtrip_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 using namespace std::chrono;
7 using namespace std::chrono_literals;
8 
9 auto TIMEOUT = 5s;
10 
11 static void test_xlink_roundtrip(int w, int h) {
12  std::vector<std::uint8_t> data(w * h * 3);
13 
14  dai::Pipeline p;
15  auto x_in = p.create<dai::node::XLinkIn>();
16  x_in->setStreamName("to_device");
17  x_in->setMaxDataSize(data.size());
18  auto x_out = p.create<dai::node::XLinkOut>();
19  x_out->setStreamName("to_host");
20  x_in->out.link(x_out->input);
21 
22  dai::Device device(p);
23 
24  auto outQ = device.getOutputQueue("to_host");
25  auto inQ = device.getInputQueue("to_device");
26 
27  dai::ImgFrame imgFrame;
28 
29  imgFrame.setSequenceNum(123);
30  imgFrame.setWidth(w);
31  imgFrame.setHeight(h);
32 
33  imgFrame.setData(data);
35  // Send the frame
36  inQ->send(imgFrame);
37 
38  // TODO: add timeout
39  auto t1 = steady_clock::now();
40  bool success = false;
41  do {
42  auto retFrm = outQ->tryGet();
43  if(retFrm) {
44  REQUIRE(imgFrame.getSequenceNum() == 123);
45  return;
46  }
47  } while(steady_clock::now() - t1 < TIMEOUT);
48  // Timeout
49  FAIL("Timeout receiving back the sent message");
50 }
51 
52 TEST_CASE("Test XLinkIn->XLinkOut passthrough with random 1000x1000 frame") {
53  test_xlink_roundtrip(1000, 1000);
54 }
55 
56 TEST_CASE("Test XLinkIn->XLinkOut passthrough with random 2000x1000 frame") {
57  test_xlink_roundtrip(2000, 1000);
58 }
59 
60 TEST_CASE("Test XLinkIn->XLinkOut passthrough with random 4000x3000 frame") {
61  test_xlink_roundtrip(4000, 3000);
62 }
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::ImgFrame::setSequenceNum
ImgFrame & setSequenceNum(int64_t seq)
Definition: pipeline/datatype/ImgFrame.cpp:96
dai::ImgFrame::setWidth
ImgFrame & setWidth(unsigned int width)
Definition: pipeline/datatype/ImgFrame.cpp:99
DAI_SPAN_NAMESPACE_NAME::detail::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.hpp:177
dai::RawImgFrame::Type::BGR888p
@ BGR888p
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
dai::node::XLinkIn::setStreamName
void setStreamName(const std::string &name)
Definition: XLinkIn.cpp:12
dai::Buffer::getSequenceNum
int64_t getSequenceNum() const
Definition: Buffer.cpp:34
dai::ImgFrame
Definition: ImgFrame.hpp:25
dai::Device
Definition: Device.hpp:21
dai::ImgFrame::setType
ImgFrame & setType(Type type)
Definition: pipeline/datatype/ImgFrame.cpp:118
dai::ImgFrame::setHeight
ImgFrame & setHeight(unsigned int height)
Definition: pipeline/datatype/ImgFrame.cpp:105
dai::node::XLinkIn
XLinkIn node. Receives messages over XLink.
Definition: XLinkIn.hpp:14
dai::Device::getInputQueue
std::shared_ptr< DataInputQueue > getInputQueue(const std::string &name)
Definition: Device.cpp:120
dai::node::XLinkOut::setStreamName
void setStreamName(const std::string &name)
Definition: XLinkOut.cpp:13
dai::Buffer::setData
void setData(const std::vector< std::uint8_t > &data)
Definition: Buffer.cpp:17


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