1 /*
2  * Copyright (C) 2014 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 #ifndef AUDIO_EXTN_H
18 #define AUDIO_EXTN_H
19 
20 #include <cutils/str_parms.h>
21 
22 #define HW_INFO_ARRAY_MAX_SIZE 32
23 
24 struct snd_card_split {
25     char device[HW_INFO_ARRAY_MAX_SIZE];
26     char snd_card[HW_INFO_ARRAY_MAX_SIZE];
27     char form_factor[HW_INFO_ARRAY_MAX_SIZE];
28 };
29 
30 void *audio_extn_extspk_init(struct audio_device *adev);
31 void audio_extn_extspk_deinit(void *extn);
32 void audio_extn_extspk_update(void* extn);
33 void audio_extn_extspk_set_mode(void* extn, audio_mode_t mode);
34 void audio_extn_extspk_set_voice_vol(void* extn, float vol);
35 struct snd_card_split *audio_extn_get_snd_card_split();
36 void audio_extn_set_snd_card_split(const char* in_snd_card_name);
37 
38 #ifndef SPKR_PROT_ENABLED
39 #define audio_extn_spkr_prot_init(adev)       (0)
40 #define audio_extn_spkr_prot_start_processing(snd_device)    (-EINVAL)
41 #define audio_extn_spkr_prot_calib_cancel(adev) (0)
42 #define audio_extn_spkr_prot_stop_processing(snd_device)     (0)
43 #define audio_extn_spkr_prot_is_enabled() (false)
44 #define audio_extn_get_spkr_prot_snd_device(snd_device) (snd_device)
45 #else
46 void audio_extn_spkr_prot_init(void *adev);
47 int audio_extn_spkr_prot_start_processing(snd_device_t snd_device);
48 void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device);
49 bool audio_extn_spkr_prot_is_enabled();
50 int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device);
51 void audio_extn_spkr_prot_calib_cancel(void *adev);
52 #endif
53 
54 #ifndef HFP_ENABLED
55 #define audio_extn_hfp_is_active(adev)                  (0)
56 #define audio_extn_hfp_get_usecase()                    (-1)
57 #define audio_extn_hfp_set_parameters(adev, params)     (0)
58 #define audio_extn_hfp_set_mic_mute(adev, state)        (0)
59 
60 #else
61 bool audio_extn_hfp_is_active(struct audio_device *adev);
62 
63 audio_usecase_t audio_extn_hfp_get_usecase();
64 
65 void audio_extn_hfp_set_parameters(struct audio_device *adev,
66                                     struct str_parms *parms);
67 int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state);
68 
69 #endif
70 
71 #ifndef USB_TUNNEL_ENABLED
72 #define audio_extn_usb_init(adev)                                      (0)
73 #define audio_extn_usb_deinit()                                        (0)
74 #define audio_extn_usb_add_device(device, card)                        (0)
75 #define audio_extn_usb_remove_device(device, card)                     (0)
76 #define audio_extn_usb_is_config_supported(bit_width, sample_rate, ch, pb) (false)
77 #define audio_extn_usb_enable_sidetone(device, enable)                 (0)
78 #define audio_extn_usb_set_sidetone_gain(parms, value, len)            (0)
79 #define audio_extn_usb_is_capture_supported()                          (false)
80 #define audio_extn_usb_get_max_channels(dir)                           (0)
81 #define audio_extn_usb_get_max_bit_width(dir)                          (0)
82 #define audio_extn_usb_sup_sample_rates(t, s, l)        ((t), (s), (l), 0) /* fix unused warn */
83 #define audio_extn_usb_alive(adev)                                     (false)
84 #define audio_extn_usb_find_service_interval(m, p)      ((m), (p), 0) /* fix unused warn */
85 #define audio_extn_usb_altset_for_service_interval(p, si, bw, sr, ch) (-1)
86 #else
87 void audio_extn_usb_init(void *adev);
88 void audio_extn_usb_deinit();
89 void audio_extn_usb_add_device(audio_devices_t device, int card);
90 void audio_extn_usb_remove_device(audio_devices_t device, int card);
91 bool audio_extn_usb_is_config_supported(unsigned int *bit_width,
92                                         unsigned int *sample_rate,
93                                         unsigned int *ch,
94                                         bool is_playback);
95 int audio_extn_usb_enable_sidetone(int device, bool enable);
96 int audio_extn_usb_set_sidetone_gain(struct str_parms *parms,
97                                      char *value, int len);
98 bool audio_extn_usb_is_capture_supported();
99 int audio_extn_usb_get_max_channels(bool is_playback);
100 int audio_extn_usb_get_max_bit_width(bool is_playback);
101 int audio_extn_usb_sup_sample_rates(bool is_playback, uint32_t *sr, uint32_t l);
102 bool audio_extn_usb_alive(int card);
103 unsigned long audio_extn_usb_find_service_interval(bool min, bool playback);
104 int audio_extn_usb_altset_for_service_interval(bool is_playback,
105                                                unsigned long service_interval,
106                                                uint32_t *bit_width,
107                                                uint32_t *sample_rate,
108                                                uint32_t *channel_count);
109 #endif
110 
111 
112 #ifndef SOUND_TRIGGER_ENABLED
113 #define audio_extn_sound_trigger_init(adev)                            (0)
114 #define audio_extn_sound_trigger_deinit(adev)                          (0)
115 #define audio_extn_sound_trigger_update_device_status(snd_dev, event)  (0)
116 #define audio_extn_sound_trigger_update_stream_status(uc_info, event)  (0)
117 #define audio_extn_sound_trigger_set_parameters(adev, parms)           (0)
118 #define audio_extn_sound_trigger_check_and_get_session(in)             (0)
119 #define audio_extn_sound_trigger_stop_lab(in)                          (0)
120 #define audio_extn_sound_trigger_read(in, buffer, bytes)               (0)
121 
122 #else
123 
124 enum st_event_type {
125     ST_EVENT_SND_DEVICE_FREE,
126     ST_EVENT_SND_DEVICE_BUSY,
127     ST_EVENT_STREAM_FREE,
128     ST_EVENT_STREAM_BUSY
129 };
130 typedef enum st_event_type st_event_type_t;
131 
132 int audio_extn_sound_trigger_init(struct audio_device *adev);
133 void audio_extn_sound_trigger_deinit(struct audio_device *adev);
134 void audio_extn_sound_trigger_update_device_status(snd_device_t snd_device,
135                                      st_event_type_t event);
136 void audio_extn_sound_trigger_update_stream_status(struct audio_usecase *uc_info,
137                                      st_event_type_t event);
138 void audio_extn_sound_trigger_set_parameters(struct audio_device *adev,
139                                              struct str_parms *parms);
140 void audio_extn_sound_trigger_check_and_get_session(struct stream_in *in);
141 void audio_extn_sound_trigger_stop_lab(struct stream_in *in);
142 int audio_extn_sound_trigger_read(struct stream_in *in, void *buffer,
143                                   size_t bytes);
144 #endif
145 
146 #ifndef A2DP_OFFLOAD_ENABLED
147 #define audio_extn_a2dp_init(adev)                       (0)
148 #define audio_extn_a2dp_start_playback()                 (0)
149 #define audio_extn_a2dp_stop_playback()                  (0)
150 #define audio_extn_a2dp_set_parameters(parms, reconfig)  (0)
151 #define audio_extn_a2dp_get_parameters(query, reply)     (0)
152 #define audio_extn_a2dp_is_force_device_switch()         (0)
153 #define audio_extn_a2dp_set_handoff_mode(is_on)          (0)
154 #define audio_extn_a2dp_get_sample_rate(sample_rate)     (0)
155 #define audio_extn_a2dp_get_encoder_latency()            (0)
156 #define audio_extn_a2dp_is_ready()                       (0)
157 #define audio_extn_a2dp_is_suspended()                   (0)
158 #else
159 void audio_extn_a2dp_init(void *adev);
160 int audio_extn_a2dp_start_playback();
161 int audio_extn_a2dp_stop_playback();
162 int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig);
163 int audio_extn_a2dp_get_parameters(struct str_parms *query,
164                                    struct str_parms *reply);
165 bool audio_extn_a2dp_is_force_device_switch();
166 void audio_extn_a2dp_set_handoff_mode(bool is_on);
167 void audio_extn_a2dp_get_sample_rate(int *sample_rate);
168 uint32_t audio_extn_a2dp_get_encoder_latency();
169 bool audio_extn_a2dp_is_ready();
170 bool audio_extn_a2dp_is_suspended();
171 #endif
172 
173 #ifndef DSM_FEEDBACK_ENABLED
174 #define audio_extn_dsm_feedback_enable(adev, snd_device, benable)                (0)
175 #else
176 void audio_extn_dsm_feedback_enable(struct audio_device *adev,
177                          snd_device_t snd_device,
178                          bool benable);
179 #endif
180 
181 void audio_extn_utils_send_default_app_type_cfg(void *platform, struct mixer *mixer);
182 int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
183                                        struct audio_usecase *usecase);
184 void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
185                                              struct audio_usecase *usecase);
186 int audio_extn_utils_send_app_type_gain(struct audio_device *adev,
187                                         int app_type,
188                                         int *gain);
189 #ifndef HWDEP_CAL_ENABLED
190 #define  audio_extn_hwdep_cal_send(snd_card, acdb_handle) (0)
191 #else
192 void audio_extn_hwdep_cal_send(int snd_card, void *acdb_handle);
193 #endif
194 
195 #ifndef KPI_OPTIMIZE_ENABLED
196 #define audio_extn_perf_lock_init() (0)
197 #define audio_extn_perf_lock_acquire() (0)
198 #define audio_extn_perf_lock_release() (0)
199 #else
200 int audio_extn_perf_lock_init(void);
201 void audio_extn_perf_lock_acquire(void);
202 void audio_extn_perf_lock_release(void);
203 #endif /* KPI_OPTIMIZE_ENABLED */
204 
205 #ifndef HW_VARIANTS_ENABLED
206 #define hw_info_init(snd_card_name)                  (0)
207 #define hw_info_deinit(hw_info)                      (0)
208 #define hw_info_append_hw_type(hw_info,\
209         snd_device, device_name)                     (0)
210 #else
211 void *hw_info_init(const char *snd_card_name);
212 void hw_info_deinit(void *hw_info);
213 void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device,
214                              char *device_name);
215 #endif /* HW_VARIANTS_ENABLED */
216 
217 typedef void (* snd_mon_cb)(void * stream, struct str_parms * parms);
218 #ifndef SND_MONITOR_ENABLED
219 #define audio_extn_snd_mon_init()           (0)
220 #define audio_extn_snd_mon_deinit()         (0)
221 #define audio_extn_snd_mon_register_listener(stream, cb) (0)
222 #define audio_extn_snd_mon_unregister_listener(stream) (0)
223 #else
224 int audio_extn_snd_mon_init();
225 int audio_extn_snd_mon_deinit();
226 int audio_extn_snd_mon_register_listener(void *stream, snd_mon_cb cb);
227 int audio_extn_snd_mon_unregister_listener(void *stream);
228 #endif
229 
230 bool audio_extn_utils_resolve_config_file(char[]);
231 int audio_extn_utils_get_platform_info(const char* snd_card_name,
232                                        char* platform_info_file);
233 int audio_extn_utils_get_snd_card_num();
234 #endif /* AUDIO_EXTN_H */
235