1 /*
2  * Copyright (C) 2013-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_PLATFORM_API_H
18 #define AUDIO_PLATFORM_API_H
19 
20 #include "voice.h"
21 #define MAX_VOLUME_CAL_STEPS 15
22 #define CODEC_BACKEND_DEFAULT_SAMPLE_RATE 48000
23 #define CODEC_BACKEND_DEFAULT_BIT_WIDTH 16
24 #define CODEC_BACKEND_DEFAULT_CHANNELS 2
25 #define CODEC_BACKEND_DEFAULT_TX_CHANNELS 1
26 #define SAMPLE_RATE_8000 8000
27 #define SAMPLE_RATE_11025 11025
28 #define sample_rate_multiple(sr, base) ((sr % base)== 0?true:false)
29 
30 typedef enum {
31     EFFECT_NONE = 0,
32     EFFECT_AEC,
33     EFFECT_NS,
34     EFFECT_COUNT
35 } effect_type_t;
36 
37 struct audio_effect_config {
38     uint32_t module_id;
39     uint32_t instance_id;
40     uint32_t param_id;
41     uint32_t param_value;
42 };
43 
44 struct amp_db_and_gain_table {
45     float amp;
46     float db;
47     uint32_t level;
48 };
49 
50 struct mic_info {
51     char device_id[AUDIO_MICROPHONE_ID_MAX_LEN];
52     size_t channel_count;
53     audio_microphone_channel_mapping_t channel_mapping[AUDIO_CHANNEL_COUNT_MAX];
54 };
55 
56 enum card_status_t;
57 struct audio_usecase;
58 enum usecase_type_t;
59 struct audio_backend_cfg;
60 
61 void *platform_init(struct audio_device *adev);
62 void platform_deinit(void *platform);
63 const char *platform_get_snd_device_name(snd_device_t snd_device);
64 int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
65                                       char *device_name);
66 void platform_add_backend_name(void *platform, char *mixer_path,
67                                                     snd_device_t snd_device);
68 bool platform_send_gain_dep_cal(void *platform, int level);
69 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type);
70 int platform_get_snd_device_index(char *snd_device_index_name);
71 int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id);
72 int platform_get_snd_device_acdb_id(snd_device_t snd_device);
73 int platform_set_effect_config_data(snd_device_t snd_device,
74                                       struct audio_effect_config effect_config,
75                                       effect_type_t effect_type);
76 int platform_get_effect_config_data(snd_device_t snd_device,
77                                       struct audio_effect_config *effect_config,
78                                       effect_type_t effect_type);
79 int platform_send_audio_calibration(void *platform, snd_device_t snd_device);
80 int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
81                                        int app_type, int sample_rate);
82 int platform_set_acdb_metainfo_key(void *platform, char *name, int key);
83 int platform_get_default_app_type_v2(void *platform, enum usecase_type_t type, int *app_type);
84 int platform_switch_voice_call_device_pre(void *platform);
85 int platform_switch_voice_call_enable_device_config(void *platform,
86                                                     snd_device_t out_snd_device,
87                                                     snd_device_t in_snd_device);
88 int platform_switch_voice_call_device_post(void *platform,
89                                            snd_device_t out_snd_device,
90                                            snd_device_t in_snd_device);
91 int platform_switch_voice_call_usecase_route_post(void *platform,
92                                                   snd_device_t out_snd_device,
93                                                   snd_device_t in_snd_device);
94 int platform_start_voice_call(void *platform, uint32_t vsid);
95 int platform_stop_voice_call(void *platform, uint32_t vsid);
96 int platform_set_mic_break_det(void *platform, bool enable);
97 int platform_set_voice_volume(void *platform, int volume);
98 void platform_set_speaker_gain_in_combo(struct audio_device *adev,
99                                         snd_device_t snd_device,
100                                         bool enable);
101 int platform_set_mic_mute(void *platform, bool state);
102 int platform_get_sample_rate(void *platform, uint32_t *rate);
103 int platform_set_device_mute(void *platform, bool state, char *dir);
104 snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices);
105 snd_device_t platform_get_input_snd_device(void *platform,
106                                            struct stream_in *in,
107                                            audio_devices_t out_device);
108 int platform_set_hdmi_channels(void *platform, int channel_count);
109 int platform_edid_get_max_channels(void *platform);
110 void platform_add_operator_specific_device(snd_device_t snd_device,
111                                            const char *operator,
112                                            const char *mixer_path,
113                                            unsigned int acdb_id);
114 void platform_add_external_specific_device(snd_device_t snd_device,
115                                            const char *name,
116                                            unsigned int acdb_id);
117 /* return true if adding entry success
118    return false if adding entry fails */
119 
120 bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry);
121 
122 /* return 0 if no custome mapping table found or when error detected
123             use default mapping in this case
124    return > 0 indicates number of entries in mapping table */
125 
126 int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
127                                     int table_size);
128 
129 /* returns the latency for a usecase in Us */
130 int64_t platform_render_latency(audio_usecase_t usecase);
131 
132 int platform_set_incall_recording_session_id(void *platform,
133                                              uint32_t session_id, int rec_mode);
134 int platform_set_incall_recording_session_channels(void *platform,
135                                                    uint32_t session_channels);
136 int platform_stop_incall_recording_usecase(void *platform);
137 int platform_start_incall_music_usecase(void *platform);
138 int platform_stop_incall_music_usecase(void *platform);
139 
140 int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend,
141                                     const char * hw_interface);
142 
143 bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id);
144 
145 typedef int (*set_parameters_fn)(void *platform, struct str_parms *parms);
146 
147 /* From platform_info.c */
148 int platform_info_init(const char *filename, void *,
149                        bool do_full_parse, set_parameters_fn);
150 
151 int platform_get_usecase_index(const char * usecase);
152 int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id);
153 void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device);
154 int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels);
155 int platform_set_swap_channels(struct audio_device *adev, bool swap_channels);
156 
157 int platform_can_split_snd_device(snd_device_t in_snd_device,
158                                   int *num_devices,
159                                   snd_device_t *out_snd_devices);
160 
161 bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2);
162 
163 int platform_set_parameters(void *platform, struct str_parms *parms);
164 
165 bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
166                    struct audio_usecase *usecase, snd_device_t snd_device);
167 
168 bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
169                    struct audio_usecase *usecase, snd_device_t snd_device);
170 
171 int platform_snd_card_update(void *platform, enum card_status_t status);
172 void platform_check_and_update_copp_sample_rate(void *platform, snd_device_t snd_device,
173      unsigned int stream_sr,int *sample_rate);
174 int platform_get_snd_device_backend_index(snd_device_t snd_device);
175 bool platform_supports_app_type_cfg();
176 int platform_get_app_type_v2(void *platform,
177                              enum usecase_type_t type,
178                              const char *mode,
179                              int bw, int sr, int *app_type);
180 void platform_add_app_type(const char *uc_type,
181                            const char *mode,
182                            int bw, int app_type, int max_sr);
183 int platform_get_snd_device_backend_index(snd_device_t snd_device);
184 int platform_set_sidetone(struct audio_device *adev,
185                           snd_device_t out_snd_device,
186                           bool enable, char * str);
187 int platform_get_mmap_data_fd(void *platform, int dev, int dir,
188                               int *fd, uint32_t *size);
189 bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id);
190 bool platform_snd_device_has_speaker(snd_device_t dev);
191 
192 bool platform_set_microphone_characteristic(void *platform,
193                                             struct audio_microphone_characteristic_t mic);
194 bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device,
195                                  const struct mic_info *info);
196 int platform_get_microphones(void *platform,
197                              struct audio_microphone_characteristic_t *mic_array,
198                              size_t *mic_count);
199 int platform_get_active_microphones(void *platform, unsigned int channels,
200                                     audio_usecase_t usecase,
201                                     struct audio_microphone_characteristic_t *mic_array,
202                                     size_t *mic_count);
203 int platform_set_usb_service_interval(void *platform,
204                                       bool playback,
205                                       unsigned long service_interval,
206                                       bool *reconfig);
207 int platform_get_usb_service_interval(void *platform,
208                                       bool playback,
209                                       unsigned long *service_interval);
210 int platform_get_haptics_pcm_device_id();
211 
212 /* callback functions from platform to common audio HAL */
213 struct stream_in *adev_get_active_input(const struct audio_device *adev);
214 
215 #endif // AUDIO_PLATFORM_API_H
216