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