From 61007218e8085b73124c86af44a282af74507d81 Mon Sep 17 00:00:00 2001
From: Sebastian Hahta <joseha@utu.fi>
Date: Fri, 31 Jan 2020 12:38:44 +0200
Subject: [PATCH] data channel

---
 components/streams/src/receiver.cpp |  5 ++--
 components/streams/src/sender.cpp   | 43 +++++++++++++++--------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/components/streams/src/receiver.cpp b/components/streams/src/receiver.cpp
index cb1d62844..6ef07b742 100644
--- a/components/streams/src/receiver.cpp
+++ b/components/streams/src/receiver.cpp
@@ -121,8 +121,9 @@ void Receiver::_processState(const StreamPacket &spkt, const Packet &pkt) {
 }
 
 void Receiver::_processData(const StreamPacket &spkt, const Packet &pkt) {
-	InternalVideoStates &frame = _getVideoFrame(spkt);
-	frame.frame.createRawData(spkt.channel, pkt.data);
+	//InternalVideoStates &frame = _getVideoFrame(spkt);
+	auto &frame = builder_[spkt.streamID].get(spkt.timestamp, spkt.frame_number);
+	frame.createRawData(spkt.channel, pkt.data);
 }
 
 void Receiver::_processAudio(const StreamPacket &spkt, const Packet &pkt) {
diff --git a/components/streams/src/sender.cpp b/components/streams/src/sender.cpp
index d10bf37bb..80b6799b1 100644
--- a/components/streams/src/sender.cpp
+++ b/components/streams/src/sender.cpp
@@ -141,7 +141,26 @@ void Sender::post(const ftl::rgbd::FrameSet &fs) {
 			if (frame.hasChanged(Channel::Configuration)) injectConfig(stream_, fs, i);
 		}
 
-        for (auto c : frame.getChannels()) {
+		// FIXME: Allow data channel selection rather than always send
+		for (auto c : frame.getDataChannels()) {
+			StreamPacket spkt;
+			spkt.version = 4;
+			spkt.timestamp = fs.timestamp;
+			spkt.streamID = 0; //fs.id;
+			spkt.frame_number = i;
+			spkt.channel = c;
+
+			ftl::codecs::Packet pkt;
+			pkt.codec = ftl::codecs::codec_t::MSGPACK;
+			pkt.definition = ftl::codecs::definition_t::Any;
+			pkt.frame_count = 1;
+			pkt.flags = 0;
+			pkt.bitrate = 0;
+			pkt.data = frame.getRawData(c);
+			stream_->post(spkt, pkt);
+		}
+
+		for (auto c : frame.getChannels()) {
 			if (selected.has(c)) {
 				// FIXME: Sends high res colour, but receive end currently broken
 				//auto cc = (c == Channel::Colour && frame.hasChannel(Channel::ColourHighRes)) ? Channel::ColourHighRes : Channel::Colour;
@@ -174,27 +193,9 @@ void Sender::post(const ftl::rgbd::FrameSet &fs) {
 			} else {
 				available += c;
 			}
-        }
-
-		// FIXME: Allow data channel selection rather than always send
-		for (auto c : frame.getDataChannels()) {
-			StreamPacket spkt;
-			spkt.version = 4;
-			spkt.timestamp = fs.timestamp;
-			spkt.streamID = 0; //fs.id;
-			spkt.frame_number = i;
-			spkt.channel = c;
-
-			ftl::codecs::Packet pkt;
-			pkt.codec = ftl::codecs::codec_t::MSGPACK;
-			pkt.definition = ftl::codecs::definition_t::Any;
-			pkt.frame_count = 1;
-			pkt.flags = 0;
-			pkt.bitrate = 0;
-			pkt.data = frame.getRawData(c);
-			stream_->post(spkt, pkt);
 		}
-    }
+
+	}
 
 	for (auto c : available) {
 		// Not selected so send an empty packet...
-- 
GitLab