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); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 159 | |
| 160 | // create audio processors according to stream |
| 161 | status_t status = mAudioPolicyEffects->addOutputSessionEffects(output, stream, session); |
| 162 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 163 | ALOGW("Failed to add effects on session %d", session); |
| 164 | } |
| 165 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 166 | return mAudioPolicyManager->startOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 170 | audio_stream_type_t stream, |
| 171 | int session) |
| 172 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 173 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 174 | return NO_INIT; |
| 175 | } |
| 176 | ALOGV("stopOutput()"); |
| 177 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 178 | return NO_ERROR; |
| 179 | } |
| 180 | |
| 181 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 182 | audio_stream_type_t stream, |
| 183 | int session) |
| 184 | { |
| 185 | ALOGV("doStopOutput from tid %d", gettid()); |
| 186 | Mutex::Autolock _l(mLock); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 187 | |
| 188 | // release audio processors from the stream |
| 189 | status_t status = mAudioPolicyEffects->releaseOutputSessionEffects(output, stream, session); |
| 190 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 191 | ALOGW("Failed to release effects on session %d", session); |
| 192 | } |
| 193 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 194 | return mAudioPolicyManager->stopOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 198 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 199 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | ALOGV("releaseOutput()"); |
| 203 | mOutputCommandThread->releaseOutputCommand(output); |
| 204 | } |
| 205 | |
| 206 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output) |
| 207 | { |
| 208 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 209 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 210 | mAudioPolicyManager->releaseOutput(output); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource, |
| 214 | uint32_t samplingRate, |
| 215 | audio_format_t format, |
| 216 | audio_channel_mask_t channelMask, |
| 217 | int audioSession) |
| 218 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 219 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | // already checked by client, but double-check in case the client wrapper is bypassed |
| 223 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD) { |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | Mutex::Autolock _l(mLock); |
| 232 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 233 | audio_io_handle_t input = mAudioPolicyManager->getInput(inputSource, samplingRate, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 234 | format, channelMask, (audio_in_acoustics_t) 0); |
| 235 | |
| 236 | if (input == 0) { |
| 237 | return input; |
| 238 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 239 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 240 | // create audio pre processors according to input source |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 241 | status_t status = mAudioPolicyEffects->addInputEffects(input, inputSource, audioSession); |
| 242 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 243 | ALOGW("Failed to add effects on input %d", input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 246 | return input; |
| 247 | } |
| 248 | |
| 249 | status_t AudioPolicyService::startInput(audio_io_handle_t input) |
| 250 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 251 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 252 | return NO_INIT; |
| 253 | } |
| 254 | Mutex::Autolock _l(mLock); |
| 255 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 256 | return mAudioPolicyManager->startInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | status_t AudioPolicyService::stopInput(audio_io_handle_t input) |
| 260 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 261 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 262 | return NO_INIT; |
| 263 | } |
| 264 | Mutex::Autolock _l(mLock); |
| 265 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 266 | return mAudioPolicyManager->stopInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void AudioPolicyService::releaseInput(audio_io_handle_t input) |
| 270 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 271 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 275 | mAudioPolicyManager->releaseInput(input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 276 | |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 277 | // release audio processors from the input |
| 278 | status_t status = mAudioPolicyEffects->releaseInputEffects(input); |
| 279 | if(status != NO_ERROR) { |
| 280 | ALOGW("Failed to release effects on input %d", input); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 281 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 285 | int indexMin, |
| 286 | int indexMax) |
| 287 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 288 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 289 | return NO_INIT; |
| 290 | } |
| 291 | if (!settingsAllowed()) { |
| 292 | return PERMISSION_DENIED; |
| 293 | } |
| 294 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 295 | return BAD_VALUE; |
| 296 | } |
| 297 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 298 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 299 | return NO_ERROR; |
| 300 | } |
| 301 | |
| 302 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 303 | int index, |
| 304 | audio_devices_t device) |
| 305 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 306 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 307 | return NO_INIT; |
| 308 | } |
| 309 | if (!settingsAllowed()) { |
| 310 | return PERMISSION_DENIED; |
| 311 | } |
| 312 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 313 | return BAD_VALUE; |
| 314 | } |
| 315 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 316 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 317 | index, |
| 318 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 322 | int *index, |
| 323 | audio_devices_t device) |
| 324 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 325 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 326 | return NO_INIT; |
| 327 | } |
| 328 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 329 | return BAD_VALUE; |
| 330 | } |
| 331 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 332 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 333 | index, |
| 334 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 338 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 339 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 340 | return 0; |
| 341 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 342 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | //audio policy: use audio_device_t appropriately |
| 346 | |
| 347 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 348 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 349 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 350 | return (audio_devices_t)0; |
| 351 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 352 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 356 | { |
| 357 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 358 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 362 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 366 | audio_io_handle_t io, |
| 367 | uint32_t strategy, |
| 368 | int session, |
| 369 | int id) |
| 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 NO_INIT; |
| 373 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 374 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | status_t AudioPolicyService::unregisterEffect(int id) |
| 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 NO_INIT; |
| 381 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 382 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 386 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 387 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 388 | return NO_INIT; |
| 389 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 390 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 394 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 395 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 399 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 403 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 404 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 408 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 412 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 413 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 414 | return false; |
| 415 | } |
| 416 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 417 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 421 | effect_descriptor_t *descriptors, |
| 422 | uint32_t *count) |
| 423 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 424 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 425 | *count = 0; |
| 426 | return NO_INIT; |
| 427 | } |
| 428 | Mutex::Autolock _l(mLock); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 429 | |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame^] | 430 | return mAudioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 434 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 435 | if (mAudioPolicyManager == NULL) { |
| 436 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 437 | return false; |
| 438 | } |
| 439 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 440 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 443 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 444 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 445 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 446 | struct audio_port *ports, |
| 447 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 448 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 449 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 450 | if(!modifyAudioRoutingAllowed()) { |
| 451 | return PERMISSION_DENIED; |
| 452 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 453 | if (mAudioPolicyManager == NULL) { |
| 454 | return NO_INIT; |
| 455 | } |
| 456 | |
| 457 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 460 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 461 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 462 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 463 | if(!modifyAudioRoutingAllowed()) { |
| 464 | return PERMISSION_DENIED; |
| 465 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 466 | if (mAudioPolicyManager == NULL) { |
| 467 | return NO_INIT; |
| 468 | } |
| 469 | |
| 470 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 473 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 474 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 475 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 476 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 477 | if(!modifyAudioRoutingAllowed()) { |
| 478 | return PERMISSION_DENIED; |
| 479 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 480 | if (mAudioPolicyManager == NULL) { |
| 481 | return NO_INIT; |
| 482 | } |
| 483 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 484 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 487 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 488 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 489 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 490 | if(!modifyAudioRoutingAllowed()) { |
| 491 | return PERMISSION_DENIED; |
| 492 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 493 | if (mAudioPolicyManager == NULL) { |
| 494 | return NO_INIT; |
| 495 | } |
| 496 | |
| 497 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 498 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 502 | struct audio_patch *patches, |
| 503 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 504 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 505 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 506 | if(!modifyAudioRoutingAllowed()) { |
| 507 | return PERMISSION_DENIED; |
| 508 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 509 | if (mAudioPolicyManager == NULL) { |
| 510 | return NO_INIT; |
| 511 | } |
| 512 | |
| 513 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 516 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 517 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 518 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 519 | if(!modifyAudioRoutingAllowed()) { |
| 520 | return PERMISSION_DENIED; |
| 521 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 522 | if (mAudioPolicyManager == NULL) { |
| 523 | return NO_INIT; |
| 524 | } |
| 525 | |
| 526 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 527 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 528 | |
| 529 | }; // namespace android |