[Spice-devel] [PATCH spice-server 04/15] Stream: store channel in stream

Jonathon Jongsma jjongsma at redhat.com
Fri Oct 20 21:13:09 UTC 2017


This allows us to unref the stream directly rather than needing to pass
the associated DisplayChannel to stream_unref(). The same is also true
for stream_agent_unref, since the only reason that stream_agent_unref()
required a DisplayChannel parameter was to pass it to stream_unref().
This also resulted in some additional minor redesign due to the fact
that streams are pre-allocated in a pool in the display channel, and
freeing a stream simply means moving it to a different ring to be
re-used.
---
 server/stream.c | 29 +++++++++++++++++------------
 server/stream.h |  7 +++----
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/server/stream.c b/server/stream.c
index 846c921a7..37fb64c81 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -66,8 +66,7 @@ static void stream_agent_stats_print(StreamAgent *agent)
 static void stream_create_destroy_item_release(RedPipeItem *base)
 {
     StreamCreateDestroyItem *item = SPICE_UPCAST(StreamCreateDestroyItem, base);
-    DisplayChannel *display = DCC_TO_DC(item->agent->dcc);
-    stream_agent_unref(display, item->agent);
+    stream_agent_unref(item->agent);
     g_free(item);
 }
 
@@ -122,15 +121,22 @@ void stream_stop(DisplayChannel *display, Stream *stream)
     }
     display->priv->streams_size_total -= stream->width * stream->height;
     ring_remove(&stream->link);
-    stream_unref(display, stream);
+    stream_unref(stream);
 }
 
-static void stream_free(DisplayChannel *display, Stream *stream)
+static void stream_recycle(DisplayChannel *display, Stream *stream)
 {
     stream->next = display->priv->free_streams;
     display->priv->free_streams = stream;
 }
 
+static void stream_free(Stream *stream)
+{
+    DisplayChannel *display = stream->display;
+    stream_recycle(display, stream);
+    display->priv->stream_count--;
+}
+
 void display_channel_init_streams(DisplayChannel *display)
 {
     int i;
@@ -140,35 +146,33 @@ void display_channel_init_streams(DisplayChannel *display)
     for (i = 0; i < NUM_STREAMS; i++) {
         Stream *stream = display_channel_get_nth_stream(display, i);
         ring_item_init(&stream->link);
-        stream_free(display, stream);
+        stream_recycle(display, stream);
     }
 }
 
-void stream_unref(DisplayChannel *display, Stream *stream)
+void stream_unref(Stream *stream)
 {
     if (--stream->refs != 0)
         return;
 
     spice_warn_if_fail(!ring_item_is_linked(&stream->link));
 
-    stream_free(display, stream);
-    display->priv->stream_count--;
+    stream_free(stream);
 }
 
-void stream_agent_unref(DisplayChannel *display, StreamAgent *agent)
+void stream_agent_unref(StreamAgent *agent)
 {
-    stream_unref(display, agent->stream);
+    stream_unref(agent->stream);
 }
 
 static void red_stream_clip_item_free(RedPipeItem *base)
 {
     g_return_if_fail(base != NULL);
     RedStreamClipItem *item = SPICE_UPCAST(RedStreamClipItem, base);
-    DisplayChannel *display = DCC_TO_DC(item->stream_agent->dcc);
 
     g_return_if_fail(item->base.refcount == 0);
 
-    stream_agent_unref(display, item->stream_agent);
+    stream_agent_unref(item->stream_agent);
     g_free(item->rects);
     g_free(item);
 }
@@ -371,6 +375,7 @@ static Stream *display_channel_stream_try_new(DisplayChannel *display)
     }
     stream = display->priv->free_streams;
     display->priv->free_streams = display->priv->free_streams->next;
+    stream->display = display;
     return stream;
 }
 
diff --git a/server/stream.h b/server/stream.h
index 6f194618d..6047f2ef7 100644
--- a/server/stream.h
+++ b/server/stream.h
@@ -125,13 +125,13 @@ struct Stream {
     uint32_t num_input_frames;
     uint64_t input_fps_start_time;
     uint32_t input_fps;
+    DisplayChannel *display;
 };
 
 void                  display_channel_init_streams                  (DisplayChannel *display);
 void                  stream_stop                                   (DisplayChannel *display,
                                                                      Stream *stream);
-void                  stream_unref                                  (DisplayChannel *display,
-                                                                     Stream *stream);
+void                  stream_unref                                  (Stream *stream);
 void                  stream_trace_update                           (DisplayChannel *display,
                                                                      Drawable *drawable);
 void                  stream_maintenance                            (DisplayChannel *display,
@@ -145,8 +145,7 @@ void                  stream_detach_behind                          (DisplayChan
                                                                      QRegion *region,
                                                                      Drawable *drawable);
 
-void                  stream_agent_unref                            (DisplayChannel *display,
-                                                                     StreamAgent *agent);
+void                  stream_agent_unref                            (StreamAgent *agent);
 void                  stream_agent_stop                             (StreamAgent *agent);
 
 void stream_detach_drawable(Stream *stream);
-- 
2.13.6



More information about the Spice-devel mailing list