2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "audio_policy_default"
18 //#define LOG_NDEBUG 0
25 #include <hardware/hardware.h>
26 #include <system/audio.h>
27 #include <system/audio_policy.h>
28 #include <hardware/audio_policy.h>
30 struct default_ap_module {
31 struct audio_policy_module module;
34 struct default_ap_device {
35 struct audio_policy_device device;
38 struct default_audio_policy {
39 struct audio_policy policy;
41 struct audio_policy_service_ops *aps_ops;
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)
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)
58 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
61 static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
65 static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
70 static void ap_set_force_use(struct audio_policy *pol,
71 audio_policy_force_use_t usage,
72 audio_policy_forced_cfg_t config)
76 /* retreive current device category forced for a given usage */
77 static audio_policy_forced_cfg_t ap_get_force_use(
78 const struct audio_policy *pol,
79 audio_policy_force_use_t usage)
81 return AUDIO_POLICY_FORCE_NONE;
84 /* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
85 * can still be muted. */
86 static void ap_set_can_mute_enforced_audible(struct audio_policy *pol,
91 static int ap_init_check(const struct audio_policy *pol)
96 static audio_io_handle_t ap_get_output(struct audio_policy *pol,
97 audio_stream_type_t stream,
98 uint32_t sampling_rate,
101 audio_policy_output_flags_t flags)
106 static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output,
107 audio_stream_type_t stream, int session)
112 static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output,
113 audio_stream_type_t stream, int session)
118 static void ap_release_output(struct audio_policy *pol,
119 audio_io_handle_t output)
123 static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
124 uint32_t sampling_rate,
127 audio_in_acoustics_t acoustics)
132 static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input)
137 static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input)
142 static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input)
146 static void ap_init_stream_volume(struct audio_policy *pol,
147 audio_stream_type_t stream, int index_min,
152 static int ap_set_stream_volume_index(struct audio_policy *pol,
153 audio_stream_type_t stream,
159 static int ap_get_stream_volume_index(const struct audio_policy *pol,
160 audio_stream_type_t stream,
166 static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
167 audio_stream_type_t stream)
172 static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
173 audio_stream_type_t stream)
178 static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol,
179 struct effect_descriptor_s *desc)
184 static int ap_register_effect(struct audio_policy *pol,
185 struct effect_descriptor_s *desc,
186 audio_io_handle_t output,
194 static int ap_unregister_effect(struct audio_policy *pol, int id)
199 static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled)
204 static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
210 static int ap_dump(const struct audio_policy *pol, int fd)
215 static int create_default_ap(const struct audio_policy_device *device,
216 struct audio_policy_service_ops *aps_ops,
218 struct audio_policy **ap)
220 struct default_ap_device *dev;
221 struct default_audio_policy *dap;
226 if (!service || !aps_ops)
229 dap = (struct default_audio_policy *)calloc(1, sizeof(*dap));
233 dap->policy.set_device_connection_state = ap_set_device_connection_state;
234 dap->policy.get_device_connection_state = ap_get_device_connection_state;
235 dap->policy.set_phone_state = ap_set_phone_state;
236 dap->policy.set_ringer_mode = ap_set_ringer_mode;
237 dap->policy.set_force_use = ap_set_force_use;
238 dap->policy.get_force_use = ap_get_force_use;
239 dap->policy.set_can_mute_enforced_audible =
240 ap_set_can_mute_enforced_audible;
241 dap->policy.init_check = ap_init_check;
242 dap->policy.get_output = ap_get_output;
243 dap->policy.start_output = ap_start_output;
244 dap->policy.stop_output = ap_stop_output;
245 dap->policy.release_output = ap_release_output;
246 dap->policy.get_input = ap_get_input;
247 dap->policy.start_input = ap_start_input;
248 dap->policy.stop_input = ap_stop_input;
249 dap->policy.release_input = ap_release_input;
250 dap->policy.init_stream_volume = ap_init_stream_volume;
251 dap->policy.set_stream_volume_index = ap_set_stream_volume_index;
252 dap->policy.get_stream_volume_index = ap_get_stream_volume_index;
253 dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
254 dap->policy.get_devices_for_stream = ap_get_devices_for_stream;
255 dap->policy.get_output_for_effect = ap_get_output_for_effect;
256 dap->policy.register_effect = ap_register_effect;
257 dap->policy.unregister_effect = ap_unregister_effect;
258 dap->policy.set_effect_enabled = ap_set_effect_enabled;
259 dap->policy.is_stream_active = ap_is_stream_active;
260 dap->policy.dump = ap_dump;
262 dap->service = service;
263 dap->aps_ops = aps_ops;
269 static int destroy_default_ap(const struct audio_policy_device *ap_dev,
270 struct audio_policy *ap)
276 static int default_ap_dev_close(hw_device_t* device)
282 static int default_ap_dev_open(const hw_module_t* module, const char* name,
283 hw_device_t** device)
285 struct default_ap_device *dev;
289 if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0)
292 dev = (struct default_ap_device *)calloc(1, sizeof(*dev));
296 dev->device.common.tag = HARDWARE_DEVICE_TAG;
297 dev->device.common.version = 0;
298 dev->device.common.module = (hw_module_t *)module;
299 dev->device.common.close = default_ap_dev_close;
300 dev->device.create_audio_policy = create_default_ap;
301 dev->device.destroy_audio_policy = destroy_default_ap;
303 *device = &dev->device.common;
308 static struct hw_module_methods_t default_ap_module_methods = {
309 .open = default_ap_dev_open,
312 struct default_ap_module HAL_MODULE_INFO_SYM = {
315 .tag = HARDWARE_MODULE_TAG,
318 .id = AUDIO_POLICY_HARDWARE_MODULE_ID,
319 .name = "Default audio policy HAL",
320 .author = "The Android Open Source Project",
321 .methods = &default_ap_module_methods,