From 920efe0b2678ae5aec87483c24785359a946c3a6 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 9 Jun 2017 20:40:03 +0200 Subject: [PATCH] Updated serve-type inputs to obey "always on" stream config setting, push inputs no longer counted as viewers. --- src/input/input.cpp | 38 ++++++++++++++++++++++++++++++++------ src/input/input.h | 4 ++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index 6557d2b5..08e7cfd9 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -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()); diff --git a/src/input/input.h b/src/input/input.h index 98963f2a..9d11e430 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -48,8 +48,8 @@ namespace Mist { virtual void convert(); virtual void serve(); virtual void stream(); - - + bool isAlwaysOn(); + virtual void parseHeader(); bool bufferFrame(unsigned int track, unsigned int keyNum);