diff --git a/applications/gui2/src/main.cpp b/applications/gui2/src/main.cpp index 7d422d98d3a8a455b835040d2225d8bc132e4d1f..85d6c38d3b152c7a1871478925e5417c5bfb5121 100644 --- a/applications/gui2/src/main.cpp +++ b/applications/gui2/src/main.cpp @@ -155,6 +155,9 @@ int main(int argc, char **argv) { Pylon::PylonAutoInitTerm autoInitTerm; #endif + // Note: This causes 100% CPU use but prevents the random frame drops. + ftl::timer::setHighPrecision(true); + { nanogui::init(); diff --git a/components/common/cpp/src/timer.cpp b/components/common/cpp/src/timer.cpp index 0121c046ddb9918bf20adbfc4426707b03abdbd2..890f7dc839a17e848f5392146072d180f2067afd 100644 --- a/components/common/cpp/src/timer.cpp +++ b/components/common/cpp/src/timer.cpp @@ -89,6 +89,30 @@ static void waitTimePoint() { } } + /*while (msdelay >= 10 && sincelast != mspf) { + sleep_for(milliseconds(5)); + now = get_time(); + msdelay = mspf - (now % mspf); + }*/ + + if (msdelay >= 2 && sincelast != mspf) { + UNIQUE_LOCK(mtx, lk); + auto idle_job = jobs[kTimerIdle1].begin(); + while (idle_job != jobs[kTimerIdle1].end() && msdelay >= 2 && sincelast != mspf) { + (*idle_job).active = true; + bool doremove = !(*idle_job).job.trigger(now); + + if (doremove) { + idle_job = jobs[kTimerIdle1].erase(idle_job); + LOG(INFO) << "Timer job removed"; + } else { + (*idle_job++).active = false; + } + now = get_time(); + msdelay = mspf - (now % mspf); + } + } + if (hprec_) { // Spin loop until exact grab time // Accurate to around 4 micro seconds. @@ -194,12 +218,20 @@ static void trigger_jobs() { auto *pj = &j; - ftl::pool.push([pj,ts](int id) { + // If last job in list then do in this thread + if (active_jobs == jobs[kTimerMain].size()+1) { bool doremove = !pj->job.trigger(ts); pj->active = false; active_jobs--; if (doremove) removeJob(pj->id); - }); + } else { + ftl::pool.push([pj,ts](int id) { + bool doremove = !pj->job.trigger(ts); + pj->active = false; + active_jobs--; + if (doremove) removeJob(pj->id); + }); + } } // Final cleanup of stale jobs diff --git a/components/rgbd-sources/include/ftl/rgbd/source.hpp b/components/rgbd-sources/include/ftl/rgbd/source.hpp index 7773756f2434c56c2ce18a0fb211ffd477145040..c7cc7d574d833f1ed5a7cc80926265a223c68301 100644 --- a/components/rgbd-sources/include/ftl/rgbd/source.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/source.hpp @@ -92,7 +92,7 @@ class Source : public ftl::Configurable, public ftl::data::DiscreteSource { BaseSourceImpl *impl_; SHARED_MUTEX mutex_; cudaStream_t stream_; - bool is_retrieving; + std::atomic_bool is_retrieving; void _swap(); }; diff --git a/components/streams/src/builder.cpp b/components/streams/src/builder.cpp index 8d2e60f8bea38a7d1cb318ba8bb1b21974d7d3cf..72dd73c5ad37b87a7bb71697c2c12871ab8bc8b2 100644 --- a/components/streams/src/builder.cpp +++ b/components/streams/src/builder.cpp @@ -138,7 +138,7 @@ void IntervalSourceBuilder::start() { // TODO: Do in parallel... for (auto *s : srcs_) { if (!s->retrieve(fs->firstFrame())) { - LOG(WARNING) << "Frame was skipping"; + LOG(WARNING) << "Frame is being skipped: " << ts; } }