From 926193f369d717d2b783d2e017068658d28642c7 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 15 Dec 2019 10:32:26 +0200
Subject: [PATCH] Fix for more than 2 channels in ftl file

---
 .../src/sources/ftlfile/file_source.cpp       | 23 +++++++++++++++----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/components/rgbd-sources/src/sources/ftlfile/file_source.cpp b/components/rgbd-sources/src/sources/ftlfile/file_source.cpp
index 0962c1886..25033f9af 100644
--- a/components/rgbd-sources/src/sources/ftlfile/file_source.cpp
+++ b/components/rgbd-sources/src/sources/ftlfile/file_source.cpp
@@ -184,21 +184,34 @@ bool FileSource::compute(int n, int b) {
 
 		if (c.spkt.channel == Channel::Colour) {
 			rgb_.create(cv::Size(ftl::codecs::getWidth(c.pkt.definition),ftl::codecs::getHeight(c.pkt.definition)), CV_8UC3);
-		} else {
+			_createDecoder(0, c.pkt);
+
+			try {
+				decoders_[0]->decode(c.pkt, rgb_);
+			} catch (std::exception &e) {
+				LOG(INFO) << "Decoder exception: " << e.what();
+			}
+		} else if (host_->getChannel() == c.spkt.channel) {
 			depth_.create(cv::Size(ftl::codecs::getWidth(c.pkt.definition),ftl::codecs::getHeight(c.pkt.definition)), CV_32F);
+			_createDecoder(1, c.pkt);
+			try {
+				decoders_[1]->decode(c.pkt, depth_);
+			} catch (std::exception &e) {
+				LOG(INFO) << "Decoder exception: " << e.what();
+			}
 		}
 	
-		_createDecoder((c.spkt.channel == Channel::Colour) ? 0 : 1, c.pkt);
+		//_createDecoder((c.spkt.channel == Channel::Colour) ? 0 : 1, c.pkt);
 
-		try {
+		/*try {
 			decoders_[(c.spkt.channel == Channel::Colour) ? 0 : 1]->decode(c.pkt, (c.spkt.channel == Channel::Colour) ? rgb_ : depth_);
 		} catch (std::exception &e) {
 			LOG(INFO) << "Decoder exception: " << e.what();
-		}
+		}*/
 	}
 
 	// FIXME: Consider case of Channel::None
-	if (lastc != 2) {
+	if (lastc < 2) {
 		LOG(ERROR) << "Channels not in sync (" << sourceid_ << "): " << lastts;
 		return false;
 	}
-- 
GitLab