You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Replace sleep()/usleep() with std::chrono calls (#473)
This commit is contained in:
@@ -31,6 +31,9 @@
|
||||
#include "../../include/Qt/VideoCacheThread.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include <thread> // for std::this_thread::sleep_for
|
||||
#include <chrono> // for std::chrono::milliseconds
|
||||
|
||||
namespace openshot
|
||||
{
|
||||
// Constructor
|
||||
@@ -81,10 +84,14 @@ namespace openshot
|
||||
// Start the thread
|
||||
void VideoCacheThread::run()
|
||||
{
|
||||
while (!threadShouldExit() && is_playing) {
|
||||
// Types for storing time durations in whole and fractional milliseconds
|
||||
using ms = std::chrono::milliseconds;
|
||||
using double_ms = std::chrono::duration<double, ms::period>;
|
||||
|
||||
// Calculate sleep time for frame rate
|
||||
double frame_time = (1000.0 / reader->info.fps.ToDouble());
|
||||
// Calculate on-screen time for a single frame in milliseconds
|
||||
const auto frame_duration = double_ms(1000.0 / reader->info.fps.ToDouble());
|
||||
|
||||
while (!threadShouldExit() && is_playing) {
|
||||
|
||||
// Cache frames before the other threads need them
|
||||
// Cache frames up to the max frames
|
||||
@@ -117,7 +124,7 @@ namespace openshot
|
||||
}
|
||||
|
||||
// Sleep for 1 frame length
|
||||
usleep(frame_time * 1000);
|
||||
std::this_thread::sleep_for(frame_duration);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user