Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
Christopher N. Hesse | 2f6f858 | 2017-01-28 12:46:15 +0100 | [diff] [blame] | 3 | * Copyright (C) 2017 Christopher N. Hesse <raymanfx@gmail.com> |
stenkinevgeniy | 4433536 | 2018-05-07 18:00:13 +0000 | [diff] [blame] | 4 | * Copyright (C) 2018 The LineageOS Project |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
Christopher N. Hesse | 0612a4e | 2017-01-28 14:05:39 +0100 | [diff] [blame] | 19 | #ifndef SAMSUNG_AUDIO_HW_H |
| 20 | #define SAMSUNG_AUDIO_HW_H |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 21 | |
| 22 | #include <cutils/list.h> |
| 23 | #include <hardware/audio.h> |
Christopher N. Hesse | 6a2a307 | 2017-08-04 21:17:55 +0200 | [diff] [blame] | 24 | #include <hardware/audio_amplifier.h> |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 25 | |
| 26 | #include <tinyalsa/asoundlib.h> |
| 27 | #include <tinycompress/tinycompress.h> |
| 28 | /* TODO: remove resampler if possible when AudioFlinger supports downsampling from 48 to 8 */ |
| 29 | #include <audio_utils/resampler.h> |
| 30 | #include <audio_route/audio_route.h> |
| 31 | |
| 32 | /* Retry for delay in FW loading*/ |
| 33 | #define RETRY_NUMBER 10 |
| 34 | #define RETRY_US 500000 |
| 35 | |
| 36 | #ifdef __LP64__ |
| 37 | #define OFFLOAD_FX_LIBRARY_PATH "/system/lib64/soundfx/libnvvisualizer.so" |
| 38 | #else |
| 39 | #define OFFLOAD_FX_LIBRARY_PATH "/system/lib/soundfx/libnvvisualizer.so" |
| 40 | #endif |
| 41 | |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 42 | #ifdef PREPROCESSING_ENABLED |
| 43 | #include <audio_utils/echo_reference.h> |
| 44 | #define MAX_PREPROCESSORS 3 |
| 45 | struct effect_info_s { |
| 46 | effect_handle_t effect_itfe; |
| 47 | size_t num_channel_configs; |
| 48 | channel_config_t *channel_configs; |
| 49 | }; |
| 50 | #endif |
| 51 | |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 52 | /* Sound devices specific to the platform |
| 53 | * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound |
| 54 | * devices to enable corresponding mixer paths |
| 55 | */ |
| 56 | enum { |
| 57 | SND_DEVICE_NONE = 0, |
| 58 | |
| 59 | /* Playback devices */ |
| 60 | SND_DEVICE_MIN, |
| 61 | SND_DEVICE_OUT_BEGIN = SND_DEVICE_MIN, |
Christopher N. Hesse | 530cf0d | 2017-01-31 21:59:54 +0100 | [diff] [blame] | 62 | SND_DEVICE_OUT_EARPIECE = SND_DEVICE_OUT_BEGIN, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 63 | SND_DEVICE_OUT_SPEAKER, |
| 64 | SND_DEVICE_OUT_HEADPHONES, |
| 65 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, |
Christopher N. Hesse | 530cf0d | 2017-01-31 21:59:54 +0100 | [diff] [blame] | 66 | SND_DEVICE_OUT_VOICE_EARPIECE, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 67 | SND_DEVICE_OUT_VOICE_EARPIECE_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 68 | SND_DEVICE_OUT_VOICE_SPEAKER, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 69 | SND_DEVICE_OUT_VOICE_SPEAKER_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 70 | SND_DEVICE_OUT_VOICE_HEADPHONES, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 71 | SND_DEVICE_OUT_VOICE_HEADPHONES_WB, |
Christopher N. Hesse | 56caa26 | 2017-03-20 19:40:53 +0100 | [diff] [blame] | 72 | SND_DEVICE_OUT_VOICE_BT_SCO, |
| 73 | SND_DEVICE_OUT_VOICE_BT_SCO_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 74 | SND_DEVICE_OUT_HDMI, |
| 75 | SND_DEVICE_OUT_SPEAKER_AND_HDMI, |
| 76 | SND_DEVICE_OUT_BT_SCO, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 77 | SND_DEVICE_OUT_END, |
| 78 | |
| 79 | /* |
| 80 | * Note: IN_BEGIN should be same as OUT_END because total number of devices |
| 81 | * SND_DEVICES_MAX should not exceed MAX_RX + MAX_TX devices. |
| 82 | */ |
| 83 | /* Capture devices */ |
| 84 | SND_DEVICE_IN_BEGIN = SND_DEVICE_OUT_END, |
Christopher N. Hesse | 530cf0d | 2017-01-31 21:59:54 +0100 | [diff] [blame] | 85 | SND_DEVICE_IN_EARPIECE_MIC = SND_DEVICE_IN_BEGIN, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 86 | SND_DEVICE_IN_SPEAKER_MIC, |
| 87 | SND_DEVICE_IN_HEADSET_MIC, |
Christopher N. Hesse | 530cf0d | 2017-01-31 21:59:54 +0100 | [diff] [blame] | 88 | SND_DEVICE_IN_EARPIECE_MIC_AEC, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 89 | SND_DEVICE_IN_SPEAKER_MIC_AEC, |
| 90 | SND_DEVICE_IN_HEADSET_MIC_AEC, |
Andreas Schneider | 82f3248 | 2017-02-06 09:00:48 +0100 | [diff] [blame] | 91 | SND_DEVICE_IN_VOICE_MIC, |
| 92 | SND_DEVICE_IN_VOICE_EARPIECE_MIC, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 93 | SND_DEVICE_IN_VOICE_EARPIECE_MIC_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 94 | SND_DEVICE_IN_VOICE_SPEAKER_MIC, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 95 | SND_DEVICE_IN_VOICE_SPEAKER_MIC_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 96 | SND_DEVICE_IN_VOICE_HEADSET_MIC, |
Andreas Schneider | 59486fa | 2017-02-06 09:16:39 +0100 | [diff] [blame] | 97 | SND_DEVICE_IN_VOICE_HEADSET_MIC_WB, |
Christopher N. Hesse | 56caa26 | 2017-03-20 19:40:53 +0100 | [diff] [blame] | 98 | SND_DEVICE_IN_VOICE_BT_SCO_MIC, |
| 99 | SND_DEVICE_IN_VOICE_BT_SCO_MIC_WB, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 100 | SND_DEVICE_IN_HDMI_MIC, |
| 101 | SND_DEVICE_IN_BT_SCO_MIC, |
| 102 | SND_DEVICE_IN_CAMCORDER_MIC, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 103 | SND_DEVICE_IN_VOICE_REC_HEADSET_MIC, |
| 104 | SND_DEVICE_IN_VOICE_REC_MIC, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 105 | SND_DEVICE_IN_END, |
| 106 | |
| 107 | SND_DEVICE_MAX = SND_DEVICE_IN_END, |
| 108 | |
| 109 | }; |
| 110 | |
| 111 | |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 112 | /* |
| 113 | * tinyAlsa library interprets period size as number of frames |
| 114 | * one frame = channel_count * sizeof (pcm sample) |
| 115 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes |
| 116 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes |
| 117 | * We should take care of returning proper size when AudioFlinger queries for |
| 118 | * the buffer size of an input/output stream |
| 119 | */ |
| 120 | #define PLAYBACK_PERIOD_SIZE 256 |
| 121 | #define PLAYBACK_PERIOD_COUNT 2 |
| 122 | #define PLAYBACK_DEFAULT_CHANNEL_COUNT 2 |
| 123 | #define PLAYBACK_DEFAULT_SAMPLING_RATE 48000 |
| 124 | #define PLAYBACK_START_THRESHOLD(size, count) (((size) * (count)) - 1) |
| 125 | #define PLAYBACK_STOP_THRESHOLD(size, count) ((size) * ((count) + 2)) |
| 126 | #define PLAYBACK_AVAILABLE_MIN 1 |
| 127 | |
| 128 | |
| 129 | #define SCO_PERIOD_SIZE 168 |
| 130 | #define SCO_PERIOD_COUNT 2 |
| 131 | #define SCO_DEFAULT_CHANNEL_COUNT 2 |
| 132 | #define SCO_DEFAULT_SAMPLING_RATE 8000 |
Fevax | 51bd12c | 2017-03-15 10:56:39 -0300 | [diff] [blame] | 133 | #define SCO_WB_SAMPLING_RATE 16000 |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 134 | #define SCO_START_THRESHOLD 335 |
| 135 | #define SCO_STOP_THRESHOLD 336 |
| 136 | #define SCO_AVAILABLE_MIN 1 |
| 137 | |
| 138 | #define PLAYBACK_HDMI_MULTI_PERIOD_SIZE 1024 |
| 139 | #define PLAYBACK_HDMI_MULTI_PERIOD_COUNT 4 |
| 140 | #define PLAYBACK_HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6 |
| 141 | #define PLAYBACK_HDMI_MULTI_PERIOD_BYTES \ |
| 142 | (PLAYBACK_HDMI_MULTI_PERIOD_SIZE * PLAYBACK_HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2) |
| 143 | #define PLAYBACK_HDMI_MULTI_START_THRESHOLD 4095 |
| 144 | #define PLAYBACK_HDMI_MULTI_STOP_THRESHOLD 4096 |
| 145 | #define PLAYBACK_HDMI_MULTI_AVAILABLE_MIN 1 |
| 146 | |
| 147 | #define PLAYBACK_HDMI_DEFAULT_CHANNEL_COUNT 2 |
| 148 | |
| 149 | #define CAPTURE_PERIOD_SIZE 1024 |
| 150 | #define CAPTURE_PERIOD_SIZE_LOW_LATENCY 256 |
| 151 | #define CAPTURE_PERIOD_COUNT 2 |
| 152 | #define CAPTURE_PERIOD_COUNT_LOW_LATENCY 2 |
| 153 | #define CAPTURE_DEFAULT_CHANNEL_COUNT 2 |
| 154 | #define CAPTURE_DEFAULT_SAMPLING_RATE 48000 |
| 155 | #define CAPTURE_START_THRESHOLD 1 |
| 156 | |
| 157 | #define COMPRESS_CARD 0 |
| 158 | #define COMPRESS_DEVICE 5 |
| 159 | #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024) |
| 160 | #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4 |
| 161 | /* ToDo: Check and update a proper value in msec */ |
| 162 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96 |
| 163 | #define COMPRESS_PLAYBACK_VOLUME_MAX 0x10000 //NV suggested value |
| 164 | |
| 165 | #define DEEP_BUFFER_OUTPUT_SAMPLING_RATE 48000 |
| 166 | #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 480 |
| 167 | #define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 8 |
| 168 | |
| 169 | #define MAX_SUPPORTED_CHANNEL_MASKS 2 |
| 170 | |
| 171 | typedef int snd_device_t; |
| 172 | |
| 173 | /* These are the supported use cases by the hardware. |
| 174 | * Each usecase is mapped to a specific PCM device. |
| 175 | * Refer to pcm_device_table[]. |
| 176 | */ |
| 177 | typedef enum { |
| 178 | USECASE_INVALID = -1, |
| 179 | /* Playback usecases */ |
| 180 | USECASE_AUDIO_PLAYBACK = 0, |
| 181 | USECASE_AUDIO_PLAYBACK_MULTI_CH, |
| 182 | USECASE_AUDIO_PLAYBACK_OFFLOAD, |
| 183 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER, |
| 184 | |
| 185 | /* Capture usecases */ |
| 186 | USECASE_AUDIO_CAPTURE, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 187 | |
| 188 | USECASE_VOICE_CALL, |
| 189 | AUDIO_USECASE_MAX |
| 190 | } audio_usecase_t; |
| 191 | |
| 192 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 193 | |
| 194 | /* |
| 195 | * tinyAlsa library interprets period size as number of frames |
| 196 | * one frame = channel_count * sizeof (pcm sample) |
| 197 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes |
| 198 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes |
| 199 | * We should take care of returning proper size when AudioFlinger queries for |
| 200 | * the buffer size of an input/output stream |
| 201 | */ |
| 202 | |
| 203 | enum { |
| 204 | OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/ |
| 205 | OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */ |
| 206 | OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */ |
| 207 | OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */ |
| 208 | }; |
| 209 | |
| 210 | enum { |
| 211 | OFFLOAD_STATE_IDLE, |
| 212 | OFFLOAD_STATE_PLAYING, |
| 213 | OFFLOAD_STATE_PAUSED, |
| 214 | OFFLOAD_STATE_PAUSED_FLUSHED, |
| 215 | }; |
| 216 | |
| 217 | typedef enum { |
| 218 | PCM_PLAYBACK = 0x1, |
| 219 | PCM_CAPTURE = 0x2, |
| 220 | VOICE_CALL = 0x4, |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 221 | PCM_CAPTURE_LOW_LATENCY = 0x10, |
| 222 | } usecase_type_t; |
| 223 | |
| 224 | struct offload_cmd { |
| 225 | struct listnode node; |
| 226 | int cmd; |
| 227 | int data[]; |
| 228 | }; |
| 229 | |
| 230 | struct pcm_device_profile { |
| 231 | struct pcm_config config; |
| 232 | int card; |
| 233 | int id; |
| 234 | usecase_type_t type; |
| 235 | audio_devices_t devices; |
| 236 | }; |
| 237 | |
| 238 | struct pcm_device { |
| 239 | struct listnode stream_list_node; |
| 240 | struct pcm_device_profile* pcm_profile; |
| 241 | struct pcm* pcm; |
| 242 | int status; |
| 243 | /* TODO: remove resampler if possible when AudioFlinger supports downsampling from 48 to 8 */ |
| 244 | struct resampler_itfe* resampler; |
| 245 | int16_t* res_buffer; |
| 246 | size_t res_byte_count; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | struct stream_out { |
| 250 | struct audio_stream_out stream; |
| 251 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 252 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ |
| 253 | pthread_cond_t cond; |
| 254 | struct pcm_config config; |
| 255 | struct listnode pcm_dev_list; |
| 256 | struct compr_config compr_config; |
| 257 | struct compress* compr; |
| 258 | int standby; |
| 259 | unsigned int sample_rate; |
| 260 | audio_channel_mask_t channel_mask; |
| 261 | audio_format_t format; |
| 262 | audio_devices_t devices; |
| 263 | audio_output_flags_t flags; |
| 264 | audio_usecase_t usecase; |
| 265 | /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */ |
| 266 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; |
| 267 | bool muted; |
| 268 | /* total frames written, not cleared when entering standby */ |
| 269 | uint64_t written; |
| 270 | audio_io_handle_t handle; |
| 271 | |
| 272 | int non_blocking; |
| 273 | int offload_state; |
| 274 | pthread_cond_t offload_cond; |
| 275 | pthread_t offload_thread; |
| 276 | struct listnode offload_cmd_list; |
| 277 | bool offload_thread_blocked; |
| 278 | |
| 279 | stream_callback_t offload_callback; |
| 280 | void* offload_cookie; |
| 281 | struct compr_gapless_mdata gapless_mdata; |
| 282 | int send_new_metadata; |
| 283 | |
| 284 | struct audio_device* dev; |
| 285 | |
| 286 | #ifdef PREPROCESSING_ENABLED |
| 287 | struct echo_reference_itfe *echo_reference; |
| 288 | // echo_reference_generation indicates if the echo reference used by the output stream is |
| 289 | // in sync with the one known by the audio_device. When different from the generation stored |
| 290 | // in the audio_device the output stream must release the echo reference. |
| 291 | // always modified with audio device and stream mutex locked. |
| 292 | int32_t echo_reference_generation; |
| 293 | #endif |
| 294 | |
| 295 | bool is_fastmixer_affinity_set; |
Christopher N. Hesse | e6b3a3e | 2017-01-08 00:03:23 +0100 | [diff] [blame] | 296 | |
| 297 | int64_t last_write_time_us; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | struct stream_in { |
| 301 | struct audio_stream_in stream; |
| 302 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 303 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by |
| 304 | capture thread */ |
| 305 | struct pcm_config config; |
| 306 | struct listnode pcm_dev_list; |
| 307 | int standby; |
| 308 | audio_source_t source; |
| 309 | audio_devices_t devices; |
| 310 | uint32_t main_channels; |
| 311 | audio_usecase_t usecase; |
| 312 | usecase_type_t usecase_type; |
| 313 | bool enable_aec; |
| 314 | audio_input_flags_t input_flags; |
| 315 | |
| 316 | /* TODO: remove resampler if possible when AudioFlinger supports downsampling from 48 to 8 */ |
| 317 | unsigned int requested_rate; |
| 318 | struct resampler_itfe* resampler; |
| 319 | struct resampler_buffer_provider buf_provider; |
| 320 | int read_status; |
| 321 | int16_t* read_buf; |
| 322 | size_t read_buf_size; |
| 323 | size_t read_buf_frames; |
| 324 | |
| 325 | int16_t *proc_buf_in; |
| 326 | int16_t *proc_buf_out; |
| 327 | size_t proc_buf_size; |
| 328 | size_t proc_buf_frames; |
| 329 | |
| 330 | #ifdef PREPROCESSING_ENABLED |
| 331 | struct echo_reference_itfe *echo_reference; |
| 332 | int16_t *ref_buf; |
| 333 | size_t ref_buf_size; |
| 334 | size_t ref_buf_frames; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 335 | int num_preprocessors; |
| 336 | struct effect_info_s preprocessors[MAX_PREPROCESSORS]; |
| 337 | |
| 338 | bool aux_channels_changed; |
| 339 | uint32_t aux_channels; |
| 340 | #endif |
| 341 | |
| 342 | struct audio_device* dev; |
| 343 | bool is_fastcapture_affinity_set; |
Christopher N. Hesse | e6b3a3e | 2017-01-08 00:03:23 +0100 | [diff] [blame] | 344 | |
| 345 | int64_t last_read_time_us; |
Christopher N. Hesse | ce6d5af | 2017-01-12 11:40:30 +0100 | [diff] [blame] | 346 | int64_t frames_read; /* total frames read, not cleared when |
| 347 | entering standby */ |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | struct mixer_card { |
| 351 | struct listnode adev_list_node; |
| 352 | struct listnode uc_list_node[AUDIO_USECASE_MAX]; |
| 353 | int card; |
| 354 | struct mixer* mixer; |
| 355 | struct audio_route* audio_route; |
Andreas Schneider | 759368f | 2017-02-02 16:11:14 +0100 | [diff] [blame] | 356 | struct timespec dsp_poweroff_time; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | struct audio_usecase { |
| 360 | struct listnode adev_list_node; |
| 361 | audio_usecase_t id; |
| 362 | usecase_type_t type; |
| 363 | audio_devices_t devices; |
| 364 | snd_device_t out_snd_device; |
| 365 | snd_device_t in_snd_device; |
| 366 | struct audio_stream* stream; |
| 367 | struct listnode mixer_list; |
| 368 | }; |
| 369 | |
Andreas Schneider | 74ef3a1 | 2017-02-02 18:29:12 +0100 | [diff] [blame] | 370 | struct voice_data { |
| 371 | bool in_call; |
| 372 | float volume; |
| 373 | bool bluetooth_nrec; |
Andreas Schneider | 05bc188 | 2017-02-09 14:03:11 +0100 | [diff] [blame] | 374 | bool bluetooth_wb; |
Christopher N. Hesse | 41c9f3d | 2017-02-02 20:48:56 +0100 | [diff] [blame] | 375 | void *session; |
Andreas Schneider | 74ef3a1 | 2017-02-02 18:29:12 +0100 | [diff] [blame] | 376 | }; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 377 | |
| 378 | struct audio_device { |
| 379 | struct audio_hw_device device; |
| 380 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 381 | struct listnode mixer_list; |
| 382 | audio_mode_t mode; |
| 383 | struct stream_in* active_input; |
| 384 | struct stream_out* primary_output; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 385 | bool mic_mute; |
Andreas Schneider | ecd17ce | 2017-02-09 10:45:21 +0100 | [diff] [blame] | 386 | bool screen_off; |
Andreas Schneider | 74ef3a1 | 2017-02-02 18:29:12 +0100 | [diff] [blame] | 387 | |
| 388 | struct voice_data voice; |
| 389 | |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 390 | int* snd_dev_ref_cnt; |
| 391 | struct listnode usecase_list; |
| 392 | bool speaker_lr_swap; |
| 393 | unsigned int cur_hdmi_channels; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 394 | bool ns_in_voice_rec; |
| 395 | |
| 396 | void* offload_fx_lib; |
| 397 | int (*offload_fx_start_output)(audio_io_handle_t); |
| 398 | int (*offload_fx_stop_output)(audio_io_handle_t); |
| 399 | |
| 400 | #ifdef PREPROCESSING_ENABLED |
| 401 | struct echo_reference_itfe* echo_reference; |
| 402 | // echo_reference_generation indicates if the echo reference used by the output stream is |
| 403 | // in sync with the one known by the audio_device. |
| 404 | // incremented atomically with a memory barrier and audio device mutex locked but WITHOUT |
| 405 | // stream mutex locked: the stream will load it atomically with a barrier and re-read it |
| 406 | // with audio device mutex if needed |
| 407 | volatile int32_t echo_reference_generation; |
| 408 | #endif |
| 409 | |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 410 | pthread_mutex_t lock_inputs; /* see note below on mutex acquisition order */ |
Christopher N. Hesse | 6a2a307 | 2017-08-04 21:17:55 +0200 | [diff] [blame] | 411 | amplifier_device_t *amp; |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | /* |
| 415 | * NOTE: when multiple mutexes have to be acquired, always take the |
Christopher N. Hesse | 2f6f858 | 2017-01-28 12:46:15 +0100 | [diff] [blame] | 416 | * lock_inputs, stream_in, stream_out, then audio_device mutex. |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 417 | * stream_in mutex must always be before stream_out mutex |
Christopher N. Hesse | 297a636 | 2017-01-28 12:40:45 +0100 | [diff] [blame] | 418 | * lock_inputs must be held in order to either close the input stream, or prevent closure. |
| 419 | */ |
| 420 | |
Christopher N. Hesse | 0612a4e | 2017-01-28 14:05:39 +0100 | [diff] [blame] | 421 | #endif // SAMSUNG_AUDIO_HW_H |