diff --git a/components/common/cpp/include/ftl/configuration.hpp b/components/common/cpp/include/ftl/configuration.hpp index 7ad81440b1abdcd4d4d2d6cf4a68d7be55be7c1c..5b0106fe0dbc15e8cb3cefbbb7b08630d52d5098 100644 --- a/components/common/cpp/include/ftl/configuration.hpp +++ b/components/common/cpp/include/ftl/configuration.hpp @@ -79,6 +79,11 @@ json_t &resolveWait(const std::string &); */ Configurable *find(const std::string &uri); +/** + * Add an alternative URI for a configurable. + */ +void alias(const std::string &uri, Configurable *cfg); + /** * Get all configurables that contain a specified tag. Tags are given under the * "tags" property as an array of strings, but only during configurable diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp index 5e7bd0ea23122034eefbb71292318ac105f63bf5..9c1154d6e63e88c80197b12b6d681b0a29c7ac30 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -238,6 +238,7 @@ static bool mergeConfig(const string path) { static std::map<std::string, json_t*> config_index; static std::map<std::string, ftl::Configurable*> config_instance; +static std::map<std::string, ftl::Configurable*> config_alias; static std::map<std::string, std::vector<ftl::Configurable*>> tag_index; /* @@ -269,10 +270,18 @@ ftl::Configurable *ftl::config::find(const std::string &uri) { } auto ix = config_instance.find(actual_uri); - if (ix == config_instance.end()) return nullptr; + if (ix == config_instance.end()) { + auto ix = config_alias.find(actual_uri); + if (ix == config_instance.end()) return nullptr; + else return (*ix).second; + } else return (*ix).second; } +void ftl::config::alias(const std::string &uri, Configurable *cfg) { + config_alias[uri] = cfg; +} + const std::vector<Configurable*> &ftl::config::findByTag(const std::string &tag) { return tag_index[tag]; } diff --git a/components/rgbd-sources/src/sources/stereovideo/rectification.cpp b/components/rgbd-sources/src/sources/stereovideo/rectification.cpp index 78c935eccef49bda930e445739dc5abdedae8478..a514c54f170f535fe67d85de1a3dc3dae7a7a3d7 100644 --- a/components/rgbd-sources/src/sources/stereovideo/rectification.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/rectification.cpp @@ -181,6 +181,7 @@ double StereoRectification::baseline() { } double StereoRectification::doff() { + if (!enabled_ || !valid_) return 0.0; return -(Q_.at<double>(3,3) * baseline_); } diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index 815e426577533abf3ee83ca4c96e62ba72c77005..5416b167f5f6e700bebebab564332f0e87348cbb 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -172,6 +172,8 @@ void StereoVideoSource::updateParameters(ftl::rgbd::Frame &frame) { calibration_change_ = frame.onChange(Channel::CalibrationData, [this] (ftl::data::Frame& frame, ftl::codecs::Channel) { + if (!lsrc_->isStereo()) return true; + auto &change = frame.get<ftl::calibration::CalibrationData>(Channel::CalibrationData); try { change.writeFile(fname_calib_); diff --git a/components/streams/src/netstream.cpp b/components/streams/src/netstream.cpp index 105152c140813dcb0ae2432bc259281f4ce640d2..73c758f49bd463dcf0f9877b64d098478fc0d4d5 100644 --- a/components/streams/src/netstream.cpp +++ b/components/streams/src/netstream.cpp @@ -3,6 +3,11 @@ #define LOGURU_REPLACE_GLOG 1 #include <loguru.hpp> +#ifndef WIN32 +#include <unistd.h> +#include <limits.h> +#endif + using ftl::stream::Net; using ftl::codecs::StreamPacket; using ftl::codecs::Packet; @@ -229,6 +234,24 @@ bool Net::begin() { // TODO: Register URI as available. host_ = true; + // Alias the URI to the configurable if not already + // Allows the URI to be used to get config data. + if (ftl::config::find(uri_) == nullptr) { + ftl::config::alias(uri_, this); + } + + // Automatically set name if missing + if (!get<std::string>("name")) { + char hostname[1024] = {0}; + #ifdef WIN32 + GetComputerName(hostname, 1024); + #else + gethostname(hostname, 1024); + #endif + + set("name", std::string(hostname)); + } + net_->broadcast("add_stream", uri_); return true;