Added new generalized input keepRunning() function, FLV input now shuts down if the file is updated file it is active, added 15 second DTSH regeneration window
This commit is contained in:
parent
94e39f8323
commit
8d83a203be
4 changed files with 48 additions and 6 deletions
|
@ -81,7 +81,8 @@ namespace Mist {
|
||||||
INSANE_MSG("No header exists to compare - ignoring header check");
|
INSANE_MSG("No header exists to compare - ignoring header check");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (bufHeader.st_mtime < bufStream.st_mtime) {
|
//the same second is not enough - add a 15 second window where we consider it too old
|
||||||
|
if (bufHeader.st_mtime < bufStream.st_mtime + 15) {
|
||||||
INFO_MSG("Overwriting outdated DTSH header file: %s ", headerFile.c_str());
|
INFO_MSG("Overwriting outdated DTSH header file: %s ", headerFile.c_str());
|
||||||
remove(headerFile.c_str());
|
remove(headerFile.c_str());
|
||||||
}
|
}
|
||||||
|
@ -167,12 +168,16 @@ namespace Mist {
|
||||||
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);
|
||||||
|
|
||||||
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();
|
||||||
long long int activityCounter = Util::bootSecs();
|
//main serve loop
|
||||||
while (((Util::bootSecs() - activityCounter) < INPUT_TIMEOUT || (myMeta.live && (Util::bootSecs() - activityCounter) < myMeta.biggestFragment()/500)) && config->is_active) { //15 second timeout
|
while (keepRunning()) {
|
||||||
|
//load pages for connected clients on request
|
||||||
|
//through the callbackWrapper function
|
||||||
userPage.parseEach(callbackWrapper);
|
userPage.parseEach(callbackWrapper);
|
||||||
|
//unload pages that haven't been used for a while
|
||||||
removeUnused();
|
removeUnused();
|
||||||
|
//If users are connected and tracks exist, reset the activity counter
|
||||||
if (userPage.connectedUsers) {
|
if (userPage.connectedUsers) {
|
||||||
if (myMeta.tracks.size()){
|
if (myMeta.tracks.size()){
|
||||||
activityCounter = Util::bootSecs();
|
activityCounter = Util::bootSecs();
|
||||||
|
@ -181,6 +186,7 @@ namespace Mist {
|
||||||
}else{
|
}else{
|
||||||
DEBUG_MSG(DLVL_INSANE, "Timer running");
|
DEBUG_MSG(DLVL_INSANE, "Timer running");
|
||||||
}
|
}
|
||||||
|
//if not shutting down, wait 1 second before looping
|
||||||
if (config->is_active){
|
if (config->is_active){
|
||||||
Util::wait(1000);
|
Util::wait(1000);
|
||||||
}
|
}
|
||||||
|
@ -190,6 +196,14 @@ namespace Mist {
|
||||||
//end player functionality
|
//end player functionality
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Input::keepRunning(){
|
||||||
|
//We keep running in serve mode if the config is still active AND either
|
||||||
|
// - INPUT_TIMEOUT seconds haven't passed yet,
|
||||||
|
// - this is a live stream and at least two of the biggest fragment haven't passed yet,
|
||||||
|
bool ret = (config->is_active && ((Util::bootSecs() - activityCounter) < INPUT_TIMEOUT || (myMeta.live && (Util::bootSecs() - activityCounter) < myMeta.biggestFragment()/500)));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/// Main loop for stream-style inputs.
|
/// Main loop for stream-style inputs.
|
||||||
/// This loop will start the buffer without resume support, and then repeatedly call ..... followed by ....
|
/// This loop will start the buffer without resume support, and then repeatedly call ..... followed by ....
|
||||||
void Input::stream(){
|
void Input::stream(){
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace Mist {
|
||||||
virtual void getNext(bool smart = true) {};
|
virtual void getNext(bool smart = true) {};
|
||||||
virtual void seek(int seekTime){};
|
virtual void seek(int seekTime){};
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
virtual bool keepRunning();
|
||||||
virtual bool openStreamSource() { return false; };
|
virtual bool openStreamSource() { return false; };
|
||||||
virtual void closeStreamSource() {};
|
virtual void closeStreamSource() {};
|
||||||
virtual void parseStreamHeader() {};
|
virtual void parseStreamHeader() {};
|
||||||
|
@ -60,6 +61,7 @@ namespace Mist {
|
||||||
unsigned int benchMark;
|
unsigned int benchMark;
|
||||||
|
|
||||||
bool isBuffer;
|
bool isBuffer;
|
||||||
|
uint64_t activityCounter;
|
||||||
|
|
||||||
JSON::Value capa;
|
JSON::Value capa;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/types.h>//for stat
|
||||||
|
#include <sys/stat.h>//for stat
|
||||||
|
#include <unistd.h>//for stat
|
||||||
#include <mist/util.h>
|
#include <mist/util.h>
|
||||||
#include <mist/stream.h>
|
#include <mist/stream.h>
|
||||||
#include <mist/defines.h>
|
#include <mist/defines.h>
|
||||||
|
@ -46,9 +49,30 @@ namespace Mist {
|
||||||
if (!inFile) {
|
if (!inFile) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
struct stat statData;
|
||||||
|
lastModTime = 0;
|
||||||
|
if (stat(config->getString("input").c_str(), &statData) != -1){
|
||||||
|
lastModTime = statData.st_mtime;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Overrides the default keepRunning function to shut down
|
||||||
|
/// if the file disappears or changes, by polling the file's mtime.
|
||||||
|
/// If neither applies, calls the original function.
|
||||||
|
bool inputFLV::keepRunning(){
|
||||||
|
struct stat statData;
|
||||||
|
if (stat(config->getString("input").c_str(), &statData) == -1){
|
||||||
|
INFO_MSG("Shutting down because input file disappeared");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (lastModTime != statData.st_mtime){
|
||||||
|
INFO_MSG("Shutting down because input file changed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Input::keepRunning();
|
||||||
|
}
|
||||||
|
|
||||||
bool inputFLV::readHeader() {
|
bool inputFLV::readHeader() {
|
||||||
if (!inFile){return false;}
|
if (!inFile){return false;}
|
||||||
//See whether a separate header file exists.
|
//See whether a separate header file exists.
|
||||||
|
|
|
@ -13,7 +13,9 @@ namespace Mist {
|
||||||
void getNext(bool smart = true);
|
void getNext(bool smart = true);
|
||||||
void seek(int seekTime);
|
void seek(int seekTime);
|
||||||
void trackSelect(std::string trackSpec);
|
void trackSelect(std::string trackSpec);
|
||||||
|
bool keepRunning();
|
||||||
FLV::Tag tmpTag;
|
FLV::Tag tmpTag;
|
||||||
|
uint64_t lastModTime;
|
||||||
FILE * inFile;
|
FILE * inFile;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue