Added stream status shared memory page (temporary system)

This commit is contained in:
Thulinma 2017-06-22 14:03:35 +02:00
parent 76b5a91da6
commit 25699ef8b2
6 changed files with 27 additions and 0 deletions

View file

@ -107,6 +107,14 @@ static inline void show_stackframe(){}
#define FLIP_MIN_DURATION 20000 #define FLIP_MIN_DURATION 20000
#define SHM_STREAM_INDEX "MstSTRM%s" //%s stream name #define SHM_STREAM_INDEX "MstSTRM%s" //%s stream name
#define SHM_STREAM_STATE "MstSTATE%s" //%s stream name
#define STRMSTAT_OFF 0
#define STRMSTAT_INIT 1
#define STRMSTAT_BOOT 2
#define STRMSTAT_WAIT 3
#define STRMSTAT_READY 4
#define STRMSTAT_SHUTDOWN 5
#define STRMSTAT_INVALID 255
#define SHM_TRACK_META "MstTRAK%s@%lu" //%s stream name, %lu track ID #define SHM_TRACK_META "MstTRAK%s@%lu" //%s stream name, %lu track ID
#define SHM_TRACK_INDEX "MstTRID%s@%lu" //%s stream name, %lu track ID #define SHM_TRACK_INDEX "MstTRID%s@%lu" //%s stream name, %lu track ID
#define SHM_TRACK_INDEX_SIZE 8192 #define SHM_TRACK_INDEX_SIZE 8192

View file

@ -299,3 +299,11 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
return streamAlive(streamname); return streamAlive(streamname);
} }
uint8_t Util::getStreamStatus(std::string & streamname){
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamname.c_str());
IPC::sharedPage streamStatus(pageName, 1, false, false);
if (!streamStatus){return STRMSTAT_OFF;}
return streamStatus.mapped[0];
}

View file

@ -12,5 +12,6 @@ namespace Util {
bool streamAlive(std::string & streamname); bool streamAlive(std::string & streamname);
bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true, bool isProvider = false); bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true, bool isProvider = false);
JSON::Value getStreamConfig(std::string streamname); JSON::Value getStreamConfig(std::string streamname);
uint8_t getStreamStatus(std::string & streamname);
} }

View file

@ -114,6 +114,10 @@ namespace Mist {
DEBUG_MSG(DLVL_DEVEL, "A player for stream %s is already running", streamName.c_str()); DEBUG_MSG(DLVL_DEVEL, "A player for stream %s is already running", streamName.c_str());
return 1; return 1;
} }
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 1, true, false);
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INIT;}
} }
config->activate(); config->activate();
uint64_t reTimer = 0; uint64_t reTimer = 0;
@ -142,6 +146,7 @@ namespace Mist {
MEDIUM_MSG("Input for stream %s shut down cleanly", streamName.c_str()); MEDIUM_MSG("Input for stream %s shut down cleanly", streamName.c_str());
break; break;
} }
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INVALID;}
#if DEBUG >= DLVL_DEVEL #if DEBUG >= DLVL_DEVEL
WARN_MSG("Aborting autoclean; this is a development build."); WARN_MSG("Aborting autoclean; this is a development build.");
INFO_MSG("Input for stream %s uncleanly shut down! Aborting restart; this is a development build.", streamName.c_str()); INFO_MSG("Input for stream %s uncleanly shut down! Aborting restart; this is a development build.", streamName.c_str());
@ -162,6 +167,7 @@ namespace Mist {
} }
int Input::run() { int Input::run() {
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_BOOT;}
checkHeaderTimes(config->getString("input")); checkHeaderTimes(config->getString("input"));
if (!readHeader()){ if (!readHeader()){
std::cerr << "Reading header for " << config->getString("input") << " failed." << std::endl; std::cerr << "Reading header for " << config->getString("input") << " failed." << std::endl;
@ -256,6 +262,7 @@ namespace Mist {
char userPageName[NAME_BUFFER_SIZE]; char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str()); snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
userPage.init(userPageName, PLAY_EX_SIZE, true); userPage.init(userPageName, PLAY_EX_SIZE, true);
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_READY;}
DEBUG_MSG(DLVL_DEVEL, "Input for stream %s started", streamName.c_str()); DEBUG_MSG(DLVL_DEVEL, "Input for stream %s started", streamName.c_str());
activityCounter = Util::bootSecs(); activityCounter = Util::bootSecs();
@ -279,6 +286,7 @@ namespace Mist {
Util::wait(1000); Util::wait(1000);
} }
} }
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_SHUTDOWN;}
config->is_active = false; config->is_active = false;
finish(); finish();
DEBUG_MSG(DLVL_DEVEL, "Input for stream %s closing clean", streamName.c_str()); DEBUG_MSG(DLVL_DEVEL, "Input for stream %s closing clean", streamName.c_str());

View file

@ -69,6 +69,7 @@ namespace Mist {
//Create server for user pages //Create server for user pages
IPC::sharedServer userPage; IPC::sharedServer userPage;
IPC::sharedPage streamStatus;
std::map<unsigned int, std::map<unsigned int, unsigned int> > pageCounter; std::map<unsigned int, std::map<unsigned int, unsigned int> > pageCounter;

View file

@ -394,6 +394,7 @@ namespace Mist {
} }
} }
updateMeta(); updateMeta();
if (streamStatus){streamStatus.mapped[0] = hasPush ? STRMSTAT_READY : STRMSTAT_WAIT;}
static bool everHadPush = false; static bool everHadPush = false;
if (hasPush) { if (hasPush) {
hasPush = false; hasPush = false;