diff --git a/include/ftl/protocol/broadcaster.hpp b/include/ftl/protocol/broadcaster.hpp index 55c88d0ac035632f50aedfcb98ea124560d92513..a1d3f897935b1bf39a034ab312c8f03f97a4829a 100644 --- a/include/ftl/protocol/broadcaster.hpp +++ b/include/ftl/protocol/broadcaster.hpp @@ -32,6 +32,7 @@ class Broadcast : public Stream { bool begin() override; bool end() override; bool active() override; + bool active(FrameID id) override; void reset() override; diff --git a/include/ftl/protocol/muxer.hpp b/include/ftl/protocol/muxer.hpp index 425216c25156f69579120691f19a19b628c100ba..4cb37d36a122e4fdbcee9198670a7802af707a0f 100644 --- a/include/ftl/protocol/muxer.hpp +++ b/include/ftl/protocol/muxer.hpp @@ -61,6 +61,7 @@ class Muxer : public Stream { bool begin() override; bool end() override; bool active() override; + bool active(FrameID id) override; void reset() override; diff --git a/include/ftl/protocol/streams.hpp b/include/ftl/protocol/streams.hpp index 90265b44946b5b9ad97373d2ba35a6a6a6b68d00..1035790b8e0a3839c283af0c90b5f311c423cc6e 100644 --- a/include/ftl/protocol/streams.hpp +++ b/include/ftl/protocol/streams.hpp @@ -146,6 +146,8 @@ class Stream { */ virtual bool active() = 0; + virtual bool active(FrameID id); + /** * @brief Clear all state. This will remove all information about available * and enabled frames or channels. You will then need to enable frames and diff --git a/src/streams/broadcaster.cpp b/src/streams/broadcaster.cpp index 441a7559833b5a38cc5ef3dd78ff8586594ae5eb..0103b331f18e446986e524a23ec5ee759891ad76 100644 --- a/src/streams/broadcaster.cpp +++ b/src/streams/broadcaster.cpp @@ -89,6 +89,17 @@ bool Broadcast::active() { return r; } +bool Broadcast::active(FrameID id) { + if (streams_.size() == 0) return false; + + for (auto &s : streams_) { + if (s.stream->active(id)) { + return true; + } + } + return false; +} + void Broadcast::reset() { SHARED_LOCK(mtx_, lk); for (auto &s : streams_) { diff --git a/src/streams/muxer.cpp b/src/streams/muxer.cpp index 0df1a67ae592e497b3b56cd34c32efd55f4fb856..b0f6b57f4db12bb13225348a3f0b54333ed605c5 100644 --- a/src/streams/muxer.cpp +++ b/src/streams/muxer.cpp @@ -293,6 +293,15 @@ bool Muxer::active() { return r; } +bool Muxer::active(FrameID id) { + auto p = _mapToOutput(id); + if (p.second) { + return p.second->stream->active(p.first); + } else { + return false; + } +} + void Muxer::reset() { for (auto &s : streams_) { s.stream->reset(); diff --git a/src/streams/netstream.cpp b/src/streams/netstream.cpp index 590b265b236f043e2d5bd63e0ca4307a89cf9d38..91e9ac9c607df3e8af2581978df96bf0329d4b41 100644 --- a/src/streams/netstream.cpp +++ b/src/streams/netstream.cpp @@ -554,6 +554,11 @@ bool Net::active() { return active_; } +bool Net::active(FrameID id) { + SHARED_LOCK(mtx_, lk); + return active_ && clients_.count(id) > 0; +} + void Net::setProperty(ftl::protocol::StreamProperty opt, std::any value) { switch (opt) { case StreamProperty::kBitrate : diff --git a/src/streams/netstream.hpp b/src/streams/netstream.hpp index 565b94273cb7e174e118f6ec8af53eb1b019427e..eeedaaa659378ac837b595e8b4171b7d43812556 100644 --- a/src/streams/netstream.hpp +++ b/src/streams/netstream.hpp @@ -47,6 +47,7 @@ class Net : public Stream { bool begin() override; bool end() override; bool active() override; + bool active(FrameID id) override; bool enable(FrameID id) override; bool enable(FrameID id, ftl::protocol::Channel c) override; diff --git a/src/streams/streams.cpp b/src/streams/streams.cpp index 198230c34f2783c3417e8991bb7e44a4b87acb2a..79fc28398c8fbddd9b73649de250c5207b02e863 100644 --- a/src/streams/streams.cpp +++ b/src/streams/streams.cpp @@ -176,3 +176,7 @@ void Stream::request(const ftl::protocol::Request &req) { void Stream::error(ftl::protocol::Error err, const std::string &str) { error_cb_.trigger(err, str); } + +bool Stream::active(FrameID id) { + return active(); +} diff --git a/test/stream_integration.cpp b/test/stream_integration.cpp index fd98adeb835591aadeb894e35889f276bd8e3a73..161b5669509b6691fcef63c91fe290536e478536 100644 --- a/test/stream_integration.cpp +++ b/test/stream_integration.cpp @@ -111,11 +111,15 @@ TEST_CASE("TCP Stream", "[net]") { s1->begin(); s2->begin(); + REQUIRE(s1->active(FrameID(0, 0)) == false); + s2->enable(FrameID(0, 0)); // TODO: Find better option std::this_thread::sleep_for(std::chrono::milliseconds(10)); + REQUIRE(s1->active(FrameID(0, 0)) == true); + ftl::protocol::StreamPacket spkt; spkt.streamID = 0; spkt.frame_number = 0;