blob: 9335654e3dc2197ce9fb9e3764ba69c7d989853b [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
Glenn Kasten6df641e2012-01-09 10:41:30 -080061static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
Dima Zavin8cc353a2011-04-20 16:38:05 -070062{
63}
64
Glenn Kasten080a8022012-01-18 15:15:07 -080065// deprecated, never called
Dima Zavin8cc353a2011-04-20 16:38:05 -070066static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
67 uint32_t mask)
68{
69}
70
71static void ap_set_force_use(struct audio_policy *pol,
72 audio_policy_force_use_t usage,
73 audio_policy_forced_cfg_t config)
74{
75}
76
77 /* retreive current device category forced for a given usage */
78static audio_policy_forced_cfg_t ap_get_force_use(
79 const struct audio_policy *pol,
80 audio_policy_force_use_t usage)
81{
82 return AUDIO_POLICY_FORCE_NONE;
83}
84
85/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
86 * can still be muted. */
87static void ap_set_can_mute_enforced_audible(struct audio_policy *pol,
88 bool can_mute)
89{
90}
91
92static int ap_init_check(const struct audio_policy *pol)
93{
94 return 0;
95}
96
97static audio_io_handle_t ap_get_output(struct audio_policy *pol,
98 audio_stream_type_t stream,
99 uint32_t sampling_rate,
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800100 audio_format_t format,
Glenn Kastena6354492012-06-19 12:16:04 -0700101 audio_channel_mask_t channelMask,
Richard Fitzgerald072a79d2013-05-13 16:58:54 +0100102 audio_output_flags_t flags,
103 const audio_offload_info_t *info)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700104{
105 return 0;
106}
107
108static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output,
109 audio_stream_type_t stream, int session)
110{
111 return -ENOSYS;
112}
113
114static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output,
115 audio_stream_type_t stream, int session)
116{
117 return -ENOSYS;
118}
119
120static void ap_release_output(struct audio_policy *pol,
121 audio_io_handle_t output)
122{
123}
124
Glenn Kastenae2e42b2012-01-26 16:47:25 -0800125static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700126 uint32_t sampling_rate,
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800127 audio_format_t format,
Glenn Kastena6354492012-06-19 12:16:04 -0700128 audio_channel_mask_t channelMask,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700129 audio_in_acoustics_t acoustics)
130{
131 return 0;
132}
133
134static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input)
135{
136 return -ENOSYS;
137}
138
139static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input)
140{
141 return -ENOSYS;
142}
143
144static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input)
145{
146}
147
148static void ap_init_stream_volume(struct audio_policy *pol,
149 audio_stream_type_t stream, int index_min,
150 int index_max)
151{
152}
153
154static int ap_set_stream_volume_index(struct audio_policy *pol,
155 audio_stream_type_t stream,
156 int index)
157{
158 return -ENOSYS;
159}
160
161static int ap_get_stream_volume_index(const struct audio_policy *pol,
162 audio_stream_type_t stream,
163 int *index)
164{
165 return -ENOSYS;
166}
167
Eric Laurentca20b172011-12-09 17:10:40 -0800168static int ap_set_stream_volume_index_for_device(struct audio_policy *pol,
169 audio_stream_type_t stream,
170 int index,
171 audio_devices_t device)
172{
173 return -ENOSYS;
174}
175
176static int ap_get_stream_volume_index_for_device(const struct audio_policy *pol,
177 audio_stream_type_t stream,
178 int *index,
179 audio_devices_t device)
180{
181 return -ENOSYS;
182}
183
Dima Zavin8cc353a2011-04-20 16:38:05 -0700184static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
185 audio_stream_type_t stream)
186{
187 return 0;
188}
189
Eric Laurent83c62ce2012-03-08 13:44:18 -0800190static audio_devices_t ap_get_devices_for_stream(const struct audio_policy *pol,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700191 audio_stream_type_t stream)
192{
193 return 0;
194}
195
196static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol,
Glenn Kasten48915ac2012-02-20 12:08:57 -0800197 const struct effect_descriptor_s *desc)
Dima Zavin8cc353a2011-04-20 16:38:05 -0700198{
199 return 0;
200}
201
202static int ap_register_effect(struct audio_policy *pol,
Glenn Kasten48915ac2012-02-20 12:08:57 -0800203 const struct effect_descriptor_s *desc,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700204 audio_io_handle_t output,
205 uint32_t strategy,
206 int session,
207 int id)
208{
209 return -ENOSYS;
210}
211
212static int ap_unregister_effect(struct audio_policy *pol, int id)
213{
214 return -ENOSYS;
215}
216
Eric Laurent78d2c692011-08-10 20:15:48 -0700217static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled)
218{
219 return -ENOSYS;
220}
221
Glenn Kasten5161a842012-01-12 14:56:21 -0800222static bool ap_is_stream_active(const struct audio_policy *pol, audio_stream_type_t stream,
Dima Zavin8cc353a2011-04-20 16:38:05 -0700223 uint32_t in_past_ms)
224{
225 return false;
226}
227
228static int ap_dump(const struct audio_policy *pol, int fd)
229{
230 return -ENOSYS;
231}
232
Richard Fitzgerald072a79d2013-05-13 16:58:54 +0100233static bool ap_is_offload_supported(const struct audio_policy *pol,
234 const audio_offload_info_t *info)
235{
236 return false;
237}
238
Dima Zavin8cc353a2011-04-20 16:38:05 -0700239static int create_default_ap(const struct audio_policy_device *device,
240 struct audio_policy_service_ops *aps_ops,
241 void *service,
242 struct audio_policy **ap)
243{
244 struct default_ap_device *dev;
245 struct default_audio_policy *dap;
246 int ret;
247
248 *ap = NULL;
249
250 if (!service || !aps_ops)
251 return -EINVAL;
252
253 dap = (struct default_audio_policy *)calloc(1, sizeof(*dap));
254 if (!dap)
255 return -ENOMEM;
256
257 dap->policy.set_device_connection_state = ap_set_device_connection_state;
258 dap->policy.get_device_connection_state = ap_get_device_connection_state;
259 dap->policy.set_phone_state = ap_set_phone_state;
260 dap->policy.set_ringer_mode = ap_set_ringer_mode;
261 dap->policy.set_force_use = ap_set_force_use;
262 dap->policy.get_force_use = ap_get_force_use;
263 dap->policy.set_can_mute_enforced_audible =
264 ap_set_can_mute_enforced_audible;
265 dap->policy.init_check = ap_init_check;
266 dap->policy.get_output = ap_get_output;
267 dap->policy.start_output = ap_start_output;
268 dap->policy.stop_output = ap_stop_output;
269 dap->policy.release_output = ap_release_output;
270 dap->policy.get_input = ap_get_input;
271 dap->policy.start_input = ap_start_input;
272 dap->policy.stop_input = ap_stop_input;
273 dap->policy.release_input = ap_release_input;
274 dap->policy.init_stream_volume = ap_init_stream_volume;
275 dap->policy.set_stream_volume_index = ap_set_stream_volume_index;
276 dap->policy.get_stream_volume_index = ap_get_stream_volume_index;
Eric Laurentca20b172011-12-09 17:10:40 -0800277 dap->policy.set_stream_volume_index_for_device = ap_set_stream_volume_index_for_device;
278 dap->policy.get_stream_volume_index_for_device = ap_get_stream_volume_index_for_device;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700279 dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
280 dap->policy.get_devices_for_stream = ap_get_devices_for_stream;
281 dap->policy.get_output_for_effect = ap_get_output_for_effect;
282 dap->policy.register_effect = ap_register_effect;
283 dap->policy.unregister_effect = ap_unregister_effect;
Eric Laurent78d2c692011-08-10 20:15:48 -0700284 dap->policy.set_effect_enabled = ap_set_effect_enabled;
Dima Zavin8cc353a2011-04-20 16:38:05 -0700285 dap->policy.is_stream_active = ap_is_stream_active;
286 dap->policy.dump = ap_dump;
287
Richard Fitzgerald072a79d2013-05-13 16:58:54 +0100288 dap->policy.is_offload_supported = ap_is_offload_supported;
289
Dima Zavin8cc353a2011-04-20 16:38:05 -0700290 dap->service = service;
291 dap->aps_ops = aps_ops;
292
293 *ap = &dap->policy;
294 return 0;
295}
296
297static int destroy_default_ap(const struct audio_policy_device *ap_dev,
298 struct audio_policy *ap)
299{
300 free(ap);
301 return 0;
302}
303
304static int default_ap_dev_close(hw_device_t* device)
305{
306 free(device);
307 return 0;
308}
309
310static int default_ap_dev_open(const hw_module_t* module, const char* name,
311 hw_device_t** device)
312{
313 struct default_ap_device *dev;
314
315 *device = NULL;
316
317 if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0)
318 return -EINVAL;
319
320 dev = (struct default_ap_device *)calloc(1, sizeof(*dev));
321 if (!dev)
322 return -ENOMEM;
323
324 dev->device.common.tag = HARDWARE_DEVICE_TAG;
325 dev->device.common.version = 0;
326 dev->device.common.module = (hw_module_t *)module;
327 dev->device.common.close = default_ap_dev_close;
328 dev->device.create_audio_policy = create_default_ap;
329 dev->device.destroy_audio_policy = destroy_default_ap;
330
331 *device = &dev->device.common;
332
333 return 0;
334}
335
336static struct hw_module_methods_t default_ap_module_methods = {
337 .open = default_ap_dev_open,
338};
339
340struct default_ap_module HAL_MODULE_INFO_SYM = {
341 .module = {
342 .common = {
343 .tag = HARDWARE_MODULE_TAG,
344 .version_major = 1,
345 .version_minor = 0,
346 .id = AUDIO_POLICY_HARDWARE_MODULE_ID,
347 .name = "Default audio policy HAL",
348 .author = "The Android Open Source Project",
349 .methods = &default_ap_module_methods,
350 },
351 },
352};