summaryrefslogtreecommitdiffstats
path: root/media/mtp/MtpDataPacket.cpp
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-11-19 11:20:19 -0500
committerMike Lockwood <lockwood@android.com>2010-11-19 11:30:10 -0500
commitb9ff444a7eaf7ffd43970c0477110c6808bd4a7c (patch)
tree6fcfa2ec5805ead1a62757b7875a20eee5b4a151 /media/mtp/MtpDataPacket.cpp
parent317ca79a49746dbd1b6bb83712e93e2dc5f6e4f0 (diff)
downloadframeworks_av-b9ff444a7eaf7ffd43970c0477110c6808bd4a7c.zip
frameworks_av-b9ff444a7eaf7ffd43970c0477110c6808bd4a7c.tar.gz
frameworks_av-b9ff444a7eaf7ffd43970c0477110c6808bd4a7c.tar.bz2
PTP: Improve performance and reliability of file importing
Now the file copy is done completely within the media process rather than pushing data to the client via ContProvider.openFile(). File system writes are now interleaved with USB reads, which allows us to copy the data faster and prevents the camera from timing out during transfer. File is automatically inserted in the media provider after a successful import and a Uri is returned to the client. BUG: 2994234 Change-Id: Ie75c63da76f623343d3d966c6a707aa1ae871972 Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/mtp/MtpDataPacket.cpp')
-rw-r--r--media/mtp/MtpDataPacket.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp
index 20dd94d..e1d1a92 100644
--- a/media/mtp/MtpDataPacket.cpp
+++ b/media/mtp/MtpDataPacket.cpp
@@ -413,20 +413,32 @@ int MtpDataPacket::read(struct usb_endpoint *ep) {
}
int MtpDataPacket::readData(struct usb_endpoint *ep, void* buffer, int length) {
- int packetSize = usb_endpoint_max_packet(ep);
int read = 0;
while (read < length) {
- int ret = transfer(ep, (char *)buffer + read, packetSize);
+ int ret = transfer(ep, (char *)buffer + read, length - read);
if (ret < 0) {
-printf("MtpDataPacket::readData returning %d\n", ret);
return ret;
}
read += ret;
}
-printf("MtpDataPacket::readData returning %d\n", read);
return read;
}
+// Queue a read request. Call readDataWait to wait for result
+int MtpDataPacket::readDataAsync(struct usb_endpoint *ep, void* buffer, int length) {
+ if (usb_endpoint_queue(ep, buffer, length)) {
+ LOGE("usb_endpoint_queue failed, errno: %d", errno);
+ return -1;
+ }
+ return 0;
+}
+
+// Wait for result of readDataAsync
+int MtpDataPacket::readDataWait(struct usb_endpoint *ep) {
+ int ep_num;
+ return usb_endpoint_wait(usb_endpoint_get_device(ep), &ep_num);
+}
+
int MtpDataPacket::readDataHeader(struct usb_endpoint *ep) {
int length = transfer(ep, mBuffer, usb_endpoint_max_packet(ep));
if (length >= 0)
@@ -454,15 +466,7 @@ int MtpDataPacket::write(struct usb_endpoint *ep) {
}
int MtpDataPacket::write(struct usb_endpoint *ep, void* buffer, uint32_t length) {
- int ret = 0;
- int packetSize = usb_endpoint_max_packet(ep);
- while (length > 0) {
- int write = (length > packetSize ? packetSize : length);
- int ret = transfer(ep, buffer, write);
- if (ret < 0)
- break;
- length -= ret;
- }
+ int ret = transfer(ep, buffer, length);
return (ret < 0 ? ret : 0);
}