diff --git a/components/rgbd-sources/src/net_source.cpp b/components/rgbd-sources/src/net_source.cpp index 5084063f96d39c123fdd4be5d20ffc06d9a2257a..9777306a1bca92f44d4e361450984027843af5ff 100644 --- a/components/rgbd-sources/src/net_source.cpp +++ b/components/rgbd-sources/src/net_source.cpp @@ -15,23 +15,28 @@ using std::this_thread::sleep_for; using std::chrono::milliseconds; bool NetSource::_getCalibration(Universe &net, const UUID &peer, const string &src, ftl::rgbd::CameraParameters &p) { - while(true) { - auto buf = net.call<vector<unsigned char>>(peer_, "source_calibration", src); - if (buf.size() > 0) { - memcpy((char*)&p, buf.data(), buf.size()); - - if (sizeof(p) != buf.size()) { - LOG(ERROR) << "Corrupted calibration"; - return false; + try { + while(true) { + auto buf = net.call<vector<unsigned char>>(peer_, "source_calibration", src); + + if (buf.size() > 0) { + memcpy((char*)&p, buf.data(), buf.size()); + + if (sizeof(p) != buf.size()) { + LOG(ERROR) << "Corrupted calibration"; + return false; + } + + LOG(INFO) << "Calibration received: " << p.cx << ", " << p.cy << ", " << p.fx << ", " << p.fy; + + return true; + } else { + LOG(INFO) << "Could not get calibration, retrying"; + sleep_for(milliseconds(500)); } - - LOG(INFO) << "Calibration received: " << p.cx << ", " << p.cy << ", " << p.fx << ", " << p.fy; - - return true; - } else { - LOG(INFO) << "Could not get calibration, retrying"; - sleep_for(milliseconds(500)); } + } catch (...) { + return false; } } @@ -59,7 +64,11 @@ NetSource::NetSource(nlohmann::json &config, ftl::net::Universe *net) N_ = 10; // Initiate stream with request for first 10 frames - net->send(peer_, "get_stream", getURI(), 10, 0, net->id(), getURI()); + try { + net->send(peer_, "get_stream", getURI(), 10, 0, net->id(), getURI()); + } catch(...) { + LOG(ERROR) << "Could not connect to stream " << getURI(); + } } NetSource::~NetSource() { @@ -81,7 +90,11 @@ void NetSource::_recv(const vector<unsigned char> &jpg, const vector<unsigned ch void NetSource::setPose(const Eigen::Matrix4f &pose) { vector<unsigned char> vec((unsigned char*)pose.data(), (unsigned char*)(pose.data()+(pose.size()))); - net_->send(peer_, "set_pose", getURI(), vec); + try { + net_->send(peer_, "set_pose", getURI(), vec); + } catch (...) { + + } RGBDSource::setPose(pose); } diff --git a/components/rgbd-sources/src/rgbd_streamer.cpp b/components/rgbd-sources/src/rgbd_streamer.cpp index ad4e700c0d4c0b2b3d6c4fa33b65b718e998a92c..583c6f199d808d4b37cd78a97079e2d5315aa9f1 100644 --- a/components/rgbd-sources/src/rgbd_streamer.cpp +++ b/components/rgbd-sources/src/rgbd_streamer.cpp @@ -30,8 +30,10 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) net_ = net; net->bind("find_stream", [this](const std::string &uri) -> optional<UUID> { - if (sources_.find(uri) != sources_.end()) return net_->id(); - else return {}; + if (sources_.find(uri) != sources_.end()) { + LOG(INFO) << "Valid source request received: " << uri; + return net_->id(); + } else return {}; }); net->bind("list_streams", [this]() -> vector<string> { @@ -91,6 +93,8 @@ void Streamer::add(RGBDSource *src) { s->src = src; s->state = 0; sources_[src->getURI()] = s; + + LOG(INFO) << "Added source: " << src->getURI(); } void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID &peer, const string &dest) {