Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [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 | |
| 17 | #define LOG_TAG "AudioPolicyService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <utils/Log.h> |
| 21 | #include "AudioPolicyService.h" |
| 22 | #include "ServiceUtilities.h" |
| 23 | |
| 24 | #include <system/audio.h> |
| 25 | #include <system/audio_policy.h> |
| 26 | #include <hardware/audio_policy.h> |
Eric Laurent | f380677 | 2014-10-07 09:19:31 -0700 | [diff] [blame] | 27 | #include <media/AudioPolicyHelper.h> |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | |
| 34 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, |
| 35 | audio_policy_dev_state_t state, |
| 36 | const char *device_address) |
| 37 | { |
| 38 | if (mpAudioPolicy == NULL) { |
| 39 | return NO_INIT; |
| 40 | } |
| 41 | if (!settingsAllowed()) { |
| 42 | return PERMISSION_DENIED; |
| 43 | } |
| 44 | if (!audio_is_output_device(device) && !audio_is_input_device(device)) { |
| 45 | return BAD_VALUE; |
| 46 | } |
| 47 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 48 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 49 | return BAD_VALUE; |
| 50 | } |
| 51 | |
| 52 | ALOGV("setDeviceConnectionState()"); |
| 53 | Mutex::Autolock _l(mLock); |
| 54 | return mpAudioPolicy->set_device_connection_state(mpAudioPolicy, device, |
| 55 | state, device_address); |
| 56 | } |
| 57 | |
| 58 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( |
| 59 | audio_devices_t device, |
| 60 | const char *device_address) |
| 61 | { |
| 62 | if (mpAudioPolicy == NULL) { |
| 63 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
| 64 | } |
| 65 | return mpAudioPolicy->get_device_connection_state(mpAudioPolicy, device, |
| 66 | device_address); |
| 67 | } |
| 68 | |
| 69 | status_t AudioPolicyService::setPhoneState(audio_mode_t state) |
| 70 | { |
| 71 | if (mpAudioPolicy == NULL) { |
| 72 | return NO_INIT; |
| 73 | } |
| 74 | if (!settingsAllowed()) { |
| 75 | return PERMISSION_DENIED; |
| 76 | } |
| 77 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
| 78 | return BAD_VALUE; |
| 79 | } |
| 80 | |
| 81 | ALOGV("setPhoneState()"); |
| 82 | |
| 83 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 84 | AudioSystem::setMode(state); |
| 85 | |
| 86 | Mutex::Autolock _l(mLock); |
| 87 | mpAudioPolicy->set_phone_state(mpAudioPolicy, state); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 88 | mPhoneState = state; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 89 | return NO_ERROR; |
| 90 | } |
| 91 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 92 | audio_mode_t AudioPolicyService::getPhoneState() |
| 93 | { |
| 94 | Mutex::Autolock _l(mLock); |
| 95 | return mPhoneState; |
| 96 | } |
| 97 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 98 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 99 | audio_policy_forced_cfg_t config) |
| 100 | { |
| 101 | if (mpAudioPolicy == NULL) { |
| 102 | return NO_INIT; |
| 103 | } |
| 104 | if (!settingsAllowed()) { |
| 105 | return PERMISSION_DENIED; |
| 106 | } |
| 107 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 108 | return BAD_VALUE; |
| 109 | } |
| 110 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 111 | return BAD_VALUE; |
| 112 | } |
| 113 | ALOGV("setForceUse()"); |
| 114 | Mutex::Autolock _l(mLock); |
| 115 | mpAudioPolicy->set_force_use(mpAudioPolicy, usage, config); |
| 116 | return NO_ERROR; |
| 117 | } |
| 118 | |
| 119 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 120 | { |
| 121 | if (mpAudioPolicy == NULL) { |
| 122 | return AUDIO_POLICY_FORCE_NONE; |
| 123 | } |
| 124 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 125 | return AUDIO_POLICY_FORCE_NONE; |
| 126 | } |
| 127 | return mpAudioPolicy->get_force_use(mpAudioPolicy, usage); |
| 128 | } |
| 129 | |
| 130 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream, |
| 131 | uint32_t samplingRate, |
| 132 | audio_format_t format, |
| 133 | audio_channel_mask_t channelMask, |
| 134 | audio_output_flags_t flags, |
| 135 | const audio_offload_info_t *offloadInfo) |
| 136 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 137 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 138 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 139 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 140 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 141 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 142 | } |
| 143 | ALOGV("getOutput()"); |
| 144 | Mutex::Autolock _l(mLock); |
| 145 | return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate, |
| 146 | format, channelMask, flags, offloadInfo); |
| 147 | } |
| 148 | |
| 149 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
| 150 | audio_stream_type_t stream, |
| 151 | int session) |
| 152 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 153 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 154 | return BAD_VALUE; |
| 155 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 156 | if (mpAudioPolicy == NULL) { |
| 157 | return NO_INIT; |
| 158 | } |
| 159 | ALOGV("startOutput()"); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 160 | // create audio processors according to stream |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 161 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 162 | { |
| 163 | Mutex::Autolock _l(mLock); |
| 164 | audioPolicyEffects = mAudioPolicyEffects; |
| 165 | } |
| 166 | if (audioPolicyEffects != 0) { |
| 167 | status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session); |
| 168 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 169 | ALOGW("Failed to add effects on session %d", session); |
| 170 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 173 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 174 | return mpAudioPolicy->start_output(mpAudioPolicy, output, stream, session); |
| 175 | } |
| 176 | |
| 177 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 178 | audio_stream_type_t stream, |
| 179 | int session) |
| 180 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 181 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 182 | return BAD_VALUE; |
| 183 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 184 | if (mpAudioPolicy == NULL) { |
| 185 | return NO_INIT; |
| 186 | } |
| 187 | ALOGV("stopOutput()"); |
| 188 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 189 | return NO_ERROR; |
| 190 | } |
| 191 | |
| 192 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 193 | audio_stream_type_t stream, |
| 194 | int session) |
| 195 | { |
| 196 | ALOGV("doStopOutput from tid %d", gettid()); |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 197 | // release audio processors from the stream |
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 | status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session); |
| 205 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 206 | ALOGW("Failed to release effects on session %d", session); |
| 207 | } |
| 208 | } |
| 209 | Mutex::Autolock _l(mLock); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 210 | return mpAudioPolicy->stop_output(mpAudioPolicy, output, stream, session); |
| 211 | } |
| 212 | |
| 213 | void AudioPolicyService::releaseOutput(audio_io_handle_t output) |
| 214 | { |
| 215 | if (mpAudioPolicy == NULL) { |
| 216 | return; |
| 217 | } |
| 218 | ALOGV("releaseOutput()"); |
| 219 | mOutputCommandThread->releaseOutputCommand(output); |
| 220 | } |
| 221 | |
| 222 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output) |
| 223 | { |
| 224 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 225 | Mutex::Autolock _l(mLock); |
| 226 | mpAudioPolicy->release_output(mpAudioPolicy, output); |
| 227 | } |
| 228 | |
| 229 | audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource, |
| 230 | uint32_t samplingRate, |
| 231 | audio_format_t format, |
| 232 | audio_channel_mask_t channelMask, |
Glenn Kasten | b3b1660 | 2014-07-16 08:36:31 -0700 | [diff] [blame] | 233 | int audioSession, |
| 234 | audio_input_flags_t flags __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 235 | { |
| 236 | if (mpAudioPolicy == NULL) { |
| 237 | return 0; |
| 238 | } |
| 239 | // 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] | 240 | if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD && |
| 241 | inputSource != AUDIO_SOURCE_FM_TUNER) { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
Hochi Huang | f53eaf4 | 2014-10-09 11:36:22 +0800 | [diff] [blame] | 245 | if (((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) || |
| 246 | ((inputSource == AUDIO_SOURCE_FM_TUNER) && !captureFmTunerAllowed())) { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 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 = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate, |
| 256 | format, channelMask, (audio_in_acoustics_t) 0); |
| 257 | audioPolicyEffects = mAudioPolicyEffects; |
| 258 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 259 | if (input == 0) { |
| 260 | return input; |
| 261 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 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 | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 269 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [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 __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 275 | { |
| 276 | if (mpAudioPolicy == NULL) { |
| 277 | return NO_INIT; |
| 278 | } |
| 279 | Mutex::Autolock _l(mLock); |
| 280 | |
| 281 | return mpAudioPolicy->start_input(mpAudioPolicy, input); |
| 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 __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 286 | { |
| 287 | if (mpAudioPolicy == NULL) { |
| 288 | return NO_INIT; |
| 289 | } |
| 290 | Mutex::Autolock _l(mLock); |
| 291 | |
| 292 | return mpAudioPolicy->stop_input(mpAudioPolicy, input); |
| 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 __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 297 | { |
| 298 | if (mpAudioPolicy == NULL) { |
| 299 | return; |
| 300 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 301 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 302 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 303 | { |
| 304 | Mutex::Autolock _l(mLock); |
| 305 | mpAudioPolicy->release_input(mpAudioPolicy, input); |
| 306 | audioPolicyEffects = mAudioPolicyEffects; |
| 307 | } |
| 308 | if (audioPolicyEffects != 0) { |
| 309 | // release audio processors from the input |
| 310 | status_t status = audioPolicyEffects->releaseInputEffects(input); |
| 311 | if(status != NO_ERROR) { |
| 312 | ALOGW("Failed to release effects on input %d", input); |
| 313 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 314 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 318 | int indexMin, |
| 319 | int indexMax) |
| 320 | { |
| 321 | if (mpAudioPolicy == NULL) { |
| 322 | return NO_INIT; |
| 323 | } |
| 324 | if (!settingsAllowed()) { |
| 325 | return PERMISSION_DENIED; |
| 326 | } |
| 327 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 328 | return BAD_VALUE; |
| 329 | } |
| 330 | Mutex::Autolock _l(mLock); |
| 331 | mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax); |
| 332 | return NO_ERROR; |
| 333 | } |
| 334 | |
| 335 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 336 | int index, |
| 337 | audio_devices_t device) |
| 338 | { |
| 339 | if (mpAudioPolicy == NULL) { |
| 340 | return NO_INIT; |
| 341 | } |
| 342 | if (!settingsAllowed()) { |
| 343 | return PERMISSION_DENIED; |
| 344 | } |
| 345 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 346 | return BAD_VALUE; |
| 347 | } |
| 348 | Mutex::Autolock _l(mLock); |
| 349 | if (mpAudioPolicy->set_stream_volume_index_for_device) { |
| 350 | return mpAudioPolicy->set_stream_volume_index_for_device(mpAudioPolicy, |
| 351 | stream, |
| 352 | index, |
| 353 | device); |
| 354 | } else { |
| 355 | return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 360 | int *index, |
| 361 | audio_devices_t device) |
| 362 | { |
| 363 | if (mpAudioPolicy == NULL) { |
| 364 | return NO_INIT; |
| 365 | } |
| 366 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 367 | return BAD_VALUE; |
| 368 | } |
| 369 | Mutex::Autolock _l(mLock); |
| 370 | if (mpAudioPolicy->get_stream_volume_index_for_device) { |
| 371 | return mpAudioPolicy->get_stream_volume_index_for_device(mpAudioPolicy, |
| 372 | stream, |
| 373 | index, |
| 374 | device); |
| 375 | } else { |
| 376 | return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 381 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 382 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 383 | return 0; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 384 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 385 | if (mpAudioPolicy == NULL) { |
| 386 | return 0; |
| 387 | } |
| 388 | return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream); |
| 389 | } |
| 390 | |
| 391 | //audio policy: use audio_device_t appropriately |
| 392 | |
| 393 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 394 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 395 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 396 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 397 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 398 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 399 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 400 | } |
| 401 | return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream); |
| 402 | } |
| 403 | |
| 404 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 405 | { |
| 406 | // FIXME change return type to status_t, and return NO_INIT here |
| 407 | if (mpAudioPolicy == NULL) { |
| 408 | return 0; |
| 409 | } |
| 410 | Mutex::Autolock _l(mLock); |
| 411 | return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc); |
| 412 | } |
| 413 | |
| 414 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 415 | audio_io_handle_t io, |
| 416 | uint32_t strategy, |
| 417 | int session, |
| 418 | int id) |
| 419 | { |
| 420 | if (mpAudioPolicy == NULL) { |
| 421 | return NO_INIT; |
| 422 | } |
| 423 | return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id); |
| 424 | } |
| 425 | |
| 426 | status_t AudioPolicyService::unregisterEffect(int id) |
| 427 | { |
| 428 | if (mpAudioPolicy == NULL) { |
| 429 | return NO_INIT; |
| 430 | } |
| 431 | return mpAudioPolicy->unregister_effect(mpAudioPolicy, id); |
| 432 | } |
| 433 | |
| 434 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 435 | { |
| 436 | if (mpAudioPolicy == NULL) { |
| 437 | return NO_INIT; |
| 438 | } |
| 439 | return mpAudioPolicy->set_effect_enabled(mpAudioPolicy, id, enabled); |
| 440 | } |
| 441 | |
| 442 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 443 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 444 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 445 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 446 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 447 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 448 | return false; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 449 | } |
| 450 | Mutex::Autolock _l(mLock); |
| 451 | return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs); |
| 452 | } |
| 453 | |
| 454 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 455 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 456 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 457 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 458 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 459 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame^] | 460 | return false; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 461 | } |
| 462 | Mutex::Autolock _l(mLock); |
| 463 | return mpAudioPolicy->is_stream_active_remotely(mpAudioPolicy, stream, inPastMs); |
| 464 | } |
| 465 | |
| 466 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 467 | { |
| 468 | if (mpAudioPolicy == NULL) { |
| 469 | return false; |
| 470 | } |
| 471 | if (mpAudioPolicy->is_source_active == 0) { |
| 472 | return false; |
| 473 | } |
| 474 | Mutex::Autolock _l(mLock); |
| 475 | return mpAudioPolicy->is_source_active(mpAudioPolicy, source); |
| 476 | } |
| 477 | |
| 478 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 479 | effect_descriptor_t *descriptors, |
| 480 | uint32_t *count) |
| 481 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 482 | if (mpAudioPolicy == NULL) { |
| 483 | *count = 0; |
| 484 | return NO_INIT; |
| 485 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 486 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 487 | { |
| 488 | Mutex::Autolock _l(mLock); |
| 489 | audioPolicyEffects = mAudioPolicyEffects; |
| 490 | } |
| 491 | if (audioPolicyEffects == 0) { |
| 492 | *count = 0; |
| 493 | return NO_INIT; |
| 494 | } |
| 495 | return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 499 | { |
| 500 | if (mpAudioPolicy == NULL) { |
| 501 | ALOGV("mpAudioPolicy == NULL"); |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | if (mpAudioPolicy->is_offload_supported == NULL) { |
| 506 | ALOGV("HAL does not implement is_offload_supported"); |
| 507 | return false; |
| 508 | } |
| 509 | |
| 510 | return mpAudioPolicy->is_offload_supported(mpAudioPolicy, &info); |
| 511 | } |
| 512 | |
Eric Laurent | 8670c31 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 513 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role __unused, |
| 514 | audio_port_type_t type __unused, |
| 515 | unsigned int *num_ports, |
| 516 | struct audio_port *ports __unused, |
| 517 | unsigned int *generation __unused) |
| 518 | { |
| 519 | *num_ports = 0; |
| 520 | return INVALID_OPERATION; |
| 521 | } |
| 522 | |
| 523 | status_t AudioPolicyService::getAudioPort(struct audio_port *port __unused) |
| 524 | { |
| 525 | return INVALID_OPERATION; |
| 526 | } |
| 527 | |
| 528 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch __unused, |
| 529 | audio_patch_handle_t *handle __unused) |
| 530 | { |
| 531 | return INVALID_OPERATION; |
| 532 | } |
| 533 | |
| 534 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle __unused) |
| 535 | { |
| 536 | return INVALID_OPERATION; |
| 537 | } |
| 538 | |
| 539 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
| 540 | struct audio_patch *patches __unused, |
| 541 | unsigned int *generation __unused) |
| 542 | { |
| 543 | *num_patches = 0; |
| 544 | return INVALID_OPERATION; |
| 545 | } |
| 546 | |
| 547 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config __unused) |
| 548 | { |
| 549 | return INVALID_OPERATION; |
| 550 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 551 | |
Eric Laurent | f380677 | 2014-10-07 09:19:31 -0700 | [diff] [blame] | 552 | audio_io_handle_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 553 | uint32_t samplingRate, |
| 554 | audio_format_t format, |
| 555 | audio_channel_mask_t channelMask, |
| 556 | audio_output_flags_t flags, |
| 557 | const audio_offload_info_t *offloadInfo) |
| 558 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 559 | audio_stream_type_t stream = audio_attributes_to_stream_type(attr); |
| 560 | |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 561 | return getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo); |
| 562 | } |
| 563 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 564 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 565 | audio_io_handle_t *ioHandle, |
| 566 | audio_devices_t *device) |
| 567 | { |
| 568 | return INVALID_OPERATION; |
| 569 | } |
| 570 | |
| 571 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 572 | { |
| 573 | return INVALID_OPERATION; |
| 574 | } |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 575 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 576 | }; // namespace android |