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 | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 137 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_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, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 151 | audio_session_t session) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 152 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 153 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 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, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 179 | audio_session_t session) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 180 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 181 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 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, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 194 | audio_session_t session) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 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 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 213 | void AudioPolicyService::releaseOutput(audio_io_handle_t output, |
| 214 | audio_stream_type_t stream, |
| 215 | audio_session_t session) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 216 | { |
| 217 | if (mpAudioPolicy == NULL) { |
| 218 | return; |
| 219 | } |
| 220 | ALOGV("releaseOutput()"); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 221 | mOutputCommandThread->releaseOutputCommand(output, stream, session); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 224 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output, |
| 225 | audio_stream_type_t stream __unused, |
| 226 | audio_session_t session __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 227 | { |
| 228 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 229 | Mutex::Autolock _l(mLock); |
| 230 | mpAudioPolicy->release_output(mpAudioPolicy, output); |
| 231 | } |
| 232 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 233 | status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, |
| 234 | audio_io_handle_t *input, |
| 235 | audio_session_t session, |
| 236 | uint32_t samplingRate, |
| 237 | audio_format_t format, |
| 238 | audio_channel_mask_t channelMask, |
| 239 | audio_input_flags_t flags __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 240 | { |
| 241 | if (mpAudioPolicy == NULL) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 242 | return NO_INIT; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 243 | } |
| 244 | // already checked by client, but double-check in case the client wrapper is bypassed |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 245 | if (attr->source >= AUDIO_SOURCE_CNT && attr->source != AUDIO_SOURCE_HOTWORD && |
| 246 | attr->source != AUDIO_SOURCE_FM_TUNER) { |
| 247 | return BAD_VALUE; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 250 | if (((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) || |
| 251 | ((attr->source == AUDIO_SOURCE_FM_TUNER) && !captureFmTunerAllowed())) { |
| 252 | return BAD_VALUE; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 255 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 256 | { |
| 257 | Mutex::Autolock _l(mLock); |
| 258 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 259 | *input = mpAudioPolicy->get_input(mpAudioPolicy, attr->source, samplingRate, |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 260 | format, channelMask, (audio_in_acoustics_t) 0); |
| 261 | audioPolicyEffects = mAudioPolicyEffects; |
| 262 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 263 | if (*input == AUDIO_IO_HANDLE_NONE) { |
| 264 | return INVALID_OPERATION; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 265 | } |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 266 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 267 | if (audioPolicyEffects != 0) { |
| 268 | // create audio pre processors according to input source |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 269 | status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 270 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 271 | ALOGW("Failed to add effects on input %d", input); |
| 272 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 273 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame^] | 274 | return NO_ERROR; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 277 | status_t AudioPolicyService::startInput(audio_io_handle_t input, |
| 278 | audio_session_t session __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 279 | { |
| 280 | if (mpAudioPolicy == NULL) { |
| 281 | return NO_INIT; |
| 282 | } |
| 283 | Mutex::Autolock _l(mLock); |
| 284 | |
| 285 | return mpAudioPolicy->start_input(mpAudioPolicy, input); |
| 286 | } |
| 287 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 288 | status_t AudioPolicyService::stopInput(audio_io_handle_t input, |
| 289 | audio_session_t session __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 290 | { |
| 291 | if (mpAudioPolicy == NULL) { |
| 292 | return NO_INIT; |
| 293 | } |
| 294 | Mutex::Autolock _l(mLock); |
| 295 | |
| 296 | return mpAudioPolicy->stop_input(mpAudioPolicy, input); |
| 297 | } |
| 298 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 299 | void AudioPolicyService::releaseInput(audio_io_handle_t input, |
| 300 | audio_session_t session __unused) |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 301 | { |
| 302 | if (mpAudioPolicy == NULL) { |
| 303 | return; |
| 304 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 305 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 306 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 307 | { |
| 308 | Mutex::Autolock _l(mLock); |
| 309 | mpAudioPolicy->release_input(mpAudioPolicy, input); |
| 310 | audioPolicyEffects = mAudioPolicyEffects; |
| 311 | } |
| 312 | if (audioPolicyEffects != 0) { |
| 313 | // release audio processors from the input |
| 314 | status_t status = audioPolicyEffects->releaseInputEffects(input); |
| 315 | if(status != NO_ERROR) { |
| 316 | ALOGW("Failed to release effects on input %d", input); |
| 317 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 318 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 322 | int indexMin, |
| 323 | int indexMax) |
| 324 | { |
| 325 | if (mpAudioPolicy == NULL) { |
| 326 | return NO_INIT; |
| 327 | } |
| 328 | if (!settingsAllowed()) { |
| 329 | return PERMISSION_DENIED; |
| 330 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 331 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 332 | return BAD_VALUE; |
| 333 | } |
| 334 | Mutex::Autolock _l(mLock); |
| 335 | mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax); |
| 336 | return NO_ERROR; |
| 337 | } |
| 338 | |
| 339 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 340 | int index, |
| 341 | audio_devices_t device) |
| 342 | { |
| 343 | if (mpAudioPolicy == NULL) { |
| 344 | return NO_INIT; |
| 345 | } |
| 346 | if (!settingsAllowed()) { |
| 347 | return PERMISSION_DENIED; |
| 348 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 349 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 350 | return BAD_VALUE; |
| 351 | } |
| 352 | Mutex::Autolock _l(mLock); |
| 353 | if (mpAudioPolicy->set_stream_volume_index_for_device) { |
| 354 | return mpAudioPolicy->set_stream_volume_index_for_device(mpAudioPolicy, |
| 355 | stream, |
| 356 | index, |
| 357 | device); |
| 358 | } else { |
| 359 | return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 364 | int *index, |
| 365 | audio_devices_t device) |
| 366 | { |
| 367 | if (mpAudioPolicy == NULL) { |
| 368 | return NO_INIT; |
| 369 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 370 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 371 | return BAD_VALUE; |
| 372 | } |
| 373 | Mutex::Autolock _l(mLock); |
| 374 | if (mpAudioPolicy->get_stream_volume_index_for_device) { |
| 375 | return mpAudioPolicy->get_stream_volume_index_for_device(mpAudioPolicy, |
| 376 | stream, |
| 377 | index, |
| 378 | device); |
| 379 | } else { |
| 380 | return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 385 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 386 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 387 | return 0; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 388 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 389 | if (mpAudioPolicy == NULL) { |
| 390 | return 0; |
| 391 | } |
| 392 | return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream); |
| 393 | } |
| 394 | |
| 395 | //audio policy: use audio_device_t appropriately |
| 396 | |
| 397 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 398 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 399 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 400 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 401 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 402 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 403 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 404 | } |
| 405 | return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream); |
| 406 | } |
| 407 | |
| 408 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 409 | { |
| 410 | // FIXME change return type to status_t, and return NO_INIT here |
| 411 | if (mpAudioPolicy == NULL) { |
| 412 | return 0; |
| 413 | } |
| 414 | Mutex::Autolock _l(mLock); |
| 415 | return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc); |
| 416 | } |
| 417 | |
| 418 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 419 | audio_io_handle_t io, |
| 420 | uint32_t strategy, |
| 421 | int session, |
| 422 | int id) |
| 423 | { |
| 424 | if (mpAudioPolicy == NULL) { |
| 425 | return NO_INIT; |
| 426 | } |
| 427 | return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id); |
| 428 | } |
| 429 | |
| 430 | status_t AudioPolicyService::unregisterEffect(int id) |
| 431 | { |
| 432 | if (mpAudioPolicy == NULL) { |
| 433 | return NO_INIT; |
| 434 | } |
| 435 | return mpAudioPolicy->unregister_effect(mpAudioPolicy, id); |
| 436 | } |
| 437 | |
| 438 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 439 | { |
| 440 | if (mpAudioPolicy == NULL) { |
| 441 | return NO_INIT; |
| 442 | } |
| 443 | return mpAudioPolicy->set_effect_enabled(mpAudioPolicy, id, enabled); |
| 444 | } |
| 445 | |
| 446 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 447 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 448 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 449 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 450 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 451 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 452 | return false; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 453 | } |
| 454 | Mutex::Autolock _l(mLock); |
| 455 | return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs); |
| 456 | } |
| 457 | |
| 458 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 459 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 460 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 461 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 462 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 463 | if (mpAudioPolicy == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 464 | return false; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 465 | } |
| 466 | Mutex::Autolock _l(mLock); |
| 467 | return mpAudioPolicy->is_stream_active_remotely(mpAudioPolicy, stream, inPastMs); |
| 468 | } |
| 469 | |
| 470 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 471 | { |
| 472 | if (mpAudioPolicy == NULL) { |
| 473 | return false; |
| 474 | } |
| 475 | if (mpAudioPolicy->is_source_active == 0) { |
| 476 | return false; |
| 477 | } |
| 478 | Mutex::Autolock _l(mLock); |
| 479 | return mpAudioPolicy->is_source_active(mpAudioPolicy, source); |
| 480 | } |
| 481 | |
| 482 | status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession, |
| 483 | effect_descriptor_t *descriptors, |
| 484 | uint32_t *count) |
| 485 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 486 | if (mpAudioPolicy == NULL) { |
| 487 | *count = 0; |
| 488 | return NO_INIT; |
| 489 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 490 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 491 | { |
| 492 | Mutex::Autolock _l(mLock); |
| 493 | audioPolicyEffects = mAudioPolicyEffects; |
| 494 | } |
| 495 | if (audioPolicyEffects == 0) { |
| 496 | *count = 0; |
| 497 | return NO_INIT; |
| 498 | } |
| 499 | return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 503 | { |
| 504 | if (mpAudioPolicy == NULL) { |
| 505 | ALOGV("mpAudioPolicy == NULL"); |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | if (mpAudioPolicy->is_offload_supported == NULL) { |
| 510 | ALOGV("HAL does not implement is_offload_supported"); |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | return mpAudioPolicy->is_offload_supported(mpAudioPolicy, &info); |
| 515 | } |
| 516 | |
Eric Laurent | 8670c31 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 517 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role __unused, |
| 518 | audio_port_type_t type __unused, |
| 519 | unsigned int *num_ports, |
| 520 | struct audio_port *ports __unused, |
| 521 | unsigned int *generation __unused) |
| 522 | { |
| 523 | *num_ports = 0; |
| 524 | return INVALID_OPERATION; |
| 525 | } |
| 526 | |
| 527 | status_t AudioPolicyService::getAudioPort(struct audio_port *port __unused) |
| 528 | { |
| 529 | return INVALID_OPERATION; |
| 530 | } |
| 531 | |
| 532 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch __unused, |
| 533 | audio_patch_handle_t *handle __unused) |
| 534 | { |
| 535 | return INVALID_OPERATION; |
| 536 | } |
| 537 | |
| 538 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle __unused) |
| 539 | { |
| 540 | return INVALID_OPERATION; |
| 541 | } |
| 542 | |
| 543 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
| 544 | struct audio_patch *patches __unused, |
| 545 | unsigned int *generation __unused) |
| 546 | { |
| 547 | *num_patches = 0; |
| 548 | return INVALID_OPERATION; |
| 549 | } |
| 550 | |
| 551 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config __unused) |
| 552 | { |
| 553 | return INVALID_OPERATION; |
| 554 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 555 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 556 | status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 557 | audio_io_handle_t *output, |
| 558 | audio_session_t session, |
| 559 | audio_stream_type_t *stream, |
| 560 | uint32_t samplingRate, |
| 561 | audio_format_t format, |
| 562 | audio_channel_mask_t channelMask, |
| 563 | audio_output_flags_t flags, |
| 564 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 565 | { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 566 | if (attr != NULL) { |
| 567 | *stream = audio_attributes_to_stream_type(attr); |
| 568 | } else { |
| 569 | if (*stream == AUDIO_STREAM_DEFAULT) { |
| 570 | return BAD_VALUE; |
| 571 | } |
| 572 | } |
| 573 | *output = getOutput(*stream, samplingRate, format, channelMask, |
| 574 | flags, offloadInfo); |
| 575 | if (*output == AUDIO_IO_HANDLE_NONE) { |
| 576 | return INVALID_OPERATION; |
| 577 | } |
| 578 | return NO_ERROR; |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 581 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session __unused, |
| 582 | audio_io_handle_t *ioHandle __unused, |
| 583 | audio_devices_t *device __unused) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 584 | { |
| 585 | return INVALID_OPERATION; |
| 586 | } |
| 587 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 588 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session __unused) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 589 | { |
| 590 | return INVALID_OPERATION; |
| 591 | } |
Eric Laurent | 7c5b60a | 2014-07-15 10:38:16 -0700 | [diff] [blame] | 592 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 593 | }; // namespace android |