diff options
author | gdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-05 19:29:09 +0000 |
---|---|---|
committer | gdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-05 19:29:09 +0000 |
commit | b5fb8afb885035cf884e2202e9a2490c26da590c (patch) | |
tree | 3012accc49d20498fe172fef047e1a6ee6d07ab9 /chrome/browser/usb | |
parent | 10daa7cfd10b72c26852a60e2ab8cf163e7ab924 (diff) | |
download | chromium_src-b5fb8afb885035cf884e2202e9a2490c26da590c.zip chromium_src-b5fb8afb885035cf884e2202e9a2490c26da590c.tar.gz chromium_src-b5fb8afb885035cf884e2202e9a2490c26da590c.tar.bz2 |
Isochronous transfer support for USB extension API.
BUG=130190
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10511017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/usb')
-rw-r--r-- | chrome/browser/usb/usb_device.cc | 34 | ||||
-rw-r--r-- | chrome/browser/usb/usb_device.h | 20 |
2 files changed, 39 insertions, 15 deletions
diff --git a/chrome/browser/usb/usb_device.cc b/chrome/browser/usb/usb_device.cc index b3ae7ce..519b72e 100644 --- a/chrome/browser/usb/usb_device.cc +++ b/chrome/browser/usb/usb_device.cc @@ -113,8 +113,7 @@ void UsbDevice::ControlTransfer(const TransferDirection direction, libusb_fill_control_transfer(transfer, handle_, reinterpret_cast<uint8*>( buffer->data()), reinterpret_cast<libusb_transfer_cb_fn>( &HandleTransferCompletion), this, timeout); - AddTransfer(transfer, buffer, callback); - libusb_submit_transfer(transfer); + SubmitTransfer(transfer, buffer, callback); } void UsbDevice::BulkTransfer(const TransferDirection direction, @@ -128,8 +127,7 @@ void UsbDevice::BulkTransfer(const TransferDirection direction, reinterpret_cast<uint8*>(buffer->data()), length, reinterpret_cast<libusb_transfer_cb_fn>(&HandleTransferCompletion), this, timeout); - AddTransfer(transfer, buffer, callback); - libusb_submit_transfer(transfer); + SubmitTransfer(transfer, buffer, callback); } void UsbDevice::InterruptTransfer(const TransferDirection direction, @@ -143,17 +141,35 @@ void UsbDevice::InterruptTransfer(const TransferDirection direction, reinterpret_cast<uint8*>(buffer->data()), length, reinterpret_cast<libusb_transfer_cb_fn>(&HandleTransferCompletion), this, timeout); - AddTransfer(transfer, buffer, callback); - libusb_submit_transfer(transfer); + SubmitTransfer(transfer, buffer, callback); +} + +void UsbDevice::IsochronousTransfer(const TransferDirection direction, + const uint8 endpoint, net::IOBuffer* buffer, const size_t length, + const unsigned int packets, const unsigned int packet_length, + const unsigned int timeout, const net::CompletionCallback& callback) { + CheckDevice(); + + struct libusb_transfer* const transfer = libusb_alloc_transfer(packets); + const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint; + libusb_fill_iso_transfer(transfer, handle_, new_endpoint, + reinterpret_cast<uint8*>(buffer->data()), length, packets, + reinterpret_cast<libusb_transfer_cb_fn>(&HandleTransferCompletion), this, + timeout); + libusb_set_iso_packet_lengths(transfer, packet_length); + + SubmitTransfer(transfer, buffer, callback); } void UsbDevice::CheckDevice() { DCHECK(handle_) << "Device is already closed."; } -void UsbDevice::AddTransfer(PlatformUsbTransferHandle handle, - net::IOBuffer* buffer, - const net::CompletionCallback& callback) { +void UsbDevice::SubmitTransfer(PlatformUsbTransferHandle handle, + net::IOBuffer* buffer, + const net::CompletionCallback& callback) { + libusb_submit_transfer(handle); + Transfer transfer; transfer.buffer = buffer; transfer.callback = callback; diff --git a/chrome/browser/usb/usb_device.h b/chrome/browser/usb/usb_device.h index 6ac4030..7343966 100644 --- a/chrome/browser/usb/usb_device.h +++ b/chrome/browser/usb/usb_device.h @@ -68,6 +68,15 @@ class UsbDevice : public base::RefCounted<UsbDevice> { const unsigned int timeout, const net::CompletionCallback& callback); + void IsochronousTransfer(const TransferDirection direction, + const uint8 endpoint, + net::IOBuffer* buffer, + const size_t length, + const unsigned int packets, + const unsigned int packet_length, + const unsigned int timeout, + const net::CompletionCallback& callback); + // Normal code should not call this function. It is called by the platform's // callback mechanism in such a way that it cannot be made private. Invokes // the callbacks associated with a given transfer, and removes it from the @@ -89,12 +98,11 @@ class UsbDevice : public base::RefCounted<UsbDevice> { // Checks that the device has not yet been closed. void CheckDevice(); - // Starts tracking the USB transfer associated with a platform transfer - // handle. Retains the buffer and copies the completion callback until the - // transfer finishes, whereupon it invokes the callback then releases the - // buffer. - void AddTransfer(PlatformUsbTransferHandle handle, net::IOBuffer* buffer, - const net::CompletionCallback& callback); + // Submits a transfer and starts tracking it. Retains the buffer and copies + // the completion callback until the transfer finishes, whereupon it invokes + // the callback then releases the buffer. + void SubmitTransfer(PlatformUsbTransferHandle handle, net::IOBuffer* buffer, + const net::CompletionCallback& callback); // The UsbService isn't referenced here to prevent a dependency cycle between // the service and the devices. Since a service owns every device, and is |