Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "AudioPolicyService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #undef __STRICT_ANSI__ |
| 21 | #define __STDINT_LIMITS |
| 22 | #define __STDC_LIMIT_MACROS |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include <sys/time.h> |
| 26 | #include <binder/IServiceManager.h> |
| 27 | #include <utils/Log.h> |
| 28 | #include <cutils/properties.h> |
| 29 | #include <binder/IPCThreadState.h> |
| 30 | #include <utils/String16.h> |
| 31 | #include <utils/threads.h> |
| 32 | #include "AudioPolicyService.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 33 | #include <cutils/properties.h> |
| 34 | #include <dlfcn.h> |
| 35 | #include <hardware_legacy/power.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 36 | #include <media/AudioEffect.h> |
| 37 | #include <media/EffectsFactoryApi.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 38 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 39 | #include <hardware/hardware.h> |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 40 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 41 | #include <system/audio_policy.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 42 | #include <hardware/audio_policy.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 43 | #include <audio_effects/audio_effects_conf.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 44 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 45 | namespace android { |
| 46 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 47 | static const char *kDeadlockedString = "AudioPolicyService may be deadlocked\n"; |
| 48 | static const char *kCmdDeadlockedString = "AudioPolicyService command thread may be deadlocked\n"; |
| 49 | |
| 50 | static const int kDumpLockRetries = 50; |
| 51 | static const int kDumpLockSleep = 20000; |
| 52 | |
| 53 | static bool checkPermission() { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 54 | if (getpid() == IPCThreadState::self()->getCallingPid()) return true; |
| 55 | bool ok = checkCallingPermission(String16("android.permission.MODIFY_AUDIO_SETTINGS")); |
| 56 | if (!ok) LOGE("Request requires android.permission.MODIFY_AUDIO_SETTINGS"); |
| 57 | return ok; |
| 58 | } |
| 59 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 60 | namespace { |
| 61 | extern struct audio_policy_service_ops aps_ops; |
| 62 | }; |
| 63 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 64 | // ---------------------------------------------------------------------------- |
| 65 | |
| 66 | AudioPolicyService::AudioPolicyService() |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 67 | : BnAudioPolicyService() , mpAudioPolicyDev(NULL) , mpAudioPolicy(NULL) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 68 | { |
| 69 | char value[PROPERTY_VALUE_MAX]; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 70 | const struct hw_module_t *module; |
| 71 | int forced_val; |
| 72 | int rc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 73 | |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 74 | Mutex::Autolock _l(mLock); |
| 75 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 76 | // start tone playback thread |
| 77 | mTonePlaybackThread = new AudioCommandThread(String8("")); |
| 78 | // start audio commands thread |
| 79 | mAudioCommandThread = new AudioCommandThread(String8("ApmCommandThread")); |
| 80 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 81 | /* instantiate the audio policy manager */ |
| 82 | rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module); |
| 83 | if (rc) |
| 84 | return; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 85 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 86 | rc = audio_policy_dev_open(module, &mpAudioPolicyDev); |
| 87 | LOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc)); |
| 88 | if (rc) |
| 89 | return; |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 90 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 91 | rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this, |
| 92 | &mpAudioPolicy); |
| 93 | LOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc)); |
| 94 | if (rc) |
| 95 | return; |
| 96 | |
| 97 | rc = mpAudioPolicy->init_check(mpAudioPolicy); |
| 98 | LOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc)); |
| 99 | if (rc) |
| 100 | return; |
| 101 | |
| 102 | property_get("ro.camera.sound.forced", value, "0"); |
| 103 | forced_val = strtol(value, NULL, 0); |
| 104 | mpAudioPolicy->set_can_mute_enforced_audible(mpAudioPolicy, !forced_val); |
| 105 | |
| 106 | LOGI("Loaded audio policy from %s (%s)", module->name, module->id); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 107 | |
| 108 | // load audio pre processing modules |
| 109 | if (access(AUDIO_EFFECT_VENDOR_CONFIG_FILE, R_OK) == 0) { |
| 110 | loadPreProcessorConfig(AUDIO_EFFECT_VENDOR_CONFIG_FILE); |
| 111 | } else if (access(AUDIO_EFFECT_DEFAULT_CONFIG_FILE, R_OK) == 0) { |
| 112 | loadPreProcessorConfig(AUDIO_EFFECT_DEFAULT_CONFIG_FILE); |
| 113 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | AudioPolicyService::~AudioPolicyService() |
| 117 | { |
| 118 | mTonePlaybackThread->exit(); |
| 119 | mTonePlaybackThread.clear(); |
| 120 | mAudioCommandThread->exit(); |
| 121 | mAudioCommandThread.clear(); |
| 122 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 123 | |
| 124 | // release audio pre processing resources |
| 125 | for (size_t i = 0; i < mInputSources.size(); i++) { |
| 126 | InputSourceDesc *source = mInputSources.valueAt(i); |
| 127 | Vector <EffectDesc *> effects = source->mEffects; |
| 128 | for (size_t j = 0; j < effects.size(); j++) { |
| 129 | delete effects[j]->mName; |
| 130 | Vector <effect_param_t *> params = effects[j]->mParams; |
| 131 | for (size_t k = 0; k < params.size(); k++) { |
| 132 | delete params[k]; |
| 133 | } |
| 134 | params.clear(); |
| 135 | delete effects[j]; |
| 136 | } |
| 137 | effects.clear(); |
| 138 | delete source; |
| 139 | } |
| 140 | mInputSources.clear(); |
| 141 | |
| 142 | for (size_t i = 0; i < mInputs.size(); i++) { |
| 143 | mInputs.valueAt(i)->mEffects.clear(); |
| 144 | delete mInputs.valueAt(i); |
| 145 | } |
| 146 | mInputs.clear(); |
| 147 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 148 | if (mpAudioPolicy && mpAudioPolicyDev) |
| 149 | mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy); |
| 150 | if (mpAudioPolicyDev) |
| 151 | audio_policy_dev_close(mpAudioPolicyDev); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 154 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, |
| 155 | audio_policy_dev_state_t state, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 156 | const char *device_address) |
| 157 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 158 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 159 | return NO_INIT; |
| 160 | } |
| 161 | if (!checkPermission()) { |
| 162 | return PERMISSION_DENIED; |
| 163 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 164 | if (!audio_is_output_device(device) && !audio_is_input_device(device)) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 165 | return BAD_VALUE; |
| 166 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 167 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 168 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 169 | return BAD_VALUE; |
| 170 | } |
| 171 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 172 | ALOGV("setDeviceConnectionState() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 173 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 174 | return mpAudioPolicy->set_device_connection_state(mpAudioPolicy, device, |
| 175 | state, device_address); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 178 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( |
| 179 | audio_devices_t device, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 180 | const char *device_address) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 181 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 182 | if (mpAudioPolicy == NULL) { |
| 183 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 184 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 185 | return mpAudioPolicy->get_device_connection_state(mpAudioPolicy, device, |
| 186 | device_address); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | status_t AudioPolicyService::setPhoneState(int state) |
| 190 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 191 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 192 | return NO_INIT; |
| 193 | } |
| 194 | if (!checkPermission()) { |
| 195 | return PERMISSION_DENIED; |
| 196 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 197 | if (state < 0 || state >= AUDIO_MODE_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 198 | return BAD_VALUE; |
| 199 | } |
| 200 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 201 | ALOGV("setPhoneState() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 202 | |
| 203 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 204 | AudioSystem::setMode(state); |
| 205 | |
| 206 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 207 | mpAudioPolicy->set_phone_state(mpAudioPolicy, state); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 208 | return NO_ERROR; |
| 209 | } |
| 210 | |
| 211 | status_t AudioPolicyService::setRingerMode(uint32_t mode, uint32_t mask) |
| 212 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 213 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 214 | return NO_INIT; |
| 215 | } |
| 216 | if (!checkPermission()) { |
| 217 | return PERMISSION_DENIED; |
| 218 | } |
| 219 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 220 | mpAudioPolicy->set_ringer_mode(mpAudioPolicy, mode, mask); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 221 | return NO_ERROR; |
| 222 | } |
| 223 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 224 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 225 | audio_policy_forced_cfg_t config) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 226 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 227 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 228 | return NO_INIT; |
| 229 | } |
| 230 | if (!checkPermission()) { |
| 231 | return PERMISSION_DENIED; |
| 232 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 233 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 234 | return BAD_VALUE; |
| 235 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 236 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 237 | return BAD_VALUE; |
| 238 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 239 | ALOGV("setForceUse() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 240 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 241 | mpAudioPolicy->set_force_use(mpAudioPolicy, usage, config); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 242 | return NO_ERROR; |
| 243 | } |
| 244 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 245 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 246 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 247 | if (mpAudioPolicy == NULL) { |
| 248 | return AUDIO_POLICY_FORCE_NONE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 249 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 250 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 251 | return AUDIO_POLICY_FORCE_NONE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 252 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 253 | return mpAudioPolicy->get_force_use(mpAudioPolicy, usage); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 256 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 257 | uint32_t samplingRate, |
| 258 | uint32_t format, |
| 259 | uint32_t channels, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 260 | audio_policy_output_flags_t flags) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 261 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 262 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 263 | return 0; |
| 264 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 265 | ALOGV("getOutput() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 266 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 267 | return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate, format, channels, flags); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 270 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 271 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 272 | int session) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 273 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 274 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 275 | return NO_INIT; |
| 276 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 277 | ALOGV("startOutput() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 278 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 279 | return mpAudioPolicy->start_output(mpAudioPolicy, output, stream, session); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 282 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 283 | audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 284 | int session) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 285 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 286 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 287 | return NO_INIT; |
| 288 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 289 | ALOGV("stopOutput() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 290 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 291 | return mpAudioPolicy->stop_output(mpAudioPolicy, output, stream, session); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 295 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 296 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 297 | return; |
| 298 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 299 | ALOGV("releaseOutput() tid %d", gettid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 300 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 301 | mpAudioPolicy->release_output(mpAudioPolicy, output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | audio_io_handle_t AudioPolicyService::getInput(int inputSource, |
| 305 | uint32_t samplingRate, |
| 306 | uint32_t format, |
| 307 | uint32_t channels, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 308 | audio_in_acoustics_t acoustics, |
| 309 | int audioSession) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 310 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 311 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | Mutex::Autolock _l(mLock); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 315 | audio_io_handle_t input = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate, |
| 316 | format, channels, acoustics); |
| 317 | |
| 318 | if (input == 0) { |
| 319 | return input; |
| 320 | } |
| 321 | // create audio pre processors according to input source |
| 322 | ssize_t index = mInputSources.indexOfKey((audio_source_t)inputSource); |
| 323 | if (index < 0) { |
| 324 | return input; |
| 325 | } |
| 326 | ssize_t idx = mInputs.indexOfKey(input); |
| 327 | InputDesc *inputDesc; |
| 328 | if (idx < 0) { |
| 329 | inputDesc = new InputDesc(); |
| 330 | inputDesc->mSessionId = audioSession; |
| 331 | mInputs.add(input, inputDesc); |
| 332 | } else { |
| 333 | inputDesc = mInputs.valueAt(idx); |
| 334 | } |
| 335 | |
| 336 | Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects; |
| 337 | for (size_t i = 0; i < effects.size(); i++) { |
| 338 | EffectDesc *effect = effects[i]; |
| 339 | sp<AudioEffect> fx = new AudioEffect(NULL, &effect->mUuid, -1, 0, 0, audioSession, input); |
| 340 | status_t status = fx->initCheck(); |
| 341 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 342 | LOGW("Failed to create Fx %s on input %d", effect->mName, input); |
| 343 | // fx goes out of scope and strong ref on AudioEffect is released |
| 344 | continue; |
| 345 | } |
| 346 | for (size_t j = 0; j < effect->mParams.size(); j++) { |
| 347 | fx->setParameter(effect->mParams[j]); |
| 348 | } |
| 349 | inputDesc->mEffects.add(fx); |
| 350 | } |
| 351 | setPreProcessorEnabled(inputDesc, true); |
| 352 | return input; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | status_t AudioPolicyService::startInput(audio_io_handle_t input) |
| 356 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 357 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 358 | return NO_INIT; |
| 359 | } |
| 360 | Mutex::Autolock _l(mLock); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 361 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 362 | return mpAudioPolicy->start_input(mpAudioPolicy, input); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | status_t AudioPolicyService::stopInput(audio_io_handle_t input) |
| 366 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 367 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 368 | return NO_INIT; |
| 369 | } |
| 370 | Mutex::Autolock _l(mLock); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 371 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 372 | return mpAudioPolicy->stop_input(mpAudioPolicy, input); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void AudioPolicyService::releaseInput(audio_io_handle_t input) |
| 376 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 377 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 378 | return; |
| 379 | } |
| 380 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 381 | mpAudioPolicy->release_input(mpAudioPolicy, input); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 382 | |
| 383 | ssize_t index = mInputs.indexOfKey(input); |
| 384 | if (index < 0) { |
| 385 | return; |
| 386 | } |
| 387 | InputDesc *inputDesc = mInputs.valueAt(index); |
| 388 | setPreProcessorEnabled(inputDesc, false); |
| 389 | inputDesc->mEffects.clear(); |
| 390 | delete inputDesc; |
| 391 | mInputs.removeItemsAt(index); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 394 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 395 | int indexMin, |
| 396 | int indexMax) |
| 397 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 398 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 399 | return NO_INIT; |
| 400 | } |
| 401 | if (!checkPermission()) { |
| 402 | return PERMISSION_DENIED; |
| 403 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 404 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 405 | return BAD_VALUE; |
| 406 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 407 | mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 408 | return NO_ERROR; |
| 409 | } |
| 410 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 411 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, int index) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 412 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 413 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 414 | return NO_INIT; |
| 415 | } |
| 416 | if (!checkPermission()) { |
| 417 | return PERMISSION_DENIED; |
| 418 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 419 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 420 | return BAD_VALUE; |
| 421 | } |
| 422 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 423 | return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 426 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, int *index) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 427 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 428 | if (mpAudioPolicy == NULL) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 429 | return NO_INIT; |
| 430 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 431 | if (stream < 0 || stream >= AUDIO_STREAM_CNT) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 432 | return BAD_VALUE; |
| 433 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 434 | return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 437 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 438 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 439 | if (mpAudioPolicy == NULL) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 440 | return 0; |
| 441 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 442 | return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 445 | uint32_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 446 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 447 | if (mpAudioPolicy == NULL) { |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 448 | return 0; |
| 449 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 450 | return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream); |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 453 | audio_io_handle_t AudioPolicyService::getOutputForEffect(effect_descriptor_t *desc) |
| 454 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 455 | if (mpAudioPolicy == NULL) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 456 | return NO_INIT; |
| 457 | } |
| 458 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 459 | return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | status_t AudioPolicyService::registerEffect(effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 463 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 464 | uint32_t strategy, |
| 465 | int session, |
| 466 | int id) |
| 467 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 468 | if (mpAudioPolicy == NULL) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 469 | return NO_INIT; |
| 470 | } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 471 | return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | status_t AudioPolicyService::unregisterEffect(int id) |
| 475 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 476 | if (mpAudioPolicy == NULL) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 477 | return NO_INIT; |
| 478 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 479 | return mpAudioPolicy->unregister_effect(mpAudioPolicy, id); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 482 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 483 | { |
| 484 | if (mpAudioPolicy == NULL) { |
| 485 | return NO_INIT; |
| 486 | } |
| 487 | return mpAudioPolicy->set_effect_enabled(mpAudioPolicy, id, enabled); |
| 488 | } |
| 489 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 490 | bool AudioPolicyService::isStreamActive(int stream, uint32_t inPastMs) const |
| 491 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 492 | if (mpAudioPolicy == NULL) { |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | Mutex::Autolock _l(mLock); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 496 | return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs); |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 499 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 500 | effect_descriptor_t *descriptors, |
| 501 | uint32_t *count) |
| 502 | { |
| 503 | |
| 504 | if (mpAudioPolicy == NULL) { |
| 505 | *count = 0; |
| 506 | return NO_INIT; |
| 507 | } |
| 508 | Mutex::Autolock _l(mLock); |
| 509 | status_t status = NO_ERROR; |
| 510 | |
| 511 | size_t index; |
| 512 | for (index = 0; index < mInputs.size(); index++) { |
| 513 | if (mInputs.valueAt(index)->mSessionId == audioSession) { |
| 514 | break; |
| 515 | } |
| 516 | } |
| 517 | if (index == mInputs.size()) { |
| 518 | *count = 0; |
| 519 | return BAD_VALUE; |
| 520 | } |
| 521 | Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects; |
| 522 | |
| 523 | for (size_t i = 0; i < effects.size(); i++) { |
| 524 | effect_descriptor_t desc = effects[i]->descriptor(); |
| 525 | if (i < *count) { |
| 526 | memcpy(descriptors + i, &desc, sizeof(effect_descriptor_t)); |
| 527 | } |
| 528 | } |
| 529 | if (effects.size() > *count) { |
| 530 | status = NO_MEMORY; |
| 531 | } |
| 532 | *count = effects.size(); |
| 533 | return status; |
| 534 | } |
| 535 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 536 | void AudioPolicyService::binderDied(const wp<IBinder>& who) { |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 537 | LOGW("binderDied() %p, tid %d, calling tid %d", who.unsafe_get(), gettid(), |
| 538 | IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static bool tryLock(Mutex& mutex) |
| 542 | { |
| 543 | bool locked = false; |
| 544 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 545 | if (mutex.tryLock() == NO_ERROR) { |
| 546 | locked = true; |
| 547 | break; |
| 548 | } |
| 549 | usleep(kDumpLockSleep); |
| 550 | } |
| 551 | return locked; |
| 552 | } |
| 553 | |
| 554 | status_t AudioPolicyService::dumpInternals(int fd) |
| 555 | { |
| 556 | const size_t SIZE = 256; |
| 557 | char buffer[SIZE]; |
| 558 | String8 result; |
| 559 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 560 | snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 561 | result.append(buffer); |
| 562 | snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get()); |
| 563 | result.append(buffer); |
| 564 | snprintf(buffer, SIZE, "Tones Thread: %p\n", mTonePlaybackThread.get()); |
| 565 | result.append(buffer); |
| 566 | |
| 567 | write(fd, result.string(), result.size()); |
| 568 | return NO_ERROR; |
| 569 | } |
| 570 | |
| 571 | status_t AudioPolicyService::dump(int fd, const Vector<String16>& args) |
| 572 | { |
| 573 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 574 | dumpPermissionDenial(fd); |
| 575 | } else { |
| 576 | bool locked = tryLock(mLock); |
| 577 | if (!locked) { |
| 578 | String8 result(kDeadlockedString); |
| 579 | write(fd, result.string(), result.size()); |
| 580 | } |
| 581 | |
| 582 | dumpInternals(fd); |
| 583 | if (mAudioCommandThread != NULL) { |
| 584 | mAudioCommandThread->dump(fd); |
| 585 | } |
| 586 | if (mTonePlaybackThread != NULL) { |
| 587 | mTonePlaybackThread->dump(fd); |
| 588 | } |
| 589 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 590 | if (mpAudioPolicy) { |
| 591 | mpAudioPolicy->dump(mpAudioPolicy, fd); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | if (locked) mLock.unlock(); |
| 595 | } |
| 596 | return NO_ERROR; |
| 597 | } |
| 598 | |
| 599 | status_t AudioPolicyService::dumpPermissionDenial(int fd) |
| 600 | { |
| 601 | const size_t SIZE = 256; |
| 602 | char buffer[SIZE]; |
| 603 | String8 result; |
| 604 | snprintf(buffer, SIZE, "Permission Denial: " |
| 605 | "can't dump AudioPolicyService from pid=%d, uid=%d\n", |
| 606 | IPCThreadState::self()->getCallingPid(), |
| 607 | IPCThreadState::self()->getCallingUid()); |
| 608 | result.append(buffer); |
| 609 | write(fd, result.string(), result.size()); |
| 610 | return NO_ERROR; |
| 611 | } |
| 612 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 613 | void AudioPolicyService::setPreProcessorEnabled(InputDesc *inputDesc, bool enabled) |
| 614 | { |
| 615 | Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects; |
| 616 | for (size_t i = 0; i < fxVector.size(); i++) { |
| 617 | sp<AudioEffect> fx = fxVector.itemAt(i); |
| 618 | fx->setEnabled(enabled); |
| 619 | } |
| 620 | } |
| 621 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 622 | status_t AudioPolicyService::onTransact( |
| 623 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 624 | { |
| 625 | return BnAudioPolicyService::onTransact(code, data, reply, flags); |
| 626 | } |
| 627 | |
| 628 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 629 | // ----------- AudioPolicyService::AudioCommandThread implementation ---------- |
| 630 | |
| 631 | AudioPolicyService::AudioCommandThread::AudioCommandThread(String8 name) |
| 632 | : Thread(false), mName(name) |
| 633 | { |
| 634 | mpToneGenerator = NULL; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | AudioPolicyService::AudioCommandThread::~AudioCommandThread() |
| 639 | { |
| 640 | if (mName != "" && !mAudioCommands.isEmpty()) { |
| 641 | release_wake_lock(mName.string()); |
| 642 | } |
| 643 | mAudioCommands.clear(); |
| 644 | if (mpToneGenerator != NULL) delete mpToneGenerator; |
| 645 | } |
| 646 | |
| 647 | void AudioPolicyService::AudioCommandThread::onFirstRef() |
| 648 | { |
| 649 | if (mName != "") { |
| 650 | run(mName.string(), ANDROID_PRIORITY_AUDIO); |
| 651 | } else { |
| 652 | run("AudioCommandThread", ANDROID_PRIORITY_AUDIO); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | bool AudioPolicyService::AudioCommandThread::threadLoop() |
| 657 | { |
| 658 | nsecs_t waitTime = INT64_MAX; |
| 659 | |
| 660 | mLock.lock(); |
| 661 | while (!exitPending()) |
| 662 | { |
| 663 | while(!mAudioCommands.isEmpty()) { |
| 664 | nsecs_t curTime = systemTime(); |
| 665 | // commands are sorted by increasing time stamp: execute them from index 0 and up |
| 666 | if (mAudioCommands[0]->mTime <= curTime) { |
| 667 | AudioCommand *command = mAudioCommands[0]; |
| 668 | mAudioCommands.removeAt(0); |
| 669 | mLastCommand = *command; |
| 670 | |
| 671 | switch (command->mCommand) { |
| 672 | case START_TONE: { |
| 673 | mLock.unlock(); |
| 674 | ToneData *data = (ToneData *)command->mParam; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 675 | ALOGV("AudioCommandThread() processing start tone %d on stream %d", |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 676 | data->mType, data->mStream); |
| 677 | if (mpToneGenerator != NULL) |
| 678 | delete mpToneGenerator; |
| 679 | mpToneGenerator = new ToneGenerator(data->mStream, 1.0); |
| 680 | mpToneGenerator->startTone(data->mType); |
| 681 | delete data; |
| 682 | mLock.lock(); |
| 683 | }break; |
| 684 | case STOP_TONE: { |
| 685 | mLock.unlock(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 686 | ALOGV("AudioCommandThread() processing stop tone"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 687 | if (mpToneGenerator != NULL) { |
| 688 | mpToneGenerator->stopTone(); |
| 689 | delete mpToneGenerator; |
| 690 | mpToneGenerator = NULL; |
| 691 | } |
| 692 | mLock.lock(); |
| 693 | }break; |
| 694 | case SET_VOLUME: { |
| 695 | VolumeData *data = (VolumeData *)command->mParam; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 696 | ALOGV("AudioCommandThread() processing set volume stream %d, \ |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 697 | volume %f, output %d", data->mStream, data->mVolume, data->mIO); |
| 698 | command->mStatus = AudioSystem::setStreamVolume(data->mStream, |
| 699 | data->mVolume, |
| 700 | data->mIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 701 | if (command->mWaitStatus) { |
| 702 | command->mCond.signal(); |
| 703 | mWaitWorkCV.wait(mLock); |
| 704 | } |
| 705 | delete data; |
| 706 | }break; |
| 707 | case SET_PARAMETERS: { |
| 708 | ParametersData *data = (ParametersData *)command->mParam; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 709 | ALOGV("AudioCommandThread() processing set parameters string %s, io %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 710 | data->mKeyValuePairs.string(), data->mIO); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 711 | command->mStatus = AudioSystem::setParameters(data->mIO, data->mKeyValuePairs); |
| 712 | if (command->mWaitStatus) { |
| 713 | command->mCond.signal(); |
| 714 | mWaitWorkCV.wait(mLock); |
| 715 | } |
| 716 | delete data; |
| 717 | }break; |
| 718 | case SET_VOICE_VOLUME: { |
| 719 | VoiceVolumeData *data = (VoiceVolumeData *)command->mParam; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 720 | ALOGV("AudioCommandThread() processing set voice volume volume %f", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 721 | data->mVolume); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 722 | command->mStatus = AudioSystem::setVoiceVolume(data->mVolume); |
| 723 | if (command->mWaitStatus) { |
| 724 | command->mCond.signal(); |
| 725 | mWaitWorkCV.wait(mLock); |
| 726 | } |
| 727 | delete data; |
| 728 | }break; |
| 729 | default: |
| 730 | LOGW("AudioCommandThread() unknown command %d", command->mCommand); |
| 731 | } |
| 732 | delete command; |
| 733 | waitTime = INT64_MAX; |
| 734 | } else { |
| 735 | waitTime = mAudioCommands[0]->mTime - curTime; |
| 736 | break; |
| 737 | } |
| 738 | } |
| 739 | // release delayed commands wake lock |
| 740 | if (mName != "" && mAudioCommands.isEmpty()) { |
| 741 | release_wake_lock(mName.string()); |
| 742 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 743 | ALOGV("AudioCommandThread() going to sleep"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 744 | mWaitWorkCV.waitRelative(mLock, waitTime); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 745 | ALOGV("AudioCommandThread() waking up"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 746 | } |
| 747 | mLock.unlock(); |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | status_t AudioPolicyService::AudioCommandThread::dump(int fd) |
| 752 | { |
| 753 | const size_t SIZE = 256; |
| 754 | char buffer[SIZE]; |
| 755 | String8 result; |
| 756 | |
| 757 | snprintf(buffer, SIZE, "AudioCommandThread %p Dump\n", this); |
| 758 | result.append(buffer); |
| 759 | write(fd, result.string(), result.size()); |
| 760 | |
| 761 | bool locked = tryLock(mLock); |
| 762 | if (!locked) { |
| 763 | String8 result2(kCmdDeadlockedString); |
| 764 | write(fd, result2.string(), result2.size()); |
| 765 | } |
| 766 | |
| 767 | snprintf(buffer, SIZE, "- Commands:\n"); |
| 768 | result = String8(buffer); |
| 769 | result.append(" Command Time Wait pParam\n"); |
| 770 | for (int i = 0; i < (int)mAudioCommands.size(); i++) { |
| 771 | mAudioCommands[i]->dump(buffer, SIZE); |
| 772 | result.append(buffer); |
| 773 | } |
| 774 | result.append(" Last Command\n"); |
| 775 | mLastCommand.dump(buffer, SIZE); |
| 776 | result.append(buffer); |
| 777 | |
| 778 | write(fd, result.string(), result.size()); |
| 779 | |
| 780 | if (locked) mLock.unlock(); |
| 781 | |
| 782 | return NO_ERROR; |
| 783 | } |
| 784 | |
| 785 | void AudioPolicyService::AudioCommandThread::startToneCommand(int type, int stream) |
| 786 | { |
| 787 | AudioCommand *command = new AudioCommand(); |
| 788 | command->mCommand = START_TONE; |
| 789 | ToneData *data = new ToneData(); |
| 790 | data->mType = type; |
| 791 | data->mStream = stream; |
| 792 | command->mParam = (void *)data; |
| 793 | command->mWaitStatus = false; |
| 794 | Mutex::Autolock _l(mLock); |
| 795 | insertCommand_l(command); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 796 | ALOGV("AudioCommandThread() adding tone start type %d, stream %d", type, stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 797 | mWaitWorkCV.signal(); |
| 798 | } |
| 799 | |
| 800 | void AudioPolicyService::AudioCommandThread::stopToneCommand() |
| 801 | { |
| 802 | AudioCommand *command = new AudioCommand(); |
| 803 | command->mCommand = STOP_TONE; |
| 804 | command->mParam = NULL; |
| 805 | command->mWaitStatus = false; |
| 806 | Mutex::Autolock _l(mLock); |
| 807 | insertCommand_l(command); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 808 | ALOGV("AudioCommandThread() adding tone stop"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 809 | mWaitWorkCV.signal(); |
| 810 | } |
| 811 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 812 | status_t AudioPolicyService::AudioCommandThread::volumeCommand(int stream, |
| 813 | float volume, |
| 814 | int output, |
| 815 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 816 | { |
| 817 | status_t status = NO_ERROR; |
| 818 | |
| 819 | AudioCommand *command = new AudioCommand(); |
| 820 | command->mCommand = SET_VOLUME; |
| 821 | VolumeData *data = new VolumeData(); |
| 822 | data->mStream = stream; |
| 823 | data->mVolume = volume; |
| 824 | data->mIO = output; |
| 825 | command->mParam = data; |
| 826 | if (delayMs == 0) { |
| 827 | command->mWaitStatus = true; |
| 828 | } else { |
| 829 | command->mWaitStatus = false; |
| 830 | } |
| 831 | Mutex::Autolock _l(mLock); |
| 832 | insertCommand_l(command, delayMs); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 833 | ALOGV("AudioCommandThread() adding set volume stream %d, volume %f, output %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 834 | stream, volume, output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 835 | mWaitWorkCV.signal(); |
| 836 | if (command->mWaitStatus) { |
| 837 | command->mCond.wait(mLock); |
| 838 | status = command->mStatus; |
| 839 | mWaitWorkCV.signal(); |
| 840 | } |
| 841 | return status; |
| 842 | } |
| 843 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 844 | status_t AudioPolicyService::AudioCommandThread::parametersCommand(int ioHandle, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 845 | const char *keyValuePairs, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 846 | int delayMs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 847 | { |
| 848 | status_t status = NO_ERROR; |
| 849 | |
| 850 | AudioCommand *command = new AudioCommand(); |
| 851 | command->mCommand = SET_PARAMETERS; |
| 852 | ParametersData *data = new ParametersData(); |
| 853 | data->mIO = ioHandle; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 854 | data->mKeyValuePairs = String8(keyValuePairs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 855 | command->mParam = data; |
| 856 | if (delayMs == 0) { |
| 857 | command->mWaitStatus = true; |
| 858 | } else { |
| 859 | command->mWaitStatus = false; |
| 860 | } |
| 861 | Mutex::Autolock _l(mLock); |
| 862 | insertCommand_l(command, delayMs); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 863 | ALOGV("AudioCommandThread() adding set parameter string %s, io %d ,delay %d", |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 864 | keyValuePairs, ioHandle, delayMs); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 865 | mWaitWorkCV.signal(); |
| 866 | if (command->mWaitStatus) { |
| 867 | command->mCond.wait(mLock); |
| 868 | status = command->mStatus; |
| 869 | mWaitWorkCV.signal(); |
| 870 | } |
| 871 | return status; |
| 872 | } |
| 873 | |
| 874 | status_t AudioPolicyService::AudioCommandThread::voiceVolumeCommand(float volume, int delayMs) |
| 875 | { |
| 876 | status_t status = NO_ERROR; |
| 877 | |
| 878 | AudioCommand *command = new AudioCommand(); |
| 879 | command->mCommand = SET_VOICE_VOLUME; |
| 880 | VoiceVolumeData *data = new VoiceVolumeData(); |
| 881 | data->mVolume = volume; |
| 882 | command->mParam = data; |
| 883 | if (delayMs == 0) { |
| 884 | command->mWaitStatus = true; |
| 885 | } else { |
| 886 | command->mWaitStatus = false; |
| 887 | } |
| 888 | Mutex::Autolock _l(mLock); |
| 889 | insertCommand_l(command, delayMs); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 890 | ALOGV("AudioCommandThread() adding set voice volume volume %f", volume); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 891 | mWaitWorkCV.signal(); |
| 892 | if (command->mWaitStatus) { |
| 893 | command->mCond.wait(mLock); |
| 894 | status = command->mStatus; |
| 895 | mWaitWorkCV.signal(); |
| 896 | } |
| 897 | return status; |
| 898 | } |
| 899 | |
| 900 | // insertCommand_l() must be called with mLock held |
| 901 | void AudioPolicyService::AudioCommandThread::insertCommand_l(AudioCommand *command, int delayMs) |
| 902 | { |
| 903 | ssize_t i; |
| 904 | Vector <AudioCommand *> removedCommands; |
| 905 | |
| 906 | command->mTime = systemTime() + milliseconds(delayMs); |
| 907 | |
| 908 | // acquire wake lock to make sure delayed commands are processed |
| 909 | if (mName != "" && mAudioCommands.isEmpty()) { |
| 910 | acquire_wake_lock(PARTIAL_WAKE_LOCK, mName.string()); |
| 911 | } |
| 912 | |
| 913 | // check same pending commands with later time stamps and eliminate them |
| 914 | for (i = mAudioCommands.size()-1; i >= 0; i--) { |
| 915 | AudioCommand *command2 = mAudioCommands[i]; |
| 916 | // commands are sorted by increasing time stamp: no need to scan the rest of mAudioCommands |
| 917 | if (command2->mTime <= command->mTime) break; |
| 918 | if (command2->mCommand != command->mCommand) continue; |
| 919 | |
| 920 | switch (command->mCommand) { |
| 921 | case SET_PARAMETERS: { |
| 922 | ParametersData *data = (ParametersData *)command->mParam; |
| 923 | ParametersData *data2 = (ParametersData *)command2->mParam; |
| 924 | if (data->mIO != data2->mIO) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 925 | ALOGV("Comparing parameter command %s to new command %s", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 926 | data2->mKeyValuePairs.string(), data->mKeyValuePairs.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 927 | AudioParameter param = AudioParameter(data->mKeyValuePairs); |
| 928 | AudioParameter param2 = AudioParameter(data2->mKeyValuePairs); |
| 929 | for (size_t j = 0; j < param.size(); j++) { |
| 930 | String8 key; |
| 931 | String8 value; |
| 932 | param.getAt(j, key, value); |
| 933 | for (size_t k = 0; k < param2.size(); k++) { |
| 934 | String8 key2; |
| 935 | String8 value2; |
| 936 | param2.getAt(k, key2, value2); |
| 937 | if (key2 == key) { |
| 938 | param2.remove(key2); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 939 | ALOGV("Filtering out parameter %s", key2.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 940 | break; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | // if all keys have been filtered out, remove the command. |
| 945 | // otherwise, update the key value pairs |
| 946 | if (param2.size() == 0) { |
| 947 | removedCommands.add(command2); |
| 948 | } else { |
| 949 | data2->mKeyValuePairs = param2.toString(); |
| 950 | } |
| 951 | } break; |
| 952 | |
| 953 | case SET_VOLUME: { |
| 954 | VolumeData *data = (VolumeData *)command->mParam; |
| 955 | VolumeData *data2 = (VolumeData *)command2->mParam; |
| 956 | if (data->mIO != data2->mIO) break; |
| 957 | if (data->mStream != data2->mStream) break; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 958 | ALOGV("Filtering out volume command on output %d for stream %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 959 | data->mIO, data->mStream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 960 | removedCommands.add(command2); |
| 961 | } break; |
| 962 | case START_TONE: |
| 963 | case STOP_TONE: |
| 964 | default: |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | // remove filtered commands |
| 970 | for (size_t j = 0; j < removedCommands.size(); j++) { |
| 971 | // removed commands always have time stamps greater than current command |
| 972 | for (size_t k = i + 1; k < mAudioCommands.size(); k++) { |
| 973 | if (mAudioCommands[k] == removedCommands[j]) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 974 | ALOGV("suppressing command: %d", mAudioCommands[k]->mCommand); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 975 | mAudioCommands.removeAt(k); |
| 976 | break; |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | removedCommands.clear(); |
| 981 | |
| 982 | // insert command at the right place according to its time stamp |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 983 | ALOGV("inserting command: %d at index %d, num commands %d", |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 984 | command->mCommand, (int)i+1, mAudioCommands.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 985 | mAudioCommands.insertAt(command, i + 1); |
| 986 | } |
| 987 | |
| 988 | void AudioPolicyService::AudioCommandThread::exit() |
| 989 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 990 | ALOGV("AudioCommandThread::exit"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 991 | { |
| 992 | AutoMutex _l(mLock); |
| 993 | requestExit(); |
| 994 | mWaitWorkCV.signal(); |
| 995 | } |
| 996 | requestExitAndWait(); |
| 997 | } |
| 998 | |
| 999 | void AudioPolicyService::AudioCommandThread::AudioCommand::dump(char* buffer, size_t size) |
| 1000 | { |
| 1001 | snprintf(buffer, size, " %02d %06d.%03d %01u %p\n", |
| 1002 | mCommand, |
| 1003 | (int)ns2s(mTime), |
| 1004 | (int)ns2ms(mTime)%1000, |
| 1005 | mWaitStatus, |
| 1006 | mParam); |
| 1007 | } |
| 1008 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1009 | /******* helpers for the service_ops callbacks defined below *********/ |
| 1010 | void AudioPolicyService::setParameters(audio_io_handle_t ioHandle, |
| 1011 | const char *keyValuePairs, |
| 1012 | int delayMs) |
| 1013 | { |
| 1014 | mAudioCommandThread->parametersCommand((int)ioHandle, keyValuePairs, |
| 1015 | delayMs); |
| 1016 | } |
| 1017 | |
| 1018 | int AudioPolicyService::setStreamVolume(audio_stream_type_t stream, |
| 1019 | float volume, |
| 1020 | audio_io_handle_t output, |
| 1021 | int delayMs) |
| 1022 | { |
| 1023 | return (int)mAudioCommandThread->volumeCommand((int)stream, volume, |
| 1024 | (int)output, delayMs); |
| 1025 | } |
| 1026 | |
| 1027 | int AudioPolicyService::startTone(audio_policy_tone_t tone, |
| 1028 | audio_stream_type_t stream) |
| 1029 | { |
| 1030 | if (tone != AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION) |
| 1031 | LOGE("startTone: illegal tone requested (%d)", tone); |
| 1032 | if (stream != AUDIO_STREAM_VOICE_CALL) |
| 1033 | LOGE("startTone: illegal stream (%d) requested for tone %d", stream, |
| 1034 | tone); |
| 1035 | mTonePlaybackThread->startToneCommand(ToneGenerator::TONE_SUP_CALL_WAITING, |
| 1036 | AUDIO_STREAM_VOICE_CALL); |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | int AudioPolicyService::stopTone() |
| 1041 | { |
| 1042 | mTonePlaybackThread->stopToneCommand(); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | int AudioPolicyService::setVoiceVolume(float volume, int delayMs) |
| 1047 | { |
| 1048 | return (int)mAudioCommandThread->voiceVolumeCommand(volume, delayMs); |
| 1049 | } |
| 1050 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1051 | // ---------------------------------------------------------------------------- |
| 1052 | // Audio pre-processing configuration |
| 1053 | // ---------------------------------------------------------------------------- |
| 1054 | |
| 1055 | const char *AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = { |
| 1056 | MIC_SRC_TAG, |
| 1057 | VOICE_UL_SRC_TAG, |
| 1058 | VOICE_DL_SRC_TAG, |
| 1059 | VOICE_CALL_SRC_TAG, |
| 1060 | CAMCORDER_SRC_TAG, |
| 1061 | VOICE_REC_SRC_TAG, |
| 1062 | VOICE_COMM_SRC_TAG |
| 1063 | }; |
| 1064 | |
| 1065 | // returns the audio_source_t enum corresponding to the input source name or |
| 1066 | // AUDIO_SOURCE_CNT is no match found |
| 1067 | audio_source_t AudioPolicyService::inputSourceNameToEnum(const char *name) |
| 1068 | { |
| 1069 | int i; |
| 1070 | for (i = AUDIO_SOURCE_MIC; i < AUDIO_SOURCE_CNT; i++) { |
| 1071 | if (strcmp(name, kInputSourceNames[i - AUDIO_SOURCE_MIC]) == 0) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1072 | ALOGV("inputSourceNameToEnum found source %s %d", name, i); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | return (audio_source_t)i; |
| 1077 | } |
| 1078 | |
| 1079 | size_t AudioPolicyService::growParamSize(char *param, |
| 1080 | size_t size, |
| 1081 | size_t *curSize, |
| 1082 | size_t *totSize) |
| 1083 | { |
| 1084 | // *curSize is at least sizeof(effect_param_t) + 2 * sizeof(int) |
| 1085 | size_t pos = ((*curSize - 1 ) / size + 1) * size; |
| 1086 | |
| 1087 | if (pos + size > *totSize) { |
| 1088 | while (pos + size > *totSize) { |
| 1089 | *totSize += ((*totSize + 7) / 8) * 4; |
| 1090 | } |
| 1091 | param = (char *)realloc(param, *totSize); |
| 1092 | } |
| 1093 | *curSize = pos + size; |
| 1094 | return pos; |
| 1095 | } |
| 1096 | |
| 1097 | size_t AudioPolicyService::readParamValue(cnode *node, |
| 1098 | char *param, |
| 1099 | size_t *curSize, |
| 1100 | size_t *totSize) |
| 1101 | { |
| 1102 | if (strncmp(node->name, SHORT_TAG, sizeof(SHORT_TAG) + 1) == 0) { |
| 1103 | size_t pos = growParamSize(param, sizeof(short), curSize, totSize); |
| 1104 | *(short *)((char *)param + pos) = (short)atoi(node->value); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1105 | ALOGV("readParamValue() reading short %d", *(short *)((char *)param + pos)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1106 | return sizeof(short); |
| 1107 | } else if (strncmp(node->name, INT_TAG, sizeof(INT_TAG) + 1) == 0) { |
| 1108 | size_t pos = growParamSize(param, sizeof(int), curSize, totSize); |
| 1109 | *(int *)((char *)param + pos) = atoi(node->value); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1110 | ALOGV("readParamValue() reading int %d", *(int *)((char *)param + pos)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1111 | return sizeof(int); |
| 1112 | } else if (strncmp(node->name, FLOAT_TAG, sizeof(FLOAT_TAG) + 1) == 0) { |
| 1113 | size_t pos = growParamSize(param, sizeof(float), curSize, totSize); |
| 1114 | *(float *)((char *)param + pos) = (float)atof(node->value); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1115 | ALOGV("readParamValue() reading float %f",*(float *)((char *)param + pos)); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1116 | return sizeof(float); |
| 1117 | } else if (strncmp(node->name, BOOL_TAG, sizeof(BOOL_TAG) + 1) == 0) { |
| 1118 | size_t pos = growParamSize(param, sizeof(bool), curSize, totSize); |
| 1119 | if (strncmp(node->value, "false", strlen("false") + 1) == 0) { |
| 1120 | *(bool *)((char *)param + pos) = false; |
| 1121 | } else { |
| 1122 | *(bool *)((char *)param + pos) = true; |
| 1123 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1124 | ALOGV("readParamValue() reading bool %s",*(bool *)((char *)param + pos) ? "true" : "false"); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1125 | return sizeof(bool); |
| 1126 | } else if (strncmp(node->name, STRING_TAG, sizeof(STRING_TAG) + 1) == 0) { |
| 1127 | size_t len = strnlen(node->value, EFFECT_STRING_LEN_MAX); |
| 1128 | if (*curSize + len + 1 > *totSize) { |
| 1129 | *totSize = *curSize + len + 1; |
| 1130 | param = (char *)realloc(param, *totSize); |
| 1131 | } |
| 1132 | strncpy(param + *curSize, node->value, len); |
| 1133 | *curSize += len; |
| 1134 | param[*curSize] = '\0'; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1135 | ALOGV("readParamValue() reading string %s", param + *curSize - len); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1136 | return len; |
| 1137 | } |
| 1138 | LOGW("readParamValue() unknown param type %s", node->name); |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | effect_param_t *AudioPolicyService::loadEffectParameter(cnode *root) |
| 1143 | { |
| 1144 | cnode *param; |
| 1145 | cnode *value; |
| 1146 | size_t curSize = sizeof(effect_param_t); |
| 1147 | size_t totSize = sizeof(effect_param_t) + 2 * sizeof(int); |
| 1148 | effect_param_t *fx_param = (effect_param_t *)malloc(totSize); |
| 1149 | |
| 1150 | param = config_find(root, PARAM_TAG); |
| 1151 | value = config_find(root, VALUE_TAG); |
| 1152 | if (param == NULL && value == NULL) { |
| 1153 | // try to parse simple parameter form {int int} |
| 1154 | param = root->first_child; |
| 1155 | if (param) { |
| 1156 | // Note: that a pair of random strings is read as 0 0 |
| 1157 | int *ptr = (int *)fx_param->data; |
| 1158 | int *ptr2 = (int *)((char *)param + sizeof(effect_param_t)); |
| 1159 | LOGW("loadEffectParameter() ptr %p ptr2 %p", ptr, ptr2); |
| 1160 | *ptr++ = atoi(param->name); |
| 1161 | *ptr = atoi(param->value); |
| 1162 | fx_param->psize = sizeof(int); |
| 1163 | fx_param->vsize = sizeof(int); |
| 1164 | return fx_param; |
| 1165 | } |
| 1166 | } |
| 1167 | if (param == NULL || value == NULL) { |
| 1168 | LOGW("loadEffectParameter() invalid parameter description %s", root->name); |
| 1169 | goto error; |
| 1170 | } |
| 1171 | |
| 1172 | fx_param->psize = 0; |
| 1173 | param = param->first_child; |
| 1174 | while (param) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1175 | ALOGV("loadEffectParameter() reading param of type %s", param->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1176 | size_t size = readParamValue(param, (char *)fx_param, &curSize, &totSize); |
| 1177 | if (size == 0) { |
| 1178 | goto error; |
| 1179 | } |
| 1180 | fx_param->psize += size; |
| 1181 | param = param->next; |
| 1182 | } |
| 1183 | |
| 1184 | // align start of value field on 32 bit boundary |
| 1185 | curSize = ((curSize - 1 ) / sizeof(int) + 1) * sizeof(int); |
| 1186 | |
| 1187 | fx_param->vsize = 0; |
| 1188 | value = value->first_child; |
| 1189 | while (value) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1190 | ALOGV("loadEffectParameter() reading value of type %s", value->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1191 | size_t size = readParamValue(value, (char *)fx_param, &curSize, &totSize); |
| 1192 | if (size == 0) { |
| 1193 | goto error; |
| 1194 | } |
| 1195 | fx_param->vsize += size; |
| 1196 | value = value->next; |
| 1197 | } |
| 1198 | |
| 1199 | return fx_param; |
| 1200 | |
| 1201 | error: |
| 1202 | delete fx_param; |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | |
| 1206 | void AudioPolicyService::loadEffectParameters(cnode *root, Vector <effect_param_t *>& params) |
| 1207 | { |
| 1208 | cnode *node = root->first_child; |
| 1209 | while (node) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1210 | ALOGV("loadEffectParameters() loading param %s", node->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1211 | effect_param_t *param = loadEffectParameter(node); |
| 1212 | if (param == NULL) { |
| 1213 | node = node->next; |
| 1214 | continue; |
| 1215 | } |
| 1216 | params.add(param); |
| 1217 | node = node->next; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | AudioPolicyService::InputSourceDesc *AudioPolicyService::loadInputSource( |
| 1222 | cnode *root, |
| 1223 | const Vector <EffectDesc *>& effects) |
| 1224 | { |
| 1225 | cnode *node = root->first_child; |
| 1226 | if (node == NULL) { |
| 1227 | LOGW("loadInputSource() empty element %s", root->name); |
| 1228 | return NULL; |
| 1229 | } |
| 1230 | InputSourceDesc *source = new InputSourceDesc(); |
| 1231 | while (node) { |
| 1232 | size_t i; |
| 1233 | for (i = 0; i < effects.size(); i++) { |
| 1234 | if (strncmp(effects[i]->mName, node->name, EFFECT_STRING_LEN_MAX) == 0) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1235 | ALOGV("loadInputSource() found effect %s in list", node->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1236 | break; |
| 1237 | } |
| 1238 | } |
| 1239 | if (i == effects.size()) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1240 | ALOGV("loadInputSource() effect %s not in list", node->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1241 | node = node->next; |
| 1242 | continue; |
| 1243 | } |
| 1244 | EffectDesc *effect = new EffectDesc(*effects[i]); |
| 1245 | loadEffectParameters(node, effect->mParams); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1246 | ALOGV("loadInputSource() adding effect %s uuid %08x", effect->mName, effect->mUuid.timeLow); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1247 | source->mEffects.add(effect); |
| 1248 | node = node->next; |
| 1249 | } |
| 1250 | if (source->mEffects.size() == 0) { |
| 1251 | LOGW("loadInputSource() no valid effects found in source %s", root->name); |
| 1252 | delete source; |
| 1253 | return NULL; |
| 1254 | } |
| 1255 | return source; |
| 1256 | } |
| 1257 | |
| 1258 | status_t AudioPolicyService::loadInputSources(cnode *root, const Vector <EffectDesc *>& effects) |
| 1259 | { |
| 1260 | cnode *node = config_find(root, PREPROCESSING_TAG); |
| 1261 | if (node == NULL) { |
| 1262 | return -ENOENT; |
| 1263 | } |
| 1264 | node = node->first_child; |
| 1265 | while (node) { |
| 1266 | audio_source_t source = inputSourceNameToEnum(node->name); |
| 1267 | if (source == AUDIO_SOURCE_CNT) { |
| 1268 | LOGW("loadInputSources() invalid input source %s", node->name); |
| 1269 | node = node->next; |
| 1270 | continue; |
| 1271 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1272 | ALOGV("loadInputSources() loading input source %s", node->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1273 | InputSourceDesc *desc = loadInputSource(node, effects); |
| 1274 | if (desc == NULL) { |
| 1275 | node = node->next; |
| 1276 | continue; |
| 1277 | } |
| 1278 | mInputSources.add(source, desc); |
| 1279 | node = node->next; |
| 1280 | } |
| 1281 | return NO_ERROR; |
| 1282 | } |
| 1283 | |
| 1284 | AudioPolicyService::EffectDesc *AudioPolicyService::loadEffect(cnode *root) |
| 1285 | { |
| 1286 | cnode *node = config_find(root, UUID_TAG); |
| 1287 | if (node == NULL) { |
| 1288 | return NULL; |
| 1289 | } |
| 1290 | effect_uuid_t uuid; |
| 1291 | if (AudioEffect::stringToGuid(node->value, &uuid) != NO_ERROR) { |
| 1292 | LOGW("loadEffect() invalid uuid %s", node->value); |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | EffectDesc *effect = new EffectDesc(); |
| 1296 | effect->mName = strdup(root->name); |
| 1297 | memcpy(&effect->mUuid, &uuid, sizeof(effect_uuid_t)); |
| 1298 | |
| 1299 | return effect; |
| 1300 | } |
| 1301 | |
| 1302 | status_t AudioPolicyService::loadEffects(cnode *root, Vector <EffectDesc *>& effects) |
| 1303 | { |
| 1304 | cnode *node = config_find(root, EFFECTS_TAG); |
| 1305 | if (node == NULL) { |
| 1306 | return -ENOENT; |
| 1307 | } |
| 1308 | node = node->first_child; |
| 1309 | while (node) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1310 | ALOGV("loadEffects() loading effect %s", node->name); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1311 | EffectDesc *effect = loadEffect(node); |
| 1312 | if (effect == NULL) { |
| 1313 | node = node->next; |
| 1314 | continue; |
| 1315 | } |
| 1316 | effects.add(effect); |
| 1317 | node = node->next; |
| 1318 | } |
| 1319 | return NO_ERROR; |
| 1320 | } |
| 1321 | |
| 1322 | status_t AudioPolicyService::loadPreProcessorConfig(const char *path) |
| 1323 | { |
| 1324 | cnode *root; |
| 1325 | char *data; |
| 1326 | |
| 1327 | data = (char *)load_file(path, NULL); |
| 1328 | if (data == NULL) { |
| 1329 | return -ENODEV; |
| 1330 | } |
| 1331 | root = config_node("", ""); |
| 1332 | config_load(root, data); |
| 1333 | |
| 1334 | Vector <EffectDesc *> effects; |
| 1335 | loadEffects(root, effects); |
| 1336 | loadInputSources(root, effects); |
| 1337 | |
| 1338 | config_free(root); |
| 1339 | free(root); |
| 1340 | free(data); |
| 1341 | |
| 1342 | return NO_ERROR; |
| 1343 | } |
| 1344 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1345 | /* implementation of the interface to the policy manager */ |
| 1346 | extern "C" { |
| 1347 | |
| 1348 | static audio_io_handle_t aps_open_output(void *service, |
| 1349 | uint32_t *pDevices, |
| 1350 | uint32_t *pSamplingRate, |
| 1351 | uint32_t *pFormat, |
| 1352 | uint32_t *pChannels, |
| 1353 | uint32_t *pLatencyMs, |
| 1354 | audio_policy_output_flags_t flags) |
| 1355 | { |
| 1356 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1357 | if (af == NULL) { |
| 1358 | LOGW("%s: could not get AudioFlinger", __func__); |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | return af->openOutput(pDevices, pSamplingRate, pFormat, pChannels, |
| 1363 | pLatencyMs, flags); |
| 1364 | } |
| 1365 | |
| 1366 | static audio_io_handle_t aps_open_dup_output(void *service, |
| 1367 | audio_io_handle_t output1, |
| 1368 | audio_io_handle_t output2) |
| 1369 | { |
| 1370 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1371 | if (af == NULL) { |
| 1372 | LOGW("%s: could not get AudioFlinger", __func__); |
| 1373 | return 0; |
| 1374 | } |
| 1375 | return af->openDuplicateOutput(output1, output2); |
| 1376 | } |
| 1377 | |
| 1378 | static int aps_close_output(void *service, audio_io_handle_t output) |
| 1379 | { |
| 1380 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1381 | if (af == NULL) |
| 1382 | return PERMISSION_DENIED; |
| 1383 | |
| 1384 | return af->closeOutput(output); |
| 1385 | } |
| 1386 | |
| 1387 | static int aps_suspend_output(void *service, audio_io_handle_t output) |
| 1388 | { |
| 1389 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1390 | if (af == NULL) { |
| 1391 | LOGW("%s: could not get AudioFlinger", __func__); |
| 1392 | return PERMISSION_DENIED; |
| 1393 | } |
| 1394 | |
| 1395 | return af->suspendOutput(output); |
| 1396 | } |
| 1397 | |
| 1398 | static int aps_restore_output(void *service, audio_io_handle_t output) |
| 1399 | { |
| 1400 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1401 | if (af == NULL) { |
| 1402 | LOGW("%s: could not get AudioFlinger", __func__); |
| 1403 | return PERMISSION_DENIED; |
| 1404 | } |
| 1405 | |
| 1406 | return af->restoreOutput(output); |
| 1407 | } |
| 1408 | |
| 1409 | static audio_io_handle_t aps_open_input(void *service, |
| 1410 | uint32_t *pDevices, |
| 1411 | uint32_t *pSamplingRate, |
| 1412 | uint32_t *pFormat, |
| 1413 | uint32_t *pChannels, |
| 1414 | uint32_t acoustics) |
| 1415 | { |
| 1416 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1417 | if (af == NULL) { |
| 1418 | LOGW("%s: could not get AudioFlinger", __func__); |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | return af->openInput(pDevices, pSamplingRate, pFormat, pChannels, |
| 1423 | acoustics); |
| 1424 | } |
| 1425 | |
| 1426 | static int aps_close_input(void *service, audio_io_handle_t input) |
| 1427 | { |
| 1428 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1429 | if (af == NULL) |
| 1430 | return PERMISSION_DENIED; |
| 1431 | |
| 1432 | return af->closeInput(input); |
| 1433 | } |
| 1434 | |
| 1435 | static int aps_set_stream_output(void *service, audio_stream_type_t stream, |
| 1436 | audio_io_handle_t output) |
| 1437 | { |
| 1438 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1439 | if (af == NULL) |
| 1440 | return PERMISSION_DENIED; |
| 1441 | |
| 1442 | return af->setStreamOutput(stream, output); |
| 1443 | } |
| 1444 | |
| 1445 | static int aps_move_effects(void *service, int session, |
| 1446 | audio_io_handle_t src_output, |
| 1447 | audio_io_handle_t dst_output) |
| 1448 | { |
| 1449 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 1450 | if (af == NULL) |
| 1451 | return PERMISSION_DENIED; |
| 1452 | |
| 1453 | return af->moveEffects(session, (int)src_output, (int)dst_output); |
| 1454 | } |
| 1455 | |
| 1456 | static char * aps_get_parameters(void *service, audio_io_handle_t io_handle, |
| 1457 | const char *keys) |
| 1458 | { |
| 1459 | String8 result = AudioSystem::getParameters(io_handle, String8(keys)); |
| 1460 | return strdup(result.string()); |
| 1461 | } |
| 1462 | |
| 1463 | static void aps_set_parameters(void *service, audio_io_handle_t io_handle, |
| 1464 | const char *kv_pairs, int delay_ms) |
| 1465 | { |
| 1466 | AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; |
| 1467 | |
| 1468 | audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms); |
| 1469 | } |
| 1470 | |
| 1471 | static int aps_set_stream_volume(void *service, audio_stream_type_t stream, |
| 1472 | float volume, audio_io_handle_t output, |
| 1473 | int delay_ms) |
| 1474 | { |
| 1475 | AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; |
| 1476 | |
| 1477 | return audioPolicyService->setStreamVolume(stream, volume, output, |
| 1478 | delay_ms); |
| 1479 | } |
| 1480 | |
| 1481 | static int aps_start_tone(void *service, audio_policy_tone_t tone, |
| 1482 | audio_stream_type_t stream) |
| 1483 | { |
| 1484 | AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; |
| 1485 | |
| 1486 | return audioPolicyService->startTone(tone, stream); |
| 1487 | } |
| 1488 | |
| 1489 | static int aps_stop_tone(void *service) |
| 1490 | { |
| 1491 | AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; |
| 1492 | |
| 1493 | return audioPolicyService->stopTone(); |
| 1494 | } |
| 1495 | |
| 1496 | static int aps_set_voice_volume(void *service, float volume, int delay_ms) |
| 1497 | { |
| 1498 | AudioPolicyService *audioPolicyService = (AudioPolicyService *)service; |
| 1499 | |
| 1500 | return audioPolicyService->setVoiceVolume(volume, delay_ms); |
| 1501 | } |
| 1502 | |
| 1503 | }; // extern "C" |
| 1504 | |
| 1505 | namespace { |
| 1506 | struct audio_policy_service_ops aps_ops = { |
| 1507 | open_output : aps_open_output, |
| 1508 | open_duplicate_output : aps_open_dup_output, |
| 1509 | close_output : aps_close_output, |
| 1510 | suspend_output : aps_suspend_output, |
| 1511 | restore_output : aps_restore_output, |
| 1512 | open_input : aps_open_input, |
| 1513 | close_input : aps_close_input, |
| 1514 | set_stream_volume : aps_set_stream_volume, |
| 1515 | set_stream_output : aps_set_stream_output, |
| 1516 | set_parameters : aps_set_parameters, |
| 1517 | get_parameters : aps_get_parameters, |
| 1518 | start_tone : aps_start_tone, |
| 1519 | stop_tone : aps_stop_tone, |
| 1520 | set_voice_volume : aps_set_voice_volume, |
| 1521 | move_effects : aps_move_effects, |
| 1522 | }; |
| 1523 | }; // namespace <unnamed> |
| 1524 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1525 | }; // namespace android |