From 8b14718cf2535a6641a4b3d314a57530b4c849c2 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 18 Jul 2019 10:08:57 +0300
Subject: [PATCH] Fix timestamp to grab frame

---
 components/rgbd-sources/include/ftl/rgbd/source.hpp | 3 ++-
 components/rgbd-sources/src/source.cpp              | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/components/rgbd-sources/include/ftl/rgbd/source.hpp b/components/rgbd-sources/include/ftl/rgbd/source.hpp
index 64321d36a..c11bc83fe 100644
--- a/components/rgbd-sources/include/ftl/rgbd/source.hpp
+++ b/components/rgbd-sources/include/ftl/rgbd/source.hpp
@@ -118,7 +118,7 @@ class Source : public ftl::Configurable {
 	void writeFrames(const ftl::cuda::TextureObject<uchar4> &rgb, const ftl::cuda::TextureObject<uint> &depth, cudaStream_t stream);
 	void writeFrames(const ftl::cuda::TextureObject<uchar4> &rgb, const ftl::cuda::TextureObject<float> &depth, cudaStream_t stream);
 
-	int64_t timestamp() const { return (impl_) ? impl_->timestamp_ : 0; }
+	int64_t timestamp() const { return timestamp_; }
 
 	/**
 	 * Directly upload source RGB and Depth to GPU.
@@ -204,6 +204,7 @@ class Source : public ftl::Configurable {
 	bool bullet_;
 	channel_t channel_;
 	cudaStream_t stream_;
+	int64_t timestamp_;
 
 	detail::Source *_createImplementation();
 	detail::Source *_createFileImpl(const ftl::URI &uri);
diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp
index d2ab4e416..c2b5dc5a9 100644
--- a/components/rgbd-sources/src/source.cpp
+++ b/components/rgbd-sources/src/source.cpp
@@ -30,6 +30,7 @@ Source::Source(ftl::config::json_t &cfg) : Configurable(cfg), pose_(Eigen::Matri
 	impl_ = nullptr;
 	params_ = {0};
 	stream_ = 0;
+	timestamp_ = 0;
 	reset();
 
 	on("uri", [this](const ftl::config::Event &e) {
@@ -42,6 +43,7 @@ Source::Source(ftl::config::json_t &cfg, ftl::net::Universe *net) : Configurable
 	impl_ = nullptr;
 	params_ = {0};
 	stream_ = 0;
+	timestamp_ = 0;
 	reset();
 
 	on("uri", [this](const ftl::config::Event &e) {
@@ -228,6 +230,7 @@ bool Source::grab() {
 		stream_ = 0;
 		return true;
 	} else if (impl_ && impl_->grab(-1,-1)) {
+		timestamp_ = impl_->timestamp_;
 		impl_->rgb_.copyTo(rgb_);
 		impl_->depth_.copyTo(depth_);
 		return true;
-- 
GitLab