Skip to content
Snippets Groups Projects
Commit dcbb0430 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Debug info and lock in net code

parent e68bb830
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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_;
};
......
#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;
......
......@@ -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 {
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment