Skip to content

Commit

Permalink
prevent duplicate xlink stream names
Browse files Browse the repository at this point in the history
- fixes luxonis#469
- add test case
  • Loading branch information
diablodale committed Apr 14, 2023
1 parent c4af66c commit 782250a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/device/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ bool Device::startPipelineImpl(const Pipeline& pipeline) {
}

// Create DataInputQueue's
auto streamName = xlinkIn->getStreamName();
if (inputQueueMap.count(streamName) != 0)
throw std::invalid_argument(fmt::format("Streams have duplicate name '{}'", streamName));
// set max data size, for more verbosity
inputQueueMap[xlinkIn->getStreamName()] = std::make_shared<DataInputQueue>(connection, xlinkIn->getStreamName(), 16, true, xlinkIn->getMaxDataSize());
inputQueueMap[std::move(streamName)] = std::make_shared<DataInputQueue>(connection, xlinkIn->getStreamName(), 16, true, xlinkIn->getMaxDataSize());
}
for(const auto& kv : pipeline.getNodeMap()) {
const auto& node = kv.second;
Expand All @@ -275,12 +278,14 @@ bool Device::startPipelineImpl(const Pipeline& pipeline) {
continue;
}

auto streamName = xlinkOut->getStreamName();
// Create DataOutputQueue's
auto streamName = xlinkOut->getStreamName();
if (outputQueueMap.count(streamName) != 0)
throw std::invalid_argument(fmt::format("Streams have duplicate name '{}'", streamName));
outputQueueMap[streamName] = std::make_shared<DataOutputQueue>(connection, streamName);

// Add callback for events
callbackIdMap[streamName] = outputQueueMap[streamName]->addCallback([this](std::string queueName, std::shared_ptr<ADatatype>) {
callbackIdMap[std::move(streamName)] = outputQueueMap[xlinkOut->getStreamName()]->addCallback([this](std::string queueName, std::shared_ptr<ADatatype>) {
{
// Lock first
std::unique_lock<std::mutex> lock(eventMtx);
Expand Down
24 changes: 24 additions & 0 deletions tests/src/pipeline_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,27 @@ TEST_CASE("Cross pipeline link with Input and Output") {
// Then check that actually linking throws
REQUIRE_THROWS(xin->out.link(xout->input));
}

TEST_CASE("Duplicate xlink stream names") {
dai::Pipeline p;
auto sysInfo1 = p.create<dai::node::SystemLogger>();
auto sysInfo2 = p.create<dai::node::SystemLogger>();
auto xout1 = p.create<dai::node::XLinkOut>();
auto xout2 = p.create<dai::node::XLinkOut>();
sysInfo1->out.link(xout1->input);
sysInfo2->out.link(xout2->input);
xout1->setStreamName("test1");
xout2->setStreamName("test1");
REQUIRE_THROWS_AS(dai::Device{p}, std::invalid_argument);

p = {};
auto script1 = p.create<dai::node::Script>();
auto script2 = p.create<dai::node::Script>();
auto xin1 = p.create<dai::node::XLinkIn>();
auto xin2 = p.create<dai::node::XLinkIn>();
xin1->out.link(script1->inputs["in"]);
xin2->out.link(script2->inputs["in"]);
xin1->setStreamName("test2");
xin1->setStreamName("test2");
REQUIRE_THROWS_AS(dai::Device{p}, std::invalid_argument);
}

0 comments on commit 782250a

Please sign in to comment.