[spice-server] fixup! Move stream creation/maintenance funcs to DisplayChannel

Submitted by Jonathon Jongsma on Nov. 30, 2017, 8:50 p.m.

Details

Message ID 20171130205032.12311-1-jjongsma@redhat.com
State New
Headers show
Series "Stream cleanups" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Jonathon Jongsma Nov. 30, 2017, 8:50 p.m.
---
Here's a potential fix to be squashed with patch 3/7 that moves the
VideoStream initialization to video-stream.h as I mentioned in the last
email.


 server/display-channel.c | 25 +------------------------
 server/video-stream.c    | 28 ++++++++++++++++++++++++++++
 server/video-stream.h    |  1 +
 3 files changed, 30 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/display-channel.c b/server/display-channel.c
index 1c14344be..5b8c88bad 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -2780,7 +2780,6 @@  static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
 {
     DisplayChannelClient *dcc;
     VideoStream *stream;
-    SpiceRect* src_rect;
 
     spice_assert(!drawable->stream);
 
@@ -2788,31 +2787,9 @@  static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
         return;
     }
 
-    spice_assert(drawable->red_drawable->type == QXL_DRAW_COPY);
-    src_rect = &drawable->red_drawable->u.copy.src_area;
-
+    video_stream_init(stream, drawable);
     ring_add(&display->priv->streams, &stream->link);
-    stream->current = drawable;
-    stream->last_time = drawable->creation_time;
-    stream->width = src_rect->right - src_rect->left;
-    stream->height = src_rect->bottom - src_rect->top;
-    stream->dest_area = drawable->red_drawable->bbox;
-    stream->refs = 1;
-    SpiceBitmap *bitmap = &drawable->red_drawable->u.copy.src_bitmap->u.bitmap;
-    stream->top_down = !!(bitmap->flags & SPICE_BITMAP_FLAGS_TOP_DOWN);
     drawable->stream = stream;
-    /* Provide an fps estimate the video encoder can use when initializing
-     * based on the frames that lead to the creation of the stream. Round to
-     * the nearest integer, for instance 24 for 23.976.
-     */
-    uint64_t duration = drawable->creation_time - drawable->first_frame_time;
-    if (duration > NSEC_PER_SEC * drawable->frames_count / MAX_FPS) {
-        stream->input_fps = (NSEC_PER_SEC * drawable->frames_count + duration / 2) / duration;
-    } else {
-        stream->input_fps = MAX_FPS;
-    }
-    stream->num_input_frames = 0;
-    stream->input_fps_start_time = drawable->creation_time;
     display->priv->streams_size_total += stream->width * stream->height;
     display->priv->stream_count++;
     FOREACH_DCC(display, dcc) {
diff --git a/server/video-stream.c b/server/video-stream.c
index ddb76a679..d03ec93da 100644
--- a/server/video-stream.c
+++ b/server/video-stream.c
@@ -90,6 +90,34 @@  static RedPipeItem *video_stream_destroy_item_new(VideoStreamAgent *agent)
     return video_stream_create_destroy_item_new(agent, RED_PIPE_ITEM_TYPE_STREAM_DESTROY);
 }
 
+void video_stream_init(VideoStream *stream, Drawable *drawable)
+{
+    SpiceRect* src_rect;
+    spice_assert(drawable->red_drawable->type == QXL_DRAW_COPY);
+
+    src_rect = &drawable->red_drawable->u.copy.src_area;
+    stream->current = drawable;
+    stream->last_time = drawable->creation_time;
+    stream->width = src_rect->right - src_rect->left;
+    stream->height = src_rect->bottom - src_rect->top;
+    stream->dest_area = drawable->red_drawable->bbox;
+    stream->refs = 1;
+    SpiceBitmap *bitmap = &drawable->red_drawable->u.copy.src_bitmap->u.bitmap;
+    stream->top_down = !!(bitmap->flags & SPICE_BITMAP_FLAGS_TOP_DOWN);
+
+    /* Provide an fps estimate the video encoder can use when initializing
+     * based on the frames that lead to the creation of the stream. Round to
+     * the nearest integer, for instance 24 for 23.976.
+     */
+    uint64_t duration = drawable->creation_time - drawable->first_frame_time;
+    if (duration > NSEC_PER_SEC * drawable->frames_count / MAX_FPS) {
+        stream->input_fps = (NSEC_PER_SEC * drawable->frames_count + duration / 2) / duration;
+    } else {
+        stream->input_fps = MAX_FPS;
+    }
+    stream->num_input_frames = 0;
+    stream->input_fps_start_time = drawable->creation_time;
+}
 
 void video_stream_stop(VideoStream *stream)
 {
diff --git a/server/video-stream.h b/server/video-stream.h
index e5a35dd89..55b432663 100644
--- a/server/video-stream.h
+++ b/server/video-stream.h
@@ -128,6 +128,7 @@  struct VideoStream {
     DisplayChannel *display;
 };
 
+void video_stream_init(VideoStream *stream, Drawable *drawable);
 void video_stream_stop(VideoStream *stream);
 void video_stream_unref(VideoStream *stream);
 void video_stream_timeout(DisplayChannel *display);