diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d5a06e1091b155dc1c393de696bbca07dd65453..8a86df76fa91ab3a70939b2b952ff14e5ca2e69d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ include(ftl_paths) if (WIN32) # TODO(nick) Should do based upon compiler (VS) add_definitions(-DWIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17") - set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -Wall") + set(CMAKE_CXX_FLAGS_DEBUG "-DFTL_DEBUG -Wall") set(CMAKE_CXX_FLAGS_RELEASE "/O2") else() add_definitions(-DUNIX) diff --git a/net/cpp/include/ftl/net/universe.hpp b/net/cpp/include/ftl/net/universe.hpp index 81f2a6f269bd2c1164e01f91fa4b2972158fcdfd..59eb49a276ca95cb08d735ff5c238c0205e2c532 100644 --- a/net/cpp/include/ftl/net/universe.hpp +++ b/net/cpp/include/ftl/net/universe.hpp @@ -13,6 +13,7 @@ #include <vector> #include <string> #include <thread> +#include <mutex> #include <map> namespace ftl { @@ -148,6 +149,7 @@ class Universe { std::map<ftl::UUID, ftl::net::Peer*> peer_ids_; ftl::UUID id_; ftl::net::Dispatcher disp_; + std::mutex net_mutex_; // std::map<std::string, std::vector<ftl::net::Peer*>> subscriptions_; }; diff --git a/net/cpp/src/universe.cpp b/net/cpp/src/universe.cpp index 066e7514d1e699a19895dcb61723a16e654ef52c..f6d7e2acba34e6fde82b07a6db7064555512c303 100644 --- a/net/cpp/src/universe.cpp +++ b/net/cpp/src/universe.cpp @@ -1,4 +1,5 @@ #include <ftl/net/universe.hpp> +#include <chrono> #ifdef WIN32 #include <Ws2tcpip.h> @@ -14,6 +15,8 @@ using ftl::net::Universe; using nlohmann::json; using ftl::UUID; using std::optional; +using std::unique_lock; +using std::mutex; Universe::Universe() : active_(true), thread_(Universe::__start, this) { _installBindings(); @@ -58,6 +61,7 @@ Universe::~Universe() { bool Universe::listen(const string &addr) { auto l = new Listener(addr.c_str()); if (!l) return false; + unique_lock<mutex> lk(net_mutex_); listeners_.push_back(l); return l->isListening(); } @@ -67,6 +71,7 @@ bool Universe::connect(const string &addr) { if (!p) return false; if (p->status() != Peer::kInvalid) { + unique_lock<mutex> lk(net_mutex_); peers_.push_back(p); } @@ -86,6 +91,8 @@ int Universe::_setDescriptors() { int n = 0; + unique_lock<mutex> lk(net_mutex_); + //Set file descriptor for the listening sockets. for (auto l : listeners_) { if (l != nullptr && l->isListening()) { @@ -200,6 +207,11 @@ void Universe::_run() { int n = _setDescriptors(); int selres = 1; + if (n == 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(300)); + continue; + } + //Wait for a network event or timeout in 3 seconds block.tv_sec = 0; block.tv_usec = 10000; diff --git a/vision/src/local.cpp b/vision/src/local.cpp index d0e542669df9e2e6faba2ba0268fb53b7d99183a..d8d5229e84ccb39b7639a914941185c423b36a27 100644 --- a/vision/src/local.cpp +++ b/vision/src/local.cpp @@ -29,8 +29,14 @@ LocalSource::LocalSource(nlohmann::json &config) flip_v_(config["flip_vert"]), nostereo_(config["nostereo"]), downsize_(config.value("scale", 1.0f)) { + // Use cameras - camera_a_ = new VideoCapture((flip_) ? 1 : 0); + camera_a_ = new VideoCapture; + LOG(INFO) << "Cameras check... "; + camera_a_->open((flip_) ? 1 : 0); + + LOG(INFO) << "Cameras open? " << flip_; + if (!nostereo_) { camera_b_ = new VideoCapture((flip_) ? 0 : 1); } else { diff --git a/vision/src/main.cpp b/vision/src/main.cpp index fbfcae64968049a0ecfd88756d88c40a85624546..0665b797cdb017c09dbafdfcf5f0dd9011f5ead4 100644 --- a/vision/src/main.cpp +++ b/vision/src/main.cpp @@ -61,32 +61,40 @@ static void run(const string &file) { ctpl::thread_pool pool(2); Universe net(config["net"]); + LOG(INFO) << "Net started."; + LocalSource *lsrc; if (ftl::is_video(file)) { // Load video file + LOG(INFO) << "Using video file..."; lsrc = new LocalSource(file, config["source"]); } else if (file != "") { auto vid = ftl::locateFile("video.mp4"); if (!vid) { LOG(FATAL) << "No video.mp4 file found in provided paths"; } else { + LOG(INFO) << "Using test directory..."; lsrc = new LocalSource(*vid, config["source"]); } } else { // Use cameras + LOG(INFO) << "Using cameras..."; lsrc = new LocalSource(config["source"]); } - auto sync = new SyncSource(); // TODO(nick) Pass protocol object + //auto sync = new SyncSource(); // TODO(nick) Pass protocol object // Add any remote channels /* for (auto c : OPTION_channels) { sync->addChannel(c); } */ + LOG(INFO) << "Locating calibration..."; + // Perform or load calibration intrinsics + extrinsics Calibrate calibrate(lsrc, config["calibration"]); if (config["calibrate"]) calibrate.recalibrate(); if (!calibrate.isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!"; + else LOG(INFO) << "Calibration initiated."; cv::Mat Q_32F; calibrate.getQ().convertTo(Q_32F, CV_32F); @@ -115,6 +123,8 @@ static void run(const string &file) { Streamer stream(net, config["stream"]); + LOG(INFO) << "Beginning capture..."; + while (display.active()) { mutex m; condition_variable cv; @@ -134,7 +144,9 @@ static void run(const string &file) { //sync->get(ftl::LEFT, l); //sync->get(ftl::RIGHT, r); + LOG(INFO) << "PRE DISPARITY"; disparity->compute(l, r, disp); + LOG(INFO) << "POST DISPARITY"; unique_lock<mutex> lk(m); jobs++; @@ -218,6 +230,8 @@ static void run(const string &file) { //net.publish(uri, rgb_buf, d_buf); } + + LOG(INFO) << "Finished."; } int main(int argc, char **argv) {