Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
Susan Wang | 6dd1309 | 2021-01-25 10:27:11 -0500 | [diff] [blame] | 2 | * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved. |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3 | * Not a contribution. |
| 4 | * |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 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. |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 18 | * |
| 19 | * This file was modified by DTS, Inc. The portions of the |
| 20 | * code modified by DTS, Inc are copyrighted and |
| 21 | * licensed separately, as follows: |
| 22 | * |
| 23 | * (C) 2014 DTS, Inc. |
| 24 | * |
| 25 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 26 | * you may not use this file except in compliance with the License. |
| 27 | * You may obtain a copy of the License at |
| 28 | * |
| 29 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 30 | * |
| 31 | * Unless required by applicable law or agreed to in writing, software |
| 32 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 34 | * See the License for the specific language governing permissions and |
| 35 | * limitations under the License. |
Krishna Kishor Jha | 10ad39f | 2022-02-21 17:02:47 +0530 | [diff] [blame] | 36 | |
| 37 | * Changes from Qualcomm Innovation Center are provided under the following license: |
| 38 | |
| 39 | * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. |
| 40 | |
| 41 | * Redistribution and use in source and binary forms, with or without |
| 42 | * modification, are permitted (subject to the limitations in the |
| 43 | * disclaimer below) provided that the following conditions are met: |
| 44 | |
| 45 | * * Redistributions of source code must retain the above copyright |
| 46 | * notice, this list of conditions and the following disclaimer. |
| 47 | |
| 48 | * * Redistributions in binary form must reproduce the above |
| 49 | * copyright notice, this list of conditions and the following |
| 50 | * disclaimer in the documentation and/or other materials provided |
| 51 | * with the distribution. |
| 52 | |
| 53 | * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its |
| 54 | * contributors may be used to endorse or promote products derived |
| 55 | * from this software without specific prior written permission. |
| 56 | |
| 57 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE |
| 58 | * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT |
| 59 | * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 60 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 61 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 62 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 63 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 64 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 65 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 66 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 67 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 68 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 69 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 70 | */ |
| 71 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 72 | #ifndef QCOM_AUDIO_HW_H |
| 73 | #define QCOM_AUDIO_HW_H |
| 74 | |
Mingming Yin | 497419f | 2015-07-01 16:57:32 -0700 | [diff] [blame] | 75 | #include <stdlib.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 76 | #include <cutils/str_parms.h> |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 77 | #include <cutils/list.h> |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 78 | #include <cutils/hashmap.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 79 | #include <hardware/audio.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 80 | #include <tinyalsa/asoundlib.h> |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 81 | #include <tinycompress/tinycompress.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 82 | |
| 83 | #include <audio_route/audio_route.h> |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 84 | #ifndef LINUX_ENABLED |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 85 | #include <audio_utils/ErrorLog.h> |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 86 | #else |
| 87 | typedef int error_log_t; |
| 88 | #define error_log_dump(error_log, fd, prefix, lines, limit_ns) (0) |
| 89 | #define error_log_create(entries, aggregate_ns) (0) |
| 90 | #define error_log_destroy(error_log) (0) |
| 91 | #endif |
| 92 | #ifndef LINUX_ENABLED |
Andy Hung | a1f48fa | 2019-07-01 18:14:53 -0700 | [diff] [blame] | 93 | #include <audio_utils/Statistics.h> |
| 94 | #include <audio_utils/clock.h> |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 95 | #endif |
Mingming Yin | 23c383c | 2014-07-11 10:39:59 -0700 | [diff] [blame] | 96 | #include "audio_defs.h" |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 97 | #include "voice.h" |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 98 | #include "audio_hw_extn_api.h" |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 99 | #include "device_utils.h" |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 100 | |
Weiyin Jiang | a3719ac | 2016-11-23 19:29:35 +0800 | [diff] [blame] | 101 | #if LINUX_ENABLED |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 102 | typedef struct { |
| 103 | int64_t n; |
| 104 | double min; |
| 105 | double max; |
| 106 | double last; |
| 107 | double mean; |
| 108 | } simple_stats_t; |
| 109 | #define NANOS_PER_SECOND 1000000000LL |
| 110 | #endif |
| 111 | |
| 112 | #if LINUX_ENABLED |
Surendar karka | b51c257 | 2018-02-22 13:09:48 +0530 | [diff] [blame] | 113 | #if defined(__LP64__) |
| 114 | #define VISUALIZER_LIBRARY_PATH "/usr/lib64/libqcomvisualizer.so" |
| 115 | #define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/usr/lib64/libqcompostprocbundle.so" |
| 116 | #define ADM_LIBRARY_PATH "/usr/lib64/libadm.so" |
| 117 | #else |
| 118 | #define VISUALIZER_LIBRARY_PATH "/usr/lib/libqcomvisualizer.so" |
| 119 | #define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/usr/lib/libqcompostprocbundle.so" |
| 120 | #define ADM_LIBRARY_PATH "/usr/lib/libadm.so" |
| 121 | #endif |
Weiyin Jiang | a3719ac | 2016-11-23 19:29:35 +0800 | [diff] [blame] | 122 | #else |
Weiyin Jiang | ae97a68 | 2017-06-30 13:37:47 +0800 | [diff] [blame] | 123 | #define VISUALIZER_LIBRARY_PATH "/vendor/lib/soundfx/libqcomvisualizer.so" |
| 124 | #define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/vendor/lib/soundfx/libqcompostprocbundle.so" |
David Ng | 06ccd87 | 2017-03-15 11:39:33 -0700 | [diff] [blame] | 125 | #define ADM_LIBRARY_PATH "/vendor/lib/libadm.so" |
Weiyin Jiang | a3719ac | 2016-11-23 19:29:35 +0800 | [diff] [blame] | 126 | #endif |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 127 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 128 | /* Flags used to initialize acdb_settings variable that goes to ACDB library */ |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 129 | #define NONE_FLAG 0x00000000 |
Banajit Goswami | de0ea45 | 2014-04-07 12:11:47 -0700 | [diff] [blame] | 130 | #define ANC_FLAG 0x00000001 |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 131 | #define DMIC_FLAG 0x00000002 |
| 132 | #define QMIC_FLAG 0x00000004 |
Aditya Bavanari | 4051c8d | 2017-12-13 13:31:26 +0530 | [diff] [blame] | 133 | /* Include TMIC Flag after existing QMIC flag to avoid backward compatibility |
| 134 | * issues since they are bit masked */ |
| 135 | #define TMIC_FLAG 0x00000008 |
Venkata Narendra Kumar Gutta | 88fd0bc | 2014-03-27 19:47:56 +0530 | [diff] [blame] | 136 | #define TTY_MODE_OFF 0x00000010 |
| 137 | #define TTY_MODE_FULL 0x00000020 |
| 138 | #define TTY_MODE_VCO 0x00000040 |
| 139 | #define TTY_MODE_HCO 0x00000080 |
| 140 | #define TTY_MODE_CLEAR 0xFFFFFF0F |
| 141 | #define FLUENCE_MODE_CLEAR 0xFFFFFFF0 |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 142 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 143 | #define ACDB_DEV_TYPE_OUT 1 |
| 144 | #define ACDB_DEV_TYPE_IN 2 |
| 145 | |
Zhou Song | 12c2950 | 2019-03-16 10:37:18 +0800 | [diff] [blame] | 146 | /* SCO SWB codec mode */ |
| 147 | #define SPEECH_MODE_INVALID 0xFFFF |
| 148 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 149 | /* support positional and index masks to 8ch */ |
| 150 | #define MAX_SUPPORTED_CHANNEL_MASKS (2 * FCC_8) |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 151 | #define MAX_SUPPORTED_FORMATS 15 |
| 152 | #define MAX_SUPPORTED_SAMPLE_RATES 7 |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 153 | #define DEFAULT_HDMI_OUT_CHANNELS 2 |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 154 | #define DEFAULT_HDMI_OUT_SAMPLE_RATE 48000 |
| 155 | #define DEFAULT_HDMI_OUT_FORMAT AUDIO_FORMAT_PCM_16_BIT |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 156 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 157 | #define ERROR_LOG_ENTRIES 16 |
| 158 | |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 159 | #define SND_CARD_STATE_OFFLINE 0 |
| 160 | #define SND_CARD_STATE_ONLINE 1 |
| 161 | |
| 162 | #define STREAM_DIRECTION_IN 0 |
| 163 | #define STREAM_DIRECTION_OUT 1 |
| 164 | |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 165 | #define MAX_PERF_LOCK_OPTS 20 |
| 166 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 167 | #define MAX_STREAM_PROFILE_STR_LEN 32 |
Vikram Panduranga | df59cae | 2017-08-03 18:04:55 -0700 | [diff] [blame] | 168 | typedef enum { |
| 169 | EFFECT_NONE = 0, |
| 170 | EFFECT_AEC, |
| 171 | EFFECT_NS, |
| 172 | EFFECT_MAX |
| 173 | } effect_type_t; |
| 174 | |
| 175 | struct audio_effect_config { |
| 176 | uint32_t module_id; |
| 177 | uint32_t instance_id; |
| 178 | uint32_t param_id; |
| 179 | uint32_t param_value; |
| 180 | }; |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 181 | |
Guodong Hu | 1d46f34 | 2019-06-28 16:57:30 +0800 | [diff] [blame] | 182 | struct audio_fluence_mmsecns_config { |
| 183 | uint32_t topology_id; |
| 184 | uint32_t module_id; |
| 185 | uint32_t instance_id; |
| 186 | uint32_t param_id; |
| 187 | }; |
| 188 | |
Alexy Joseph | 9898883 | 2017-01-13 14:56:59 -0800 | [diff] [blame] | 189 | #define MAX_MIXER_PATH_LEN 64 |
| 190 | |
Haynes Mathew George | 3a1f1fb | 2016-08-09 15:43:13 -0700 | [diff] [blame] | 191 | typedef enum card_status_t { |
| 192 | CARD_STATUS_OFFLINE, |
| 193 | CARD_STATUS_ONLINE |
| 194 | } card_status_t; |
| 195 | |
Shubhasini Sugumaran | 3fde658 | 2022-01-19 15:54:50 -0500 | [diff] [blame] | 196 | typedef enum power_policy_status_t { |
| 197 | POWER_POLICY_STATUS_OFFLINE, |
| 198 | POWER_POLICY_STATUS_ONLINE |
| 199 | } power_policy_status_t; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 200 | /* These are the supported use cases by the hardware. |
| 201 | * Each usecase is mapped to a specific PCM device. |
| 202 | * Refer to pcm_device_table[]. |
| 203 | */ |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 204 | enum { |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 205 | USECASE_INVALID = -1, |
| 206 | /* Playback usecases */ |
| 207 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0, |
| 208 | USECASE_AUDIO_PLAYBACK_LOW_LATENCY, |
| 209 | USECASE_AUDIO_PLAYBACK_MULTI_CH, |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 210 | USECASE_AUDIO_PLAYBACK_OFFLOAD, |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 211 | USECASE_AUDIO_PLAYBACK_OFFLOAD2, |
| 212 | USECASE_AUDIO_PLAYBACK_OFFLOAD3, |
| 213 | USECASE_AUDIO_PLAYBACK_OFFLOAD4, |
| 214 | USECASE_AUDIO_PLAYBACK_OFFLOAD5, |
| 215 | USECASE_AUDIO_PLAYBACK_OFFLOAD6, |
| 216 | USECASE_AUDIO_PLAYBACK_OFFLOAD7, |
| 217 | USECASE_AUDIO_PLAYBACK_OFFLOAD8, |
| 218 | USECASE_AUDIO_PLAYBACK_OFFLOAD9, |
Ravi Kumar Alamanda | 474de5a | 2015-06-25 20:08:01 -0700 | [diff] [blame] | 219 | USECASE_AUDIO_PLAYBACK_ULL, |
Haynes Mathew George | 1608104 | 2017-05-31 17:16:49 -0700 | [diff] [blame] | 220 | USECASE_AUDIO_PLAYBACK_MMAP, |
Vignesh Kulothungan | a692727 | 2019-02-20 15:17:07 -0800 | [diff] [blame] | 221 | USECASE_AUDIO_PLAYBACK_WITH_HAPTICS, |
Meng Wang | 51d8c2a | 2020-04-27 15:23:21 +0800 | [diff] [blame] | 222 | USECASE_AUDIO_PLAYBACK_HAPTICS, |
Haynes Mathew George | 484e8d2 | 2017-07-31 18:55:17 -0700 | [diff] [blame] | 223 | USECASE_AUDIO_PLAYBACK_HIFI, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 224 | USECASE_AUDIO_PLAYBACK_TTS, |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 225 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 226 | /* FM usecase */ |
| 227 | USECASE_AUDIO_PLAYBACK_FM, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 228 | |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 229 | /* HFP Use case*/ |
| 230 | USECASE_AUDIO_HFP_SCO, |
Vimal Puthanveed | 47e6485 | 2013-12-20 13:23:39 -0800 | [diff] [blame] | 231 | USECASE_AUDIO_HFP_SCO_WB, |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 232 | USECASE_AUDIO_HFP_SCO_DOWNLINK, |
| 233 | USECASE_AUDIO_HFP_SCO_WB_DOWNLINK, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 234 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 235 | /* Capture usecases */ |
| 236 | USECASE_AUDIO_RECORD, |
Krishna Kishor Jha | 0f4d848 | 2022-02-18 10:56:05 +0530 | [diff] [blame] | 237 | USECASE_AUDIO_RECORD2, |
| 238 | USECASE_AUDIO_RECORD3, |
Mingming Yin | e62d784 | 2013-10-25 16:26:03 -0700 | [diff] [blame] | 239 | USECASE_AUDIO_RECORD_COMPRESS, |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 240 | USECASE_AUDIO_RECORD_COMPRESS2, |
| 241 | USECASE_AUDIO_RECORD_COMPRESS3, |
| 242 | USECASE_AUDIO_RECORD_COMPRESS4, |
Dhananjay Kumar | 376e38b | 2017-09-28 22:26:23 +0530 | [diff] [blame] | 243 | USECASE_AUDIO_RECORD_COMPRESS5, |
| 244 | USECASE_AUDIO_RECORD_COMPRESS6, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 245 | USECASE_AUDIO_RECORD_LOW_LATENCY, |
Preetam Singh Ranawat | de84f1a | 2013-11-01 14:58:16 -0700 | [diff] [blame] | 246 | USECASE_AUDIO_RECORD_FM_VIRTUAL, |
Haynes Mathew George | 484e8d2 | 2017-07-31 18:55:17 -0700 | [diff] [blame] | 247 | USECASE_AUDIO_RECORD_HIFI, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 248 | |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 249 | USECASE_AUDIO_PLAYBACK_VOIP, |
| 250 | USECASE_AUDIO_RECORD_VOIP, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 251 | /* Voice usecase */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 252 | USECASE_VOICE_CALL, |
Haynes Mathew George | 1608104 | 2017-05-31 17:16:49 -0700 | [diff] [blame] | 253 | USECASE_AUDIO_RECORD_MMAP, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 254 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 255 | /* Voice extension usecases */ |
| 256 | USECASE_VOICE2_CALL, |
| 257 | USECASE_VOLTE_CALL, |
| 258 | USECASE_QCHAT_CALL, |
Vicky Sehrawat | 7e4fc15 | 2014-02-12 17:58:59 -0800 | [diff] [blame] | 259 | USECASE_VOWLAN_CALL, |
Vidyakumar Athota | 0e10935 | 2015-02-12 17:38:22 -0800 | [diff] [blame] | 260 | USECASE_VOICEMMODE1_CALL, |
| 261 | USECASE_VOICEMMODE2_CALL, |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 262 | USECASE_COMPRESS_VOIP_CALL, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 263 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 264 | USECASE_INCALL_REC_UPLINK, |
| 265 | USECASE_INCALL_REC_DOWNLINK, |
| 266 | USECASE_INCALL_REC_UPLINK_AND_DOWNLINK, |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 267 | USECASE_INCALL_REC_UPLINK_COMPRESS, |
| 268 | USECASE_INCALL_REC_DOWNLINK_COMPRESS, |
| 269 | USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 270 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 271 | USECASE_INCALL_MUSIC_UPLINK, |
| 272 | USECASE_INCALL_MUSIC_UPLINK2, |
| 273 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 274 | USECASE_AUDIO_SPKR_CALIB_RX, |
| 275 | USECASE_AUDIO_SPKR_CALIB_TX, |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 276 | |
| 277 | USECASE_AUDIO_PLAYBACK_AFE_PROXY, |
| 278 | USECASE_AUDIO_RECORD_AFE_PROXY, |
Zhou Song | 62ea028 | 2020-03-22 19:53:01 +0800 | [diff] [blame] | 279 | USECASE_AUDIO_RECORD_AFE_PROXY2, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 280 | USECASE_AUDIO_DSM_FEEDBACK, |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 281 | |
Md Mansoor Ahmed | db1b4f9 | 2018-01-25 18:56:31 +0530 | [diff] [blame] | 282 | USECASE_AUDIO_PLAYBACK_SILENCE, |
Shiv Maliyappanahalli | c065640 | 2016-09-03 14:13:26 -0700 | [diff] [blame] | 283 | |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 284 | USECASE_AUDIO_TRANSCODE_LOOPBACK_RX, |
| 285 | USECASE_AUDIO_TRANSCODE_LOOPBACK_TX, |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 286 | |
| 287 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM1, |
| 288 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM2, |
| 289 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM3, |
| 290 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM4, |
| 291 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM5, |
| 292 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM6, |
| 293 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM7, |
| 294 | USECASE_AUDIO_PLAYBACK_INTERACTIVE_STREAM8, |
Garmond Leung | e2433c3 | 2017-09-28 21:51:22 -0700 | [diff] [blame] | 295 | |
| 296 | USECASE_AUDIO_EC_REF_LOOPBACK, |
Aniket Kumar Lata | 7fd86e1 | 2018-02-20 19:26:10 -0800 | [diff] [blame] | 297 | |
| 298 | USECASE_AUDIO_A2DP_ABR_FEEDBACK, |
| 299 | |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 300 | /* car streams usecases */ |
| 301 | USECASE_AUDIO_PLAYBACK_MEDIA, |
| 302 | USECASE_AUDIO_PLAYBACK_SYS_NOTIFICATION, |
| 303 | USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE, |
| 304 | USECASE_AUDIO_PLAYBACK_PHONE, |
Susan Wang | 117cf6f | 2022-04-06 20:11:46 -0400 | [diff] [blame] | 305 | USECASE_AUDIO_PLAYBACK_ALERTS, |
Derek Chen | 1bcdc6b | 2020-02-06 22:44:53 -0800 | [diff] [blame] | 306 | USECASE_AUDIO_PLAYBACK_FRONT_PASSENGER, |
Derek Chen | df05eea | 2019-08-01 13:57:49 -0700 | [diff] [blame] | 307 | USECASE_AUDIO_PLAYBACK_REAR_SEAT, |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 308 | USECASE_AUDIO_RECORD_BUS, |
| 309 | USECASE_AUDIO_RECORD_BUS_FRONT_PASSENGER, |
| 310 | USECASE_AUDIO_RECORD_BUS_REAR_SEAT, |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 311 | |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 312 | USECASE_AUDIO_PLAYBACK_SYNTHESIZER, |
| 313 | |
Susan Wang | e395956 | 2021-03-11 11:50:26 -0500 | [diff] [blame] | 314 | /* Echo reference capture usecases */ |
| 315 | USECASE_AUDIO_RECORD_ECHO_REF_EXT, |
| 316 | |
Rahul Sharma | 9977098 | 2019-03-06 17:05:26 +0530 | [diff] [blame] | 317 | /*Audio FM Tuner usecase*/ |
| 318 | USECASE_AUDIO_FM_TUNER_EXT, |
Revathi Uddaraju | d9f23d9 | 2020-07-27 10:55:06 +0530 | [diff] [blame] | 319 | /*voip usecase with low latency path*/ |
| 320 | USECASE_AUDIO_RECORD_VOIP_LOW_LATENCY, |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame] | 321 | |
| 322 | /*In Car Communication Usecase*/ |
| 323 | USECASE_ICC_CALL, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 324 | AUDIO_USECASE_MAX |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | const char * const use_case_table[AUDIO_USECASE_MAX]; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 328 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 329 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 330 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 331 | /* |
| 332 | * tinyAlsa library interprets period size as number of frames |
| 333 | * one frame = channel_count * sizeof (pcm sample) |
| 334 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes |
| 335 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes |
| 336 | * We should take care of returning proper size when AudioFlinger queries for |
| 337 | * the buffer size of an input/output stream |
| 338 | */ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 339 | enum { |
| 340 | OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/ |
| 341 | OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */ |
| 342 | OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */ |
| 343 | OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */ |
Haynes Mathew George | 3a1f1fb | 2016-08-09 15:43:13 -0700 | [diff] [blame] | 344 | OFFLOAD_CMD_ERROR, /* offload playback hit some error */ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
Eric Laurent | 4b08413 | 2018-10-19 17:33:43 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Camera selection indicated via set_parameters "cameraFacing=front|back and |
| 349 | * "rotation=0|90|180|270"" |
| 350 | */ |
| 351 | enum { |
| 352 | CAMERA_FACING_BACK = 0x0, |
| 353 | CAMERA_FACING_FRONT = 0x1, |
| 354 | CAMERA_FACING_MASK = 0x0F, |
| 355 | CAMERA_ROTATION_LANDSCAPE = 0x0, |
| 356 | CAMERA_ROTATION_INVERT_LANDSCAPE = 0x10, |
| 357 | CAMERA_ROTATION_PORTRAIT = 0x20, |
| 358 | CAMERA_ROTATION_MASK = 0xF0, |
| 359 | CAMERA_BACK_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_LANDSCAPE), |
| 360 | CAMERA_BACK_INVERT_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_INVERT_LANDSCAPE), |
| 361 | CAMERA_BACK_PORTRAIT = (CAMERA_FACING_BACK|CAMERA_ROTATION_PORTRAIT), |
| 362 | CAMERA_FRONT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_LANDSCAPE), |
| 363 | CAMERA_FRONT_INVERT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_INVERT_LANDSCAPE), |
| 364 | CAMERA_FRONT_PORTRAIT = (CAMERA_FACING_FRONT|CAMERA_ROTATION_PORTRAIT), |
| 365 | |
| 366 | CAMERA_DEFAULT = CAMERA_BACK_LANDSCAPE, |
| 367 | }; |
| 368 | |
| 369 | //FIXME: to be replaced by proper video capture properties API |
| 370 | #define AUDIO_PARAMETER_KEY_CAMERA_FACING "cameraFacing" |
| 371 | #define AUDIO_PARAMETER_VALUE_FRONT "front" |
| 372 | #define AUDIO_PARAMETER_VALUE_BACK "back" |
| 373 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 374 | enum { |
| 375 | OFFLOAD_STATE_IDLE, |
| 376 | OFFLOAD_STATE_PLAYING, |
| 377 | OFFLOAD_STATE_PAUSED, |
| 378 | }; |
| 379 | |
| 380 | struct offload_cmd { |
| 381 | struct listnode node; |
| 382 | int cmd; |
| 383 | int data[]; |
| 384 | }; |
| 385 | |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 386 | typedef enum render_mode { |
| 387 | RENDER_MODE_AUDIO_NO_TIMESTAMP = 0, |
| 388 | RENDER_MODE_AUDIO_MASTER, |
| 389 | RENDER_MODE_AUDIO_STC_MASTER, |
| 390 | } render_mode_t; |
| 391 | |
Derek Chen | 1bcdc6b | 2020-02-06 22:44:53 -0800 | [diff] [blame] | 392 | /* This defines the physical car audio streams supported in |
| 393 | * audio HAL, limited by the available frontend PCM devices. |
| 394 | * Max number of physical streams supported is 32 and is |
Derek Chen | df05eea | 2019-08-01 13:57:49 -0700 | [diff] [blame] | 395 | * represented by stream bit flag. |
Derek Chen | 1bcdc6b | 2020-02-06 22:44:53 -0800 | [diff] [blame] | 396 | * Primary zone: bit 0 - 7 |
| 397 | * Front passenger zone: bit 8 - 15 |
| 398 | * Rear seat zone: bit 16 - 23 |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 399 | */ |
Derek Chen | 1bcdc6b | 2020-02-06 22:44:53 -0800 | [diff] [blame] | 400 | #define MAX_CAR_AUDIO_STREAMS 32 |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 401 | enum { |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 402 | CAR_AUDIO_STREAM_MEDIA = 0x1, |
| 403 | CAR_AUDIO_STREAM_SYS_NOTIFICATION = 0x2, |
| 404 | CAR_AUDIO_STREAM_NAV_GUIDANCE = 0x4, |
| 405 | CAR_AUDIO_STREAM_PHONE = 0x8, |
| 406 | CAR_AUDIO_STREAM_IN_PRIMARY = 0x10, |
Susan Wang | 117cf6f | 2022-04-06 20:11:46 -0400 | [diff] [blame] | 407 | CAR_AUDIO_STREAM_ALERTS = 0x20, |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 408 | CAR_AUDIO_STREAM_FRONT_PASSENGER = 0x100, |
| 409 | CAR_AUDIO_STREAM_IN_FRONT_PASSENGER = 0x200, |
| 410 | CAR_AUDIO_STREAM_REAR_SEAT = 0x10000, |
| 411 | CAR_AUDIO_STREAM_IN_REAR_SEAT = 0x20000, |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 412 | }; |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 413 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 414 | struct stream_app_type_cfg { |
| 415 | int sample_rate; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 416 | uint32_t bit_width; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 417 | int app_type; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 418 | int gain[2]; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 419 | }; |
| 420 | |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 421 | struct stream_config { |
| 422 | unsigned int sample_rate; |
| 423 | audio_channel_mask_t channel_mask; |
| 424 | audio_format_t format; |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 425 | struct listnode device_list; |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 426 | unsigned int bit_width; |
| 427 | }; |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 428 | |
Susan Wang | 6dd1309 | 2021-01-25 10:27:11 -0500 | [diff] [blame] | 429 | typedef struct streams_input_ctxt { |
| 430 | struct listnode list; |
| 431 | struct stream_in *input; |
| 432 | } streams_input_ctxt_t; |
| 433 | |
| 434 | typedef struct streams_output_ctxt { |
| 435 | struct listnode list; |
| 436 | struct stream_out *output; |
| 437 | } streams_output_ctxt_t; |
| 438 | |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 439 | struct stream_inout { |
| 440 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
| 441 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ |
| 442 | pthread_cond_t cond; |
| 443 | struct stream_config in_config; |
| 444 | struct stream_config out_config; |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 445 | struct stream_app_type_cfg out_app_type_cfg; |
| 446 | char profile[MAX_STREAM_PROFILE_STR_LEN]; |
Vidyakumar Athota | 6d65588 | 2017-05-22 18:26:24 -0700 | [diff] [blame] | 447 | struct audio_device *dev; |
| 448 | void *adsp_hdlr_stream_handle; |
| 449 | void *ip_hdlr_handle; |
| 450 | stream_callback_t client_callback; |
| 451 | void *client_cookie; |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 452 | }; |
Weiyin Jiang | 280ea74 | 2020-09-08 20:28:22 +0800 | [diff] [blame] | 453 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 454 | struct stream_out { |
| 455 | struct audio_stream_out stream; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 456 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 457 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 458 | pthread_cond_t cond; |
Weiyin Jiang | 280ea74 | 2020-09-08 20:28:22 +0800 | [diff] [blame] | 459 | /* stream_out->lock is of large granularity, and can only be held before device lock |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 460 | * latch is a supplemetary lock to protect certain fields of out stream (such as |
| 461 | * offload_state, a2dp_muted, to add any stream member that needs to be accessed |
| 462 | * with device lock held) and it can be held after device lock |
Weiyin Jiang | 280ea74 | 2020-09-08 20:28:22 +0800 | [diff] [blame] | 463 | */ |
| 464 | pthread_mutex_t latch_lock; |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 465 | pthread_mutex_t position_query_lock; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 466 | struct pcm_config config; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 467 | struct compr_config compr_config; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 468 | struct pcm *pcm; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 469 | struct compress *compr; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 470 | int standby; |
| 471 | int pcm_device_id; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 472 | unsigned int sample_rate; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 473 | audio_channel_mask_t channel_mask; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 474 | audio_format_t format; |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 475 | struct listnode device_list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 476 | audio_output_flags_t flags; |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 477 | char profile[MAX_STREAM_PROFILE_STR_LEN]; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 478 | audio_usecase_t usecase; |
| 479 | /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */ |
| 480 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 481 | audio_format_t supported_formats[MAX_SUPPORTED_FORMATS+1]; |
Mingming Yin | 3a941d4 | 2016-02-17 18:08:05 -0800 | [diff] [blame] | 482 | uint32_t supported_sample_rates[MAX_SUPPORTED_SAMPLE_RATES+1]; |
Eric Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 483 | bool muted; |
Glenn Kasten | 2ccd7ba | 2013-09-10 09:04:31 -0700 | [diff] [blame] | 484 | uint64_t written; /* total frames written, not cleared when entering standby */ |
Phil Burk | fe17efd | 2019-03-25 10:23:35 -0700 | [diff] [blame] | 485 | int64_t mmap_time_offset_nanos; /* fudge factor to correct inaccuracies in DSP */ |
Phil Burk | d898ba6 | 2019-06-20 12:49:01 -0700 | [diff] [blame] | 486 | int mmap_shared_memory_fd; /* file descriptor associated with MMAP NOIRQ shared memory */ |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 487 | audio_io_handle_t handle; |
Susan Wang | 6dd1309 | 2021-01-25 10:27:11 -0500 | [diff] [blame] | 488 | streams_output_ctxt_t out_ctxt; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 489 | struct stream_app_type_cfg app_type_cfg; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 490 | |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 491 | int non_blocking; |
| 492 | int playback_started; |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 493 | int offload_state; /* guarded by latch_lock */ |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 494 | pthread_cond_t offload_cond; |
| 495 | pthread_t offload_thread; |
| 496 | struct listnode offload_cmd_list; |
| 497 | bool offload_thread_blocked; |
Zhou Song | 48453a0 | 2018-01-10 17:50:59 +0800 | [diff] [blame] | 498 | struct timespec writeAt; |
Ravi Kumar Alamanda | 4e02e55 | 2013-07-17 15:22:04 -0700 | [diff] [blame] | 499 | |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 500 | void *adsp_hdlr_stream_handle; |
Naresh Tanniru | 8581945 | 2017-05-04 18:55:45 -0700 | [diff] [blame] | 501 | void *ip_hdlr_handle; |
Ben Romberger | d771a7c | 2017-02-22 18:05:17 -0800 | [diff] [blame] | 502 | |
| 503 | stream_callback_t client_callback; |
| 504 | void *client_cookie; |
Haynes Mathew George | 352f27b | 2013-07-26 00:00:15 -0700 | [diff] [blame] | 505 | struct compr_gapless_mdata gapless_mdata; |
| 506 | int send_new_metadata; |
Chaithanya Krishna Bacharaju | a70cb6a | 2015-07-24 14:15:05 +0530 | [diff] [blame] | 507 | bool send_next_track_params; |
| 508 | bool is_compr_metadata_avail; |
Mingming Yin | 3ee55c6 | 2014-08-04 14:23:35 -0700 | [diff] [blame] | 509 | unsigned int bit_width; |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 510 | uint32_t hal_fragment_size; |
| 511 | audio_format_t hal_ip_format; |
| 512 | audio_format_t hal_op_format; |
| 513 | void *convert_buffer; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 514 | |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 515 | bool realtime; |
| 516 | int af_period_multiplier; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 517 | struct audio_device *dev; |
Dhananjay Kumar | e6293dd | 2017-05-25 17:25:30 +0530 | [diff] [blame] | 518 | card_status_t card_status; |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 519 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 520 | void* qaf_stream_handle; |
Sidipotu Ashok | d2f10ba | 2019-05-06 15:41:56 +0530 | [diff] [blame] | 521 | void* qap_stream_handle; |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 522 | pthread_cond_t qaf_offload_cond; |
| 523 | pthread_t qaf_offload_thread; |
| 524 | struct listnode qaf_offload_cmd_list; |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 525 | uint32_t platform_latency; |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 526 | render_mode_t render_mode; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 527 | bool drift_correction_enabled; |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 528 | |
Naresh Tanniru | 29bce4e | 2017-04-27 17:54:30 +0530 | [diff] [blame] | 529 | struct audio_out_channel_map_param channel_map_param; /* input channel map */ |
Lakshman Chaluvaraju | b4ec870 | 2016-11-04 19:21:12 +0530 | [diff] [blame] | 530 | audio_offload_info_t info; |
Ashish Jain | 1b9b30c | 2017-05-18 20:57:40 +0530 | [diff] [blame] | 531 | int started; |
Naresh Tanniru | ee3499a | 2017-01-05 14:05:35 +0530 | [diff] [blame] | 532 | qahwi_stream_out_t qahwi_out; |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 533 | |
| 534 | bool is_iec61937_info_available; |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 535 | bool a2dp_muted; /* guarded by latch_lock */ |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 536 | float volume_l; |
| 537 | float volume_r; |
Ramu Gottipati | 97bdcfb | 2018-04-13 17:58:24 +0530 | [diff] [blame] | 538 | bool apply_volume; |
Alexy Joseph | 9898883 | 2017-01-13 14:56:59 -0800 | [diff] [blame] | 539 | |
| 540 | char pm_qos_mixer_path[MAX_MIXER_PATH_LEN]; |
Aniket Kumar Lata | 932f487 | 2017-11-06 18:29:44 -0800 | [diff] [blame] | 541 | int hal_output_suspend_supported; |
| 542 | int dynamic_pm_qos_config_supported; |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 543 | bool stream_config_changed; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 544 | mix_matrix_params_t pan_scale_params; |
| 545 | mix_matrix_params_t downmix_params; |
Surendar Karka | f51b584 | 2018-04-26 11:28:38 +0530 | [diff] [blame] | 546 | bool set_dual_mono; |
Manisha Agarwal | 7b3e377 | 2019-02-20 14:33:45 +0530 | [diff] [blame] | 547 | bool prev_card_status_offline; |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 548 | #ifndef LINUX_ENABLED |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 549 | error_log_t *error_log; |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 550 | #endif |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 551 | bool pspd_coeff_sent; |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 552 | |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 553 | int car_audio_stream; /* handle for car_audio_stream */ |
Vignesh Kulothungan | 39fc6a2 | 2019-08-01 00:55:59 -0700 | [diff] [blame] | 554 | |
| 555 | union { |
| 556 | char *addr; |
| 557 | struct { |
| 558 | int controller; |
| 559 | int stream; |
| 560 | } cs; |
| 561 | } extconn; |
Andy Hung | a1f48fa | 2019-07-01 18:14:53 -0700 | [diff] [blame] | 562 | |
| 563 | size_t kernel_buffer_size; // cached value of the alsa buffer size, const after open(). |
| 564 | |
| 565 | // last out_get_presentation_position() cached info. |
| 566 | bool last_fifo_valid; |
| 567 | unsigned int last_fifo_frames_remaining; |
| 568 | int64_t last_fifo_time_ns; |
| 569 | |
| 570 | simple_stats_t fifo_underruns; // TODO: keep a list of the last N fifo underrun times. |
Andy Hung | c6bfd4a | 2019-07-01 18:26:00 -0700 | [diff] [blame] | 571 | simple_stats_t start_latency_ms; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | struct stream_in { |
| 575 | struct audio_stream_in stream; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 576 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Shiv Maliyappanahalli | 736d4ce | 2015-09-28 15:23:06 -0700 | [diff] [blame] | 577 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 578 | struct pcm_config config; |
| 579 | struct pcm *pcm; |
| 580 | int standby; |
| 581 | int source; |
| 582 | int pcm_device_id; |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 583 | struct listnode device_list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 584 | audio_channel_mask_t channel_mask; |
| 585 | audio_usecase_t usecase; |
Ravi Kumar Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 586 | bool enable_aec; |
Ravi Kumar Alamanda | 198185e | 2013-11-07 15:42:19 -0800 | [diff] [blame] | 587 | bool enable_ns; |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 588 | audio_format_t format; |
Carter Hsu | 2e429db | 2019-05-14 18:50:52 +0800 | [diff] [blame] | 589 | bool enable_ec_port; |
| 590 | bool ec_opened; |
| 591 | struct listnode aec_list; |
| 592 | struct listnode ns_list; |
Phil Burk | e0a86d1 | 2019-02-16 22:28:11 -0800 | [diff] [blame] | 593 | int64_t mmap_time_offset_nanos; /* fudge factor to correct inaccuracies in DSP */ |
Phil Burk | d898ba6 | 2019-06-20 12:49:01 -0700 | [diff] [blame] | 594 | int mmap_shared_memory_fd; /* file descriptor associated with MMAP NOIRQ shared memory */ |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 595 | audio_io_handle_t capture_handle; |
Susan Wang | 6dd1309 | 2021-01-25 10:27:11 -0500 | [diff] [blame] | 596 | streams_input_ctxt_t in_ctxt; |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 597 | audio_input_flags_t flags; |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 598 | char profile[MAX_STREAM_PROFILE_STR_LEN]; |
Ravi Kumar Alamanda | 8fa6b19 | 2014-09-09 16:06:42 -0700 | [diff] [blame] | 599 | bool is_st_session; |
Bharath Ramachandramurthy | 837535b | 2015-02-05 14:27:59 -0800 | [diff] [blame] | 600 | bool is_st_session_active; |
Dhananjay Kumar | 9983c37 | 2016-12-09 22:00:40 +0530 | [diff] [blame] | 601 | unsigned int sample_rate; |
| 602 | unsigned int bit_width; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 603 | bool realtime; |
| 604 | int af_period_multiplier; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 605 | struct stream_app_type_cfg app_type_cfg; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 606 | void *cin_extn; |
| 607 | qahwi_stream_in_t qahwi_in; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 608 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 609 | struct audio_device *dev; |
Dhananjay Kumar | e6293dd | 2017-05-25 17:25:30 +0530 | [diff] [blame] | 610 | card_status_t card_status; |
Haynes Mathew George | 1608104 | 2017-05-31 17:16:49 -0700 | [diff] [blame] | 611 | int capture_started; |
justinweng | 20fb6d8 | 2019-02-21 18:49:00 -0700 | [diff] [blame] | 612 | float zoom; |
| 613 | audio_microphone_direction_t direction; |
Haynes Mathew George | 484e8d2 | 2017-07-31 18:55:17 -0700 | [diff] [blame] | 614 | |
Deeraj Soman | 30cc7ae | 2019-03-18 16:26:55 +0530 | [diff] [blame] | 615 | volatile int32_t capture_stopped; |
| 616 | |
Haynes Mathew George | 484e8d2 | 2017-07-31 18:55:17 -0700 | [diff] [blame] | 617 | /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */ |
| 618 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; |
| 619 | audio_format_t supported_formats[MAX_SUPPORTED_FORMATS + 1]; |
| 620 | uint32_t supported_sample_rates[MAX_SUPPORTED_SAMPLE_RATES + 1]; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 621 | |
| 622 | int64_t frames_read; /* total frames read, not cleared when entering standby */ |
| 623 | int64_t frames_muted; /* total frames muted, not cleared when entering standby */ |
| 624 | |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 625 | #ifndef LINUX_ENABLED |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 626 | error_log_t *error_log; |
Dechen Chai | 2276845 | 2021-07-30 09:29:16 +0530 | [diff] [blame] | 627 | #endif |
Andy Hung | c6bfd4a | 2019-07-01 18:26:00 -0700 | [diff] [blame] | 628 | simple_stats_t start_latency_ms; |
Huicheng Liu | 1404ba1 | 2020-09-11 01:03:25 -0400 | [diff] [blame] | 629 | |
| 630 | int car_audio_stream; /* handle for car_audio_stream*/ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 631 | }; |
| 632 | |
| 633 | typedef enum { |
| 634 | PCM_PLAYBACK, |
| 635 | PCM_CAPTURE, |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 636 | VOICE_CALL, |
Vimal Puthanveed | 5b4d3f1 | 2013-11-05 15:57:39 -0800 | [diff] [blame] | 637 | VOIP_CALL, |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 638 | PCM_HFP_CALL, |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 639 | TRANSCODE_LOOPBACK_RX, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 640 | TRANSCODE_LOOPBACK_TX, |
Rahul Sharma | 9977098 | 2019-03-06 17:05:26 +0530 | [diff] [blame] | 641 | PCM_PASSTHROUGH, |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame] | 642 | ICC_CALL, |
Fei Tong | affdf73 | 2020-02-20 20:39:05 +0800 | [diff] [blame] | 643 | SYNTH_LOOPBACK, |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 644 | USECASE_TYPE_MAX |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 645 | } usecase_type_t; |
| 646 | |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 647 | typedef enum { |
| 648 | PATCH_NONE = -1, |
| 649 | PATCH_PLAYBACK, |
| 650 | PATCH_CAPTURE, |
| 651 | PATCH_DEVICE_LOOPBACK |
| 652 | } patch_type_t; |
| 653 | |
| 654 | struct audio_patch_info { |
| 655 | struct audio_patch *patch; |
| 656 | patch_type_t patch_type; |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 657 | }; |
| 658 | |
| 659 | struct audio_stream_info { |
| 660 | struct audio_stream *stream; |
| 661 | audio_patch_handle_t patch_handle; |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 662 | }; |
| 663 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 664 | union stream_ptr { |
| 665 | struct stream_in *in; |
| 666 | struct stream_out *out; |
Siddartha Shaik | 31b530e | 2017-05-19 15:26:33 +0530 | [diff] [blame] | 667 | struct stream_inout *inout; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 668 | }; |
| 669 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 670 | struct audio_usecase { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 671 | struct listnode list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 672 | audio_usecase_t id; |
| 673 | usecase_type_t type; |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 674 | struct listnode device_list; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 675 | snd_device_t out_snd_device; |
| 676 | snd_device_t in_snd_device; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 677 | struct stream_app_type_cfg out_app_type_cfg; |
| 678 | struct stream_app_type_cfg in_app_type_cfg; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 679 | union stream_ptr stream; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 680 | }; |
| 681 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 682 | struct stream_format { |
| 683 | struct listnode list; |
| 684 | audio_format_t format; |
| 685 | }; |
| 686 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 687 | struct stream_sample_rate { |
| 688 | struct listnode list; |
| 689 | uint32_t sample_rate; |
| 690 | }; |
| 691 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 692 | typedef union { |
| 693 | audio_output_flags_t out_flags; |
| 694 | audio_input_flags_t in_flags; |
| 695 | } audio_io_flags_t; |
| 696 | |
| 697 | struct streams_io_cfg { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 698 | struct listnode list; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 699 | audio_io_flags_t flags; |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 700 | char profile[MAX_STREAM_PROFILE_STR_LEN]; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 701 | struct listnode format_list; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 702 | struct listnode sample_rate_list; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 703 | struct stream_app_type_cfg app_type_cfg; |
| 704 | }; |
| 705 | |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 706 | typedef void* (*adm_init_t)(); |
| 707 | typedef void (*adm_deinit_t)(void *); |
| 708 | typedef void (*adm_register_output_stream_t)(void *, audio_io_handle_t, audio_output_flags_t); |
| 709 | typedef void (*adm_register_input_stream_t)(void *, audio_io_handle_t, audio_input_flags_t); |
| 710 | typedef void (*adm_deregister_stream_t)(void *, audio_io_handle_t); |
| 711 | typedef void (*adm_request_focus_t)(void *, audio_io_handle_t); |
| 712 | typedef void (*adm_abandon_focus_t)(void *, audio_io_handle_t); |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 713 | typedef void (*adm_set_config_t)(void *, audio_io_handle_t, |
| 714 | struct pcm *, |
| 715 | struct pcm_config *); |
| 716 | typedef void (*adm_request_focus_v2_t)(void *, audio_io_handle_t, long); |
| 717 | typedef bool (*adm_is_noirq_avail_t)(void *, int, int, int); |
| 718 | typedef void (*adm_on_routing_change_t)(void *, audio_io_handle_t); |
Aniket Kumar Lata | 60586a9 | 2019-05-22 22:18:55 -0700 | [diff] [blame] | 719 | typedef int (*adm_request_focus_v2_1_t)(void *, audio_io_handle_t, long); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 720 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 721 | struct audio_device { |
| 722 | struct audio_hw_device device; |
Eric Laurent | 4b08413 | 2018-10-19 17:33:43 -0700 | [diff] [blame] | 723 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 724 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Weiyin Jiang | fa65d3e | 2019-03-05 23:39:45 +0800 | [diff] [blame] | 725 | pthread_mutex_t cal_lock; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 726 | struct mixer *mixer; |
| 727 | audio_mode_t mode; |
Jaideep Sharma | 477917f | 2020-03-13 18:13:33 +0530 | [diff] [blame] | 728 | audio_mode_t prev_mode; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 729 | audio_devices_t out_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 730 | struct stream_out *primary_output; |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 731 | struct stream_out *voice_tx_output; |
| 732 | struct stream_out *current_call_output; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 733 | bool bluetooth_nrec; |
| 734 | bool screen_off; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 735 | int *snd_dev_ref_cnt; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 736 | struct listnode usecase_list; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 737 | struct listnode streams_output_cfg_list; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 738 | struct listnode streams_input_cfg_list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 739 | struct audio_route *audio_route; |
| 740 | int acdb_settings; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 741 | bool speaker_lr_swap; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 742 | struct voice voice; |
Eric Laurent | 07eeafd | 2013-10-06 12:52:49 -0700 | [diff] [blame] | 743 | unsigned int cur_hdmi_channels; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 744 | audio_format_t cur_hdmi_format; |
| 745 | unsigned int cur_hdmi_sample_rate; |
| 746 | unsigned int cur_hdmi_bit_width; |
Krishnankutty Kolathappilly | 0b2de1c | 2014-02-14 14:45:49 -0800 | [diff] [blame] | 747 | unsigned int cur_wfd_channels; |
Mingming Yin | 514a8bc | 2014-07-29 15:22:21 -0700 | [diff] [blame] | 748 | bool bt_wb_speech_enabled; |
Zhou Song | 12c2950 | 2019-03-16 10:37:18 +0800 | [diff] [blame] | 749 | unsigned int swb_speech_mode; |
vivek mehta | 344576a | 2016-04-12 18:56:03 -0700 | [diff] [blame] | 750 | bool allow_afe_proxy_usage; |
Haynes Mathew George | 01156f9 | 2018-04-13 15:29:54 -0700 | [diff] [blame] | 751 | bool is_charging; // from battery listener |
Vignesh Kulothungan | 7d37431 | 2018-02-21 17:12:00 -0800 | [diff] [blame] | 752 | bool mic_break_enabled; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 753 | bool enable_hfp; |
| 754 | bool mic_muted; |
| 755 | bool enable_voicerx; |
Quinn Male | f605036 | 2019-01-30 15:55:40 -0800 | [diff] [blame] | 756 | unsigned int num_va_sessions; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 757 | |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 758 | int snd_card; |
Dhananjay Kumar | e6293dd | 2017-05-25 17:25:30 +0530 | [diff] [blame] | 759 | card_status_t card_status; |
Shubhasini Sugumaran | 3fde658 | 2022-01-19 15:54:50 -0500 | [diff] [blame] | 760 | power_policy_status_t out_power_policy; |
| 761 | power_policy_status_t in_power_policy; |
Apoorv Raghuvanshi | 2149216 | 2015-02-19 18:19:36 -0800 | [diff] [blame] | 762 | unsigned int cur_codec_backend_samplerate; |
| 763 | unsigned int cur_codec_backend_bit_width; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 764 | bool is_channel_status_set; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 765 | void *platform; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 766 | void *extspk; |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 767 | unsigned int offload_usecases_state; |
Samyak Jain | 15fda66 | 2018-12-18 16:40:52 +0530 | [diff] [blame] | 768 | unsigned int pcm_record_uc_state; |
Eric Laurent | c4aef75 | 2013-09-12 17:45:53 -0700 | [diff] [blame] | 769 | void *visualizer_lib; |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 770 | int (*visualizer_start_output)(audio_io_handle_t, int); |
| 771 | int (*visualizer_stop_output)(audio_io_handle_t, int); |
| 772 | void *offload_effects_lib; |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 773 | int (*offload_effects_start_output)(audio_io_handle_t, int, struct mixer *); |
Subhash Chandra Bose Naripeddy | 1d08916 | 2013-11-13 13:31:50 -0800 | [diff] [blame] | 774 | int (*offload_effects_stop_output)(audio_io_handle_t, int); |
Naresh Tanniru | 4c63039 | 2014-05-12 01:05:52 +0530 | [diff] [blame] | 775 | |
Jitendra Naruka | 1b6513f | 2014-11-22 19:34:13 -0800 | [diff] [blame] | 776 | int (*offload_effects_set_hpx_state)(bool); |
Ravi Kumar Alamanda | 8a0f977 | 2015-06-15 10:35:19 -0700 | [diff] [blame] | 777 | |
| 778 | void *adm_data; |
| 779 | void *adm_lib; |
| 780 | adm_init_t adm_init; |
| 781 | adm_deinit_t adm_deinit; |
| 782 | adm_register_input_stream_t adm_register_input_stream; |
| 783 | adm_register_output_stream_t adm_register_output_stream; |
| 784 | adm_deregister_stream_t adm_deregister_stream; |
| 785 | adm_request_focus_t adm_request_focus; |
| 786 | adm_abandon_focus_t adm_abandon_focus; |
Haynes Mathew George | 5beddd4 | 2016-06-27 18:33:40 -0700 | [diff] [blame] | 787 | adm_set_config_t adm_set_config; |
| 788 | adm_request_focus_v2_t adm_request_focus_v2; |
| 789 | adm_is_noirq_avail_t adm_is_noirq_avail; |
| 790 | adm_on_routing_change_t adm_on_routing_change; |
Aniket Kumar Lata | 60586a9 | 2019-05-22 22:18:55 -0700 | [diff] [blame] | 791 | adm_request_focus_v2_1_t adm_request_focus_v2_1; |
Dhananjay Kumar | d68883d | 2015-09-04 13:39:26 +0530 | [diff] [blame] | 792 | |
| 793 | void (*offload_effects_get_parameters)(struct str_parms *, |
| 794 | struct str_parms *); |
| 795 | void (*offload_effects_set_parameters)(struct str_parms *); |
vivek mehta | 446c396 | 2015-09-14 10:57:35 -0700 | [diff] [blame] | 796 | |
| 797 | bool multi_offload_enable; |
Sudheer Papothi | fa9d228 | 2015-09-17 01:53:25 +0530 | [diff] [blame] | 798 | int perf_lock_handle; |
| 799 | int perf_lock_opts[MAX_PERF_LOCK_OPTS]; |
| 800 | int perf_lock_opts_size; |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 801 | bool native_playback_enabled; |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 802 | bool asrc_mode_enabled; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 803 | qahwi_device_t qahwi_dev; |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 804 | bool vr_audio_mode_enabled; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 805 | uint32_t dsp_bit_width_enforce_mode; |
Ashish Jain | 1b9b30c | 2017-05-18 20:57:40 +0530 | [diff] [blame] | 806 | bool bt_sco_on; |
Satish Babu Patakokila | c3c5d43 | 2017-07-04 22:48:59 +0530 | [diff] [blame] | 807 | struct audio_device_config_param *device_cfg_params; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 808 | unsigned int interactive_usecase_state; |
Aalique Grahame | 3765986 | 2017-12-03 22:34:26 -0800 | [diff] [blame] | 809 | bool dp_allowed_for_voice; |
Derek Chen | d253007 | 2014-11-24 12:39:14 -0800 | [diff] [blame] | 810 | void *ext_hw_plugin; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 811 | |
Vignesh Kulothungan | a692727 | 2019-02-20 15:17:07 -0800 | [diff] [blame] | 812 | struct pcm_config haptics_config; |
| 813 | struct pcm *haptic_pcm; |
| 814 | int haptic_pcm_device_id; |
| 815 | uint8_t *haptic_buffer; |
| 816 | size_t haptic_buffer_size; |
Kunlei Zhang | a3c4cb0 | 2021-03-05 16:03:54 +0800 | [diff] [blame] | 817 | int fluence_nn_usecase_id; |
Vignesh Kulothungan | a692727 | 2019-02-20 15:17:07 -0800 | [diff] [blame] | 818 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 819 | /* logging */ |
| 820 | snd_device_t last_logged_snd_device[AUDIO_USECASE_MAX][2]; /* [out, in] */ |
| 821 | |
| 822 | /* The pcm_params use_case_table is loaded by adev_verify_devices() upon |
| 823 | * calling adev_open(). |
| 824 | * |
| 825 | * If an entry is not NULL, it can be used to determine if extended precision |
| 826 | * or other capabilities are present for the device corresponding to that usecase. |
| 827 | */ |
| 828 | struct pcm_params *use_case_table[AUDIO_USECASE_MAX]; |
Derek Chen | f939fb7 | 2018-11-13 13:34:41 -0800 | [diff] [blame] | 829 | struct listnode active_inputs_list; |
| 830 | struct listnode active_outputs_list; |
Dhanalakshmi Siddani | 20628c8 | 2019-01-27 17:31:09 +0530 | [diff] [blame] | 831 | bool use_old_pspd_mix_ctrl; |
Eric Laurent | 4b08413 | 2018-10-19 17:33:43 -0700 | [diff] [blame] | 832 | int camera_orientation; /* CAMERA_BACK_LANDSCAPE ... CAMERA_FRONT_PORTRAIT */ |
Aniket Kumar Lata | 60586a9 | 2019-05-22 22:18:55 -0700 | [diff] [blame] | 833 | bool adm_routing_changed; |
Rahul Sharma | 9977098 | 2019-03-06 17:05:26 +0530 | [diff] [blame] | 834 | struct listnode audio_patch_record_list; |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 835 | Hashmap *patch_map; |
| 836 | Hashmap *io_streams_map; |
Revathi Uddaraju | b26e393 | 2020-06-10 14:51:02 +0530 | [diff] [blame] | 837 | bool a2dp_started; |
Zhou Song | 62ea028 | 2020-03-22 19:53:01 +0800 | [diff] [blame] | 838 | bool ha_proxy_enable; |
Rahul Sharma | 9977098 | 2019-03-06 17:05:26 +0530 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | struct audio_patch_record { |
| 842 | struct listnode list; |
| 843 | audio_patch_handle_t handle; |
| 844 | audio_usecase_t usecase; |
Derek Chen | 6c0f3de | 2020-02-26 00:30:42 -0800 | [diff] [blame] | 845 | struct audio_patch patch; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 846 | }; |
| 847 | |
Krishna Kishor Jha | 10ad39f | 2022-02-21 17:02:47 +0530 | [diff] [blame] | 848 | #ifdef SOFT_VOLUME |
| 849 | /* this struct is used for set/get values from AHAL*/ |
| 850 | struct soft_step_volume_params { |
| 851 | int period; |
| 852 | int step; |
| 853 | int curve; |
| 854 | }; |
| 855 | #endif |
Shubhasini Sugumaran | 3fde658 | 2022-01-19 15:54:50 -0500 | [diff] [blame] | 856 | void out_set_power_policy(uint8_t enable); |
| 857 | void in_set_power_policy(uint8_t enable); |
Krishna Kishor Jha | 10ad39f | 2022-02-21 17:02:47 +0530 | [diff] [blame] | 858 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 859 | int select_devices(struct audio_device *adev, |
| 860 | audio_usecase_t uc_id); |
| 861 | int disable_audio_route(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 862 | struct audio_usecase *usecase); |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 863 | int disable_snd_device(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 864 | snd_device_t snd_device); |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 865 | int enable_snd_device(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 866 | snd_device_t snd_device); |
| 867 | |
Gopikrishnaiah Anandan | f538cef | 2013-10-28 14:06:03 -0700 | [diff] [blame] | 868 | int enable_audio_route(struct audio_device *adev, |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 869 | struct audio_usecase *usecase); |
| 870 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 871 | struct audio_usecase *get_usecase_from_list(const struct audio_device *adev, |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 872 | audio_usecase_t uc_id); |
Krishnankutty Kolathappilly | eff07ef | 2013-11-21 20:39:59 -0800 | [diff] [blame] | 873 | |
Subhash Chandra Bose Naripeddy | 16ff4f8 | 2014-04-01 21:03:10 -0700 | [diff] [blame] | 874 | bool is_offload_usecase(audio_usecase_t uc_id); |
| 875 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 876 | bool audio_is_true_native_stream_active(struct audio_device *adev); |
| 877 | |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 878 | bool audio_is_dsd_native_stream_active(struct audio_device *adev); |
Preetam Singh Ranawat | b0c0dd7 | 2016-08-18 00:32:06 +0530 | [diff] [blame] | 879 | |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 880 | uint32_t adev_get_dsp_bit_width_enforce_mode(); |
| 881 | |
Mingming Yin | 07972cc | 2014-06-06 17:11:23 -0700 | [diff] [blame] | 882 | int pcm_ioctl(struct pcm *pcm, int request, ...); |
| 883 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 884 | audio_usecase_t get_usecase_id_from_usecase_type(const struct audio_device *adev, |
Narsinga Rao Chella | f928a98 | 2015-03-06 14:57:35 -0800 | [diff] [blame] | 885 | usecase_type_t type); |
Venkata Narendra Kumar Gutta | ed0f94f | 2014-07-09 16:29:28 +0530 | [diff] [blame] | 886 | |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 887 | /* adev lock held */ |
Weiyin Jiang | 280ea74 | 2020-09-08 20:28:22 +0800 | [diff] [blame] | 888 | int check_a2dp_restore_l(struct audio_device *adev, struct stream_out *out, bool restore); |
Chaithanya Krishna Bacharaju | 69d2e4c | 2017-05-26 18:22:46 +0530 | [diff] [blame] | 889 | |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 890 | int adev_open_output_stream(struct audio_hw_device *dev, |
| 891 | audio_io_handle_t handle, |
| 892 | audio_devices_t devices, |
| 893 | audio_output_flags_t flags, |
| 894 | struct audio_config *config, |
| 895 | struct audio_stream_out **stream_out, |
Derek Chen | 5f67a94 | 2020-02-24 23:08:13 -0800 | [diff] [blame] | 896 | const char *address); |
Lakshman Chaluvaraju | 22ba9f1 | 2016-09-12 11:42:10 +0530 | [diff] [blame] | 897 | void adev_close_output_stream(struct audio_hw_device *dev __unused, |
| 898 | struct audio_stream_out *stream); |
| 899 | |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 900 | bool is_interactive_usecase(audio_usecase_t uc_id); |
| 901 | |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 902 | size_t get_output_period_size(uint32_t sample_rate, |
| 903 | audio_format_t format, |
| 904 | int channel_count, |
| 905 | int duration /*in millisecs*/); |
| 906 | |
Krishnankutty Kolathappilly | eff07ef | 2013-11-21 20:39:59 -0800 | [diff] [blame] | 907 | #define LITERAL_TO_STRING(x) #x |
| 908 | #define CHECK(condition) LOG_ALWAYS_FATAL_IF(!(condition), "%s",\ |
| 909 | __FILE__ ":" LITERAL_TO_STRING(__LINE__)\ |
| 910 | " ASSERT_FATAL(" #condition ") failed.") |
Avinash Chandra | d7296d4 | 2021-08-04 15:07:47 +0530 | [diff] [blame] | 911 | bool is_combo_audio_input_device(struct listnode *devices); |
Krishnankutty Kolathappilly | eff07ef | 2013-11-21 20:39:59 -0800 | [diff] [blame] | 912 | |
Chaithanya Krishna Bacharaju | c9f9971 | 2019-04-16 15:32:52 +0530 | [diff] [blame] | 913 | static inline bool is_loopback_input_device(audio_devices_t device) { |
| 914 | if (!audio_is_output_device(device) && |
| 915 | ((device & AUDIO_DEVICE_IN_LOOPBACK) == AUDIO_DEVICE_IN_LOOPBACK)) |
| 916 | return true; |
| 917 | else |
| 918 | return false; |
| 919 | } |
| 920 | |
Jaideep Sharma | d305a4a | 2020-02-27 14:29:04 +0530 | [diff] [blame] | 921 | static inline bool audio_is_virtual_input_source(audio_source_t source) { |
| 922 | bool result = false; |
| 923 | switch(source) { |
| 924 | case AUDIO_SOURCE_VOICE_UPLINK : |
| 925 | case AUDIO_SOURCE_VOICE_DOWNLINK : |
| 926 | case AUDIO_SOURCE_VOICE_CALL : |
| 927 | case AUDIO_SOURCE_FM_TUNER : |
| 928 | result = true; |
| 929 | break; |
| 930 | default: |
| 931 | break; |
| 932 | } |
| 933 | return result; |
| 934 | } |
| 935 | |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 936 | int route_output_stream(struct stream_out *stream, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 937 | struct listnode *devices); |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 938 | int route_input_stream(struct stream_in *stream, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 939 | struct listnode *devices, |
| 940 | audio_source_t source); |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 941 | |
Derek Chen | 6c0f3de | 2020-02-26 00:30:42 -0800 | [diff] [blame] | 942 | audio_patch_handle_t generate_patch_handle(); |
| 943 | |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 944 | /* |
| 945 | * NOTE: when multiple mutexes have to be acquired, always take the |
Weiyin Jiang | 906db3c | 2021-03-02 13:17:04 +0800 | [diff] [blame] | 946 | * stream_in or stream_out mutex first, followed by the audio_device mutex |
| 947 | * and latch at last. |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 948 | */ |
| 949 | |
Raghu Bankapur | 37cbf38 | 2022-12-01 09:30:00 +0530 | [diff] [blame] | 950 | static inline audio_format_t pcm_format_to_audio_format(const enum pcm_format format) |
| 951 | { |
| 952 | audio_format_t ret = AUDIO_FORMAT_INVALID; |
| 953 | switch(format) { |
| 954 | case PCM_FORMAT_S16_LE: |
| 955 | ret = (audio_format_t)AUDIO_FORMAT_PCM_SUB_16_BIT; |
| 956 | break; |
| 957 | case PCM_FORMAT_S32_LE: |
| 958 | ret = (audio_format_t)AUDIO_FORMAT_PCM_SUB_32_BIT; |
| 959 | break; |
| 960 | case PCM_FORMAT_S8: |
| 961 | ret = (audio_format_t)AUDIO_FORMAT_PCM_SUB_8_BIT; |
| 962 | break; |
| 963 | case PCM_FORMAT_S24_LE: |
| 964 | ret = (audio_format_t)AUDIO_FORMAT_PCM_SUB_8_24_BIT; |
| 965 | break; |
| 966 | case PCM_FORMAT_S24_3LE: |
| 967 | ret = (audio_format_t)AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED; |
| 968 | break; |
| 969 | default: |
| 970 | break; |
| 971 | } |
| 972 | return ret; |
| 973 | } |
| 974 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 975 | #endif // QCOM_AUDIO_HW_H |