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