Loading media/mtp/MtpDataPacket.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -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 Loading media/mtp/MtpDataPacket.h +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading media/mtp/MtpDatabase.h +2 −0 Original line number Diff line number Diff line Loading @@ -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, Loading media/mtp/MtpServer.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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); Loading Loading @@ -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; Loading media/mtp/MtpServer.h +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ private: MtpResponseCode doGetObjectPropList(); MtpResponseCode doGetObjectInfo(); MtpResponseCode doGetObject(); MtpResponseCode doGetThumb(); MtpResponseCode doGetPartialObject(MtpOperationCode operation); MtpResponseCode doSendObjectInfo(); MtpResponseCode doSendObject(); Loading Loading
media/mtp/MtpDataPacket.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
media/mtp/MtpDataPacket.h +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
media/mtp/MtpDatabase.h +2 −0 Original line number Diff line number Diff line Loading @@ -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, Loading
media/mtp/MtpServer.cpp +20 −1 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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); Loading Loading @@ -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; Loading
media/mtp/MtpServer.h +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ private: MtpResponseCode doGetObjectPropList(); MtpResponseCode doGetObjectInfo(); MtpResponseCode doGetObject(); MtpResponseCode doGetThumb(); MtpResponseCode doGetPartialObject(MtpOperationCode operation); MtpResponseCode doSendObjectInfo(); MtpResponseCode doSendObject(); Loading