Parse the data sent from the guest to the streaming device. TODO remove some FIXME TODO handle protocol errors
Signed-off-by: Frediano Ziglio <fzig...@redhat.com> --- server/stream-device.c | 80 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/server/stream-device.c b/server/stream-device.c index 3b89023..96a6b92 100644 --- a/server/stream-device.c +++ b/server/stream-device.c @@ -19,6 +19,8 @@ #include <config.h> #endif +#include <spice/stream-device.h> + #include "char-device.h" #define STREAM_TYPE_DEVICE stream_device_get_type() @@ -39,6 +41,8 @@ typedef struct StreamDeviceClass StreamDeviceClass; struct StreamDevice { RedCharDevice parent; + StreamDevHeader hdr; + uint8_t hdr_pos; }; struct StreamDeviceClass { @@ -50,21 +54,91 @@ static StreamDevice *stream_device_new(SpiceCharDeviceInstance *sin, RedsState * G_DEFINE_TYPE(StreamDevice, stream_device, RED_TYPE_CHAR_DEVICE) +typedef void StreamMsgHandler(StreamDevice *dev, SpiceCharDeviceInstance *sin); + +static StreamMsgHandler handle_msg_format, handle_msg_data, handle_msg_invalid; + static RedPipeItem * stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *sin) { + StreamDevice *dev = STREAM_DEVICE(self); SpiceCharDeviceInterface *sif; int n; sif = spice_char_device_get_interface(sin); + /* read header */ + while (dev->hdr_pos < sizeof(dev->hdr)) { + n = sif->read(sin, (uint8_t *) &dev->hdr, sizeof(dev->hdr) - dev->hdr_pos); + if (n <= 0) { + return NULL; + } + dev->hdr_pos += n; + if (dev->hdr_pos >= sizeof(dev->hdr)) { + dev->hdr.type = GUINT16_FROM_LE(dev->hdr.type); + dev->hdr.size = GUINT32_FROM_LE(dev->hdr.size); + } + } + + switch ((StreamDevType) dev->hdr.type) { + case STREAM_TYPE_STREAM_FORMAT: + /* FIXME */ + spice_assert(dev->hdr.size == sizeof(StreamMsgStreamFormat)); + handle_msg_format(dev, sin); + break; + case STREAM_TYPE_DATA: + handle_msg_data(dev, sin); + break; + case STREAM_TYPE_CAPABILITIES: + /* FIXME */ + default: + handle_msg_invalid(dev, sin); + break; + } + + return NULL; +} + +static void +handle_msg_invalid(StreamDevice *dev, SpiceCharDeviceInstance *sin) +{ + /* FIXME */ +} + +static void +handle_msg_format(StreamDevice *dev, SpiceCharDeviceInstance *sin) +{ + StreamMsgStreamFormat fmt; + SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin); + int n = sif->read(sin, (uint8_t *) &fmt, sizeof(fmt)); + if (n == 0) { + return; + } + /* FIXME */ + spice_assert(n == sizeof(fmt)); + fmt.width = GUINT32_FROM_LE(fmt.width); + fmt.height = GUINT32_FROM_LE(fmt.height); + dev->hdr_pos = 0; +} + +static void +handle_msg_data(StreamDevice *dev, SpiceCharDeviceInstance *sin) +{ + SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin); + int n; do { - uint8_t buf[256]; + uint8_t buf[16 * 1024]; n = sif->read(sin, buf, sizeof(buf)); + /* FIXME */ printf("readed %d bytes from device\n", n); + if (n <= 0) { + break; + } + dev->hdr.size -= n; } while (n > 0); - - return NULL; + if (dev->hdr.size == 0) { + dev->hdr_pos = 0; + } } static void -- git-series 0.9.1 _______________________________________________ Spice-devel mailing list Spice-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/spice-devel