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

Submitted by Francois Gouget on June 8, 2015, 4:50 p.m.

Details

Message ID alpine.DEB.2.11.1506081849400.31098@amboise
State New
Headers show

Not browsing as part of any series.

Commit Message

Francois Gouget June 8, 2015, 4:50 p.m.
This is more accurate for typical values like 23.976 fps.
---
 server/red_worker.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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;