diff options
-rw-r--r-- | drm/common/Android.mk | 1 | ||||
-rw-r--r-- | drm/common/IDrmIOService.cpp | 74 | ||||
-rw-r--r-- | drm/drmserver/DrmManager.cpp | 2 | ||||
-rw-r--r-- | drm/libdrmframework/include/DrmIOService.h | 46 | ||||
-rw-r--r-- | drm/libdrmframework/include/IDrmIOService.h | 86 | ||||
-rw-r--r-- | drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk | 2 | ||||
-rwxr-xr-x | media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp | 2 | ||||
-rw-r--r-- | media/mtp/Android.mk | 2 | ||||
-rw-r--r-- | media/mtp/MtpClient.cpp | 251 | ||||
-rw-r--r-- | media/mtp/MtpClient.h | 68 | ||||
-rw-r--r-- | media/mtp/MtpDevice.cpp | 220 | ||||
-rw-r--r-- | media/mtp/MtpDevice.h | 14 | ||||
-rw-r--r-- | services/audioflinger/AudioPolicyManagerBase.cpp | 62 |
13 files changed, 286 insertions, 544 deletions
diff --git a/drm/common/Android.mk b/drm/common/Android.mk index c79a91a..f1136c9 100644 --- a/drm/common/Android.mk +++ b/drm/common/Android.mk @@ -26,7 +26,6 @@ LOCAL_SRC_FILES:= \ DrmInfoStatus.cpp \ DrmRights.cpp \ DrmSupportInfo.cpp \ - IDrmIOService.cpp \ IDrmManagerService.cpp \ IDrmServiceListener.cpp \ DrmInfoEvent.cpp \ diff --git a/drm/common/IDrmIOService.cpp b/drm/common/IDrmIOService.cpp deleted file mode 100644 index e44ca55..0000000 --- a/drm/common/IDrmIOService.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdint.h> -#include <sys/types.h> -#include <binder/Parcel.h> -#include <binder/IPCThreadState.h> -#include <drm/drm_framework_common.h> -#include "IDrmIOService.h" - -using namespace android; - -void BpDrmIOService::writeToFile(const String8& filePath, const String8& dataBuffer) { - Parcel data, reply; - - data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); - data.writeString8(filePath); - data.writeString8(dataBuffer); - - remote()->transact(WRITE_TO_FILE, data, &reply); -} - -String8 BpDrmIOService::readFromFile(const String8& filePath) { - - Parcel data, reply; - - data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); - data.writeString8(filePath); - - remote()->transact(READ_FROM_FILE, data, &reply); - return reply.readString8(); -} - -IMPLEMENT_META_INTERFACE(DrmIOService, "drm.IDrmIOService"); - -status_t BnDrmIOService::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - - switch (code) { - case WRITE_TO_FILE: - { - CHECK_INTERFACE(IDrmIOService, data, reply); - - writeToFile(data.readString8(), data.readString8()); - return DRM_NO_ERROR; - } - - case READ_FROM_FILE: - { - CHECK_INTERFACE(IDrmIOService, data, reply); - - String8 dataBuffer = readFromFile(data.readString8()); - reply->writeString8(dataBuffer); - return DRM_NO_ERROR; - } - - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index b6e0c30..ef7d274 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -87,7 +87,7 @@ void DrmManager::removeUniqueId(int uniqueId) { } status_t DrmManager::loadPlugIns() { - String8 pluginDirPath("/system/lib/drm/plugins/native"); + String8 pluginDirPath("/system/lib/drm"); return loadPlugIns(pluginDirPath); } diff --git a/drm/libdrmframework/include/DrmIOService.h b/drm/libdrmframework/include/DrmIOService.h deleted file mode 100644 index 244124e..0000000 --- a/drm/libdrmframework/include/DrmIOService.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DRM_IO_SERVICE_H__ -#define __DRM_IO_SERVICE_H__ - -#include "IDrmIOService.h" - -namespace android { - -/** - * This is the implementation class for DRM IO service. - * - * The instance of this class is created while starting the DRM IO service. - * - */ -class DrmIOService : public BnDrmIOService { -public: - static void instantiate(); - -private: - DrmIOService(); - virtual ~DrmIOService(); - -public: - void writeToFile(const String8& filePath, const String8& dataBuffer); - String8 readFromFile(const String8& filePath); -}; - -}; - -#endif /* __DRM_IO_SERVICE_H__ */ - diff --git a/drm/libdrmframework/include/IDrmIOService.h b/drm/libdrmframework/include/IDrmIOService.h deleted file mode 100644 index 5e0d907..0000000 --- a/drm/libdrmframework/include/IDrmIOService.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __IDRM_IO_SERVICE_H__ -#define __IDRM_IO_SERVICE_H__ - -#include <utils/RefBase.h> -#include <binder/IInterface.h> -#include <binder/Parcel.h> - -namespace android { - -/** - * This is the interface class for DRM IO service. - * - */ -class IDrmIOService : public IInterface -{ -public: - enum { - WRITE_TO_FILE = IBinder::FIRST_CALL_TRANSACTION, - READ_FROM_FILE - }; - -public: - DECLARE_META_INTERFACE(DrmIOService); - -public: - /** - * Writes the data into the file path provided - * - * @param[in] filePath Path of the file - * @param[in] dataBuffer Data to write - */ - virtual void writeToFile(const String8& filePath, const String8& dataBuffer) = 0; - - /** - * Reads the data from the file path provided - * - * @param[in] filePath Path of the file - * @return Data read from the file - */ - virtual String8 readFromFile(const String8& filePath) = 0; -}; - -/** - * This is the Binder implementation class for DRM IO service. - */ -class BpDrmIOService: public BpInterface<IDrmIOService> -{ -public: - BpDrmIOService(const sp<IBinder>& impl) - : BpInterface<IDrmIOService>(impl) {} - - virtual void writeToFile(const String8& filePath, const String8& dataBuffer); - - virtual String8 readFromFile(const String8& filePath); -}; - -/** - * This is the Binder implementation class for DRM IO service. - */ -class BnDrmIOService: public BnInterface<IDrmIOService> -{ -public: - virtual status_t onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); -}; - -}; - -#endif /* __IDRM_IO_SERVICE_H__ */ - diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk index d4a6f18..af67aa3 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk @@ -60,7 +60,7 @@ LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/include \ external/openssl/include -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm/plugins/native +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm LOCAL_MODULE_TAGS := optional diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp index 26c5aca..9097e20 100755 --- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp +++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp @@ -166,7 +166,7 @@ enum { REVERB_VOLUME_RAMP, }; -#define REVERB_DEFAULT_PRESET REVERB_PRESET_MEDIUMROOM +#define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE #define REVERB_SEND_LEVEL (0x0C00) // 0.75 in 4.12 format diff --git a/media/mtp/Android.mk b/media/mtp/Android.mk index 70dc340..c25285e 100644 --- a/media/mtp/Android.mk +++ b/media/mtp/Android.mk @@ -21,7 +21,6 @@ ifneq ($(TARGET_SIMULATOR),true) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - MtpClient.cpp \ MtpDataPacket.cpp \ MtpDebug.cpp \ MtpDevice.cpp \ @@ -53,7 +52,6 @@ ifeq ($(HOST_OS),linux) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ - MtpClient.cpp \ MtpDataPacket.cpp \ MtpDebug.cpp \ MtpDevice.cpp \ diff --git a/media/mtp/MtpClient.cpp b/media/mtp/MtpClient.cpp deleted file mode 100644 index c830540..0000000 --- a/media/mtp/MtpClient.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "MtpClient" - -#include "MtpDebug.h" -#include "MtpClient.h" -#include "MtpDevice.h" - -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> - -#include <usbhost/usbhost.h> - -struct usb_device; - -namespace android { - -static bool isMtpDevice(uint16_t vendor, uint16_t product) { - // Sandisk Sansa Fuze - if (vendor == 0x0781 && product == 0x74c2) - return true; - // Samsung YP-Z5 - if (vendor == 0x04e8 && product == 0x503c) - return true; - return false; -} - -class MtpClientThread : public Thread { -private: - MtpClient* mClient; - -public: - MtpClientThread(MtpClient* client) - : mClient(client) - { - } - - virtual bool threadLoop() { - return mClient->threadLoop(); - } -}; - - -MtpClient::MtpClient() - : mThread(NULL), - mUsbHostContext(NULL), - mDone(false) -{ -} - -MtpClient::~MtpClient() { - usb_host_cleanup(mUsbHostContext); -} - -bool MtpClient::start() { - Mutex::Autolock autoLock(mMutex); - - if (mThread) - return true; - - mUsbHostContext = usb_host_init(); - if (!mUsbHostContext) - return false; - - mThread = new MtpClientThread(this); - mThread->run("MtpClientThread"); - // wait for the thread to do initial device discovery before returning - mThreadStartCondition.wait(mMutex); - - return true; -} - -void MtpClient::stop() { - mDone = true; -} - -MtpDevice* MtpClient::getDevice(int id) { - for (int i = 0; i < mDeviceList.size(); i++) { - MtpDevice* device = mDeviceList[i]; - if (device->getID() == id) - return device; - } - return NULL; -} - -bool MtpClient::usbDeviceAdded(const char *devname) { - struct usb_descriptor_header* desc; - struct usb_descriptor_iter iter; - - struct usb_device *device = usb_device_open(devname); - if (!device) { - LOGE("usb_device_open failed\n"); - return mDone; - } - - usb_descriptor_iter_init(device, &iter); - - while ((desc = usb_descriptor_iter_next(&iter)) != NULL) { - if (desc->bDescriptorType == USB_DT_INTERFACE) { - struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc; - - if (interface->bInterfaceClass == USB_CLASS_STILL_IMAGE && - interface->bInterfaceSubClass == 1 && // Still Image Capture - interface->bInterfaceProtocol == 1) // Picture Transfer Protocol (PIMA 15470) - { - LOGD("Found camera: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device), - usb_device_get_product_name(device)); - } else if (interface->bInterfaceClass == 0xFF && - interface->bInterfaceSubClass == 0xFF && - interface->bInterfaceProtocol == 0) { - char* interfaceName = usb_device_get_string(device, interface->iInterface); - if (!interfaceName || strcmp(interfaceName, "MTP")) - continue; - // Looks like an android style MTP device - LOGD("Found MTP device: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device), - usb_device_get_product_name(device)); - } else { - // look for special cased devices based on vendor/product ID - // we are doing this mainly for testing purposes - uint16_t vendor = usb_device_get_vendor_id(device); - uint16_t product = usb_device_get_product_id(device); - if (!isMtpDevice(vendor, product)) { - // not an MTP or PTP device - continue; - } - // request MTP OS string and descriptor - // some music players need to see this before entering MTP mode. - char buffer[256]; - memset(buffer, 0, sizeof(buffer)); - int ret = usb_device_send_control(device, - USB_DIR_IN|USB_RECIP_DEVICE|USB_TYPE_STANDARD, - USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) | 0xEE, - 0, sizeof(buffer), buffer); - printf("usb_device_send_control returned %d errno: %d\n", ret, errno); - if (ret > 0) { - printf("got MTP string %s\n", buffer); - ret = usb_device_send_control(device, - USB_DIR_IN|USB_RECIP_DEVICE|USB_TYPE_VENDOR, 1, - 0, 4, sizeof(buffer), buffer); - printf("OS descriptor got %d\n", ret); - } else { - printf("no MTP string\n"); - } - } - - // if we got here, then we have a likely MTP or PTP device - - // interface should be followed by three endpoints - struct usb_endpoint_descriptor *ep; - struct usb_endpoint_descriptor *ep_in_desc = NULL; - struct usb_endpoint_descriptor *ep_out_desc = NULL; - struct usb_endpoint_descriptor *ep_intr_desc = NULL; - for (int i = 0; i < 3; i++) { - ep = (struct usb_endpoint_descriptor *)usb_descriptor_iter_next(&iter); - if (!ep || ep->bDescriptorType != USB_DT_ENDPOINT) { - LOGE("endpoints not found\n"); - return mDone; - } - if (ep->bmAttributes == USB_ENDPOINT_XFER_BULK) { - if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) - ep_in_desc = ep; - else - ep_out_desc = ep; - } else if (ep->bmAttributes == USB_ENDPOINT_XFER_INT && - ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { - ep_intr_desc = ep; - } - } - if (!ep_in_desc || !ep_out_desc || !ep_intr_desc) { - LOGE("endpoints not found\n"); - return mDone; - } - - if (usb_device_claim_interface(device, interface->bInterfaceNumber)) { - LOGE("usb_device_claim_interface failed errno: %d\n", errno); - return mDone; - } - - MtpDevice* mtpDevice = new MtpDevice(device, interface->bInterfaceNumber, - ep_in_desc, ep_out_desc, ep_intr_desc); - mDeviceList.add(mtpDevice); - mtpDevice->initialize(); - deviceAdded(mtpDevice); - return mDone; - } - } - - usb_device_close(device); - return mDone; -} - -bool MtpClient::usbDeviceRemoved(const char *devname) { - for (int i = 0; i < mDeviceList.size(); i++) { - MtpDevice* device = mDeviceList[i]; - if (!strcmp(devname, device->getDeviceName())) { - deviceRemoved(device); - mDeviceList.removeAt(i); - delete device; - LOGD("Camera removed!\n"); - break; - } - } - return mDone; -} - -bool MtpClient::usbDiscoveryDone() { - Mutex::Autolock autoLock(mMutex); - mThreadStartCondition.signal(); - return mDone; -} - -bool MtpClient::threadLoop() { - usb_host_run(mUsbHostContext, usb_device_added, usb_device_removed, usb_discovery_done, this); - return false; -} - -int MtpClient::usb_device_added(const char *devname, void* client_data) { - LOGD("usb_device_added %s\n", devname); - return ((MtpClient *)client_data)->usbDeviceAdded(devname); -} - -int MtpClient::usb_device_removed(const char *devname, void* client_data) { - LOGD("usb_device_removed %s\n", devname); - return ((MtpClient *)client_data)->usbDeviceRemoved(devname); -} - -int MtpClient::usb_discovery_done(void* client_data) { - LOGD("usb_discovery_done\n"); - return ((MtpClient *)client_data)->usbDiscoveryDone(); -} - -} // namespace android diff --git a/media/mtp/MtpClient.h b/media/mtp/MtpClient.h deleted file mode 100644 index fa5c527..0000000 --- a/media/mtp/MtpClient.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _MTP_CLIENT_H -#define _MTP_CLIENT_H - -#include "MtpTypes.h" - -#include <utils/threads.h> - -struct usb_host_context; - -namespace android { - -class MtpClientThread; - -class MtpClient { -private: - MtpDeviceList mDeviceList; - MtpClientThread* mThread; - Condition mThreadStartCondition; - Mutex mMutex; - struct usb_host_context* mUsbHostContext; - bool mDone; - -public: - MtpClient(); - virtual ~MtpClient(); - - bool start(); - void stop(); - - inline MtpDeviceList& getDeviceList() { return mDeviceList; } - MtpDevice* getDevice(int id); - - - virtual void deviceAdded(MtpDevice *device) = 0; - virtual void deviceRemoved(MtpDevice *device) = 0; - -private: - // these return true if we should stop monitoring USB and clean up - bool usbDeviceAdded(const char *devname); - bool usbDeviceRemoved(const char *devname); - bool usbDiscoveryDone(); - - friend class MtpClientThread; - bool threadLoop(); - static int usb_device_added(const char *devname, void* client_data); - static int usb_device_removed(const char *devname, void* client_data); - static int usb_discovery_done(void* client_data); -}; - -}; // namespace android - -#endif // _MTP_CLIENT_H diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp index d22c72f..4383b5f 100644 --- a/media/mtp/MtpDevice.cpp +++ b/media/mtp/MtpDevice.cpp @@ -38,6 +38,121 @@ namespace android { +static bool isMtpDevice(uint16_t vendor, uint16_t product) { + // Sandisk Sansa Fuze + if (vendor == 0x0781 && product == 0x74c2) + return true; + // Samsung YP-Z5 + if (vendor == 0x04e8 && product == 0x503c) + return true; + return false; +} + +MtpDevice* MtpDevice::open(const char* deviceName, int fd) { + struct usb_device *device = usb_device_new(deviceName, fd); + if (!device) { + LOGE("usb_device_new failed for %s", deviceName); + return NULL; + } + + struct usb_descriptor_header* desc; + struct usb_descriptor_iter iter; + + usb_descriptor_iter_init(device, &iter); + + while ((desc = usb_descriptor_iter_next(&iter)) != NULL) { + if (desc->bDescriptorType == USB_DT_INTERFACE) { + struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc; + + if (interface->bInterfaceClass == USB_CLASS_STILL_IMAGE && + interface->bInterfaceSubClass == 1 && // Still Image Capture + interface->bInterfaceProtocol == 1) // Picture Transfer Protocol (PIMA 15470) + { + LOGD("Found camera: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device), + usb_device_get_product_name(device)); + } else if (interface->bInterfaceClass == 0xFF && + interface->bInterfaceSubClass == 0xFF && + interface->bInterfaceProtocol == 0) { + char* interfaceName = usb_device_get_string(device, interface->iInterface); + if (!interfaceName || strcmp(interfaceName, "MTP")) + continue; + // Looks like an android style MTP device + LOGD("Found MTP device: \"%s\" \"%s\"\n", usb_device_get_manufacturer_name(device), + usb_device_get_product_name(device)); + } else { + // look for special cased devices based on vendor/product ID + // we are doing this mainly for testing purposes + uint16_t vendor = usb_device_get_vendor_id(device); + uint16_t product = usb_device_get_product_id(device); + if (!isMtpDevice(vendor, product)) { + // not an MTP or PTP device + continue; + } + // request MTP OS string and descriptor + // some music players need to see this before entering MTP mode. + char buffer[256]; + memset(buffer, 0, sizeof(buffer)); + int ret = usb_device_control_transfer(device, + USB_DIR_IN|USB_RECIP_DEVICE|USB_TYPE_STANDARD, + USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) | 0xEE, + 0, buffer, sizeof(buffer), 0); + printf("usb_device_control_transfer returned %d errno: %d\n", ret, errno); + if (ret > 0) { + printf("got MTP string %s\n", buffer); + ret = usb_device_control_transfer(device, + USB_DIR_IN|USB_RECIP_DEVICE|USB_TYPE_VENDOR, 1, + 0, 4, buffer, sizeof(buffer), 0); + printf("OS descriptor got %d\n", ret); + } else { + printf("no MTP string\n"); + } + } + + // if we got here, then we have a likely MTP or PTP device + + // interface should be followed by three endpoints + struct usb_endpoint_descriptor *ep; + struct usb_endpoint_descriptor *ep_in_desc = NULL; + struct usb_endpoint_descriptor *ep_out_desc = NULL; + struct usb_endpoint_descriptor *ep_intr_desc = NULL; + for (int i = 0; i < 3; i++) { + ep = (struct usb_endpoint_descriptor *)usb_descriptor_iter_next(&iter); + if (!ep || ep->bDescriptorType != USB_DT_ENDPOINT) { + LOGE("endpoints not found\n"); + return NULL; + } + if (ep->bmAttributes == USB_ENDPOINT_XFER_BULK) { + if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) + ep_in_desc = ep; + else + ep_out_desc = ep; + } else if (ep->bmAttributes == USB_ENDPOINT_XFER_INT && + ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { + ep_intr_desc = ep; + } + } + if (!ep_in_desc || !ep_out_desc || !ep_intr_desc) { + LOGE("endpoints not found\n"); + return NULL; + } + + if (usb_device_claim_interface(device, interface->bInterfaceNumber)) { + LOGE("usb_device_claim_interface failed errno: %d\n", errno); + return NULL; + } + + MtpDevice* mtpDevice = new MtpDevice(device, interface->bInterfaceNumber, + ep_in_desc, ep_out_desc, ep_intr_desc); + mtpDevice->initialize(); + return mtpDevice; + } + } + + usb_device_close(device); + LOGE("device not found"); + return NULL; +} + MtpDevice::MtpDevice(struct usb_device* device, int interface, const struct usb_endpoint_descriptor *ep_in, const struct usb_endpoint_descriptor *ep_out, @@ -49,7 +164,6 @@ MtpDevice::MtpDevice(struct usb_device* device, int interface, mRequestOut(NULL), mRequestIntr(NULL), mDeviceInfo(NULL), - mID(usb_device_get_unique_id(device)), mSessionID(0), mTransactionID(0), mReceivedResponse(false) @@ -430,6 +544,98 @@ MtpProperty* MtpDevice::getObjectPropDesc(MtpObjectProperty code, MtpObjectForma return NULL; } +bool MtpDevice::readObject(MtpObjectHandle handle, + bool (* callback)(void* data, int offset, int length, void* clientData), + int objectSize, void* clientData) { + Mutex::Autolock autoLock(mMutex); + bool result = false; + + mRequest.reset(); + mRequest.setParameter(1, handle); + if (sendRequest(MTP_OPERATION_GET_OBJECT) + && mData.readDataHeader(mRequestIn1)) { + uint32_t length = mData.getContainerLength(); + if (length - MTP_CONTAINER_HEADER_SIZE != objectSize) { + LOGE("readObject error objectSize: %d, length: %d", + objectSize, length); + goto fail; + } + length -= MTP_CONTAINER_HEADER_SIZE; + uint32_t remaining = length; + int offset = 0; + + int initialDataLength = 0; + void* initialData = mData.getData(initialDataLength); + if (initialData) { + if (initialDataLength > 0) { + if (!callback(initialData, 0, initialDataLength, clientData)) + goto fail; + remaining -= initialDataLength; + offset += initialDataLength; + } + free(initialData); + } + + // USB reads greater than 16K don't work + char buffer1[16384], buffer2[16384]; + mRequestIn1->buffer = buffer1; + mRequestIn2->buffer = buffer2; + struct usb_request* req = mRequestIn1; + void* writeBuffer = NULL; + int writeLength = 0; + + while (remaining > 0 || writeBuffer) { + if (remaining > 0) { + // queue up a read request + req->buffer_length = (remaining > sizeof(buffer1) ? sizeof(buffer1) : remaining); + if (mData.readDataAsync(req)) { + LOGE("readDataAsync failed"); + goto fail; + } + } else { + req = NULL; + } + + if (writeBuffer) { + // write previous buffer + if (!callback(writeBuffer, offset, writeLength, clientData)) { + LOGE("write failed"); + // wait for pending read before failing + if (req) + mData.readDataWait(mDevice); + goto fail; + } + offset += writeLength; + writeBuffer = NULL; + } + + // wait for read to complete + if (req) { + int read = mData.readDataWait(mDevice); + if (read < 0) + goto fail; + + if (read > 0) { + writeBuffer = req->buffer; + writeLength = read; + remaining -= read; + req = (req == mRequestIn1 ? mRequestIn2 : mRequestIn1); + } else { + writeBuffer = NULL; + } + } + } + + MtpResponseCode response = readResponse(); + if (response == MTP_RESPONSE_OK) + result = true; + } + +fail: + return result; +} + + // reads the object's data and writes it to the specified file path bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath, int group, int perm) { LOGD("readObject: %s", destPath); @@ -507,10 +713,14 @@ bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath, int gro if (read < 0) goto fail; - writeBuffer = req->buffer; - writeLength = read; - remaining -= read; - req = (req == mRequestIn1 ? mRequestIn2 : mRequestIn1); + if (read > 0) { + writeBuffer = req->buffer; + writeLength = read; + remaining -= read; + req = (req == mRequestIn1 ? mRequestIn2 : mRequestIn1); + } else { + writeBuffer = NULL; + } } } diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h index d0a0fb3..b69203e 100644 --- a/media/mtp/MtpDevice.h +++ b/media/mtp/MtpDevice.h @@ -45,9 +45,6 @@ private: MtpDeviceInfo* mDeviceInfo; MtpPropertyList mDeviceProperties; - // a unique ID for the device - int mID; - // current session ID MtpSessionID mSessionID; // current transaction ID @@ -67,9 +64,10 @@ public: const struct usb_endpoint_descriptor *ep_in, const struct usb_endpoint_descriptor *ep_out, const struct usb_endpoint_descriptor *ep_intr); - virtual ~MtpDevice(); - inline int getID() const { return mID; } + static MtpDevice* open(const char* deviceName, int fd); + + virtual ~MtpDevice(); void initialize(); void close(); @@ -97,7 +95,11 @@ public: MtpProperty* getDevicePropDesc(MtpDeviceProperty code); MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format); - bool readObject(MtpObjectHandle handle, const char* destPath, int group, + bool readObject(MtpObjectHandle handle, + bool (* callback)(void* data, int offset, + int length, void* clientData), + int objectSize, void* clientData); + bool readObject(MtpObjectHandle handle, const char* destPath, int group, int perm); private: diff --git a/services/audioflinger/AudioPolicyManagerBase.cpp b/services/audioflinger/AudioPolicyManagerBase.cpp index 2c81c34..e84d136 100644 --- a/services/audioflinger/AudioPolicyManagerBase.cpp +++ b/services/audioflinger/AudioPolicyManagerBase.cpp @@ -19,6 +19,7 @@ #include <utils/Log.h> #include <hardware_legacy/AudioPolicyManagerBase.h> #include <media/mediarecorder.h> +#include <math.h> namespace android { @@ -1019,6 +1020,8 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien mForceUse[i] = AudioSystem::FORCE_NONE; } + initializeVolumeCurves(); + // devices available by default are speaker, ear piece and microphone mAvailableOutputDevices = AudioSystem::DEVICE_OUT_EARPIECE | AudioSystem::DEVICE_OUT_SPEAKER; @@ -1810,6 +1813,62 @@ audio_io_handle_t AudioPolicyManagerBase::getActiveInput() return 0; } +float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc, + int indexInUi) { + // the volume index in the UI is relative to the min and max volume indices for this stream type + int nbSteps = 1 + streamDesc.mVolIndex[StreamDescriptor::VOLMAX] - + streamDesc.mVolIndex[StreamDescriptor::VOLMIN]; + int volIdx = (nbSteps * (indexInUi - streamDesc.mIndexMin)) / + (streamDesc.mIndexMax - streamDesc.mIndexMin); + + // find what part of the curve this index volume belongs to, or if it's out of bounds + int segment = 0; + if (volIdx < streamDesc.mVolIndex[StreamDescriptor::VOLMIN]) { // out of bounds + return 0.0f; + } else if (volIdx < streamDesc.mVolIndex[StreamDescriptor::VOLKNEE1]) { + segment = 0; + } else if (volIdx < streamDesc.mVolIndex[StreamDescriptor::VOLKNEE2]) { + segment = 1; + } else if (volIdx <= streamDesc.mVolIndex[StreamDescriptor::VOLMAX]) { + segment = 2; + } else { // out of bounds + return 1.0f; + } + + // linear interpolation in the attenuation table in dB + float decibels = streamDesc.mVolDbAtt[segment] + + ((float)(volIdx - streamDesc.mVolIndex[segment])) * + ( (streamDesc.mVolDbAtt[segment+1] - streamDesc.mVolDbAtt[segment]) / + ((float)(streamDesc.mVolIndex[segment+1] - streamDesc.mVolIndex[segment])) ); + + float amplification = exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 ) + + LOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f", + streamDesc.mVolIndex[segment], volIdx, streamDesc.mVolIndex[segment+1], + streamDesc.mVolDbAtt[segment], decibels, streamDesc.mVolDbAtt[segment+1], + amplification); + + return amplification; +} + +void AudioPolicyManagerBase::initializeVolumeCurves() { + // initialize the volume curves to a (-49.5 - 0 dB) attenuation in 0.5dB steps + for (int i=0 ; i< AudioSystem::NUM_STREAM_TYPES ; i++) { + mStreams[i].mVolIndex[StreamDescriptor::VOLMIN] = 1; + mStreams[i].mVolDbAtt[StreamDescriptor::VOLMIN] = -49.5f; + mStreams[i].mVolIndex[StreamDescriptor::VOLKNEE1] = 33; + mStreams[i].mVolDbAtt[StreamDescriptor::VOLKNEE1] = -33.5f; + mStreams[i].mVolIndex[StreamDescriptor::VOLKNEE2] = 66; + mStreams[i].mVolDbAtt[StreamDescriptor::VOLKNEE2] = -17.0f; + // here we use 100 steps to avoid rounding errors + // when computing the volume in volIndexToAmpl() + mStreams[i].mVolIndex[StreamDescriptor::VOLMAX] = 100; + mStreams[i].mVolDbAtt[StreamDescriptor::VOLMAX] = 0.0f; + } + + // TODO add modifications for music to have finer steps below knee1 and above knee2 +} + float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device) { float volume = 1.0; @@ -1820,8 +1879,7 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand device = outputDesc->device(); } - int volInt = (100 * (index - streamDesc.mIndexMin)) / (streamDesc.mIndexMax - streamDesc.mIndexMin); - volume = AudioSystem::linearToLog(volInt); + volume = volIndexToAmpl(device, streamDesc, index); // if a headset is connected, apply the following rules to ring tones and notifications // to avoid sound level bursts in user's ears: |