Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [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 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AudioPolicyIntefaceImpl" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <utils/Log.h> |
| 21 | #include "AudioPolicyService.h" |
| 22 | #include "ServiceUtilities.h" |
| 23 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | |
| 27 | // ---------------------------------------------------------------------------- |
| 28 | |
| 29 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, |
| 30 | audio_policy_dev_state_t state, |
| 31 | const char *device_address) |
| 32 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 33 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 34 | return NO_INIT; |
| 35 | } |
| 36 | if (!settingsAllowed()) { |
| 37 | return PERMISSION_DENIED; |
| 38 | } |
| 39 | if (!audio_is_output_device(device) && !audio_is_input_device(device)) { |
| 40 | return BAD_VALUE; |
| 41 | } |
| 42 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 43 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 44 | return BAD_VALUE; |
| 45 | } |
| 46 | |
| 47 | ALOGV("setDeviceConnectionState()"); |
| 48 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 49 | return mAudioPolicyManager->setDeviceConnectionState(device, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 50 | state, device_address); |
| 51 | } |
| 52 | |
| 53 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( |
| 54 | audio_devices_t device, |
| 55 | const char *device_address) |
| 56 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 57 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 58 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
| 59 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 60 | return mAudioPolicyManager->getDeviceConnectionState(device, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 61 | device_address); |
| 62 | } |
| 63 | |
| 64 | status_t AudioPolicyService::setPhoneState(audio_mode_t state) |
| 65 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 66 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 67 | return NO_INIT; |
| 68 | } |
| 69 | if (!settingsAllowed()) { |
| 70 | return PERMISSION_DENIED; |
| 71 | } |
| 72 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
| 73 | return BAD_VALUE; |
| 74 | } |
| 75 | |
| 76 | ALOGV("setPhoneState()"); |
| 77 | |
| 78 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 79 | AudioSystem::setMode(state); |
| 80 | |
| 81 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 82 | mAudioPolicyManager->setPhoneState(state); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 83 | return NO_ERROR; |
| 84 | } |
| 85 | |
| 86 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 87 | audio_policy_forced_cfg_t config) |
| 88 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 89 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 90 | return NO_INIT; |
| 91 | } |
| 92 | if (!settingsAllowed()) { |
| 93 | return PERMISSION_DENIED; |
| 94 | } |
| 95 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 96 | return BAD_VALUE; |
| 97 | } |
| 98 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 99 | return BAD_VALUE; |
| 100 | } |
| 101 | ALOGV("setForceUse()"); |
| 102 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 103 | mAudioPolicyManager->setForceUse(usage, config); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 104 | return NO_ERROR; |
| 105 | } |
| 106 | |
| 107 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 108 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 109 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 110 | return AUDIO_POLICY_FORCE_NONE; |
| 111 | } |
| 112 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 113 | return AUDIO_POLICY_FORCE_NONE; |
| 114 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 115 | return mAudioPolicyManager->getForceUse(usage); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream, |
| 119 | uint32_t samplingRate, |
| 120 | audio_format_t format, |
| 121 | audio_channel_mask_t channelMask, |
| 122 | audio_output_flags_t flags, |
| 123 | const audio_offload_info_t *offloadInfo) |
| 124 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 125 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | ALOGV("getOutput()"); |
| 129 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 130 | return mAudioPolicyManager->getOutput(stream, samplingRate, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 131 | format, channelMask, flags, offloadInfo); |
| 132 | } |
| 133 | |
| 134 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
| 135 | audio_stream_type_t stream, |
| 136 | int session) |
| 137 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 138 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 139 | return NO_INIT; |
| 140 | } |
| 141 | ALOGV("startOutput()"); |
| 142 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 143 | return mAudioPolicyManager->startOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 147 | audio_stream_type_t stream, |
| 148 | int session) |
| 149 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 150 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 151 | return NO_INIT; |
| 152 | } |
| 153 | ALOGV("stopOutput()"); |
| 154 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 155 | return NO_ERROR; |
| 156 | } |
| 157 | |
| 158 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 159 | audio_stream_type_t stream, |
| 160 | int session) |
| 161 | { |
| 162 | ALOGV("doStopOutput from tid %d", gettid()); |
| 163 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 164 | return mAudioPolicyManager->stopOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 168 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 169 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 170 | return; |
| 171 | } |
| 172 | ALOGV("releaseOutput()"); |
| 173 | mOutputCommandThread->releaseOutputCommand(output); |
| 174 | } |
| 175 | |
| 176 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output) |
| 177 | { |
| 178 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 179 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 180 | mAudioPolicyManager->releaseOutput(output); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource, |
| 184 | uint32_t samplingRate, |
| 185 | audio_format_t format, |
| 186 | audio_channel_mask_t channelMask, |
| 187 | int audioSession) |
| 188 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 189 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | // already checked by client, but double-check in case the client wrapper is bypassed |
| 193 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD) { |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) { |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | Mutex::Autolock _l(mLock); |
| 202 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 203 | audio_io_handle_t input = mAudioPolicyManager->getInput(inputSource, samplingRate, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 204 | format, channelMask, (audio_in_acoustics_t) 0); |
| 205 | |
| 206 | if (input == 0) { |
| 207 | return input; |
| 208 | } |
| 209 | // create audio pre processors according to input source |
| 210 | audio_source_t aliasSource = (inputSource == AUDIO_SOURCE_HOTWORD) ? |
| 211 | AUDIO_SOURCE_VOICE_RECOGNITION : inputSource; |
| 212 | |
| 213 | ssize_t index = mInputSources.indexOfKey(aliasSource); |
| 214 | if (index < 0) { |
| 215 | return input; |
| 216 | } |
| 217 | ssize_t idx = mInputs.indexOfKey(input); |
| 218 | InputDesc *inputDesc; |
| 219 | if (idx < 0) { |
| 220 | inputDesc = new InputDesc(audioSession); |
| 221 | mInputs.add(input, inputDesc); |
| 222 | } else { |
| 223 | inputDesc = mInputs.valueAt(idx); |
| 224 | } |
| 225 | |
| 226 | Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects; |
| 227 | for (size_t i = 0; i < effects.size(); i++) { |
| 228 | EffectDesc *effect = effects[i]; |
| 229 | sp<AudioEffect> fx = new AudioEffect(NULL, &effect->mUuid, -1, 0, 0, audioSession, input); |
| 230 | status_t status = fx->initCheck(); |
| 231 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 232 | ALOGW("Failed to create Fx %s on input %d", effect->mName, input); |
| 233 | // fx goes out of scope and strong ref on AudioEffect is released |
| 234 | continue; |
| 235 | } |
| 236 | for (size_t j = 0; j < effect->mParams.size(); j++) { |
| 237 | fx->setParameter(effect->mParams[j]); |
| 238 | } |
| 239 | inputDesc->mEffects.add(fx); |
| 240 | } |
| 241 | setPreProcessorEnabled(inputDesc, true); |
| 242 | return input; |
| 243 | } |
| 244 | |
| 245 | status_t AudioPolicyService::startInput(audio_io_handle_t input) |
| 246 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 247 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 248 | return NO_INIT; |
| 249 | } |
| 250 | Mutex::Autolock _l(mLock); |
| 251 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 252 | return mAudioPolicyManager->startInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | status_t AudioPolicyService::stopInput(audio_io_handle_t input) |
| 256 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 257 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 258 | return NO_INIT; |
| 259 | } |
| 260 | Mutex::Autolock _l(mLock); |
| 261 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 262 | return mAudioPolicyManager->stopInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void AudioPolicyService::releaseInput(audio_io_handle_t input) |
| 266 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 267 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 271 | mAudioPolicyManager->releaseInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 272 | |
| 273 | ssize_t index = mInputs.indexOfKey(input); |
| 274 | if (index < 0) { |
| 275 | return; |
| 276 | } |
| 277 | InputDesc *inputDesc = mInputs.valueAt(index); |
| 278 | setPreProcessorEnabled(inputDesc, false); |
| 279 | delete inputDesc; |
| 280 | mInputs.removeItemsAt(index); |
| 281 | } |
| 282 | |
| 283 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 284 | int indexMin, |
| 285 | int indexMax) |
| 286 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 287 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 288 | return NO_INIT; |
| 289 | } |
| 290 | if (!settingsAllowed()) { |
| 291 | return PERMISSION_DENIED; |
| 292 | } |
| 293 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 294 | return BAD_VALUE; |
| 295 | } |
| 296 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 297 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 298 | return NO_ERROR; |
| 299 | } |
| 300 | |
| 301 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 302 | int index, |
| 303 | audio_devices_t device) |
| 304 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 305 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 306 | return NO_INIT; |
| 307 | } |
| 308 | if (!settingsAllowed()) { |
| 309 | return PERMISSION_DENIED; |
| 310 | } |
| 311 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 312 | return BAD_VALUE; |
| 313 | } |
| 314 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 315 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 316 | index, |
| 317 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 321 | int *index, |
| 322 | audio_devices_t device) |
| 323 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 324 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 325 | return NO_INIT; |
| 326 | } |
| 327 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 328 | return BAD_VALUE; |
| 329 | } |
| 330 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 331 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 332 | index, |
| 333 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 337 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 338 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 339 | return 0; |
| 340 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 341 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | //audio policy: use audio_device_t appropriately |
| 345 | |
| 346 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 347 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 348 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 349 | return (audio_devices_t)0; |
| 350 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 351 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 355 | { |
| 356 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 357 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 361 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 365 | audio_io_handle_t io, |
| 366 | uint32_t strategy, |
| 367 | int session, |
| 368 | int id) |
| 369 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 370 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 371 | return NO_INIT; |
| 372 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 373 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | status_t AudioPolicyService::unregisterEffect(int id) |
| 377 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 378 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 379 | return NO_INIT; |
| 380 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 381 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 385 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 386 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 387 | return NO_INIT; |
| 388 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 389 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 393 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 394 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 398 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 402 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 403 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 407 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 411 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 412 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 413 | return false; |
| 414 | } |
| 415 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 416 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 420 | effect_descriptor_t *descriptors, |
| 421 | uint32_t *count) |
| 422 | { |
| 423 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 424 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 425 | *count = 0; |
| 426 | return NO_INIT; |
| 427 | } |
| 428 | Mutex::Autolock _l(mLock); |
| 429 | status_t status = NO_ERROR; |
| 430 | |
| 431 | size_t index; |
| 432 | for (index = 0; index < mInputs.size(); index++) { |
| 433 | if (mInputs.valueAt(index)->mSessionId == audioSession) { |
| 434 | break; |
| 435 | } |
| 436 | } |
| 437 | if (index == mInputs.size()) { |
| 438 | *count = 0; |
| 439 | return BAD_VALUE; |
| 440 | } |
| 441 | Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects; |
| 442 | |
| 443 | for (size_t i = 0; i < effects.size(); i++) { |
| 444 | effect_descriptor_t desc = effects[i]->descriptor(); |
| 445 | if (i < *count) { |
| 446 | descriptors[i] = desc; |
| 447 | } |
| 448 | } |
| 449 | if (effects.size() > *count) { |
| 450 | status = NO_MEMORY; |
| 451 | } |
| 452 | *count = effects.size(); |
| 453 | return status; |
| 454 | } |
| 455 | |
| 456 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 457 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 458 | if (mAudioPolicyManager == NULL) { |
| 459 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 463 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | }; // namespace android |