AudioPolicyService.cpp revision 57dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfc
165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/* 265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Copyright (C) 2009 The Android Open Source Project 365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * you may not use this file except in compliance with the License. 665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * You may obtain a copy of the License at 765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * 1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Unless required by applicable law or agreed to in writing, software 1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * See the License for the specific language governing permissions and 1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * limitations under the License. 1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian */ 1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define LOG_TAG "AudioPolicyService" 1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian//#define LOG_NDEBUG 0 1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#undef __STRICT_ANSI__ 2165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define __STDINT_LIMITS 2265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define __STDC_LIMIT_MACROS 2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <stdint.h> 2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/time.h> 2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IServiceManager.h> 2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Log.h> 2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/properties.h> 2965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IPCThreadState.h> 3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/String16.h> 3165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h> 3265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioPolicyService.h" 3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/properties.h> 3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <dlfcn.h> 3565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <hardware_legacy/power.h> 367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/AudioEffect.h> 377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/EffectsFactoryApi.h> 3865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 39fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/hardware.h> 4064760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h> 417394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <system/audio_policy.h> 42fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/audio_policy.h> 437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <audio_effects/audio_effects_conf.h> 44fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android { 4665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const char *kDeadlockedString = "AudioPolicyService may be deadlocked\n"; 4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const char *kCmdDeadlockedString = "AudioPolicyService command thread may be deadlocked\n"; 4965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const int kDumpLockRetries = 50; 5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic const int kDumpLockSleep = 20000; 5265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic bool checkPermission() { 5465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (getpid() == IPCThreadState::self()->getCallingPid()) return true; 5565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool ok = checkCallingPermission(String16("android.permission.MODIFY_AUDIO_SETTINGS")); 5665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!ok) LOGE("Request requires android.permission.MODIFY_AUDIO_SETTINGS"); 5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ok; 5865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 5965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 60fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinnamespace { 61fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin extern struct audio_policy_service_ops aps_ops; 62fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin}; 63fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 6465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 6665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioPolicyService() 67fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin : BnAudioPolicyService() , mpAudioPolicyDev(NULL) , mpAudioPolicy(NULL) 6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char value[PROPERTY_VALUE_MAX]; 70fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const struct hw_module_t *module; 71fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int forced_val; 72fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int rc; 7365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent Mutex::Autolock _l(mLock); 75935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent 7665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // start tone playback thread 7765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mTonePlaybackThread = new AudioCommandThread(String8("")); 7865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // start audio commands thread 7965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommandThread = new AudioCommandThread(String8("ApmCommandThread")); 8065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 81fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin /* instantiate the audio policy manager */ 82fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module); 83fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (rc) 84fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return; 8565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 86fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin rc = audio_policy_dev_open(module, &mpAudioPolicyDev); 87fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc)); 88fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (rc) 89fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return; 90935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent 91fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this, 92fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin &mpAudioPolicy); 93fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc)); 94fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (rc) 95fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return; 96fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 97fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin rc = mpAudioPolicy->init_check(mpAudioPolicy); 98fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc)); 99fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (rc) 100fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return; 101fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 102fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin property_get("ro.camera.sound.forced", value, "0"); 103fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin forced_val = strtol(value, NULL, 0); 104fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->set_can_mute_enforced_audible(mpAudioPolicy, !forced_val); 105fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 106fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGI("Loaded audio policy from %s (%s)", module->name, module->id); 1077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 1087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // load audio pre processing modules 1097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) { 1107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadPreProcessorConfig(AUDIO_EFFECT_VENDOR_CONFIG_FILE); 1117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (access(AUDIO_EFFECT_DEFAULT_CONFIG_FILE, R_OK) == 0) { 1127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadPreProcessorConfig(AUDIO_EFFECT_DEFAULT_CONFIG_FILE); 1137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 11565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 11665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::~AudioPolicyService() 11765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 11865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mTonePlaybackThread->exit(); 11965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mTonePlaybackThread.clear(); 12065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommandThread->exit(); 12165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommandThread.clear(); 12265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 1247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // release audio pre processing resources 1257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < mInputSources.size(); i++) { 1267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputSourceDesc *source = mInputSources.valueAt(i); 1277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector <EffectDesc *> effects = source->mEffects; 1287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t j = 0; j < effects.size(); j++) { 1297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete effects[j]->mName; 1307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector <effect_param_t *> params = effects[j]->mParams; 1317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t k = 0; k < params.size(); k++) { 1327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete params[k]; 1337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 1347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent params.clear(); 1357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete effects[j]; 1367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 1377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effects.clear(); 1387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete source; 1397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 1407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputSources.clear(); 1417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 1427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < mInputs.size(); i++) { 1437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputs.valueAt(i)->mEffects.clear(); 1447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete mInputs.valueAt(i); 1457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 1467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputs.clear(); 1477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 148fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy && mpAudioPolicyDev) 149fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy); 150fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicyDev) 151fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_dev_close(mpAudioPolicyDev); 15265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 15365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 154fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, 155fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_dev_state_t state, 15665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const char *device_address) 15765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 158fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 15965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 16065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 16165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 16265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 16365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 164fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (!audio_is_output_device(device) && !audio_is_input_device(device)) { 16565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 16665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 167fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && 168fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { 16965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 17065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 17165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 17265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("setDeviceConnectionState() tid %d", gettid()); 17365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 174fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->set_device_connection_state(mpAudioPolicy, device, 175fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin state, device_address); 17665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 17765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 178fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( 179fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_devices_t device, 180de070137f11d346fba77605bd76a44c040a618fcEric Laurent const char *device_address) 18165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 182fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 183fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; 18465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 18565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 186fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; 18765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 188fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_device_connection_state(mpAudioPolicy, device, 189fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin device_address); 19065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 19265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::setPhoneState(int state) 19365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 194fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 19565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 19665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 19965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 200fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (state < 0 || state >= AUDIO_MODE_CNT) { 20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 20265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 20465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("setPhoneState() tid %d", gettid()); 20565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 20665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // TODO: check if it is more appropriate to do it in platform specific policy manager 20765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioSystem::setMode(state); 20865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 20965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 210fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->set_phone_state(mpAudioPolicy, state); 21165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 21265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 21365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 21465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::setRingerMode(uint32_t mode, uint32_t mask) 21565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 216fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 21765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 21965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 22065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 22165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 22265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 223fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->set_ringer_mode(mpAudioPolicy, mode, mask); 22465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 22565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 22665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 227fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, 228fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_forced_cfg_t config) 22965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 230fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 23165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 23265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 23365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 23465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 23565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 236fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { 23765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 23865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 239fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { 24065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 24165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 24265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("setForceUse() tid %d", gettid()); 24365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 244fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->set_force_use(mpAudioPolicy, usage, config); 24565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 24665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 24765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 248fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) 24965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 250fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 251fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return AUDIO_POLICY_FORCE_NONE; 25265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 25365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 254fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return AUDIO_POLICY_FORCE_NONE; 25565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 256fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { 257fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return AUDIO_POLICY_FORCE_NONE; 25865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 259fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_force_use(mpAudioPolicy, usage); 26065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 26165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 262fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinaudio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream, 26365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t samplingRate, 26465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t format, 26565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t channels, 266fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_output_flags_t flags) 26765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 268fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 26965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 27065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 27165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("getOutput() tid %d", gettid()); 27265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 273fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate, format, channels, flags); 27465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 27565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 276de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::startOutput(audio_io_handle_t output, 277fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream, 278de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session) 27965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 280fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 28165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 28265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 28365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("startOutput() tid %d", gettid()); 28465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 285fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->start_output(mpAudioPolicy, output, stream, session); 28665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 28765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 288de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::stopOutput(audio_io_handle_t output, 289fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream, 290de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session) 29165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 292fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 29365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 29465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 29565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("stopOutput() tid %d", gettid()); 29665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 297fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->stop_output(mpAudioPolicy, output, stream, session); 29865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 29965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 30065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::releaseOutput(audio_io_handle_t output) 30165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 302fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 30365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return; 30465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 30565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("releaseOutput() tid %d", gettid()); 30665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 307fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->release_output(mpAudioPolicy, output); 30865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 30965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 31065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianaudio_io_handle_t AudioPolicyService::getInput(int inputSource, 31165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t samplingRate, 31265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t format, 31365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t channels, 3147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_in_acoustics_t acoustics, 3157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int audioSession) 31665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 317fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 31865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 31965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 32065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 3217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_io_handle_t input = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate, 3227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent format, channels, acoustics); 3237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 3247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (input == 0) { 3257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return input; 3267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // create audio pre processors according to input source 3287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent ssize_t index = mInputSources.indexOfKey((audio_source_t)inputSource); 3297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (index < 0) { 3307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return input; 3317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent ssize_t idx = mInputs.indexOfKey(input); 3337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputDesc *inputDesc; 3347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (idx < 0) { 3357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent inputDesc = new InputDesc(); 3367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent inputDesc->mSessionId = audioSession; 3377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputs.add(input, inputDesc); 3387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else { 3397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent inputDesc = mInputs.valueAt(idx); 3407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 3427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects; 3437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < effects.size(); i++) { 3447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = effects[i]; 3457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent sp<AudioEffect> fx = new AudioEffect(NULL, &effect->mUuid, -1, 0, 0, audioSession, input); 3467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent status_t status = fx->initCheck(); 3477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (status != NO_ERROR && status != ALREADY_EXISTS) { 3487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("Failed to create Fx %s on input %d", effect->mName, input); 3497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // fx goes out of scope and strong ref on AudioEffect is released 3507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 3517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t j = 0; j < effect->mParams.size(); j++) { 3537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx->setParameter(effect->mParams[j]); 3547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent inputDesc->mEffects.add(fx); 3567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent setPreProcessorEnabled(inputDesc, true); 3587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return input; 35965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 36065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 36165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::startInput(audio_io_handle_t input) 36265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 363fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 36465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 36565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 36665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 3677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 368fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->start_input(mpAudioPolicy, input); 36965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 37065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 37165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::stopInput(audio_io_handle_t input) 37265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 373fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 37465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 37565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 3777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 378fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->stop_input(mpAudioPolicy, input); 37965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 38065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 38165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::releaseInput(audio_io_handle_t input) 38265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 383fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 38465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return; 38565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 38665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 387fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->release_input(mpAudioPolicy, input); 3887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 3897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent ssize_t index = mInputs.indexOfKey(input); 3907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (index < 0) { 3917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return; 3927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 3937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputDesc *inputDesc = mInputs.valueAt(index); 3947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent setPreProcessorEnabled(inputDesc, false); 3957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent inputDesc->mEffects.clear(); 3967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete inputDesc; 3977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputs.removeItemsAt(index); 39865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 39965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 400fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, 40165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int indexMin, 40265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int indexMax) 40365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 404fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 40565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 40665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 40765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 40865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 40965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 410fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (stream < 0 || stream >= AUDIO_STREAM_CNT) { 41165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 41265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 413fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax); 41465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 41565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 41665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 417fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, int index) 41865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 419fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 42065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 42165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 42265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 42365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 42465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 425fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (stream < 0 || stream >= AUDIO_STREAM_CNT) { 42665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 42765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 42865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 429fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index); 43065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 43165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 432fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatus_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, int *index) 43365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 434fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 43565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_INIT; 43665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 43765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!checkPermission()) { 43865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 43965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 440fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (stream < 0 || stream >= AUDIO_STREAM_CNT) { 44165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 44265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 443fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index); 44465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 44565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 446fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinuint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) 447de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 448fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 449de070137f11d346fba77605bd76a44c040a618fcEric Laurent return 0; 450de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 451fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream); 452de070137f11d346fba77605bd76a44c040a618fcEric Laurent} 453de070137f11d346fba77605bd76a44c040a618fcEric Laurent 454fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinuint32_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) 4556b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten{ 456fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 4576b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten return 0; 4586b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten } 459fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream); 4606b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten} 4616b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten 462de070137f11d346fba77605bd76a44c040a618fcEric Laurentaudio_io_handle_t AudioPolicyService::getOutputForEffect(effect_descriptor_t *desc) 463de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 464fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 465de070137f11d346fba77605bd76a44c040a618fcEric Laurent return NO_INIT; 466de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 467de070137f11d346fba77605bd76a44c040a618fcEric Laurent Mutex::Autolock _l(mLock); 468fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc); 469de070137f11d346fba77605bd76a44c040a618fcEric Laurent} 470de070137f11d346fba77605bd76a44c040a618fcEric Laurent 471de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::registerEffect(effect_descriptor_t *desc, 4727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_io_handle_t io, 473de070137f11d346fba77605bd76a44c040a618fcEric Laurent uint32_t strategy, 474de070137f11d346fba77605bd76a44c040a618fcEric Laurent int session, 475de070137f11d346fba77605bd76a44c040a618fcEric Laurent int id) 476de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 477fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 478de070137f11d346fba77605bd76a44c040a618fcEric Laurent return NO_INIT; 479de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 4807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id); 481de070137f11d346fba77605bd76a44c040a618fcEric Laurent} 482de070137f11d346fba77605bd76a44c040a618fcEric Laurent 483de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::unregisterEffect(int id) 484de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 485fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 486de070137f11d346fba77605bd76a44c040a618fcEric Laurent return NO_INIT; 487de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 488fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->unregister_effect(mpAudioPolicy, id); 489de070137f11d346fba77605bd76a44c040a618fcEric Laurent} 490de070137f11d346fba77605bd76a44c040a618fcEric Laurent 491eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurentbool AudioPolicyService::isStreamActive(int stream, uint32_t inPastMs) const 492eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent{ 493fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy == NULL) { 494eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent return 0; 495eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent } 496eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent Mutex::Autolock _l(mLock); 497fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs); 498eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent} 499eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent 50057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurentstatus_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, 50157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent effect_descriptor_t *descriptors, 50257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent uint32_t *count) 50357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent{ 50457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent 50557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent if (mpAudioPolicy == NULL) { 50657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent *count = 0; 50757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent return NO_INIT; 50857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 50957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent Mutex::Autolock _l(mLock); 51057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent status_t status = NO_ERROR; 51157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent 51257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent size_t index; 51357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent for (index = 0; index < mInputs.size(); index++) { 51457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent if (mInputs.valueAt(index)->mSessionId == audioSession) { 51557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent break; 51657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 51757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 51857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent if (index == mInputs.size()) { 51957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent *count = 0; 52057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent return BAD_VALUE; 52157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 52257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects; 52357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent 52457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent for (size_t i = 0; i < effects.size(); i++) { 52557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent effect_descriptor_t desc = effects[i]->descriptor(); 52657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent if (i < *count) { 52757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent memcpy(descriptors + i, &desc, sizeof(effect_descriptor_t)); 52857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 52957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 53057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent if (effects.size() > *count) { 53157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent status = NO_MEMORY; 53257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent } 53357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent *count = effects.size(); 53457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent return status; 53557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent} 53657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent 53765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::binderDied(const wp<IBinder>& who) { 538de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGW("binderDied() %p, tid %d, calling tid %d", who.unsafe_get(), gettid(), 539de070137f11d346fba77605bd76a44c040a618fcEric Laurent IPCThreadState::self()->getCallingPid()); 54065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 54165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 54265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic bool tryLock(Mutex& mutex) 54365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 54465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = false; 54565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < kDumpLockRetries; ++i) { 54665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mutex.tryLock() == NO_ERROR) { 54765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian locked = true; 54865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 54965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian usleep(kDumpLockSleep); 55165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return locked; 55365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 55465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 55565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpInternals(int fd) 55665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 55765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 55865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 55965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 56065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 561fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy); 56265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 56365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get()); 56465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 56565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get()); 56665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 56765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 56965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 57065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 57265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dump(int fd, const Vector<String16>& args) 57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (checkCallingPermission(String16("android.permission.DUMP")) == false) { 57565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpPermissionDenial(fd); 57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 57765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = tryLock(mLock); 57865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 57965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kDeadlockedString); 58065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 58165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 58265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 58365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpInternals(fd); 58465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommandThread != NULL) { 58565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommandThread->dump(fd); 58665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 58765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mTonePlaybackThread != NULL) { 58865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mTonePlaybackThread->dump(fd); 58965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 59065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 591fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy) { 592fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->dump(mpAudioPolicy, fd); 59365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 59565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (locked) mLock.unlock(); 59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 59765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 59865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 59965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 60065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpPermissionDenial(int fd) 60165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 60265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 60365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 60465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 60565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Permission Denial: " 60665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian "can't dump AudioPolicyService from pid=%d, uid=%d\n", 60765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingPid(), 60865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingUid()); 60965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 61165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 61265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 61365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 6147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentvoid AudioPolicyService::setPreProcessorEnabled(InputDesc *inputDesc, bool enabled) 6157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 6167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects; 6177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < fxVector.size(); i++) { 6187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent sp<AudioEffect> fx = fxVector.itemAt(i); 6197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx->setEnabled(enabled); 6207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 6217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 6227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 62365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::onTransact( 62465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 62565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 62665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BnAudioPolicyService::onTransact(code, data, reply, flags); 62765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 62865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 62965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------- AudioPolicyService::AudioCommandThread implementation ---------- 63165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name) 63365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian : Thread(false), mName(name) 63465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 63565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = NULL; 63665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 63765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::~AudioCommandThread() 64065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 64165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && !mAudioCommands.isEmpty()) { 64265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian release_wake_lock(mName.string()); 64365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 64465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.clear(); 64565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) delete mpToneGenerator; 64665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 64765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 64865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::onFirstRef() 64965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 65065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "") { 65165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian run(mName.string(), ANDROID_PRIORITY_AUDIO); 65265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 65365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian run("AudioCommandThread", ANDROID_PRIORITY_AUDIO); 65465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 65565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 65665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 65765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioPolicyService::AudioCommandThread::threadLoop() 65865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 65965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian nsecs_t waitTime = INT64_MAX; 66065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 66165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 66265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!exitPending()) 66365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 66465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while(!mAudioCommands.isEmpty()) { 66565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian nsecs_t curTime = systemTime(); 66665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // commands are sorted by increasing time stamp: execute them from index 0 and up 66765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommands[0]->mTime <= curTime) { 66865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = mAudioCommands[0]; 66965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.removeAt(0); 67065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLastCommand = *command; 67165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 67265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian switch (command->mCommand) { 67365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case START_TONE: { 67465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 67565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ToneData *data = (ToneData *)command->mParam; 67665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() processing start tone %d on stream %d", 67765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mType, data->mStream); 67865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) 67965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete mpToneGenerator; 68065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = new ToneGenerator(data->mStream, 1.0); 68165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator->startTone(data->mType); 68265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 68365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 68465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 68565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case STOP_TONE: { 68665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 68765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() processing stop tone"); 68865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) { 68965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator->stopTone(); 69065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete mpToneGenerator; 69165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = NULL; 69265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 69365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 69465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 69565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOLUME: { 69665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = (VolumeData *)command->mParam; 697de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set volume stream %d, \ 698de070137f11d346fba77605bd76a44c040a618fcEric Laurent volume %f, output %d", data->mStream, data->mVolume, data->mIO); 699de070137f11d346fba77605bd76a44c040a618fcEric Laurent command->mStatus = AudioSystem::setStreamVolume(data->mStream, 700de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mVolume, 701de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mIO); 70265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 70365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 70465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 70565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 70665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 70765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 70865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_PARAMETERS: { 70965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = (ParametersData *)command->mParam; 710de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set parameters string %s, io %d", 711de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mKeyValuePairs.string(), data->mIO); 71265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); 71365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 71465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 71565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 71665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 71765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 71865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 71965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOICE_VOLUME: { 72065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VoiceVolumeData *data = (VoiceVolumeData *)command->mParam; 721de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set voice volume volume %f", 722de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mVolume); 72365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); 72465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 72565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 72665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 72765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 72865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 72965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 73065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian default: 73165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGW("AudioCommandThread() unknown command %d", command->mCommand); 73265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 73365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete command; 73465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian waitTime = INT64_MAX; 73565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 73665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian waitTime = mAudioCommands[0]->mTime - curTime; 73765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 73865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 73965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 74065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // release delayed commands wake lock 74165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && mAudioCommands.isEmpty()) { 74265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian release_wake_lock(mName.string()); 74365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 74465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() going to sleep"); 74565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.waitRelative(mLock, waitTime); 74665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() waking up"); 74765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 74865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 74965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return false; 75065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 75165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 75265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::AudioCommandThread::dump(int fd) 75365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 75465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 75565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 75665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 75765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 75865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); 75965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 76065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 76165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 76265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = tryLock(mLock); 76365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 76465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result2(kCmdDeadlockedString); 76565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result2.string(), result2.size()); 76665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 76765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 76865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "- Commands:\n"); 76965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result = String8(buffer); 77065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(" Command Time Wait pParam\n"); 77165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < (int)mAudioCommands.size(); i++) { 77265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands[i]->dump(buffer, SIZE); 77365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 77465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 77565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(" Last Command\n"); 77665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLastCommand.dump(buffer, SIZE); 77765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 77865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 77965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 78065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (locked) mLock.unlock(); 78265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 78465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 78565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::startToneCommand(int type, int stream) 78765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 78865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 78965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = START_TONE; 79065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ToneData *data = new ToneData(); 79165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mType = type; 79265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mStream = stream; 79365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = (void *)data; 79465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 79565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 79665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command); 79765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream); 79865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 79965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 80065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 80165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::stopToneCommand() 80265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 80365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 80465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = STOP_TONE; 80565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = NULL; 80665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 80765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 80865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command); 80965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding tone stop"); 81065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 81165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 81265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 813de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::AudioCommandThread::volumeCommand(int stream, 814de070137f11d346fba77605bd76a44c040a618fcEric Laurent float volume, 815de070137f11d346fba77605bd76a44c040a618fcEric Laurent int output, 816de070137f11d346fba77605bd76a44c040a618fcEric Laurent int delayMs) 81765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 81865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 81965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 82065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 82165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_VOLUME; 82265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = new VolumeData(); 82365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mStream = stream; 82465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mVolume = volume; 82565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mIO = output; 82665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 82765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 82865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 82965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 83065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 83165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 83265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 83365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 834de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", 835de070137f11d346fba77605bd76a44c040a618fcEric Laurent stream, volume, output); 83665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 83765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 83865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 83965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 84065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 84165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 84265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 84365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 84465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 845de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::AudioCommandThread::parametersCommand(int ioHandle, 846fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keyValuePairs, 847de070137f11d346fba77605bd76a44c040a618fcEric Laurent int delayMs) 84865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 84965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 85065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 85165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 85265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_PARAMETERS; 85365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = new ParametersData(); 85465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mIO = ioHandle; 855fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin data->mKeyValuePairs = String8(keyValuePairs); 85665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 85765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 85865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 85965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 86065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 86165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 86265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 86365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 864de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", 865fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin keyValuePairs, ioHandle, delayMs); 86665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 86765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 86865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 86965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 87065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 87165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 87265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 87365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 87465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) 87665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 87765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 87865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 88065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_VOICE_VOLUME; 88165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VoiceVolumeData *data = new VoiceVolumeData(); 88265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mVolume = volume; 88365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 88465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 88565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 88665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 88765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 88865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 88965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 89065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 89165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding set voice volume volume %f", volume); 89265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 89365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 89465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 89565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 89665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 89765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 89865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 89965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 90065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 90165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// insertCommand_l() must be called with mLock held 90265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::insertCommand_l(AudioCommand *command, int delayMs) 90365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 90465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ssize_t i; 90565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Vector <AudioCommand *> removedCommands; 90665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 90765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mTime = systemTime() + milliseconds(delayMs); 90865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 90965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // acquire wake lock to make sure delayed commands are processed 91065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && mAudioCommands.isEmpty()) { 91165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); 91265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 91365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 91465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check same pending commands with later time stamps and eliminate them 91565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (i = mAudioCommands.size()-1; i >= 0; i--) { 91665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command2 = mAudioCommands[i]; 91765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands 91865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command2->mTime <= command->mTime) break; 91965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command2->mCommand != command->mCommand) continue; 92065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 92165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian switch (command->mCommand) { 92265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_PARAMETERS: { 92365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = (ParametersData *)command->mParam; 92465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data2 = (ParametersData *)command2->mParam; 92565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mIO != data2->mIO) break; 926de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("Comparing parameter command %s to new command %s", 927de070137f11d346fba77605bd76a44c040a618fcEric Laurent data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); 92865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioParameter param = AudioParameter(data->mKeyValuePairs); 92965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); 93065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t j = 0; j < param.size(); j++) { 93165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 key; 93265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 value; 93365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param.getAt(j, key, value); 93465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t k = 0; k < param2.size(); k++) { 93565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 key2; 93665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 value2; 93765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param2.getAt(k, key2, value2); 93865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (key2 == key) { 93965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param2.remove(key2); 94065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("Filtering out parameter %s", key2.string()); 94165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 94265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // if all keys have been filtered out, remove the command. 94665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // otherwise, update the key value pairs 94765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (param2.size() == 0) { 94865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.add(command2); 94965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 95065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data2->mKeyValuePairs = param2.toString(); 95165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 95265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } break; 95365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 95465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOLUME: { 95565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = (VolumeData *)command->mParam; 95665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data2 = (VolumeData *)command2->mParam; 95765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mIO != data2->mIO) break; 95865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mStream != data2->mStream) break; 959de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("Filtering out volume command on output %d for stream %d", 960de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mIO, data->mStream); 96165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.add(command2); 96265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } break; 96365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case START_TONE: 96465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case STOP_TONE: 96565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian default: 96665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 96765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 96865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 96965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 97065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // remove filtered commands 97165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t j = 0; j < removedCommands.size(); j++) { 97265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // removed commands always have time stamps greater than current command 97365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t k = i + 1; k < mAudioCommands.size(); k++) { 97465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommands[k] == removedCommands[j]) { 97565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("suppressing command: %d", mAudioCommands[k]->mCommand); 97665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.removeAt(k); 97765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 97865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 97965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 98065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 98165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.clear(); 98265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 98365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // insert command at the right place according to its time stamp 984de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("inserting command: %d at index %d, num commands %d", 985de070137f11d346fba77605bd76a44c040a618fcEric Laurent command->mCommand, (int)i+1, mAudioCommands.size()); 98665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.insertAt(command, i + 1); 98765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 98865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 98965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::exit() 99065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 99165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread::exit"); 99265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 99365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex _l(mLock); 99465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian requestExit(); 99565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 99665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 99765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian requestExitAndWait(); 99865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 99965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 100065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) 100165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 100265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", 100365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mCommand, 100465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian (int)ns2s(mTime), 100565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian (int)ns2ms(mTime)%1000, 100665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitStatus, 100765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mParam); 100865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 100965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1010fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin/******* helpers for the service_ops callbacks defined below *********/ 1011fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinvoid AudioPolicyService::setParameters(audio_io_handle_t ioHandle, 1012fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keyValuePairs, 1013fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delayMs) 1014fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1015fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mAudioCommandThread->parametersCommand((int)ioHandle, keyValuePairs, 1016fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin delayMs); 1017fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1018fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1019fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::setStreamVolume(audio_stream_type_t stream, 1020fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin float volume, 1021fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output, 1022fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delayMs) 1023fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1024fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return (int)mAudioCommandThread->volumeCommand((int)stream, volume, 1025fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin (int)output, delayMs); 1026fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1027fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1028fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::startTone(audio_policy_tone_t tone, 1029fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream) 1030fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1031fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) 1032fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE("startTone: illegal tone requested (%d)", tone); 1033fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (stream != AUDIO_STREAM_VOICE_CALL) 1034fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE("startTone: illegal stream (%d) requested for tone %d", stream, 1035fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin tone); 1036fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING, 1037fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AUDIO_STREAM_VOICE_CALL); 1038fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1039fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1040fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1041fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::stopTone() 1042fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1043fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mTonePlaybackThread->stopToneCommand(); 1044fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1045fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1046fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1047fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::setVoiceVolume(float volume, int delayMs) 1048fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1049fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); 1050fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1051fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 10527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// ---------------------------------------------------------------------------- 10537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// Audio pre-processing configuration 10547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// ---------------------------------------------------------------------------- 10557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentconst char *AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = { 10577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent MIC_SRC_TAG, 10587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_UL_SRC_TAG, 10597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_DL_SRC_TAG, 10607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_CALL_SRC_TAG, 10617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent CAMCORDER_SRC_TAG, 10627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_REC_SRC_TAG, 10637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_COMM_SRC_TAG 10647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent}; 10657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// returns the audio_source_t enum corresponding to the input source name or 10677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// AUDIO_SOURCE_CNT is no match found 10687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentaudio_source_t AudioPolicyService::inputSourceNameToEnum(const char *name) 10697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 10707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int i; 10717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (i = AUDIO_SOURCE_MIC; i < AUDIO_SOURCE_CNT; i++) { 10727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strcmp(name, kInputSourceNames[i - AUDIO_SOURCE_MIC]) == 0) { 10737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("inputSourceNameToEnum found source %s %d", name, i); 10747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent break; 10757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return (audio_source_t)i; 10787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 10797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentsize_t AudioPolicyService::growParamSize(char *param, 10817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size, 10827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *curSize, 10837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *totSize) 10847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 10857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // *curSize is at least sizeof(effect_param_t) + 2 * sizeof(int) 10867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = ((*curSize - 1 ) / size + 1) * size; 10877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (pos + size > *totSize) { 10897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (pos + size > *totSize) { 10907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *totSize += ((*totSize + 7) / 8) * 4; 10917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = (char *)realloc(param, *totSize); 10937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *curSize = pos + size; 10957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return pos; 10967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 10977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentsize_t AudioPolicyService::readParamValue(cnode *node, 10997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent char *param, 11007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *curSize, 11017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *totSize) 11027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 11037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(node->name, SHORT_TAG, sizeof(SHORT_TAG) + 1) == 0) { 11047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(short), curSize, totSize); 11057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(short *)((char *)param + pos) = (short)atoi(node->value); 11067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading short %d", *(short *)((char *)param + pos)); 11077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(short); 11087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, INT_TAG, sizeof(INT_TAG) + 1) == 0) { 11097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(int), curSize, totSize); 11107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(int *)((char *)param + pos) = atoi(node->value); 11117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading int %d", *(int *)((char *)param + pos)); 11127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(int); 11137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, FLOAT_TAG, sizeof(FLOAT_TAG) + 1) == 0) { 11147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(float), curSize, totSize); 11157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(float *)((char *)param + pos) = (float)atof(node->value); 11167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading float %f",*(float *)((char *)param + pos)); 11177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(float); 11187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, BOOL_TAG, sizeof(BOOL_TAG) + 1) == 0) { 11197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(bool), curSize, totSize); 11207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(node->value, "false", strlen("false") + 1) == 0) { 11217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(bool *)((char *)param + pos) = false; 11227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else { 11237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(bool *)((char *)param + pos) = true; 11247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading bool %s",*(bool *)((char *)param + pos) ? "true" : "false"); 11267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(bool); 11277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, STRING_TAG, sizeof(STRING_TAG) + 1) == 0) { 11287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t len = strnlen(node->value, EFFECT_STRING_LEN_MAX); 11297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (*curSize + len + 1 > *totSize) { 11307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *totSize = *curSize + len + 1; 11317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = (char *)realloc(param, *totSize); 11327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent strncpy(param + *curSize, node->value, len); 11347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *curSize += len; 11357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param[*curSize] = '\0'; 11367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading string %s", param + *curSize - len); 11377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return len; 11387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("readParamValue() unknown param type %s", node->name); 11407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return 0; 11417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 11427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurenteffect_param_t *AudioPolicyService::loadEffectParameter(cnode *root) 11447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 11457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *param; 11467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *value; 11477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t curSize = sizeof(effect_param_t); 11487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t totSize = sizeof(effect_param_t) + 2 * sizeof(int); 11497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_param_t *fx_param = (effect_param_t *)malloc(totSize); 11507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = config_find(root, PARAM_TAG); 11527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = config_find(root, VALUE_TAG); 11537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL && value == NULL) { 11547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // try to parse simple parameter form {int int} 11557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = root->first_child; 11567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param) { 11577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // Note: that a pair of random strings is read as 0 0 11587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int *ptr = (int *)fx_param->data; 11597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int *ptr2 = (int *)((char *)param + sizeof(effect_param_t)); 11607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffectParameter() ptr %p ptr2 %p", ptr, ptr2); 11617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *ptr++ = atoi(param->name); 11627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *ptr = atoi(param->value); 11637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize = sizeof(int); 11647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize = sizeof(int); 11657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return fx_param; 11667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL || value == NULL) { 11697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffectParameter() invalid parameter description %s", root->name); 11707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize = 0; 11747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = param->first_child; 11757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (param) { 11767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameter() reading param of type %s", param->name); 11777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size = readParamValue(param, (char *)fx_param, &curSize, &totSize); 11787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (size == 0) { 11797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize += size; 11827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = param->next; 11837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // align start of value field on 32 bit boundary 11867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent curSize = ((curSize - 1 ) / sizeof(int) + 1) * sizeof(int); 11877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize = 0; 11897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = value->first_child; 11907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (value) { 11917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameter() reading value of type %s", value->name); 11927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size = readParamValue(value, (char *)fx_param, &curSize, &totSize); 11937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (size == 0) { 11947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize += size; 11977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = value->next; 11987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return fx_param; 12017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurenterror: 12037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete fx_param; 12047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentvoid AudioPolicyService::loadEffectParameters(cnode *root, Vector <effect_param_t *>& params) 12087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = root->first_child; 12107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 12117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameters() loading param %s", node->name); 12127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_param_t *param = loadEffectParameter(node); 12137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL) { 12147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent params.add(param); 12187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric LaurentAudioPolicyService::InputSourceDesc *AudioPolicyService::loadInputSource( 12237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *root, 12247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent const Vector <EffectDesc *>& effects) 12257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = root->first_child; 12277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSource() empty element %s", root->name); 12297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputSourceDesc *source = new InputSourceDesc(); 12327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 12337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t i; 12347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (i = 0; i < effects.size(); i++) { 12357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(effects[i]->mName, node->name, EFFECT_STRING_LEN_MAX) == 0) { 12367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() found effect %s in list", node->name); 12377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent break; 12387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (i == effects.size()) { 12417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() effect %s not in list", node->name); 12427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = new EffectDesc(*effects[i]); 12467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadEffectParameters(node, effect->mParams); 12477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() adding effect %s uuid %08x", effect->mName, effect->mUuid.timeLow); 12487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent source->mEffects.add(effect); 12497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (source->mEffects.size() == 0) { 12527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSource() no valid effects found in source %s", root->name); 12537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete source; 12547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return source; 12577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadInputSources(cnode *root, const Vector <EffectDesc *>& effects) 12607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, PREPROCESSING_TAG); 12627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENOENT; 12647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->first_child; 12667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 12677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_source_t source = inputSourceNameToEnum(node->name); 12687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (source == AUDIO_SOURCE_CNT) { 12697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSources() invalid input source %s", node->name); 12707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSources() loading input source %s", node->name); 12747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputSourceDesc *desc = loadInputSource(node, effects); 12757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (desc == NULL) { 12767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputSources.add(source, desc); 12807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 12837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric LaurentAudioPolicyService::EffectDesc *AudioPolicyService::loadEffect(cnode *root) 12867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, UUID_TAG); 12887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_uuid_t uuid; 12927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (AudioEffect::stringToGuid(node->value, &uuid) != NO_ERROR) { 12937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffect() invalid uuid %s", node->value); 12947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = new EffectDesc(); 12977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect->mName = strdup(root->name); 12987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent memcpy(&effect->mUuid, &uuid, sizeof(effect_uuid_t)); 12997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return effect; 13017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 13027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadEffects(cnode *root, Vector <EffectDesc *>& effects) 13047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 13057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, EFFECTS_TAG); 13067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 13077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENOENT; 13087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 13097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->first_child; 13107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 13117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffects() loading effect %s", node->name); 13127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = loadEffect(node); 13137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (effect == NULL) { 13147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 13157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 13167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 13177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effects.add(effect); 13187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 13197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 13207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 13217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 13227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadPreProcessorConfig(const char *path) 13247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 13257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *root; 13267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent char *data; 13277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent data = (char *)load_file(path, NULL); 13297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (data == NULL) { 13307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENODEV; 13317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 13327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent root = config_node("", ""); 13337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent config_load(root, data); 13347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector <EffectDesc *> effects; 13367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadEffects(root, effects); 13377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadInputSources(root, effects); 13387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent config_free(root); 13407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent free(root); 13417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent free(data); 13427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 13447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 13457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 1346fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin/* implementation of the interface to the policy manager */ 1347fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinextern "C" { 1348fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1349fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_output(void *service, 1350fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pDevices, 1351fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pSamplingRate, 1352fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pFormat, 1353fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pChannels, 1354fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pLatencyMs, 1355fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_output_flags_t flags) 1356fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1357fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1358fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1359fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1360fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1361fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1362fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1363fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openOutput(pDevices, pSamplingRate, pFormat, pChannels, 1364fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin pLatencyMs, flags); 1365fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1366fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1367fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_dup_output(void *service, 1368fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output1, 1369fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output2) 1370fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1371fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1372fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1373fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1374fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1375fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1376fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openDuplicateOutput(output1, output2); 1377fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1378fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1379fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_close_output(void *service, audio_io_handle_t output) 1380fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1381fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1382fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1383fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1384fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1385fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->closeOutput(output); 1386fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1387fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1388fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_suspend_output(void *service, audio_io_handle_t output) 1389fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1390fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1391fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1392fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1393fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1394fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1395fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1396fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->suspendOutput(output); 1397fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1398fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1399fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_restore_output(void *service, audio_io_handle_t output) 1400fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1401fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1402fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1403fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1404fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1405fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1406fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1407fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->restoreOutput(output); 1408fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1409fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1410fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_input(void *service, 1411fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pDevices, 1412fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pSamplingRate, 1413fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pFormat, 1414fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pChannels, 1415fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t acoustics) 1416fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1417fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1418fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1419fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1420fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1421fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1422fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1423fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openInput(pDevices, pSamplingRate, pFormat, pChannels, 1424fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin acoustics); 1425fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1426fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1427fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_close_input(void *service, audio_io_handle_t input) 1428fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1429fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1430fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1431fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1432fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1433fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->closeInput(input); 1434fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1435fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1436fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_stream_output(void *service, audio_stream_type_t stream, 1437fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output) 1438fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1439fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1440fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1441fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1442fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1443fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->setStreamOutput(stream, output); 1444fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1445fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1446fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_move_effects(void *service, int session, 1447fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t src_output, 1448fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t dst_output) 1449fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1450fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1451fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1452fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1453fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1454fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->moveEffects(session, (int)src_output, (int)dst_output); 1455fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1456fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1457fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic char * aps_get_parameters(void *service, audio_io_handle_t io_handle, 1458fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keys) 1459fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1460fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin String8 result = AudioSystem::getParameters(io_handle, String8(keys)); 1461fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return strdup(result.string()); 1462fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1463fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1464fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic void aps_set_parameters(void *service, audio_io_handle_t io_handle, 1465fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *kv_pairs, int delay_ms) 1466fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1467fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1468fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1469fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms); 1470fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1471fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1472fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_stream_volume(void *service, audio_stream_type_t stream, 1473fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin float volume, audio_io_handle_t output, 1474fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delay_ms) 1475fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1476fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1477fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1478fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->setStreamVolume(stream, volume, output, 1479fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin delay_ms); 1480fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1481fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1482fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_start_tone(void *service, audio_policy_tone_t tone, 1483fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream) 1484fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1485fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1486fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1487fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->startTone(tone, stream); 1488fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1489fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1490fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_stop_tone(void *service) 1491fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1492fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1493fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1494fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->stopTone(); 1495fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1496fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1497fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_voice_volume(void *service, float volume, int delay_ms) 1498fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1499fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1500fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1501fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->setVoiceVolume(volume, delay_ms); 1502fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1503fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1504fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin}; // extern "C" 1505fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1506fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinnamespace { 1507fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin struct audio_policy_service_ops aps_ops = { 1508fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_output : aps_open_output, 1509fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_duplicate_output : aps_open_dup_output, 1510fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin close_output : aps_close_output, 1511fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin suspend_output : aps_suspend_output, 1512fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin restore_output : aps_restore_output, 1513fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_input : aps_open_input, 1514fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin close_input : aps_close_input, 1515fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_stream_volume : aps_set_stream_volume, 1516fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_stream_output : aps_set_stream_output, 1517fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_parameters : aps_set_parameters, 1518fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin get_parameters : aps_get_parameters, 1519fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin start_tone : aps_start_tone, 1520fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin stop_tone : aps_stop_tone, 1521fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_voice_volume : aps_set_voice_volume, 1522fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin move_effects : aps_move_effects, 1523fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin }; 1524fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin}; // namespace <unnamed> 1525fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 152665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android 1527