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