[Spice-devel] [spice-gtk v1 07/11] channel-display: add display_stream_stats_save() helper

Victor Toso victortoso at redhat.com
Tue Mar 13 11:25:38 UTC 2018


From: Victor Toso <me at victortoso.com>

To factor out code from display_handle_stream_data() that are specific
to statistics in display_stream and not on handling stream_data
itself.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/channel-display.c | 64 +++++++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 27 deletions(-)

diff --git a/src/channel-display.c b/src/channel-display.c
index 2ee761e..f140d7b 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -1485,6 +1485,42 @@ static void display_session_mm_time_reset_cb(SpiceSession *session, gpointer dat
 
 #define STREAM_PLAYBACK_SYNC_DROP_SEQ_LEN_LIMIT 5
 
+static void display_stream_stats_save(display_stream *st,
+                                      guint32 server_mmtime,
+                                      guint32 client_mmtime)
+{
+    gint32 latency = server_mmtime - client_mmtime;
+
+    if (!st->num_input_frames) {
+        st->first_frame_mm_time = server_mmtime;
+    }
+    st->num_input_frames++;
+
+    if (latency < 0) {
+        CHANNEL_DEBUG(st->channel, "stream data too late by %u ms (ts: %u, mmtime: %u), dropping",
+                      client_mmtime - server_mmtime, server_mmtime, client_mmtime);
+        st->arrive_late_time += client_mmtime - server_mmtime;
+        st->arrive_late_count++;
+
+        if (!st->cur_drops_seq_stats.len) {
+            st->cur_drops_seq_stats.start_mm_time = server_mmtime;
+        }
+        st->cur_drops_seq_stats.len++;
+        st->playback_sync_drops_seq_len++;
+        return;
+    }
+
+    CHANNEL_DEBUG(st->channel, "video latency: %d", latency);
+    if (st->cur_drops_seq_stats.len) {
+        st->cur_drops_seq_stats.duration = server_mmtime -
+                                           st->cur_drops_seq_stats.start_mm_time;
+        g_array_append_val(st->drops_seqs_stats_arr, st->cur_drops_seq_stats);
+        memset(&st->cur_drops_seq_stats, 0, sizeof(st->cur_drops_seq_stats));
+        st->num_drops_seqs++;
+    }
+    st->playback_sync_drops_seq_len = 0;
+}
+
 static SpiceFrame *spice_frame_new(display_stream *st,
                                    SpiceMsgIn *in,
                                    guint32 server_mmtime)
@@ -1539,34 +1575,8 @@ static void display_handle_stream_data(SpiceChannel *channel, SpiceMsgIn *in)
         op->multi_media_time = mmtime + 100; /* workaround... */
     }
 
-    if (!st->num_input_frames) {
-        st->first_frame_mm_time = op->multi_media_time;
-    }
-    st->num_input_frames++;
-
     latency = op->multi_media_time - mmtime;
-    if (latency < 0) {
-        CHANNEL_DEBUG(channel, "stream data too late by %u ms (ts: %u, mmtime: %u), dropping",
-                      mmtime - op->multi_media_time, op->multi_media_time, mmtime);
-        st->arrive_late_time += mmtime - op->multi_media_time;
-        st->arrive_late_count++;
-
-        if (!st->cur_drops_seq_stats.len) {
-            st->cur_drops_seq_stats.start_mm_time = op->multi_media_time;
-        }
-        st->cur_drops_seq_stats.len++;
-        st->playback_sync_drops_seq_len++;
-    } else {
-        CHANNEL_DEBUG(channel, "video latency: %d", latency);
-        if (st->cur_drops_seq_stats.len) {
-            st->cur_drops_seq_stats.duration = op->multi_media_time -
-                                               st->cur_drops_seq_stats.start_mm_time;
-            g_array_append_val(st->drops_seqs_stats_arr, st->cur_drops_seq_stats);
-            memset(&st->cur_drops_seq_stats, 0, sizeof(st->cur_drops_seq_stats));
-            st->num_drops_seqs++;
-        }
-        st->playback_sync_drops_seq_len = 0;
-    }
+    display_stream_stats_save(st, op->multi_media_time, mmtime);
 
     /* Let the video decoder queue the frames so it can optimize their
      * decoding and best decide if/when to drop them when they are late,
-- 
2.16.2



More information about the Spice-devel mailing list