Skip to content
Snippets Groups Projects
Commit 8250a249 authored by Pierre Lespagnol's avatar Pierre Lespagnol
Browse files

video/mixer: fix video mixer framerate

Change-Id: I1a2ccda21fe5f6a70423d3f9973890637cac5de0
parent aa4f3abd
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,8 @@ private: ...@@ -72,7 +72,8 @@ private:
std::mutex mutex_; std::mutex mutex_;
}; };
static constexpr const auto FRAME_DURATION = std::chrono::duration<double>(1 / 30.); static constexpr const auto MIXER_FRAMERATE = 30;
static constexpr const auto FRAME_DURATION = std::chrono::duration<double>(1. / MIXER_FRAMERATE);
VideoMixer::VideoMixer(const std::string& id) VideoMixer::VideoMixer(const std::string& id)
: VideoGenerator::VideoGenerator() : VideoGenerator::VideoGenerator()
...@@ -85,6 +86,7 @@ VideoMixer::VideoMixer(const std::string& id) ...@@ -85,6 +86,7 @@ VideoMixer::VideoMixer(const std::string& id)
if (videoLocal_) if (videoLocal_)
videoLocal_->attach(this); videoLocal_->attach(this);
loop_.start(); loop_.start();
nextProcess_ = std::chrono::steady_clock::now();
} }
VideoMixer::~VideoMixer() VideoMixer::~VideoMixer()
...@@ -193,12 +195,10 @@ VideoMixer::update(Observable<std::shared_ptr<MediaFrame>>* ob, ...@@ -193,12 +195,10 @@ VideoMixer::update(Observable<std::shared_ptr<MediaFrame>>* ob,
void void
VideoMixer::process() VideoMixer::process()
{ {
const auto now = std::chrono::system_clock::now(); nextProcess_ += std::chrono::duration_cast<std::chrono::microseconds>(FRAME_DURATION);
const auto diff = now - lastProcess_; const auto delay = nextProcess_ - std::chrono::steady_clock::now();
const auto delay = FRAME_DURATION - diff;
if (delay.count() > 0) if (delay.count() > 0)
std::this_thread::sleep_for(delay); std::this_thread::sleep_for(delay);
lastProcess_ = now;
VideoFrame& output = getNewFrame(); VideoFrame& output = getNewFrame();
try { try {
......
...@@ -105,7 +105,7 @@ private: ...@@ -105,7 +105,7 @@ private:
std::shared_ptr<SinkClient> sink_; std::shared_ptr<SinkClient> sink_;
std::chrono::time_point<std::chrono::system_clock> lastProcess_; std::chrono::time_point<std::chrono::steady_clock> nextProcess_;
std::shared_ptr<VideoFrameActiveWriter> videoLocal_; std::shared_ptr<VideoFrameActiveWriter> videoLocal_;
VideoScaler scaler_; VideoScaler scaler_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment