Internal stream state active/inactive rewritten to use newly exposed stream status

This commit is contained in:
Thulinma 2017-06-22 16:18:18 +02:00
parent 422caafde2
commit 01e0b76a6a
4 changed files with 18 additions and 10 deletions

View file

@ -572,7 +572,7 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
startPush(stream, target);
}else{
if (activeStreams.size()){
for (std::map<std::string, unsigned int>::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){
for (std::map<std::string, uint8_t>::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;

View file

@ -129,7 +129,7 @@ namespace Controller{
jsonForEach(Controller::Storage["autopushes"], it){
const std::string &pStr = (*it)[0u].asStringRef();
if (activeStreams.size()){
for (std::map<std::string, unsigned int>::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){
for (std::map<std::string, uint8_t>::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<std::string, unsigned int>::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){
for (std::map<std::string, uint8_t>::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){
std::string streamname = it->first;
if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){

View file

@ -6,6 +6,7 @@
#include <mist/shared_memory.h>
#include <mist/dtsc.h>
#include <mist/procs.h>
#include <mist/stream.h>
#include "controller_statistics.h"
#include "controller_limits.h"
#include "controller_push.h"
@ -40,7 +41,7 @@ std::map<Controller::sessIndex, Controller::statSession> Controller::sessions; /
std::map<unsigned long, Controller::sessIndex> Controller::connToSession; ///< Map of socket IDs to session info.
bool Controller::killOnExit = KILL_ON_EXIT;
tthread::mutex Controller::statsMutex;
std::map<std::string, unsigned int> Controller::activeStreams;
std::map<std::string, uint8_t> 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<std::string, unsigned int>::iterator it = activeStreams.begin(); it != activeStreams.end(); ++it){
if (++it->second > STATS_DELAY){
streamStopped(it->first);
for (std::map<std::string, uint8_t>::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;
}
}
}

View file

@ -19,7 +19,7 @@ namespace Controller {
extern unsigned int maxConnsPerIP;
//These keep track of which streams are currently active.
extern std::map<std::string, unsigned int> activeStreams;
extern std::map<std::string, uint8_t> activeStreams;
///This function is ran whenever a stream becomes active.
void streamStarted(std::string stream);
///This function is ran whenever a stream becomes inactive.