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 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 134 | audio_io_handle_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 135 | uint32_t samplingRate, |
| 136 | audio_format_t format, |
| 137 | audio_channel_mask_t channelMask, |
| 138 | audio_output_flags_t flags, |
| 139 | const audio_offload_info_t *offloadInfo) |
| 140 | { |
| 141 | if (mAudioPolicyManager == NULL) { |
| 142 | return 0; |
| 143 | } |
| 144 | ALOGV("getOutput()"); |
| 145 | Mutex::Autolock _l(mLock); |
| 146 | return mAudioPolicyManager->getOutputForAttr(attr, samplingRate, |
| 147 | format, channelMask, flags, offloadInfo); |
| 148 | } |
| 149 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 150 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
| 151 | audio_stream_type_t stream, |
| 152 | int session) |
| 153 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 154 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 155 | return NO_INIT; |
| 156 | } |
| 157 | ALOGV("startOutput()"); |
| 158 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 159 | return mAudioPolicyManager->startOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 163 | audio_stream_type_t stream, |
| 164 | int session) |
| 165 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 166 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 167 | return NO_INIT; |
| 168 | } |
| 169 | ALOGV("stopOutput()"); |
| 170 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 171 | return NO_ERROR; |
| 172 | } |
| 173 | |
| 174 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 175 | audio_stream_type_t stream, |
| 176 | int session) |
| 177 | { |
| 178 | ALOGV("doStopOutput from tid %d", gettid()); |
| 179 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 180 | return mAudioPolicyManager->stopOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 184 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 185 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | ALOGV("releaseOutput()"); |
| 189 | mOutputCommandThread->releaseOutputCommand(output); |
| 190 | } |
| 191 | |
| 192 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output) |
| 193 | { |
| 194 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 195 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 196 | mAudioPolicyManager->releaseOutput(output); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource, |
| 200 | uint32_t samplingRate, |
| 201 | audio_format_t format, |
| 202 | audio_channel_mask_t channelMask, |
| 203 | int audioSession) |
| 204 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 205 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | // already checked by client, but double-check in case the client wrapper is bypassed |
| 209 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD) { |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) { |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | Mutex::Autolock _l(mLock); |
| 218 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 219 | audio_io_handle_t input = mAudioPolicyManager->getInput(inputSource, samplingRate, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 220 | format, channelMask, (audio_in_acoustics_t) 0); |
| 221 | |
| 222 | if (input == 0) { |
| 223 | return input; |
| 224 | } |
| 225 | // create audio pre processors according to input source |
| 226 | audio_source_t aliasSource = (inputSource == AUDIO_SOURCE_HOTWORD) ? |
| 227 | AUDIO_SOURCE_VOICE_RECOGNITION : inputSource; |
| 228 | |
| 229 | ssize_t index = mInputSources.indexOfKey(aliasSource); |
| 230 | if (index < 0) { |
| 231 | return input; |
| 232 | } |
| 233 | ssize_t idx = mInputs.indexOfKey(input); |
| 234 | InputDesc *inputDesc; |
| 235 | if (idx < 0) { |
| 236 | inputDesc = new InputDesc(audioSession); |
| 237 | mInputs.add(input, inputDesc); |
| 238 | } else { |
| 239 | inputDesc = mInputs.valueAt(idx); |
| 240 | } |
| 241 | |
| 242 | Vector <EffectDesc *> effects = mInputSources.valueAt(index)->mEffects; |
| 243 | for (size_t i = 0; i < effects.size(); i++) { |
| 244 | EffectDesc *effect = effects[i]; |
| 245 | sp<AudioEffect> fx = new AudioEffect(NULL, &effect->mUuid, -1, 0, 0, audioSession, input); |
| 246 | status_t status = fx->initCheck(); |
| 247 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 248 | ALOGW("Failed to create Fx %s on input %d", effect->mName, input); |
| 249 | // fx goes out of scope and strong ref on AudioEffect is released |
| 250 | continue; |
| 251 | } |
| 252 | for (size_t j = 0; j < effect->mParams.size(); j++) { |
| 253 | fx->setParameter(effect->mParams[j]); |
| 254 | } |
| 255 | inputDesc->mEffects.add(fx); |
| 256 | } |
| 257 | setPreProcessorEnabled(inputDesc, true); |
| 258 | return input; |
| 259 | } |
| 260 | |
| 261 | status_t AudioPolicyService::startInput(audio_io_handle_t input) |
| 262 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 263 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 264 | return NO_INIT; |
| 265 | } |
| 266 | Mutex::Autolock _l(mLock); |
| 267 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 268 | return mAudioPolicyManager->startInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | status_t AudioPolicyService::stopInput(audio_io_handle_t input) |
| 272 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 273 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 274 | return NO_INIT; |
| 275 | } |
| 276 | Mutex::Autolock _l(mLock); |
| 277 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 278 | return mAudioPolicyManager->stopInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void AudioPolicyService::releaseInput(audio_io_handle_t input) |
| 282 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 283 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 284 | return; |
| 285 | } |
| 286 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 287 | mAudioPolicyManager->releaseInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 288 | |
| 289 | ssize_t index = mInputs.indexOfKey(input); |
| 290 | if (index < 0) { |
| 291 | return; |
| 292 | } |
| 293 | InputDesc *inputDesc = mInputs.valueAt(index); |
| 294 | setPreProcessorEnabled(inputDesc, false); |
| 295 | delete inputDesc; |
| 296 | mInputs.removeItemsAt(index); |
| 297 | } |
| 298 | |
| 299 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 300 | int indexMin, |
| 301 | int indexMax) |
| 302 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 303 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 304 | return NO_INIT; |
| 305 | } |
| 306 | if (!settingsAllowed()) { |
| 307 | return PERMISSION_DENIED; |
| 308 | } |
| 309 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 310 | return BAD_VALUE; |
| 311 | } |
| 312 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 313 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 314 | return NO_ERROR; |
| 315 | } |
| 316 | |
| 317 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 318 | int index, |
| 319 | audio_devices_t device) |
| 320 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 321 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 322 | return NO_INIT; |
| 323 | } |
| 324 | if (!settingsAllowed()) { |
| 325 | return PERMISSION_DENIED; |
| 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->setStreamVolumeIndex(stream, |
| 332 | index, |
| 333 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 337 | int *index, |
| 338 | audio_devices_t device) |
| 339 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 340 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 341 | return NO_INIT; |
| 342 | } |
| 343 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 344 | return BAD_VALUE; |
| 345 | } |
| 346 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 347 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 348 | index, |
| 349 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 353 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 354 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 355 | return 0; |
| 356 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 357 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | //audio policy: use audio_device_t appropriately |
| 361 | |
| 362 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 363 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 364 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 365 | return (audio_devices_t)0; |
| 366 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 367 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 371 | { |
| 372 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 373 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 377 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 381 | audio_io_handle_t io, |
| 382 | uint32_t strategy, |
| 383 | int session, |
| 384 | int id) |
| 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->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | status_t AudioPolicyService::unregisterEffect(int id) |
| 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 NO_INIT; |
| 396 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 397 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 401 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 402 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 403 | return NO_INIT; |
| 404 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 405 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 409 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 410 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 414 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 418 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 419 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 423 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 427 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 428 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 429 | return false; |
| 430 | } |
| 431 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 432 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 436 | effect_descriptor_t *descriptors, |
| 437 | uint32_t *count) |
| 438 | { |
| 439 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 440 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 441 | *count = 0; |
| 442 | return NO_INIT; |
| 443 | } |
| 444 | Mutex::Autolock _l(mLock); |
| 445 | status_t status = NO_ERROR; |
| 446 | |
| 447 | size_t index; |
| 448 | for (index = 0; index < mInputs.size(); index++) { |
| 449 | if (mInputs.valueAt(index)->mSessionId == audioSession) { |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | if (index == mInputs.size()) { |
| 454 | *count = 0; |
| 455 | return BAD_VALUE; |
| 456 | } |
| 457 | Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects; |
| 458 | |
| 459 | for (size_t i = 0; i < effects.size(); i++) { |
| 460 | effect_descriptor_t desc = effects[i]->descriptor(); |
| 461 | if (i < *count) { |
| 462 | descriptors[i] = desc; |
| 463 | } |
| 464 | } |
| 465 | if (effects.size() > *count) { |
| 466 | status = NO_MEMORY; |
| 467 | } |
| 468 | *count = effects.size(); |
| 469 | return status; |
| 470 | } |
| 471 | |
| 472 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 473 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 474 | if (mAudioPolicyManager == NULL) { |
| 475 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 476 | return false; |
| 477 | } |
| 478 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 479 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 480 | } |
| 481 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 482 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 483 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 484 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 485 | struct audio_port *ports, |
| 486 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 487 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 488 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 489 | if(!modifyAudioRoutingAllowed()) { |
| 490 | return PERMISSION_DENIED; |
| 491 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 492 | if (mAudioPolicyManager == NULL) { |
| 493 | return NO_INIT; |
| 494 | } |
| 495 | |
| 496 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 499 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 500 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 501 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 502 | if(!modifyAudioRoutingAllowed()) { |
| 503 | return PERMISSION_DENIED; |
| 504 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 505 | if (mAudioPolicyManager == NULL) { |
| 506 | return NO_INIT; |
| 507 | } |
| 508 | |
| 509 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 512 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 513 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 514 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 515 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 516 | if(!modifyAudioRoutingAllowed()) { |
| 517 | return PERMISSION_DENIED; |
| 518 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 519 | if (mAudioPolicyManager == NULL) { |
| 520 | return NO_INIT; |
| 521 | } |
| 522 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 523 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 526 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 527 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 528 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 529 | if(!modifyAudioRoutingAllowed()) { |
| 530 | return PERMISSION_DENIED; |
| 531 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 532 | if (mAudioPolicyManager == NULL) { |
| 533 | return NO_INIT; |
| 534 | } |
| 535 | |
| 536 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 537 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 541 | struct audio_patch *patches, |
| 542 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 543 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 544 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 545 | if(!modifyAudioRoutingAllowed()) { |
| 546 | return PERMISSION_DENIED; |
| 547 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 548 | if (mAudioPolicyManager == NULL) { |
| 549 | return NO_INIT; |
| 550 | } |
| 551 | |
| 552 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 555 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 556 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 557 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 558 | if(!modifyAudioRoutingAllowed()) { |
| 559 | return PERMISSION_DENIED; |
| 560 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 561 | if (mAudioPolicyManager == NULL) { |
| 562 | return NO_INIT; |
| 563 | } |
| 564 | |
| 565 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 566 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 567 | |
| 568 | }; // namespace android |