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

Allow proper file stream pausing

parent 9ff87a7a
No related branches found
No related tags found
No related merge requests found
......@@ -214,6 +214,11 @@ void Camera::setVolume(float v) {
return io->speaker()->setVolume(v);
}
void Camera::setPaused(bool set) {
paused_ = set;
io->feed()->muxer()->set("paused", set);
}
std::unordered_set<Channel> Camera::availableChannels() {
if (std::atomic_load(&latest_)) {
return latest_->frames[frame_idx].available();
......@@ -257,8 +262,6 @@ void Camera::activate(ftl::data::FrameID id) {
filter_ = io->feed()->filter(std::unordered_set<unsigned int>{id.frameset()}, {Channel::Left});
filter_->on(
[this, feed = io->feed(), speaker = io->speaker()](ftl::data::FrameSetPtr fs){
if (paused_) return true;
std::atomic_store(&current_fs_, fs);
std::atomic_store(&latest_, fs);
......
......@@ -21,8 +21,8 @@ public:
virtual void activate(ftl::data::FrameID id);
void setChannel(ftl::codecs::Channel c);
void setPaused(bool set) { paused_ = set; };
bool isPaused() { return paused_; }
void setPaused(bool set);
bool isPaused() const { return paused_; }
void toggleOverlay();
......
......@@ -177,6 +177,8 @@ public:
void lowLatencyMode();
ftl::stream::Muxer *muxer() const { return stream_.get(); }
private:
// public methods acquire lock if necessary, private methods assume locking
// managed by caller
......
......@@ -151,6 +151,7 @@ class Muxer : public Stream {
void _notify(const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt);
int _lookup(size_t fsid, StreamEntry *se, int ssid, int count);
void _forward(const std::string &name);
};
/**
......
......@@ -225,6 +225,9 @@ bool File::tick(int64_t ts) {
return false;
}
// Skip if paused
if (value("paused", false)) return true;
#ifdef DEBUG_MUTEX
UNIQUE_LOCK(mutex_, lk);
#else
......
#include <ftl/streams/stream.hpp>
#include <nlohmann/json.hpp>
#define LOGURU_WITH_STREAMS 1
#include <loguru.hpp>
......@@ -75,7 +76,8 @@ void Stream::reset() {
// ==== Muxer ==================================================================
Muxer::Muxer(nlohmann::json &config) : Stream(config), nid_{0} {
value("paused", false);
_forward("paused");
}
Muxer::~Muxer() {
......@@ -85,6 +87,16 @@ Muxer::~Muxer() {
}
}
void Muxer::_forward(const std::string &name) {
on(name, [this,name]() {
auto val = getConfig()[name];
UNIQUE_LOCK(mutex_,lk);
for (auto &se : streams_) {
se.stream->set(name, val);
}
});
}
void Muxer::add(Stream *s, size_t fsid, const std::function<int()> &cb) {
UNIQUE_LOCK(mutex_,lk);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment