From daecd3365e6447ce9683a2051d0c1ea9a2d2c84b Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nicolas.pope@utu.fi>
Date: Fri, 9 Aug 2019 12:54:37 +0300
Subject: [PATCH] Fixes for multi swap in net buffers

---
 components/rgbd-sources/src/net.cpp    |  3 +--
 components/rgbd-sources/src/source.cpp | 11 +++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp
index 12a76cc40..68f46fc2b 100644
--- a/components/rgbd-sources/src/net.cpp
+++ b/components/rgbd-sources/src/net.cpp
@@ -150,8 +150,6 @@ void NetSource::_recvChunk(int64_t frame, int chunk, bool delta, const vector<un
 					// Lock to allow buffer swap
 					UNIQUE_LOCK(mutex_,lk2);
 
-					chunk_count_ = 0;
-
 					// Swap the double buffers
 					cv::Mat tmp;
 					tmp = rgb_;
@@ -161,6 +159,7 @@ void NetSource::_recvChunk(int64_t frame, int chunk, bool delta, const vector<un
 					depth_ = d_depth_;
 					d_depth_ = tmp;
 
+					chunk_count_ = 0;
 					timestamp_ = current_frame_;
 					current_frame_ = frame;
 				}
diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp
index 913fe4acb..c5efd26fc 100644
--- a/components/rgbd-sources/src/source.cpp
+++ b/components/rgbd-sources/src/source.cpp
@@ -244,7 +244,7 @@ bool Source::compute(int N, int B) {
 		return true;
 	} else if (impl_ && impl_->compute(N,B)) {
 		timestamp_ = impl_->timestamp_;
-		cv::Mat tmp;
+		/*cv::Mat tmp;
 		rgb_.create(impl_->rgb_.size(), impl_->rgb_.type());
 		depth_.create(impl_->depth_.size(), impl_->depth_.type());
 		tmp = rgb_;
@@ -252,10 +252,13 @@ bool Source::compute(int N, int B) {
 		impl_->rgb_ = tmp;
 		tmp = depth_;
 		depth_ = impl_->depth_;
-		impl_->depth_ = tmp;
+		impl_->depth_ = tmp;*/
 
-		//impl_->rgb_.copyTo(rgb_);
-		//impl_->depth_.copyTo(depth_);
+		// TODO:(Nick) Reduce buffer copies
+		impl_->rgb_.copyTo(rgb_);
+		impl_->depth_.copyTo(depth_);
+		//rgb_ = impl_->rgb_;
+		//depth_ = impl_->depth_;
 		return true;
 	}
 	return false;
-- 
GitLab