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:
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)
: VideoGenerator::VideoGenerator()
......@@ -85,6 +86,7 @@ VideoMixer::VideoMixer(const std::string& id)
if (videoLocal_)
videoLocal_->attach(this);
loop_.start();
nextProcess_ = std::chrono::steady_clock::now();
}
VideoMixer::~VideoMixer()
......@@ -193,12 +195,10 @@ VideoMixer::update(Observable<std::shared_ptr<MediaFrame>>* ob,
void
VideoMixer::process()
{
const auto now = std::chrono::system_clock::now();
const auto diff = now - lastProcess_;
const auto delay = FRAME_DURATION - diff;
nextProcess_ += std::chrono::duration_cast<std::chrono::microseconds>(FRAME_DURATION);
const auto delay = nextProcess_ - std::chrono::steady_clock::now();
if (delay.count() > 0)
std::this_thread::sleep_for(delay);
lastProcess_ = now;
VideoFrame& output = getNewFrame();
try {
......
......@@ -105,7 +105,7 @@ private:
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_;
VideoScaler scaler_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment