From f3ba13d6bb0356d4ea105854b4e6783f99264840 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 21 Aug 2023 11:20:31 +0200 Subject: [PATCH] Change controller calls that use stream metadata to instantly time out if unavailable, rather than waiting for availability --- lib/dtsc.cpp | 12 ++++++------ lib/dtsc.h | 6 +++--- src/controller/controller_statistics.cpp | 12 ++++++------ src/controller/controller_streams.cpp | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 66630d89..bfd887d6 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -901,13 +901,13 @@ namespace DTSC{ /// Initialize empty metadata, in master or slave mode. /// If stream name is empty, slave mode is enforced. - Meta::Meta(const std::string &_streamName, bool master){ + Meta::Meta(const std::string &_streamName, bool master, bool autoBackOff){ if (!_streamName.size()){master = false;} version = DTSH_VERSION; streamMemBuf = 0; isMemBuf = false; isMaster = master; - reInit(_streamName, master); + reInit(_streamName, master, autoBackOff); } /// Initialize metadata from given DTSH file in master mode. @@ -926,12 +926,12 @@ namespace DTSC{ /// Calls clear(), then initializes freshly. /// If stream name is set, uses shared memory backing. /// If stream name is empty, uses non-shared memory backing. - void Meta::reInit(const std::string &_streamName, bool master){ + void Meta::reInit(const std::string &_streamName, bool master, bool autoBackOff){ clear(); if (_streamName == ""){ sBufMem(); }else{ - sBufShm(_streamName, DEFAULT_TRACK_COUNT, master); + sBufShm(_streamName, DEFAULT_TRACK_COUNT, master, autoBackOff); } streamInit(); } @@ -1118,7 +1118,7 @@ namespace DTSC{ /// Initializes shared memory backed mode, with enough room for the given track count. /// Should not be called repeatedly, nor to switch modes. - void Meta::sBufShm(const std::string &_streamName, size_t trackCount, bool master){ + void Meta::sBufShm(const std::string &_streamName, size_t trackCount, bool master, bool autoBackOff){ isMaster = master; if (isMaster){HIGH_MSG("Creating meta page for stream %s", _streamName.c_str());} @@ -1142,7 +1142,7 @@ namespace DTSC{ streamPage.master = false; stream = Util::RelAccX(streamPage.mapped, false); }else{ - streamPage.init(pageName, bufferSize, false, true); + streamPage.init(pageName, bufferSize, false, autoBackOff); if (!streamPage.mapped){ INFO_MSG("Page %s not found", pageName); return; diff --git a/lib/dtsc.h b/lib/dtsc.h index dafa8fc8..9a2dbd7c 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -284,11 +284,11 @@ namespace DTSC{ class Meta{ public: Meta(const std::string &_streamName, const DTSC::Scan &src); - Meta(const std::string &_streamName = "", bool master = true); + Meta(const std::string &_streamName = "", bool master = true, bool autoBackOff = true); Meta(const std::string &_streamName, const std::string &fileName); ~Meta(); - void reInit(const std::string &_streamName, bool master = true); + void reInit(const std::string &_streamName, bool master = true, bool autoBackOff = true); void reInit(const std::string &_streamName, const std::string &fileName); void reInit(const std::string &_streamName, const DTSC::Scan &src); void addTrackFrom(const DTSC::Scan &src); @@ -493,7 +493,7 @@ namespace DTSC{ protected: void sBufMem(size_t trackCount = DEFAULT_TRACK_COUNT); - void sBufShm(const std::string &_streamName, size_t trackCount = DEFAULT_TRACK_COUNT, bool master = true); + void sBufShm(const std::string &_streamName, size_t trackCount = DEFAULT_TRACK_COUNT, bool master = true, bool autoBackOff = true); void streamInit(size_t trackCount = DEFAULT_TRACK_COUNT); std::string streamName; diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 805f0075..d38248b2 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -1207,7 +1207,7 @@ void Controller::fillHasStats(JSON::Value &req, JSON::Value &rep){ jsonForEach(req, j){ if (j->asStringRef() == "clients"){rep[*it].append(clients[*it]);} if (j->asStringRef() == "lastms"){ - DTSC::Meta M(*it, false); + DTSC::Meta M(*it, false, false); if (M){ uint64_t lms = 0; std::set validTracks = M.getValidTracks(); @@ -1325,7 +1325,7 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){ }else if (j->asStringRef() == "packretrans"){ F = it->second.packRetrans; }else if (j->asStringRef() == "firstms"){ - if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} + if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);} if (M){ uint64_t fms = 0; std::set validTracks = M.getValidTracks(); @@ -1335,7 +1335,7 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){ F = fms; } }else if (j->asStringRef() == "lastms"){ - if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} + if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);} if (M){ uint64_t lms = 0; std::set validTracks = M.getValidTracks(); @@ -1345,15 +1345,15 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){ F = lms; } }else if (j->asStringRef() == "zerounix"){ - if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} + if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);} if (M && M.getLive()){ F = (M.getBootMsOffset() + (Util::unixMS() - Util::bootMS())) / 1000; } }else if (j->asStringRef() == "health"){ - if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} + if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);} if (M){M.getHealthJSON(F);} }else if (j->asStringRef() == "tracks"){ - if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} + if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);} if (M){ F = (uint64_t)M.getValidTracks().size(); } diff --git a/src/controller/controller_streams.cpp b/src/controller/controller_streams.cpp index 6c2c635b..2c8a7860 100644 --- a/src/controller/controller_streams.cpp +++ b/src/controller/controller_streams.cpp @@ -353,7 +353,7 @@ namespace Controller{ Util::sanitizeName(cleaned); std::string strmSource; if (Util::getStreamStatus(cleaned) != STRMSTAT_OFF){ - DTSC::Meta M(cleaned, false); + DTSC::Meta M(cleaned, false, false); if (M && M.getSource().size()){strmSource = M.getSource();} } if (!strmSource.size()){