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 | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 83 | mPhoneState = state; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 84 | return NO_ERROR; |
| 85 | } |
| 86 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 87 | audio_mode_t AudioPolicyService::getPhoneState() |
| 88 | { |
| 89 | Mutex::Autolock _l(mLock); |
| 90 | return mPhoneState; |
| 91 | } |
| 92 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 93 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 94 | audio_policy_forced_cfg_t config) |
| 95 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 96 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 97 | return NO_INIT; |
| 98 | } |
| 99 | if (!settingsAllowed()) { |
| 100 | return PERMISSION_DENIED; |
| 101 | } |
| 102 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 103 | return BAD_VALUE; |
| 104 | } |
| 105 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 106 | return BAD_VALUE; |
| 107 | } |
| 108 | ALOGV("setForceUse()"); |
| 109 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 110 | mAudioPolicyManager->setForceUse(usage, config); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 111 | return NO_ERROR; |
| 112 | } |
| 113 | |
| 114 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 115 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 116 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 117 | return AUDIO_POLICY_FORCE_NONE; |
| 118 | } |
| 119 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 120 | return AUDIO_POLICY_FORCE_NONE; |
| 121 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 122 | return mAudioPolicyManager->getForceUse(usage); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream, |
| 126 | uint32_t samplingRate, |
| 127 | audio_format_t format, |
| 128 | audio_channel_mask_t channelMask, |
| 129 | audio_output_flags_t flags, |
| 130 | const audio_offload_info_t *offloadInfo) |
| 131 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 132 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | ALOGV("getOutput()"); |
| 136 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 137 | return mAudioPolicyManager->getOutput(stream, samplingRate, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 138 | format, channelMask, flags, offloadInfo); |
| 139 | } |
| 140 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 141 | audio_io_handle_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 142 | uint32_t samplingRate, |
| 143 | audio_format_t format, |
| 144 | audio_channel_mask_t channelMask, |
| 145 | audio_output_flags_t flags, |
| 146 | const audio_offload_info_t *offloadInfo) |
| 147 | { |
| 148 | if (mAudioPolicyManager == NULL) { |
| 149 | return 0; |
| 150 | } |
| 151 | ALOGV("getOutput()"); |
| 152 | Mutex::Autolock _l(mLock); |
| 153 | return mAudioPolicyManager->getOutputForAttr(attr, samplingRate, |
| 154 | format, channelMask, flags, offloadInfo); |
| 155 | } |
| 156 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 157 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
| 158 | audio_stream_type_t stream, |
| 159 | int session) |
| 160 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 161 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 162 | return NO_INIT; |
| 163 | } |
| 164 | ALOGV("startOutput()"); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 165 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 166 | { |
| 167 | Mutex::Autolock _l(mLock); |
| 168 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 169 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 170 | if (audioPolicyEffects != 0) { |
| 171 | // create audio processors according to stream |
| 172 | status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session); |
| 173 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 174 | ALOGW("Failed to add effects on session %d", session); |
| 175 | } |
| 176 | } |
| 177 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 178 | return mAudioPolicyManager->startOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 182 | audio_stream_type_t stream, |
| 183 | int session) |
| 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 NO_INIT; |
| 187 | } |
| 188 | ALOGV("stopOutput()"); |
| 189 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 190 | return NO_ERROR; |
| 191 | } |
| 192 | |
| 193 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 194 | audio_stream_type_t stream, |
| 195 | int session) |
| 196 | { |
| 197 | ALOGV("doStopOutput from tid %d", gettid()); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 198 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 199 | { |
| 200 | Mutex::Autolock _l(mLock); |
| 201 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 202 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 203 | if (audioPolicyEffects != 0) { |
| 204 | // release audio processors from the stream |
| 205 | status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session); |
| 206 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 207 | ALOGW("Failed to release effects on session %d", session); |
| 208 | } |
| 209 | } |
| 210 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 211 | return mAudioPolicyManager->stopOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 215 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 216 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 217 | return; |
| 218 | } |
| 219 | ALOGV("releaseOutput()"); |
| 220 | mOutputCommandThread->releaseOutputCommand(output); |
| 221 | } |
| 222 | |
| 223 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output) |
| 224 | { |
| 225 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 226 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 227 | mAudioPolicyManager->releaseOutput(output); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource, |
| 231 | uint32_t samplingRate, |
| 232 | audio_format_t format, |
| 233 | audio_channel_mask_t channelMask, |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 234 | int audioSession, |
Glenn Kasten | 6a8ab05 | 2014-07-24 14:08:35 -0700 | [diff] [blame] | 235 | audio_input_flags_t flags) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 236 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 237 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | // already checked by client, but double-check in case the client wrapper is bypassed |
| 241 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD) { |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) { |
| 246 | return 0; |
| 247 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 248 | audio_io_handle_t input; |
| 249 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 250 | { |
| 251 | Mutex::Autolock _l(mLock); |
| 252 | // the audio_in_acoustics_t parameter is ignored by get_input() |
| 253 | input = mAudioPolicyManager->getInput(inputSource, samplingRate, |
| 254 | format, channelMask, |
| 255 | (audio_session_t)audioSession, flags); |
| 256 | audioPolicyEffects = mAudioPolicyEffects; |
| 257 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 258 | if (input == 0) { |
| 259 | return input; |
| 260 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 261 | if (audioPolicyEffects != 0) { |
| 262 | // create audio pre processors according to input source |
| 263 | status_t status = audioPolicyEffects->addInputEffects(input, inputSource, audioSession); |
| 264 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 265 | ALOGW("Failed to add effects on input %d", input); |
| 266 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 267 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 268 | return input; |
| 269 | } |
| 270 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 271 | status_t AudioPolicyService::startInput(audio_io_handle_t input, |
| 272 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 273 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 274 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 275 | return NO_INIT; |
| 276 | } |
| 277 | Mutex::Autolock _l(mLock); |
| 278 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 279 | return mAudioPolicyManager->startInput(input, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 282 | status_t AudioPolicyService::stopInput(audio_io_handle_t input, |
| 283 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 284 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 285 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 286 | return NO_INIT; |
| 287 | } |
| 288 | Mutex::Autolock _l(mLock); |
| 289 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 290 | return mAudioPolicyManager->stopInput(input, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 293 | void AudioPolicyService::releaseInput(audio_io_handle_t input, |
| 294 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 295 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 296 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 297 | return; |
| 298 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 299 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 300 | { |
| 301 | Mutex::Autolock _l(mLock); |
| 302 | mAudioPolicyManager->releaseInput(input, session); |
| 303 | audioPolicyEffects = mAudioPolicyEffects; |
| 304 | } |
| 305 | if (audioPolicyEffects != 0) { |
| 306 | // release audio processors from the input |
| 307 | status_t status = audioPolicyEffects->releaseInputEffects(input); |
| 308 | if(status != NO_ERROR) { |
| 309 | ALOGW("Failed to release effects on input %d", input); |
| 310 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 311 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 315 | int indexMin, |
| 316 | int indexMax) |
| 317 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 318 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 319 | return NO_INIT; |
| 320 | } |
| 321 | if (!settingsAllowed()) { |
| 322 | return PERMISSION_DENIED; |
| 323 | } |
| 324 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 325 | return BAD_VALUE; |
| 326 | } |
| 327 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 328 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 329 | return NO_ERROR; |
| 330 | } |
| 331 | |
| 332 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 333 | int index, |
| 334 | audio_devices_t device) |
| 335 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 336 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 337 | return NO_INIT; |
| 338 | } |
| 339 | if (!settingsAllowed()) { |
| 340 | return PERMISSION_DENIED; |
| 341 | } |
| 342 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 343 | return BAD_VALUE; |
| 344 | } |
| 345 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 346 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 347 | index, |
| 348 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 352 | int *index, |
| 353 | audio_devices_t device) |
| 354 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 355 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 356 | return NO_INIT; |
| 357 | } |
| 358 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 359 | return BAD_VALUE; |
| 360 | } |
| 361 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 362 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 363 | index, |
| 364 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 368 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 369 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 370 | return 0; |
| 371 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 372 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | //audio policy: use audio_device_t appropriately |
| 376 | |
| 377 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 378 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 379 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 380 | return (audio_devices_t)0; |
| 381 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 382 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 386 | { |
| 387 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 388 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 392 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 396 | audio_io_handle_t io, |
| 397 | uint32_t strategy, |
| 398 | int session, |
| 399 | int id) |
| 400 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 401 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 402 | return NO_INIT; |
| 403 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 404 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | status_t AudioPolicyService::unregisterEffect(int id) |
| 408 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 409 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 410 | return NO_INIT; |
| 411 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 412 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 416 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 417 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 418 | return NO_INIT; |
| 419 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 420 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 424 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 425 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 429 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 433 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 434 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 438 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 442 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 443 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 444 | return false; |
| 445 | } |
| 446 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 447 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 451 | effect_descriptor_t *descriptors, |
| 452 | uint32_t *count) |
| 453 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 454 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 455 | *count = 0; |
| 456 | return NO_INIT; |
| 457 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 458 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 459 | { |
| 460 | Mutex::Autolock _l(mLock); |
| 461 | audioPolicyEffects = mAudioPolicyEffects; |
| 462 | } |
| 463 | if (audioPolicyEffects == 0) { |
| 464 | *count = 0; |
| 465 | return NO_INIT; |
| 466 | } |
| 467 | return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 471 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 472 | if (mAudioPolicyManager == NULL) { |
| 473 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 474 | return false; |
| 475 | } |
| 476 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 477 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 480 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 481 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 482 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 483 | struct audio_port *ports, |
| 484 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 485 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 486 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 487 | if(!modifyAudioRoutingAllowed()) { |
| 488 | return PERMISSION_DENIED; |
| 489 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 490 | if (mAudioPolicyManager == NULL) { |
| 491 | return NO_INIT; |
| 492 | } |
| 493 | |
| 494 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 497 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 498 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 499 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 500 | if(!modifyAudioRoutingAllowed()) { |
| 501 | return PERMISSION_DENIED; |
| 502 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 503 | if (mAudioPolicyManager == NULL) { |
| 504 | return NO_INIT; |
| 505 | } |
| 506 | |
| 507 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 510 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 511 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 512 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 513 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 514 | if(!modifyAudioRoutingAllowed()) { |
| 515 | return PERMISSION_DENIED; |
| 516 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 517 | if (mAudioPolicyManager == NULL) { |
| 518 | return NO_INIT; |
| 519 | } |
| 520 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 521 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 524 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 525 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 526 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 527 | if(!modifyAudioRoutingAllowed()) { |
| 528 | return PERMISSION_DENIED; |
| 529 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 530 | if (mAudioPolicyManager == NULL) { |
| 531 | return NO_INIT; |
| 532 | } |
| 533 | |
| 534 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 535 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 539 | struct audio_patch *patches, |
| 540 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 541 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 542 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 543 | if(!modifyAudioRoutingAllowed()) { |
| 544 | return PERMISSION_DENIED; |
| 545 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 546 | if (mAudioPolicyManager == NULL) { |
| 547 | return NO_INIT; |
| 548 | } |
| 549 | |
| 550 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 553 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 554 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 555 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 556 | if(!modifyAudioRoutingAllowed()) { |
| 557 | return PERMISSION_DENIED; |
| 558 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 559 | if (mAudioPolicyManager == NULL) { |
| 560 | return NO_INIT; |
| 561 | } |
| 562 | |
| 563 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 564 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 565 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 566 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 567 | audio_io_handle_t *ioHandle, |
| 568 | audio_devices_t *device) |
| 569 | { |
| 570 | if (mAudioPolicyManager == NULL) { |
| 571 | return NO_INIT; |
| 572 | } |
| 573 | |
| 574 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 575 | } |
| 576 | |
| 577 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 578 | { |
| 579 | if (mAudioPolicyManager == NULL) { |
| 580 | return NO_INIT; |
| 581 | } |
| 582 | |
| 583 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 584 | } |
| 585 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 586 | }; // namespace android |