Updated serve-type inputs to obey "always on" stream config setting, push inputs no longer counted as viewers.

This commit is contained in:
Thulinma 2017-06-09 20:40:03 +02:00
parent 26f74accdf
commit 920efe0b26
2 changed files with 34 additions and 8 deletions

View file

@ -168,8 +168,10 @@ namespace Mist {
return 0;
}
myMeta.sourceURI = config->getString("input");
parseHeader();
MEDIUM_MSG("Header parsed, %lu tracks", myMeta.tracks.size());
if (myMeta.vod){
parseHeader();
MEDIUM_MSG("Header parsed, %lu tracks", myMeta.tracks.size());
}
if (!streamName.size()) {
MEDIUM_MSG("Starting convert");
@ -226,6 +228,24 @@ namespace Mist {
}
}
///Checks in the server configuration if this stream is set to always on or not.
/// Returns true if it is, or if the stream could not be found in the configuration.
bool Input::isAlwaysOn(){
bool ret = true;
std::string strName = streamName.substr(0, (streamName.find_first_of("+ ")));
IPC::sharedPage serverCfg(SHM_CONF, DEFAULT_CONF_PAGE_SIZE, false, false); ///< Contains server configuration and capabilities
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
configLock.wait();
DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(strName);
if (streamCfg){
if (!streamCfg.getMember("always_on") || !streamCfg.getMember("always_on").asBool()){
ret = false;
}
}
configLock.post();
return ret;
}
/// The main loop for inputs in stream serving mode.
void Input::serve(){
if (!isBuffer){
@ -247,25 +267,30 @@ namespace Mist {
//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) {
//Also reset periodically if the stream is configured as Always on
if (userPage.connectedUsers || ((Util::bootSecs() - activityCounter) > INPUT_TIMEOUT/2 && isAlwaysOn())) {
if (myMeta.tracks.size()){
activityCounter = Util::bootSecs();
}
DEBUG_MSG(DLVL_INSANE, "Connected users: %d", userPage.connectedUsers);
}else{
DEBUG_MSG(DLVL_INSANE, "Timer running");
}
INSANE_MSG("Connected: %d users, %d total", userPage.connectedUsers, userPage.amount);
//if not shutting down, wait 1 second before looping
if (config->is_active){
Util::wait(1000);
}
}
config->is_active = false;
finish();
DEBUG_MSG(DLVL_DEVEL, "Input for stream %s closing clean", streamName.c_str());
userPage.finishEach();
//end player functionality
}
/// This function checks if an input in serve mode should keep running or not.
/// The default implementation checks for interruption by signals and otherwise waits until a
/// save amount of time has passed before shutting down.
/// For live streams, this is twice the biggest fragment duration.
/// For non-live streams this is INPUT_TIMEOUT seconds.
bool Input::keepRunning(){
//We keep running in serve mode if the config is still active AND either
// - INPUT_TIMEOUT seconds haven't passed yet,
@ -313,6 +338,7 @@ namespace Mist {
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
nProxy.userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
nProxy.userClient.countAsViewer = false;
INFO_MSG("Input for stream %s started", streamName.c_str());

View file

@ -48,7 +48,7 @@ namespace Mist {
virtual void convert();
virtual void serve();
virtual void stream();
bool isAlwaysOn();
virtual void parseHeader();
bool bufferFrame(unsigned int track, unsigned int keyNum);