Blame SOURCES/0006-stream-device-Add-device-to-handle-streaming.patch

ad1357
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad1357
From: Frediano Ziglio <fziglio@redhat.com>
ad1357
Date: Sat, 21 Jan 2017 11:24:58 +0000
ad1357
Subject: [spice-server] stream-device: Add device to handle streaming
ad1357
ad1357
Add a stub device in guest.
ad1357
The aim of this device is to make it possible for the guest to send a
ad1357
stream through a DisplayChannel (in the sense of protocol channel).
ad1357
This stub allows the guest to send some data and you can see some debug
ad1357
lines of data arrived on host logs.
ad1357
ad1357
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
ad1357
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
ad1357
---
ad1357
 server/Makefile.am     |   1 +
ad1357
 server/char-device.h   |   1 +
ad1357
 server/reds.c          |   2 +
ad1357
 server/stream-device.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++
ad1357
 4 files changed, 134 insertions(+)
ad1357
 create mode 100644 server/stream-device.c
ad1357
ad1357
diff --git a/server/Makefile.am b/server/Makefile.am
ad1357
index 5d5590af9..f08ddf883 100644
ad1357
--- a/server/Makefile.am
ad1357
+++ b/server/Makefile.am
ad1357
@@ -166,6 +166,7 @@ libserver_la_SOURCES =				\
ad1357
 	stat.h					\
ad1357
 	stream.c				\
ad1357
 	stream.h				\
ad1357
+	stream-device.c				\
ad1357
 	sw-canvas.c				\
ad1357
 	tree.c					\
ad1357
 	tree.h					\
ad1357
diff --git a/server/char-device.h b/server/char-device.h
ad1357
index dccd576da..54a1ef939 100644
ad1357
--- a/server/char-device.h
ad1357
+++ b/server/char-device.h
ad1357
@@ -236,6 +236,7 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds,
ad1357
                                        uint8_t channel_type);
ad1357
 void spicevmc_device_disconnect(RedsState *reds,
ad1357
                                 SpiceCharDeviceInstance *char_device);
ad1357
+RedCharDevice *stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin);
ad1357
 
ad1357
 SpiceCharDeviceInterface *spice_char_device_get_interface(SpiceCharDeviceInstance *instance);
ad1357
 
