Skip to content
Snippets Groups Projects
Commit 7ee217f1 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Allow chunk config

parent 247fa4a9
No related branches found
No related tags found
1 merge request!95Implements #156 expose config options
Pipeline #12900 failed
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
namespace ftl { namespace ftl {
namespace rgbd { namespace rgbd {
static const int kChunkDim = 4; //static const int kChunkDim = 4;
static constexpr int kChunkCount = kChunkDim * kChunkDim; //static constexpr int kChunkCount = kChunkDim * kChunkDim;
namespace detail { namespace detail {
...@@ -122,6 +122,8 @@ class Streamer : public ftl::Configurable { ...@@ -122,6 +122,8 @@ class Streamer : public ftl::Configurable {
ftl::UUID time_peer_; ftl::UUID time_peer_;
int64_t last_frame_; int64_t last_frame_;
int64_t frame_no_; int64_t frame_no_;
size_t chunk_count_;
size_t chunk_dim_;
int64_t mspf_; int64_t mspf_;
float actual_fps_; float actual_fps_;
......
...@@ -147,6 +147,9 @@ NetSource::NetSource(ftl::rgbd::Source *host) ...@@ -147,6 +147,9 @@ NetSource::NetSource(ftl::rgbd::Source *host)
default_quality_ = host->value("quality", 0); default_quality_ = host->value("quality", 0);
}); });
chunks_dim_ = host->value("chunking",4);
chunk_count_ = chunks_dim_*chunks_dim_;
_updateURI(); _updateURI();
h_ = host_->getNet()->onConnect([this](ftl::net::Peer *p) { 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 ...@@ -228,13 +231,13 @@ void NetSource::_recvChunk(int64_t ts, int chunk, bool delta, const vector<unsig
++frame.chunk_count; ++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); UNIQUE_LOCK(frame.mtx, flk);
timestamp_ = frame.timestamp; timestamp_ = frame.timestamp;
if (frame.timestamp >= 0 && frame.chunk_count == kChunkCount) { if (frame.timestamp >= 0 && frame.chunk_count == chunk_count_) {
//LOG(INFO) << "Frame finished"; //LOG(INFO) << "Frame finished";
auto cb = host_->callback(); auto cb = host_->callback();
if (cb) { if (cb) {
...@@ -308,7 +311,7 @@ void NetSource::_updateURI() { ...@@ -308,7 +311,7 @@ void NetSource::_updateURI() {
N_ = 0; N_ = 0;
// Update chunk details // Update chunk details
chunks_dim_ = ftl::rgbd::kChunkDim; //chunks_dim_ = ftl::rgbd::kChunkDim;
chunk_width_ = params_.width / chunks_dim_; chunk_width_ = params_.width / chunks_dim_;
chunk_height_ = params_.height / chunks_dim_; chunk_height_ = params_.height / chunks_dim_;
//chunk_count_ = 0; //chunk_count_ = 0;
......
...@@ -79,6 +79,7 @@ class NetSource : public detail::Source { ...@@ -79,6 +79,7 @@ class NetSource : public detail::Source {
int minB_; int minB_;
int maxN_; int maxN_;
int default_quality_; int default_quality_;
int chunk_count_;
ftl::rgbd::channel_t prev_chan_; ftl::rgbd::channel_t prev_chan_;
//volatile int64_t current_frame_; //volatile int64_t current_frame_;
//std::atomic<int> chunk_count_; //std::atomic<int> chunk_count_;
......
...@@ -206,8 +206,6 @@ bool StereoVideoSource::compute(int n, int b) { ...@@ -206,8 +206,6 @@ bool StereoVideoSource::compute(int n, int b) {
stream_.waitForCompletion(); // TODO:(Nick) Move to getFrames stream_.waitForCompletion(); // TODO:(Nick) Move to getFrames
} }
LOG(INFO) << "STEREO VIDEO COMPUTE: " << timestamp_;
auto cb = host_->callback(); auto cb = host_->callback();
if (cb) cb(timestamp_, rgb_, depth_); if (cb) cb(timestamp_, rgb_, depth_);
return true; return true;
......
...@@ -37,6 +37,9 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) ...@@ -37,6 +37,9 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
//last_dropped_ = 0; //last_dropped_ = 0;
//drop_count_ = 0; //drop_count_ = 0;
chunk_dim_ = value("chunking",4);
chunk_count_ = chunk_dim_*chunk_dim_;
//group_.setFPS(value("fps", 20)); //group_.setFPS(value("fps", 20));
group_.setLatency(10); group_.setLatency(10);
...@@ -105,8 +108,6 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) ...@@ -105,8 +108,6 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
net->bind("set_channel", [this](const string &uri, unsigned int chan) { net->bind("set_channel", [this](const string &uri, unsigned int chan) {
SHARED_LOCK(mutex_,slk); SHARED_LOCK(mutex_,slk);
LOG(INFO) << "SET CHANNEL " << chan;
if (sources_.find(uri) != sources_.end()) { if (sources_.find(uri) != sources_.end()) {
sources_[uri]->src->setChannel((ftl::rgbd::channel_t)chan); 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 ...@@ -189,7 +190,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID
for (auto &client : s->clients[rate]) { for (auto &client : s->clients[rate]) {
// If already listening, just update chunk counters // If already listening, just update chunk counters
if (client.peerid == peer) { if (client.peerid == peer) {
client.txmax = N * kChunkCount; client.txmax = N * chunk_count_;
client.txcount = 0; client.txcount = 0;
return; return;
} }
...@@ -200,7 +201,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID ...@@ -200,7 +201,7 @@ void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID
c.peerid = peer; c.peerid = peer;
c.uri = dest; c.uri = dest;
c.txcount = 0; c.txcount = 0;
c.txmax = N * kChunkCount; c.txmax = N * chunk_count_;
++s->clientCount; ++s->clientCount;
} }
...@@ -279,7 +280,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) { ...@@ -279,7 +280,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) {
totalclients += src->clientCount; totalclients += src->clientCount;
// Create jobs for each chunk // 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 // Add chunk job to thread pool
ftl::pool.push([this,&fs,j,i,src](int id) { ftl::pool.push([this,&fs,j,i,src](int id) {
int chunk = i; int chunk = i;
...@@ -296,7 +297,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) { ...@@ -296,7 +297,7 @@ void Streamer::_transmit(ftl::rgbd::FrameSet &fs) {
}); });
} }
jobs_ += kChunkCount; jobs_ += chunk_count_;
} }
std::unique_lock<std::mutex> lk(job_mtx_); std::unique_lock<std::mutex> lk(job_mtx_);
...@@ -314,12 +315,12 @@ void Streamer::_encodeAndTransmit(StreamSource *src, const cv::Mat &rgb, const c ...@@ -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 hasChan2 = (!depth.empty() && src->src->getChannel() != ftl::rgbd::kChanNone);
bool delta = (chunk+src->frame) % 8 > 0; // Do XOR or not bool delta = (chunk+src->frame) % 8 > 0; // Do XOR or not
int chunk_width = rgb.cols / kChunkDim; int chunk_width = rgb.cols / chunk_dim_;
int chunk_height = rgb.rows / kChunkDim; int chunk_height = rgb.rows / chunk_dim_;
// Build chunk heads // Build chunk heads
int cx = (chunk % kChunkDim) * chunk_width; int cx = (chunk % chunk_dim_) * chunk_width;
int cy = (chunk / kChunkDim) * chunk_height; int cy = (chunk / chunk_dim_) * chunk_height;
cv::Rect roi(cx,cy,chunk_width,chunk_height); cv::Rect roi(cx,cy,chunk_width,chunk_height);
vector<unsigned char> rgb_buf; vector<unsigned char> rgb_buf;
cv::Mat chunkRGB = rgb(roi); cv::Mat chunkRGB = rgb(roi);
...@@ -354,8 +355,8 @@ void Streamer::_encodeAndTransmit(StreamSource *src, const cv::Mat &rgb, const c ...@@ -354,8 +355,8 @@ void Streamer::_encodeAndTransmit(StreamSource *src, const cv::Mat &rgb, const c
// TODO:(Nick) could reuse downscales // TODO:(Nick) could reuse downscales
} else { } else {
cv::Mat downrgb, downdepth; cv::Mat downrgb, downdepth;
cv::resize(chunkRGB, downrgb, 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 / kChunkDim, bitrate_settings[b].height / kChunkDim)); 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); _encodeChannel1(downrgb, rgb_buf, b);
if (hasChan2) _encodeChannel2(downdepth, d_buf, src->src->getChannel(), b); if (hasChan2) _encodeChannel2(downdepth, d_buf, src->src->getChannel(), b);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment