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