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

Reduce latency on net sources in gui add window

parent f5bd6695
Branches
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
...@@ -29,11 +29,9 @@ AddSourceWindow::AddSourceWindow(nanogui::Widget* parent, AddCtrl *ctrl) : ...@@ -29,11 +29,9 @@ AddSourceWindow::AddSourceWindow(nanogui::Widget* parent, AddCtrl *ctrl) :
rebuild(); rebuild();
new_source_handle_ = ctrl_->feed()->onNewSources([this](int a) { new_source_handle_ = ctrl_->feed()->onNewSources([this](int a) {
LOG(INFO) << "NEW SOURCES";
UNIQUE_LOCK(mutex_, lk); UNIQUE_LOCK(mutex_, lk);
// Note the 1, first widget is the title bar buttons do_rebuild_ = true;
while(childCount() > 1) { removeChild(childCount()-1); }
rebuild();
screen()->performLayout();
return true; return true;
}); });
} }
...@@ -140,6 +138,17 @@ void AddSourceWindow::close() { ...@@ -140,6 +138,17 @@ void AddSourceWindow::close() {
dispose(); dispose();
} }
//void AddSourceWindow::draw(NVGcontext *ctx) { void AddSourceWindow::draw(NVGcontext *ctx) {
{
UNIQUE_LOCK(mutex_, lk);
if (do_rebuild_) {
do_rebuild_ = false;
// Note the 1, first widget is the title bar buttons
while(childCount() > 1) { removeChild(childCount()-1); }
rebuild();
screen()->performLayout();
}
}
//} nanogui::Window::draw(ctx);
}
...@@ -18,7 +18,7 @@ class AddSourceWindow : public nanogui::Window { ...@@ -18,7 +18,7 @@ class AddSourceWindow : public nanogui::Window {
AddSourceWindow(nanogui::Widget *parent, AddCtrl *ctrl); AddSourceWindow(nanogui::Widget *parent, AddCtrl *ctrl);
virtual ~AddSourceWindow(); virtual ~AddSourceWindow();
//virtual void draw(NVGcontext *ctx); virtual void draw(NVGcontext *ctx);
private: private:
AddCtrl *ctrl_; AddCtrl *ctrl_;
...@@ -27,6 +27,7 @@ private: ...@@ -27,6 +27,7 @@ private:
ftl::Handle new_source_handle_; ftl::Handle new_source_handle_;
MUTEX mutex_; MUTEX mutex_;
std::atomic_bool do_rebuild_=false;
public: public:
// EIGEN_MAKE_ALIGNED_OPERATOR_NEW // EIGEN_MAKE_ALIGNED_OPERATOR_NEW
......
...@@ -158,9 +158,9 @@ vector<string> Master::getConfigurables() { ...@@ -158,9 +158,9 @@ vector<string> Master::getConfigurables() {
vector<string> Master::getConfigurables(const ftl::UUID &peer) { vector<string> Master::getConfigurables(const ftl::UUID &peer) {
try { try {
LOG(INFO) << "LISTING CONFIGS";
return net_->call<vector<string>>(peer, "list_configurables"); return net_->call<vector<string>>(peer, "list_configurables");
} catch (...) { } catch (const ftl::exception &e) {
e.ignore();
return {}; return {};
} }
} }
......
...@@ -384,7 +384,7 @@ std::vector<R> Universe::findAll(const std::string &name, ARGS... args) { ...@@ -384,7 +384,7 @@ std::vector<R> Universe::findAll(const std::string &name, ARGS... args) {
{ // Block thread until async callback notifies us { // Block thread until async callback notifies us
//UNIQUE_LOCK(m,llk); //UNIQUE_LOCK(m,llk);
std::unique_lock<std::mutex> llk(m); std::unique_lock<std::mutex> llk(m);
cv.wait_for(llk, std::chrono::seconds(1), [&returncount,&sentcount]{return returncount == sentcount;}); cv.wait_for(llk, std::chrono::seconds(1), [&returncount,sentcount]{return returncount == sentcount;});
// Cancel any further results // Cancel any further results
lk.lock(); lk.lock();
......
...@@ -131,21 +131,29 @@ static SOCKET tcpConnect(URI &uri, size_t ssize, size_t rsize) { ...@@ -131,21 +131,29 @@ static SOCKET tcpConnect(URI &uri, size_t ssize, size_t rsize) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
// FIXME:(Nick) Move to main select thread to prevent blocking // FIXME:(Nick) Move to main select thread to prevent blocking
fd_set myset; fd_set myset;
fd_set errset;
struct timeval tv; struct timeval tv;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; tv.tv_usec = 0;
FD_ZERO(&myset); FD_ZERO(&myset);
FD_SET(csocket, &myset); FD_SET(csocket, &myset);
rc = select(csocket+1u, NULL, &myset, NULL, &tv); FD_ZERO(&errset);
if (rc <= 0) { //} && errno != EINTR) { FD_SET(csocket, &errset);
rc = select(csocket+1u, NULL, &myset, &errset, &tv);
if (rc <= 0 || FD_ISSET(csocket, &errset)) { //} && errno != EINTR) {
if (rc <= 0) {
LOG(ERROR) << "Could not connect to " << uri.getBaseURI();
} else {
LOG(ERROR) << "Could not connect (" << errno << ") " << uri.getBaseURI();
}
#ifndef WIN32 #ifndef WIN32
close(csocket); close(csocket);
#else #else
closesocket(csocket); closesocket(csocket);
#endif #endif
LOG(ERROR) << "Could not connect to " << uri.getBaseURI();
return INVALID_SOCKET; return INVALID_SOCKET;
} }
} else { } else {
...@@ -252,7 +260,7 @@ Peer::Peer(const char *pUri, Universe *u, Dispatcher *d) : can_reconnect_(true), ...@@ -252,7 +260,7 @@ Peer::Peer(const char *pUri, Universe *u, Dispatcher *d) : can_reconnect_(true),
_badClose(false); _badClose(false);
} else { } else {
status_ = kConnecting; status_ = kConnecting;
LOG(INFO) << "WEB SOCK CONNECTED"; LOG(INFO) << "Websocket connected: " << pUri;
} }
} else { } else {
LOG(ERROR) << "Connection refused to " << uri.getHost() << ":" << uri.getPort(); LOG(ERROR) << "Connection refused to " << uri.getHost() << ":" << uri.getPort();
......
...@@ -69,10 +69,17 @@ RealsenseSource::~RealsenseSource() { ...@@ -69,10 +69,17 @@ RealsenseSource::~RealsenseSource() {
} }
static bool rs_supported = false;
static bool rs_init = false;
bool RealsenseSource::supported() { bool RealsenseSource::supported() {
if (rs_init) return rs_supported;
rs_init = true;
rs2::context ctx; rs2::context ctx;
auto devs = ctx.query_devices(); auto devs = ctx.query_devices();
return devs.size() > 0; rs_supported = devs.size() > 0;
return rs_supported;
} }
bool RealsenseSource::capture(int64_t ts) { bool RealsenseSource::capture(int64_t ts) {
......
...@@ -151,9 +151,11 @@ OpenCVDevice::~OpenCVDevice() { ...@@ -151,9 +151,11 @@ OpenCVDevice::~OpenCVDevice() {
} }
static std::vector<ftl::rgbd::detail::DeviceDetails> opencv_devices; static std::vector<ftl::rgbd::detail::DeviceDetails> opencv_devices;
static bool opencv_dev_init = false;
std::vector<ftl::rgbd::detail::DeviceDetails> OpenCVDevice::getDevices() { std::vector<ftl::rgbd::detail::DeviceDetails> OpenCVDevice::getDevices() {
if (opencv_devices.size() > 0) return opencv_devices; if (opencv_dev_init) return opencv_devices;
opencv_dev_init = true;
std::vector<ftl::rgbd::detail::DeviceDetails> devices; std::vector<ftl::rgbd::detail::DeviceDetails> devices;
......
...@@ -114,7 +114,13 @@ PylonDevice::~PylonDevice() { ...@@ -114,7 +114,13 @@ PylonDevice::~PylonDevice() {
} }
static std::vector<ftl::rgbd::detail::DeviceDetails> pylon_devices;
static bool pylon_dev_init = false;
std::vector<ftl::rgbd::detail::DeviceDetails> PylonDevice::listDevices() { std::vector<ftl::rgbd::detail::DeviceDetails> PylonDevice::listDevices() {
if (pylon_dev_init) return pylon_devices;
pylon_dev_init = true;
auto &inst = CTlFactory::GetInstance(); auto &inst = CTlFactory::GetInstance();
Pylon::DeviceInfoList_t devices; Pylon::DeviceInfoList_t devices;
...@@ -132,6 +138,7 @@ std::vector<ftl::rgbd::detail::DeviceDetails> PylonDevice::listDevices() { ...@@ -132,6 +138,7 @@ std::vector<ftl::rgbd::detail::DeviceDetails> PylonDevice::listDevices() {
r.maxwidth = 0; r.maxwidth = 0;
} }
pylon_devices = results;
return results; return results;
} }
......
...@@ -144,13 +144,13 @@ Feed::Feed(nlohmann::json &config, ftl::net::Universe*net) : ...@@ -144,13 +144,13 @@ Feed::Feed(nlohmann::json &config, ftl::net::Universe*net) :
// FIXME: Find better option that waiting here. // FIXME: Find better option that waiting here.
// Wait to make sure streams have started properly. // Wait to make sure streams have started properly.
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
UNIQUE_LOCK(mtx_, lk); //UNIQUE_LOCK(mtx_, lk);
updateNetSources(); updateNetSources();
}); });
}); });
net_->bind("add_stream", [this](std::string uri){ net_->bind("add_stream", [this](std::string uri){
UNIQUE_LOCK(mtx_, lk); //UNIQUE_LOCK(mtx_, lk);
updateNetSources(); updateNetSources();
}); });
...@@ -425,9 +425,12 @@ void Feed::removeFilter(Feed::Filter* filter) { ...@@ -425,9 +425,12 @@ void Feed::removeFilter(Feed::Filter* filter) {
} }
void Feed::updateNetSources() { void Feed::updateNetSources() {
netcams_ = auto netcams =
net_->findAll<std::string>("list_streams"); net_->findAll<std::string>("list_streams");
UNIQUE_LOCK(mtx_, lk);
netcams_ = std::move(netcams);
if (value("auto_host_sources", false)) { if (value("auto_host_sources", false)) {
for (auto s : netcams_) { for (auto s : netcams_) {
ftl::URI uri(s); ftl::URI uri(s);
...@@ -447,7 +450,7 @@ void Feed::updateNetSources() { ...@@ -447,7 +450,7 @@ void Feed::updateNetSources() {
<< stream->value("uri", std::string("NONE")) << stream->value("uri", std::string("NONE"))
<< " (" << fsid << ")"; << " (" << fsid << ")";
cv_net_connect_.notify_one(); //cv_net_connect_.notify_one();
} }
else { else {
LOG(INFO) << "Stream exists: " << s; LOG(INFO) << "Stream exists: " << s;
...@@ -674,7 +677,7 @@ uint32_t Feed::add(const std::string &path) { ...@@ -674,7 +677,7 @@ uint32_t Feed::add(const std::string &path) {
auto &host_details = known_hosts[uri.getBaseURIWithUser()]; auto &host_details = known_hosts[uri.getBaseURIWithUser()];
host_details["last_open"] = ftl::timer::get_time(); host_details["last_open"] = ftl::timer::get_time();
net_->connect(path)->waitConnection(); ftl::pool.push([this,path](int id) { net_->connect(path); });
} }
else if (scheme == ftl::URI::SCHEME_FTL) { else if (scheme == ftl::URI::SCHEME_FTL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment