Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1 | /* |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved. |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2014 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 | #define LOG_TAG "audio_hw_utils" |
| 21 | /* #define LOG_NDEBUG 0 */ |
| 22 | |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 23 | #include <inttypes.h> |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <cutils/properties.h> |
| 26 | #include <cutils/config_utils.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <dlfcn.h> |
| 29 | #include <cutils/str_parms.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 30 | #include <log/log.h> |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 31 | #include <cutils/misc.h> |
Vinay Verma | addfa4a | 2018-04-29 14:03:38 +0530 | [diff] [blame] | 32 | #include <unistd.h> |
Surendar Karka | 287348c | 2019-04-10 18:31:46 +0530 | [diff] [blame] | 33 | #include <sys/ioctl.h> |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 34 | |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 35 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 36 | #include "audio_hw.h" |
| 37 | #include "platform.h" |
| 38 | #include "platform_api.h" |
| 39 | #include "audio_extn.h" |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 40 | #include "voice_extn.h" |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 41 | #include "voice.h" |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 42 | #include <sound/compress_params.h> |
| 43 | #include <sound/compress_offload.h> |
Surendar Karka | 287348c | 2019-04-10 18:31:46 +0530 | [diff] [blame] | 44 | #include <sound/devdep_params.h> |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 45 | #include <tinycompress/tinycompress.h> |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 46 | |
| 47 | #ifdef DYNAMIC_LOG_ENABLED |
| 48 | #include <log_xml_parser.h> |
| 49 | #define LOG_MASK HAL_MOD_FILE_UTILS |
| 50 | #include <log_utils.h> |
| 51 | #endif |
| 52 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 53 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 54 | #include "audio_parsers.h" |
| 55 | #endif |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 56 | |
Roopesh Nataraja | 0f68be7 | 2020-04-28 12:32:02 -0700 | [diff] [blame] | 57 | #define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE_NAME "audio_io_policy.conf" |
| 58 | #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE_NAME "audio_output_policy.conf" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 59 | |
| 60 | #define OUTPUTS_TAG "outputs" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 61 | #define INPUTS_TAG "inputs" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 62 | |
| 63 | #define DYNAMIC_VALUE_TAG "dynamic" |
| 64 | #define FLAGS_TAG "flags" |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 65 | #define PROFILES_TAG "profile" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 66 | #define FORMATS_TAG "formats" |
| 67 | #define SAMPLING_RATES_TAG "sampling_rates" |
| 68 | #define BIT_WIDTH_TAG "bit_width" |
| 69 | #define APP_TYPE_TAG "app_type" |
| 70 | |
| 71 | #define STRING_TO_ENUM(string) { #string, string } |
| 72 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 73 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 74 | #define BASE_TABLE_SIZE 64 |
| 75 | #define MAX_BASEINDEX_LEN 256 |
| 76 | |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 77 | #ifndef SND_AUDIOCODEC_TRUEHD |
| 78 | #define SND_AUDIOCODEC_TRUEHD 0x00000023 |
| 79 | #endif |
| 80 | |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 81 | #define APP_TYPE_VOIP_AUDIO 0x1113A |
| 82 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 83 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 84 | #define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */ |
| 85 | #define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */ |
| 86 | #define SR_44100 (0<<0) /* 44.1kHz */ |
| 87 | #define SR_NOTID (1<<0) /* non indicated */ |
| 88 | #define SR_48000 (2<<0) /* 48kHz */ |
| 89 | #define SR_32000 (3<<0) /* 32kHz */ |
| 90 | #define SR_22050 (4<<0) /* 22.05kHz */ |
| 91 | #define SR_24000 (6<<0) /* 24kHz */ |
| 92 | #define SR_88200 (8<<0) /* 88.2kHz */ |
| 93 | #define SR_96000 (10<<0) /* 96kHz */ |
| 94 | #define SR_176400 (12<<0) /* 176.4kHz */ |
| 95 | #define SR_192000 (14<<0) /* 192kHz */ |
| 96 | |
| 97 | #endif |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 98 | |
| 99 | /* ToDo: Check and update a proper value in msec */ |
Weiyin Jiang | c49a3b5 | 2018-08-17 16:16:08 +0800 | [diff] [blame] | 100 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50 |
| 101 | #define PCM_OFFLOAD_PLAYBACK_DSP_PATHDELAY 62 |
Samyak Jain | 2546f8a | 2019-08-29 19:24:21 +0530 | [diff] [blame] | 102 | #define PCM_OFFLOAD_PLAYBACK_LATENCY PCM_OFFLOAD_PLAYBACK_DSP_PATHDELAY |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 103 | |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 104 | #ifndef MAX_CHANNELS_SUPPORTED |
| 105 | #define MAX_CHANNELS_SUPPORTED 8 |
| 106 | #endif |
| 107 | |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 108 | #ifdef __LP64__ |
| 109 | #define VNDK_FWK_LIB_PATH "/vendor/lib64/libqti_vndfwk_detect.so" |
| 110 | #else |
| 111 | #define VNDK_FWK_LIB_PATH "/vendor/lib/libqti_vndfwk_detect.so" |
| 112 | #endif |
| 113 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 114 | typedef struct vndkfwk_s { |
| 115 | void *lib_handle; |
| 116 | int (*isVendorEnhancedFwk)(void); |
| 117 | int (*getVendorEnhancedInfo)(void); |
| 118 | const char *lib_name; |
| 119 | } vndkfwk_t; |
| 120 | |
| 121 | static vndkfwk_t mVndkFwk = { |
| 122 | NULL, NULL, NULL, VNDK_FWK_LIB_PATH}; |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 123 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 124 | typedef struct { |
| 125 | const char *id_string; |
| 126 | const int value; |
| 127 | } mixer_config_lookup; |
| 128 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 129 | struct string_to_enum { |
| 130 | const char *name; |
| 131 | uint32_t value; |
| 132 | }; |
| 133 | |
| 134 | const struct string_to_enum s_flag_name_to_enum_table[] = { |
| 135 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT), |
| 136 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY), |
| 137 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST), |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 138 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 139 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER), |
| 140 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD), |
| 141 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 142 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 143 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 144 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH), |
Naresh Tanniru | ee3499a | 2017-01-05 14:05:35 +0530 | [diff] [blame] | 145 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_TIMESTAMP), |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 146 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_VOIP_RX), |
Ben Romberger | 6c4d381 | 2017-06-13 17:46:45 -0700 | [diff] [blame] | 147 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_BD), |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 148 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INTERACTIVE), |
Derek Chen | 090dfc5 | 2018-03-22 22:15:29 -0400 | [diff] [blame] | 149 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_MEDIA), |
| 150 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_SYS_NOTIFICATION), |
| 151 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NAV_GUIDANCE), |
| 152 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PHONE), |
Derek Chen | 1bcdc6b | 2020-02-06 22:44:53 -0800 | [diff] [blame] | 153 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FRONT_PASSENGER), |
Derek Chen | df05eea | 2019-08-01 13:57:49 -0700 | [diff] [blame] | 154 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_REAR_SEAT), |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 155 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE), |
| 156 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST), |
| 157 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD), |
| 158 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW), |
| 159 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC), |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 160 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP), |
Dhananjay Kumar | 704ce6f | 2017-09-28 22:08:00 +0530 | [diff] [blame] | 161 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_COMPRESS), |
Ralf Herz | aec8026 | 2018-07-03 07:08:49 +0200 | [diff] [blame] | 162 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_PASSTHROUGH), |
George Gao | 3d47708 | 2020-09-17 22:29:07 -0700 | [diff] [blame] | 163 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_MMAP_NOIRQ), |
| 164 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_VOIP_TX), |
| 165 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_AV_SYNC), |
| 166 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_DIRECT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | const struct string_to_enum s_format_name_to_enum_table[] = { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 170 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 171 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT), |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 172 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED), |
| 173 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT), |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 174 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 175 | STRING_TO_ENUM(AUDIO_FORMAT_MP3), |
| 176 | STRING_TO_ENUM(AUDIO_FORMAT_AAC), |
| 177 | STRING_TO_ENUM(AUDIO_FORMAT_VORBIS), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 178 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB), |
| 179 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 180 | STRING_TO_ENUM(AUDIO_FORMAT_AC3), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 181 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 182 | STRING_TO_ENUM(AUDIO_FORMAT_DTS), |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 183 | STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD), |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 184 | STRING_TO_ENUM(AUDIO_FORMAT_DOLBY_TRUEHD), |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 185 | STRING_TO_ENUM(AUDIO_FORMAT_IEC61937), |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 186 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 187 | STRING_TO_ENUM(AUDIO_FORMAT_WMA), |
| 188 | STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO), |
| 189 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 190 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS), |
| 191 | STRING_TO_ENUM(AUDIO_FORMAT_EVRC), |
| 192 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCB), |
| 193 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB), |
| 194 | STRING_TO_ENUM(AUDIO_FORMAT_QCELP), |
| 195 | STRING_TO_ENUM(AUDIO_FORMAT_MP2), |
| 196 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW), |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 197 | STRING_TO_ENUM(AUDIO_FORMAT_FLAC), |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 198 | STRING_TO_ENUM(AUDIO_FORMAT_ALAC), |
| 199 | STRING_TO_ENUM(AUDIO_FORMAT_APE), |
Alexy Joseph | cd8eaed | 2014-12-11 12:46:53 -0800 | [diff] [blame] | 200 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC), |
| 201 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1), |
| 202 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2), |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 203 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS), |
Ashish Jain | e513a87 | 2015-11-19 17:00:56 +0530 | [diff] [blame] | 204 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC), |
| 205 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1), |
| 206 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2), |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 207 | STRING_TO_ENUM(AUDIO_FORMAT_DSD), |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 208 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM), |
| 209 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC), |
| 210 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1), |
| 211 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2), |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 212 | STRING_TO_ENUM(AUDIO_FORMAT_APTX), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 215 | /* payload structure avt_device drift query */ |
| 216 | struct audio_avt_device_drift_stats { |
| 217 | uint32_t minor_version; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 218 | |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 219 | /* Indicates the device interface direction as either |
| 220 | * source (Tx) or sink (Rx). |
| 221 | */ |
| 222 | uint16_t device_direction; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 223 | |
| 224 | /* Reference timer for drift accumulation and time stamp information. |
| 225 | * currently it only support AFE_REF_TIMER_TYPE_AVTIMER |
| 226 | */ |
| 227 | uint16_t reference_timer; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 228 | struct audio_avt_device_drift_param drift_param; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 229 | } __attribute__((packed)); |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 230 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 231 | static char bTable[BASE_TABLE_SIZE] = { |
| 232 | 'A','B','C','D','E','F','G','H','I','J','K','L', |
| 233 | 'M','N','O','P','Q','R','S','T','U','V','W','X', |
| 234 | 'Y','Z','a','b','c','d','e','f','g','h','i','j', |
| 235 | 'k','l','m','n','o','p','q','r','s','t','u','v', |
| 236 | 'w','x','y','z','0','1','2','3','4','5','6','7', |
| 237 | '8','9','+','/' |
| 238 | }; |
| 239 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 240 | static uint32_t string_to_enum(const struct string_to_enum *table, size_t size, |
| 241 | const char *name) |
| 242 | { |
| 243 | size_t i; |
| 244 | for (i = 0; i < size; i++) { |
| 245 | if (strcmp(table[i].name, name) == 0) { |
| 246 | ALOGV("%s found %s", __func__, table[i].name); |
| 247 | return table[i].value; |
| 248 | } |
| 249 | } |
George Gao | 3d47708 | 2020-09-17 22:29:07 -0700 | [diff] [blame] | 250 | ALOGE("%s cound not find %s", __func__, name); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 254 | static audio_io_flags_t parse_flag_names(char *name) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 255 | { |
| 256 | uint32_t flag = 0; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 257 | audio_io_flags_t io_flags; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 258 | char *last_r; |
| 259 | char *flag_name = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 260 | while (flag_name != NULL) { |
| 261 | if (strlen(flag_name) != 0) { |
| 262 | flag |= string_to_enum(s_flag_name_to_enum_table, |
| 263 | ARRAY_SIZE(s_flag_name_to_enum_table), |
| 264 | flag_name); |
| 265 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 266 | flag_name = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 269 | ALOGV("parse_flag_names: flag - %x", flag); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 270 | io_flags.in_flags = (audio_input_flags_t)flag; |
| 271 | io_flags.out_flags = (audio_output_flags_t)flag; |
| 272 | return io_flags; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 275 | static void parse_format_names(char *name, struct streams_io_cfg *s_info) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 276 | { |
| 277 | struct stream_format *sf_info = NULL; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 278 | char *last_r; |
| 279 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 280 | |
| 281 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) |
| 282 | return; |
| 283 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 284 | list_init(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 285 | while (str != NULL) { |
| 286 | audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table, |
| 287 | ARRAY_SIZE(s_format_name_to_enum_table), str); |
| 288 | ALOGV("%s: format - %d", __func__, format); |
| 289 | if (format != 0) { |
| 290 | sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 291 | if (sf_info == NULL) |
| 292 | break; /* return whatever was parsed */ |
| 293 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 294 | sf_info->format = format; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 295 | list_add_tail(&s_info->format_list, &sf_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 296 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 297 | str = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 301 | static void parse_sample_rate_names(char *name, struct streams_io_cfg *s_info) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 302 | { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 303 | struct stream_sample_rate *ss_info = NULL; |
| 304 | uint32_t sample_rate = 48000; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 305 | char *last_r; |
| 306 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 307 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 308 | if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG)) |
| 309 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 310 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 311 | list_init(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 312 | while (str != NULL) { |
| 313 | sample_rate = (uint32_t)strtol(str, (char **)NULL, 10); |
| 314 | ALOGV("%s: sample_rate - %d", __func__, sample_rate); |
| 315 | if (0 != sample_rate) { |
| 316 | ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate)); |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 317 | if (!ss_info) { |
| 318 | ALOGE("%s: memory allocation failure", __func__); |
| 319 | return; |
| 320 | } |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 321 | ss_info->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 322 | list_add_tail(&s_info->sample_rate_list, &ss_info->list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 323 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 324 | str = strtok_r(NULL, "|", &last_r); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 325 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static int parse_bit_width_names(char *name) |
| 329 | { |
| 330 | int bit_width = 16; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 331 | char *last_r; |
| 332 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 333 | |
| 334 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 335 | bit_width = (int)strtol(str, (char **)NULL, 10); |
| 336 | |
| 337 | ALOGV("%s: bit_width - %d", __func__, bit_width); |
| 338 | return bit_width; |
| 339 | } |
| 340 | |
| 341 | static int parse_app_type_names(void *platform, char *name) |
| 342 | { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 343 | int app_type = platform_get_default_app_type(platform); |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 344 | char *last_r; |
| 345 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 346 | |
| 347 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 348 | app_type = (int)strtol(str, (char **)NULL, 10); |
| 349 | |
| 350 | ALOGV("%s: app_type - %d", __func__, app_type); |
| 351 | return app_type; |
| 352 | } |
| 353 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 354 | static void update_streams_cfg_list(cnode *root, void *platform, |
| 355 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 356 | { |
| 357 | cnode *node = root->first_child; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 358 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 359 | |
| 360 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 361 | s_info = (struct streams_io_cfg *)calloc(1, sizeof(struct streams_io_cfg)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 362 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 363 | if (!s_info) { |
| 364 | ALOGE("failed to allocate mem for s_info list element"); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 365 | return; |
| 366 | } |
| 367 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 368 | while (node) { |
| 369 | if (strcmp(node->name, FLAGS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 370 | s_info->flags = parse_flag_names((char *)node->value); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 371 | } else if (strcmp(node->name, PROFILES_TAG) == 0) { |
| 372 | strlcpy(s_info->profile, (char *)node->value, sizeof(s_info->profile)); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 373 | } else if (strcmp(node->name, FORMATS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 374 | parse_format_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 375 | } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 376 | s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 377 | parse_sample_rate_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 378 | } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 379 | s_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 380 | } else if (strcmp(node->name, APP_TYPE_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 381 | s_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 382 | } |
| 383 | node = node->next; |
| 384 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 385 | list_add_tail(streams_cfg_list, &s_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 388 | static void load_cfg_list(cnode *root, void *platform, |
| 389 | struct listnode *streams_output_cfg_list, |
| 390 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 391 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 392 | cnode *node = NULL; |
| 393 | |
| 394 | node = config_find(root, OUTPUTS_TAG); |
| 395 | if (node != NULL) { |
| 396 | node = node->first_child; |
| 397 | while (node) { |
| 398 | ALOGV("%s: loading output %s", __func__, node->name); |
| 399 | update_streams_cfg_list(node, platform, streams_output_cfg_list); |
| 400 | node = node->next; |
| 401 | } |
| 402 | } else { |
| 403 | ALOGI("%s: could not load output, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 406 | node = config_find(root, INPUTS_TAG); |
| 407 | if (node != NULL) { |
| 408 | node = node->first_child; |
| 409 | while (node) { |
| 410 | ALOGV("%s: loading input %s", __func__, node->name); |
| 411 | update_streams_cfg_list(node, platform, streams_input_cfg_list); |
| 412 | node = node->next; |
| 413 | } |
| 414 | } else { |
| 415 | ALOGI("%s: could not load input, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | static void send_app_type_cfg(void *platform, struct mixer *mixer, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 420 | struct listnode *streams_output_cfg_list, |
| 421 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 422 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 423 | size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0}; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 424 | int length = 0, i, num_app_types = 0; |
| 425 | struct listnode *node; |
| 426 | bool update; |
| 427 | struct mixer_ctl *ctl = NULL; |
| 428 | const char *mixer_ctl_name = "App Type Config"; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 429 | struct streams_io_cfg *s_info = NULL; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 430 | uint32_t target_bit_width = 0; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 431 | |
| 432 | if (!mixer) { |
| 433 | ALOGE("%s: mixer is null",__func__); |
| 434 | return; |
| 435 | } |
| 436 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 437 | if (!ctl) { |
| 438 | ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); |
| 439 | return; |
| 440 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 441 | app_type_cfg[length++] = num_app_types; |
| 442 | |
| 443 | if (list_empty(streams_output_cfg_list)) { |
| 444 | app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_PLAYBACK); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 445 | app_type_cfg[length++] = 48000; |
| 446 | app_type_cfg[length++] = 16; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 447 | num_app_types += 1; |
| 448 | } |
| 449 | if (list_empty(streams_input_cfg_list)) { |
| 450 | app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 451 | app_type_cfg[length++] = 48000; |
| 452 | app_type_cfg[length++] = 16; |
| 453 | num_app_types += 1; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 456 | /* get target bit width for ADM enforce mode */ |
| 457 | target_bit_width = adev_get_dsp_bit_width_enforce_mode(); |
| 458 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 459 | list_for_each(node, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 460 | s_info = node_to_item(node, struct streams_io_cfg, list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 461 | update = true; |
| 462 | for (i=0; i<length; i=i+3) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 463 | if (app_type_cfg[i+1] == 0) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 464 | break; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 465 | else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) { |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 466 | if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate) |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 467 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 468 | if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width) |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 469 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 470 | /* ADM bit width = max(enforce_bit_width, bit_width from s_info */ |
| 471 | if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) && |
| 472 | (target_bit_width > app_type_cfg[i+3])) |
| 473 | app_type_cfg[i+3] = target_bit_width; |
| 474 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 475 | update = false; |
| 476 | break; |
| 477 | } |
| 478 | } |
| 479 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 480 | num_app_types += 1; |
| 481 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 482 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 483 | app_type_cfg[length] = s_info->app_type_cfg.bit_width; |
| 484 | if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) && |
| 485 | (target_bit_width > app_type_cfg[length])) |
| 486 | app_type_cfg[length] = target_bit_width; |
| 487 | |
| 488 | length++; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | list_for_each(node, streams_input_cfg_list) { |
| 492 | s_info = node_to_item(node, struct streams_io_cfg, list); |
| 493 | update = true; |
| 494 | for (i=0; i<length; i=i+3) { |
| 495 | if (app_type_cfg[i+1] == 0) |
| 496 | break; |
| 497 | else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) { |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 498 | if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate) |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 499 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 500 | if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width) |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 501 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
| 502 | update = false; |
| 503 | break; |
| 504 | } |
| 505 | } |
| 506 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
| 507 | num_app_types += 1; |
| 508 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 509 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
| 510 | app_type_cfg[length++] = s_info->app_type_cfg.bit_width; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | ALOGV("%s: num_app_types: %d", __func__, num_app_types); |
| 514 | if (num_app_types) { |
| 515 | app_type_cfg[0] = num_app_types; |
| 516 | mixer_ctl_set_array(ctl, app_type_cfg, length); |
| 517 | } |
| 518 | } |
| 519 | |
Roopesh Nataraja | 0f68be7 | 2020-04-28 12:32:02 -0700 | [diff] [blame] | 520 | /* Function to retrieve audio vendor configs path */ |
| 521 | void audio_get_vendor_config_path (char* config_file_path, int path_size) |
| 522 | { |
| 523 | char vendor_sku[PROPERTY_VALUE_MAX] = {'\0'}; |
| 524 | if (property_get("ro.boot.product.vendor.sku", vendor_sku, "") <= 0) { |
| 525 | #ifdef LINUX_ENABLED |
| 526 | /* Audio configs are stored in /etc */ |
| 527 | snprintf(config_file_path, path_size, "%s", "/etc"); |
| 528 | #else |
| 529 | /* Audio configs are stored in /vendor/etc */ |
| 530 | snprintf(config_file_path, path_size, "%s", "/vendor/etc"); |
| 531 | #endif |
| 532 | } else { |
| 533 | /* Audio configs are stored in /vendor/etc/audio/sku_${vendor_sku} */ |
| 534 | snprintf(config_file_path, path_size, |
| 535 | "%s%s", "/vendor/etc/audio/sku_", vendor_sku); |
| 536 | } |
| 537 | } |
| 538 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 539 | void audio_extn_utils_update_streams_cfg_lists(void *platform, |
| 540 | struct mixer *mixer, |
| 541 | struct listnode *streams_output_cfg_list, |
| 542 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 543 | { |
| 544 | cnode *root; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 545 | char *data = NULL; |
Roopesh Nataraja | 0f68be7 | 2020-04-28 12:32:02 -0700 | [diff] [blame] | 546 | char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH]; |
| 547 | char audio_io_policy_file[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
| 548 | char audio_output_policy_file[VENDOR_CONFIG_FILE_MAX_LENGTH]; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 549 | |
| 550 | ALOGV("%s", __func__); |
| 551 | list_init(streams_output_cfg_list); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 552 | list_init(streams_input_cfg_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 553 | |
| 554 | root = config_node("", ""); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 555 | if (root == NULL) { |
| 556 | ALOGE("cfg_list, NULL config root"); |
| 557 | return; |
| 558 | } |
| 559 | |
Roopesh Nataraja | 0f68be7 | 2020-04-28 12:32:02 -0700 | [diff] [blame] | 560 | /* Get path for audio configuration files in vendor */ |
| 561 | audio_get_vendor_config_path(vendor_config_path, |
| 562 | sizeof(vendor_config_path)); |
| 563 | |
| 564 | /* Get path for audio_io_policy_file in vendor */ |
| 565 | snprintf(audio_io_policy_file, sizeof(audio_io_policy_file), |
| 566 | "%s/%s", vendor_config_path, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE_NAME); |
| 567 | |
| 568 | /* Load audio_io_policy_file from vendor */ |
| 569 | data = (char *)load_file(audio_io_policy_file, NULL); |
| 570 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 571 | if (data == NULL) { |
| 572 | ALOGD("%s: failed to open io config file(%s), trying older config file", |
Roopesh Nataraja | 0f68be7 | 2020-04-28 12:32:02 -0700 | [diff] [blame] | 573 | __func__, audio_io_policy_file); |
| 574 | |
| 575 | /* Get path for audio_output_policy_file in vendor */ |
| 576 | snprintf(audio_output_policy_file, sizeof(audio_output_policy_file), |
| 577 | "%s/%s", vendor_config_path, |
| 578 | AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE_NAME); |
| 579 | |
| 580 | /* Load audio_output_policy_file from vendor */ |
| 581 | data = (char *)load_file(audio_output_policy_file, NULL); |
| 582 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 583 | if (data == NULL) { |
| 584 | send_app_type_cfg(platform, mixer, |
| 585 | streams_output_cfg_list, |
| 586 | streams_input_cfg_list); |
| 587 | ALOGE("%s: could not load io policy config!", __func__); |
yidongh | 6eb4f75 | 2017-04-19 18:20:57 +0800 | [diff] [blame] | 588 | free(root); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 589 | return; |
| 590 | } |
| 591 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 592 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 593 | config_load(root, data); |
| 594 | load_cfg_list(root, platform, streams_output_cfg_list, |
| 595 | streams_input_cfg_list); |
| 596 | |
| 597 | send_app_type_cfg(platform, mixer, streams_output_cfg_list, |
| 598 | streams_input_cfg_list); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 599 | |
| 600 | config_free(root); |
yidongh | 6eb4f75 | 2017-04-19 18:20:57 +0800 | [diff] [blame] | 601 | free(root); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 602 | free(data); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 605 | static void audio_extn_utils_dump_streams_cfg_list( |
| 606 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 607 | { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 608 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 609 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 610 | struct stream_format *sf_info; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 611 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 612 | |
| 613 | list_for_each(node_i, streams_cfg_list) { |
| 614 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 615 | ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d", |
| 616 | __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate, |
| 617 | s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type); |
| 618 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 619 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 620 | ALOGV("format-%x", sf_info->format); |
| 621 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 622 | list_for_each(node_j, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 623 | ss_info = node_to_item(node_j, struct stream_sample_rate, list); |
| 624 | ALOGV("sample rate-%d", ss_info->sample_rate); |
| 625 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 629 | void audio_extn_utils_dump_streams_cfg_lists( |
| 630 | struct listnode *streams_output_cfg_list, |
| 631 | struct listnode *streams_input_cfg_list) |
| 632 | { |
| 633 | ALOGV("%s", __func__); |
| 634 | audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list); |
| 635 | audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list); |
| 636 | } |
| 637 | |
| 638 | static void audio_extn_utils_release_streams_cfg_list( |
| 639 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 640 | { |
| 641 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 642 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 643 | |
| 644 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 645 | |
| 646 | while (!list_empty(streams_cfg_list)) { |
| 647 | node_i = list_head(streams_cfg_list); |
| 648 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 649 | while (!list_empty(&s_info->format_list)) { |
| 650 | node_j = list_head(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 651 | list_remove(node_j); |
| 652 | free(node_to_item(node_j, struct stream_format, list)); |
| 653 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 654 | while (!list_empty(&s_info->sample_rate_list)) { |
| 655 | node_j = list_head(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 656 | list_remove(node_j); |
| 657 | free(node_to_item(node_j, struct stream_sample_rate, list)); |
| 658 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 659 | list_remove(node_i); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 660 | free(node_to_item(node_i, struct streams_io_cfg, list)); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 664 | void audio_extn_utils_release_streams_cfg_lists( |
| 665 | struct listnode *streams_output_cfg_list, |
| 666 | struct listnode *streams_input_cfg_list) |
| 667 | { |
| 668 | ALOGV("%s", __func__); |
| 669 | audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list); |
| 670 | audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list); |
| 671 | } |
| 672 | |
| 673 | static bool set_app_type_cfg(struct streams_io_cfg *s_info, |
| 674 | struct stream_app_type_cfg *app_type_cfg, |
| 675 | uint32_t sample_rate, uint32_t bit_width) |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 676 | { |
| 677 | struct listnode *node_i; |
| 678 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 679 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 680 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 681 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 682 | (bit_width == s_info->app_type_cfg.bit_width)) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 683 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 684 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 685 | app_type_cfg->sample_rate = ss_info->sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 686 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 687 | ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d", |
| 688 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 689 | return true; |
| 690 | } |
| 691 | } |
| 692 | /* |
| 693 | * Reiterate through the list assuming dafault sample rate. |
| 694 | * Handles scenario where input sample rate is higher |
| 695 | * than all sample rates in list for the input bit width. |
| 696 | */ |
| 697 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 698 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 699 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 700 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 701 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 702 | (bit_width == s_info->app_type_cfg.bit_width)) { |
| 703 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 704 | app_type_cfg->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 705 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 706 | ALOGV("%s Assuming sample rate. app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d", |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 707 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 708 | return true; |
| 709 | } |
| 710 | } |
| 711 | return false; |
| 712 | } |
| 713 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 714 | void audio_extn_utils_update_stream_input_app_type_cfg(void *platform, |
| 715 | struct listnode *streams_input_cfg_list, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 716 | struct listnode *devices __unused, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 717 | audio_input_flags_t flags, |
| 718 | audio_format_t format, |
| 719 | uint32_t sample_rate, |
| 720 | uint32_t bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 721 | char* profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 722 | struct stream_app_type_cfg *app_type_cfg) |
| 723 | { |
| 724 | struct listnode *node_i, *node_j; |
| 725 | struct streams_io_cfg *s_info; |
| 726 | struct stream_format *sf_info; |
| 727 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 728 | ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s", |
| 729 | __func__, flags, format, sample_rate, profile); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 730 | |
| 731 | list_for_each(node_i, streams_input_cfg_list) { |
| 732 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 733 | /* Along with flags do profile matching if set at either end.*/ |
| 734 | if (s_info->flags.in_flags == flags && |
| 735 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 736 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 737 | list_for_each(node_j, &s_info->format_list) { |
| 738 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 739 | if (sf_info->format == format) { |
| 740 | if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width)) |
| 741 | return; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | ALOGW("%s: App type could not be selected. Falling back to default", __func__); |
| 747 | app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 748 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 749 | app_type_cfg->bit_width = 16; |
| 750 | } |
| 751 | |
| 752 | void audio_extn_utils_update_stream_output_app_type_cfg(void *platform, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 753 | struct listnode *streams_output_cfg_list, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 754 | struct listnode *devices, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 755 | audio_output_flags_t flags, |
| 756 | audio_format_t format, |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 757 | uint32_t sample_rate, |
| 758 | uint32_t bit_width, |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 759 | audio_channel_mask_t channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 760 | char *profile, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 761 | struct stream_app_type_cfg *app_type_cfg) |
| 762 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 763 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 764 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 765 | struct stream_format *sf_info; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 766 | char value[PROPERTY_VALUE_MAX] = {0}; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 767 | |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 768 | if (compare_device_type(devices, AUDIO_DEVICE_OUT_SPEAKER)) { |
Ramu Gottipati | 074fa4d | 2018-09-11 20:05:51 +0530 | [diff] [blame] | 769 | int bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER); |
| 770 | if ((-ENOSYS != bw) && (bit_width > (uint32_t)bw)) |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 771 | bit_width = (uint32_t)bw; |
Ramu Gottipati | 074fa4d | 2018-09-11 20:05:51 +0530 | [diff] [blame] | 772 | else if (-ENOSYS == bw) |
| 773 | bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 774 | sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Aniket Kumar Lata | d13758f | 2020-08-06 15:11:36 -0700 | [diff] [blame] | 775 | ALOGV("%s Allowing 24 and above bits playback on speaker \ |
| 776 | ONLY at default sampling rate", __func__); |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 779 | property_get("vendor.audio.playback.mch.downsample",value,""); |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 780 | if (!strncmp("true", value, sizeof("true"))) { |
| 781 | if ((popcount(channel_mask) > 2) && |
| 782 | (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 783 | !(flags & (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) { |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 784 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 785 | ALOGD("%s: MCH session defaulting sample rate to %d", |
| 786 | __func__, sample_rate); |
| 787 | } |
| 788 | } |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 789 | |
| 790 | /* Set sampling rate to 176.4 for DSD64 |
| 791 | * and 352.8Khz for DSD128. |
| 792 | * Set Bit Width to 16. output will be 16 bit |
| 793 | * post DoP in ASM. |
| 794 | */ |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 795 | if ((flags & (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) && |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 796 | (format == AUDIO_FORMAT_DSD)) { |
| 797 | bit_width = 16; |
| 798 | if (sample_rate == INPUT_SAMPLING_RATE_DSD64) |
| 799 | sample_rate = OUTPUT_SAMPLING_RATE_DSD64; |
| 800 | else if (sample_rate == INPUT_SAMPLING_RATE_DSD128) |
| 801 | sample_rate = OUTPUT_SAMPLING_RATE_DSD128; |
| 802 | } |
| 803 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 804 | |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 805 | ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d", |
| 806 | __func__, flags, format, sample_rate, profile, app_type_cfg->app_type); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 807 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 808 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 809 | /* Along with flags do profile matching if set at either end.*/ |
| 810 | if (s_info->flags.out_flags == flags && |
| 811 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 812 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 813 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 814 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 815 | if (sf_info->format == format) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 816 | if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width)) |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 817 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 823 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 824 | if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 825 | ALOGV("Compatible output profile not found."); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 826 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
| 827 | app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate; |
| 828 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 829 | ALOGV("%s Default to primary output: App type: %d sample_rate %d", |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 830 | __func__, s_info->app_type_cfg.app_type, app_type_cfg->sample_rate); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 831 | return; |
| 832 | } |
| 833 | } |
| 834 | ALOGW("%s: App type could not be selected. Falling back to default", __func__); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 835 | app_type_cfg->app_type = platform_get_default_app_type(platform); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 836 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 837 | app_type_cfg->bit_width = 16; |
| 838 | } |
| 839 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 840 | static bool audio_is_this_native_usecase(struct audio_usecase *uc) |
| 841 | { |
| 842 | bool native_usecase = false; |
| 843 | struct stream_out *out = (struct stream_out*) uc->stream.out; |
| 844 | |
| 845 | if (PCM_PLAYBACK == uc->type && out != NULL && |
| 846 | NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() && |
| 847 | is_offload_usecase(uc->id) && |
| 848 | (out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) |
| 849 | native_usecase = true; |
| 850 | |
| 851 | return native_usecase; |
| 852 | } |
| 853 | |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 854 | bool audio_extn_is_dsp_bit_width_enforce_mode_supported(audio_output_flags_t flags) |
| 855 | { |
| 856 | /* DSP bitwidth enforce mode for ADM and AFE: |
| 857 | * includes: |
| 858 | * deep buffer, low latency, direct pcm and offload. |
| 859 | * excludes: |
| 860 | * ull(raw+fast), VOIP. |
| 861 | */ |
| 862 | if ((flags & AUDIO_OUTPUT_FLAG_VOIP_RX) || |
| 863 | ((flags & AUDIO_OUTPUT_FLAG_RAW) && |
| 864 | (flags & AUDIO_OUTPUT_FLAG_FAST))) |
| 865 | return false; |
| 866 | |
| 867 | |
| 868 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) || |
| 869 | (flags & AUDIO_OUTPUT_FLAG_DIRECT) || |
| 870 | (flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) || |
| 871 | (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) |
| 872 | return true; |
| 873 | else |
| 874 | return false; |
| 875 | } |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 876 | |
| 877 | static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev)) |
| 878 | { |
| 879 | return adev->vr_audio_mode_enabled; |
| 880 | } |
| 881 | |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 882 | static void audio_extn_btsco_get_sample_rate(int snd_device, int *sample_rate) |
| 883 | { |
| 884 | switch (snd_device) { |
| 885 | case SND_DEVICE_OUT_BT_SCO: |
| 886 | case SND_DEVICE_IN_BT_SCO_MIC: |
| 887 | case SND_DEVICE_IN_BT_SCO_MIC_NREC: |
| 888 | *sample_rate = 8000; |
| 889 | break; |
| 890 | case SND_DEVICE_OUT_BT_SCO_WB: |
| 891 | case SND_DEVICE_IN_BT_SCO_MIC_WB: |
| 892 | case SND_DEVICE_IN_BT_SCO_MIC_WB_NREC: |
| 893 | *sample_rate = 16000; |
| 894 | break; |
| 895 | default: |
Aniket Kumar Lata | d13758f | 2020-08-06 15:11:36 -0700 | [diff] [blame] | 896 | ALOGV("%s:Not a BT SCO device, need not update sampling rate\n", __func__); |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 897 | break; |
| 898 | } |
| 899 | } |
| 900 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 901 | void audio_extn_utils_update_stream_app_type_cfg_for_usecase( |
| 902 | struct audio_device *adev, |
| 903 | struct audio_usecase *usecase) |
| 904 | { |
| 905 | ALOGV("%s", __func__); |
| 906 | |
| 907 | switch(usecase->type) { |
| 908 | case PCM_PLAYBACK: |
| 909 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 910 | &adev->streams_output_cfg_list, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 911 | &usecase->stream.out->device_list, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 912 | usecase->stream.out->flags, |
Aalique Grahame | 65780b5 | 2017-09-27 14:59:56 -0700 | [diff] [blame] | 913 | usecase->stream.out->hal_op_format, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 914 | usecase->stream.out->sample_rate, |
| 915 | usecase->stream.out->bit_width, |
| 916 | usecase->stream.out->channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 917 | usecase->stream.out->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 918 | &usecase->stream.out->app_type_cfg); |
| 919 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type); |
| 920 | break; |
| 921 | case PCM_CAPTURE: |
Revathi Uddaraju | d9f23d9 | 2020-07-27 10:55:06 +0530 | [diff] [blame] | 922 | if (usecase->id == USECASE_AUDIO_RECORD_VOIP |
| 923 | || usecase->id == USECASE_AUDIO_RECORD_VOIP_LOW_LATENCY) |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 924 | usecase->stream.in->app_type_cfg.app_type = APP_TYPE_VOIP_AUDIO; |
| 925 | else |
| 926 | audio_extn_utils_update_stream_input_app_type_cfg(adev->platform, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 927 | &adev->streams_input_cfg_list, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 928 | &usecase->stream.in->device_list, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 929 | usecase->stream.in->flags, |
| 930 | usecase->stream.in->format, |
| 931 | usecase->stream.in->sample_rate, |
| 932 | usecase->stream.in->bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 933 | usecase->stream.in->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 934 | &usecase->stream.in->app_type_cfg); |
| 935 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type); |
| 936 | break; |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 937 | case TRANSCODE_LOOPBACK_RX : |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 938 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 939 | &adev->streams_output_cfg_list, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 940 | &usecase->stream.inout->out_config.device_list, |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 941 | 0, |
| 942 | usecase->stream.inout->out_config.format, |
| 943 | usecase->stream.inout->out_config.sample_rate, |
| 944 | usecase->stream.inout->out_config.bit_width, |
| 945 | usecase->stream.inout->out_config.channel_mask, |
| 946 | usecase->stream.inout->profile, |
| 947 | &usecase->stream.inout->out_app_type_cfg); |
| 948 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.inout->out_app_type_cfg.app_type); |
| 949 | break; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 950 | case PCM_HFP_CALL: |
| 951 | switch (usecase->id) { |
| 952 | case USECASE_AUDIO_HFP_SCO: |
| 953 | case USECASE_AUDIO_HFP_SCO_WB: |
| 954 | audio_extn_btsco_get_sample_rate(usecase->out_snd_device, |
| 955 | &usecase->out_app_type_cfg.sample_rate); |
Derek Chen | d730701 | 2019-11-12 12:10:41 -0500 | [diff] [blame] | 956 | usecase->in_app_type_cfg.sample_rate = usecase->out_app_type_cfg.sample_rate; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 957 | break; |
| 958 | case USECASE_AUDIO_HFP_SCO_DOWNLINK: |
| 959 | case USECASE_AUDIO_HFP_SCO_WB_DOWNLINK: |
| 960 | audio_extn_btsco_get_sample_rate(usecase->in_snd_device, |
| 961 | &usecase->in_app_type_cfg.sample_rate); |
Derek Chen | d730701 | 2019-11-12 12:10:41 -0500 | [diff] [blame] | 962 | usecase->out_app_type_cfg.sample_rate = usecase->in_app_type_cfg.sample_rate; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 963 | break; |
| 964 | default: |
| 965 | ALOGE("%s: usecase id (%d) not supported, use default sample rate", |
| 966 | __func__, usecase->id); |
| 967 | usecase->in_app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 968 | usecase->out_app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 969 | break; |
| 970 | } |
| 971 | /* update out_app_type_cfg */ |
| 972 | usecase->out_app_type_cfg.bit_width = |
| 973 | platform_get_snd_device_bit_width(usecase->out_snd_device); |
| 974 | usecase->out_app_type_cfg.app_type = |
| 975 | platform_get_default_app_type_v2(adev->platform, PCM_PLAYBACK); |
| 976 | /* update in_app_type_cfg */ |
| 977 | usecase->in_app_type_cfg.bit_width = |
| 978 | platform_get_snd_device_bit_width(usecase->in_snd_device); |
| 979 | usecase->in_app_type_cfg.app_type = |
| 980 | platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE); |
| 981 | ALOGV("%s Selected apptype: playback %d capture %d", |
| 982 | __func__, usecase->out_app_type_cfg.app_type, usecase->in_app_type_cfg.app_type); |
| 983 | break; |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame^] | 984 | case ICC_CALL: |
| 985 | /* ICC usecase: Loopback from TERT_TDM_TX to TERT_TDM_RX */ |
| 986 | /* update out_app_type_cfg */ |
| 987 | usecase->out_app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 988 | usecase->out_app_type_cfg.bit_width = platform_get_snd_device_bit_width(usecase->out_snd_device); |
| 989 | usecase->out_app_type_cfg.app_type = platform_get_default_app_type_v2(adev->platform, PCM_PLAYBACK); |
| 990 | /* update in_app_type_cfg */ |
| 991 | usecase->in_app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 992 | usecase->in_app_type_cfg.bit_width = platform_get_snd_device_bit_width(usecase->in_snd_device); |
| 993 | usecase->in_app_type_cfg.app_type = platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE); |
| 994 | |
| 995 | ALOGV("%s Selected apptype: playback %d capture %d", |
| 996 | __func__, usecase->out_app_type_cfg.app_type, usecase->in_app_type_cfg.app_type); |
| 997 | break; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 998 | default: |
| 999 | ALOGE("%s: app type cfg not supported for usecase type (%d)", |
| 1000 | __func__, usecase->type); |
| 1001 | } |
| 1002 | } |
| 1003 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1004 | static int set_stream_app_type_mixer_ctrl(struct audio_device *adev, |
| 1005 | int pcm_device_id, int app_type, |
| 1006 | int acdb_dev_id, int sample_rate, |
| 1007 | int stream_type, |
| 1008 | snd_device_t snd_device) |
| 1009 | { |
| 1010 | |
| 1011 | char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; |
| 1012 | struct mixer_ctl *ctl; |
| 1013 | int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT], len = 0, rc = 0; |
| 1014 | int snd_device_be_idx = -1; |
| 1015 | |
| 1016 | if (stream_type == PCM_PLAYBACK) { |
| 1017 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 1018 | "Audio Stream %d App Type Cfg", pcm_device_id); |
| 1019 | } else if (stream_type == PCM_CAPTURE) { |
| 1020 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 1021 | "Audio Stream Capture %d App Type Cfg", pcm_device_id); |
| 1022 | } |
| 1023 | |
| 1024 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1025 | if (!ctl) { |
| 1026 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1027 | __func__, mixer_ctl_name); |
| 1028 | rc = -EINVAL; |
| 1029 | goto exit; |
| 1030 | } |
| 1031 | app_type_cfg[len++] = app_type; |
| 1032 | app_type_cfg[len++] = acdb_dev_id; |
| 1033 | app_type_cfg[len++] = sample_rate; |
| 1034 | |
| 1035 | snd_device_be_idx = platform_get_snd_device_backend_index(snd_device); |
| 1036 | if (snd_device_be_idx > 0) |
| 1037 | app_type_cfg[len++] = snd_device_be_idx; |
| 1038 | ALOGV("%s: stream type %d app_type %d, acdb_dev_id %d " |
| 1039 | "sample rate %d, snd_device_be_idx %d", |
| 1040 | __func__, stream_type, app_type, acdb_dev_id, sample_rate, |
| 1041 | snd_device_be_idx); |
| 1042 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
| 1043 | |
| 1044 | exit: |
| 1045 | return rc; |
| 1046 | } |
| 1047 | |
| 1048 | static int audio_extn_utils_send_app_type_cfg_hfp(struct audio_device *adev, |
| 1049 | struct audio_usecase *usecase) |
| 1050 | { |
| 1051 | int pcm_device_id, acdb_dev_id = 0, snd_device = usecase->out_snd_device; |
| 1052 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1053 | int app_type = 0, rc = 0; |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1054 | bool is_bus_dev_usecase = false; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1055 | |
| 1056 | ALOGV("%s", __func__); |
| 1057 | |
| 1058 | if (usecase->type != PCM_HFP_CALL) { |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1059 | ALOGV("%s: not a HFP path, no need to cfg app type", __func__); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1060 | rc = 0; |
| 1061 | goto exit_send_app_type_cfg; |
| 1062 | } |
| 1063 | if ((usecase->id != USECASE_AUDIO_HFP_SCO) && |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1064 | (usecase->id != USECASE_AUDIO_HFP_SCO_WB) && |
| 1065 | (usecase->id != USECASE_AUDIO_HFP_SCO_DOWNLINK) && |
| 1066 | (usecase->id != USECASE_AUDIO_HFP_SCO_WB_DOWNLINK)) { |
| 1067 | ALOGV("%s: a usecase where app type cfg is not required", __func__); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1068 | rc = 0; |
| 1069 | goto exit_send_app_type_cfg; |
| 1070 | } |
| 1071 | |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 1072 | if (compare_device_type(&usecase->device_list, AUDIO_DEVICE_OUT_BUS)) |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1073 | is_bus_dev_usecase = true; |
| 1074 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1075 | snd_device = usecase->out_snd_device; |
| 1076 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
| 1077 | |
| 1078 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1079 | if (acdb_dev_id < 0) { |
| 1080 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1081 | rc = -EINVAL; |
| 1082 | goto exit_send_app_type_cfg; |
| 1083 | } |
| 1084 | |
| 1085 | if (usecase->type == PCM_HFP_CALL) { |
| 1086 | |
| 1087 | /* config HFP session:1 playback path */ |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1088 | if (is_bus_dev_usecase) { |
| 1089 | app_type = usecase->out_app_type_cfg.app_type; |
| 1090 | sample_rate= usecase->out_app_type_cfg.sample_rate; |
| 1091 | } else { |
| 1092 | snd_device = SND_DEVICE_NONE; // use legacy behavior |
| 1093 | app_type = platform_get_default_app_type_v2(adev->platform, PCM_PLAYBACK); |
| 1094 | sample_rate= CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 1095 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1096 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1097 | acdb_dev_id, sample_rate, |
| 1098 | PCM_PLAYBACK, |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1099 | snd_device); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1100 | if (rc < 0) |
| 1101 | goto exit_send_app_type_cfg; |
| 1102 | |
| 1103 | /* config HFP session:1 capture path */ |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1104 | if (is_bus_dev_usecase) { |
| 1105 | snd_device = usecase->in_snd_device; |
| 1106 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
| 1107 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1108 | if (acdb_dev_id < 0) { |
| 1109 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1110 | rc = -EINVAL; |
| 1111 | goto exit_send_app_type_cfg; |
| 1112 | } |
| 1113 | app_type = usecase->in_app_type_cfg.app_type; |
| 1114 | sample_rate= usecase->in_app_type_cfg.sample_rate; |
| 1115 | } else { |
| 1116 | snd_device = SND_DEVICE_NONE; // use legacy behavior |
| 1117 | app_type = platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE); |
| 1118 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1119 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1120 | acdb_dev_id, sample_rate, |
| 1121 | PCM_CAPTURE, |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1122 | snd_device); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1123 | if (rc < 0) |
| 1124 | goto exit_send_app_type_cfg; |
| 1125 | |
Derek Chen | f709279 | 2017-05-23 12:23:53 -0400 | [diff] [blame] | 1126 | if (is_bus_dev_usecase) |
| 1127 | goto exit_send_app_type_cfg; |
| 1128 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1129 | /* config HFP session:2 capture path */ |
| 1130 | pcm_device_id = HFP_ASM_RX_TX; |
| 1131 | snd_device = usecase->in_snd_device; |
| 1132 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1133 | if (acdb_dev_id <= 0) { |
| 1134 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1135 | rc = -EINVAL; |
| 1136 | goto exit_send_app_type_cfg; |
| 1137 | } |
| 1138 | app_type = platform_get_default_app_type_v2(adev->platform, PCM_CAPTURE); |
| 1139 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1140 | acdb_dev_id, sample_rate, PCM_CAPTURE, |
| 1141 | SND_DEVICE_NONE); |
| 1142 | if (rc < 0) |
| 1143 | goto exit_send_app_type_cfg; |
| 1144 | |
| 1145 | /* config HFP session:2 playback path */ |
| 1146 | app_type = platform_get_default_app_type_v2(adev->platform, PCM_PLAYBACK); |
| 1147 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1148 | acdb_dev_id, sample_rate, |
| 1149 | PCM_PLAYBACK, SND_DEVICE_NONE); |
| 1150 | if (rc < 0) |
| 1151 | goto exit_send_app_type_cfg; |
| 1152 | } |
| 1153 | |
| 1154 | rc = 0; |
| 1155 | exit_send_app_type_cfg: |
| 1156 | return rc; |
| 1157 | } |
| 1158 | |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame^] | 1159 | int audio_extn_utils_send_app_type_cfg_icc(struct audio_device *adev, |
| 1160 | struct audio_usecase *usecase) |
| 1161 | { |
| 1162 | int pcm_device_id, acdb_dev_id = 0, snd_device = usecase->out_snd_device; |
| 1163 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1164 | int app_type = 0, rc = 0; |
| 1165 | |
| 1166 | ALOGV("%s", __func__); |
| 1167 | |
| 1168 | if (usecase->type != ICC_CALL) { |
| 1169 | ALOGV("%s: not an ICC path, no need to cfg app type", __func__); |
| 1170 | rc = 0; |
| 1171 | goto exit_send_app_type_cfg; |
| 1172 | } |
| 1173 | if (usecase->id != USECASE_ICC_CALL) { |
| 1174 | ALOGV("%s: a usecase where app type cfg is not required", __func__); |
| 1175 | rc = 0; |
| 1176 | goto exit_send_app_type_cfg; |
| 1177 | } |
| 1178 | |
| 1179 | snd_device = usecase->out_snd_device; |
| 1180 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
| 1181 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1182 | if (acdb_dev_id < 0) { |
| 1183 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1184 | rc = -EINVAL; |
| 1185 | goto exit_send_app_type_cfg; |
| 1186 | } |
| 1187 | /* config ICC session: playback path */ |
| 1188 | app_type = usecase->out_app_type_cfg.app_type; |
| 1189 | sample_rate= usecase->out_app_type_cfg.sample_rate; |
| 1190 | |
| 1191 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1192 | acdb_dev_id, sample_rate, |
| 1193 | PCM_PLAYBACK, |
| 1194 | snd_device); |
| 1195 | if (rc < 0) |
| 1196 | goto exit_send_app_type_cfg; |
| 1197 | |
| 1198 | /* config ICC session: capture path */ |
| 1199 | snd_device = usecase->in_snd_device; |
| 1200 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
| 1201 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1202 | if (acdb_dev_id < 0) { |
| 1203 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1204 | rc = -EINVAL; |
| 1205 | goto exit_send_app_type_cfg; |
| 1206 | } |
| 1207 | app_type = usecase->in_app_type_cfg.app_type; |
| 1208 | sample_rate= usecase->in_app_type_cfg.sample_rate; |
| 1209 | rc = set_stream_app_type_mixer_ctrl(adev, pcm_device_id, app_type, |
| 1210 | acdb_dev_id, sample_rate, |
| 1211 | PCM_CAPTURE, |
| 1212 | snd_device); |
| 1213 | exit_send_app_type_cfg: |
| 1214 | return rc; |
| 1215 | } |
| 1216 | |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1217 | int audio_extn_utils_get_app_sample_rate_for_device( |
| 1218 | struct audio_device *adev, |
| 1219 | struct audio_usecase *usecase, int snd_device) |
| 1220 | { |
| 1221 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 1222 | int sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1223 | |
| 1224 | if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) { |
| 1225 | property_get("vendor.audio.playback.mch.downsample",value,""); |
| 1226 | if (!strncmp("true", value, sizeof("true"))) { |
| 1227 | if ((popcount(usecase->stream.out->channel_mask) > 2) && |
| 1228 | (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
| 1229 | !(usecase->stream.out->flags & |
| 1230 | (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) |
| 1231 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 1232 | } |
| 1233 | |
| 1234 | if (usecase->id == USECASE_AUDIO_PLAYBACK_VOIP) { |
| 1235 | usecase->stream.out->app_type_cfg.sample_rate = usecase->stream.out->sample_rate; |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 1236 | } else if (compare_device_type(&usecase->stream.out->device_list, |
| 1237 | AUDIO_DEVICE_OUT_SPEAKER)) { |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1238 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 1239 | } else if ((snd_device == SND_DEVICE_OUT_HDMI || |
| 1240 | snd_device == SND_DEVICE_OUT_USB_HEADSET || |
| 1241 | snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && |
| 1242 | (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) { |
| 1243 | /* |
| 1244 | * To best utlize DSP, check if the stream sample rate is supported/multiple of |
| 1245 | * configured device sample rate, if not update the COPP rate to be equal to the |
| 1246 | * device sample rate, else open COPP at stream sample rate |
| 1247 | */ |
| 1248 | platform_check_and_update_copp_sample_rate(adev->platform, snd_device, |
| 1249 | usecase->stream.out->sample_rate, |
| 1250 | &usecase->stream.out->app_type_cfg.sample_rate); |
| 1251 | } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && |
| 1252 | !audio_is_this_native_usecase(usecase)) && |
| 1253 | usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || |
| 1254 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
| 1255 | /* Reset to default if no native stream is active*/ |
| 1256 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Zhou Song | 9e9b381 | 2019-12-30 17:52:10 +0800 | [diff] [blame] | 1257 | } else if (usecase->out_snd_device == SND_DEVICE_OUT_BT_A2DP || |
| 1258 | usecase->out_snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP || |
| 1259 | usecase->out_snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP) { |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1260 | /* |
| 1261 | * For a2dp playback get encoder sampling rate and set copp sampling rate, |
| 1262 | * for bit width use the stream param only. |
| 1263 | */ |
| 1264 | audio_extn_a2dp_get_enc_sample_rate(&usecase->stream.out->app_type_cfg.sample_rate); |
| 1265 | ALOGI("%s using %d sample rate rate for A2DP CoPP", |
| 1266 | __func__, usecase->stream.out->app_type_cfg.sample_rate); |
| 1267 | } |
| 1268 | audio_extn_btsco_get_sample_rate(snd_device, &usecase->stream.out->app_type_cfg.sample_rate); |
| 1269 | sample_rate = usecase->stream.out->app_type_cfg.sample_rate; |
| 1270 | |
| 1271 | if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) || |
| 1272 | (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) || |
| 1273 | (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD)) |
| 1274 | && audio_extn_passthru_is_passthrough_stream(usecase->stream.out) |
| 1275 | && !audio_extn_passthru_is_convert_supported(adev, usecase->stream.out)) { |
| 1276 | sample_rate = sample_rate * 4; |
| 1277 | if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE) |
| 1278 | sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE; |
| 1279 | } |
| 1280 | } else if (usecase->type == PCM_CAPTURE) { |
| 1281 | if (usecase->stream.in != NULL) { |
Revathi Uddaraju | d9f23d9 | 2020-07-27 10:55:06 +0530 | [diff] [blame] | 1282 | if (usecase->id == USECASE_AUDIO_RECORD_VOIP |
| 1283 | || usecase->id == USECASE_AUDIO_RECORD_VOIP_LOW_LATENCY) |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1284 | usecase->stream.in->app_type_cfg.sample_rate = usecase->stream.in->sample_rate; |
| 1285 | if (voice_is_in_call_rec_stream(usecase->stream.in)) { |
| 1286 | audio_extn_btsco_get_sample_rate(usecase->in_snd_device, |
| 1287 | &usecase->stream.in->app_type_cfg.sample_rate); |
| 1288 | } else { |
| 1289 | audio_extn_btsco_get_sample_rate(snd_device, |
| 1290 | &usecase->stream.in->app_type_cfg.sample_rate); |
| 1291 | } |
| 1292 | sample_rate = usecase->stream.in->app_type_cfg.sample_rate; |
| 1293 | } else if (usecase->id == USECASE_AUDIO_SPKR_CALIB_TX) { |
Sujin Panicker | b6d7626 | 2019-09-09 10:55:38 +0530 | [diff] [blame] | 1294 | if ((property_get("vendor.audio.spkr_prot.tx.sampling_rate", value, NULL) > 0)) |
| 1295 | sample_rate = atoi(value); |
| 1296 | else |
| 1297 | sample_rate = SAMPLE_RATE_8000; |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1298 | } |
| 1299 | } else if (usecase->type == TRANSCODE_LOOPBACK_RX) { |
| 1300 | sample_rate = usecase->stream.inout->out_config.sample_rate; |
| 1301 | } |
| 1302 | return sample_rate; |
| 1303 | } |
| 1304 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1305 | static int send_app_type_cfg_for_device(struct audio_device *adev, |
| 1306 | struct audio_usecase *usecase, |
| 1307 | int split_snd_device) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1308 | { |
| 1309 | char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1310 | size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0}; |
| 1311 | int len = 0, rc; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1312 | struct mixer_ctl *ctl; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1313 | int pcm_device_id = 0, acdb_dev_id, app_type; |
| 1314 | int snd_device = split_snd_device, snd_device_be_idx = -1; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 1315 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1316 | struct streams_io_cfg *s_info = NULL; |
| 1317 | struct listnode *node = NULL; |
Nikhil Laturkar | ac4a749 | 2017-08-31 18:27:19 +0530 | [diff] [blame] | 1318 | int bd_app_type = 0; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1319 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1320 | ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s", |
| 1321 | __func__, platform_get_snd_device_name(usecase->out_snd_device), |
| 1322 | platform_get_snd_device_name(usecase->in_snd_device), |
| 1323 | platform_get_snd_device_name(split_snd_device)); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1324 | |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1325 | if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE && |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 1326 | usecase->type != TRANSCODE_LOOPBACK_RX) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1327 | ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1328 | rc = 0; |
| 1329 | goto exit_send_app_type_cfg; |
| 1330 | } |
| 1331 | if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) && |
Vignesh Kulothungan | 0a2eff0 | 2019-07-11 16:30:13 -0700 | [diff] [blame] | 1332 | (usecase->id != USECASE_AUDIO_PLAYBACK_WITH_HAPTICS) && |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1333 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) && |
| 1334 | (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) && |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 1335 | (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) && |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 1336 | (usecase->id != USECASE_AUDIO_PLAYBACK_VOIP) && |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 1337 | (usecase->id != USECASE_AUDIO_TRANSCODE_LOOPBACK_RX) && |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1338 | (!is_interactive_usecase(usecase->id)) && |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 1339 | (!is_offload_usecase(usecase->id)) && |
Derek Chen | f6318be | 2017-06-12 17:16:24 -0400 | [diff] [blame] | 1340 | (usecase->type != PCM_CAPTURE) && |
| 1341 | (!audio_extn_auto_hal_is_bus_device_usecase(usecase->id))) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1342 | ALOGV("%s: a rx/tx/loopback path where app type cfg is not required %d", __func__, usecase->id); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1343 | rc = 0; |
| 1344 | goto exit_send_app_type_cfg; |
| 1345 | } |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 1346 | |
| 1347 | //if VR is active then only send the mixer control |
| 1348 | if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) { |
| 1349 | ALOGI("ULL doesnt need sending app type cfg, returning"); |
| 1350 | rc = 0; |
| 1351 | goto exit_send_app_type_cfg; |
| 1352 | } |
| 1353 | |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 1354 | if (usecase->type == PCM_PLAYBACK || usecase->type == TRANSCODE_LOOPBACK_RX) { |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 1355 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1356 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 1357 | "Audio Stream %d App Type Cfg", pcm_device_id); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 1358 | } else if (usecase->type == PCM_CAPTURE) { |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 1359 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1360 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 1361 | "Audio Stream Capture %d App Type Cfg", pcm_device_id); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 1362 | } |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1363 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1364 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1365 | if (!ctl) { |
| 1366 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, |
| 1367 | mixer_ctl_name); |
| 1368 | rc = -EINVAL; |
| 1369 | goto exit_send_app_type_cfg; |
| 1370 | } |
Aditya Bavanari | 701a699 | 2017-03-30 19:17:16 +0530 | [diff] [blame] | 1371 | snd_device = platform_get_spkr_prot_snd_device(snd_device); |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 1372 | if (voice_is_in_call_rec_stream(usecase->stream.in) && usecase->type == PCM_CAPTURE) { |
| 1373 | snd_device_t voice_device = voice_get_incall_rec_snd_device(usecase->in_snd_device); |
| 1374 | acdb_dev_id = platform_get_snd_device_acdb_id(voice_device); |
| 1375 | ALOGV("acdb id for voice call use case %d", acdb_dev_id); |
| 1376 | } else { |
| 1377 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 1378 | } |
Rohit Kumar | 1181b29 | 2017-01-31 18:07:17 +0530 | [diff] [blame] | 1379 | if (acdb_dev_id <= 0) { |
| 1380 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 1381 | rc = -EINVAL; |
| 1382 | goto exit_send_app_type_cfg; |
| 1383 | } |
| 1384 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1385 | snd_device_be_idx = platform_get_snd_device_backend_index(snd_device); |
| 1386 | if (snd_device_be_idx < 0) { |
| 1387 | ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d", |
| 1388 | __func__, platform_get_snd_device_name(snd_device), |
| 1389 | snd_device_be_idx); |
| 1390 | } |
| 1391 | |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1392 | sample_rate = audio_extn_utils_get_app_sample_rate_for_device(adev, usecase, snd_device); |
| 1393 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1394 | if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) { |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1395 | /* Interactive streams are supported with only direct app type id. |
| 1396 | * Get Direct profile app type and use it for interactive streams |
| 1397 | */ |
| 1398 | list_for_each(node, &adev->streams_output_cfg_list) { |
| 1399 | s_info = node_to_item(node, struct streams_io_cfg, list); |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 1400 | if (s_info->flags.out_flags == (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_BD | |
Nikhil Laturkar | ac4a749 | 2017-08-31 18:27:19 +0530 | [diff] [blame] | 1401 | AUDIO_OUTPUT_FLAG_DIRECT_PCM | |
| 1402 | AUDIO_OUTPUT_FLAG_DIRECT)) |
| 1403 | bd_app_type = s_info->app_type_cfg.app_type; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1404 | } |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 1405 | if (usecase->stream.out->flags == (audio_output_flags_t)AUDIO_OUTPUT_FLAG_INTERACTIVE) |
Nikhil Laturkar | ac4a749 | 2017-08-31 18:27:19 +0530 | [diff] [blame] | 1406 | app_type = bd_app_type; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1407 | else |
| 1408 | app_type = usecase->stream.out->app_type_cfg.app_type; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1409 | app_type_cfg[len++] = app_type; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 1410 | app_type_cfg[len++] = acdb_dev_id; |
Naresh Tanniru | 3a40677 | 2017-05-10 13:09:05 -0700 | [diff] [blame] | 1411 | app_type_cfg[len++] = sample_rate; |
| 1412 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1413 | if (snd_device_be_idx > 0) |
| 1414 | app_type_cfg[len++] = snd_device_be_idx; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1415 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1416 | ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1417 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1418 | |
| 1419 | } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) { |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1420 | app_type = usecase->stream.in->app_type_cfg.app_type; |
| 1421 | app_type_cfg[len++] = app_type; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1422 | app_type_cfg[len++] = acdb_dev_id; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1423 | app_type_cfg[len++] = sample_rate; |
| 1424 | if (snd_device_be_idx > 0) |
| 1425 | app_type_cfg[len++] = snd_device_be_idx; |
| 1426 | ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1427 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1428 | } else { |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1429 | app_type = platform_get_default_app_type_v2(adev->platform, usecase->type); |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 1430 | if(usecase->type == TRANSCODE_LOOPBACK_RX) { |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1431 | app_type = usecase->stream.inout->out_app_type_cfg.app_type; |
| 1432 | } |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1433 | app_type_cfg[len++] = app_type; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1434 | app_type_cfg[len++] = acdb_dev_id; |
| 1435 | app_type_cfg[len++] = sample_rate; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1436 | if (snd_device_be_idx > 0) |
| 1437 | app_type_cfg[len++] = snd_device_be_idx; |
| 1438 | ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1439 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Ashish Jain | c02430d | 2016-01-04 10:42:43 +0530 | [diff] [blame] | 1440 | } |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1441 | |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1442 | if(ctl) |
| 1443 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
Zhou Song | d9bd930 | 2020-08-04 16:34:45 +0800 | [diff] [blame] | 1444 | |
| 1445 | /* send app type cfg for haptics */ |
| 1446 | if (usecase->id == USECASE_AUDIO_PLAYBACK_WITH_HAPTICS) { |
| 1447 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 1448 | "Audio Stream %d App Type Cfg", adev->haptic_pcm_device_id ); |
| 1449 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 1450 | if (!ctl) { |
| 1451 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, |
| 1452 | mixer_ctl_name); |
| 1453 | rc = -EINVAL; |
| 1454 | goto exit_send_app_type_cfg; |
| 1455 | } |
| 1456 | acdb_dev_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_HAPTICS); |
| 1457 | snd_device_be_idx = platform_get_snd_device_backend_index(SND_DEVICE_OUT_HAPTICS); |
| 1458 | /* haptics acdb id */ |
| 1459 | app_type_cfg[1] = acdb_dev_id; |
| 1460 | /* haptics be index */ |
| 1461 | app_type_cfg[3] = snd_device_be_idx; |
| 1462 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
| 1463 | } |
| 1464 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1465 | rc = 0; |
| 1466 | exit_send_app_type_cfg: |
| 1467 | return rc; |
| 1468 | } |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1469 | |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 1470 | static int audio_extn_utils_check_input_parameters(uint32_t sample_rate, |
| 1471 | audio_format_t format, |
| 1472 | int channel_count) |
| 1473 | { |
| 1474 | int ret = 0; |
| 1475 | |
| 1476 | if (((format != AUDIO_FORMAT_PCM_16_BIT) && (format != AUDIO_FORMAT_PCM_8_24_BIT) && |
| 1477 | (format != AUDIO_FORMAT_PCM_24_BIT_PACKED) && (format != AUDIO_FORMAT_PCM_32_BIT) && |
| 1478 | (format != AUDIO_FORMAT_PCM_FLOAT)) && |
| 1479 | !voice_extn_compress_voip_is_format_supported(format) && |
| 1480 | !audio_extn_compr_cap_format_supported(format) && |
| 1481 | !audio_extn_cin_format_supported(format)) |
| 1482 | ret = -EINVAL; |
| 1483 | |
| 1484 | switch (channel_count) { |
| 1485 | case 1: |
| 1486 | case 2: |
| 1487 | case 3: |
| 1488 | case 4: |
| 1489 | case 6: |
| 1490 | case 8: |
| 1491 | break; |
| 1492 | default: |
| 1493 | ret = -EINVAL; |
| 1494 | } |
| 1495 | |
| 1496 | switch (sample_rate) { |
| 1497 | case 8000: |
| 1498 | case 11025: |
| 1499 | case 12000: |
| 1500 | case 16000: |
| 1501 | case 22050: |
| 1502 | case 24000: |
| 1503 | case 32000: |
| 1504 | case 44100: |
| 1505 | case 48000: |
| 1506 | case 88200: |
| 1507 | case 96000: |
| 1508 | case 176400: |
| 1509 | case 192000: |
| 1510 | break; |
| 1511 | default: |
| 1512 | ret = -EINVAL; |
| 1513 | } |
| 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
| 1518 | static inline uint32_t audio_extn_utils_nearest_multiple(uint32_t num, uint32_t multiplier) |
| 1519 | { |
| 1520 | uint32_t remainder = 0; |
| 1521 | |
| 1522 | if (!multiplier) |
| 1523 | return num; |
| 1524 | |
| 1525 | remainder = num % multiplier; |
| 1526 | if (remainder) |
| 1527 | num += (multiplier - remainder); |
| 1528 | |
| 1529 | return num; |
| 1530 | } |
| 1531 | |
| 1532 | static inline uint32_t audio_extn_utils_lcm(uint32_t num1, uint32_t num2) |
| 1533 | { |
| 1534 | uint32_t high = num1, low = num2, temp = 0; |
| 1535 | |
| 1536 | if (!num1 || !num2) |
| 1537 | return 0; |
| 1538 | |
| 1539 | if (num1 < num2) { |
| 1540 | high = num2; |
| 1541 | low = num1; |
| 1542 | } |
| 1543 | |
| 1544 | while (low != 0) { |
| 1545 | temp = low; |
| 1546 | low = high % low; |
| 1547 | high = temp; |
| 1548 | } |
| 1549 | return (num1 * num2)/high; |
| 1550 | } |
| 1551 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1552 | int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, |
| 1553 | struct audio_usecase *usecase) |
| 1554 | { |
| 1555 | int i, num_devices = 0; |
| 1556 | snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0}; |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 1557 | snd_device_t in_snd_device = usecase->in_snd_device; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1558 | int rc = 0; |
| 1559 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1560 | if (usecase->type == PCM_HFP_CALL) { |
| 1561 | return audio_extn_utils_send_app_type_cfg_hfp(adev, usecase); |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame^] | 1562 | } else if (usecase->type == ICC_CALL) { |
| 1563 | return audio_extn_utils_send_app_type_cfg_icc(adev, usecase); |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1566 | switch (usecase->type) { |
| 1567 | case PCM_PLAYBACK: |
Surendar Karka | 93cd25a | 2018-08-28 14:21:37 +0530 | [diff] [blame] | 1568 | case TRANSCODE_LOOPBACK_RX: |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1569 | ALOGD("%s: usecase->out_snd_device %s", |
| 1570 | __func__, platform_get_snd_device_name(usecase->out_snd_device)); |
| 1571 | /* check for out combo device */ |
| 1572 | if (platform_split_snd_device(adev->platform, |
| 1573 | usecase->out_snd_device, |
| 1574 | &num_devices, new_snd_devices)) { |
| 1575 | new_snd_devices[0] = usecase->out_snd_device; |
| 1576 | num_devices = 1; |
| 1577 | } |
| 1578 | break; |
| 1579 | case PCM_CAPTURE: |
| 1580 | ALOGD("%s: usecase->in_snd_device %s", |
| 1581 | __func__, platform_get_snd_device_name(usecase->in_snd_device)); |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 1582 | if (voice_is_in_call_rec_stream(usecase->stream.in)) { |
| 1583 | in_snd_device = voice_get_incall_rec_backend_device(usecase->stream.in); |
| 1584 | } |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1585 | /* check for in combo device */ |
| 1586 | if (platform_split_snd_device(adev->platform, |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 1587 | in_snd_device, |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1588 | &num_devices, new_snd_devices)) { |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 1589 | new_snd_devices[0] = in_snd_device; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1590 | num_devices = 1; |
| 1591 | } |
| 1592 | break; |
| 1593 | default: |
| 1594 | ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__); |
| 1595 | rc = 0; |
| 1596 | break; |
| 1597 | } |
| 1598 | |
| 1599 | for (i = 0; i < num_devices; i++) { |
| 1600 | rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]); |
| 1601 | if (rc) |
| 1602 | break; |
| 1603 | } |
| 1604 | |
| 1605 | return rc; |
| 1606 | } |
| 1607 | |
Preetam Singh Ranawat | 9519e9c | 2015-11-18 16:05:55 +0530 | [diff] [blame] | 1608 | int read_line_from_file(const char *path, char *buf, size_t count) |
| 1609 | { |
| 1610 | char * fgets_ret; |
| 1611 | FILE * fd; |
| 1612 | int rv; |
| 1613 | |
| 1614 | fd = fopen(path, "r"); |
| 1615 | if (fd == NULL) |
| 1616 | return -1; |
| 1617 | |
| 1618 | fgets_ret = fgets(buf, (int)count, fd); |
| 1619 | if (NULL != fgets_ret) { |
| 1620 | rv = (int)strlen(buf); |
| 1621 | } else { |
| 1622 | rv = ferror(fd); |
| 1623 | } |
| 1624 | fclose(fd); |
| 1625 | |
| 1626 | return rv; |
| 1627 | } |
| 1628 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1629 | /*Translates ALSA formats to AOSP PCM formats*/ |
| 1630 | audio_format_t alsa_format_to_hal(uint32_t alsa_format) |
| 1631 | { |
| 1632 | audio_format_t format; |
| 1633 | |
| 1634 | switch(alsa_format) { |
| 1635 | case SNDRV_PCM_FORMAT_S16_LE: |
| 1636 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 1637 | break; |
| 1638 | case SNDRV_PCM_FORMAT_S24_3LE: |
| 1639 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 1640 | break; |
| 1641 | case SNDRV_PCM_FORMAT_S24_LE: |
| 1642 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 1643 | break; |
| 1644 | case SNDRV_PCM_FORMAT_S32_LE: |
| 1645 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 1646 | break; |
| 1647 | default: |
| 1648 | ALOGW("Incorrect ALSA format"); |
| 1649 | format = AUDIO_FORMAT_INVALID; |
| 1650 | } |
| 1651 | return format; |
| 1652 | } |
| 1653 | |
| 1654 | /*Translates hal format (AOSP) to alsa formats*/ |
| 1655 | uint32_t hal_format_to_alsa(audio_format_t hal_format) |
| 1656 | { |
| 1657 | uint32_t alsa_format; |
| 1658 | |
| 1659 | switch (hal_format) { |
| 1660 | case AUDIO_FORMAT_PCM_32_BIT: { |
| 1661 | if (platform_supports_true_32bit()) |
| 1662 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 1663 | else |
| 1664 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1665 | } |
| 1666 | break; |
| 1667 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1668 | alsa_format = SNDRV_PCM_FORMAT_S8; |
| 1669 | break; |
| 1670 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1671 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1672 | break; |
| 1673 | case AUDIO_FORMAT_PCM_8_24_BIT: { |
| 1674 | if (platform_supports_true_32bit()) |
| 1675 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 1676 | else |
| 1677 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1678 | } |
| 1679 | break; |
| 1680 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1681 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1682 | break; |
| 1683 | default: |
| 1684 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1685 | alsa_format = SNDRV_PCM_FORMAT_S16_LE; |
| 1686 | break; |
| 1687 | } |
| 1688 | return alsa_format; |
| 1689 | } |
| 1690 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1691 | /*Translates PCM formats to AOSP formats*/ |
| 1692 | audio_format_t pcm_format_to_hal(uint32_t pcm_format) |
| 1693 | { |
| 1694 | audio_format_t format = AUDIO_FORMAT_INVALID; |
| 1695 | |
| 1696 | switch(pcm_format) { |
| 1697 | case PCM_FORMAT_S16_LE: |
| 1698 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 1699 | break; |
| 1700 | case PCM_FORMAT_S24_3LE: |
| 1701 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 1702 | break; |
| 1703 | case PCM_FORMAT_S24_LE: |
| 1704 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 1705 | break; |
| 1706 | case PCM_FORMAT_S32_LE: |
| 1707 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 1708 | break; |
| 1709 | default: |
| 1710 | ALOGW("Incorrect PCM format"); |
| 1711 | format = AUDIO_FORMAT_INVALID; |
| 1712 | } |
| 1713 | return format; |
| 1714 | } |
| 1715 | |
| 1716 | /*Translates hal format (AOSP) to alsa formats*/ |
| 1717 | uint32_t hal_format_to_pcm(audio_format_t hal_format) |
| 1718 | { |
| 1719 | uint32_t pcm_format; |
| 1720 | |
| 1721 | switch (hal_format) { |
| 1722 | case AUDIO_FORMAT_PCM_32_BIT: |
| 1723 | case AUDIO_FORMAT_PCM_8_24_BIT: |
| 1724 | case AUDIO_FORMAT_PCM_FLOAT: { |
| 1725 | if (platform_supports_true_32bit()) |
| 1726 | pcm_format = PCM_FORMAT_S32_LE; |
| 1727 | else |
| 1728 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1729 | } |
| 1730 | break; |
| 1731 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1732 | pcm_format = PCM_FORMAT_S8; |
| 1733 | break; |
| 1734 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1735 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1736 | break; |
| 1737 | default: |
| 1738 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1739 | pcm_format = PCM_FORMAT_S16_LE; |
| 1740 | break; |
| 1741 | } |
| 1742 | return pcm_format; |
| 1743 | } |
| 1744 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1745 | uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample, |
| 1746 | uint32_t sample_rate, |
Deeraj Soman | 65358ab | 2019-02-07 15:40:49 +0530 | [diff] [blame] | 1747 | uint32_t noOfChannels, |
| 1748 | int64_t duration_ms) |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1749 | { |
| 1750 | uint32_t fragment_size = 0; |
| 1751 | uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION; |
| 1752 | |
Deeraj Soman | 65358ab | 2019-02-07 15:40:49 +0530 | [diff] [blame] | 1753 | if (duration_ms >= MIN_OFFLOAD_BUFFER_DURATION_MS && duration_ms <= MAX_OFFLOAD_BUFFER_DURATION_MS) |
| 1754 | pcm_offload_time = duration_ms; |
| 1755 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1756 | fragment_size = (pcm_offload_time |
| 1757 | * sample_rate |
| 1758 | * bytes_per_sample |
| 1759 | * noOfChannels)/1000; |
| 1760 | if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1761 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1762 | else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1763 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1764 | /*To have same PCM samples for all channels, the buffer size requires to |
| 1765 | *be multiple of (number of channels * bytes per sample) |
| 1766 | *For writes to succeed, the buffer must be written at address which is multiple of 32 |
| 1767 | */ |
Aalique Grahame | b85f2d9 | 2017-10-16 17:53:23 -0700 | [diff] [blame] | 1768 | fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32)); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1769 | |
| 1770 | ALOGI("PCM offload Fragment size to %d bytes", fragment_size); |
| 1771 | return fragment_size; |
| 1772 | } |
| 1773 | |
| 1774 | /* Calculates the fragment size required to configure compress session. |
| 1775 | * Based on the alsa format selected, decide if conversion is needed in |
| 1776 | |
| 1777 | * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to |
| 1778 | * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver. |
| 1779 | */ |
| 1780 | void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out) |
| 1781 | { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1782 | audio_format_t dst_format = out->hal_op_format; |
| 1783 | audio_format_t src_format = out->hal_ip_format; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1784 | uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format); |
| 1785 | uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format); |
| 1786 | |
| 1787 | out->compr_config.fragment_size = |
| 1788 | get_alsa_fragment_size(hal_op_bytes_per_sample, |
| 1789 | out->sample_rate, |
Deeraj Soman | 65358ab | 2019-02-07 15:40:49 +0530 | [diff] [blame] | 1790 | popcount(out->channel_mask), |
| 1791 | out->info.duration_us / 1000); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1792 | |
| 1793 | if ((src_format != dst_format) && |
| 1794 | hal_op_bytes_per_sample != hal_ip_bytes_per_sample) { |
| 1795 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1796 | out->hal_fragment_size = |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1797 | ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) / |
| 1798 | hal_op_bytes_per_sample); |
| 1799 | ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x", |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1800 | out->hal_fragment_size, src_format, dst_format); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1801 | } else { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1802 | out->hal_fragment_size = out->compr_config.fragment_size; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1806 | /* converts pcm format 24_8 to 8_24 inplace */ |
| 1807 | size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes) |
| 1808 | { |
| 1809 | size_t i = 0; |
| 1810 | int *int_buf_stream = buf; |
| 1811 | |
| 1812 | if ((bytes % 4) != 0) { |
| 1813 | ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__); |
| 1814 | return -EINVAL; |
| 1815 | } |
| 1816 | |
| 1817 | for (; i < (bytes / 4); i++) |
| 1818 | int_buf_stream[i] >>= 8; |
| 1819 | |
| 1820 | return bytes; |
| 1821 | } |
| 1822 | |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 1823 | #ifdef AUDIO_GKI_ENABLED |
| 1824 | int get_snd_codec_id(audio_format_t format) |
| 1825 | { |
| 1826 | int id = 0; |
| 1827 | |
| 1828 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 1829 | case AUDIO_FORMAT_MP3: |
| 1830 | id = SND_AUDIOCODEC_MP3; |
| 1831 | break; |
| 1832 | case AUDIO_FORMAT_AAC: |
| 1833 | id = SND_AUDIOCODEC_AAC; |
| 1834 | break; |
| 1835 | case AUDIO_FORMAT_AAC_ADTS: |
| 1836 | id = SND_AUDIOCODEC_AAC; |
| 1837 | break; |
| 1838 | case AUDIO_FORMAT_AAC_LATM: |
| 1839 | id = SND_AUDIOCODEC_AAC; |
| 1840 | break; |
| 1841 | case AUDIO_FORMAT_PCM: |
| 1842 | id = SND_AUDIOCODEC_PCM; |
| 1843 | break; |
| 1844 | case AUDIO_FORMAT_FLAC: |
| 1845 | case AUDIO_FORMAT_ALAC: |
| 1846 | case AUDIO_FORMAT_APE: |
| 1847 | case AUDIO_FORMAT_VORBIS: |
| 1848 | case AUDIO_FORMAT_WMA: |
| 1849 | case AUDIO_FORMAT_WMA_PRO: |
| 1850 | case AUDIO_FORMAT_DSD: |
| 1851 | case AUDIO_FORMAT_APTX: |
| 1852 | id = SND_AUDIOCODEC_BESPOKE; |
| 1853 | break; |
| 1854 | case AUDIO_FORMAT_MP2: |
| 1855 | id = SND_AUDIOCODEC_MP2; |
| 1856 | break; |
| 1857 | case AUDIO_FORMAT_AC3: |
| 1858 | id = SND_AUDIOCODEC_AC3; |
| 1859 | break; |
| 1860 | case AUDIO_FORMAT_E_AC3: |
| 1861 | case AUDIO_FORMAT_E_AC3_JOC: |
| 1862 | id = SND_AUDIOCODEC_EAC3; |
| 1863 | break; |
| 1864 | case AUDIO_FORMAT_DTS: |
| 1865 | case AUDIO_FORMAT_DTS_HD: |
| 1866 | id = SND_AUDIOCODEC_DTS; |
| 1867 | break; |
| 1868 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 1869 | id = SND_AUDIOCODEC_TRUEHD; |
| 1870 | break; |
| 1871 | case AUDIO_FORMAT_IEC61937: |
| 1872 | id = SND_AUDIOCODEC_IEC61937; |
| 1873 | break; |
| 1874 | default: |
| 1875 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
| 1876 | } |
| 1877 | |
| 1878 | return id; |
| 1879 | } |
| 1880 | #else |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1881 | int get_snd_codec_id(audio_format_t format) |
| 1882 | { |
| 1883 | int id = 0; |
| 1884 | |
| 1885 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 1886 | case AUDIO_FORMAT_MP3: |
| 1887 | id = SND_AUDIOCODEC_MP3; |
| 1888 | break; |
| 1889 | case AUDIO_FORMAT_AAC: |
| 1890 | id = SND_AUDIOCODEC_AAC; |
| 1891 | break; |
| 1892 | case AUDIO_FORMAT_AAC_ADTS: |
| 1893 | id = SND_AUDIOCODEC_AAC; |
| 1894 | break; |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 1895 | case AUDIO_FORMAT_AAC_LATM: |
| 1896 | id = SND_AUDIOCODEC_AAC; |
| 1897 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1898 | case AUDIO_FORMAT_PCM: |
| 1899 | id = SND_AUDIOCODEC_PCM; |
| 1900 | break; |
| 1901 | case AUDIO_FORMAT_FLAC: |
| 1902 | id = SND_AUDIOCODEC_FLAC; |
| 1903 | break; |
| 1904 | case AUDIO_FORMAT_ALAC: |
| 1905 | id = SND_AUDIOCODEC_ALAC; |
| 1906 | break; |
| 1907 | case AUDIO_FORMAT_APE: |
| 1908 | id = SND_AUDIOCODEC_APE; |
| 1909 | break; |
| 1910 | case AUDIO_FORMAT_VORBIS: |
| 1911 | id = SND_AUDIOCODEC_VORBIS; |
| 1912 | break; |
| 1913 | case AUDIO_FORMAT_WMA: |
| 1914 | id = SND_AUDIOCODEC_WMA; |
| 1915 | break; |
| 1916 | case AUDIO_FORMAT_WMA_PRO: |
| 1917 | id = SND_AUDIOCODEC_WMA_PRO; |
| 1918 | break; |
Satish Babu Patakokila | 0c31392 | 2016-12-08 12:07:08 +0530 | [diff] [blame] | 1919 | case AUDIO_FORMAT_MP2: |
| 1920 | id = SND_AUDIOCODEC_MP2; |
| 1921 | break; |
Satish Babu Patakokila | 915ecba | 2017-01-10 17:43:56 +0530 | [diff] [blame] | 1922 | case AUDIO_FORMAT_AC3: |
| 1923 | id = SND_AUDIOCODEC_AC3; |
| 1924 | break; |
| 1925 | case AUDIO_FORMAT_E_AC3: |
| 1926 | case AUDIO_FORMAT_E_AC3_JOC: |
| 1927 | id = SND_AUDIOCODEC_EAC3; |
| 1928 | break; |
| 1929 | case AUDIO_FORMAT_DTS: |
| 1930 | case AUDIO_FORMAT_DTS_HD: |
| 1931 | id = SND_AUDIOCODEC_DTS; |
| 1932 | break; |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 1933 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 1934 | id = SND_AUDIOCODEC_TRUEHD; |
| 1935 | break; |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 1936 | case AUDIO_FORMAT_IEC61937: |
| 1937 | id = SND_AUDIOCODEC_IEC61937; |
| 1938 | break; |
Preetam Singh Ranawat | 4277a5a | 2017-01-18 19:02:24 +0530 | [diff] [blame] | 1939 | case AUDIO_FORMAT_DSD: |
| 1940 | id = SND_AUDIOCODEC_DSD; |
| 1941 | break; |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 1942 | case AUDIO_FORMAT_APTX: |
| 1943 | id = SND_AUDIOCODEC_APTX; |
| 1944 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1945 | default: |
| 1946 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
| 1947 | } |
| 1948 | |
| 1949 | return id; |
| 1950 | } |
Xiaojun Sang | 782e5b1 | 2020-06-29 21:13:06 +0800 | [diff] [blame] | 1951 | #endif |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1952 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1953 | void audio_extn_utils_send_audio_calibration(struct audio_device *adev, |
| 1954 | struct audio_usecase *usecase) |
| 1955 | { |
| 1956 | int type = usecase->type; |
| 1957 | |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1958 | if (type == PCM_PLAYBACK && usecase->stream.out != NULL) { |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1959 | platform_send_audio_calibration(adev->platform, usecase, |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1960 | usecase->stream.out->app_type_cfg.app_type); |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1961 | } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1962 | platform_send_audio_calibration(adev->platform, usecase, |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1963 | usecase->stream.in->app_type_cfg.app_type); |
| 1964 | } else if ((type == PCM_HFP_CALL) || (type == PCM_CAPTURE) || |
Derek Chen | a30a5f4 | 2019-12-03 11:17:09 -0500 | [diff] [blame^] | 1965 | (type == TRANSCODE_LOOPBACK_RX && usecase->stream.inout != NULL) || |
| 1966 | (type == ICC_CALL)) { |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1967 | platform_send_audio_calibration(adev->platform, usecase, |
Zhou Song | 06761dd | 2019-04-28 18:08:17 +0800 | [diff] [blame] | 1968 | platform_get_default_app_type_v2(adev->platform, usecase->type)); |
Vidyakumar Athota | e57f600 | 2017-03-01 13:13:16 -0800 | [diff] [blame] | 1969 | } else { |
| 1970 | /* No need to send audio calibration for voice and voip call usecases */ |
| 1971 | if ((type != VOICE_CALL) && (type != VOIP_CALL)) |
| 1972 | ALOGW("%s: No audio calibration for usecase type = %d", __func__, type); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 1976 | // Base64 Encode and Decode |
| 1977 | // Not all features supported. This must be used only with following conditions. |
| 1978 | // Decode Modes: Support with and without padding |
| 1979 | // CRLF not handling. So no CRLF in string to decode. |
| 1980 | // Encode Modes: Supports only padding |
| 1981 | int b64decode(char *inp, int ilen, uint8_t* outp) |
| 1982 | { |
| 1983 | int i, j, k, ii, num; |
| 1984 | int rem, pcnt; |
| 1985 | uint32_t res=0; |
| 1986 | uint8_t getIndex[MAX_BASEINDEX_LEN]; |
| 1987 | uint8_t tmp, cflag; |
| 1988 | |
| 1989 | if(inp == NULL || outp == NULL || ilen <= 0) { |
| 1990 | ALOGE("[%s] received NULL pointer or zero length",__func__); |
| 1991 | return -1; |
| 1992 | } |
| 1993 | |
| 1994 | memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex)); |
| 1995 | for(i=0;i<BASE_TABLE_SIZE;i++) { |
| 1996 | getIndex[(uint8_t)bTable[i]] = (uint8_t)i; |
| 1997 | } |
| 1998 | getIndex[(uint8_t)'=']=0; |
| 1999 | |
| 2000 | j=0;k=0; |
| 2001 | num = ilen/4; |
| 2002 | rem = ilen%4; |
| 2003 | if(rem==0) |
| 2004 | num = num-1; |
| 2005 | cflag=0; |
| 2006 | for(i=0; i<num; i++) { |
| 2007 | res=0; |
| 2008 | for(ii=0;ii<4;ii++) { |
| 2009 | res = res << 6; |
| 2010 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 2011 | res = res | tmp; |
| 2012 | cflag = cflag | tmp; |
| 2013 | } |
| 2014 | outp[k++] = (res >> 16)&0xFF; |
| 2015 | outp[k++] = (res >> 8)&0xFF; |
| 2016 | outp[k++] = res & 0xFF; |
| 2017 | } |
| 2018 | |
| 2019 | // Handle last bytes special |
| 2020 | pcnt=0; |
| 2021 | if(rem == 0) { |
| 2022 | //With padding or full data |
| 2023 | res = 0; |
| 2024 | for(ii=0;ii<4;ii++) { |
| 2025 | if(inp[j] == '=') |
| 2026 | pcnt++; |
| 2027 | res = res << 6; |
| 2028 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 2029 | res = res | tmp; |
| 2030 | cflag = cflag | tmp; |
| 2031 | } |
| 2032 | outp[k++] = res >> 16; |
| 2033 | if(pcnt == 2) |
| 2034 | goto done; |
| 2035 | outp[k++] = (res>>8)&0xFF; |
| 2036 | if(pcnt == 1) |
| 2037 | goto done; |
| 2038 | outp[k++] = res&0xFF; |
| 2039 | } else { |
| 2040 | //without padding |
| 2041 | res = 0; |
| 2042 | for(i=0;i<rem;i++) { |
| 2043 | res = res << 6; |
| 2044 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 2045 | res = res | tmp; |
| 2046 | cflag = cflag | tmp; |
| 2047 | } |
| 2048 | for(i=rem;i<4;i++) { |
| 2049 | res = res << 6; |
| 2050 | pcnt++; |
| 2051 | } |
| 2052 | outp[k++] = res >> 16; |
| 2053 | if(pcnt == 2) |
| 2054 | goto done; |
| 2055 | outp[k++] = (res>>8)&0xFF; |
| 2056 | if(pcnt == 1) |
| 2057 | goto done; |
| 2058 | outp[k++] = res&0xFF; |
| 2059 | } |
| 2060 | done: |
| 2061 | if(cflag == 0xFF) { |
| 2062 | ALOGE("[%s] base64 decode failed. Invalid character found %s", |
| 2063 | __func__, inp); |
| 2064 | return 0; |
| 2065 | } |
| 2066 | return k; |
| 2067 | } |
| 2068 | |
| 2069 | int b64encode(uint8_t *inp, int ilen, char* outp) |
| 2070 | { |
| 2071 | int i,j,k, num; |
| 2072 | int rem=0; |
| 2073 | uint32_t res=0; |
| 2074 | |
| 2075 | if(inp == NULL || outp == NULL || ilen<=0) { |
| 2076 | ALOGE("[%s] received NULL pointer or zero input length",__func__); |
| 2077 | return -1; |
| 2078 | } |
| 2079 | |
| 2080 | num = ilen/3; |
| 2081 | rem = ilen%3; |
| 2082 | j=0;k=0; |
| 2083 | for(i=0; i<num; i++) { |
| 2084 | //prepare index |
| 2085 | res = inp[j++]<<16; |
| 2086 | res = res | inp[j++]<<8; |
| 2087 | res = res | inp[j++]; |
| 2088 | //get output map from index |
| 2089 | outp[k++] = (char) bTable[(res>>18)&0x3F]; |
| 2090 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 2091 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 2092 | outp[k++] = (char) bTable[res&0x3F]; |
| 2093 | } |
| 2094 | |
| 2095 | switch(rem) { |
| 2096 | case 1: |
| 2097 | res = inp[j++]<<16; |
| 2098 | outp[k++] = (char) bTable[res>>18]; |
| 2099 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 2100 | //outp[k++] = '='; |
| 2101 | //outp[k++] = '='; |
| 2102 | break; |
| 2103 | case 2: |
| 2104 | res = inp[j++]<<16; |
| 2105 | res = res | inp[j++]<<8; |
| 2106 | outp[k++] = (char) bTable[res>>18]; |
| 2107 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 2108 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 2109 | //outp[k++] = '='; |
| 2110 | break; |
| 2111 | default: |
| 2112 | break; |
| 2113 | } |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 2114 | outp[k] = '\0'; |
| 2115 | return k; |
| 2116 | } |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2117 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 2118 | |
| 2119 | int audio_extn_utils_get_codec_version(const char *snd_card_name, |
| 2120 | int card_num, |
| 2121 | char *codec_version) |
| 2122 | { |
| 2123 | char procfs_path[50]; |
| 2124 | FILE *fp; |
| 2125 | |
| 2126 | if (strstr(snd_card_name, "tasha")) { |
| 2127 | snprintf(procfs_path, sizeof(procfs_path), |
| 2128 | "/proc/asound/card%d/codecs/tasha/version", card_num); |
| 2129 | if ((fp = fopen(procfs_path, "r")) != NULL) { |
| 2130 | fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp); |
| 2131 | fclose(fp); |
| 2132 | } else { |
| 2133 | ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path); |
| 2134 | return -ENOENT; |
| 2135 | } |
| 2136 | ALOGD("%s: codec version %s", __func__, codec_version); |
| 2137 | } |
| 2138 | |
| 2139 | return 0; |
| 2140 | } |
| 2141 | |
Preetam Singh Ranawat | 9d0d8e4 | 2019-07-15 12:27:25 +0530 | [diff] [blame] | 2142 | int audio_extn_utils_get_codec_variant(int card_num, |
| 2143 | char *codec_variant) |
| 2144 | { |
| 2145 | char procfs_path[50]; |
| 2146 | FILE *fp; |
| 2147 | snprintf(procfs_path, sizeof(procfs_path), |
| 2148 | "/proc/asound/card%d/codecs/wcd938x/variant", card_num); |
| 2149 | if ((fp = fopen(procfs_path, "r")) == NULL) { |
| 2150 | snprintf(procfs_path, sizeof(procfs_path), |
| 2151 | "/proc/asound/card%d/codecs/wcd937x/variant", card_num); |
| 2152 | if ((fp = fopen(procfs_path, "r")) == NULL) { |
| 2153 | ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path); |
| 2154 | return -ENOENT; |
| 2155 | } |
| 2156 | } |
| 2157 | fgets(codec_variant, CODEC_VARIANT_MAX_LENGTH, fp); |
| 2158 | fclose(fp); |
| 2159 | ALOGD("%s: codec variant is %s", __func__, codec_variant); |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 2163 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2164 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 2165 | |
| 2166 | void get_default_compressed_channel_status( |
| 2167 | unsigned char *channel_status) |
| 2168 | { |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2169 | memset(channel_status,0,24); |
| 2170 | |
| 2171 | /* block start bit in preamble bit 3 */ |
| 2172 | channel_status[0] |= PROFESSIONAL; |
| 2173 | //compre out |
| 2174 | channel_status[0] |= NON_LPCM; |
| 2175 | // sample rate; fixed 48K for default/transcode |
| 2176 | channel_status[3] |= SR_48000; |
| 2177 | } |
| 2178 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2179 | int32_t get_compressed_channel_status(void *audio_stream_data, |
| 2180 | uint32_t audio_frame_size, |
| 2181 | unsigned char *channel_status, |
| 2182 | enum audio_parser_code_type codec_type) |
| 2183 | // codec_type - AUDIO_PARSER_CODEC_AC3 |
| 2184 | // - AUDIO_PARSER_CODEC_DTS |
| 2185 | { |
| 2186 | unsigned char *stream; |
| 2187 | int ret = 0; |
| 2188 | stream = (unsigned char *)audio_stream_data; |
| 2189 | |
| 2190 | if (audio_stream_data == NULL || audio_frame_size == 0) { |
| 2191 | ALOGW("no buffer to get channel status, return default for compress"); |
| 2192 | get_default_compressed_channel_status(channel_status); |
| 2193 | return ret; |
| 2194 | } |
| 2195 | |
| 2196 | memset(channel_status,0,24); |
| 2197 | if(init_audio_parser(stream, audio_frame_size, codec_type) == -1) |
| 2198 | { |
| 2199 | ALOGE("init audio parser failed"); |
| 2200 | return -1; |
| 2201 | } |
| 2202 | ret = get_channel_status(channel_status, codec_type); |
| 2203 | return ret; |
| 2204 | |
| 2205 | } |
| 2206 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2207 | void get_lpcm_channel_status(uint32_t sampleRate, |
| 2208 | unsigned char *channel_status) |
| 2209 | { |
| 2210 | int32_t status = 0; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2211 | memset(channel_status,0,24); |
| 2212 | /* block start bit in preamble bit 3 */ |
| 2213 | channel_status[0] |= PROFESSIONAL; |
| 2214 | //LPCM OUT |
| 2215 | channel_status[0] &= ~NON_LPCM; |
| 2216 | |
| 2217 | switch (sampleRate) { |
| 2218 | case 8000: |
| 2219 | case 11025: |
| 2220 | case 12000: |
| 2221 | case 16000: |
| 2222 | case 22050: |
| 2223 | channel_status[3] |= SR_NOTID; |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 2224 | break; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2225 | case 24000: |
| 2226 | channel_status[3] |= SR_24000; |
| 2227 | break; |
| 2228 | case 32000: |
| 2229 | channel_status[3] |= SR_32000; |
| 2230 | break; |
| 2231 | case 44100: |
| 2232 | channel_status[3] |= SR_44100; |
| 2233 | break; |
| 2234 | case 48000: |
| 2235 | channel_status[3] |= SR_48000; |
| 2236 | break; |
| 2237 | case 88200: |
| 2238 | channel_status[3] |= SR_88200; |
| 2239 | break; |
| 2240 | case 96000: |
| 2241 | channel_status[3] |= SR_96000; |
| 2242 | break; |
| 2243 | case 176400: |
| 2244 | channel_status[3] |= SR_176400; |
| 2245 | break; |
| 2246 | case 192000: |
| 2247 | channel_status[3] |= SR_192000; |
| 2248 | break; |
| 2249 | default: |
| 2250 | ALOGV("Invalid sample_rate %u\n", sampleRate); |
| 2251 | status = -1; |
| 2252 | break; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes) |
| 2257 | { |
| 2258 | unsigned char channel_status[24]={0}; |
| 2259 | struct snd_aes_iec958 iec958; |
| 2260 | const char *mixer_ctl_name = "IEC958 Playback PCM Stream"; |
| 2261 | struct mixer_ctl *ctl; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 2262 | ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 2263 | |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 2264 | if (audio_extn_utils_is_dolby_format(out->format) && |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2265 | /*TODO:Extend code to support DTS passthrough*/ |
| 2266 | /*set compressed channel status bits*/ |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 2267 | audio_extn_passthru_is_passthrough_stream(out) && |
| 2268 | audio_extn_is_hdmi_passthru_enabled()) { |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2269 | get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3); |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 2270 | } else { |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 2271 | /*set channel status bit for LPCM*/ |
| 2272 | get_lpcm_channel_status(out->sample_rate, channel_status); |
| 2273 | } |
| 2274 | |
| 2275 | memcpy(iec958.status, channel_status,sizeof(iec958.status)); |
| 2276 | ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name); |
| 2277 | if (!ctl) { |
| 2278 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2279 | __func__, mixer_ctl_name); |
| 2280 | return; |
| 2281 | } |
| 2282 | if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) { |
| 2283 | ALOGE("%s: Could not set channel status for ext HDMI ", |
| 2284 | __func__); |
| 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | } |
| 2289 | #endif |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2290 | |
| 2291 | int audio_extn_utils_get_avt_device_drift( |
| 2292 | struct audio_usecase *usecase, |
| 2293 | struct audio_avt_device_drift_param *drift_param) |
| 2294 | { |
| 2295 | int ret = 0, count = 0; |
| 2296 | char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0}; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2297 | const char *backend = NULL; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2298 | struct mixer_ctl *ctl = NULL; |
| 2299 | struct audio_avt_device_drift_stats drift_stats; |
| 2300 | struct audio_device *adev = NULL; |
| 2301 | |
| 2302 | if (usecase != NULL && usecase->type == PCM_PLAYBACK) { |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2303 | backend = platform_get_snd_device_backend_interface(usecase->out_snd_device); |
| 2304 | if (!backend) { |
| 2305 | ALOGE("%s: Unsupported device %d", __func__, |
Aniket Kumar Lata | 0e6e1e5 | 2019-11-14 21:43:55 -0800 | [diff] [blame] | 2306 | get_device_types(&usecase->stream.out->device_list)); |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2307 | ret = -EINVAL; |
| 2308 | goto done; |
| 2309 | } |
| 2310 | strlcpy(avt_device_drift_mixer_ctl_name, |
| 2311 | backend, |
| 2312 | MIXER_PATH_MAX_LENGTH); |
| 2313 | |
| 2314 | count = strlen(backend); |
| 2315 | if (MIXER_PATH_MAX_LENGTH - count > 0) { |
| 2316 | strlcat(&avt_device_drift_mixer_ctl_name[count], |
| 2317 | " DRIFT", |
| 2318 | MIXER_PATH_MAX_LENGTH - count); |
| 2319 | } else { |
| 2320 | ret = -EINVAL; |
| 2321 | goto done; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2322 | } |
| 2323 | } else { |
Naresh Tanniru | 7586e29 | 2017-04-13 10:38:13 +0530 | [diff] [blame] | 2324 | ALOGE("%s: Invalid usecase",__func__); |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2325 | ret = -EINVAL; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2326 | goto done; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2327 | } |
| 2328 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2329 | adev = usecase->stream.out->dev; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 2330 | ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name); |
| 2331 | if (!ctl) { |
| 2332 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 2333 | __func__, avt_device_drift_mixer_ctl_name); |
| 2334 | |
| 2335 | ret = -EINVAL; |
| 2336 | goto done; |
| 2337 | } |
| 2338 | |
| 2339 | ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__, |
| 2340 | avt_device_drift_mixer_ctl_name); |
| 2341 | |
| 2342 | mixer_ctl_update(ctl); |
| 2343 | count = mixer_ctl_get_num_values(ctl); |
| 2344 | if (count != sizeof(struct audio_avt_device_drift_stats)) { |
| 2345 | ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size", |
| 2346 | __func__); |
| 2347 | |
| 2348 | ret = -EINVAL; |
| 2349 | goto done; |
| 2350 | } |
| 2351 | |
| 2352 | ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count); |
| 2353 | if (ret != 0) { |
| 2354 | ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params", |
| 2355 | __func__); |
| 2356 | |
| 2357 | ret = -EINVAL; |
| 2358 | goto done; |
| 2359 | } |
| 2360 | memcpy(drift_param, &drift_stats.drift_param, |
| 2361 | sizeof(struct audio_avt_device_drift_param)); |
| 2362 | done: |
| 2363 | return ret; |
| 2364 | } |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 2365 | |
| 2366 | #ifdef SNDRV_COMPRESS_PATH_DELAY |
| 2367 | int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out) |
| 2368 | { |
| 2369 | int ret = -EINVAL; |
| 2370 | struct snd_compr_metadata metadata; |
| 2371 | int delay_ms = COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
| 2372 | |
Weiyin Jiang | c49a3b5 | 2018-08-17 16:16:08 +0800 | [diff] [blame] | 2373 | /* override the latency for pcm offload use case */ |
| 2374 | if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT) && |
| 2375 | !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) { |
| 2376 | delay_ms = PCM_OFFLOAD_PLAYBACK_LATENCY; |
| 2377 | } |
| 2378 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 2379 | if (property_get_bool("vendor.audio.playback.dsp.pathdelay", false)) { |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 2380 | ALOGD("%s:: Quering DSP delay %d",__func__, __LINE__); |
| 2381 | if (!(is_offload_usecase(out->usecase))) { |
| 2382 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2383 | goto exit; |
| 2384 | } |
| 2385 | |
| 2386 | if (!out->compr) { |
| 2387 | ALOGD("%s:: Invalid compress handle,returning default dsp latency", |
| 2388 | __func__); |
| 2389 | goto exit; |
| 2390 | } |
| 2391 | |
| 2392 | metadata.key = SNDRV_COMPRESS_PATH_DELAY; |
| 2393 | ret = compress_get_metadata(out->compr, &metadata); |
| 2394 | if(ret) { |
| 2395 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2396 | goto exit; |
| 2397 | } |
| 2398 | delay_ms = metadata.value[0] / 1000; /*convert to ms*/ |
| 2399 | } else { |
| 2400 | ALOGD("%s:: Using Fix DSP delay",__func__); |
| 2401 | } |
| 2402 | |
| 2403 | exit: |
| 2404 | ALOGD("%s:: delay in ms is %d",__func__, delay_ms); |
| 2405 | return delay_ms; |
| 2406 | } |
| 2407 | #else |
| 2408 | int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out __unused) |
| 2409 | { |
| 2410 | return COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
| 2411 | } |
| 2412 | #endif |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 2413 | |
| 2414 | #ifdef SNDRV_COMPRESS_RENDER_MODE |
| 2415 | int audio_extn_utils_compress_set_render_mode(struct stream_out *out) |
| 2416 | { |
| 2417 | struct snd_compr_metadata metadata; |
| 2418 | int ret = -EINVAL; |
| 2419 | |
| 2420 | if (!(is_offload_usecase(out->usecase))) { |
| 2421 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2422 | goto exit; |
| 2423 | } |
| 2424 | |
| 2425 | if (!out->compr) { |
| 2426 | ALOGD("%s:: Invalid compress handle", |
| 2427 | __func__); |
| 2428 | goto exit; |
| 2429 | } |
| 2430 | |
| 2431 | ALOGD("%s:: render mode %d", __func__, out->render_mode); |
| 2432 | |
| 2433 | metadata.key = SNDRV_COMPRESS_RENDER_MODE; |
| 2434 | if (out->render_mode == RENDER_MODE_AUDIO_MASTER) { |
| 2435 | metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_AUDIO_MASTER; |
| 2436 | } else if (out->render_mode == RENDER_MODE_AUDIO_STC_MASTER) { |
| 2437 | metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_STC_MASTER; |
| 2438 | } else { |
| 2439 | ret = 0; |
| 2440 | goto exit; |
| 2441 | } |
| 2442 | ret = compress_set_metadata(out->compr, &metadata); |
| 2443 | if(ret) { |
| 2444 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2445 | } |
| 2446 | exit: |
| 2447 | return ret; |
| 2448 | } |
| 2449 | #else |
| 2450 | int audio_extn_utils_compress_set_render_mode(struct stream_out *out __unused) |
| 2451 | { |
| 2452 | ALOGD("%s:: configuring render mode not supported", __func__); |
| 2453 | return 0; |
| 2454 | } |
| 2455 | #endif |
Manish Dewangan | 5822938 | 2017-02-02 15:48:41 +0530 | [diff] [blame] | 2456 | |
| 2457 | #ifdef SNDRV_COMPRESS_CLK_REC_MODE |
| 2458 | int audio_extn_utils_compress_set_clk_rec_mode( |
| 2459 | struct audio_usecase *usecase) |
| 2460 | { |
| 2461 | struct snd_compr_metadata metadata; |
| 2462 | struct stream_out *out = NULL; |
| 2463 | int ret = -EINVAL; |
| 2464 | |
Naresh Tanniru | 7586e29 | 2017-04-13 10:38:13 +0530 | [diff] [blame] | 2465 | if (usecase == NULL || usecase->type != PCM_PLAYBACK) { |
Manish Dewangan | 5822938 | 2017-02-02 15:48:41 +0530 | [diff] [blame] | 2466 | ALOGE("%s:: Invalid use case", __func__); |
| 2467 | goto exit; |
| 2468 | } |
| 2469 | |
| 2470 | out = usecase->stream.out; |
| 2471 | if (!out) { |
| 2472 | ALOGE("%s:: invalid stream", __func__); |
| 2473 | goto exit; |
| 2474 | } |
| 2475 | |
| 2476 | if (!is_offload_usecase(out->usecase)) { |
| 2477 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2478 | goto exit; |
| 2479 | } |
| 2480 | |
| 2481 | if (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER) { |
| 2482 | ALOGD("%s:: clk recovery is only supported in STC render mode", |
| 2483 | __func__); |
| 2484 | ret = 0; |
| 2485 | goto exit; |
| 2486 | } |
| 2487 | |
| 2488 | if (!out->compr) { |
| 2489 | ALOGD("%s:: Invalid compress handle", |
| 2490 | __func__); |
| 2491 | goto exit; |
| 2492 | } |
| 2493 | metadata.key = SNDRV_COMPRESS_CLK_REC_MODE; |
| 2494 | switch(usecase->out_snd_device) { |
| 2495 | case SND_DEVICE_OUT_HDMI: |
| 2496 | case SND_DEVICE_OUT_SPEAKER_AND_HDMI: |
| 2497 | case SND_DEVICE_OUT_DISPLAY_PORT: |
| 2498 | case SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT: |
| 2499 | metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_NONE; |
| 2500 | break; |
| 2501 | default: |
| 2502 | metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_AUTO; |
| 2503 | break; |
| 2504 | } |
| 2505 | |
| 2506 | ALOGD("%s:: clk recovery mode %d",__func__, metadata.value[0]); |
| 2507 | |
| 2508 | ret = compress_set_metadata(out->compr, &metadata); |
| 2509 | if(ret) { |
| 2510 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2511 | } |
| 2512 | |
| 2513 | exit: |
| 2514 | return ret; |
| 2515 | } |
| 2516 | #else |
| 2517 | int audio_extn_utils_compress_set_clk_rec_mode( |
| 2518 | struct audio_usecase *usecase __unused) |
| 2519 | { |
| 2520 | ALOGD("%s:: configuring render mode not supported", __func__); |
| 2521 | return 0; |
| 2522 | } |
| 2523 | #endif |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 2524 | |
| 2525 | #ifdef SNDRV_COMPRESS_RENDER_WINDOW |
| 2526 | int audio_extn_utils_compress_set_render_window( |
| 2527 | struct stream_out *out, |
| 2528 | struct audio_out_render_window_param *render_window) |
| 2529 | { |
| 2530 | struct snd_compr_metadata metadata; |
| 2531 | int ret = -EINVAL; |
| 2532 | |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 2533 | if(render_window == NULL) { |
| 2534 | ALOGE("%s:: Invalid render_window", __func__); |
| 2535 | goto exit; |
| 2536 | } |
| 2537 | |
Aniket Kumar Lata | 1e1d366 | 2017-06-01 18:45:48 -0700 | [diff] [blame] | 2538 | ALOGD("%s:: render window start 0x%"PRIx64" end 0x%"PRIx64"", |
| 2539 | __func__,render_window->render_ws, render_window->render_we); |
| 2540 | |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 2541 | if (!is_offload_usecase(out->usecase)) { |
| 2542 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2543 | goto exit; |
| 2544 | } |
| 2545 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2546 | if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) && |
| 2547 | (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) { |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 2548 | ALOGD("%s:: only supported in timestamp mode, current " |
| 2549 | "render mode mode %d", __func__, out->render_mode); |
| 2550 | goto exit; |
| 2551 | } |
| 2552 | |
| 2553 | if (!out->compr) { |
| 2554 | ALOGW("%s:: offload session not yet opened," |
| 2555 | "render window will be configure later", __func__); |
| 2556 | /* store render window to reconfigure in start_output_stream() */ |
| 2557 | goto exit; |
| 2558 | } |
| 2559 | |
| 2560 | metadata.key = SNDRV_COMPRESS_RENDER_WINDOW; |
| 2561 | /*render window start value */ |
| 2562 | metadata.value[0] = 0xFFFFFFFF & render_window->render_ws; /* lsb */ |
| 2563 | metadata.value[1] = \ |
| 2564 | (0xFFFFFFFF00000000 & render_window->render_ws) >> 32; /* msb*/ |
| 2565 | /*render window end value */ |
| 2566 | metadata.value[2] = 0xFFFFFFFF & render_window->render_we; /* lsb */ |
| 2567 | metadata.value[3] = \ |
| 2568 | (0xFFFFFFFF00000000 & render_window->render_we) >> 32; /* msb*/ |
| 2569 | |
| 2570 | ret = compress_set_metadata(out->compr, &metadata); |
| 2571 | if(ret) { |
| 2572 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2573 | } |
| 2574 | |
| 2575 | exit: |
| 2576 | return ret; |
| 2577 | } |
| 2578 | #else |
| 2579 | int audio_extn_utils_compress_set_render_window( |
| 2580 | struct stream_out *out __unused, |
| 2581 | struct audio_out_render_window_param *render_window __unused) |
| 2582 | { |
| 2583 | ALOGD("%s:: configuring render window not supported", __func__); |
| 2584 | return 0; |
| 2585 | } |
| 2586 | #endif |
Manish Dewangan | 14956cc | 2017-02-14 18:54:42 +0530 | [diff] [blame] | 2587 | |
| 2588 | #ifdef SNDRV_COMPRESS_START_DELAY |
| 2589 | int audio_extn_utils_compress_set_start_delay( |
| 2590 | struct stream_out *out, |
| 2591 | struct audio_out_start_delay_param *delay_param) |
| 2592 | { |
| 2593 | struct snd_compr_metadata metadata; |
| 2594 | int ret = -EINVAL; |
| 2595 | |
| 2596 | if(delay_param == NULL) { |
| 2597 | ALOGE("%s:: Invalid delay_param", __func__); |
| 2598 | goto exit; |
| 2599 | } |
| 2600 | |
| 2601 | ALOGD("%s:: render start delay 0x%"PRIx64" ", __func__, |
| 2602 | delay_param->start_delay); |
| 2603 | |
| 2604 | if (!is_offload_usecase(out->usecase)) { |
| 2605 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2606 | goto exit; |
| 2607 | } |
| 2608 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2609 | if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) && |
| 2610 | (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) { |
Manish Dewangan | 14956cc | 2017-02-14 18:54:42 +0530 | [diff] [blame] | 2611 | ALOGD("%s:: only supported in timestamp mode, current " |
| 2612 | "render mode mode %d", __func__, out->render_mode); |
| 2613 | goto exit; |
| 2614 | } |
| 2615 | |
| 2616 | if (!out->compr) { |
| 2617 | ALOGW("%s:: offload session not yet opened," |
| 2618 | "start delay will be configure later", __func__); |
| 2619 | goto exit; |
| 2620 | } |
| 2621 | |
| 2622 | metadata.key = SNDRV_COMPRESS_START_DELAY; |
| 2623 | metadata.value[0] = 0xFFFFFFFF & delay_param->start_delay; /* lsb */ |
| 2624 | metadata.value[1] = \ |
| 2625 | (0xFFFFFFFF00000000 & delay_param->start_delay) >> 32; /* msb*/ |
| 2626 | |
| 2627 | ret = compress_set_metadata(out->compr, &metadata); |
| 2628 | if(ret) { |
| 2629 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2630 | } |
| 2631 | |
| 2632 | exit: |
| 2633 | return ret; |
| 2634 | } |
| 2635 | #else |
| 2636 | int audio_extn_utils_compress_set_start_delay( |
| 2637 | struct stream_out *out __unused, |
| 2638 | struct audio_out_start_delay_param *delay_param __unused) |
| 2639 | { |
| 2640 | ALOGD("%s:: configuring render window not supported", __func__); |
| 2641 | return 0; |
| 2642 | } |
| 2643 | #endif |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2644 | |
Surendar Karka | 287348c | 2019-04-10 18:31:46 +0530 | [diff] [blame] | 2645 | #ifdef SNDRV_COMPRESS_DSP_POSITION |
| 2646 | int audio_extn_utils_compress_get_dsp_presentation_pos(struct stream_out *out, |
| 2647 | uint64_t *frames, struct timespec *timestamp, int32_t clock_id) |
| 2648 | { |
| 2649 | int ret = -EINVAL; |
| 2650 | uint64_t *val = NULL; |
| 2651 | uint64_t time = 0; |
| 2652 | struct snd_compr_metadata metadata; |
| 2653 | |
| 2654 | ALOGV("%s:: Quering DSP position with clock id %d",__func__, clock_id); |
| 2655 | metadata.key = SNDRV_COMPRESS_DSP_POSITION; |
| 2656 | metadata.value[0] = clock_id; |
| 2657 | ret = compress_get_metadata(out->compr, &metadata); |
| 2658 | if (ret) { |
| 2659 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2660 | ret = -errno; |
| 2661 | goto exit; |
| 2662 | } |
| 2663 | val = (uint64_t *)&metadata.value[1]; |
| 2664 | *frames = *val; |
| 2665 | time = *(val + 1); |
| 2666 | timestamp->tv_sec = time / 1000000; |
| 2667 | timestamp->tv_nsec = (time % 1000000)*1000; |
| 2668 | |
| 2669 | exit: |
| 2670 | return ret; |
| 2671 | } |
| 2672 | #else |
| 2673 | int audio_extn_utils_compress_get_dsp_presentation_pos(struct stream_out *out __unused, |
| 2674 | uint64_t *frames __unused, struct timespec *timestamp __unused, |
| 2675 | int32_t clock_id __unused) |
| 2676 | { |
| 2677 | ALOGD("%s:: dsp presentation position not supported", __func__); |
| 2678 | return 0; |
| 2679 | |
| 2680 | } |
| 2681 | #endif |
| 2682 | |
| 2683 | #ifdef SNDRV_PCM_IOCTL_DSP_POSITION |
| 2684 | int audio_extn_utils_pcm_get_dsp_presentation_pos(struct stream_out *out, |
| 2685 | uint64_t *frames, struct timespec *timestamp, int32_t clock_id) |
| 2686 | { |
| 2687 | int ret = -EINVAL; |
| 2688 | uint64_t time = 0; |
| 2689 | struct snd_pcm_prsnt_position prsnt_position; |
| 2690 | |
| 2691 | ALOGV("%s:: Quering DSP position with clock id %d",__func__, clock_id); |
| 2692 | prsnt_position.clock_id = clock_id; |
| 2693 | ret = pcm_ioctl(out->pcm, SNDRV_PCM_IOCTL_DSP_POSITION, &prsnt_position); |
| 2694 | if (ret) { |
| 2695 | ALOGE("%s::error %d", __func__, ret); |
| 2696 | ret = -EIO; |
| 2697 | goto exit; |
| 2698 | } |
| 2699 | |
| 2700 | *frames = prsnt_position.frames; |
| 2701 | time = prsnt_position.timestamp; |
| 2702 | timestamp->tv_sec = time / 1000000; |
| 2703 | timestamp->tv_nsec = (time % 1000000)*1000; |
| 2704 | |
| 2705 | exit: |
| 2706 | return ret; |
| 2707 | } |
| 2708 | #else |
| 2709 | int audio_extn_utils_pcm_get_dsp_presentation_pos(struct stream_out *out __unused, |
| 2710 | uint64_t *frames __unused, struct timespec *timestamp __unused, |
| 2711 | int32_t clock_id __unused) |
| 2712 | { |
| 2713 | ALOGD("%s:: dsp presentation position not supported", __func__); |
| 2714 | return 0; |
| 2715 | |
| 2716 | } |
| 2717 | #endif |
| 2718 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2719 | #define MAX_SND_CARD 8 |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2720 | #define RETRY_US 1000000 |
| 2721 | #define RETRY_NUMBER 40 |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 2722 | #define PLATFORM_INFO_XML_PATH "audio_platform_info.xml" |
| 2723 | #define PLATFORM_INFO_XML_BASE_STRING "audio_platform_info" |
| 2724 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 2725 | bool audio_extn_utils_resolve_config_file(char file_name[MIXER_PATH_MAX_LENGTH]) |
| 2726 | { |
| 2727 | char full_config_path[MIXER_PATH_MAX_LENGTH]; |
Saurav Kumar | f5d2c34 | 2020-07-29 19:31:49 +0530 | [diff] [blame] | 2728 | char vendor_config_path[VENDOR_CONFIG_PATH_MAX_LENGTH]; |
| 2729 | |
| 2730 | /* Get path for audio configuration files in vendor */ |
| 2731 | audio_get_vendor_config_path(vendor_config_path, |
| 2732 | sizeof(vendor_config_path)); |
| 2733 | snprintf(full_config_path, sizeof(full_config_path), |
| 2734 | "%s/%s", vendor_config_path, file_name); |
| 2735 | if (F_OK == access(full_config_path, 0)) { |
| 2736 | strlcpy(file_name, full_config_path, MIXER_PATH_MAX_LENGTH); |
| 2737 | return true; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 2738 | } |
| 2739 | return false; |
| 2740 | } |
| 2741 | |
| 2742 | /* platform_info_file should be size 'MIXER_PATH_MAX_LENGTH' */ |
| 2743 | int audio_extn_utils_get_platform_info(const char* snd_card_name, char* platform_info_file) |
| 2744 | { |
| 2745 | if (NULL == snd_card_name) { |
| 2746 | return -1; |
| 2747 | } |
| 2748 | |
| 2749 | struct snd_card_split *snd_split_handle = NULL; |
| 2750 | int ret = 0; |
| 2751 | audio_extn_set_snd_card_split(snd_card_name); |
| 2752 | snd_split_handle = audio_extn_get_snd_card_split(); |
| 2753 | |
| 2754 | snprintf(platform_info_file, MIXER_PATH_MAX_LENGTH, "%s_%s_%s.xml", |
| 2755 | PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card, |
| 2756 | snd_split_handle->form_factor); |
| 2757 | |
| 2758 | if (!audio_extn_utils_resolve_config_file(platform_info_file)) { |
| 2759 | memset(platform_info_file, 0, MIXER_PATH_MAX_LENGTH); |
| 2760 | snprintf(platform_info_file, MIXER_PATH_MAX_LENGTH, "%s_%s.xml", |
| 2761 | PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card); |
| 2762 | |
| 2763 | if (!audio_extn_utils_resolve_config_file(platform_info_file)) { |
| 2764 | memset(platform_info_file, 0, MIXER_PATH_MAX_LENGTH); |
| 2765 | strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH); |
| 2766 | ret = audio_extn_utils_resolve_config_file(platform_info_file) ? 0 : -1; |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | return ret; |
| 2771 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2772 | |
| 2773 | int audio_extn_utils_get_snd_card_num() |
| 2774 | { |
Soumya Managoli | 9fee7c6 | 2018-04-06 16:21:50 +0530 | [diff] [blame] | 2775 | int snd_card_num = 0; |
| 2776 | struct mixer *mixer = NULL; |
| 2777 | |
| 2778 | snd_card_num = audio_extn_utils_open_snd_mixer(&mixer); |
| 2779 | if (mixer) |
| 2780 | mixer_close(mixer); |
| 2781 | return snd_card_num; |
| 2782 | } |
| 2783 | |
| 2784 | int audio_extn_utils_open_snd_mixer(struct mixer **mixer_handle) |
| 2785 | { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2786 | |
| 2787 | void *hw_info = NULL; |
| 2788 | struct mixer *mixer = NULL; |
| 2789 | int retry_num = 0; |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2790 | int snd_card_num = 0; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2791 | char* snd_card_name = NULL; |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2792 | int snd_card_detection_info[MAX_SND_CARD] = {0}; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2793 | |
Soumya Managoli | 9fee7c6 | 2018-04-06 16:21:50 +0530 | [diff] [blame] | 2794 | if (!mixer_handle) { |
| 2795 | ALOGE("invalid mixer handle"); |
| 2796 | return -1; |
| 2797 | } |
| 2798 | *mixer_handle = NULL; |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2799 | /* |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2800 | * Try with all the sound cards ( 0 to 7 ) and if none of them were detected |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2801 | * sleep for 1 sec and try detections with sound card 0 again. |
| 2802 | * If sound card gets detected, check if it is relevant, if not check with the |
| 2803 | * other sound cards. To ensure that the irrelevant sound card is not check again, |
| 2804 | * we maintain it in min_snd_card_num. |
| 2805 | */ |
| 2806 | while (retry_num < RETRY_NUMBER) { |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2807 | snd_card_num = 0; |
| 2808 | while (snd_card_num < MAX_SND_CARD) { |
| 2809 | if (snd_card_detection_info[snd_card_num] == 0) { |
| 2810 | mixer = mixer_open(snd_card_num); |
| 2811 | if (!mixer) |
| 2812 | snd_card_num++; |
| 2813 | else |
| 2814 | break; |
| 2815 | } else |
| 2816 | snd_card_num++; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | if (!mixer) { |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2820 | usleep(RETRY_US); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2821 | retry_num++; |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2822 | ALOGD("%s: retry, retry_num %d", __func__, retry_num); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2823 | continue; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | snd_card_name = strdup(mixer_get_name(mixer)); |
| 2827 | if (!snd_card_name) { |
| 2828 | ALOGE("failed to allocate memory for snd_card_name\n"); |
| 2829 | mixer_close(mixer); |
| 2830 | return -1; |
| 2831 | } |
| 2832 | ALOGD("%s: snd_card_name: %s", __func__, snd_card_name); |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2833 | snd_card_detection_info[snd_card_num] = 1; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2834 | hw_info = hw_info_init(snd_card_name); |
| 2835 | if (hw_info) { |
| 2836 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 2837 | break; |
| 2838 | } |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2839 | ALOGE("%s: Failed to init hardware info, snd_card_num:%d", __func__, snd_card_num); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2840 | |
Dhananjay Kumar | a7e2783 | 2017-07-11 15:40:39 +0530 | [diff] [blame] | 2841 | free(snd_card_name); |
| 2842 | snd_card_name = NULL; |
| 2843 | |
| 2844 | mixer_close(mixer); |
| 2845 | mixer = NULL; |
| 2846 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2847 | if (snd_card_name) |
| 2848 | free(snd_card_name); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2849 | |
Dhananjay Kumar | a7e2783 | 2017-07-11 15:40:39 +0530 | [diff] [blame] | 2850 | if (hw_info) |
| 2851 | hw_info_deinit(hw_info); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2852 | |
mpang | faa7bae | 2019-01-15 16:38:13 +0800 | [diff] [blame] | 2853 | if (retry_num >= RETRY_NUMBER) { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2854 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
| 2855 | return -1; |
| 2856 | } |
| 2857 | |
Soumya Managoli | 9fee7c6 | 2018-04-06 16:21:50 +0530 | [diff] [blame] | 2858 | if (mixer) |
| 2859 | *mixer_handle = mixer; |
| 2860 | |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2861 | return snd_card_num; |
| 2862 | } |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2863 | |
Soumya Managoli | 9fee7c6 | 2018-04-06 16:21:50 +0530 | [diff] [blame] | 2864 | void audio_extn_utils_close_snd_mixer(struct mixer *mixer) |
| 2865 | { |
| 2866 | if (mixer) |
| 2867 | mixer_close(mixer); |
| 2868 | } |
| 2869 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2870 | #ifdef SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK |
| 2871 | int audio_extn_utils_compress_enable_drift_correction( |
| 2872 | struct stream_out *out, |
| 2873 | struct audio_out_enable_drift_correction *drift) |
| 2874 | { |
| 2875 | struct snd_compr_metadata metadata; |
| 2876 | int ret = -EINVAL; |
| 2877 | |
| 2878 | if(drift == NULL) { |
| 2879 | ALOGE("%s:: Invalid param", __func__); |
| 2880 | goto exit; |
| 2881 | } |
| 2882 | |
| 2883 | ALOGD("%s:: drift enable %d", __func__,drift->enable); |
| 2884 | |
| 2885 | if (!is_offload_usecase(out->usecase)) { |
| 2886 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2887 | goto exit; |
| 2888 | } |
| 2889 | |
| 2890 | if (!out->compr) { |
| 2891 | ALOGW("%s:: offload session not yet opened," |
| 2892 | "start delay will be configure later", __func__); |
| 2893 | goto exit; |
| 2894 | } |
| 2895 | |
| 2896 | metadata.key = SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK; |
| 2897 | metadata.value[0] = drift->enable; |
| 2898 | out->drift_correction_enabled = drift->enable; |
| 2899 | |
| 2900 | ret = compress_set_metadata(out->compr, &metadata); |
| 2901 | if(ret) { |
| 2902 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2903 | out->drift_correction_enabled = false; |
| 2904 | } |
| 2905 | |
| 2906 | exit: |
| 2907 | return ret; |
| 2908 | } |
| 2909 | #else |
| 2910 | int audio_extn_utils_compress_enable_drift_correction( |
| 2911 | struct stream_out *out __unused, |
| 2912 | struct audio_out_enable_drift_correction *drift __unused) |
| 2913 | { |
| 2914 | ALOGD("%s:: configuring drift enablement not supported", __func__); |
| 2915 | return 0; |
| 2916 | } |
| 2917 | #endif |
| 2918 | |
| 2919 | #ifdef SNDRV_COMPRESS_ADJUST_SESSION_CLOCK |
| 2920 | int audio_extn_utils_compress_correct_drift( |
| 2921 | struct stream_out *out, |
| 2922 | struct audio_out_correct_drift *drift_param) |
| 2923 | { |
| 2924 | struct snd_compr_metadata metadata; |
| 2925 | int ret = -EINVAL; |
| 2926 | |
| 2927 | if (drift_param == NULL) { |
| 2928 | ALOGE("%s:: Invalid drift_param", __func__); |
| 2929 | goto exit; |
| 2930 | } |
| 2931 | |
| 2932 | ALOGD("%s:: adjust time 0x%"PRIx64" ", __func__, |
| 2933 | drift_param->adjust_time); |
| 2934 | |
| 2935 | if (!is_offload_usecase(out->usecase)) { |
| 2936 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2937 | goto exit; |
| 2938 | } |
| 2939 | |
| 2940 | if (!out->compr) { |
| 2941 | ALOGW("%s:: offload session not yet opened", __func__); |
| 2942 | goto exit; |
| 2943 | } |
| 2944 | |
| 2945 | if (!out->drift_correction_enabled) { |
| 2946 | ALOGE("%s:: drift correction not enabled", __func__); |
| 2947 | goto exit; |
| 2948 | } |
| 2949 | |
| 2950 | metadata.key = SNDRV_COMPRESS_ADJUST_SESSION_CLOCK; |
| 2951 | metadata.value[0] = 0xFFFFFFFF & drift_param->adjust_time; /* lsb */ |
| 2952 | metadata.value[1] = \ |
| 2953 | (0xFFFFFFFF00000000 & drift_param->adjust_time) >> 32; /* msb*/ |
| 2954 | |
| 2955 | ret = compress_set_metadata(out->compr, &metadata); |
| 2956 | if(ret) |
| 2957 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2958 | exit: |
| 2959 | return ret; |
| 2960 | } |
| 2961 | #else |
| 2962 | int audio_extn_utils_compress_correct_drift( |
| 2963 | struct stream_out *out __unused, |
| 2964 | struct audio_out_correct_drift *drift_param __unused) |
| 2965 | { |
| 2966 | ALOGD("%s:: setting adjust clock not supported", __func__); |
| 2967 | return 0; |
| 2968 | } |
| 2969 | #endif |
Naresh Tanniru | 29bce4e | 2017-04-27 17:54:30 +0530 | [diff] [blame] | 2970 | |
| 2971 | int audio_extn_utils_set_channel_map( |
| 2972 | struct stream_out *out, |
| 2973 | struct audio_out_channel_map_param *channel_map_param) |
| 2974 | { |
| 2975 | int ret = -EINVAL, i = 0; |
| 2976 | int channels = audio_channel_count_from_out_mask(out->channel_mask); |
| 2977 | |
| 2978 | if (channel_map_param == NULL) { |
| 2979 | ALOGE("%s:: Invalid channel_map", __func__); |
| 2980 | goto exit; |
| 2981 | } |
| 2982 | |
| 2983 | if (channel_map_param->channels != channels) { |
| 2984 | ALOGE("%s:: Channels(%d) does not match stream channels(%d)", |
| 2985 | __func__, channel_map_param->channels, channels); |
| 2986 | goto exit; |
| 2987 | } |
| 2988 | |
| 2989 | for ( i = 0; i < channels; i++) { |
| 2990 | ALOGV("%s:: channel_map[%d]- %d", __func__, i, channel_map_param->channel_map[i]); |
| 2991 | out->channel_map_param.channel_map[i] = channel_map_param->channel_map[i]; |
| 2992 | } |
| 2993 | ret = 0; |
| 2994 | exit: |
| 2995 | return ret; |
| 2996 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2997 | |
| 2998 | int audio_extn_utils_set_pan_scale_params( |
| 2999 | struct stream_out *out, |
| 3000 | struct mix_matrix_params *mm_params) |
| 3001 | { |
| 3002 | int ret = -EINVAL, i = 0, j = 0; |
| 3003 | |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 3004 | if (mm_params == NULL || out == NULL) { |
| 3005 | ALOGE("%s:: Invalid mix matrix or out param", __func__); |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3006 | goto exit; |
| 3007 | } |
| 3008 | |
| 3009 | if (mm_params->num_output_channels > MAX_CHANNELS_SUPPORTED || |
| 3010 | mm_params->num_output_channels <= 0 || |
| 3011 | mm_params->num_input_channels > MAX_CHANNELS_SUPPORTED || |
| 3012 | mm_params->num_input_channels <= 0) |
| 3013 | goto exit; |
| 3014 | |
| 3015 | out->pan_scale_params.num_output_channels = mm_params->num_output_channels; |
| 3016 | out->pan_scale_params.num_input_channels = mm_params->num_input_channels; |
| 3017 | out->pan_scale_params.has_output_channel_map = |
| 3018 | mm_params->has_output_channel_map; |
| 3019 | for (i = 0; i < mm_params->num_output_channels; i++) |
| 3020 | out->pan_scale_params.output_channel_map[i] = |
| 3021 | mm_params->output_channel_map[i]; |
| 3022 | |
| 3023 | out->pan_scale_params.has_input_channel_map = |
| 3024 | mm_params->has_input_channel_map; |
| 3025 | for (i = 0; i < mm_params->num_input_channels; i++) |
| 3026 | out->pan_scale_params.input_channel_map[i] = |
| 3027 | mm_params->input_channel_map[i]; |
| 3028 | |
| 3029 | out->pan_scale_params.has_mixer_coeffs = mm_params->has_mixer_coeffs; |
| 3030 | for (i = 0; i < mm_params->num_output_channels; i++) |
| 3031 | for (j = 0; j < mm_params->num_input_channels; j++) { |
| 3032 | //Convert the channel coefficient gains in Q14 format |
| 3033 | out->pan_scale_params.mixer_coeffs[i][j] = |
| 3034 | mm_params->mixer_coeffs[i][j] * (2 << 13); |
| 3035 | } |
| 3036 | |
| 3037 | ret = platform_set_stream_pan_scale_params(out->dev->platform, |
| 3038 | out->pcm_device_id, |
| 3039 | out->pan_scale_params); |
| 3040 | |
| 3041 | exit: |
| 3042 | return ret; |
| 3043 | } |
| 3044 | |
| 3045 | int audio_extn_utils_set_downmix_params( |
| 3046 | struct stream_out *out, |
| 3047 | struct mix_matrix_params *mm_params) |
| 3048 | { |
| 3049 | int ret = -EINVAL, i = 0, j = 0; |
| 3050 | struct audio_usecase *usecase = NULL; |
| 3051 | |
Aniket Kumar Lata | f9f246e | 2017-09-15 15:20:16 -0700 | [diff] [blame] | 3052 | if (mm_params == NULL || out == NULL) { |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 3053 | ALOGE("%s:: Invalid mix matrix or out param", __func__); |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3054 | goto exit; |
| 3055 | } |
| 3056 | |
| 3057 | if (mm_params->num_output_channels > MAX_CHANNELS_SUPPORTED || |
| 3058 | mm_params->num_output_channels <= 0 || |
| 3059 | mm_params->num_input_channels > MAX_CHANNELS_SUPPORTED || |
| 3060 | mm_params->num_input_channels <= 0) |
| 3061 | goto exit; |
| 3062 | |
| 3063 | usecase = get_usecase_from_list(out->dev, out->usecase); |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 3064 | if (!usecase) { |
| 3065 | ALOGE("%s: Get usecase list failed!", __func__); |
Aniket Kumar Lata | f9f246e | 2017-09-15 15:20:16 -0700 | [diff] [blame] | 3066 | goto exit; |
| 3067 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3068 | out->downmix_params.num_output_channels = mm_params->num_output_channels; |
| 3069 | out->downmix_params.num_input_channels = mm_params->num_input_channels; |
| 3070 | |
| 3071 | out->downmix_params.has_output_channel_map = |
| 3072 | mm_params->has_output_channel_map; |
| 3073 | for (i = 0; i < mm_params->num_output_channels; i++) { |
| 3074 | out->downmix_params.output_channel_map[i] = |
| 3075 | mm_params->output_channel_map[i]; |
| 3076 | } |
| 3077 | |
| 3078 | out->downmix_params.has_input_channel_map = |
| 3079 | mm_params->has_input_channel_map; |
| 3080 | for (i = 0; i < mm_params->num_input_channels; i++) |
| 3081 | out->downmix_params.input_channel_map[i] = |
| 3082 | mm_params->input_channel_map[i]; |
| 3083 | |
| 3084 | out->downmix_params.has_mixer_coeffs = mm_params->has_mixer_coeffs; |
| 3085 | for (i = 0; i < mm_params->num_output_channels; i++) |
Nikhil Latukar | 2e6f624 | 2017-08-15 13:37:07 +0530 | [diff] [blame] | 3086 | for (j = 0; j < mm_params->num_input_channels; j++) { |
| 3087 | //Convert the channel coefficient gains in Q14 format |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3088 | out->downmix_params.mixer_coeffs[i][j] = |
Nikhil Latukar | 2e6f624 | 2017-08-15 13:37:07 +0530 | [diff] [blame] | 3089 | mm_params->mixer_coeffs[i][j] * (2 << 13); |
| 3090 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 3091 | |
| 3092 | ret = platform_set_stream_downmix_params(out->dev->platform, |
| 3093 | out->pcm_device_id, |
| 3094 | usecase->out_snd_device, |
| 3095 | out->downmix_params); |
| 3096 | |
| 3097 | exit: |
| 3098 | return ret; |
| 3099 | } |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 3100 | |
| 3101 | bool audio_extn_utils_is_dolby_format(audio_format_t format) |
| 3102 | { |
| 3103 | if (format == AUDIO_FORMAT_AC3 || |
| 3104 | format == AUDIO_FORMAT_E_AC3 || |
| 3105 | format == AUDIO_FORMAT_E_AC3_JOC) |
| 3106 | return true; |
| 3107 | else |
| 3108 | return false; |
| 3109 | } |
| 3110 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 3111 | int audio_extn_utils_get_bit_width_from_string(const char *id_string) |
| 3112 | { |
| 3113 | int i; |
| 3114 | const mixer_config_lookup mixer_bitwidth_config[] = {{"S24_3LE", 24}, |
| 3115 | {"S32_LE", 32}, |
| 3116 | {"S24_LE", 24}, |
| 3117 | {"S16_LE", 16}}; |
| 3118 | int num_configs = sizeof(mixer_bitwidth_config) / sizeof(mixer_bitwidth_config[0]); |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 3119 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 3120 | for (i = 0; i < num_configs; i++) { |
| 3121 | if (!strcmp(id_string, mixer_bitwidth_config[i].id_string)) |
| 3122 | return mixer_bitwidth_config[i].value; |
| 3123 | } |
| 3124 | |
| 3125 | return -EINVAL; |
| 3126 | } |
| 3127 | |
| 3128 | int audio_extn_utils_get_sample_rate_from_string(const char *id_string) |
| 3129 | { |
| 3130 | int i; |
| 3131 | const mixer_config_lookup mixer_samplerate_config[] = {{"KHZ_32", 32000}, |
| 3132 | {"KHZ_48", 48000}, |
| 3133 | {"KHZ_96", 96000}, |
| 3134 | {"KHZ_144", 144000}, |
| 3135 | {"KHZ_192", 192000}, |
| 3136 | {"KHZ_384", 384000}, |
| 3137 | {"KHZ_44P1", 44100}, |
| 3138 | {"KHZ_88P2", 88200}, |
| 3139 | {"KHZ_176P4", 176400}, |
| 3140 | {"KHZ_352P8", 352800}}; |
| 3141 | int num_configs = sizeof(mixer_samplerate_config) / sizeof(mixer_samplerate_config[0]); |
| 3142 | |
| 3143 | for (i = 0; i < num_configs; i++) { |
| 3144 | if (!strcmp(id_string, mixer_samplerate_config[i].id_string)) |
| 3145 | return mixer_samplerate_config[i].value; |
| 3146 | } |
| 3147 | |
| 3148 | return -EINVAL; |
| 3149 | } |
| 3150 | |
| 3151 | int audio_extn_utils_get_channels_from_string(const char *id_string) |
| 3152 | { |
| 3153 | int i; |
| 3154 | const mixer_config_lookup mixer_channels_config[] = {{"One", 1}, |
| 3155 | {"Two", 2}, |
| 3156 | {"Three",3}, |
| 3157 | {"Four", 4}, |
| 3158 | {"Five", 5}, |
| 3159 | {"Six", 6}, |
| 3160 | {"Seven", 7}, |
| 3161 | {"Eight", 8}}; |
| 3162 | int num_configs = sizeof(mixer_channels_config) / sizeof(mixer_channels_config[0]); |
| 3163 | |
| 3164 | for (i = 0; i < num_configs; i++) { |
| 3165 | if (!strcmp(id_string, mixer_channels_config[i].id_string)) |
| 3166 | return mixer_channels_config[i].value; |
| 3167 | } |
| 3168 | |
| 3169 | return -EINVAL; |
| 3170 | } |
Surendar karka | 3056979 | 2018-05-08 12:02:21 +0530 | [diff] [blame] | 3171 | |
Weiyin Jiang | 0d84c8e | 2019-04-09 22:59:54 +0800 | [diff] [blame] | 3172 | void audio_extn_utils_release_snd_device(snd_device_t snd_device) |
| 3173 | { |
| 3174 | audio_extn_dev_arbi_release(snd_device); |
| 3175 | audio_extn_sound_trigger_update_device_status(snd_device, |
| 3176 | ST_EVENT_SND_DEVICE_FREE); |
| 3177 | audio_extn_listen_update_device_status(snd_device, |
| 3178 | LISTEN_EVENT_SND_DEVICE_FREE); |
| 3179 | } |
| 3180 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3181 | int audio_extn_utils_get_license_params( |
| 3182 | const struct audio_device *adev, |
| 3183 | struct audio_license_params *license_params) |
Surendar karka | 3056979 | 2018-05-08 12:02:21 +0530 | [diff] [blame] | 3184 | { |
| 3185 | if(!license_params) |
| 3186 | return -EINVAL; |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3187 | |
| 3188 | return platform_get_license_by_product(adev->platform, |
| 3189 | (const char*)license_params->product, &license_params->key, license_params->license); |
Surendar karka | 3056979 | 2018-05-08 12:02:21 +0530 | [diff] [blame] | 3190 | } |
| 3191 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 3192 | int audio_extn_utils_send_app_type_gain(struct audio_device *adev, |
| 3193 | int app_type, |
| 3194 | int *gain) |
| 3195 | { |
| 3196 | int gain_cfg[4]; |
| 3197 | const char *mixer_ctl_name = "App Type Gain"; |
| 3198 | struct mixer_ctl *ctl; |
| 3199 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 3200 | if (!ctl) { |
| 3201 | ALOGE("%s: Could not get volume ctl mixer %s", __func__, |
| 3202 | mixer_ctl_name); |
| 3203 | return -EINVAL; |
| 3204 | } |
| 3205 | gain_cfg[0] = 0; |
| 3206 | gain_cfg[1] = app_type; |
| 3207 | gain_cfg[2] = gain[0]; |
| 3208 | gain_cfg[3] = gain[1]; |
| 3209 | ALOGV("%s app_type %d l(%d) r(%d)", __func__, app_type, gain[0], gain[1]); |
| 3210 | return mixer_ctl_set_array(ctl, gain_cfg, |
| 3211 | sizeof(gain_cfg)/sizeof(gain_cfg[0])); |
| 3212 | } |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 3213 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3214 | static void vndk_fwk_init() |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 3215 | { |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3216 | if (mVndkFwk.lib_handle != NULL) |
| 3217 | return; |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 3218 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3219 | mVndkFwk.lib_handle = dlopen(VNDK_FWK_LIB_PATH, RTLD_NOW); |
| 3220 | if (mVndkFwk.lib_handle == NULL) { |
| 3221 | ALOGW("%s: failed to dlopen VNDK_FWK_LIB %s", __func__, strerror(errno)); |
| 3222 | return; |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
Weiyin Jiang | d5718bd | 2019-09-04 16:52:08 +0800 | [diff] [blame] | 3225 | *(void **)(&mVndkFwk.isVendorEnhancedFwk) = |
| 3226 | dlsym(mVndkFwk.lib_handle, "isRunningWithVendorEnhancedFramework"); |
| 3227 | if (mVndkFwk.isVendorEnhancedFwk == NULL) { |
| 3228 | ALOGW("%s: dlsym failed %s", __func__, strerror(errno)); |
| 3229 | if (mVndkFwk.lib_handle) { |
| 3230 | dlclose(mVndkFwk.lib_handle); |
| 3231 | mVndkFwk.lib_handle = NULL; |
| 3232 | } |
| 3233 | return; |
| 3234 | } |
| 3235 | |
| 3236 | |
| 3237 | *(void **)(&mVndkFwk.getVendorEnhancedInfo) = |
| 3238 | dlsym(mVndkFwk.lib_handle, "getVendorEnhancedInfo"); |
| 3239 | if (mVndkFwk.getVendorEnhancedInfo == NULL) { |
| 3240 | ALOGW("%s: dlsym failed %s", __func__, strerror(errno)); |
| 3241 | if (mVndkFwk.lib_handle) { |
| 3242 | dlclose(mVndkFwk.lib_handle); |
| 3243 | mVndkFwk.lib_handle = NULL; |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | return; |
| 3248 | } |
| 3249 | |
| 3250 | bool audio_extn_utils_is_vendor_enhanced_fwk() |
| 3251 | { |
| 3252 | static int is_vendor_enhanced_fwk = -EINVAL; |
| 3253 | if (is_vendor_enhanced_fwk != -EINVAL) |
| 3254 | return (bool)is_vendor_enhanced_fwk; |
| 3255 | |
| 3256 | vndk_fwk_init(); |
| 3257 | |
| 3258 | if (mVndkFwk.isVendorEnhancedFwk != NULL) { |
| 3259 | is_vendor_enhanced_fwk = mVndkFwk.isVendorEnhancedFwk(); |
| 3260 | ALOGW("%s: is_vendor_enhanced_fwk %d", __func__, is_vendor_enhanced_fwk); |
| 3261 | } else { |
| 3262 | is_vendor_enhanced_fwk = 0; |
| 3263 | ALOGW("%s: default to non enhanced_fwk config", __func__); |
| 3264 | } |
| 3265 | |
| 3266 | return (bool)is_vendor_enhanced_fwk; |
| 3267 | } |
| 3268 | |
| 3269 | int audio_extn_utils_get_vendor_enhanced_info() |
| 3270 | { |
| 3271 | static int vendor_enhanced_info = -EINVAL; |
| 3272 | if (vendor_enhanced_info != -EINVAL) |
| 3273 | return vendor_enhanced_info; |
| 3274 | |
| 3275 | vndk_fwk_init(); |
| 3276 | |
| 3277 | if (mVndkFwk.getVendorEnhancedInfo != NULL) { |
| 3278 | vendor_enhanced_info = mVndkFwk.getVendorEnhancedInfo(); |
| 3279 | ALOGW("%s: vendor_enhanced_info 0x%x", __func__, vendor_enhanced_info); |
| 3280 | } else { |
| 3281 | vendor_enhanced_info = 0x0; |
| 3282 | ALOGW("%s: default to vendor_enhanced_info 0x0", __func__); |
| 3283 | } |
| 3284 | |
| 3285 | return vendor_enhanced_info; |
Aniket Kumar Lata | 4f9a2a5 | 2019-05-09 18:44:09 -0700 | [diff] [blame] | 3286 | } |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 3287 | |
Deeraj Soman | fa377bf | 2019-02-06 12:57:59 +0530 | [diff] [blame] | 3288 | int audio_extn_utils_get_perf_mode_flag(void) |
| 3289 | { |
| 3290 | #ifdef COMPRESSED_PERF_MODE_FLAG |
| 3291 | return COMPRESSED_PERF_MODE_FLAG; |
| 3292 | #else |
| 3293 | return 0; |
| 3294 | #endif |
| 3295 | } |
| 3296 | |
Deeraj Soman | 1423092 | 2019-01-30 16:39:30 +0530 | [diff] [blame] | 3297 | size_t audio_extn_utils_get_input_buffer_size(uint32_t sample_rate, |
| 3298 | audio_format_t format, |
| 3299 | int channel_count, |
| 3300 | int64_t duration_ms, |
| 3301 | bool is_low_latency) |
| 3302 | { |
| 3303 | size_t size = 0; |
| 3304 | size_t capture_duration = AUDIO_CAPTURE_PERIOD_DURATION_MSEC; |
| 3305 | uint32_t bytes_per_period_sample = 0; |
| 3306 | |
| 3307 | |
| 3308 | if (audio_extn_utils_check_input_parameters(sample_rate, format, channel_count) != 0) |
| 3309 | return 0; |
| 3310 | |
| 3311 | if (duration_ms >= MIN_OFFLOAD_BUFFER_DURATION_MS && duration_ms <= MAX_OFFLOAD_BUFFER_DURATION_MS) |
| 3312 | capture_duration = duration_ms; |
| 3313 | |
| 3314 | size = (sample_rate * capture_duration) / 1000; |
| 3315 | if (is_low_latency) |
| 3316 | size = LOW_LATENCY_CAPTURE_PERIOD_SIZE; |
| 3317 | |
| 3318 | |
| 3319 | bytes_per_period_sample = audio_bytes_per_sample(format) * channel_count; |
| 3320 | size *= bytes_per_period_sample; |
| 3321 | |
| 3322 | /* make sure the size is multiple of 32 bytes and additionally multiple of |
| 3323 | * the frame_size (required for 24bit samples and non-power-of-2 channel counts) |
| 3324 | * At 48 kHz mono 16-bit PCM: |
| 3325 | * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15) |
| 3326 | * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10) |
| 3327 | * |
| 3328 | * The loop reaches result within 32 iterations, as initial size is |
| 3329 | * already a multiple of frame_size |
| 3330 | */ |
| 3331 | size = audio_extn_utils_nearest_multiple(size, audio_extn_utils_lcm(32, bytes_per_period_sample)); |
| 3332 | |
| 3333 | return size; |
| 3334 | } |
Aniket Kumar Lata | 1fda943 | 2019-11-01 17:08:33 -0700 | [diff] [blame] | 3335 | |
| 3336 | int audio_extn_utils_hash_fn(void *key) |
| 3337 | { |
| 3338 | return (int)key; |
| 3339 | } |
| 3340 | |
| 3341 | bool audio_extn_utils_hash_eq(void *key1, void *key2) |
| 3342 | { |
| 3343 | return (key1 == key2); |
| 3344 | } |