From d5d7487abbcb1c9c0a38f1c0c150fcadede66266 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 24 Jul 2019 19:44:30 +0300
Subject: [PATCH] Add frame callback

---
 components/rgbd-sources/include/ftl/rgbd/source.hpp | 5 +++++
 components/rgbd-sources/src/net.cpp                 | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/components/rgbd-sources/include/ftl/rgbd/source.hpp b/components/rgbd-sources/include/ftl/rgbd/source.hpp
index 440f566ed..0b537aecd 100644
--- a/components/rgbd-sources/include/ftl/rgbd/source.hpp
+++ b/components/rgbd-sources/include/ftl/rgbd/source.hpp
@@ -191,6 +191,10 @@ class Source : public ftl::Configurable {
 
 	SHARED_MUTEX &mutex() { return mutex_; }
 
+	std::function<void(int64_t, const cv::Mat &, const cv::Mat &)> &callback() { return callback_; }
+	void setCallback(std::function<void(int64_t, const cv::Mat &, const cv::Mat &)> cb) { callback_ = cb; }
+
+
 	private:
 	detail::Source *impl_;
 	cv::Mat rgb_;
@@ -205,6 +209,7 @@ class Source : public ftl::Configurable {
 	channel_t channel_;
 	cudaStream_t stream_;
 	int64_t timestamp_;
+	std::function<void(int64_t, const cv::Mat &, const cv::Mat &)> callback_;
 
 	detail::Source *_createImplementation();
 	detail::Source *_createFileImpl(const ftl::URI &uri);
diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp
index 25270084d..fb8ab4837 100644
--- a/components/rgbd-sources/src/net.cpp
+++ b/components/rgbd-sources/src/net.cpp
@@ -153,6 +153,13 @@ void NetSource::_recvChunk(int64_t frame, int chunk, bool delta, const vector<un
 
 		timestamp_ = current_frame_*40;  // FIXME: Don't hardcode 40ms
 		current_frame_ = frame;
+
+		if (host_->callback()) {
+			//ftl::pool.push([this](id) {
+			//	UNIQUE_LOCK(host_->mutex(),lk);
+				host_->callback()(timestamp_, rgb_, depth_);
+			//});
+		}
 	} else if (frame < current_frame_) {
 		LOG(WARNING) << "Chunk dropped";
 		if (chunk == 0) N_--;
-- 
GitLab