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 "AudioPolicyClientImpl" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 20 | #include "AudioPolicyService.h" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 21 | |
Ytai Ben-Tsvi | 74cd6b0 | 2019-10-25 10:06:40 -0700 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | |
| 24 | #include "BinderProxy.h" |
| 25 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 28 | /* implementation of the client interface from the policy manager */ |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 29 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 30 | audio_module_handle_t AudioPolicyService::AudioPolicyClient::loadHwModule(const char *name) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 31 | { |
| 32 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 33 | if (af == 0) { |
| 34 | ALOGW("%s: could not get AudioFlinger", __func__); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 35 | return AUDIO_MODULE_HANDLE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | return af->loadHwModule(name); |
| 39 | } |
| 40 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 41 | status_t AudioPolicyService::AudioPolicyClient::openOutput(audio_module_handle_t module, |
| 42 | audio_io_handle_t *output, |
| 43 | audio_config_t *config, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 44 | const sp<DeviceDescriptorBase>& device, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 45 | uint32_t *latencyMs, |
| 46 | audio_output_flags_t flags) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 47 | { |
| 48 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 49 | if (af == 0) { |
| 50 | ALOGW("%s: could not get AudioFlinger", __func__); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 51 | return PERMISSION_DENIED; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 52 | } |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 53 | |
| 54 | media::OpenOutputRequest request; |
| 55 | media::OpenOutputResponse response; |
| 56 | |
| 57 | request.module = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_module_handle_t_int32_t(module)); |
| 58 | request.config = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_config_t_AudioConfig(*config)); |
| 59 | request.device = VALUE_OR_RETURN_STATUS(legacy2aidl_DeviceDescriptorBase(device)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 60 | request.flags = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 61 | |
| 62 | status_t status = af->openOutput(request, &response); |
| 63 | if (status == OK) { |
| 64 | *output = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_io_handle_t(response.output)); |
| 65 | *config = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioConfig_audio_config_t(response.config)); |
| 66 | *latencyMs = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(response.latencyMs)); |
| 67 | } |
| 68 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 71 | audio_io_handle_t AudioPolicyService::AudioPolicyClient::openDuplicateOutput( |
| 72 | audio_io_handle_t output1, |
| 73 | audio_io_handle_t output2) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 74 | { |
| 75 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 76 | if (af == 0) { |
| 77 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 78 | return 0; |
| 79 | } |
| 80 | return af->openDuplicateOutput(output1, output2); |
| 81 | } |
| 82 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 83 | status_t AudioPolicyService::AudioPolicyClient::closeOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 84 | { |
| 85 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 86 | if (af == 0) { |
| 87 | return PERMISSION_DENIED; |
| 88 | } |
| 89 | |
| 90 | return af->closeOutput(output); |
| 91 | } |
| 92 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 93 | status_t AudioPolicyService::AudioPolicyClient::suspendOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 94 | { |
| 95 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 96 | if (af == 0) { |
| 97 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 98 | return PERMISSION_DENIED; |
| 99 | } |
| 100 | |
| 101 | return af->suspendOutput(output); |
| 102 | } |
| 103 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 104 | status_t AudioPolicyService::AudioPolicyClient::restoreOutput(audio_io_handle_t output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 105 | { |
| 106 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 107 | if (af == 0) { |
| 108 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 109 | return PERMISSION_DENIED; |
| 110 | } |
| 111 | |
| 112 | return af->restoreOutput(output); |
| 113 | } |
| 114 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 115 | status_t AudioPolicyService::AudioPolicyClient::openInput(audio_module_handle_t module, |
| 116 | audio_io_handle_t *input, |
| 117 | audio_config_t *config, |
| 118 | audio_devices_t *device, |
| 119 | const String8& address, |
| 120 | audio_source_t source, |
| 121 | audio_input_flags_t flags) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 122 | { |
| 123 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 124 | if (af == 0) { |
| 125 | ALOGW("%s: could not get AudioFlinger", __func__); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 126 | return PERMISSION_DENIED; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Ytai Ben-Tsvi | 12a0b84 | 2020-11-05 13:47:32 -0800 | [diff] [blame] | 129 | AudioDeviceTypeAddr deviceTypeAddr(*device, address.c_str()); |
| 130 | |
| 131 | media::OpenInputRequest request; |
| 132 | request.module = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_module_handle_t_int32_t(module)); |
| 133 | request.input = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(*input)); |
| 134 | request.config = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_config_t_AudioConfig(*config)); |
| 135 | request.device = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioDeviceTypeAddress(deviceTypeAddr)); |
| 136 | request.source = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_source_t_AudioSourceType(source)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 137 | request.flags = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
Ytai Ben-Tsvi | 12a0b84 | 2020-11-05 13:47:32 -0800 | [diff] [blame] | 138 | |
| 139 | media::OpenInputResponse response; |
| 140 | status_t status = af->openInput(request, &response); |
| 141 | if (status == OK) { |
| 142 | *input = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_module_handle_t(response.input)); |
| 143 | } |
| 144 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 147 | status_t AudioPolicyService::AudioPolicyClient::closeInput(audio_io_handle_t input) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 148 | { |
| 149 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 150 | if (af == 0) { |
| 151 | return PERMISSION_DENIED; |
| 152 | } |
| 153 | |
| 154 | return af->closeInput(input); |
| 155 | } |
| 156 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 157 | status_t AudioPolicyService::AudioPolicyClient::setStreamVolume(audio_stream_type_t stream, |
| 158 | float volume, audio_io_handle_t output, |
| 159 | int delay_ms) |
| 160 | { |
| 161 | return mAudioPolicyService->setStreamVolume(stream, volume, output, |
| 162 | delay_ms); |
| 163 | } |
| 164 | |
| 165 | status_t AudioPolicyService::AudioPolicyClient::invalidateStream(audio_stream_type_t stream) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 166 | { |
| 167 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 168 | if (af == 0) { |
| 169 | return PERMISSION_DENIED; |
| 170 | } |
| 171 | |
| 172 | return af->invalidateStream(stream); |
| 173 | } |
| 174 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 175 | void AudioPolicyService::AudioPolicyClient::setParameters(audio_io_handle_t io_handle, |
| 176 | const String8& keyValuePairs, |
| 177 | int delay_ms) |
| 178 | { |
| 179 | mAudioPolicyService->setParameters(io_handle, keyValuePairs.string(), delay_ms); |
| 180 | } |
| 181 | |
| 182 | String8 AudioPolicyService::AudioPolicyClient::getParameters(audio_io_handle_t io_handle, |
| 183 | const String8& keys) |
| 184 | { |
| 185 | String8 result = AudioSystem::getParameters(io_handle, keys); |
| 186 | return result; |
| 187 | } |
| 188 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 189 | status_t AudioPolicyService::AudioPolicyClient::setVoiceVolume(float volume, int delay_ms) |
| 190 | { |
| 191 | return mAudioPolicyService->setVoiceVolume(volume, delay_ms); |
| 192 | } |
| 193 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 194 | status_t AudioPolicyService::AudioPolicyClient::moveEffects(audio_session_t session, |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 195 | audio_io_handle_t src_output, |
| 196 | audio_io_handle_t dst_output) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 197 | { |
| 198 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 199 | if (af == 0) { |
| 200 | return PERMISSION_DENIED; |
| 201 | } |
| 202 | |
| 203 | return af->moveEffects(session, src_output, dst_output); |
| 204 | } |
| 205 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 206 | void AudioPolicyService::AudioPolicyClient::setEffectSuspended(int effectId, |
| 207 | audio_session_t sessionId, |
| 208 | bool suspended) |
| 209 | { |
| 210 | mAudioPolicyService->setEffectSuspended(effectId, sessionId, suspended); |
| 211 | } |
| 212 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 213 | status_t AudioPolicyService::AudioPolicyClient::createAudioPatch(const struct audio_patch *patch, |
| 214 | audio_patch_handle_t *handle, |
| 215 | int delayMs) |
| 216 | { |
| 217 | return mAudioPolicyService->clientCreateAudioPatch(patch, handle, delayMs); |
| 218 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 219 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 220 | status_t AudioPolicyService::AudioPolicyClient::releaseAudioPatch(audio_patch_handle_t handle, |
| 221 | int delayMs) |
| 222 | { |
| 223 | return mAudioPolicyService->clientReleaseAudioPatch(handle, delayMs); |
| 224 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 225 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 226 | status_t AudioPolicyService::AudioPolicyClient::setAudioPortConfig( |
| 227 | const struct audio_port_config *config, |
| 228 | int delayMs) |
| 229 | { |
| 230 | return mAudioPolicyService->clientSetAudioPortConfig(config, delayMs); |
| 231 | } |
| 232 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 233 | void AudioPolicyService::AudioPolicyClient::onAudioPortListUpdate() |
| 234 | { |
| 235 | mAudioPolicyService->onAudioPortListUpdate(); |
| 236 | } |
| 237 | |
| 238 | void AudioPolicyService::AudioPolicyClient::onAudioPatchListUpdate() |
| 239 | { |
| 240 | mAudioPolicyService->onAudioPatchListUpdate(); |
| 241 | } |
| 242 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 243 | void AudioPolicyService::AudioPolicyClient::onDynamicPolicyMixStateUpdate( |
| 244 | String8 regId, int32_t state) |
| 245 | { |
| 246 | mAudioPolicyService->onDynamicPolicyMixStateUpdate(regId, state); |
| 247 | } |
| 248 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 249 | void AudioPolicyService::AudioPolicyClient::onRecordingConfigurationUpdate( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 250 | int event, |
| 251 | const record_client_info_t *clientInfo, |
| 252 | const audio_config_base_t *clientConfig, |
| 253 | std::vector<effect_descriptor_t> clientEffects, |
| 254 | const audio_config_base_t *deviceConfig, |
| 255 | std::vector<effect_descriptor_t> effects, |
| 256 | audio_patch_handle_t patchHandle, |
| 257 | audio_source_t source) |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 258 | { |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 259 | mAudioPolicyService->onRecordingConfigurationUpdate(event, clientInfo, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 260 | clientConfig, clientEffects, deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 261 | } |
| 262 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 263 | void AudioPolicyService::AudioPolicyClient::onAudioVolumeGroupChanged(volume_group_t group, |
| 264 | int flags) |
| 265 | { |
| 266 | mAudioPolicyService->onAudioVolumeGroupChanged(group, flags); |
| 267 | } |
| 268 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 269 | audio_unique_id_t AudioPolicyService::AudioPolicyClient::newAudioUniqueId(audio_unique_id_use_t use) |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 270 | { |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 271 | return AudioSystem::newAudioUniqueId(use); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Ytai Ben-Tsvi | 1ef846b | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 274 | void AudioPolicyService::AudioPolicyClient::setSoundTriggerCaptureState(bool active) |
| 275 | { |
| 276 | mAudioPolicyService->mCaptureStateNotifier.setCaptureState(active); |
Ytai Ben-Tsvi | 74cd6b0 | 2019-10-25 10:06:40 -0700 | [diff] [blame] | 277 | } |
| 278 | |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 279 | status_t AudioPolicyService::AudioPolicyClient::getAudioPort(struct audio_port_v7 *port) |
| 280 | { |
| 281 | sp<IAudioFlinger> af = AudioSystem::get_audio_flinger(); |
| 282 | if (af == 0) { |
| 283 | ALOGW("%s: could not get AudioFlinger", __func__); |
| 284 | return PERMISSION_DENIED; |
| 285 | } |
| 286 | return af->getAudioPort(port); |
| 287 | } |
| 288 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 289 | } // namespace android |