From a7d897989052433b9d47a4ac0c19035ff30cd3e1 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 14 Jun 2019 14:09:21 +0300 Subject: [PATCH] Add get frames to existing client --- components/rgbd-sources/include/ftl/rgbd/streamer.hpp | 4 ++-- components/rgbd-sources/src/net.cpp | 2 +- components/rgbd-sources/src/streamer.cpp | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp index 02025e222..972f48bec 100644 --- a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp @@ -8,7 +8,7 @@ #include <ftl/rgbd/source.hpp> #include <ftl/net/universe.hpp> #include <string> -#include <list> +#include <vector> #include <map> #include <shared_mutex> @@ -32,7 +32,7 @@ struct StreamSource { unsigned int state; // Busy or ready to swap? cv::Mat rgb; // Tx buffer cv::Mat depth; // Tx buffer - std::list<detail::StreamClient> clients[10]; // One list per bitrate + std::vector<detail::StreamClient> clients[10]; // One list per bitrate std::shared_mutex mutex; }; diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp index ac7bc8553..ee89beca2 100644 --- a/components/rgbd-sources/src/net.cpp +++ b/components/rgbd-sources/src/net.cpp @@ -135,7 +135,7 @@ void NetSource::_updateURI() { } bool NetSource::grab() { - if (N_ == 0) { + if (N_ == 1) { N_ += 10; if (!host_->getNet()->send(peer_, "get_stream", *host_->get<string>("uri"), 10, 0, host_->getNet()->id(), *host_->get<string>("uri"))) { active_ = false; diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp index ccf16b170..4c1051397 100644 --- a/components/rgbd-sources/src/streamer.cpp +++ b/components/rgbd-sources/src/streamer.cpp @@ -114,13 +114,22 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID LOG(INFO) << "Adding Stream Peer: " << peer.to_string(); + StreamSource *s = sources_[source]; + for (int i=0; i<s->clients[rate].size(); i++) { + if (s->clients[rate][i].peerid == peer) { + StreamClient &c = s->clients[rate][i]; + c.txmax = N; + c.txcount -= N; + return; + } + } + StreamClient c; c.peerid = peer; c.uri = dest; c.txcount = 0; c.txmax = N; - StreamSource *s = sources_[source]; //unique_lock<shared_mutex> ulk(s->mutex); s->clients[rate].push_back(c); } -- GitLab