blob: 58dae3ec25e39657a71acf889e9d5623209aa168 [file] [log] [blame]
Dima Zavin8cc353a2011-04-20 16:38:05 -07001/*
2 * Copyright (C) 2011 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 "audio_policy_default"
18//#define LOG_NDEBUG 0
19
20#include <errno.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <hardware/hardware.h>
Dima Zavinaa211722011-05-11 14:15:53 -070026#include <system/audio.h>
Dima Zavin11998652011-06-13 18:00:30 -070027#include <system/audio_policy.h>
Dima Zavin3bc15862011-06-13 17:59:54 -070028#include <hardware/audio_policy.h>
Dima Zavin8cc353a2011-04-20 16:38:05 -070029
30struct default_ap_module {
31 struct audio_policy_module module;
32};
33
34struct default_ap_device {
35 struct audio_policy_device device;
36};
37
38struct default_audio_policy {
39 struct audio_policy policy;
40
41 struct audio_policy_service_ops *aps_ops;
42 void *service;
43};
44
45static int ap_set_device_connection_state(struct audio_policy *pol,
46 audio_devices_t device,
47 audio_policy_dev_state_t state,
48 const char *device_address)
49{
50 return -ENOSYS;
51}
52
53static audio_policy_dev_state_t ap_get_device_connection_state(
54 const struct audio_policy *pol,
55 audio_devices_t device,
56 const char *device_address)
57{
58 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
59}
60
61static void ap_set_phone_state(struct audio_policy *pol, int state)
62{
63}
64
65static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
66 uint32_t mask)
67{
68}
69
70static void ap_set_force_use(struct audio_policy *pol,
71 audio_policy_force_use_t usage,
72 audio_policy_forced_cfg_t config)
73{
74}
75
76 /* retreive current device category forced for a given usage */
77static audio_policy_forced_cfg_t ap_get_force_use(
78 const struct audio_policy *pol,
79 audio_policy_force_use_t usage)
80{
81 return AUDIO_POLICY_FORCE_NONE;
82}
83
84/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
85 * can still be muted. */
86static void ap_set_can_mute_enforced_audible(struct audio_policy *pol,
87 bool can_mute)
88{
89}
90
91static int ap_init_check(const struct audio_policy *pol)
92{
93 return 0;
94}
95
96static audio_io_handle_t ap_get_output(struct audio_policy *pol,
97 audio_stream_type_t stream,
98 uint32_t sampling_rate,
99 uint32_t format,
100 uint32_t channels,
101 audio_policy_output_flags_t flags)
102{
103 return 0;
104}
105
106static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output,
107 audio_stream_type_t stream, int session)
108{
109 return -ENOSYS;
110}
111
112static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output,
113 audio_stream_type_t stream, int session)
114{
115 return -ENOSYS;
116}
117
118static void ap_release_output(struct audio_policy *pol,
119 audio_io_handle_t output)
120{
121}
122
123static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
124 uint32_t sampling_rate,
125 uint32_t format,
126 uint32_t channels,
127 audio_in_acoustics_t acoustics)
128{
129 return 0;
130}
131
132static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input)
133{
134 return -ENOSYS;
135}
136
137static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input)
138{
139 return -ENOSYS;
140}
141
142static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input)
143{
144}
145
146static void ap_init_stream_volume(struct audio_policy *pol,
147 audio_stream_type_t stream, int index_min,
148 int index_max)
149{
150}
151
152static int ap_set_stream_volume_index(struct audio_policy *pol,
153 audio_stream_type_t stream,
154 int index)
155{
156 return -ENOSYS;
157}
158
159static int ap_get_stream_volume_index(const struct audio_policy *pol,
160 audio_stream_type_t stream,
161 int *index)
162{
163 return -ENOSYS;
164}
165
166static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
167 audio_stream_type_t stream)
168{
169 return 0;
170}
171
172static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
173 audio_stream_type_t stream)
174{
175 return 0;
176}
177
178static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol,
179 struct effect_descriptor_s *desc)
180{
181 return 0;
182}
183
184static int ap_register_effect(struct audio_policy *pol,
185 struct effect_descriptor_s *desc,
186 audio_io_handle_t output,
187 uint32_t strategy,
188 int session,
189 int id)
190{
191 return -ENOSYS;
192}
193
194static int ap_unregister_effect(struct audio_policy *pol, int id)
195{
196 return -ENOSYS;
197}
198
199static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
200 uint32_t in_past_ms)
201{
202 return false;
203}
204
205static int ap_dump(const struct audio_policy *pol, int fd)
206{
207 return -ENOSYS;
208}
209
210static int create_default_ap(const struct audio_policy_device *device,
211 struct audio_policy_service_ops *aps_ops,
212 void *service,
213 struct audio_policy **ap)
214{
215 struct default_ap_device *dev;
216 struct default_audio_policy *dap;
217 int ret;
218
219 *ap = NULL;
220
221 if (!service || !aps_ops)
222 return -EINVAL;
223
224 dap = (struct default_audio_policy *)calloc(1, sizeof(*dap));
225 if (!dap)
226 return -ENOMEM;
227
228 dap->policy.set_device_connection_state = ap_set_device_connection_state;
229 dap->policy.get_device_connection_state = ap_get_device_connection_state;
230 dap->policy.set_phone_state = ap_set_phone_state;
231 dap->policy.set_ringer_mode = ap_set_ringer_mode;
232 dap->policy.set_force_use = ap_set_force_use;
233 dap->policy.get_force_use = ap_get_force_use;
234 dap->policy.set_can_mute_enforced_audible =
235 ap_set_can_mute_enforced_audible;
236 dap->policy.init_check = ap_init_check;
237 dap->policy.get_output = ap_get_output;
238 dap->policy.start_output = ap_start_output;
239 dap->policy.stop_output = ap_stop_output;
240 dap->policy.release_output = ap_release_output;
241 dap->policy.get_input = ap_get_input;
242 dap->policy.start_input = ap_start_input;
243 dap->policy.stop_input = ap_stop_input;
244 dap->policy.release_input = ap_release_input;
245 dap->policy.init_stream_volume = ap_init_stream_volume;
246 dap->policy.set_stream_volume_index = ap_set_stream_volume_index;
247 dap->policy.get_stream_volume_index = ap_get_stream_volume_index;
248 dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
249 dap->policy.get_devices_for_stream = ap_get_devices_for_stream;
250 dap->policy.get_output_for_effect = ap_get_output_for_effect;
251 dap->policy.register_effect = ap_register_effect;
252 dap->policy.unregister_effect = ap_unregister_effect;
253 dap->policy.is_stream_active = ap_is_stream_active;
254 dap->policy.dump = ap_dump;
255
256 dap->service = service;
257 dap->aps_ops = aps_ops;
258
259 *ap = &dap->policy;
260 return 0;
261}
262
263static int destroy_default_ap(const struct audio_policy_device *ap_dev,
264 struct audio_policy *ap)
265{
266 free(ap);
267 return 0;
268}
269
270static int default_ap_dev_close(hw_device_t* device)
271{
272 free(device);
273 return 0;
274}
275
276static int default_ap_dev_open(const hw_module_t* module, const char* name,
277 hw_device_t** device)
278{
279 struct default_ap_device *dev;
280
281 *device = NULL;
282
283 if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0)
284 return -EINVAL;
285
286 dev = (struct default_ap_device *)calloc(1, sizeof(*dev));
287 if (!dev)
288 return -ENOMEM;
289
290 dev->device.common.tag = HARDWARE_DEVICE_TAG;
291 dev->device.common.version = 0;
292 dev->device.common.module = (hw_module_t *)module;
293 dev->device.common.close = default_ap_dev_close;
294 dev->device.create_audio_policy = create_default_ap;
295 dev->device.destroy_audio_policy = destroy_default_ap;
296
297 *device = &dev->device.common;
298
299 return 0;
300}
301
302static struct hw_module_methods_t default_ap_module_methods = {
303 .open = default_ap_dev_open,
304};
305
306struct default_ap_module HAL_MODULE_INFO_SYM = {
307 .module = {
308 .common = {
309 .tag = HARDWARE_MODULE_TAG,
310 .version_major = 1,
311 .version_minor = 0,
312 .id = AUDIO_POLICY_HARDWARE_MODULE_ID,
313 .name = "Default audio policy HAL",
314 .author = "The Android Open Source Project",
315 .methods = &default_ap_module_methods,
316 },
317 },
318};