From 636cda3a3aa97ab4a8bcb71edf65e26a5967a7e1 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Fri, 4 Oct 2019 10:31:12 +0300
Subject: [PATCH] Allow for frame buffer full problems

---
 applications/reconstruct/src/main.cpp |  4 ++--
 components/rgbd-sources/src/net.cpp   | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp
index c2f357e18..52d9b603e 100644
--- a/applications/reconstruct/src/main.cpp
+++ b/applications/reconstruct/src/main.cpp
@@ -159,12 +159,12 @@ static void run(ftl::Configurable *root) {
 		group.addSource(in);
 	}
 
-	stream->setLatency(4);  // FIXME: This depends on source!?
+	stream->setLatency(5);  // FIXME: This depends on source!?
 	stream->run();
 
 	bool busy = false;
 
-	group.setLatency(4);
+	group.setLatency(5);
 	group.setName("ReconGroup");
 	group.sync([splat,virt,&busy,&slave,&scene_A,&scene_B,&align](ftl::rgbd::FrameSet &fs) -> bool {
 		//cudaSetDevice(scene->getCUDADevice());
diff --git a/components/rgbd-sources/src/net.cpp b/components/rgbd-sources/src/net.cpp
index ba485c940..4f1f5b141 100644
--- a/components/rgbd-sources/src/net.cpp
+++ b/components/rgbd-sources/src/net.cpp
@@ -40,6 +40,8 @@ NetFrame &NetFrameQueue::getFrame(int64_t ts, const cv::Size &s, int c1type, int
 		if (f.timestamp == ts) return f;
 	}
 
+	int64_t oldest = ts;
+
 	// No match so find an empty slot
 	for (auto &f : frames_) {
 		if (f.timestamp == -1) {
@@ -51,11 +53,23 @@ NetFrame &NetFrameQueue::getFrame(int64_t ts, const cv::Size &s, int c1type, int
 			f.channel2.create(s, c2type);
 			return f;
 		}
+		oldest = (f.timestamp < oldest) ? f.timestamp : oldest;
 	}
 
 	// No empty slot, so give a fatal error
 	for (auto &f : frames_) {
 		LOG(ERROR) << "Stale frame: " << f.timestamp << " - " << f.chunk_count;
+
+		// Force release of frame!
+		if (f.timestamp == oldest) {
+			f.timestamp = ts;
+			f.chunk_count = 0;
+			f.chunk_total = 0;
+			f.tx_size = 0;
+			f.channel1.create(s, c1type);
+			f.channel2.create(s, c2type);
+			return f;
+		}
 	}
 	LOG(FATAL) << "Net Frame Queue not large enough: " << ts;
 	// FIXME: (Nick) Could auto resize the queue.
-- 
GitLab