[Spice-devel] [PATCH spice] server: Round the framerate estimate to the nearest integer.

Francois Gouget fgouget at codeweavers.com
Mon Jun 8 09:50:16 PDT 2015


This is more accurate for typical values like 23.976 fps.
---
 server/red_worker.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index cc0a116..0207977 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -3159,15 +3159,15 @@ static void red_stream_input_fps_timer_cb(void *opaque)
 {
     Stream *stream = opaque;
     uint64_t now = red_now();
-    double duration_sec;
 
     spice_assert(opaque);
     if (now == stream->input_fps_timer_start) {
         spice_warning("timer start and expiry time are equal");
         return;
     }
-    duration_sec = (now - stream->input_fps_timer_start)/(1000.0*1000*1000);
-    stream->input_fps = stream->num_input_frames / duration_sec;
+    /* Round to the nearest integer, for instance 24 for 23.976 */
+    uint64_t duration = now - stream->input_fps_timer_start;
+    stream->input_fps = ((uint64_t)stream->num_input_frames * 1000 * 1000 * 1000 + duration / 2) / duration;
     spice_debug("input-fps=%u", stream->input_fps);
     stream->num_input_frames = 0;
     stream->input_fps_timer_start = now;
-- 
2.1.4


More information about the Spice-devel mailing list