From cc2af3b925bc824c343d1c0ce024c4cf15bfea98 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sun, 13 Oct 2019 16:20:48 +0300
Subject: [PATCH] Add broadcast stream support

---
 components/codecs/include/ftl/codecs/packet.hpp | 2 +-
 components/codecs/include/ftl/codecs/reader.hpp | 2 +-
 components/codecs/include/ftl/codecs/writer.hpp | 2 +-
 components/codecs/src/reader.cpp                | 5 +++++
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/components/codecs/include/ftl/codecs/packet.hpp b/components/codecs/include/ftl/codecs/packet.hpp
index 988617fc5..edddd205a 100644
--- a/components/codecs/include/ftl/codecs/packet.hpp
+++ b/components/codecs/include/ftl/codecs/packet.hpp
@@ -43,7 +43,7 @@ struct Packet {
  */
 struct StreamPacket {
 	int64_t timestamp;
-	uint8_t streamID;  		// Source number...
+	uint8_t streamID;  		// Source number... 255 = broadcast stream
 	uint8_t channel_count;	// Number of channels to expect for this frame to complete (usually 1 or 2)
 	ftl::codecs::Channel channel;		// Actual channel of this current set of packets
 
diff --git a/components/codecs/include/ftl/codecs/reader.hpp b/components/codecs/include/ftl/codecs/reader.hpp
index 65be39eaa..9e607c77f 100644
--- a/components/codecs/include/ftl/codecs/reader.hpp
+++ b/components/codecs/include/ftl/codecs/reader.hpp
@@ -14,7 +14,7 @@ namespace codecs {
 
 class Reader {
 	public:
-	Reader(std::istream &);
+	explicit Reader(std::istream &);
 	~Reader();
 
 	/**
diff --git a/components/codecs/include/ftl/codecs/writer.hpp b/components/codecs/include/ftl/codecs/writer.hpp
index abdbdb3db..3befecf7c 100644
--- a/components/codecs/include/ftl/codecs/writer.hpp
+++ b/components/codecs/include/ftl/codecs/writer.hpp
@@ -12,7 +12,7 @@ namespace codecs {
 
 class Writer {
 	public:
-	Writer(std::ostream &);
+	explicit Writer(std::ostream &);
 	~Writer();
 
 	bool begin();
diff --git a/components/codecs/src/reader.cpp b/components/codecs/src/reader.cpp
index 96002aeee..c12c6c6dc 100644
--- a/components/codecs/src/reader.cpp
+++ b/components/codecs/src/reader.cpp
@@ -92,6 +92,11 @@ bool Reader::read(int64_t ts) {
 	return read(ts, [this](const ftl::codecs::StreamPacket &spkt, ftl::codecs::Packet &pkt) {
 		if (handlers_.size() > spkt.streamID && (bool)handlers_[spkt.streamID]) {
 			handlers_[spkt.streamID](spkt, pkt);
+		} else if (spkt.streamID == 255) {
+			// Broadcast stream, send packets to every source handler.
+			for (auto &h : handlers_) {
+				h(spkt, pkt);
+			}
 		}
 	});
 }
-- 
GitLab