From af1693bb15e5c73dc6c3c13da5e9c2f9a8b5f4d2 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Fri, 25 Oct 2019 19:18:34 +0300
Subject: [PATCH] Detect and load all sources in ftl file

---
 applications/reconstruct/src/main.cpp | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp
index b8487d5b1..65b92f6c9 100644
--- a/applications/reconstruct/src/main.cpp
+++ b/applications/reconstruct/src/main.cpp
@@ -16,6 +16,7 @@
 #include <ftl/rgbd/group.hpp>
 #include <ftl/threads.hpp>
 #include <ftl/codecs/writer.hpp>
+#include <ftl/codecs/reader.hpp>
 
 #include "ilw/ilw.hpp"
 #include <ftl/render/splat_render.hpp>
@@ -110,9 +111,27 @@ static void run(ftl::Configurable *root) {
 		auto eix = path.find_last_of('.');
 		auto ext = path.substr(eix+1);
 
+		// Command line path is ftl file
 		if (ext == "ftl") {
 			LOG(INFO) << "PATH TO CHECK: " << path;
-			root->getConfig()["sources"].push_back(nlohmann::json{{"uri",std::string("file://") + path + std::string("#0")}});
+
+			// Create temp reader to count number of sources found in file
+			std::ifstream file;
+			file.open(path);
+			ftl::codecs::Reader reader(file);
+			reader.begin();
+
+			int max_stream = 0;
+			reader.read(reader.getStartTime()+100, [&max_stream](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
+				max_stream = max(max_stream, spkt.streamID);
+			});
+			reader.end();
+
+			LOG(INFO) << "Found " << (max_stream+1) << " sources in " << path;
+
+			for (int i=0; i<max_stream; ++i) {
+				root->getConfig()["sources"].push_back(nlohmann::json{{"uri",std::string("file://") + path + std::string("#") + std::to_string(i)}});
+			}
 		}
 	}
 	LOG(INFO) << (*root->get<nlohmann::json>("sources")).dump();
-- 
GitLab