<div dir="ltr">Hi<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 11, 2015 at 7:39 PM, Francois Gouget <span dir="ltr"><<a href="mailto:fgouget@codeweavers.com" target="_blank">fgouget@codeweavers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Francois Gouget <<a href="mailto:fgouget@codeweavers.com">fgouget@codeweavers.com</a>><br>
---<br>
<br>
This implements Marc-André Lureau's suggestion:<br>
<a href="http://lists.freedesktop.org/archives/spice-devel/2015-June/020202.html" target="_blank">http://lists.freedesktop.org/archives/spice-devel/2015-June/020202.html</a><br>
<br>
And supersedes the input-fps rounding patch.<br>
<a href="http://lists.freedesktop.org/archives/spice-devel/2015-June/020176.html" target="_blank">http://lists.freedesktop.org/archives/spice-devel/2015-June/020176.html</a><br>
<br>
<br>
 server/red_worker.c | 45 +++++++++++++++------------------------------<br>
 1 file changed, 15 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/server/red_worker.c b/server/red_worker.c<br>
index 5deb30b..a07a78a 100644<br>
--- a/server/red_worker.c<br>
+++ b/server/red_worker.c<br>
@@ -120,7 +120,7 @@<br>
 #define RED_STREAM_GRADUAL_FRAMES_START_CONDITION 0.2<br>
 #define RED_STREAM_FRAMES_RESET_CONDITION 100<br>
 #define RED_STREAM_MIN_SIZE (96 * 96)<br>
-#define RED_STREAM_INPUT_FPS_TIMEOUT (5 * 1000) // 5 sec<br>
+#define RED_STREAM_INPUT_FPS_TIMEOUT ((uint64_t)5 * 1000 * 1000 * 1000) // 5 sec<br>
 #define RED_STREAM_CHANNEL_CAPACITY 0.8<br>
 /* the client's stream report frequency is the minimum of the 2 values below */<br>
 #define RED_STREAM_CLIENT_REPORT_WINDOW 5 // #frames<br>
@@ -450,9 +450,8 @@ struct Stream {<br>
     Stream *next;<br>
     RingItem link;<br>
<br>
-    SpiceTimer *input_fps_timer;<br>
     uint32_t num_input_frames;<br>
-    uint64_t input_fps_timer_start;<br>
+    uint64_t input_fps_start_time;<br>
     uint32_t input_fps;<br>
 };<br>
<br>
@@ -2532,9 +2531,6 @@ static int is_same_drawable(RedWorker *worker, Drawable *d1, Drawable *d2)<br>
<br>
 static inline void red_free_stream(RedWorker *worker, Stream *stream)<br>
 {<br>
-    if (stream->input_fps_timer) {<br>
-        spice_timer_remove(stream->input_fps_timer);<br>
-    }<br>
     stream->next = worker->free_streams;<br>
     worker->free_streams = stream;<br>
 }<br>
@@ -2613,7 +2609,17 @@ static void red_attach_stream(RedWorker *worker, Drawable *drawable, Stream *str<br>
     stream->current = drawable;<br>
     drawable->stream = stream;<br>
     stream->last_time = drawable->creation_time;<br>
-    stream->num_input_frames++;<br>
+<br>
+    uint64_t duration = drawable->creation_time - stream->input_fps_start_time;<br>
+    if (duration >= RED_STREAM_INPUT_FPS_TIMEOUT) {<br>
+        /* Round to the nearest integer, for instance 24 for 23.976 */<br>
+        stream->input_fps = ((uint64_t)stream->num_input_frames * 1000 * 1000 * 1000 + duration / 2) / duration;<br>
+        spice_debug("input-fps=%u", stream->input_fps);<br>
+        stream->num_input_frames = 0;<br>
+        stream->input_fps_start_time = drawable->creation_time;<br></blockquote><div><br></div><div>Every time  RED_STREAM_INPUT_FPS_TIMEOUT elpased and a new frame comes, input_fps is updated. <br><br></div><div>Patch looks good to me, I haven't tested it though.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    } else {<br>
+        stream->num_input_frames++;<br>
+    }<br>
<br>
     WORKER_FOREACH_DCC_SAFE(worker, item, next, dcc) {<br>
         StreamAgent *agent;<br>
@@ -3123,24 +3129,6 @@ static void red_display_create_stream(DisplayChannelClient *dcc, Stream *stream)<br>
 #endif<br>
 }<br>
<br>
-static void red_stream_input_fps_timer_cb(void *opaque)<br>
-{<br>
-    Stream *stream = opaque;<br>
-    uint64_t now = red_now();<br>
-    double duration_sec;<br>
-<br>
-    spice_assert(opaque);<br>
-    if (now == stream->input_fps_timer_start) {<br>
-        spice_warning("timer start and expiry time are equal");<br>
-        return;<br>
-    }<br>
-    duration_sec = (now - stream->input_fps_timer_start)/(1000.0*1000*1000);<br>
-    stream->input_fps = stream->num_input_frames / duration_sec;<br>
-    spice_debug("input-fps=%u", stream->input_fps);<br>
-    stream->num_input_frames = 0;<br>
-    stream->input_fps_timer_start = now;<br>
-}<br>
-<br>
 static void red_create_stream(RedWorker *worker, Drawable *drawable)<br>
 {<br>
     DisplayChannelClient *dcc;<br>
@@ -3167,12 +3155,9 @@ static void red_create_stream(RedWorker *worker, Drawable *drawable)<br>
     SpiceBitmap *bitmap = &drawable->red_drawable->u.copy.src_bitmap->u.bitmap;<br>
     stream->top_down = !!(bitmap->flags & SPICE_BITMAP_FLAGS_TOP_DOWN);<br>
     drawable->stream = stream;<br>
-    stream->input_fps_timer = spice_timer_queue_add(red_stream_input_fps_timer_cb, stream);<br>
-    spice_assert(stream->input_fps_timer);<br>
-    spice_timer_set(stream->input_fps_timer, RED_STREAM_INPUT_FPS_TIMEOUT);<br>
-    stream->num_input_frames = 0;<br>
-    stream->input_fps_timer_start = red_now();<br>
     stream->input_fps = MAX_FPS;<br>
+    stream->num_input_frames = 0;<br>
+    stream->input_fps_start_time = drawable->creation_time;<br>
     worker->streams_size_total += stream->width * stream->height;<br>
     worker->stream_count++;<br>
     WORKER_FOREACH_DCC_SAFE(worker, dcc_ring_item, next, dcc) {<br>
<span class=""><font color="#888888">--<br>
2.1.4</font></span><br>_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Marc-André Lureau</div>
</div></div></div>