[Spice-devel] [usbredir PATCH v3] usbredirhost: new callback for iso streams
Victor Toso
victortoso at redhat.com
Mon Oct 19 03:07:04 PDT 2015
For streaming devices it might be necessary from application to drop
data for different reasons. This patch provides a new callback that it
is called before queueing the most recent iso packages.
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1264156
---
usbredirhost/usbredirhost.c | 19 +++++++++++++++++--
usbredirhost/usbredirhost.h | 12 ++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c
index ad30722..ecc57e3 100644
--- a/usbredirhost/usbredirhost.c
+++ b/usbredirhost/usbredirhost.c
@@ -109,6 +109,7 @@ struct usbredirhost {
usbredirparser_read read_func;
usbredirparser_write write_func;
usbredirhost_flush_writes flush_writes_func;
+ usbredirhost_can_write_iso can_write_iso_func;
void *func_priv;
int verbose;
libusb_context *ctx;
@@ -1028,8 +1029,11 @@ static void usbredirhost_send_stream_data(struct usbredirhost *host,
.status = status,
.length = len,
};
- usbredirparser_send_iso_packet(host->parser, id, &iso_packet,
- data, len);
+
+ if (!host->can_write_iso_func ||
+ host->can_write_iso_func(host->func_priv) != 0)
+ usbredirparser_send_iso_packet(host->parser, id, &iso_packet,
+ data, len);
break;
}
case usb_redir_type_bulk: {
@@ -1358,6 +1362,17 @@ static void usbredirhost_log_data(struct usbredirhost *host, const char *desc,
/**************************************************************************/
+void usbredirhost_set_cb_can_write_iso(struct usbredirhost *host,
+ usbredirhost_can_write_iso can_write_iso_func)
+{
+ if (!host) {
+ ERROR("invalid usbredirhost");
+ return;
+ }
+
+ host->can_write_iso_func = can_write_iso_func;
+}
+
/* Return value:
0 All ok
1 Packet borked, continue with next packet / urb
diff --git a/usbredirhost/usbredirhost.h b/usbredirhost/usbredirhost.h
index c0042c9..98c81c8 100644
--- a/usbredirhost/usbredirhost.h
+++ b/usbredirhost/usbredirhost.h
@@ -33,6 +33,8 @@ struct usbredirhost;
typedef void (*usbredirhost_flush_writes)(void *priv);
+typedef int (*usbredirhost_can_write_iso)(void *priv);
+
/* This function creates an usbredirhost instance, including its embedded
libusbredirparser instance and sends the initial usb_redir_hello packet to
the usb-guest.
@@ -114,6 +116,16 @@ void usbredirhost_close(struct usbredirhost *host);
int usbredirhost_set_device(struct usbredirhost *host,
libusb_device_handle *usb_dev_handle);
+/* Call this function to set a callback in usbredirhost to be called prior any
+ iso packets are queued. If the callback returns 0 the iso packets will be
+ dropped; In case the callback returns any other value, the iso packets will
+ be queued to be written to the client;
+
+ Call this function with NULL to erase previous callback;
+*/
+void usbredirhost_set_cb_can_write_iso(struct usbredirhost *host,
+ usbredirhost_can_write_iso can_write_iso_func);
+
/* Call this whenever there is data ready for the usbredirhost to read from
the usb-guest
returns 0 on success, or an error code from the below enum on error.
--
2.5.0
More information about the Spice-devel
mailing list