From 132ecae5f62cf8188b5a0289816630768481e710 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 6 Jul 2020 11:48:24 +0300
Subject: [PATCH] Small fixes to sending depth

---
 applications/vision/src/main.cpp     | 2 +-
 components/streams/src/netstream.cpp | 1 +
 components/streams/src/sender.cpp    | 6 ++++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp
index 8d1b46c75..a2dd5e1c0 100644
--- a/applications/vision/src/main.cpp
+++ b/applications/vision/src/main.cpp
@@ -201,7 +201,7 @@ static void run(ftl::Configurable *root) {
 
 			// Send any remaining channels...
 			// Note: Ensures these send now, otherwise waits until destructor
-			//fs->flush();
+			fs->flush(Channel::Depth);
 
 			++frames;
 			latency += float(ftl::timer::get_time() - fs->timestamp());
diff --git a/components/streams/src/netstream.cpp b/components/streams/src/netstream.cpp
index 361df1b92..2f2046a18 100644
--- a/components/streams/src/netstream.cpp
+++ b/components/streams/src/netstream.cpp
@@ -88,6 +88,7 @@ bool Net::post(const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet
 				try {
 					// FIXME: This doesn't work for file sources with file relative timestamps...
 					short pre_transmit_latency = short(ftl::timer::get_time() - spkt.timestamp);
+
 					if (!net_->send(client.peerid,
 							uri_,
 							pre_transmit_latency,  // Time since timestamp for tx
diff --git a/components/streams/src/sender.cpp b/components/streams/src/sender.cpp
index c75d2677a..27abc33b4 100644
--- a/components/streams/src/sender.cpp
+++ b/components/streams/src/sender.cpp
@@ -166,10 +166,12 @@ void Sender::post(ftl::data::FrameSet &fs, ftl::codecs::Channel c) {
 
 	bool do_inject = !do_inject_.test_and_set();
 	if (do_inject) injection_timestamp_ = fs.timestamp();
-	bool do_iframe = injection_timestamp_ == fs.timestamp();
 
 	// Add an iframe at the requested frequency.
 	if (add_iframes_ > 0) iframe_ = (iframe_+1) % add_iframes_;
+	if (iframe_ == 0) injection_timestamp_ = fs.timestamp();
+
+	bool do_iframe = injection_timestamp_ == fs.timestamp();
 
 	FTL_Profile("SenderPost", 0.02);
 
@@ -284,7 +286,7 @@ void Sender::post(ftl::data::FrameSet &fs, ftl::codecs::Channel c) {
 
 	if (needs_encoding) {
 		// TODO: One thread per channel.
-		_encodeChannel(fs, c, do_iframe || iframe_ == 0);
+		_encodeChannel(fs, c, do_iframe);
 	}
 
 	//do_inject_ = false;
-- 
GitLab