diff --git a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp index e7c4b85819ac8b5da82d19c6cf85661d170afbe2..3ca7b8574c972e829873c492677253702399bd05 100644 --- a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp @@ -16,8 +16,8 @@ namespace ftl { namespace rgbd { -static const int kChunkDim = 4; -static constexpr int kChunkCount = kChunkDim * kChunkDim; +//static const int kChunkDim = 4; +//static constexpr int kChunkCount = kChunkDim * kChunkDim; namespace detail { @@ -122,6 +122,8 @@ class Streamer : public ftl::Configurable { ftl::UUID time_peer_; int64_t last_frame_; int64_t frame_no_; + size_t chunk_count_; + size_t chunk_dim_; int64_t mspf_; float actual_fps_; diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp index 86fa08a2b9adbddce2529e992bccc0f5307cd012..e0e5ff11dd69d29f0de456c7b8f05fce3bdc7d23 100644 --- a/components/rgbd-sources/src/net.cpp +++ b/components/rgbd-sources/src/net.cpp @@ -147,6 +147,9 @@ NetSource::NetSource(ftl::rgbd::Source *host) default_quality_ = host->value("quality", 0); }); + chunks_dim_ = host->value("chunking",4); + chunk_count_ = chunks_dim_*chunks_dim_; + _updateURI(); h_ = host_->getNet()->onConnect([this](ftl::net::Peer *p) { @@ -228,13 +231,13 @@ void NetSource::_recvChunk(int64_t ts, int chunk, bool delta, const vector<unsig ++frame.chunk_count; - if (frame.chunk_count > kChunkCount) LOG(FATAL) << "TOO MANY CHUNKS"; + if (frame.chunk_count > chunk_count_) LOG(FATAL) << "TOO MANY CHUNKS"; - if (frame.chunk_count == kChunkCount) { + if (frame.chunk_count == chunk_count_) { UNIQUE_LOCK(frame.mtx, flk); timestamp_ = frame.timestamp; - if (frame.timestamp >= 0 && frame.chunk_count == kChunkCount) { + if (frame.timestamp >= 0 && frame.chunk_count == chunk_count_) { //LOG(INFO) << "Frame finished"; auto cb = host_->callback(); if (cb) { @@ -308,7 +311,7 @@ void NetSource::_updateURI() { N_ = 0; // Update chunk details - chunks_dim_ = ftl::rgbd::kChunkDim; + //chunks_dim_ = ftl::rgbd::kChunkDim; chunk_width_ = params_.width / chunks_dim_; chunk_height_ = params_.height / chunks_dim_; //chunk_count_ = 0; diff --git a/components/rgbd-sources/src/net.hpp b/components/rgbd-sources/src/net.hpp index 52852320a89db79a3b8534e63cdd1a07967f9a32..23206896c844cf4a29aa844771d66347010305d6 100644 --- a/components/rgbd-sources/src/net.hpp +++ b/components/rgbd-sources/src/net.hpp @@ -79,6 +79,7 @@ class NetSource : public detail::Source { int minB_; int maxN_; int default_quality_; + int chunk_count_; ftl::rgbd::channel_t prev_chan_; //volatile int64_t current_frame_; //std::atomic<int> chunk_count_; diff --git a/components/rgbd-sources/src/stereovideo.cpp b/components/rgbd-sources/src/stereovideo.cpp index 84cf30c0013c9bc268ab715d3e23f3606aa3313a..57e57fbbd245ee9e8f4e7038d4b24b85b4259145 100644 --- a/components/rgbd-sources/src/stereovideo.cpp +++ b/components/rgbd-sources/src/stereovideo.cpp @@ -206,8 +206,6 @@ bool StereoVideoSource::compute(int n, int b) { stream_.waitForCompletion(); // TODO:(Nick) Move to getFrames } - LOG(INFO) << "STEREO VIDEO COMPUTE: " << timestamp_; - auto cb = host_->callback(); if (cb) cb(timestamp_, rgb_, depth_); return true; diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp index e854ac590e03c9fc291edca479981a90f939a6be..6998ca83c7110d6bef6403410dd042d5fd782625 100644 --- a/components/rgbd-sources/src/streamer.cpp +++ b/components/rgbd-sources/src/streamer.cpp @@ -37,6 +37,9 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) //last_dropped_ = 0; //drop_count_ = 0; + chunk_dim_ = value("chunking",4); + chunk_count_ = chunk_dim_*chunk_dim_; + //group_.setFPS(value("fps", 20)); group_.setLatency(10); @@ -105,8 +108,6 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) net->bind("set_channel", [this](const string &uri, unsigned int chan) { SHARED_LOCK(mutex_,slk); - LOG(INFO) << "SET CHANNEL " << chan; - if (sources_.find(uri) != sources_.end()) { sources_[uri]->src->setChannel((ftl::rgbd::channel_t)chan); } @@ -189,7 +190,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID for (auto &client : s->clients[rate]) { // If already listening, just update chunk counters if (client.peerid == peer) { - client.txmax = N * kChunkCount; + client.txmax = N * chunk_count_; client.txcount = 0; return; } @@ -200,7 +201,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID c.peerid = peer; c.uri = dest; c.txcount = 0; - c.txmax = N * kChunkCount; + c.txmax = N * chunk_count_; ++s->clientCount; } @@ -279,7 +280,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) { totalclients += src->clientCount; // Create jobs for each chunk - for (int i=0; i<kChunkCount; ++i) { + for (int i=0; i<chunk_count_; ++i) { // Add chunk job to thread pool ftl::pool.push([this,&fs,j,i,src](int id) { int chunk = i; @@ -296,7 +297,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) { }); } - jobs_ += kChunkCount; + jobs_ += chunk_count_; } std::unique_lock<std::mutex> lk(job_mtx_); @@ -314,12 +315,12 @@ void Streamer::_encodeAndTransmit(StreamSource *src, const cv::Mat &rgb, const c bool hasChan2 = (!depth.empty() && src->src->getChannel() != ftl::rgbd::kChanNone); bool delta = (chunk+src->frame) % 8 > 0; // Do XOR or not - int chunk_width = rgb.cols / kChunkDim; - int chunk_height = rgb.rows / kChunkDim; + int chunk_width = rgb.cols / chunk_dim_; + int chunk_height = rgb.rows / chunk_dim_; // Build chunk heads - int cx = (chunk % kChunkDim) * chunk_width; - int cy = (chunk / kChunkDim) * chunk_height; + int cx = (chunk % chunk_dim_) * chunk_width; + int cy = (chunk / chunk_dim_) * chunk_height; cv::Rect roi(cx,cy,chunk_width,chunk_height); vector<unsigned char> rgb_buf; cv::Mat chunkRGB = rgb(roi); @@ -354,8 +355,8 @@ void Streamer::_encodeAndTransmit(StreamSource *src, const cv::Mat &rgb, const c // TODO:(Nick) could reuse downscales } else { cv::Mat downrgb, downdepth; - cv::resize(chunkRGB, downrgb, cv::Size(bitrate_settings[b].width / kChunkDim, bitrate_settings[b].height / kChunkDim)); - if (hasChan2) cv::resize(d2, downdepth, cv::Size(bitrate_settings[b].width / kChunkDim, bitrate_settings[b].height / kChunkDim)); + cv::resize(chunkRGB, downrgb, cv::Size(bitrate_settings[b].width / chunk_dim_, bitrate_settings[b].height / chunk_dim_)); + if (hasChan2) cv::resize(d2, downdepth, cv::Size(bitrate_settings[b].width / chunk_dim_, bitrate_settings[b].height / chunk_dim_)); _encodeChannel1(downrgb, rgb_buf, b); if (hasChan2) _encodeChannel2(downdepth, d_buf, src->src->getChannel(), b);