diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp index f26e43d59ebfd3283e629e2c690ed03360451508..4be44e5d09e8df6d3eae58f3c216caea34a9d344 100644 --- a/applications/vision/src/main.cpp +++ b/applications/vision/src/main.cpp @@ -58,6 +58,8 @@ using std::chrono::milliseconds; using cv::Mat; using json = nlohmann::json; +static bool quiet = false; + static void run(ftl::Configurable *root) { Universe *net = ftl::create<Universe>(root, "net"); @@ -117,10 +119,8 @@ static void run(ftl::Configurable *root) { auto paths = root->get<vector<string>>("paths"); string file = ""; - //if (paths && (*paths).size() > 0) file = (*paths)[(*paths).size()-1]; for (auto &x : *paths) { - //LOG(INFO) << "PATH - " << x; if (x != "") { ftl::URI uri(x); if (uri.isValid()) { @@ -150,7 +150,7 @@ static void run(ftl::Configurable *root) { ftl::audio::Source *audioSrc = ftl::create<ftl::audio::Source>(root, "audio_test"); - ftl::data::Pool pool(2,5); + ftl::data::Pool pool(root->value("mempool_min", 2),root->value("mempool_max", 5)); auto *creator = new ftl::streams::IntervalSourceBuilder(&pool, 0, {source, audioSrc}); std::shared_ptr<ftl::streams::BaseBuilder> creatorptr(creator); @@ -184,6 +184,11 @@ static void run(ftl::Configurable *root) { float latency = 0.0f; int64_t stats_time = 0; + quiet = root->value("quiet", false); + root->on("quiet", [root](const ftl::config::Event &e) { + quiet = root->value("quiet", false); + }); + auto *pipeline = ftl::config::create<ftl::operators::Graph>(root, "pipeline"); pipeline->append<ftl::operators::DetectAndTrack>("facedetection")->value("enabled", false); pipeline->append<ftl::operators::ArUco>("aruco")->value("enabled", false); @@ -224,7 +229,7 @@ static void run(ftl::Configurable *root) { ++frames; latency += float(ftl::timer::get_time() - fs->timestamp()); - if (--stats_count <= 0) { + if (!quiet && --stats_count <= 0) { latency /= float(frames); int64_t nowtime = ftl::timer::get_time(); stats_time = nowtime - stats_time; @@ -253,18 +258,12 @@ static void run(ftl::Configurable *root) { // Start the timed generation of frames creator->start(); - - // TODO: TEMPORARY - /*ftl::audio::Source *audioSrc = ftl::create<ftl::audio::Source>(root, "audio_test"); - audioSrc->onFrameSet([sender](ftl::audio::FrameSet &fs) { - sender->post(fs); - return true; - }); */ + // Only now start listening for connections net->start(); LOG(INFO) << "Running..."; - ftl::timer::start(true); + ftl::timer::start(true); // Blocks LOG(INFO) << "Stopping..."; ctrl.stop(); @@ -279,7 +278,6 @@ static void run(ftl::Configurable *root) { delete audioSrc; delete outstream; - //delete source; // TODO(Nick) Add ftl::destroy delete net; } @@ -292,11 +290,23 @@ int main(int argc, char **argv) { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); #endif std::cout << "FTL Vision Node " << FTL_VERSION_LONG << std::endl; - auto root = ftl::configure(argc, argv, "vision_default"); - - root->restore("root", { + auto root = ftl::configure(argc, argv, "vision_default", { "uri", - "fps" + "fps", + "time_master", + "time_peer", + "quiet" + }); + + root->value("restart", 0); + + // Allow config controlled restart + root->on("restart", [root](const ftl::config::Event &e) { + auto val = root->get<int>("restart"); + if (val) { + ftl::exit_code = *val; + ftl::running = false; + } }); // Use other GPU if available. diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 79a5b540322a376799c721eb2f987dd3d10a1325..d555d6dc5eecfa9eeb56137d56661f7affc5763d 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -9,6 +9,7 @@ #include <string> #include <vector> #include <optional> +#include <unordered_set> namespace ftl { @@ -38,7 +39,7 @@ std::optional<std::string> locateFile(const std::string &name); std::map<std::string, std::string> read_options(char ***argv, int *argc); -Configurable *configure(int argc, char **argv, const std::string &root); +Configurable *configure(int argc, char **argv, const std::string &root, const std::unordered_set<std::string> &restoreable={}); Configurable *configure(json_t &); diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index 45428962b6cdfaf7a7ebc1e9d3c45d1ddee4ae30..276bad5c6429be3346e0b921cc1fb77e2c98370b 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -836,7 +836,7 @@ template void ftl::config::setJSON<float>(nlohmann::json *config, const std::str template void ftl::config::setJSON<int>(nlohmann::json *config, const std::string &name, int value); template void ftl::config::setJSON<std::string>(nlohmann::json *config, const std::string &name, std::string value); -Configurable *ftl::config::configure(int argc, char **argv, const std::string &root) { +Configurable *ftl::config::configure(int argc, char **argv, const std::string &root, const std::unordered_set<std::string> &restoreable) { loguru::g_preamble_date = false; loguru::g_preamble_uptime = false; loguru::g_preamble_thread = false; @@ -878,6 +878,7 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r //root_config = rootcfg->getConfig(); rootCFG = rootcfg; rootcfg->set("paths", paths); + rootcfg->restore("root", restoreable); process_options(rootcfg, options); if (rootcfg->get<int>("profiler")) {