Improved time management for software framerate limiter.

This commit is contained in:
brunoherbelin
2021-01-27 09:35:46 +01:00
parent 29c40036b2
commit 9b795a0df7
2 changed files with 9 additions and 4 deletions

View File

@@ -188,7 +188,7 @@ void Mixer::update()
update_time_ = gst_util_get_timestamp (); update_time_ = gst_util_get_timestamp ();
guint64 current_time = gst_util_get_timestamp (); guint64 current_time = gst_util_get_timestamp ();
// dt is in milisecond, with fractional precision (from micro seconds) // dt is in milisecond, with fractional precision (from micro seconds)
dt_ = static_cast<float>( GST_TIME_AS_USECONDS(current_time - update_time_) * 0.001f); dt_ = static_cast<float>( GST_TIME_AS_USECONDS(current_time - update_time_) ) * 0.001f;
update_time_ = current_time; update_time_ = current_time;
// update session and associated sources // update session and associated sources

View File

@@ -229,6 +229,8 @@ void Rendering::pushBackDrawCallback(RenderingCallback function)
void Rendering::draw() void Rendering::draw()
{ {
// guint64 _time = gst_util_get_timestamp ();
// operate on main window context // operate on main window context
main_.makeCurrent(); main_.makeCurrent();
@@ -275,10 +277,13 @@ void Rendering::draw()
// software framerate limiter 60FPS if not v-sync // software framerate limiter 60FPS if not v-sync
if ( Settings::application.render.vsync < 1 ) { if ( Settings::application.render.vsync < 1 ) {
int dt = 18000 - int( 1000.f * Mixer::manager().dt() ); static GTimer *timer = g_timer_new ();
if (dt > 100) double elapsed = g_timer_elapsed (timer, NULL) * 1000000.0;
g_usleep( dt ); if (elapsed < 16000)
g_usleep( 16000 - (gulong)elapsed );
g_timer_start(timer);
} }
} }