From 9456be856ce5440196f61386e27abfb5b3fd4459 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 19 Sep 2019 09:43:12 +0300
Subject: [PATCH] Fix latency and encode bug

---
 applications/reconstruct/src/main.cpp                 | 1 +
 components/codecs/src/nvpipe_encoder.cpp              | 2 +-
 components/rgbd-sources/include/ftl/rgbd/streamer.hpp | 2 ++
 components/rgbd-sources/src/streamer.cpp              | 3 +--
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp
index f7cdf4d37..a4ff3bfd8 100644
--- a/applications/reconstruct/src/main.cpp
+++ b/applications/reconstruct/src/main.cpp
@@ -116,6 +116,7 @@ static void run(ftl::Configurable *root) {
 		group.addSource(in);
 	}
 
+	stream->setLatency(4);
 	stream->run();
 
 	bool busy = false;
diff --git a/components/codecs/src/nvpipe_encoder.cpp b/components/codecs/src/nvpipe_encoder.cpp
index e03dc7073..42374bede 100644
--- a/components/codecs/src/nvpipe_encoder.cpp
+++ b/components/codecs/src/nvpipe_encoder.cpp
@@ -91,7 +91,7 @@ bool NvPipeEncoder::encode(const cv::Mat &in, definition_t odefinition, bitrate_
 
 bool NvPipeEncoder::_encoderMatch(const cv::Mat &in, definition_t def) {
     return ((in.type() == CV_32F && is_float_channel_) ||
-        (in.type() == CV_8UC3 && !is_float_channel_)) && current_definition_ == def;
+        ((in.type() == CV_8UC3 || in.type() == CV_8UC4) && !is_float_channel_)) && current_definition_ == def;
 }
 
 bool NvPipeEncoder::_createEncoder(const cv::Mat &in, definition_t def, bitrate_t rate) {
diff --git a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp
index 3f6f1c4fa..7c6e6f479 100644
--- a/components/rgbd-sources/include/ftl/rgbd/streamer.hpp
+++ b/components/rgbd-sources/include/ftl/rgbd/streamer.hpp
@@ -117,6 +117,8 @@ class Streamer : public ftl::Configurable {
 
 	void wait();
 
+	void setLatency(int l) { group_.setLatency(l); }
+
 	/**
 	 * Alternative to calling run(), it will operate a single frame capture,
 	 * compress and stream cycle.
diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp
index 3691c36fd..7a9118c9f 100644
--- a/components/rgbd-sources/src/streamer.cpp
+++ b/components/rgbd-sources/src/streamer.cpp
@@ -47,7 +47,7 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
 	hq_devices_ = (value("disable_hardware_encode", false)) ? device_t::Software : device_t::Any;
 
 	//group_.setFPS(value("fps", 20));
-	group_.setLatency(3);
+	group_.setLatency(4);
 
 	compress_level_ = value("compression", 1);
 	
@@ -74,7 +74,6 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
 		if (sources_.find(uri) != sources_.end()) {
 			Eigen::Matrix4d pose;
 			memcpy(pose.data(), buf.data(), buf.size());
-			LOG(INFO) << "SET POSE:";
 			sources_[uri]->src->setPose(pose);
 		}
 	});
-- 
GitLab