From 6f7f351cc1a8f036adac153ed45446f9c5baf5a5 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 14 Jun 2019 13:53:40 +0300 Subject: [PATCH] Have streamer do some jobs directly --- components/rgbd-sources/src/net.cpp | 9 ++++----- components/rgbd-sources/src/streamer.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp index 4c606aa36..ac7bc8553 100644 --- a/components/rgbd-sources/src/net.cpp +++ b/components/rgbd-sources/src/net.cpp @@ -64,20 +64,19 @@ NetSource::~NetSource() { void NetSource::_recv(const vector<unsigned char> &jpg, const vector<unsigned char> &d) { cv::Mat tmp_rgb, tmp_depth; - auto start = std::chrono::high_resolution_clock::now(); cv::imdecode(jpg, cv::IMREAD_COLOR, &tmp_rgb); //Mat(rgb_.size(), CV_16UC1); cv::imdecode(d, cv::IMREAD_UNCHANGED, &tmp_depth); + auto start = std::chrono::high_resolution_clock::now(); unique_lock<shared_mutex> lk(host_->mutex()); + std::chrono::duration<double> elapsed = + std::chrono::high_resolution_clock::now() - start; + LOG(INFO) << "ELAPSED LOCK: " << elapsed.count(); rgb_ = tmp_rgb; tmp_depth.convertTo(depth_, CV_32FC1, 1.0f/(16.0f*100.0f)); N_--; lk.unlock(); - - std::chrono::duration<double> elapsed = - std::chrono::high_resolution_clock::now() - start; - LOG(INFO) << "ELAPSED DECODE: " << elapsed.count(); } void NetSource::setPose(const Eigen::Matrix4f &pose) { diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp index 00a370fc6..eeb3fb827 100644 --- a/components/rgbd-sources/src/streamer.cpp +++ b/components/rgbd-sources/src/streamer.cpp @@ -291,6 +291,12 @@ void Streamer::_schedule() { }); } + // Do some jobs in this thread, might as well... + std::function<void(int)> j; + while ((bool)(j=pool_.pop())) { + j(-1); + } + // Wait for all jobs to complete before finishing frame unique_lock<mutex> lk(job_mtx); job_cv.wait(lk, [&jobs]{ return jobs == 0; }); -- GitLab