From fbb344fe45a2f72fa247f2807b8e90a00c2ffc5f Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 10 Aug 2020 19:54:00 +0300
Subject: [PATCH] Use different schedule mechanism

---
 applications/vision/src/main.cpp   |  2 +-
 components/streams/src/builder.cpp | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp
index 9c829d1cb..09df96b93 100644
--- a/applications/vision/src/main.cpp
+++ b/applications/vision/src/main.cpp
@@ -164,7 +164,7 @@ static void run(ftl::Configurable *root) {
 
 	// Send channels on flush
 	auto flushhandle = pool.onFlushSet([sender,&encodable](ftl::data::FrameSet &fs, ftl::codecs::Channel c) {
-		if (!fs.test(ftl::data::FSFlag::AUTO_SEND)) return true;
+		if (c != Channel::EndFrame && !fs.test(ftl::data::FSFlag::AUTO_SEND)) return true;
 
 		// Always send data channels
 		if ((int)c >= 32) sender->post(fs, c);
diff --git a/components/streams/src/builder.cpp b/components/streams/src/builder.cpp
index 58f2dd3c9..4a80bbdbc 100644
--- a/components/streams/src/builder.cpp
+++ b/components/streams/src/builder.cpp
@@ -367,20 +367,20 @@ std::shared_ptr<ftl::data::FrameSet> ForeignBuilder::_findFrameset(int64_t ts) {
  * Note: Must occur inside a mutex lock.
  */
 std::shared_ptr<ftl::data::FrameSet> ForeignBuilder::_getFrameset() {
+	ftl::data::FrameSetPtr f;
 	auto i = framesets_.begin();
 	int N = bufferSize_;
 
 	// Skip N frames to fixed buffer location
 	if (bufferSize_ > 0) {
 		while (N-- > 0 && i != framesets_.end()) ++i;
-	// Otherwise skip to first fully completed frame
+		if (i != framesets_.end()) f = *i;
 	} else {
-		while (i != framesets_.end() && !(*i)->isComplete()) ++i;
+		// Always choose oldest frameset when it completes
+		if (framesets_.size() > 0 && framesets_.back()->isComplete()) f = framesets_.back();
 	}
 
-	if (i != framesets_.end()) {
-		auto f = *i;
-		
+	if (f) {
 		// Lock to force completion of on going construction first
 		UNIQUE_LOCK(f->smtx, slk);
 		last_frame_ = f->timestamp();
-- 
GitLab