Added Video framerate limiter
Will fix cinematics and videos when readed over their framerate
This commit is contained in:
@@ -278,14 +278,32 @@ void Codec::Decode() {
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point last_frame_time = std::chrono::steady_clock::now();
|
||||
std::chrono::microseconds min_call_interval = std::chrono::microseconds(1000/Settings::values.video_framerate.GetValue()*1000);
|
||||
AVFramePtr Codec::GetCurrentFrame() {
|
||||
// Sometimes VIC will request more frames than have been decoded.
|
||||
// in this case, return a nullptr and don't overwrite previous frame data
|
||||
if (av_frames.empty()) {
|
||||
return AVFramePtr{nullptr, AVFrameDeleter};
|
||||
}
|
||||
|
||||
AVFramePtr frame = std::move(av_frames.front());
|
||||
av_frames.pop();
|
||||
|
||||
if (Settings::values.use_video_framerate.GetValue()) {
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
std::chrono::microseconds elapsed =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(now - last_frame_time);
|
||||
|
||||
if (elapsed < min_call_interval) {
|
||||
std::this_thread::sleep_for(min_call_interval - elapsed);
|
||||
now = std::chrono::steady_clock::now();
|
||||
elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - last_frame_time);
|
||||
}
|
||||
|
||||
last_frame_time = now;
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user