diff options
author | Mike Lockwood <lockwood@android.com> | 2011-05-04 08:57:47 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-05-04 08:57:47 -0700 |
commit | d2ca5614d246e0c345b76cafa04fc768cce77095 (patch) | |
tree | 584886cbfe61d60db52da5055039e3586061cd76 | |
parent | 3e9987d831c579674060503bda735a9dc3dd35c1 (diff) | |
parent | 1daaaf28f75ebc7cf798a0c45392ab301a7527a7 (diff) | |
download | frameworks_av-d2ca5614d246e0c345b76cafa04fc768cce77095.zip frameworks_av-d2ca5614d246e0c345b76cafa04fc768cce77095.tar.gz frameworks_av-d2ca5614d246e0c345b76cafa04fc768cce77095.tar.bz2 |
am a792c804: DO NOT MERGE MTP: Implement GetThumb command
* commit 'a792c804025e25eb8a110d1db63f26bbd09e0e6b':
DO NOT MERGE MTP: Implement GetThumb command
-rw-r--r-- | media/mtp/MtpDataPacket.cpp | 10 | ||||
-rw-r--r-- | media/mtp/MtpDataPacket.h | 1 | ||||
-rw-r--r-- | media/mtp/MtpDatabase.h | 2 | ||||
-rw-r--r-- | media/mtp/MtpServer.cpp | 21 | ||||
-rw-r--r-- | media/mtp/MtpServer.h | 1 |
5 files changed, 34 insertions, 1 deletions
diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp index 0b0c80d..817eac0 100644 --- a/media/mtp/MtpDataPacket.cpp +++ b/media/mtp/MtpDataPacket.cpp @@ -388,6 +388,16 @@ int MtpDataPacket::writeDataHeader(int fd, uint32_t length) { int ret = ::write(fd, mBuffer, MTP_CONTAINER_HEADER_SIZE); return (ret < 0 ? ret : 0); } + +int MtpDataPacket::writeData(int fd, void* data, uint32_t length) { + MtpPacket::putUInt32(MTP_CONTAINER_LENGTH_OFFSET, length + MTP_CONTAINER_HEADER_SIZE); + MtpPacket::putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_DATA); + int ret = ::write(fd, mBuffer, MTP_CONTAINER_HEADER_SIZE); + if (ret == MTP_CONTAINER_HEADER_SIZE) + ret = ::write(fd, data, length); + return (ret < 0 ? ret : 0); +} + #endif // MTP_DEVICE #ifdef MTP_HOST diff --git a/media/mtp/MtpDataPacket.h b/media/mtp/MtpDataPacket.h index 577cea1..8a08948 100644 --- a/media/mtp/MtpDataPacket.h +++ b/media/mtp/MtpDataPacket.h @@ -100,6 +100,7 @@ public: // write our data to the given file descriptor int write(int fd); int writeDataHeader(int fd, uint32_t length); + int writeData(int fd, void* data, uint32_t length); #endif #ifdef MTP_HOST diff --git a/media/mtp/MtpDatabase.h b/media/mtp/MtpDatabase.h index d7bde00..4e6ac7a 100644 --- a/media/mtp/MtpDatabase.h +++ b/media/mtp/MtpDatabase.h @@ -84,6 +84,8 @@ public: virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle, MtpObjectInfo& info) = 0; + virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize) = 0; + virtual MtpResponseCode getObjectFilePath(MtpObjectHandle handle, MtpString& outFilePath, int64_t& outFileLength, diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp index b744b5b..4a8fd3e 100644 --- a/media/mtp/MtpServer.cpp +++ b/media/mtp/MtpServer.cpp @@ -50,7 +50,7 @@ static const MtpOperationCode kSupportedOperationCodes[] = { MTP_OPERATION_GET_OBJECT_HANDLES, MTP_OPERATION_GET_OBJECT_INFO, MTP_OPERATION_GET_OBJECT, -// MTP_OPERATION_GET_THUMB, + MTP_OPERATION_GET_THUMB, MTP_OPERATION_DELETE_OBJECT, MTP_OPERATION_SEND_OBJECT_INFO, MTP_OPERATION_SEND_OBJECT, @@ -370,6 +370,9 @@ bool MtpServer::handleRequest() { case MTP_OPERATION_GET_OBJECT: response = doGetObject(); break; + case MTP_OPERATION_GET_THUMB: + response = doGetThumb(); + break; case MTP_OPERATION_GET_PARTIAL_OBJECT: case MTP_OPERATION_GET_PARTIAL_OBJECT_64: response = doGetPartialObject(operation); @@ -736,6 +739,22 @@ MtpResponseCode MtpServer::doGetObject() { return MTP_RESPONSE_OK; } +MtpResponseCode MtpServer::doGetThumb() { + MtpObjectHandle handle = mRequest.getParameter(1); + size_t thumbSize; + void* thumb = mDatabase->getThumbnail(handle, thumbSize); + if (thumb) { + // send data + mData.setOperationCode(mRequest.getOperationCode()); + mData.setTransactionID(mRequest.getTransactionID()); + mData.writeData(mFD, thumb, thumbSize); + free(thumb); + return MTP_RESPONSE_OK; + } else { + return MTP_RESPONSE_GENERAL_ERROR; + } +} + MtpResponseCode MtpServer::doGetPartialObject(MtpOperationCode operation) { if (!hasStorage()) return MTP_RESPONSE_INVALID_OBJECT_HANDLE; diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h index b06eb28..859a18e 100644 --- a/media/mtp/MtpServer.h +++ b/media/mtp/MtpServer.h @@ -133,6 +133,7 @@ private: MtpResponseCode doGetObjectPropList(); MtpResponseCode doGetObjectInfo(); MtpResponseCode doGetObject(); + MtpResponseCode doGetThumb(); MtpResponseCode doGetPartialObject(MtpOperationCode operation); MtpResponseCode doSendObjectInfo(); MtpResponseCode doSendObject(); |