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 |
Hochi Huang | f53eaf4 | 2014-10-09 11:36:22 +0800 | [diff] [blame^] | 241 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD && |
| 242 | inputSource != AUDIO_SOURCE_FM_TUNER) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Hochi Huang | f53eaf4 | 2014-10-09 11:36:22 +0800 | [diff] [blame^] | 246 | if (((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) || |
| 247 | ((inputSource == AUDIO_SOURCE_FM_TUNER) && !captureFmTunerAllowed())) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 248 | return 0; |
| 249 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 250 | audio_io_handle_t input; |
| 251 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 252 | { |
| 253 | Mutex::Autolock _l(mLock); |
| 254 | // the audio_in_acoustics_t parameter is ignored by get_input() |
| 255 | input = mAudioPolicyManager->getInput(inputSource, samplingRate, |
| 256 | format, channelMask, |
| 257 | (audio_session_t)audioSession, flags); |
| 258 | audioPolicyEffects = mAudioPolicyEffects; |
| 259 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 260 | if (input == 0) { |
| 261 | return input; |
| 262 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 263 | if (audioPolicyEffects != 0) { |
| 264 | // create audio pre processors according to input source |
| 265 | status_t status = audioPolicyEffects->addInputEffects(input, inputSource, audioSession); |
| 266 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 267 | ALOGW("Failed to add effects on input %d", input); |
| 268 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 269 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 270 | return input; |
| 271 | } |
| 272 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 273 | status_t AudioPolicyService::startInput(audio_io_handle_t input, |
| 274 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 275 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 276 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 277 | return NO_INIT; |
| 278 | } |
| 279 | Mutex::Autolock _l(mLock); |
| 280 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 281 | return mAudioPolicyManager->startInput(input, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 284 | status_t AudioPolicyService::stopInput(audio_io_handle_t input, |
| 285 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 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 | Mutex::Autolock _l(mLock); |
| 291 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 292 | return mAudioPolicyManager->stopInput(input, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 295 | void AudioPolicyService::releaseInput(audio_io_handle_t input, |
| 296 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 297 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 298 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 299 | return; |
| 300 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 301 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 302 | { |
| 303 | Mutex::Autolock _l(mLock); |
| 304 | mAudioPolicyManager->releaseInput(input, session); |
| 305 | audioPolicyEffects = mAudioPolicyEffects; |
| 306 | } |
| 307 | if (audioPolicyEffects != 0) { |
| 308 | // release audio processors from the input |
| 309 | status_t status = audioPolicyEffects->releaseInputEffects(input); |
| 310 | if(status != NO_ERROR) { |
| 311 | ALOGW("Failed to release effects on input %d", input); |
| 312 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 313 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 317 | int indexMin, |
| 318 | int indexMax) |
| 319 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 320 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 321 | return NO_INIT; |
| 322 | } |
| 323 | if (!settingsAllowed()) { |
| 324 | return PERMISSION_DENIED; |
| 325 | } |
| 326 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 327 | return BAD_VALUE; |
| 328 | } |
| 329 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 330 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 331 | return NO_ERROR; |
| 332 | } |
| 333 | |
| 334 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 335 | int index, |
| 336 | audio_devices_t device) |
| 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 NO_INIT; |
| 340 | } |
| 341 | if (!settingsAllowed()) { |
| 342 | return PERMISSION_DENIED; |
| 343 | } |
| 344 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 345 | return BAD_VALUE; |
| 346 | } |
| 347 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 348 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 349 | index, |
| 350 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 354 | int *index, |
| 355 | audio_devices_t device) |
| 356 | { |
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 NO_INIT; |
| 359 | } |
| 360 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 361 | return BAD_VALUE; |
| 362 | } |
| 363 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 364 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 365 | index, |
| 366 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 370 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 371 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 372 | return 0; |
| 373 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 374 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | //audio policy: use audio_device_t appropriately |
| 378 | |
| 379 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 380 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 381 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 382 | return (audio_devices_t)0; |
| 383 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 384 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 388 | { |
| 389 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 390 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 394 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 398 | audio_io_handle_t io, |
| 399 | uint32_t strategy, |
| 400 | int session, |
| 401 | int id) |
| 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 NO_INIT; |
| 405 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 406 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | status_t AudioPolicyService::unregisterEffect(int id) |
| 410 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 411 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 412 | return NO_INIT; |
| 413 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 414 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 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 NO_INIT; |
| 421 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 422 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 426 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 427 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 431 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 435 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 436 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 440 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 444 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 445 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 446 | return false; |
| 447 | } |
| 448 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 449 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 453 | effect_descriptor_t *descriptors, |
| 454 | uint32_t *count) |
| 455 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 456 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 457 | *count = 0; |
| 458 | return NO_INIT; |
| 459 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 460 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 461 | { |
| 462 | Mutex::Autolock _l(mLock); |
| 463 | audioPolicyEffects = mAudioPolicyEffects; |
| 464 | } |
| 465 | if (audioPolicyEffects == 0) { |
| 466 | *count = 0; |
| 467 | return NO_INIT; |
| 468 | } |
| 469 | return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 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 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 568 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 569 | audio_io_handle_t *ioHandle, |
| 570 | audio_devices_t *device) |
| 571 | { |
| 572 | if (mAudioPolicyManager == NULL) { |
| 573 | return NO_INIT; |
| 574 | } |
| 575 | |
| 576 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 577 | } |
| 578 | |
| 579 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 580 | { |
| 581 | if (mAudioPolicyManager == NULL) { |
| 582 | return NO_INIT; |
| 583 | } |
| 584 | |
| 585 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 586 | } |
| 587 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 588 | }; // namespace android |