From 8c3b8d96668316be46f048b6c8426deeb50052c0 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 17 Jan 2018 11:28:04 +0100 Subject: [PATCH] Added timeout support to analysers in validate mode --- src/analysers/analyser.cpp | 28 +++++++++++++++++++++++++++- src/analysers/analyser.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/analysers/analyser.cpp b/src/analysers/analyser.cpp index 86c10a02..5c07ea59 100644 --- a/src/analysers/analyser.cpp +++ b/src/analysers/analyser.cpp @@ -6,6 +6,7 @@ Analyser::Analyser(Util::Config &conf){ validate = conf.getBool("validate"); detail = conf.getInteger("detail"); + timeOut = conf.getInteger("timeout"); mediaTime = 0; upTime = Util::bootSecs(); isActive = &conf.is_active; @@ -61,9 +62,26 @@ int Analyser::run(Util::Config &conf){ } if (validate){ finTime = Util::bootSecs(); + + //slow down to realtime + 10s + if (validate && ((finTime - upTime + 10) * 1000 < mediaTime)){ + uint32_t sleepMs = mediaTime - (Util::bootSecs() - upTime + 10) * 1000; + if ((finTime - upTime + sleepMs / 1000) >= timeOut){ + WARN_MSG("Reached timeout of %llu seconds, stopping", timeOut); + return 3; + } + INFO_MSG("Sleeping for %lums", sleepMs); + Util::sleep(sleepMs); + finTime = Util::bootSecs(); + } + if ((finTime - upTime) > (mediaTime / 1000) + 2){ FAIL_MSG("Media time more than 2 seconds behind!"); - return 1; + return 4; + } + if ((finTime - upTime) >= timeOut){ + WARN_MSG("Reached timeout of %llu seconds, stopping", timeOut); + return 3; } } } @@ -88,6 +106,14 @@ void Analyser::init(Util::Config &conf){ conf.addOption("validate", opt); opt.null(); + opt["long"] = "timeout"; + opt["short"] = "T"; + opt["arg"] = "num"; + opt["default"] = 0ll; + opt["help"] = "Time out after X seconds of processing/retrieving"; + conf.addOption("timeout", opt); + opt.null(); + opt["long"] = "detail"; opt["short"] = "D"; opt["arg"] = "num"; diff --git a/src/analysers/analyser.h b/src/analysers/analyser.h index a60b2b2e..59b9bf27 100644 --- a/src/analysers/analyser.h +++ b/src/analysers/analyser.h @@ -31,6 +31,7 @@ public: protected: // These hold the current state and/or config bool validate; ///< True of validation mode is enabled + uint64_t timeOut; ///< After how many seconds a timeout should trigger int detail; ///< Detail level of analyser uint64_t mediaTime; ///< Timestamp in ms of last media packet received uint64_t upTime; ///< Unix time of analyser start