diff options
-rw-r--r-- | src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h | 1 | ||||
-rw-r--r-- | src/components/transport_manager/src/usb/libusb/usb_connection.cc | 16 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h index bad1cd7117..5f6bd40957 100644 --- a/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h +++ b/src/components/transport_manager/include/transport_manager/usb/libusb/usb_connection.h @@ -80,6 +80,7 @@ class UsbConnection : public Connection { uint8_t out_endpoint_; uint16_t out_endpoint_max_packet_size_; unsigned char* in_buffer_; + uint16_t in_buffer_size_; libusb_transfer* in_transfer_; libusb_transfer* out_transfer_; diff --git a/src/components/transport_manager/src/usb/libusb/usb_connection.cc b/src/components/transport_manager/src/usb/libusb/usb_connection.cc index 409209b2b2..a1b2430889 100644 --- a/src/components/transport_manager/src/usb/libusb/usb_connection.cc +++ b/src/components/transport_manager/src/usb/libusb/usb_connection.cc @@ -43,6 +43,9 @@ #include "utils/logger.h" +// Define the buffer size, because the Android accessory protocol packet support packet buffers up to 16Kbytes +#define TRANSPORT_USB_BUFFER_MAX_SIZE (16*1024) + namespace transport_manager { namespace transport_adapter { @@ -64,6 +67,7 @@ UsbConnection::UsbConnection(const DeviceUID& device_uid, , out_endpoint_(0) , out_endpoint_max_packet_size_(0) , in_buffer_(NULL) + , in_buffer_size_(0) , in_transfer_(NULL) , out_transfer_(0) , out_messages_() @@ -96,7 +100,7 @@ bool UsbConnection::PostInTransfer() { device_handle_, in_endpoint_, in_buffer_, - in_endpoint_max_packet_size_, + in_buffer_size_, InTransferCallback, this, 0); @@ -307,7 +311,15 @@ bool UsbConnection::Init() { LOG4CXX_TRACE(logger_, "exit with FALSE. Condition: !FindEndpoints()"); return false; } - in_buffer_ = new unsigned char[in_endpoint_max_packet_size_]; + + if(in_endpoint_max_packet_size_ < TRANSPORT_USB_BUFFER_MAX_SIZE){ + in_buffer_size_ = TRANSPORT_USB_BUFFER_MAX_SIZE; + } + else { + in_buffer_size_ = in_endpoint_max_packet_size_; + } + + in_buffer_ = new unsigned char[in_buffer_size_]; in_transfer_ = libusb_alloc_transfer(0); if (NULL == in_transfer_) { LOG4CXX_ERROR(logger_, "libusb_alloc_transfer failed"); |