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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]