Merge branch 'development' into LTS_development

# Conflicts:
#	src/input/input.cpp
#	src/output/output.cpp
This commit is contained in:
Thulinma 2016-11-14 11:29:24 +01:00
commit 3f14db4b12
12 changed files with 137 additions and 64 deletions

View file

@ -97,7 +97,8 @@ namespace Mist {
INSANE_MSG("No header exists to compare - ignoring header check");
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());
remove(headerFile.c_str());
}
@ -180,12 +181,6 @@ namespace Mist {
/// streamname
/// input name
/// ~~~~~~~~~~~~~~~
/// The `"STREAM_UNLOAD"` trigger is stream-specific, and is ran right before an input shuts down and stops serving a stream. If cancelled, the shut down is delayed. Its payload is:
/// ~~~~~~~~~~~~~~~
/// streamname
/// input name
/// ~~~~~~~~~~~~~~~
//
void Input::serve(){
if (!isBuffer) {
for (std::map<unsigned int, DTSC::Track>::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++) {
@ -205,11 +200,15 @@ namespace Mist {
/*LTS-END*/
DEBUG_MSG(DLVL_DEVEL, "Input for stream %s started", streamName.c_str());
long long int activityCounter = Util::bootSecs();
while (((Util::bootSecs() - activityCounter) < INPUT_TIMEOUT || (myMeta.live && (Util::bootSecs() - activityCounter) < myMeta.biggestFragment()/500)) && config->is_active) { //15 second timeout
activityCounter = Util::bootSecs();
//main serve loop
while (keepRunning()) {
//load pages for connected clients on request
//through the callbackWrapper function
userPage.parseEach(callbackWrapper);
//unload pages that haven't been used for a while
removeUnused();
//If users are connected and tracks exist, reset the activity counter
if (userPage.connectedUsers) {
if (myMeta.tracks.size()){
activityCounter = Util::bootSecs();
@ -218,17 +217,7 @@ namespace Mist {
} else {
DEBUG_MSG(DLVL_INSANE, "Timer running");
}
/*LTS-START*/
if ((Util::bootSecs() - activityCounter) >= INPUT_TIMEOUT || !config->is_active){//15 second timeout
if(Triggers::shouldTrigger("STREAM_UNLOAD", config->getString("streamname"))){
std::string payload = config->getString("streamname")+"\n" +capa["name"].asStringRef()+"\n";
if (!Triggers::doTrigger("STREAM_UNLOAD", payload, config->getString("streamname"))){
activityCounter = Util::bootSecs();
config->is_active = true;
}
}
}
/*LTS-END*/
//if not shutting down, wait 1 second before looping
if (config->is_active){
Util::wait(1000);
}
@ -238,6 +227,14 @@ namespace Mist {
//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.
/// This loop will start the buffer without resume support, and then repeatedly call ..... followed by ....
void Input::stream(){

View file

@ -34,6 +34,7 @@ namespace Mist {
virtual void getNext(bool smart = true) {};
virtual void seek(int seekTime){};
virtual void finish();
virtual bool keepRunning();
virtual bool openStreamSource() { return false; };
virtual void closeStreamSource() {};
virtual void parseStreamHeader() {};
@ -60,6 +61,7 @@ namespace Mist {
unsigned int benchMark;
bool isBuffer;
uint64_t activityCounter;
JSON::Value capa;

View file

@ -5,6 +5,9 @@
#include <cstdlib>
#include <cstdio>
#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/stream.h>
#include <mist/defines.h>
@ -46,9 +49,30 @@ namespace Mist {
if (!inFile) {
return false;
}
struct stat statData;
lastModTime = 0;
if (stat(config->getString("input").c_str(), &statData) != -1){
lastModTime = statData.st_mtime;
}
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() {
if (!inFile){return false;}
//See whether a separate header file exists.

View file

@ -13,7 +13,9 @@ namespace Mist {
void getNext(bool smart = true);
void seek(int seekTime);
void trackSelect(std::string trackSpec);
bool keepRunning();
FLV::Tag tmpTag;
uint64_t lastModTime;
FILE * inFile;
};
}