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