AudioPolicyService.cpp revision 7c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745
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 50065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::binderDied(const wp<IBinder>& who) { 501de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGW("binderDied() %p, tid %d, calling tid %d", who.unsafe_get(), gettid(), 502de070137f11d346fba77605bd76a44c040a618fcEric Laurent IPCThreadState::self()->getCallingPid()); 50365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 50465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 50565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatic bool tryLock(Mutex& mutex) 50665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 50765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = false; 50865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < kDumpLockRetries; ++i) { 50965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mutex.tryLock() == NO_ERROR) { 51065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian locked = true; 51165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 51265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 51365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian usleep(kDumpLockSleep); 51465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 51565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return locked; 51665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 51765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 51865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpInternals(int fd) 51965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 52065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 52165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 52265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 52365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 524fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy); 52565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 52665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get()); 52765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 52865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get()); 52965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 53065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 53165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 53265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 53365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 53465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 53565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dump(int fd, const Vector<String16>& args) 53665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 53765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (checkCallingPermission(String16("android.permission.DUMP")) == false) { 53865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpPermissionDenial(fd); 53965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 54065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = tryLock(mLock); 54165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 54265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kDeadlockedString); 54365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 54465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 54565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 54665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpInternals(fd); 54765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommandThread != NULL) { 54865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommandThread->dump(fd); 54965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mTonePlaybackThread != NULL) { 55165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mTonePlaybackThread->dump(fd); 55265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 554fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (mpAudioPolicy) { 555fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mpAudioPolicy->dump(mpAudioPolicy, fd); 55665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 55865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (locked) mLock.unlock(); 55965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 56065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 56165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 56265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 56365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::dumpPermissionDenial(int fd) 56465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 56565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 56665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 56765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Permission Denial: " 56965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian "can't dump AudioPolicyService from pid=%d, uid=%d\n", 57065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingPid(), 57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingUid()); 57265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 57565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentvoid AudioPolicyService::setPreProcessorEnabled(InputDesc *inputDesc, bool enabled) 5787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 5797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects; 5807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < fxVector.size(); i++) { 5817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent sp<AudioEffect> fx = fxVector.itemAt(i); 5827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx->setEnabled(enabled); 5837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 5847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 5857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 58665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::onTransact( 58765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 58865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 58965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BnAudioPolicyService::onTransact(code, data, reply, flags); 59065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 59165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 59265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 59365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------- AudioPolicyService::AudioCommandThread implementation ---------- 59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 59565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name) 59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian : Thread(false), mName(name) 59765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 59865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = NULL; 59965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 60065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 60165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 60265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioPolicyService::AudioCommandThread::~AudioCommandThread() 60365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 60465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && !mAudioCommands.isEmpty()) { 60565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian release_wake_lock(mName.string()); 60665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 60765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.clear(); 60865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) delete mpToneGenerator; 60965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 61165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::onFirstRef() 61265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 61365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "") { 61465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian run(mName.string(), ANDROID_PRIORITY_AUDIO); 61565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 61665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian run("AudioCommandThread", ANDROID_PRIORITY_AUDIO); 61765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 61865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 61965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 62065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioPolicyService::AudioCommandThread::threadLoop() 62165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 62265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian nsecs_t waitTime = INT64_MAX; 62365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 62465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 62565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!exitPending()) 62665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 62765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while(!mAudioCommands.isEmpty()) { 62865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian nsecs_t curTime = systemTime(); 62965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // commands are sorted by increasing time stamp: execute them from index 0 and up 63065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommands[0]->mTime <= curTime) { 63165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = mAudioCommands[0]; 63265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.removeAt(0); 63365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLastCommand = *command; 63465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian switch (command->mCommand) { 63665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case START_TONE: { 63765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 63865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ToneData *data = (ToneData *)command->mParam; 63965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() processing start tone %d on stream %d", 64065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mType, data->mStream); 64165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) 64265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete mpToneGenerator; 64365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = new ToneGenerator(data->mStream, 1.0); 64465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator->startTone(data->mType); 64565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 64665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 64765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 64865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case STOP_TONE: { 64965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 65065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() processing stop tone"); 65165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mpToneGenerator != NULL) { 65265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator->stopTone(); 65365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete mpToneGenerator; 65465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mpToneGenerator = NULL; 65565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 65665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.lock(); 65765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 65865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOLUME: { 65965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = (VolumeData *)command->mParam; 660de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set volume stream %d, \ 661de070137f11d346fba77605bd76a44c040a618fcEric Laurent volume %f, output %d", data->mStream, data->mVolume, data->mIO); 662de070137f11d346fba77605bd76a44c040a618fcEric Laurent command->mStatus = AudioSystem::setStreamVolume(data->mStream, 663de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mVolume, 664de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mIO); 66565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 66665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 66765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 66865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 66965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 67065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 67165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_PARAMETERS: { 67265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = (ParametersData *)command->mParam; 673de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set parameters string %s, io %d", 674de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mKeyValuePairs.string(), data->mIO); 67565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); 67665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 67765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 67865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 67965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 68065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 68165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 68265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOICE_VOLUME: { 68365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VoiceVolumeData *data = (VoiceVolumeData *)command->mParam; 684de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() processing set voice volume volume %f", 685de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mVolume); 68665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); 68765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 68865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.signal(); 68965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.wait(mLock); 69065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 69165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete data; 69265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian }break; 69365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian default: 69465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGW("AudioCommandThread() unknown command %d", command->mCommand); 69565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 69665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian delete command; 69765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian waitTime = INT64_MAX; 69865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 69965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian waitTime = mAudioCommands[0]->mTime - curTime; 70065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 70165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 70265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 70365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // release delayed commands wake lock 70465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && mAudioCommands.isEmpty()) { 70565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian release_wake_lock(mName.string()); 70665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 70765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() going to sleep"); 70865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.waitRelative(mLock, waitTime); 70965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() waking up"); 71065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 71165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLock.unlock(); 71265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return false; 71365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 71465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 71565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::AudioCommandThread::dump(int fd) 71665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 71765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 71865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 71965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 72065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 72165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); 72265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 72365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 72465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 72565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = tryLock(mLock); 72665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 72765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result2(kCmdDeadlockedString); 72865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result2.string(), result2.size()); 72965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 73065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 73165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "- Commands:\n"); 73265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result = String8(buffer); 73365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(" Command Time Wait pParam\n"); 73465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < (int)mAudioCommands.size(); i++) { 73565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands[i]->dump(buffer, SIZE); 73665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 73765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 73865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(" Last Command\n"); 73965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mLastCommand.dump(buffer, SIZE); 74065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 74165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 74365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (locked) mLock.unlock(); 74565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 74765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 74865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::startToneCommand(int type, int stream) 75065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 75165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 75265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = START_TONE; 75365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ToneData *data = new ToneData(); 75465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mType = type; 75565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mStream = stream; 75665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = (void *)data; 75765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 75865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 75965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command); 76065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream); 76165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 76265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 76365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 76465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::stopToneCommand() 76565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 76665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 76765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = STOP_TONE; 76865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = NULL; 76965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 77065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 77165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command); 77265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding tone stop"); 77365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 77465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 77565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 776de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::AudioCommandThread::volumeCommand(int stream, 777de070137f11d346fba77605bd76a44c040a618fcEric Laurent float volume, 778de070137f11d346fba77605bd76a44c040a618fcEric Laurent int output, 779de070137f11d346fba77605bd76a44c040a618fcEric Laurent int delayMs) 78065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 78165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 78265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 78465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_VOLUME; 78565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = new VolumeData(); 78665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mStream = stream; 78765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mVolume = volume; 78865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mIO = output; 78965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 79065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 79165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 79265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 79365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 79465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 79565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 79665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 797de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", 798de070137f11d346fba77605bd76a44c040a618fcEric Laurent stream, volume, output); 79965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 80065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 80165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 80265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 80365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 80465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 80565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 80665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 80765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 808de070137f11d346fba77605bd76a44c040a618fcEric Laurentstatus_t AudioPolicyService::AudioCommandThread::parametersCommand(int ioHandle, 809fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keyValuePairs, 810de070137f11d346fba77605bd76a44c040a618fcEric Laurent int delayMs) 81165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 81265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 81365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 81465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 81565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_PARAMETERS; 81665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = new ParametersData(); 81765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mIO = ioHandle; 818fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin data->mKeyValuePairs = String8(keyValuePairs); 81965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 82065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 82165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 82265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 82365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 82465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 82565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 82665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 827de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", 828fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin keyValuePairs, ioHandle, delayMs); 82965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 83065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 83165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 83265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 83365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 83465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 83565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 83665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 83765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 83865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) 83965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 84065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status = NO_ERROR; 84165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 84265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command = new AudioCommand(); 84365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCommand = SET_VOICE_VOLUME; 84465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VoiceVolumeData *data = new VoiceVolumeData(); 84565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data->mVolume = volume; 84665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mParam = data; 84765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (delayMs == 0) { 84865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = true; 84965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 85065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mWaitStatus = false; 85165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 85265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 85365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian insertCommand_l(command, delayMs); 85465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread() adding set voice volume volume %f", volume); 85565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 85665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command->mWaitStatus) { 85765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mCond.wait(mLock); 85865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status = command->mStatus; 85965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 86065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 86165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return status; 86265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 86365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 86465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// insertCommand_l() must be called with mLock held 86565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::insertCommand_l(AudioCommand *command, int delayMs) 86665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 86765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ssize_t i; 86865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Vector <AudioCommand *> removedCommands; 86965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian command->mTime = systemTime() + milliseconds(delayMs); 87165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // acquire wake lock to make sure delayed commands are processed 87365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mName != "" && mAudioCommands.isEmpty()) { 87465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); 87565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 87665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check same pending commands with later time stamps and eliminate them 87865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (i = mAudioCommands.size()-1; i >= 0; i--) { 87965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioCommand *command2 = mAudioCommands[i]; 88065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands 88165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command2->mTime <= command->mTime) break; 88265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (command2->mCommand != command->mCommand) continue; 88365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 88465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian switch (command->mCommand) { 88565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_PARAMETERS: { 88665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data = (ParametersData *)command->mParam; 88765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian ParametersData *data2 = (ParametersData *)command2->mParam; 88865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mIO != data2->mIO) break; 889de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("Comparing parameter command %s to new command %s", 890de070137f11d346fba77605bd76a44c040a618fcEric Laurent data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); 89165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioParameter param = AudioParameter(data->mKeyValuePairs); 89265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); 89365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t j = 0; j < param.size(); j++) { 89465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 key; 89565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 value; 89665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param.getAt(j, key, value); 89765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t k = 0; k < param2.size(); k++) { 89865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 key2; 89965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 value2; 90065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param2.getAt(k, key2, value2); 90165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (key2 == key) { 90265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian param2.remove(key2); 90365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("Filtering out parameter %s", key2.string()); 90465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 90565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 90665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 90765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 90865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // if all keys have been filtered out, remove the command. 90965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // otherwise, update the key value pairs 91065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (param2.size() == 0) { 91165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.add(command2); 91265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 91365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian data2->mKeyValuePairs = param2.toString(); 91465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 91565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } break; 91665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 91765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case SET_VOLUME: { 91865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data = (VolumeData *)command->mParam; 91965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian VolumeData *data2 = (VolumeData *)command2->mParam; 92065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mIO != data2->mIO) break; 92165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (data->mStream != data2->mStream) break; 922de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("Filtering out volume command on output %d for stream %d", 923de070137f11d346fba77605bd76a44c040a618fcEric Laurent data->mIO, data->mStream); 92465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.add(command2); 92565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } break; 92665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case START_TONE: 92765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian case STOP_TONE: 92865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian default: 92965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 93065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 93165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 93265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 93365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // remove filtered commands 93465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t j = 0; j < removedCommands.size(); j++) { 93565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // removed commands always have time stamps greater than current command 93665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t k = i + 1; k < mAudioCommands.size(); k++) { 93765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mAudioCommands[k] == removedCommands[j]) { 93865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("suppressing command: %d", mAudioCommands[k]->mCommand); 93965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.removeAt(k); 94065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 94165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 94465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian removedCommands.clear(); 94565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 94665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // insert command at the right place according to its time stamp 947de070137f11d346fba77605bd76a44c040a618fcEric Laurent LOGV("inserting command: %d at index %d, num commands %d", 948de070137f11d346fba77605bd76a44c040a618fcEric Laurent command->mCommand, (int)i+1, mAudioCommands.size()); 94965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mAudioCommands.insertAt(command, i + 1); 95065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 95165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 95265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::exit() 95365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 95465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian LOGV("AudioCommandThread::exit"); 95565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 95665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex _l(mLock); 95765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian requestExit(); 95865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitWorkCV.signal(); 95965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 96065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian requestExitAndWait(); 96165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 96265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 96365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) 96465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 96565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", 96665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mCommand, 96765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian (int)ns2s(mTime), 96865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian (int)ns2ms(mTime)%1000, 96965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mWaitStatus, 97065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mParam); 97165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 97265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 973fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin/******* helpers for the service_ops callbacks defined below *********/ 974fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinvoid AudioPolicyService::setParameters(audio_io_handle_t ioHandle, 975fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keyValuePairs, 976fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delayMs) 977fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 978fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mAudioCommandThread->parametersCommand((int)ioHandle, keyValuePairs, 979fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin delayMs); 980fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 981fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 982fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::setStreamVolume(audio_stream_type_t stream, 983fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin float volume, 984fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output, 985fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delayMs) 986fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 987fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return (int)mAudioCommandThread->volumeCommand((int)stream, volume, 988fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin (int)output, delayMs); 989fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 990fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 991fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::startTone(audio_policy_tone_t tone, 992fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream) 993fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 994fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) 995fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE("startTone: illegal tone requested (%d)", tone); 996fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (stream != AUDIO_STREAM_VOICE_CALL) 997fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGE("startTone: illegal stream (%d) requested for tone %d", stream, 998fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin tone); 999fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING, 1000fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AUDIO_STREAM_VOICE_CALL); 1001fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1002fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1003fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1004fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::stopTone() 1005fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1006fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin mTonePlaybackThread->stopToneCommand(); 1007fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1008fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1009fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1010fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinint AudioPolicyService::setVoiceVolume(float volume, int delayMs) 1011fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1012fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); 1013fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1014fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 10157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// ---------------------------------------------------------------------------- 10167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// Audio pre-processing configuration 10177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// ---------------------------------------------------------------------------- 10187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentconst char *AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = { 10207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent MIC_SRC_TAG, 10217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_UL_SRC_TAG, 10227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_DL_SRC_TAG, 10237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_CALL_SRC_TAG, 10247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent CAMCORDER_SRC_TAG, 10257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_REC_SRC_TAG, 10267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent VOICE_COMM_SRC_TAG 10277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent}; 10287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// returns the audio_source_t enum corresponding to the input source name or 10307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent// AUDIO_SOURCE_CNT is no match found 10317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentaudio_source_t AudioPolicyService::inputSourceNameToEnum(const char *name) 10327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 10337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int i; 10347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (i = AUDIO_SOURCE_MIC; i < AUDIO_SOURCE_CNT; i++) { 10357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strcmp(name, kInputSourceNames[i - AUDIO_SOURCE_MIC]) == 0) { 10367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("inputSourceNameToEnum found source %s %d", name, i); 10377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent break; 10387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return (audio_source_t)i; 10417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 10427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentsize_t AudioPolicyService::growParamSize(char *param, 10447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size, 10457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *curSize, 10467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *totSize) 10477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 10487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // *curSize is at least sizeof(effect_param_t) + 2 * sizeof(int) 10497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = ((*curSize - 1 ) / size + 1) * size; 10507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (pos + size > *totSize) { 10527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (pos + size > *totSize) { 10537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *totSize += ((*totSize + 7) / 8) * 4; 10547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = (char *)realloc(param, *totSize); 10567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *curSize = pos + size; 10587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return pos; 10597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 10607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 10617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentsize_t AudioPolicyService::readParamValue(cnode *node, 10627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent char *param, 10637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *curSize, 10647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t *totSize) 10657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 10667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(node->name, SHORT_TAG, sizeof(SHORT_TAG) + 1) == 0) { 10677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(short), curSize, totSize); 10687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(short *)((char *)param + pos) = (short)atoi(node->value); 10697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading short %d", *(short *)((char *)param + pos)); 10707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(short); 10717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, INT_TAG, sizeof(INT_TAG) + 1) == 0) { 10727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(int), curSize, totSize); 10737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(int *)((char *)param + pos) = atoi(node->value); 10747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading int %d", *(int *)((char *)param + pos)); 10757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(int); 10767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, FLOAT_TAG, sizeof(FLOAT_TAG) + 1) == 0) { 10777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(float), curSize, totSize); 10787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(float *)((char *)param + pos) = (float)atof(node->value); 10797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading float %f",*(float *)((char *)param + pos)); 10807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(float); 10817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, BOOL_TAG, sizeof(BOOL_TAG) + 1) == 0) { 10827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t pos = growParamSize(param, sizeof(bool), curSize, totSize); 10837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(node->value, "false", strlen("false") + 1) == 0) { 10847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(bool *)((char *)param + pos) = false; 10857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else { 10867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *(bool *)((char *)param + pos) = true; 10877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading bool %s",*(bool *)((char *)param + pos) ? "true" : "false"); 10897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return sizeof(bool); 10907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } else if (strncmp(node->name, STRING_TAG, sizeof(STRING_TAG) + 1) == 0) { 10917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t len = strnlen(node->value, EFFECT_STRING_LEN_MAX); 10927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (*curSize + len + 1 > *totSize) { 10937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *totSize = *curSize + len + 1; 10947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = (char *)realloc(param, *totSize); 10957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 10967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent strncpy(param + *curSize, node->value, len); 10977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *curSize += len; 10987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param[*curSize] = '\0'; 10997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("readParamValue() reading string %s", param + *curSize - len); 11007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return len; 11017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("readParamValue() unknown param type %s", node->name); 11037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return 0; 11047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 11057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurenteffect_param_t *AudioPolicyService::loadEffectParameter(cnode *root) 11077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 11087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *param; 11097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *value; 11107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t curSize = sizeof(effect_param_t); 11117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t totSize = sizeof(effect_param_t) + 2 * sizeof(int); 11127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_param_t *fx_param = (effect_param_t *)malloc(totSize); 11137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = config_find(root, PARAM_TAG); 11157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = config_find(root, VALUE_TAG); 11167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL && value == NULL) { 11177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // try to parse simple parameter form {int int} 11187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = root->first_child; 11197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param) { 11207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // Note: that a pair of random strings is read as 0 0 11217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int *ptr = (int *)fx_param->data; 11227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int *ptr2 = (int *)((char *)param + sizeof(effect_param_t)); 11237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffectParameter() ptr %p ptr2 %p", ptr, ptr2); 11247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *ptr++ = atoi(param->name); 11257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent *ptr = atoi(param->value); 11267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize = sizeof(int); 11277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize = sizeof(int); 11287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return fx_param; 11297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL || value == NULL) { 11327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffectParameter() invalid parameter description %s", root->name); 11337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize = 0; 11377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = param->first_child; 11387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (param) { 11397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameter() reading param of type %s", param->name); 11407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size = readParamValue(param, (char *)fx_param, &curSize, &totSize); 11417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (size == 0) { 11427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->psize += size; 11457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent param = param->next; 11467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // align start of value field on 32 bit boundary 11497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent curSize = ((curSize - 1 ) / sizeof(int) + 1) * sizeof(int); 11507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize = 0; 11527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = value->first_child; 11537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (value) { 11547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameter() reading value of type %s", value->name); 11557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t size = readParamValue(value, (char *)fx_param, &curSize, &totSize); 11567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (size == 0) { 11577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent goto error; 11587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent fx_param->vsize += size; 11607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent value = value->next; 11617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return fx_param; 11647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurenterror: 11667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete fx_param; 11677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 11687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 11697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentvoid AudioPolicyService::loadEffectParameters(cnode *root, Vector <effect_param_t *>& params) 11717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 11727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = root->first_child; 11737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 11747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffectParameters() loading param %s", node->name); 11757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_param_t *param = loadEffectParameter(node); 11767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (param == NULL) { 11777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 11787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 11797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent params.add(param); 11817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 11827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 11847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 11857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric LaurentAudioPolicyService::InputSourceDesc *AudioPolicyService::loadInputSource( 11867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *root, 11877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent const Vector <EffectDesc *>& effects) 11887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 11897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = root->first_child; 11907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 11917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSource() empty element %s", root->name); 11927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 11937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 11947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputSourceDesc *source = new InputSourceDesc(); 11957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 11967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent size_t i; 11977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (i = 0; i < effects.size(); i++) { 11987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (strncmp(effects[i]->mName, node->name, EFFECT_STRING_LEN_MAX) == 0) { 11997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() found effect %s in list", node->name); 12007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent break; 12017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (i == effects.size()) { 12047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() effect %s not in list", node->name); 12057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = new EffectDesc(*effects[i]); 12097c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadEffectParameters(node, effect->mParams); 12107c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSource() adding effect %s uuid %08x", effect->mName, effect->mUuid.timeLow); 12117c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent source->mEffects.add(effect); 12127c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12137c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12147c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (source->mEffects.size() == 0) { 12157c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSource() no valid effects found in source %s", root->name); 12167c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent delete source; 12177c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12187c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12197c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return source; 12207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadInputSources(cnode *root, const Vector <EffectDesc *>& effects) 12237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, PREPROCESSING_TAG); 12257c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENOENT; 12277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->first_child; 12297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 12307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent audio_source_t source = inputSourceNameToEnum(node->name); 12317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (source == AUDIO_SOURCE_CNT) { 12327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadInputSources() invalid input source %s", node->name); 12337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadInputSources() loading input source %s", node->name); 12377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent InputSourceDesc *desc = loadInputSource(node, effects); 12387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (desc == NULL) { 12397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mInputSources.add(source, desc); 12437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 12467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric LaurentAudioPolicyService::EffectDesc *AudioPolicyService::loadEffect(cnode *root) 12497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, UUID_TAG); 12517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect_uuid_t uuid; 12557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (AudioEffect::stringToGuid(node->value, &uuid) != NO_ERROR) { 12567c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGW("loadEffect() invalid uuid %s", node->value); 12577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NULL; 12587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = new EffectDesc(); 12607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effect->mName = strdup(root->name); 12617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent memcpy(&effect->mUuid, &uuid, sizeof(effect_uuid_t)); 12627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return effect; 12647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadEffects(cnode *root, Vector <EffectDesc *>& effects) 12677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *node = config_find(root, EFFECTS_TAG); 12697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (node == NULL) { 12707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENOENT; 12717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->first_child; 12737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent while (node) { 12747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent LOGV("loadEffects() loading effect %s", node->name); 12757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent EffectDesc *effect = loadEffect(node); 12767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (effect == NULL) { 12777c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12787c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent continue; 12797c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12807c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent effects.add(effect); 12817c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent node = node->next; 12827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 12847c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 12857c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurentstatus_t AudioPolicyService::loadPreProcessorConfig(const char *path) 12877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent{ 12887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent cnode *root; 12897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent char *data; 12907c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent data = (char *)load_file(path, NULL); 12927c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent if (data == NULL) { 12937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return -ENODEV; 12947c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 12957c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent root = config_node("", ""); 12967c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent config_load(root, data); 12977c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 12987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent Vector <EffectDesc *> effects; 12997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadEffects(root, effects); 13007c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent loadInputSources(root, effects); 13017c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent config_free(root); 13037c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent free(root); 13047c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent free(data); 13057c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 13067c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent return NO_ERROR; 13077c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent} 13087c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent 1309fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin/* implementation of the interface to the policy manager */ 1310fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinextern "C" { 1311fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1312fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_output(void *service, 1313fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pDevices, 1314fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pSamplingRate, 1315fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pFormat, 1316fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pChannels, 1317fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pLatencyMs, 1318fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_policy_output_flags_t flags) 1319fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1320fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1321fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1322fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1323fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1324fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1325fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1326fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openOutput(pDevices, pSamplingRate, pFormat, pChannels, 1327fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin pLatencyMs, flags); 1328fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1329fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1330fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_dup_output(void *service, 1331fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output1, 1332fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output2) 1333fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1334fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1335fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1336fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1337fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1338fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1339fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openDuplicateOutput(output1, output2); 1340fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1341fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1342fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_close_output(void *service, audio_io_handle_t output) 1343fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1344fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1345fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1346fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1347fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1348fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->closeOutput(output); 1349fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1350fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1351fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_suspend_output(void *service, audio_io_handle_t output) 1352fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1353fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1354fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1355fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1356fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1357fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1358fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1359fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->suspendOutput(output); 1360fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1361fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1362fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_restore_output(void *service, audio_io_handle_t output) 1363fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1364fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1365fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1366fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1367fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1368fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1369fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1370fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->restoreOutput(output); 1371fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1372fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1373fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic audio_io_handle_t aps_open_input(void *service, 1374fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pDevices, 1375fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pSamplingRate, 1376fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pFormat, 1377fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t *pChannels, 1378fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t acoustics) 1379fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1380fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1381fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) { 1382fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin LOGW("%s: could not get AudioFlinger", __func__); 1383fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return 0; 1384fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin } 1385fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1386fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->openInput(pDevices, pSamplingRate, pFormat, pChannels, 1387fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin acoustics); 1388fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1389fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1390fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_close_input(void *service, audio_io_handle_t input) 1391fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1392fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1393fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1394fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1395fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1396fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->closeInput(input); 1397fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1398fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1399fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_stream_output(void *service, audio_stream_type_t stream, 1400fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t output) 1401fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1402fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1403fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1404fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1405fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1406fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->setStreamOutput(stream, output); 1407fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1408fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1409fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_move_effects(void *service, int session, 1410fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t src_output, 1411fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_io_handle_t dst_output) 1412fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1413fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); 1414fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (af == NULL) 1415fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return PERMISSION_DENIED; 1416fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1417fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return af->moveEffects(session, (int)src_output, (int)dst_output); 1418fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1419fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1420fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic char * aps_get_parameters(void *service, audio_io_handle_t io_handle, 1421fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *keys) 1422fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1423fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin String8 result = AudioSystem::getParameters(io_handle, String8(keys)); 1424fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return strdup(result.string()); 1425fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1426fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1427fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic void aps_set_parameters(void *service, audio_io_handle_t io_handle, 1428fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin const char *kv_pairs, int delay_ms) 1429fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1430fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1431fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1432fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms); 1433fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1434fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1435fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_stream_volume(void *service, audio_stream_type_t stream, 1436fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin float volume, audio_io_handle_t output, 1437fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin int delay_ms) 1438fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1439fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1440fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1441fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->setStreamVolume(stream, volume, output, 1442fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin delay_ms); 1443fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1444fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1445fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_start_tone(void *service, audio_policy_tone_t tone, 1446fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_stream_type_t stream) 1447fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1448fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1449fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1450fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->startTone(tone, stream); 1451fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1452fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1453fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_stop_tone(void *service) 1454fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1455fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1456fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1457fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->stopTone(); 1458fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1459fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1460fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinstatic int aps_set_voice_volume(void *service, float volume, int delay_ms) 1461fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin{ 1462fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; 1463fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1464fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return audioPolicyService->setVoiceVolume(volume, delay_ms); 1465fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin} 1466fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1467fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin}; // extern "C" 1468fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1469fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavinnamespace { 1470fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin struct audio_policy_service_ops aps_ops = { 1471fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_output : aps_open_output, 1472fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_duplicate_output : aps_open_dup_output, 1473fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin close_output : aps_close_output, 1474fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin suspend_output : aps_suspend_output, 1475fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin restore_output : aps_restore_output, 1476fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin open_input : aps_open_input, 1477fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin close_input : aps_close_input, 1478fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_stream_volume : aps_set_stream_volume, 1479fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_stream_output : aps_set_stream_output, 1480fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_parameters : aps_set_parameters, 1481fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin get_parameters : aps_get_parameters, 1482fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin start_tone : aps_start_tone, 1483fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin stop_tone : aps_stop_tone, 1484fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin set_voice_volume : aps_set_voice_volume, 1485fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin move_effects : aps_move_effects, 1486fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin }; 1487fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin}; // namespace <unnamed> 1488fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 148965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android 1490