[Spice-devel] [PATCH spice-gtk 2/3] Drop frames if the backlog is above some limit

Christophe de Dinechin christophe at dinechin.org
Thu Jul 13 14:57:27 UTC 2017


From: Christophe de Dinechin <dinechin at redhat.com>

Experience has shown that if the machine running the guest is overloaded,
it may pile up a lot of backlog in the frames queue. This patch clears
the queue if it exceeds 100 entries. This value is arbitrary. It
corresponds to a few seconds on a highly overloaded machine.

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/channel-display-gst.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index 3cf451b..17c2847 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -498,6 +498,9 @@ static void spice_gst_decoder_destroy(VideoDecoder *video_decoder)
  * 9) display_frame() then frees the SpiceGstFrame, which frees the SpiceFrame
  *    and decompressed frame with it.
  */
+
+SPICE_TWEAK_DEFINE(gst_queue_max_length, 100, "Max length of GStreamer queue");
+
 static gboolean spice_gst_decoder_queue_frame(VideoDecoder *video_decoder,
                                               SpiceFrame *frame, int latency)
 {
@@ -541,6 +544,16 @@ static gboolean spice_gst_decoder_queue_frame(VideoDecoder *video_decoder,
     }
 #endif
 
+    if (SPICE_TWEAK(gst_queue_max_length) &&
+        decoder->decoding_queue->length > SPICE_TWEAK(gst_queue_max_length)) {
+       SpiceGstFrame *gstframe;
+       g_mutex_lock(&decoder->queues_mutex);
+        while ((gstframe = g_queue_pop_head(decoder->decoding_queue)))
+            free_gst_frame(gstframe);
+        g_mutex_unlock(&decoder->queues_mutex);
+        return TRUE;
+    }
+
     /* ref() the frame data for the buffer */
     frame->ref_data(frame->data_opaque);
     GstBuffer *buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS,
-- 
2.11.0 (Apple Git-81)



More information about the Spice-devel mailing list