AudioPolicyClientImplLegacy.cpp revision dce54a1492c410ad0d93253b341fb33305337505
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 "AudioPolicyService"
18//#define LOG_NDEBUG 0
19
20#include "Configuration.h"
21#undef __STRICT_ANSI__
22#define __STDINT_LIMITS
23#define __STDC_LIMIT_MACROS
24#include <stdint.h>
25
26#include <sys/time.h>
27#include <binder/IServiceManager.h>
28#include <utils/Log.h>
29#include <cutils/properties.h>
30#include <binder/IPCThreadState.h>
31#include <utils/String16.h>
32#include <utils/threads.h>
33#include "AudioPolicyService.h"
34#include "ServiceUtilities.h"
35#include <hardware_legacy/power.h>
36#include <media/AudioEffect.h>
37#include <media/EffectsFactoryApi.h>
38//#include <media/IAudioFlinger.h>
39
40#include <hardware/hardware.h>
41#include <system/audio.h>
42#include <system/audio_policy.h>
43#include <hardware/audio_policy.h>
44#include <audio_effects/audio_effects_conf.h>
45#include <media/AudioParameter.h>
46
47
48namespace android {
49
50/* implementation of the interface to the policy manager */
51extern "C" {
52
53audio_module_handle_t aps_load_hw_module(void *service __unused,
54                                             const char *name)
55{
56    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
57    if (af == 0) {
58        ALOGW("%s: could not get AudioFlinger", __func__);
59        return 0;
60    }
61
62    return af->loadHwModule(name);
63}
64
65// deprecated: replaced by aps_open_output_on_module()
66audio_io_handle_t aps_open_output(void *service __unused,
67                                         audio_devices_t *pDevices,
68                                         uint32_t *pSamplingRate,
69                                         audio_format_t *pFormat,
70                                         audio_channel_mask_t *pChannelMask,
71                                         uint32_t *pLatencyMs,
72                                         audio_output_flags_t flags)
73{
74    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
75    if (af == 0) {
76        ALOGW("%s: could not get AudioFlinger", __func__);
77        return 0;
78    }
79
80    return af->openOutput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask,
81                          pLatencyMs, flags);
82}
83
84audio_io_handle_t aps_open_output_on_module(void *service __unused,
85                                                   audio_module_handle_t module,
86                                                   audio_devices_t *pDevices,
87                                                   uint32_t *pSamplingRate,
88                                                   audio_format_t *pFormat,
89                                                   audio_channel_mask_t *pChannelMask,
90                                                   uint32_t *pLatencyMs,
91                                                   audio_output_flags_t flags,
92                                                   const audio_offload_info_t *offloadInfo)
93{
94    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
95    if (af == 0) {
96        ALOGW("%s: could not get AudioFlinger", __func__);
97        return 0;
98    }
99    return af->openOutput(module, pDevices, pSamplingRate, pFormat, pChannelMask,
100                          pLatencyMs, flags, offloadInfo);
101}
102
103audio_io_handle_t aps_open_dup_output(void *service __unused,
104                                                 audio_io_handle_t output1,
105                                                 audio_io_handle_t output2)
106{
107    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
108    if (af == 0) {
109        ALOGW("%s: could not get AudioFlinger", __func__);
110        return 0;
111    }
112    return af->openDuplicateOutput(output1, output2);
113}
114
115int aps_close_output(void *service __unused, audio_io_handle_t output)
116{
117    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
118    if (af == 0) {
119        return PERMISSION_DENIED;
120    }
121
122    return af->closeOutput(output);
123}
124
125int aps_suspend_output(void *service __unused, audio_io_handle_t output)
126{
127    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
128    if (af == 0) {
129        ALOGW("%s: could not get AudioFlinger", __func__);
130        return PERMISSION_DENIED;
131    }
132
133    return af->suspendOutput(output);
134}
135
136int aps_restore_output(void *service __unused, audio_io_handle_t output)
137{
138    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
139    if (af == 0) {
140        ALOGW("%s: could not get AudioFlinger", __func__);
141        return PERMISSION_DENIED;
142    }
143
144    return af->restoreOutput(output);
145}
146
147// deprecated: replaced by aps_open_input_on_module(), and acoustics parameter is ignored
148audio_io_handle_t aps_open_input(void *service __unused,
149                                        audio_devices_t *pDevices,
150                                        uint32_t *pSamplingRate,
151                                        audio_format_t *pFormat,
152                                        audio_channel_mask_t *pChannelMask,
153                                        audio_in_acoustics_t acoustics __unused)
154{
155    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
156    if (af == 0) {
157        ALOGW("%s: could not get AudioFlinger", __func__);
158        return 0;
159    }
160
161    return af->openInput((audio_module_handle_t)0, pDevices, pSamplingRate, pFormat, pChannelMask);
162}
163
164audio_io_handle_t aps_open_input_on_module(void *service __unused,
165                                                  audio_module_handle_t module,
166                                                  audio_devices_t *pDevices,
167                                                  uint32_t *pSamplingRate,
168                                                  audio_format_t *pFormat,
169                                                  audio_channel_mask_t *pChannelMask)
170{
171    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
172    if (af == 0) {
173        ALOGW("%s: could not get AudioFlinger", __func__);
174        return 0;
175    }
176
177    return af->openInput(module, pDevices, pSamplingRate, pFormat, pChannelMask);
178}
179
180int aps_close_input(void *service __unused, audio_io_handle_t input)
181{
182    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
183    if (af == 0) {
184        return PERMISSION_DENIED;
185    }
186
187    return af->closeInput(input);
188}
189
190int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream)
191{
192    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
193    if (af == 0) {
194        return PERMISSION_DENIED;
195    }
196
197    return af->invalidateStream(stream);
198}
199
200int aps_move_effects(void *service __unused, int session,
201                                audio_io_handle_t src_output,
202                                audio_io_handle_t dst_output)
203{
204    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
205    if (af == 0) {
206        return PERMISSION_DENIED;
207    }
208
209    return af->moveEffects(session, src_output, dst_output);
210}
211
212char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle,
213                                     const char *keys)
214{
215    String8 result = AudioSystem::getParameters(io_handle, String8(keys));
216    return strdup(result.string());
217}
218
219void aps_set_parameters(void *service, audio_io_handle_t io_handle,
220                                   const char *kv_pairs, int delay_ms)
221{
222    AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
223
224    audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms);
225}
226
227int aps_set_stream_volume(void *service, audio_stream_type_t stream,
228                                     float volume, audio_io_handle_t output,
229                                     int delay_ms)
230{
231    AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
232
233    return audioPolicyService->setStreamVolume(stream, volume, output,
234                                               delay_ms);
235}
236
237int aps_start_tone(void *service, audio_policy_tone_t tone,
238                              audio_stream_type_t stream)
239{
240    AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
241
242    return audioPolicyService->startTone(tone, stream);
243}
244
245int aps_stop_tone(void *service)
246{
247    AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
248
249    return audioPolicyService->stopTone();
250}
251
252int aps_set_voice_volume(void *service, float volume, int delay_ms)
253{
254    AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
255
256    return audioPolicyService->setVoiceVolume(volume, delay_ms);
257}
258
259}; // extern "C"
260
261}; // namespace android
262