[Spice-devel] [spice-gtk PATCH v3] Avoid compression of isochronous devices
Marc-André Lureau
mlureau at redhat.com
Fri Oct 7 08:12:16 UTC 2016
Hi
----- Original Message -----
> Device is considered isochronous if one of its endpoints is
> defined as isochronous transfer, in that case data transfer
> over the usbredir channel will not be compressed
> (it is assumed that there is a strong correlation between
> isochronous devices and devices which their data is usually
> compressed)
>
> E.g.
> Camera/mic device will usually be recognised as isochronous
> while storage devices won't
> ---
> src/channel-usbredir.c | 9 +++++++++
> src/usb-device-manager-priv.h | 1 +
> src/usb-device-manager.c | 34 ++++++++++++++++++++++++++++++++++
> 3 files changed, 44 insertions(+)
>
> diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
> index dd17e6c..2d025f5 100644
> --- a/src/channel-usbredir.c
> +++ b/src/channel-usbredir.c
> @@ -544,6 +544,11 @@ void
> spice_usbredir_channel_disconnect_device_async(SpiceUsbredirChannel *channe
> g_object_unref(task);
> }
>
> +static SpiceUsbDevice
> *spice_usbredir_channel_get_spice_usb_device(SpiceUsbredirChannel *channel)
> +{
> + return channel->priv->spice_device;
> +}
> +
> G_GNUC_INTERNAL
> libusb_device *spice_usbredir_channel_get_device(SpiceUsbredirChannel
> *channel)
> {
> @@ -673,6 +678,10 @@ static int try_write_compress_LZ4(SpiceUsbredirChannel
> *channel, uint8_t *data,
> /* No server compression capability - data will not be compressed */
> return FALSE;
> }
> +
> if(spice_usb_device_is_isochronous(spice_usbredir_channel_get_spice_usb_device(channel)))
> {
> + /* Don't compress - one of the device endpoints is isochronous */
> + return FALSE;
> + }
> bound = LZ4_compressBound(count);
> if (bound == 0) {
> /* Invalid bound - data will not be compressed */
> diff --git a/src/usb-device-manager-priv.h b/src/usb-device-manager-priv.h
> index b6fa9c9..83884d7 100644
> --- a/src/usb-device-manager-priv.h
> +++ b/src/usb-device-manager-priv.h
> @@ -40,6 +40,7 @@ guint8 spice_usb_device_get_busnum(const SpiceUsbDevice
> *device);
> guint8 spice_usb_device_get_devaddr(const SpiceUsbDevice *device);
> guint16 spice_usb_device_get_vid(const SpiceUsbDevice *device);
> guint16 spice_usb_device_get_pid(const SpiceUsbDevice *device);
> +gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *device);
>
> #endif
>
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index f076967..f117683 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -153,6 +153,7 @@ typedef struct _SpiceUsbDeviceInfo {
> guint8 devaddr;
> guint16 vid;
> guint16 pid;
> + gboolean isochronous;
> #ifdef G_OS_WIN32
> guint8 state;
> #else
> @@ -2017,6 +2018,29 @@ gchar *spice_usb_device_get_description(SpiceUsbDevice
> *device, const gchar *for
>
>
> #ifdef USE_USBREDIR
> +static gboolean probe_isochronous_endpoint(libusb_device *libdev) {
> + struct libusb_config_descriptor * conf_desc;
> + gboolean isoc_found = FALSE;
> + gint i,j,k;
> +
> + g_return_val_if_fail(libdev != NULL, FALSE);
> + g_return_val_if_fail(!libusb_get_active_config_descriptor(libdev,
> &conf_desc), FALSE);
> +
It's not a good idea to put code with side-effect in g_return, as it could be removed with G_DISABLE_CHECKS (unlikely)
I'll touch it on commit.
thanks
> + for(i = 0; !isoc_found && i < conf_desc->bNumInterfaces; i++) {
> + for(j = 0; !isoc_found && j <
> conf_desc->interface[i].num_altsetting; j++) {
> + for(k = 0; !isoc_found && k <
> conf_desc->interface[i].altsetting[j].bNumEndpoints;k++) {
> + gint attributes =
> conf_desc->interface[i].altsetting[j].endpoint[k].bmAttributes;
> + gint type = attributes & LIBUSB_TRANSFER_TYPE_MASK;
> + if (type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS)
> + isoc_found = TRUE;
> + }
> + }
> + }
> +
> + libusb_free_config_descriptor(conf_desc);
> + return isoc_found;
> +}
> +
> /*
> * SpiceUsbDeviceInfo
> */
> @@ -2042,6 +2066,7 @@ static SpiceUsbDeviceInfo
> *spice_usb_device_new(libusb_device *libdev)
> info->vid = vid;
> info->pid = pid;
> info->ref = 1;
> + info->isochronous = probe_isochronous_endpoint(libdev);
> #ifndef G_OS_WIN32
> info->libdev = libusb_ref_device(libdev);
> #endif
> @@ -2085,6 +2110,15 @@ guint16 spice_usb_device_get_pid(const SpiceUsbDevice
> *device)
> return info->pid;
> }
>
> +gboolean spice_usb_device_is_isochronous(const SpiceUsbDevice *device)
> +{
> + const SpiceUsbDeviceInfo *info = (const SpiceUsbDeviceInfo *)device;
> +
> + g_return_val_if_fail(info != NULL, 0);
> +
> + return info->isochronous;
> +}
> +
> #ifdef G_OS_WIN32
> void spice_usb_device_set_state(SpiceUsbDevice *device, guint8 state)
> {
> --
> 2.5.5
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
>
More information about the Spice-devel
mailing list