Dhananjay Kumar | daf6ebb | 2013-10-07 11:38:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 3 | * Not a contribution. |
| 4 | * |
| 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #ifndef QCOM_AUDIO_HW_H |
| 21 | #define QCOM_AUDIO_HW_H |
| 22 | |
| 23 | #include <cutils/list.h> |
| 24 | #include <hardware/audio.h> |
| 25 | #include <tinyalsa/asoundlib.h> |
| 26 | #include <tinycompress/tinycompress.h> |
| 27 | |
| 28 | #include <audio_route/audio_route.h> |
| 29 | |
| 30 | #define VISUALIZER_LIBRARY_PATH "/system/lib/soundfx/libqcomvisualizer.so" |
| 31 | |
| 32 | /* Flags used to initialize acdb_settings variable that goes to ACDB library */ |
| 33 | #define DMIC_FLAG 0x00000002 |
| 34 | #define QMIC_FLAG 0x00000004 |
| 35 | #define TTY_MODE_OFF 0x00000010 |
| 36 | #define TTY_MODE_FULL 0x00000020 |
| 37 | #define TTY_MODE_VCO 0x00000040 |
| 38 | #define TTY_MODE_HCO 0x00000080 |
| 39 | #define TTY_MODE_CLEAR 0xFFFFFF0F |
| 40 | |
| 41 | #define ACDB_DEV_TYPE_OUT 1 |
| 42 | #define ACDB_DEV_TYPE_IN 2 |
| 43 | |
| 44 | #define MAX_SUPPORTED_CHANNEL_MASKS 2 |
| 45 | #define DEFAULT_HDMI_OUT_CHANNELS 2 |
| 46 | |
| 47 | typedef int snd_device_t; |
| 48 | |
| 49 | /* These are the supported use cases by the hardware. |
| 50 | * Each usecase is mapped to a specific PCM device. |
| 51 | * Refer to pcm_device_table[]. |
| 52 | */ |
| 53 | typedef enum { |
| 54 | USECASE_INVALID = -1, |
| 55 | /* Playback usecases */ |
| 56 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0, |
| 57 | USECASE_AUDIO_PLAYBACK_LOW_LATENCY, |
| 58 | USECASE_AUDIO_PLAYBACK_MULTI_CH, |
| 59 | USECASE_AUDIO_PLAYBACK_OFFLOAD, |
| 60 | |
| 61 | /* FM usecase */ |
| 62 | USECASE_AUDIO_PLAYBACK_FM, |
| 63 | |
| 64 | /* Capture usecases */ |
| 65 | USECASE_AUDIO_RECORD, |
| 66 | USECASE_AUDIO_RECORD_COMPRESS, |
| 67 | USECASE_AUDIO_RECORD_LOW_LATENCY, |
| 68 | USECASE_AUDIO_RECORD_FM_VIRTUAL, |
| 69 | |
| 70 | /* Voice usecase */ |
| 71 | USECASE_VOICE_CALL, |
| 72 | |
| 73 | /* Voice extension usecases */ |
| 74 | USECASE_VOICE2_CALL, |
| 75 | USECASE_VOLTE_CALL, |
| 76 | USECASE_QCHAT_CALL, |
| 77 | USECASE_COMPRESS_VOIP_CALL, |
| 78 | |
| 79 | USECASE_INCALL_REC_UPLINK, |
| 80 | USECASE_INCALL_REC_DOWNLINK, |
| 81 | USECASE_INCALL_REC_UPLINK_AND_DOWNLINK, |
| 82 | |
| 83 | USECASE_INCALL_MUSIC_UPLINK, |
| 84 | USECASE_INCALL_MUSIC_UPLINK2, |
| 85 | |
| 86 | USECASE_AUDIO_SPKR_CALIB_RX, |
| 87 | USECASE_AUDIO_SPKR_CALIB_TX, |
| 88 | AUDIO_USECASE_MAX |
| 89 | } audio_usecase_t; |
| 90 | |
| 91 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 92 | |
| 93 | /* |
| 94 | * tinyAlsa library interprets period size as number of frames |
| 95 | * one frame = channel_count * sizeof (pcm sample) |
| 96 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes |
| 97 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes |
| 98 | * We should take care of returning proper size when AudioFlinger queries for |
| 99 | * the buffer size of an input/output stream |
| 100 | */ |
| 101 | |
| 102 | enum { |
| 103 | OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/ |
| 104 | OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */ |
| 105 | OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */ |
| 106 | OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */ |
| 107 | }; |
| 108 | |
| 109 | enum { |
| 110 | OFFLOAD_STATE_IDLE, |
| 111 | OFFLOAD_STATE_PLAYING, |
| 112 | OFFLOAD_STATE_PAUSED, |
| 113 | }; |
| 114 | |
| 115 | struct offload_cmd { |
| 116 | struct listnode node; |
| 117 | int cmd; |
| 118 | int data[]; |
| 119 | }; |
| 120 | |
| 121 | struct stream_out { |
| 122 | struct audio_stream_out stream; |
| 123 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 124 | pthread_cond_t cond; |
| 125 | struct pcm_config config; |
| 126 | struct compr_config compr_config; |
| 127 | struct pcm *pcm; |
| 128 | struct compress *compr; |
| 129 | int standby; |
| 130 | int pcm_device_id; |
| 131 | unsigned int sample_rate; |
| 132 | audio_channel_mask_t channel_mask; |
| 133 | audio_format_t format; |
| 134 | audio_devices_t devices; |
| 135 | audio_output_flags_t flags; |
| 136 | audio_usecase_t usecase; |
| 137 | /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */ |
| 138 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; |
| 139 | bool muted; |
| 140 | uint64_t written; /* total frames written, not cleared when entering standby */ |
| 141 | audio_io_handle_t handle; |
| 142 | |
| 143 | int non_blocking; |
| 144 | int playback_started; |
| 145 | int offload_state; |
| 146 | pthread_cond_t offload_cond; |
| 147 | pthread_t offload_thread; |
| 148 | struct listnode offload_cmd_list; |
| 149 | bool offload_thread_blocked; |
| 150 | |
| 151 | stream_callback_t offload_callback; |
| 152 | void *offload_cookie; |
| 153 | struct compr_gapless_mdata gapless_mdata; |
| 154 | int send_new_metadata; |
| 155 | |
| 156 | struct audio_device *dev; |
| 157 | }; |
| 158 | |
| 159 | struct stream_in { |
| 160 | struct audio_stream_in stream; |
| 161 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 162 | struct pcm_config config; |
| 163 | struct pcm *pcm; |
| 164 | int standby; |
| 165 | int source; |
| 166 | int pcm_device_id; |
| 167 | int device; |
| 168 | audio_channel_mask_t channel_mask; |
| 169 | audio_usecase_t usecase; |
| 170 | bool enable_aec; |
| 171 | bool enable_ns; |
| 172 | audio_format_t format; |
| 173 | |
| 174 | struct audio_device *dev; |
| 175 | }; |
| 176 | |
| 177 | typedef enum { |
| 178 | PCM_PLAYBACK, |
| 179 | PCM_CAPTURE, |
| 180 | VOICE_CALL, |
| 181 | VOIP_CALL |
| 182 | } usecase_type_t; |
| 183 | |
| 184 | union stream_ptr { |
| 185 | struct stream_in *in; |
| 186 | struct stream_out *out; |
| 187 | }; |
| 188 | |
| 189 | struct audio_usecase { |
| 190 | struct listnode list; |
| 191 | audio_usecase_t id; |
| 192 | usecase_type_t type; |
| 193 | audio_devices_t devices; |
| 194 | snd_device_t out_snd_device; |
| 195 | snd_device_t in_snd_device; |
| 196 | union stream_ptr stream; |
| 197 | }; |
| 198 | |
| 199 | struct audio_device { |
| 200 | struct audio_hw_device device; |
| 201 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 202 | struct mixer *mixer; |
| 203 | audio_mode_t mode; |
| 204 | audio_devices_t out_device; |
| 205 | struct stream_in *active_input; |
| 206 | struct stream_out *primary_output; |
| 207 | bool bluetooth_nrec; |
| 208 | bool screen_off; |
| 209 | int *snd_dev_ref_cnt; |
| 210 | struct listnode usecase_list; |
| 211 | struct audio_route *audio_route; |
| 212 | int acdb_settings; |
| 213 | bool speaker_lr_swap; |
| 214 | unsigned int cur_hdmi_channels; |
| 215 | |
| 216 | void *platform; |
| 217 | |
| 218 | void *visualizer_lib; |
| 219 | int (*visualizer_start_output)(audio_io_handle_t); |
| 220 | int (*visualizer_stop_output)(audio_io_handle_t); |
| 221 | }; |
| 222 | |
Dhananjay Kumar | 01e921a | 2013-11-26 23:33:22 +0530 | [diff] [blame] | 223 | static const char * const use_case_table[AUDIO_USECASE_MAX] = { |
| 224 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback", |
| 225 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback", |
| 226 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback", |
| 227 | [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback", |
| 228 | [USECASE_AUDIO_RECORD] = "audio-record", |
| 229 | [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress", |
| 230 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record", |
| 231 | [USECASE_AUDIO_RECORD_FM_VIRTUAL] = "fm-virtual-record", |
| 232 | [USECASE_AUDIO_PLAYBACK_FM] = "play-fm", |
| 233 | [USECASE_VOICE_CALL] = "voice-call", |
| 234 | |
| 235 | [USECASE_VOICE2_CALL] = "voice2-call", |
| 236 | [USECASE_VOLTE_CALL] = "volte-call", |
| 237 | [USECASE_QCHAT_CALL] = "qchat-call", |
| 238 | [USECASE_COMPRESS_VOIP_CALL] = "compress-voip-call", |
| 239 | [USECASE_INCALL_REC_UPLINK] = "incall-rec-uplink", |
| 240 | [USECASE_INCALL_REC_DOWNLINK] = "incall-rec-downlink", |
| 241 | [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = "incall-rec-uplink-and-downlink", |
| 242 | [USECASE_INCALL_MUSIC_UPLINK] = "incall_music_uplink", |
| 243 | [USECASE_INCALL_MUSIC_UPLINK2] = "incall_music_uplink2", |
| 244 | [USECASE_AUDIO_SPKR_CALIB_RX] = "spkr-rx-calib", |
| 245 | [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record", |
| 246 | }; |
| 247 | |
| 248 | int adev_open_output_stream(struct audio_hw_device *dev, |
| 249 | audio_io_handle_t handle, |
| 250 | audio_devices_t devices, |
| 251 | audio_output_flags_t flags, |
| 252 | struct audio_config *config, |
| 253 | struct audio_stream_out **stream_out); |
| 254 | |
| 255 | void adev_close_output_stream(struct audio_hw_device *dev, |
| 256 | struct audio_stream_out *stream); |
| 257 | |
Dhananjay Kumar | daf6ebb | 2013-10-07 11:38:46 -0700 | [diff] [blame] | 258 | int select_devices(struct audio_device *adev, |
| 259 | audio_usecase_t uc_id); |
| 260 | int disable_audio_route(struct audio_device *adev, |
| 261 | struct audio_usecase *usecase, |
| 262 | bool update_mixer); |
| 263 | int disable_snd_device(struct audio_device *adev, |
| 264 | snd_device_t snd_device, |
| 265 | bool update_mixer); |
| 266 | int enable_snd_device(struct audio_device *adev, |
| 267 | snd_device_t snd_device, |
| 268 | bool update_mixer); |
| 269 | int enable_audio_route(struct audio_device *adev, |
| 270 | struct audio_usecase *usecase, |
| 271 | bool update_mixer); |
| 272 | struct audio_usecase *get_usecase_from_list(struct audio_device *adev, |
| 273 | audio_usecase_t uc_id); |
| 274 | /* |
| 275 | * NOTE: when multiple mutexes have to be acquired, always take the |
| 276 | * stream_in or stream_out mutex first, followed by the audio_device mutex. |
| 277 | */ |
| 278 | |
| 279 | #endif // QCOM_AUDIO_HW_H |