ad1357
diff --git a/server/reds.c b/server/reds.c
ad1357
index 99b1fd76b..b24f61ab2 100644
ad1357
--- a/server/reds.c
ad1357
+++ b/server/reds.c
ad1357
@@ -3223,6 +3223,8 @@ static int spice_server_char_device_add_interface(SpiceServer *reds,
ad1357
     else if (strcmp(char_device->subtype, SUBTYPE_PORT) == 0) {
ad1357
         if (strcmp(char_device->portname, "org.spice-space.webdav.0") == 0) {
ad1357
             dev_state = spicevmc_device_connect(reds, char_device, SPICE_CHANNEL_WEBDAV);
ad1357
+        } else if (strcmp(char_device->portname, "com.redhat.stream.0") == 0) {
ad1357
+            dev_state = stream_device_connect(reds, char_device);
ad1357
         } else {
ad1357
             dev_state = spicevmc_device_connect(reds, char_device, SPICE_CHANNEL_PORT);
ad1357
         }
ad1357
diff --git a/server/stream-device.c b/server/stream-device.c
ad1357
new file mode 100644
ad1357
index 000000000..f3a147b80
ad1357
--- /dev/null
ad1357
+++ b/server/stream-device.c
ad1357
@@ -0,0 +1,130 @@
ad1357
+/* spice-server character device to handle a video stream
ad1357
+
ad1357
+   Copyright (C) 2017 Red Hat, Inc.
ad1357
+
ad1357
+   This library is free software; you can redistribute it and/or
ad1357
+   modify it under the terms of the GNU Lesser General Public
ad1357
+   License as published by the Free Software Foundation; either
ad1357
+   version 2.1 of the License, or (at your option) any later version.
ad1357
+
ad1357
+   This library is distributed in the hope that it will be useful,
ad1357
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ad1357
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ad1357
+   Lesser General Public License for more details.
ad1357
+
ad1357
+   You should have received a copy of the GNU Lesser General Public
ad1357
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
ad1357
+*/
ad1357
+#ifdef HAVE_CONFIG_H
ad1357
+#include <config.h>
ad1357
+#endif
ad1357
+
ad1357
+#include "char-device.h"
ad1357
+
ad1357
+#define TYPE_STREAM_DEVICE stream_device_get_type()
ad1357
+
ad1357
+#define STREAM_DEVICE(obj) \
ad1357
+    (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_DEVICE, StreamDevice))
ad1357
+#define STREAM_DEVICE_CLASS(klass) \
ad1357
+    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_DEVICE, StreamDeviceClass))
ad1357
+#define STREAM_DEVICE_GET_CLASS(obj) \
ad1357
+    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_DEVICE, StreamDeviceClass))
ad1357
+
ad1357
+typedef struct StreamDevice StreamDevice;
ad1357
+typedef struct StreamDeviceClass StreamDeviceClass;
ad1357
+
ad1357
+struct StreamDevice {
ad1357
+    RedCharDevice parent;
ad1357
+};
ad1357
+
ad1357
+struct StreamDeviceClass {
ad1357
+    RedCharDeviceClass parent_class;
ad1357
+};
ad1357
+
ad1357
+static GType stream_device_get_type(void) G_GNUC_CONST;
ad1357
+static StreamDevice *stream_device_new(SpiceCharDeviceInstance *sin, RedsState *reds);
ad1357
+
ad1357
+G_DEFINE_TYPE(StreamDevice, stream_device, RED_TYPE_CHAR_DEVICE)
ad1357
+
ad1357
+static RedPipeItem *
ad1357
+stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *sin)
ad1357
+{
ad1357
+    SpiceCharDeviceInterface *sif;
ad1357
+    int n;
ad1357
+
ad1357
+    sif = spice_char_device_get_interface(sin);
ad1357
+
ad1357
+    do {
ad1357
+        uint8_t buf[256];
ad1357
+        n = sif->read(sin, buf, sizeof(buf));
ad1357
+        spice_debug("read %d bytes from device", n);
ad1357
+    } while (n > 0);
ad1357
+
ad1357
+    return NULL;
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_send_msg_to_client(RedCharDevice *self, RedPipeItem *msg, RedClient *client)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_send_tokens_to_client(RedCharDevice *self, RedClient *client, uint32_t tokens)
ad1357
+{
ad1357
+    spice_printerr("Not implemented!");
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_remove_client(RedCharDevice *self, RedClient *client)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+RedCharDevice *
ad1357
+stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin)
ad1357
+{
ad1357
+    SpiceCharDeviceInterface *sif;
ad1357
+
ad1357
+    StreamDevice *dev = stream_device_new(sin, reds);
ad1357
+
ad1357
+    sif = spice_char_device_get_interface(sin);
ad1357
+    if (sif->state) {
ad1357
+        sif->state(sin, 1);
ad1357
+    }
ad1357
+
ad1357
+    return RED_CHAR_DEVICE(dev);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_dispose(GObject *object)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_class_init(StreamDeviceClass *klass)
ad1357
+{
ad1357
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
ad1357
+    RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
ad1357
+
ad1357
+    object_class->dispose = stream_device_dispose;
ad1357
+
ad1357
+    char_dev_class->read_one_msg_from_device = stream_device_read_msg_from_dev;
ad1357
+    char_dev_class->send_msg_to_client = stream_device_send_msg_to_client;
ad1357
+    char_dev_class->send_tokens_to_client = stream_device_send_tokens_to_client;
ad1357
+    char_dev_class->remove_client = stream_device_remove_client;
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
+stream_device_init(StreamDevice *self)
ad1357
+{
ad1357
+}
ad1357
+
ad1357
+static StreamDevice *
ad1357
+stream_device_new(SpiceCharDeviceInstance *sin, RedsState *reds)
ad1357
+{
ad1357
+    return g_object_new(TYPE_STREAM_DEVICE,
ad1357
+                        "sin", sin,
ad1357
+                        "spice-server", reds,
ad1357
+                        "client-tokens-interval", 0ULL,
ad1357
+                        "self-tokens", ~0ULL,
ad1357
+                        NULL);
ad1357
+}