[Spice-devel] [RFC PATCH spice-server v3 02/20] stream-device: Add device to handle streaming

Jonathon Jongsma jjongsma at redhat.com
Wed Aug 23 21:26:03 UTC 2017


On Wed, 2017-08-23 at 10:14 +0100, Frediano Ziglio wrote:
> Add a stub device in guest.
> The aim of this device is make possible for the guest to send

"is to make it possible for"

> a stream through a DisplayChannel (in the sense of protocol
> channel).
> This stub allows the guest to send some data and you can
> see some debug lines of data arrived on host logs.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/Makefile.am     |   1 +
>  server/char-device.h   |   1 +
>  server/reds.c          |   2 +
>  server/stream-device.c | 130
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 134 insertions(+)
>  create mode 100644 server/stream-device.c
> 
> diff --git a/server/Makefile.am b/server/Makefile.am
> index ef8d31fc..495a7a20 100644
> --- a/server/Makefile.am
> +++ b/server/Makefile.am
> @@ -164,6 +164,7 @@ libserver_la_SOURCES =				
> \
>  	stat.h					\
>  	stream.c				\
>  	stream.h				\
> +	stream-device.c				\
>  	sw-canvas.c				\
>  	tree.c					\
>  	tree.h					\
> diff --git a/server/char-device.h b/server/char-device.h
> index dccd576d..54a1ef93 100644
> --- a/server/char-device.h
> +++ b/server/char-device.h
> @@ -236,6 +236,7 @@ RedCharDevice *spicevmc_device_connect(RedsState
> *reds,
>                                         uint8_t channel_type);
>  void spicevmc_device_disconnect(RedsState *reds,
>                                  SpiceCharDeviceInstance
> *char_device);
> +RedCharDevice *stream_device_connect(RedsState *reds,
> SpiceCharDeviceInstance *sin);
>  
>  SpiceCharDeviceInterface
> *spice_char_device_get_interface(SpiceCharDeviceInstance *instance);
>  
> diff --git a/server/reds.c b/server/reds.c
> index 33f038c7..1a50a4fd 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -3197,6 +3197,8 @@ static int
> spice_server_char_device_add_interface(SpiceServer *reds,
>      else if (strcmp(char_device->subtype, SUBTYPE_PORT) == 0) {
>          if (strcmp(char_device->portname, "org.spice-
> space.webdav.0") == 0) {
>              dev_state = spicevmc_device_connect(reds, char_device,
> SPICE_CHANNEL_WEBDAV);
> +        } else if (strcmp(char_device->portname,
> "com.redhat.stream.0") == 0) {
> +            dev_state = stream_device_connect(reds, char_device);
>          } else {
>              dev_state = spicevmc_device_connect(reds, char_device,
> SPICE_CHANNEL_PORT);
>          }
> diff --git a/server/stream-device.c b/server/stream-device.c
> new file mode 100644
> index 00000000..fb0ce582
> --- /dev/null
> +++ b/server/stream-device.c
> @@ -0,0 +1,130 @@
> +/* spice-server character device to handle a video stream
> +
> +   Copyright (C) 2017 Red Hat, Inc.
> +
> +   This library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later
> version.
> +
> +   This library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with this library; if not, see <http://www.gnu.org/
> licenses/>.
> +*/
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include "char-device.h"
> +
> +#define TYPE_STREAM_DEVICE stream_device_get_type()
> +
> +#define STREAM_DEVICE(obj) \
> +    (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_STREAM_DEVICE,
> StreamDevice))
> +#define STREAM_DEVICE_CLASS(klass) \
> +    (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_STREAM_DEVICE,
> StreamDeviceClass))
> +#define STREAM_DEVICE_GET_CLASS(obj) \
> +    (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_STREAM_DEVICE,
> StreamDeviceClass))
> +
> +typedef struct StreamDevice StreamDevice;
> +typedef struct StreamDeviceClass StreamDeviceClass;
> +
> +struct StreamDevice {
> +    RedCharDevice parent;
> +};
> +
> +struct StreamDeviceClass {
> +    RedCharDeviceClass parent_class;
> +};
> +
> +static GType stream_device_get_type(void) G_GNUC_CONST;
> +static StreamDevice *stream_device_new(SpiceCharDeviceInstance *sin,
> RedsState *reds);
> +
> +G_DEFINE_TYPE(StreamDevice, stream_device, RED_TYPE_CHAR_DEVICE)
> +
> +static RedPipeItem *
> +stream_device_read_msg_from_dev(RedCharDevice *self,
> SpiceCharDeviceInstance *sin)
> +{
> +    SpiceCharDeviceInterface *sif;
> +    int n;
> +
> +    sif = spice_char_device_get_interface(sin);
> +
> +    do {
> +        uint8_t buf[256];
> +        n = sif->read(sin, buf, sizeof(buf));
> +        spice_debug("readed %d bytes from device", n);

I know this is just a temporary debug message, but...
"readed" -> "read"

> +    } while (n > 0);
> +
> +    return NULL;
> +}
> +
> +static void
> +stream_device_send_msg_to_client(RedCharDevice *self, RedPipeItem
> *msg, RedClient *client)
> +{
> +}
> +
> +static void
> +stream_device_send_tokens_to_client(RedCharDevice *self, RedClient
> *client, uint32_t tokens)
> +{
> +    spice_printerr("Not implemented!");
> +}
> +
> +static void
> +stream_device_remove_client(RedCharDevice *self, RedClient *client)
> +{
> +}
> +
> +RedCharDevice *
> +stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin)
> +{
> +    SpiceCharDeviceInterface *sif;
> +
> +    StreamDevice *dev = stream_device_new(sin, reds);
> +
> +    sif = spice_char_device_get_interface(sin);
> +    if (sif->state) {
> +        sif->state(sin, 1);
> +    }
> +
> +    return RED_CHAR_DEVICE(dev);
> +}
> +
> +static void
> +stream_device_dispose(GObject *object)
> +{
> +}
> +
> +static void
> +stream_device_class_init(StreamDeviceClass *klass)
> +{
> +    GObjectClass *object_class = G_OBJECT_CLASS(klass);
> +    RedCharDeviceClass *char_dev_class =
> RED_CHAR_DEVICE_CLASS(klass);
> +
> +    object_class->dispose = stream_device_dispose;
> +
> +    char_dev_class->read_one_msg_from_device =
> stream_device_read_msg_from_dev;
> +    char_dev_class->send_msg_to_client =
> stream_device_send_msg_to_client;
> +    char_dev_class->send_tokens_to_client =
> stream_device_send_tokens_to_client;
> +    char_dev_class->remove_client = stream_device_remove_client;
> +}
> +
> +static void
> +stream_device_init(StreamDevice *self)
> +{
> +}
> +
> +static StreamDevice *
> +stream_device_new(SpiceCharDeviceInstance *sin, RedsState *reds)
> +{
> +    return g_object_new(TYPE_STREAM_DEVICE,
> +                        "sin", sin,
> +                        "spice-server", reds,
> +                        "client-tokens-interval", 0ULL,
> +                        "self-tokens", ~0ULL,
> +                        NULL);
> +}


Acked-by: Jonathon Jongsma <jjongsma at redhat.com>



More information about the Spice-devel mailing list