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