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