From 01e0b76a6a3b0649c8d1930350830d13d5c68de1 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 22 Jun 2017 16:18:18 +0200 Subject: [PATCH] Internal stream state active/inactive rewritten to use newly exposed stream status --- src/controller/controller_api.cpp | 2 +- src/controller/controller_push.cpp | 4 ++-- src/controller/controller_statistics.cpp | 20 ++++++++++++++------ src/controller/controller_statistics.h | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index 4ef1adcd..d5d2d4c5 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -572,7 +572,7 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response startPush(stream, target); }else{ if (activeStreams.size()){ - for (std::map::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){ + for (std::map::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){ if (jt->first.substr(0, stream.size()) == stream){ std::string streamname = jt->first; std::string target_tmp = target; diff --git a/src/controller/controller_push.cpp b/src/controller/controller_push.cpp index 4ecb034a..18f17ff5 100644 --- a/src/controller/controller_push.cpp +++ b/src/controller/controller_push.cpp @@ -129,7 +129,7 @@ namespace Controller{ jsonForEach(Controller::Storage["autopushes"], it){ const std::string &pStr = (*it)[0u].asStringRef(); if (activeStreams.size()){ - for (std::map::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){ + for (std::map::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){ std::string streamname = jt->first; std::string target = (*it)[1u]; if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){ @@ -195,7 +195,7 @@ namespace Controller{ if (activeStreams.size()){ const std::string &pStr = newPush[0u].asStringRef(); std::string target = newPush[1u].asStringRef(); - for (std::map::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ + for (std::map::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ std::string streamname = it->first; if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){ diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index f42482ca..ee23a088 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "controller_statistics.h" #include "controller_limits.h" #include "controller_push.h" @@ -40,7 +41,7 @@ std::map Controller::sessions; / std::map Controller::connToSession; ///< Map of socket IDs to session info. bool Controller::killOnExit = KILL_ON_EXIT; tthread::mutex Controller::statsMutex; -std::map Controller::activeStreams; +std::map Controller::activeStreams; unsigned int Controller::maxConnsPerIP = 0; /// Session cache shared memory page @@ -319,9 +320,17 @@ void Controller::SharedMemStats(void * config){ } } if (activeStreams.size()){ - for (std::map::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ - if (++it->second > STATS_DELAY){ - streamStopped(it->first); + for (std::map::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){ + uint8_t newState = Util::getStreamStatus(it->first); + if (newState != activeStreams[it->first]){ + activeStreams[it->first] = newState; + if (newState == STRMSTAT_READY){ + streamStarted(it->first); + }else{ + streamStopped(it->first); + } + } + if (newState == STRMSTAT_OFF){ inactiveStreams.insert(it->first); } } @@ -955,9 +964,8 @@ void Controller::parseStatistics(char * data, size_t len, unsigned int id){ std::string strmName = tmpEx.streamName(); if (strmName.size()){ if (!activeStreams.count(strmName)){ - streamStarted(strmName); + activeStreams[strmName] = 0; } - activeStreams[strmName] = 0; } } } diff --git a/src/controller/controller_statistics.h b/src/controller/controller_statistics.h index f134019e..ce0c61dd 100644 --- a/src/controller/controller_statistics.h +++ b/src/controller/controller_statistics.h @@ -19,7 +19,7 @@ namespace Controller { extern unsigned int maxConnsPerIP; //These keep track of which streams are currently active. - extern std::map activeStreams; + extern std::map activeStreams; ///This function is ran whenever a stream becomes active. void streamStarted(std::string stream); ///This function is ran whenever a stream becomes inactive.