Skip to content

Commit

Permalink
Use render throttling for saving resources and support all streaming …
Browse files Browse the repository at this point in the history
…channels (Deflect, ws)
  • Loading branch information
tribal-tec committed Jun 1, 2018
1 parent 99b2f3a commit 999f0b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
20 changes: 16 additions & 4 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,23 @@ struct Brayns::Impl : public PluginAPI

void render()
{
std::lock_guard<std::mutex> lock{_renderMutex};
{
std::lock_guard<std::mutex> lock{_renderMutex};

_renderTimer.start();
_engine->render();
_renderTimer.stop();
}

_renderTimer.start();
_engine->render();
_renderTimer.stop();
const auto& params = _parametersManager.getApplicationParameters();
const auto fps = params.getImageStreamFPS();
const auto delta = _renderTimer.perSecondSmoothed() - fps;
if (delta > 0)
{
const int64_t targetTime = (1. / fps) * 1000.f;
std::this_thread::sleep_for(std::chrono::milliseconds(
targetTime - _renderTimer.milliseconds()));
}
}

Engine& getEngine() { return *_engine; }
Expand Down
14 changes: 0 additions & 14 deletions plugins/RocketsPlugin/RocketsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ class RocketsPlugin::Impl

_setupWebsocket();
_registerEndpoints();
_timer.start();
}

void _setupWebsocket()
Expand Down Expand Up @@ -633,16 +632,6 @@ class RocketsPlugin::Impl
{
const auto& params =
_parametersManager.getApplicationParameters();
const auto fps = params.getImageStreamFPS();
const auto elapsed = _timer.elapsed() + _leftover;
const auto duration = 1.0 / fps;
if (elapsed < duration)
return;

_leftover = elapsed - duration;
for (; _leftover > duration;)
_leftover -= duration;
_timer.start();

const auto image =
_imageGenerator.createJPEG(_engine->getFrameBuffer(),
Expand Down Expand Up @@ -946,9 +935,6 @@ class RocketsPlugin::Impl

ImageGenerator _imageGenerator;

Timer _timer;
float _leftover{0.f};

std::map<TaskPtr, std::shared_ptr<async::task<void>>> _tasks;
std::mutex _tasksMutex;

Expand Down

0 comments on commit 999f0b0

Please sign in to comment.