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

Use correct framerate

parent e664901c
No related branches found
No related tags found
1 merge request!17Implements #49 RGBD Streamer
Pipeline #11107 passed
...@@ -49,7 +49,7 @@ class Streamer : public ftl::Configurable { ...@@ -49,7 +49,7 @@ class Streamer : public ftl::Configurable {
void remove(RGBDSource *); void remove(RGBDSource *);
void remove(const std::string &); void remove(const std::string &);
void run(); void run(bool block=false);
void stop(); void stop();
RGBDSource *get(const std::string &uri); RGBDSource *get(const std::string &uri);
......
...@@ -83,7 +83,7 @@ void Streamer::add(RGBDSource *src) { ...@@ -83,7 +83,7 @@ void Streamer::add(RGBDSource *src) {
sources_[src->getURI()] = s; sources_[src->getURI()] = s;
} }
void Streamer::_addClient(const string &source, int N, int rate, const UUID &peer, const string &dest) { void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID &peer, const string &dest) {
shared_lock<shared_mutex> slk(mutex_); shared_lock<shared_mutex> slk(mutex_);
if (sources_.find(source) == sources_.end()) return; if (sources_.find(source) == sources_.end()) return;
...@@ -113,20 +113,38 @@ void Streamer::stop() { ...@@ -113,20 +113,38 @@ void Streamer::stop() {
active_ = false; active_ = false;
} }
void Streamer::run() { void Streamer::run(bool block) {
active_ = true; active_ = true;
if (block) {
while (active_) {
double wait = 1.0f / 25.0f;
auto start = std::chrono::high_resolution_clock::now();
// Create frame jobs at correct FPS interval
_schedule();
std::chrono::duration<double> elapsed =
std::chrono::high_resolution_clock::now() - start;
sleep_for(milliseconds((long long)((wait - elapsed.count()) * 1000.0f)));
}
} else {
// Create thread job for frame ticking // Create thread job for frame ticking
pool_.push([this](int id) { pool_.push([this](int id) {
while (active_) { while (active_) {
double wait = 1.0f / 25.0f;
auto start = std::chrono::high_resolution_clock::now();
// Create frame jobs at correct FPS interval // Create frame jobs at correct FPS interval
_schedule(); _schedule();
// TODO Proper time control std::chrono::duration<double> elapsed =
sleep_for(milliseconds(40)); std::chrono::high_resolution_clock::now() - start;
sleep_for(milliseconds((long long)((wait - elapsed.count()) * 1000.0f)));
} }
}); });
} }
}
void Streamer::_swap(StreamSource &src) { void Streamer::_swap(StreamSource &src) {
if (src.state == (ftl::rgbd::detail::kGrabbed | ftl::rgbd::detail::kTransmitted)) { if (src.state == (ftl::rgbd::detail::kGrabbed | ftl::rgbd::detail::kTransmitted)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment