[Spice-commits] 3 commits - src/channel-display.c src/channel-display-gst.c src/channel-display-mjpeg.c src/channel-display-priv.h src/spice-widget.c src/usb-device-manager.c src/win-usb-clerk.h src/win-usb-driver-install.c

Pavel Grunt pgrunt at kemper.freedesktop.org
Mon Jun 6 12:03:14 UTC 2016


 src/channel-display-gst.c    |   41 +++++++++++++++++++++++++++++++++--------
 src/channel-display-mjpeg.c  |   11 ++++++-----
 src/channel-display-priv.h   |    3 +--
 src/channel-display.c        |   24 +-----------------------
 src/spice-widget.c           |   14 ++++++++------
 src/usb-device-manager.c     |    6 +++---
 src/win-usb-clerk.h          |    4 ++--
 src/win-usb-driver-install.c |    3 ++-
 8 files changed, 56 insertions(+), 50 deletions(-)

New commits:
commit b2e6f64da9c970db8eec50e08fd8b8eedc96fdf1
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Fri Jun 3 15:02:59 2016 +0200

    streaming: Use the frame dimensions reported by the video decoder
    
    The dimensions sent by the remote end are redundant and should not be
    trusted.
    
    Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
    Acked-by: Pavel Grunt <pgrunt at redhat.com>

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index ca6b6e7..c752639 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -87,26 +87,51 @@ static void schedule_frame(SpiceGstDecoder *decoder);
 static gboolean display_frame(gpointer video_decoder)
 {
     SpiceGstDecoder *decoder = (SpiceGstDecoder*)video_decoder;
+    SpiceFrame *frame;
+    GstCaps *caps;
+    gint width, height;
+    GstStructure *s;
+    GstBuffer *buffer;
+    GstMapInfo mapinfo;
 
     decoder->timer_id = 0;
 
     g_mutex_lock(&decoder->queues_mutex);
-    SpiceFrame *frame = g_queue_pop_head(decoder->display_queue);
+    frame = g_queue_pop_head(decoder->display_queue);
     g_mutex_unlock(&decoder->queues_mutex);
+    /* If the queue is empty we don't even need to reschedule */
     g_return_val_if_fail(frame, G_SOURCE_REMOVE);
 
-    GstBuffer *buffer = frame->sample ? gst_sample_get_buffer(frame->sample) : NULL;
-    GstMapInfo mapinfo;
     if (!frame->sample) {
         spice_warning("got a frame without a sample!");
-    } else if (gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
-        stream_display_frame(decoder->base.stream, frame->msg, mapinfo.data);
-        gst_buffer_unmap(buffer, &mapinfo);
-    } else {
+        goto error;
+    }
+
+    caps = gst_sample_get_caps(frame->sample);
+    if (!caps) {
+        spice_warning("GStreamer error: could not get the caps of the sample");
+        goto error;
+    }
+
+    s = gst_caps_get_structure(caps, 0);
+    if (!gst_structure_get_int(s, "width", &width) ||
+        !gst_structure_get_int(s, "height", &height)) {
+        spice_warning("GStreamer error: could not get the size of the frame");
+        goto error;
+    }
+
+    buffer = gst_sample_get_buffer(frame->sample);
+    if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
         spice_warning("GStreamer error: could not map the buffer");
+        goto error;
     }
-    free_frame(frame);
 
+    stream_display_frame(decoder->base.stream, frame->msg,
+                         width, height, mapinfo.data);
+    gst_buffer_unmap(buffer, &mapinfo);
+
+ error:
+    free_frame(frame);
     schedule_frame(decoder);
     return G_SOURCE_REMOVE;
 }
diff --git a/src/channel-display-mjpeg.c b/src/channel-display-mjpeg.c
index a2dae82..4976d53 100644
--- a/src/channel-display-mjpeg.c
+++ b/src/channel-display-mjpeg.c
@@ -86,12 +86,13 @@ static gboolean mjpeg_decoder_decode_frame(gpointer video_decoder)
 {
     MJpegDecoder *decoder = (MJpegDecoder*)video_decoder;
     gboolean back_compat = decoder->base.stream->channel->priv->peer_hdr.major_version == 1;
-    int width;
-    int height;
+    JDIMENSION width, height;
     uint8_t *dest;
     uint8_t *lines[4];
 
-    stream_get_dimensions(decoder->base.stream, decoder->cur_frame_msg, &width, &height);
+    jpeg_read_header(&decoder->mjpeg_cinfo, 1);
+    width = decoder->mjpeg_cinfo.image_width;
+    height = decoder->mjpeg_cinfo.image_height;
     if (decoder->out_size < width * height * 4) {
         g_free(decoder->out_frame);
         decoder->out_size = width * height * 4;
@@ -99,7 +100,6 @@ static gboolean mjpeg_decoder_decode_frame(gpointer video_decoder)
     }
     dest = decoder->out_frame;
 
-    jpeg_read_header(&decoder->mjpeg_cinfo, 1);
 #ifdef JCS_EXTENSIONS
     // requires jpeg-turbo
     if (back_compat)
@@ -168,7 +168,8 @@ static gboolean mjpeg_decoder_decode_frame(gpointer video_decoder)
     jpeg_finish_decompress(&decoder->mjpeg_cinfo);
 
     /* Display the frame and dispose of it */
-    stream_display_frame(decoder->base.stream, decoder->cur_frame_msg, decoder->out_frame);
+    stream_display_frame(decoder->base.stream, decoder->cur_frame_msg,
+                         width, height, decoder->out_frame);
     spice_msg_in_unref(decoder->cur_frame_msg);
     decoder->cur_frame_msg = NULL;
     decoder->timer_id = 0;
diff --git a/src/channel-display-priv.h b/src/channel-display-priv.h
index 3155015..3fcf2e2 100644
--- a/src/channel-display-priv.h
+++ b/src/channel-display-priv.h
@@ -135,10 +135,9 @@ struct display_stream {
     uint32_t report_drops_seq_len;
 };
 
-void stream_get_dimensions(display_stream *st, SpiceMsgIn *frame_msg, int *width, int *height);
 guint32 stream_get_time(display_stream *st);
 void stream_dropped_frame_on_playback(display_stream *st);
-void stream_display_frame(display_stream *st, SpiceMsgIn *frame_msg, uint8_t* data);
+void stream_display_frame(display_stream *st, SpiceMsgIn *frame_msg, uint32_t width, uint32_t height, uint8_t *data);
 uint32_t spice_msg_in_frame_data(SpiceMsgIn *frame_msg, uint8_t **data);
 
 
diff --git a/src/channel-display.c b/src/channel-display.c
index 54bc30e..22e64e2 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -1174,26 +1174,6 @@ uint32_t spice_msg_in_frame_data(SpiceMsgIn *frame_msg, uint8_t **data)
 }
 
 G_GNUC_INTERNAL
-void stream_get_dimensions(display_stream *st, SpiceMsgIn *frame_msg, int *width, int *height)
-{
-    g_return_if_fail(width != NULL);
-    g_return_if_fail(height != NULL);
-
-    if (frame_msg == NULL ||
-        spice_msg_in_type(frame_msg) != SPICE_MSG_DISPLAY_STREAM_DATA_SIZED) {
-        SpiceMsgDisplayStreamCreate *info = spice_msg_in_parsed(st->msg_create);
-
-        *width = info->stream_width;
-        *height = info->stream_height;
-    } else {
-        SpiceMsgDisplayStreamDataSized *op = spice_msg_in_parsed(frame_msg);
-
-        *width = op->width;
-        *height = op->height;
-   }
-}
-
-G_GNUC_INTERNAL
 guint32 stream_get_time(display_stream *st)
 {
     SpiceSession *session = spice_channel_get_session(st->channel);
@@ -1210,13 +1190,11 @@ void stream_dropped_frame_on_playback(display_stream *st)
 /* main context */
 G_GNUC_INTERNAL
 void stream_display_frame(display_stream *st, SpiceMsgIn *frame_msg,
-                          uint8_t* data)
+                          uint32_t width, uint32_t height, uint8_t *data)
 {
-    int width, height;
     const SpiceRect *dest;
     int stride;
 
-    stream_get_dimensions(st, frame_msg, &width, &height);
     dest = stream_get_dest(st, frame_msg);
 
     stride = width * sizeof(uint32_t);
commit 3666ec4d5c275ad6cb0130f45165dff174cf7615
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Fri Jun 3 14:16:25 2016 +0200

    widget: Avoid using GDK_GRAB_FAILED defined in Gtk 3.16.
    
    The returned value from do_pointer_grab() is treated as a boolean - grab
    was successful or not. Change the function to return a boolean value.
    
    Reported-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/src/spice-widget.c b/src/spice-widget.c
index c7a9040..51a2055 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -930,12 +930,13 @@ error:
 }
 #endif
 
-static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
+static gboolean do_pointer_grab(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
     GdkWindow *window = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
-    GdkGrabStatus status = GDK_GRAB_FAILED;
+    GdkGrabStatus status;
     GdkCursor *blank = get_blank_cursor();
+    gboolean grab_successful = FALSE;
 
     if (!gtk_widget_get_realized(GTK_WIDGET(display)))
         goto end;
@@ -964,7 +965,8 @@ static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
                      NULL,
                      blank,
                      GDK_CURRENT_TIME);
-    if (status != GDK_GRAB_SUCCESS) {
+    grab_successful = (status == GDK_GRAB_SUCCESS);
+    if (!grab_successful) {
         d->mouse_grab_active = false;
         g_warning("pointer grab failed %u", status);
     } else {
@@ -976,7 +978,7 @@ static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
 
 end:
     g_object_unref(blank);
-    return status;
+    return grab_successful;
 }
 
 static void update_mouse_pointer(SpiceDisplay *display)
@@ -1023,7 +1025,7 @@ static void try_mouse_grab(SpiceDisplay *display)
     if (d->mouse_grab_active)
         return;
 
-    if (do_pointer_grab(display) != GDK_GRAB_SUCCESS)
+    if (!do_pointer_grab(display))
         return;
 
     d->mouse_last_x = -1;
commit 0fb13d68dc9ad3ce49c86579ca1ba5269a6137ba
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Mon Jun 6 11:08:53 2016 +0200

    mingw: Fix -Werror format & missing-prototypes
    
    -Wmissing prototypes were enabled in d5e3a4a5c34fc4408298e824872c4ed511b4bb3c
    format warnings were added in da8ecf1f95382e8c12fd14915f471a3e76e4b178

diff --git a/src/spice-widget.c b/src/spice-widget.c
index d0fa912..c7a9040 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -923,7 +923,7 @@ error:
     {
         DWORD errval  = GetLastError();
         gchar *errstr = g_win32_error_message(errval);
-        g_warning("failed to clip cursor (%ld) %s", errval, errstr);
+        g_warning("failed to clip cursor (%lu) %s", errval, errstr);
     }
 
     return false;
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 325533d..1fc8fc1 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -54,7 +54,7 @@
 #include <glib/gi18n.h>
 
 #ifndef G_OS_WIN32 /* Linux -- device id is bus.addr */
-#define DEV_ID_FMT "at %d.%d"
+#define DEV_ID_FMT "at %u.%u"
 #else /* Windows -- device id is vid:pid */
 #define DEV_ID_FMT "0x%04x:0x%04x"
 #endif
@@ -999,7 +999,7 @@ static void spice_usb_device_manager_add_dev(SpiceUsbDeviceManager  *self,
 }
 
 static void spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager *self,
-                                                int bus, int address)
+                                                guint bus, guint address)
 {
     SpiceUsbDeviceManagerPrivate *priv = self->priv;
     SpiceUsbDevice *device;
@@ -1081,7 +1081,7 @@ static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
         spice_usb_device_manager_add_dev(self, libdev);
     else
         g_warning("Could not find USB device to add " DEV_ID_FMT,
-                  bus, address);
+                  (guint) bus, (guint) address);
 
     if (!priv->coldplug_list)
         libusb_free_device_list(dev_list, 1);
diff --git a/src/win-usb-clerk.h b/src/win-usb-clerk.h
index 24da3b4..a17980d 100644
--- a/src/win-usb-clerk.h
+++ b/src/win-usb-clerk.h
@@ -4,8 +4,8 @@
 #include <windows.h>
 
 #define USB_CLERK_PIPE_NAME     TEXT("\\\\.\\pipe\\usbclerkpipe")
-#define USB_CLERK_MAGIC         0xDADA
-#define USB_CLERK_VERSION       0x0003
+#define USB_CLERK_MAGIC         0xDADAu
+#define USB_CLERK_VERSION       0x0003u
 
 typedef struct USBClerkHeader {
     UINT16 magic;
diff --git a/src/win-usb-driver-install.c b/src/win-usb-driver-install.c
index 99660ce..a72fcb8 100644
--- a/src/win-usb-driver-install.c
+++ b/src/win-usb-driver-install.c
@@ -78,7 +78,7 @@ static gboolean spice_win_usb_driver_initable_init(GInitable     *initable,
         DWORD errval  = GetLastError();
         gchar *errstr = g_win32_error_message(errval);
         g_set_error(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_USB_SERVICE,
-                    "Failed to create service named pipe (%ld) %s", errval, errstr);
+                    "Failed to create service named pipe (%lu) %s", errval, errstr);
         g_free(errstr);
         return FALSE;
     }
@@ -117,6 +117,7 @@ static void spice_win_usb_driver_initable_iface_init(GInitableIface *iface)
 /* ------------------------------------------------------------------ */
 /* callbacks                                                          */
 
+static
 void win_usb_driver_handle_reply_cb(GObject *gobject,
                                     GAsyncResult *read_res,
                                     gpointer user_data)


More information about the Spice-commits mailing list