From 720f4b5d051a3cc0787667d357ed0d7ba2911b1d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 24 Jul 2023 15:33:38 +0200 Subject: [PATCH] Added configurable input timeout for all inputs --- src/input/input.cpp | 21 ++++++++++++++++++--- src/input/input.h | 1 + src/input/input_buffer.cpp | 9 +++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index 834e785f..6098aaab 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -100,6 +100,7 @@ namespace Mist{ config = cfg; standAlone = true; Util::Config::binaryType = Util::INPUT; + inputTimeout = INPUT_TIMEOUT; JSON::Value option; option["long"] = "json"; @@ -131,6 +132,19 @@ namespace Mist{ option["value"].append(0u); option["help"] = "Generate .dtsh, then exit"; config->addOption("headeronly", option); + option.null(); + option["short"] = "i"; + option["arg"] = "integer"; + option["long"] = "inputtimeout"; + option["value"].append(inputTimeout); + option["help"] = "Time in seconds to keep the input process loaded without activity"; + config->addOption("inputtimeout", option); + capa["optional"]["inputtimeout"]["name"] = "Input inactivity timeout"; + capa["optional"]["inputtimeout"]["help"] = "How long the input should remain loaded without activity"; + capa["optional"]["inputtimeout"]["default"] = inputTimeout; + capa["optional"]["inputtimeout"]["unit"] = "s"; + capa["optional"]["inputtimeout"]["type"] = "uint"; + capa["optional"]["inputtimeout"]["option"] = "--inputtimeout"; /*LTS-START*/ /* @@ -368,6 +382,7 @@ namespace Mist{ int Input::boot(int argc, char *argv[]){ if (!(config->parseArgs(argc, argv))){return 1;} streamName = config->getString("streamname"); + inputTimeout = config->getInteger("inputtimeout"); Util::setStreamName(streamName); if (config->getBool("json")){ @@ -923,7 +938,7 @@ namespace Mist{ // 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); + bool ret = config->is_active && ((Util::bootSecs() - activityCounter) < inputTimeout); /*LTS-START*/ if (!ret){ if (Triggers::shouldTrigger("STREAM_UNLOAD", config->getString("streamname"))){ @@ -936,8 +951,8 @@ namespace Mist{ } } /*LTS-END*/ - if (!ret && ((Util::bootSecs() - activityCounter) >= INPUT_TIMEOUT)){ - Util::logExitReason(ER_CLEAN_INACTIVE, "no activity for %u seconds", Util::bootSecs() - activityCounter); + if (!ret && ((Util::bootSecs() - activityCounter) >= inputTimeout)){ + Util::logExitReason(ER_CLEAN_INACTIVE, "no activity for %us (> %" PRIu64 "s)", Util::bootSecs() - activityCounter, inputTimeout); } return ret; } diff --git a/src/input/input.h b/src/input/input.h index 5902fed7..311c5939 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -57,6 +57,7 @@ namespace Mist{ Comms::Connections statComm; uint64_t startTime; uint64_t lastStats; + uint64_t inputTimeout; virtual bool checkArguments() = 0; virtual bool readHeader(); diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index a48faf57..6fa15510 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -557,7 +557,13 @@ namespace Mist{ bufferTime = tmpNum; } - /*LTS-START*/ + //Check if input timeout setting is correct + tmpNum = retrieveSetting(streamCfg, "inputtimeout"); + if (inputTimeout != tmpNum){ + DEVEL_MSG("Setting input timeout from %" PRIu64 " to new value of %" PRIu64, inputTimeout, tmpNum); + inputTimeout = tmpNum; + } + //Check if cutTime setting is correct tmpNum = retrieveSetting(streamCfg, "cut"); // if the new value is different, print a message and apply it @@ -594,7 +600,6 @@ namespace Mist{ meta.setMaxKeepAway(tmpNum); } - /*LTS-END*/ return true; }