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