Skip to content
Snippets Groups Projects
Commit 80889666 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/#14' into 'main'

#14 Add channel disabling

See merge request nicolaspope/beyond-protocol!11
parents c2d63ce7 967f0782
Branches
Tags 0.2.0
No related merge requests found
...@@ -51,6 +51,12 @@ class Broadcast : public Stream { ...@@ -51,6 +51,12 @@ class Broadcast : public Stream {
bool enable(FrameID id, const ftl::protocol::ChannelSet &channels) override; bool enable(FrameID id, const ftl::protocol::ChannelSet &channels) override;
void disable(FrameID id) override;
void disable(FrameID id, ftl::protocol::Channel channel) override;
void disable(FrameID id, const ftl::protocol::ChannelSet &channels) override;
StreamType type() const override; StreamType type() const override;
private: private:
......
...@@ -69,6 +69,12 @@ class Muxer : public Stream { ...@@ -69,6 +69,12 @@ class Muxer : public Stream {
bool enable(FrameID id, const ftl::protocol::ChannelSet &channels) override; bool enable(FrameID id, const ftl::protocol::ChannelSet &channels) override;
void disable(FrameID id) override;
void disable(FrameID id, ftl::protocol::Channel channel) override;
void disable(FrameID id, const ftl::protocol::ChannelSet &channels) override;
void setProperty(ftl::protocol::StreamProperty opt, std::any value) override; void setProperty(ftl::protocol::StreamProperty opt, std::any value) override;
std::any getProperty(ftl::protocol::StreamProperty opt) override; std::any getProperty(ftl::protocol::StreamProperty opt) override;
......
...@@ -284,7 +284,31 @@ class Stream { ...@@ -284,7 +284,31 @@ class Stream {
*/ */
virtual bool enable(FrameID id, const ftl::protocol::ChannelSet &channels); virtual bool enable(FrameID id, const ftl::protocol::ChannelSet &channels);
// TODO(Nick): Disable /**
* @brief Disable an entire frame. If the frame is not available or is already
* disabled then this method has no effect.
*
* @param id
*/
virtual void disable(FrameID id);
/**
* @brief Disable a specific channel in a frame. If not available or already
* disabled then this method has no effect.
*
* @param id
* @param channel
*/
virtual void disable(FrameID id, ftl::protocol::Channel channel);
/**
* @brief Disable a set of channels in a frame. If not available or already
* disabled then this method has no effect.
*
* @param id
* @param channels
*/
virtual void disable(FrameID id, const ftl::protocol::ChannelSet &channels);
/** /**
* @brief Set a stream property to a new value. If the property is not supported, * @brief Set a stream property to a new value. If the property is not supported,
......
...@@ -134,6 +134,36 @@ bool Broadcast::enable(FrameID id, const ftl::protocol::ChannelSet &channels) { ...@@ -134,6 +134,36 @@ bool Broadcast::enable(FrameID id, const ftl::protocol::ChannelSet &channels) {
return r; return r;
} }
void Broadcast::disable(FrameID id) {
{
SHARED_LOCK(mtx_, lk);
for (auto &s : streams_) {
s.stream->disable(id);
}
}
Stream::disable(id);
}
void Broadcast::disable(FrameID id, ftl::protocol::Channel channel) {
{
SHARED_LOCK(mtx_, lk);
for (auto &s : streams_) {
s.stream->disable(id, channel);
}
}
Stream::disable(id, channel);
}
void Broadcast::disable(FrameID id, const ftl::protocol::ChannelSet &channels) {
{
SHARED_LOCK(mtx_, lk);
for (auto &s : streams_) {
s.stream->disable(id, channels);
}
}
Stream::disable(id, channels);
}
void Broadcast::setProperty(ftl::protocol::StreamProperty opt, std::any value) {} void Broadcast::setProperty(ftl::protocol::StreamProperty opt, std::any value) {}
std::any Broadcast::getProperty(ftl::protocol::StreamProperty opt) { std::any Broadcast::getProperty(ftl::protocol::StreamProperty opt) {
......
...@@ -201,6 +201,27 @@ bool Muxer::enable(FrameID id, const ftl::protocol::ChannelSet &channels) { ...@@ -201,6 +201,27 @@ bool Muxer::enable(FrameID id, const ftl::protocol::ChannelSet &channels) {
return r; return r;
} }
void Muxer::disable(FrameID id) {
auto p = _mapToOutput(id);
if (!p.second) return;
p.second->stream->disable(p.first);
Stream::disable(id);
}
void Muxer::disable(FrameID id, ftl::protocol::Channel channel) {
auto p = _mapToOutput(id);
if (!p.second) return;
p.second->stream->disable(p.first, channel);
Stream::disable(id, channel);
}
void Muxer::disable(FrameID id, const ftl::protocol::ChannelSet &channels) {
auto p = _mapToOutput(id);
if (!p.second) return;
p.second->stream->disable(p.first, channels);
Stream::disable(id, channels);
}
void Muxer::setProperty(ftl::protocol::StreamProperty opt, std::any value) { void Muxer::setProperty(ftl::protocol::StreamProperty opt, std::any value) {
for (auto &s : streams_) { for (auto &s : streams_) {
s.stream->setProperty(opt, value); s.stream->setProperty(opt, value);
......
...@@ -121,6 +121,32 @@ bool Stream::enable(FrameID id, const ftl::protocol::ChannelSet &channels) { ...@@ -121,6 +121,32 @@ bool Stream::enable(FrameID id, const ftl::protocol::ChannelSet &channels) {
return true; return true;
} }
void Stream::disable(FrameID id) {
UNIQUE_LOCK(mtx_, lk);
auto &p = state_[id];
p.enabled = false;
}
void Stream::disable(FrameID id, ftl::protocol::Channel channel) {
UNIQUE_LOCK(mtx_, lk);
auto &p = state_[id];
p.selected.erase(channel);
if (p.selected.size() == 0) {
p.enabled = false;
}
}
void Stream::disable(FrameID id, const ftl::protocol::ChannelSet &channels) {
UNIQUE_LOCK(mtx_, lk);
auto &p = state_[id];
for (const auto &c : channels) {
p.selected.erase(c);
}
if (p.selected.size() == 0) {
p.enabled = false;
}
}
void Stream::reset() { void Stream::reset() {
UNIQUE_LOCK(mtx_, lk); UNIQUE_LOCK(mtx_, lk);
state_.clear(); state_.clear();
......
...@@ -350,6 +350,51 @@ TEST_CASE("Muxer enable", "[stream]") { ...@@ -350,6 +350,51 @@ TEST_CASE("Muxer enable", "[stream]") {
} }
} }
TEST_CASE("Muxer disable", "[stream]") {
std::unique_ptr<Muxer> mux = std::make_unique<Muxer>();
REQUIRE(mux);
std::shared_ptr<TestStream> s1 = std::make_shared<TestStream>();
REQUIRE(s1);
std::shared_ptr<TestStream> s2 = std::make_shared<TestStream>();
REQUIRE(s2);
mux->add(s1);
mux->add(s2);
SECTION("disable frame id") {
FrameID id1(0, 1);
s1->forceSeen(id1, Channel::kColour);
FrameID id2(1, 1);
s2->forceSeen(id2, Channel::kColour);
REQUIRE( mux->enable(id1) );
REQUIRE( mux->enable(id2) );
REQUIRE(s1->enabled(id1));
REQUIRE(s2->enabled(id2));
mux->disable(id1);
REQUIRE(!s1->enabled(id1));
REQUIRE(s2->enabled(id2));
mux->disable(id2);
REQUIRE(!s1->enabled(id1));
REQUIRE(!s2->enabled(id2));
}
SECTION("disable frame channel") {
FrameID id1(0, 1);
s1->forceSeen(id1, Channel::kColour);
s1->forceSeen(id1, Channel::kDepth);
REQUIRE( mux->enable(id1, Channel::kColour) );
REQUIRE( mux->enable(id1, Channel::kDepth) );
REQUIRE(s1->enabled(id1, Channel::kColour));
REQUIRE(s1->enabled(id1, Channel::kDepth));
mux->disable(id1, Channel::kColour);
REQUIRE(!s1->enabled(id1, Channel::kColour));
REQUIRE(s1->enabled(id1, Channel::kDepth));
}
}
TEST_CASE("Muxer available", "[stream]") { TEST_CASE("Muxer available", "[stream]") {
std::unique_ptr<Muxer> mux = std::make_unique<Muxer>(); std::unique_ptr<Muxer> mux = std::make_unique<Muxer>();
REQUIRE(mux); REQUIRE(mux);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment