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