Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1 | /* |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2017, 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> |
| 30 | #include <cutils/log.h> |
| 31 | #include <cutils/misc.h> |
| 32 | |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 33 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 34 | #include "audio_hw.h" |
| 35 | #include "platform.h" |
| 36 | #include "platform_api.h" |
| 37 | #include "audio_extn.h" |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 38 | #include "voice.h" |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 39 | #include <sound/compress_params.h> |
| 40 | #include <sound/compress_offload.h> |
| 41 | #include <tinycompress/tinycompress.h> |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 42 | |
| 43 | #ifdef DYNAMIC_LOG_ENABLED |
| 44 | #include <log_xml_parser.h> |
| 45 | #define LOG_MASK HAL_MOD_FILE_UTILS |
| 46 | #include <log_utils.h> |
| 47 | #endif |
| 48 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 49 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 50 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 51 | #include "audio_parsers.h" |
| 52 | #endif |
| 53 | #endif |
| 54 | |
Yamit Mehta | a0d653a | 2016-11-25 20:33:25 +0530 | [diff] [blame] | 55 | #ifdef LINUX_ENABLED |
| 56 | #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/etc/audio_output_policy.conf" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 57 | #define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/etc/audio_io_policy.conf" |
Yamit Mehta | a0d653a | 2016-11-25 20:33:25 +0530 | [diff] [blame] | 58 | #else |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 59 | #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 60 | #define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_io_policy.conf" |
Yamit Mehta | a0d653a | 2016-11-25 20:33:25 +0530 | [diff] [blame] | 61 | #endif |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 62 | |
| 63 | #define OUTPUTS_TAG "outputs" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 64 | #define INPUTS_TAG "inputs" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 65 | |
| 66 | #define DYNAMIC_VALUE_TAG "dynamic" |
| 67 | #define FLAGS_TAG "flags" |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 68 | #define PROFILES_TAG "profile" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 69 | #define FORMATS_TAG "formats" |
| 70 | #define SAMPLING_RATES_TAG "sampling_rates" |
| 71 | #define BIT_WIDTH_TAG "bit_width" |
| 72 | #define APP_TYPE_TAG "app_type" |
| 73 | |
| 74 | #define STRING_TO_ENUM(string) { #string, string } |
| 75 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 76 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 77 | #define BASE_TABLE_SIZE 64 |
| 78 | #define MAX_BASEINDEX_LEN 256 |
| 79 | |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 80 | #ifndef SND_AUDIOCODEC_TRUEHD |
| 81 | #define SND_AUDIOCODEC_TRUEHD 0x00000023 |
| 82 | #endif |
| 83 | |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 84 | #define APP_TYPE_VOIP_AUDIO 0x1113A |
| 85 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 86 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 87 | #define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */ |
| 88 | #define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */ |
| 89 | #define SR_44100 (0<<0) /* 44.1kHz */ |
| 90 | #define SR_NOTID (1<<0) /* non indicated */ |
| 91 | #define SR_48000 (2<<0) /* 48kHz */ |
| 92 | #define SR_32000 (3<<0) /* 32kHz */ |
| 93 | #define SR_22050 (4<<0) /* 22.05kHz */ |
| 94 | #define SR_24000 (6<<0) /* 24kHz */ |
| 95 | #define SR_88200 (8<<0) /* 88.2kHz */ |
| 96 | #define SR_96000 (10<<0) /* 96kHz */ |
| 97 | #define SR_176400 (12<<0) /* 176.4kHz */ |
| 98 | #define SR_192000 (14<<0) /* 192kHz */ |
| 99 | |
| 100 | #endif |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 101 | |
| 102 | /* ToDo: Check and update a proper value in msec */ |
| 103 | #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50 |
| 104 | |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 105 | #ifndef MAX_CHANNELS_SUPPORTED |
| 106 | #define MAX_CHANNELS_SUPPORTED 8 |
| 107 | #endif |
| 108 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 109 | typedef struct { |
| 110 | const char *id_string; |
| 111 | const int value; |
| 112 | } mixer_config_lookup; |
| 113 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 114 | struct string_to_enum { |
| 115 | const char *name; |
| 116 | uint32_t value; |
| 117 | }; |
| 118 | |
| 119 | const struct string_to_enum s_flag_name_to_enum_table[] = { |
| 120 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT), |
| 121 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY), |
| 122 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST), |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 123 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 124 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER), |
| 125 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD), |
| 126 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 127 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 128 | #ifdef INCALL_MUSIC_ENABLED |
| 129 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC), |
| 130 | #endif |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 131 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH), |
Naresh Tanniru | ee3499a | 2017-01-05 14:05:35 +0530 | [diff] [blame] | 132 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_TIMESTAMP), |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 133 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_VOIP_RX), |
Ben Romberger | 6c4d381 | 2017-06-13 17:46:45 -0700 | [diff] [blame] | 134 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_BD), |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 135 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INTERACTIVE), |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 136 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE), |
| 137 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST), |
| 138 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD), |
| 139 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW), |
| 140 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC), |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 141 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP), |
Dhananjay Kumar | 704ce6f | 2017-09-28 22:08:00 +0530 | [diff] [blame] | 142 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_COMPRESS), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | const struct string_to_enum s_format_name_to_enum_table[] = { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 146 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 147 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT), |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 148 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED), |
| 149 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT), |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 150 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 151 | STRING_TO_ENUM(AUDIO_FORMAT_MP3), |
| 152 | STRING_TO_ENUM(AUDIO_FORMAT_AAC), |
| 153 | STRING_TO_ENUM(AUDIO_FORMAT_VORBIS), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 154 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB), |
| 155 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 156 | STRING_TO_ENUM(AUDIO_FORMAT_AC3), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 157 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 158 | STRING_TO_ENUM(AUDIO_FORMAT_DTS), |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 159 | STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD), |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 160 | STRING_TO_ENUM(AUDIO_FORMAT_DOLBY_TRUEHD), |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 161 | STRING_TO_ENUM(AUDIO_FORMAT_IEC61937), |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 162 | #ifdef AUDIO_EXTN_FORMATS_ENABLED |
| 163 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 164 | STRING_TO_ENUM(AUDIO_FORMAT_WMA), |
| 165 | STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO), |
| 166 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 167 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS), |
| 168 | STRING_TO_ENUM(AUDIO_FORMAT_EVRC), |
| 169 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCB), |
| 170 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB), |
| 171 | STRING_TO_ENUM(AUDIO_FORMAT_QCELP), |
| 172 | STRING_TO_ENUM(AUDIO_FORMAT_MP2), |
| 173 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW), |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 174 | STRING_TO_ENUM(AUDIO_FORMAT_FLAC), |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 175 | STRING_TO_ENUM(AUDIO_FORMAT_ALAC), |
| 176 | STRING_TO_ENUM(AUDIO_FORMAT_APE), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 177 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Alexy Joseph | cd8eaed | 2014-12-11 12:46:53 -0800 | [diff] [blame] | 178 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC), |
| 179 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1), |
| 180 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2), |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 181 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS), |
Ashish Jain | e513a87 | 2015-11-19 17:00:56 +0530 | [diff] [blame] | 182 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC), |
| 183 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1), |
| 184 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2), |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 185 | STRING_TO_ENUM(AUDIO_FORMAT_DSD), |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 186 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM), |
| 187 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC), |
| 188 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1), |
| 189 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2), |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 190 | STRING_TO_ENUM(AUDIO_FORMAT_APTX), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 191 | #endif |
| 192 | }; |
| 193 | |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 194 | /* payload structure avt_device drift query */ |
| 195 | struct audio_avt_device_drift_stats { |
| 196 | uint32_t minor_version; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 197 | |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 198 | /* Indicates the device interface direction as either |
| 199 | * source (Tx) or sink (Rx). |
| 200 | */ |
| 201 | uint16_t device_direction; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 202 | |
| 203 | /* Reference timer for drift accumulation and time stamp information. |
| 204 | * currently it only support AFE_REF_TIMER_TYPE_AVTIMER |
| 205 | */ |
| 206 | uint16_t reference_timer; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 207 | struct audio_avt_device_drift_param drift_param; |
Manish Dewangan | 338c50a | 2017-09-12 15:22:03 +0530 | [diff] [blame] | 208 | } __attribute__((packed)); |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 209 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 210 | static char bTable[BASE_TABLE_SIZE] = { |
| 211 | 'A','B','C','D','E','F','G','H','I','J','K','L', |
| 212 | 'M','N','O','P','Q','R','S','T','U','V','W','X', |
| 213 | 'Y','Z','a','b','c','d','e','f','g','h','i','j', |
| 214 | 'k','l','m','n','o','p','q','r','s','t','u','v', |
| 215 | 'w','x','y','z','0','1','2','3','4','5','6','7', |
| 216 | '8','9','+','/' |
| 217 | }; |
| 218 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 219 | static uint32_t string_to_enum(const struct string_to_enum *table, size_t size, |
| 220 | const char *name) |
| 221 | { |
| 222 | size_t i; |
| 223 | for (i = 0; i < size; i++) { |
| 224 | if (strcmp(table[i].name, name) == 0) { |
| 225 | ALOGV("%s found %s", __func__, table[i].name); |
| 226 | return table[i].value; |
| 227 | } |
| 228 | } |
| 229 | return 0; |
| 230 | } |
| 231 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 232 | static audio_io_flags_t parse_flag_names(char *name) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 233 | { |
| 234 | uint32_t flag = 0; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 235 | audio_io_flags_t io_flags; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 236 | char *last_r; |
| 237 | char *flag_name = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 238 | while (flag_name != NULL) { |
| 239 | if (strlen(flag_name) != 0) { |
| 240 | flag |= string_to_enum(s_flag_name_to_enum_table, |
| 241 | ARRAY_SIZE(s_flag_name_to_enum_table), |
| 242 | flag_name); |
| 243 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 244 | flag_name = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 247 | ALOGV("parse_flag_names: flag - %x", flag); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 248 | io_flags.in_flags = (audio_input_flags_t)flag; |
| 249 | io_flags.out_flags = (audio_output_flags_t)flag; |
| 250 | return io_flags; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 253 | 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] | 254 | { |
| 255 | struct stream_format *sf_info = NULL; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 256 | char *last_r; |
| 257 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 258 | |
| 259 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) |
| 260 | return; |
| 261 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 262 | list_init(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 263 | while (str != NULL) { |
| 264 | audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table, |
| 265 | ARRAY_SIZE(s_format_name_to_enum_table), str); |
| 266 | ALOGV("%s: format - %d", __func__, format); |
| 267 | if (format != 0) { |
| 268 | sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 269 | if (sf_info == NULL) |
| 270 | break; /* return whatever was parsed */ |
| 271 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 272 | sf_info->format = format; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 273 | list_add_tail(&s_info->format_list, &sf_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 274 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 275 | str = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 279 | 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] | 280 | { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 281 | struct stream_sample_rate *ss_info = NULL; |
| 282 | uint32_t sample_rate = 48000; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 283 | char *last_r; |
| 284 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 285 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 286 | if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG)) |
| 287 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 288 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 289 | list_init(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 290 | while (str != NULL) { |
| 291 | sample_rate = (uint32_t)strtol(str, (char **)NULL, 10); |
| 292 | ALOGV("%s: sample_rate - %d", __func__, sample_rate); |
| 293 | if (0 != sample_rate) { |
| 294 | 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] | 295 | if (!ss_info) { |
| 296 | ALOGE("%s: memory allocation failure", __func__); |
| 297 | return; |
| 298 | } |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 299 | ss_info->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 300 | list_add_tail(&s_info->sample_rate_list, &ss_info->list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 301 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 302 | str = strtok_r(NULL, "|", &last_r); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 303 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static int parse_bit_width_names(char *name) |
| 307 | { |
| 308 | int bit_width = 16; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 309 | char *last_r; |
| 310 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 311 | |
| 312 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 313 | bit_width = (int)strtol(str, (char **)NULL, 10); |
| 314 | |
| 315 | ALOGV("%s: bit_width - %d", __func__, bit_width); |
| 316 | return bit_width; |
| 317 | } |
| 318 | |
| 319 | static int parse_app_type_names(void *platform, char *name) |
| 320 | { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 321 | int app_type = platform_get_default_app_type(platform); |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 322 | char *last_r; |
| 323 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 324 | |
| 325 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 326 | app_type = (int)strtol(str, (char **)NULL, 10); |
| 327 | |
| 328 | ALOGV("%s: app_type - %d", __func__, app_type); |
| 329 | return app_type; |
| 330 | } |
| 331 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 332 | static void update_streams_cfg_list(cnode *root, void *platform, |
| 333 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 334 | { |
| 335 | cnode *node = root->first_child; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 336 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 337 | |
| 338 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 339 | 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] | 340 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 341 | if (!s_info) { |
| 342 | ALOGE("failed to allocate mem for s_info list element"); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 346 | while (node) { |
| 347 | if (strcmp(node->name, FLAGS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 348 | s_info->flags = parse_flag_names((char *)node->value); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 349 | } else if (strcmp(node->name, PROFILES_TAG) == 0) { |
| 350 | 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] | 351 | } else if (strcmp(node->name, FORMATS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 352 | parse_format_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 353 | } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 354 | s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 355 | parse_sample_rate_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 356 | } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 357 | 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] | 358 | } else if (strcmp(node->name, APP_TYPE_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 359 | 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] | 360 | } |
| 361 | node = node->next; |
| 362 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 363 | list_add_tail(streams_cfg_list, &s_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 366 | static void load_cfg_list(cnode *root, void *platform, |
| 367 | struct listnode *streams_output_cfg_list, |
| 368 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 369 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 370 | cnode *node = NULL; |
| 371 | |
| 372 | node = config_find(root, OUTPUTS_TAG); |
| 373 | if (node != NULL) { |
| 374 | node = node->first_child; |
| 375 | while (node) { |
| 376 | ALOGV("%s: loading output %s", __func__, node->name); |
| 377 | update_streams_cfg_list(node, platform, streams_output_cfg_list); |
| 378 | node = node->next; |
| 379 | } |
| 380 | } else { |
| 381 | ALOGI("%s: could not load output, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 384 | node = config_find(root, INPUTS_TAG); |
| 385 | if (node != NULL) { |
| 386 | node = node->first_child; |
| 387 | while (node) { |
| 388 | ALOGV("%s: loading input %s", __func__, node->name); |
| 389 | update_streams_cfg_list(node, platform, streams_input_cfg_list); |
| 390 | node = node->next; |
| 391 | } |
| 392 | } else { |
| 393 | ALOGI("%s: could not load input, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | static void send_app_type_cfg(void *platform, struct mixer *mixer, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 398 | struct listnode *streams_output_cfg_list, |
| 399 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 400 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 401 | 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] | 402 | int length = 0, i, num_app_types = 0; |
| 403 | struct listnode *node; |
| 404 | bool update; |
| 405 | struct mixer_ctl *ctl = NULL; |
| 406 | const char *mixer_ctl_name = "App Type Config"; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 407 | struct streams_io_cfg *s_info = NULL; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 408 | uint32_t target_bit_width = 0; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 409 | |
| 410 | if (!mixer) { |
| 411 | ALOGE("%s: mixer is null",__func__); |
| 412 | return; |
| 413 | } |
| 414 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 415 | if (!ctl) { |
| 416 | ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); |
| 417 | return; |
| 418 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 419 | app_type_cfg[length++] = num_app_types; |
| 420 | |
| 421 | if (list_empty(streams_output_cfg_list)) { |
| 422 | 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] | 423 | app_type_cfg[length++] = 48000; |
| 424 | app_type_cfg[length++] = 16; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 425 | num_app_types += 1; |
| 426 | } |
| 427 | if (list_empty(streams_input_cfg_list)) { |
| 428 | app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 429 | app_type_cfg[length++] = 48000; |
| 430 | app_type_cfg[length++] = 16; |
| 431 | num_app_types += 1; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 434 | /* get target bit width for ADM enforce mode */ |
| 435 | target_bit_width = adev_get_dsp_bit_width_enforce_mode(); |
| 436 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 437 | list_for_each(node, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 438 | 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] | 439 | update = true; |
| 440 | for (i=0; i<length; i=i+3) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 441 | if (app_type_cfg[i+1] == 0) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 442 | break; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 443 | 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] | 444 | 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] | 445 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 446 | 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] | 447 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 448 | /* ADM bit width = max(enforce_bit_width, bit_width from s_info */ |
| 449 | if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) && |
| 450 | (target_bit_width > app_type_cfg[i+3])) |
| 451 | app_type_cfg[i+3] = target_bit_width; |
| 452 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 453 | update = false; |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 458 | num_app_types += 1; |
| 459 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 460 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 461 | app_type_cfg[length] = s_info->app_type_cfg.bit_width; |
| 462 | if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) && |
| 463 | (target_bit_width > app_type_cfg[length])) |
| 464 | app_type_cfg[length] = target_bit_width; |
| 465 | |
| 466 | length++; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | list_for_each(node, streams_input_cfg_list) { |
| 470 | s_info = node_to_item(node, struct streams_io_cfg, list); |
| 471 | update = true; |
| 472 | for (i=0; i<length; i=i+3) { |
| 473 | if (app_type_cfg[i+1] == 0) |
| 474 | break; |
| 475 | 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] | 476 | 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] | 477 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 478 | 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] | 479 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
| 480 | update = false; |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
| 485 | num_app_types += 1; |
| 486 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 487 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
| 488 | 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] | 489 | } |
| 490 | } |
| 491 | ALOGV("%s: num_app_types: %d", __func__, num_app_types); |
| 492 | if (num_app_types) { |
| 493 | app_type_cfg[0] = num_app_types; |
| 494 | mixer_ctl_set_array(ctl, app_type_cfg, length); |
| 495 | } |
| 496 | } |
| 497 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 498 | void audio_extn_utils_update_streams_cfg_lists(void *platform, |
| 499 | struct mixer *mixer, |
| 500 | struct listnode *streams_output_cfg_list, |
| 501 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 502 | { |
| 503 | cnode *root; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 504 | char *data = NULL; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 505 | |
| 506 | ALOGV("%s", __func__); |
| 507 | list_init(streams_output_cfg_list); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 508 | list_init(streams_input_cfg_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 509 | |
| 510 | root = config_node("", ""); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 511 | if (root == NULL) { |
| 512 | ALOGE("cfg_list, NULL config root"); |
| 513 | return; |
| 514 | } |
| 515 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 516 | data = (char *)load_file(AUDIO_IO_POLICY_VENDOR_CONFIG_FILE, NULL); |
| 517 | if (data == NULL) { |
| 518 | ALOGD("%s: failed to open io config file(%s), trying older config file", |
| 519 | __func__, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE); |
| 520 | data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL); |
| 521 | if (data == NULL) { |
| 522 | send_app_type_cfg(platform, mixer, |
| 523 | streams_output_cfg_list, |
| 524 | streams_input_cfg_list); |
| 525 | ALOGE("%s: could not load io policy config!", __func__); |
yidongh | 6eb4f75 | 2017-04-19 18:20:57 +0800 | [diff] [blame] | 526 | free(root); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 527 | return; |
| 528 | } |
| 529 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 530 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 531 | config_load(root, data); |
| 532 | load_cfg_list(root, platform, streams_output_cfg_list, |
| 533 | streams_input_cfg_list); |
| 534 | |
| 535 | send_app_type_cfg(platform, mixer, streams_output_cfg_list, |
| 536 | streams_input_cfg_list); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 537 | |
| 538 | config_free(root); |
yidongh | 6eb4f75 | 2017-04-19 18:20:57 +0800 | [diff] [blame] | 539 | free(root); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 540 | free(data); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 543 | static void audio_extn_utils_dump_streams_cfg_list( |
| 544 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 545 | { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 546 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 547 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 548 | struct stream_format *sf_info; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 549 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 550 | |
| 551 | list_for_each(node_i, streams_cfg_list) { |
| 552 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 553 | ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d", |
| 554 | __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate, |
| 555 | s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type); |
| 556 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 557 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 558 | ALOGV("format-%x", sf_info->format); |
| 559 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 560 | list_for_each(node_j, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 561 | ss_info = node_to_item(node_j, struct stream_sample_rate, list); |
| 562 | ALOGV("sample rate-%d", ss_info->sample_rate); |
| 563 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 567 | void audio_extn_utils_dump_streams_cfg_lists( |
| 568 | struct listnode *streams_output_cfg_list, |
| 569 | struct listnode *streams_input_cfg_list) |
| 570 | { |
| 571 | ALOGV("%s", __func__); |
| 572 | audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list); |
| 573 | audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list); |
| 574 | } |
| 575 | |
| 576 | static void audio_extn_utils_release_streams_cfg_list( |
| 577 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 578 | { |
| 579 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 580 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 581 | |
| 582 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 583 | |
| 584 | while (!list_empty(streams_cfg_list)) { |
| 585 | node_i = list_head(streams_cfg_list); |
| 586 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 587 | while (!list_empty(&s_info->format_list)) { |
| 588 | node_j = list_head(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 589 | list_remove(node_j); |
| 590 | free(node_to_item(node_j, struct stream_format, list)); |
| 591 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 592 | while (!list_empty(&s_info->sample_rate_list)) { |
| 593 | node_j = list_head(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 594 | list_remove(node_j); |
| 595 | free(node_to_item(node_j, struct stream_sample_rate, list)); |
| 596 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 597 | list_remove(node_i); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 598 | 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] | 599 | } |
| 600 | } |
| 601 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 602 | void audio_extn_utils_release_streams_cfg_lists( |
| 603 | struct listnode *streams_output_cfg_list, |
| 604 | struct listnode *streams_input_cfg_list) |
| 605 | { |
| 606 | ALOGV("%s", __func__); |
| 607 | audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list); |
| 608 | audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list); |
| 609 | } |
| 610 | |
| 611 | static bool set_app_type_cfg(struct streams_io_cfg *s_info, |
| 612 | struct stream_app_type_cfg *app_type_cfg, |
| 613 | uint32_t sample_rate, uint32_t bit_width) |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 614 | { |
| 615 | struct listnode *node_i; |
| 616 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 617 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 618 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 619 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 620 | (bit_width == s_info->app_type_cfg.bit_width)) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 621 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 622 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 623 | app_type_cfg->sample_rate = ss_info->sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 624 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 625 | ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d", |
| 626 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 627 | return true; |
| 628 | } |
| 629 | } |
| 630 | /* |
| 631 | * Reiterate through the list assuming dafault sample rate. |
| 632 | * Handles scenario where input sample rate is higher |
| 633 | * than all sample rates in list for the input bit width. |
| 634 | */ |
| 635 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 636 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 637 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 638 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 639 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 640 | (bit_width == s_info->app_type_cfg.bit_width)) { |
| 641 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 642 | app_type_cfg->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 643 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 644 | 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] | 645 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 646 | return true; |
| 647 | } |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 652 | void audio_extn_utils_update_stream_input_app_type_cfg(void *platform, |
| 653 | struct listnode *streams_input_cfg_list, |
| 654 | audio_devices_t devices __unused, |
| 655 | audio_input_flags_t flags, |
| 656 | audio_format_t format, |
| 657 | uint32_t sample_rate, |
| 658 | uint32_t bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 659 | char* profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 660 | struct stream_app_type_cfg *app_type_cfg) |
| 661 | { |
| 662 | struct listnode *node_i, *node_j; |
| 663 | struct streams_io_cfg *s_info; |
| 664 | struct stream_format *sf_info; |
| 665 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 666 | ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s", |
| 667 | __func__, flags, format, sample_rate, profile); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 668 | |
| 669 | list_for_each(node_i, streams_input_cfg_list) { |
| 670 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 671 | /* Along with flags do profile matching if set at either end.*/ |
| 672 | if (s_info->flags.in_flags == flags && |
| 673 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 674 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 675 | list_for_each(node_j, &s_info->format_list) { |
| 676 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 677 | if (sf_info->format == format) { |
| 678 | if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width)) |
| 679 | return; |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | ALOGW("%s: App type could not be selected. Falling back to default", __func__); |
| 685 | app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 686 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 687 | app_type_cfg->bit_width = 16; |
| 688 | } |
| 689 | |
| 690 | 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] | 691 | struct listnode *streams_output_cfg_list, |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 692 | audio_devices_t devices, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 693 | audio_output_flags_t flags, |
| 694 | audio_format_t format, |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 695 | uint32_t sample_rate, |
| 696 | uint32_t bit_width, |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 697 | audio_channel_mask_t channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 698 | char *profile, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 699 | struct stream_app_type_cfg *app_type_cfg) |
| 700 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 701 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 702 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 703 | struct stream_format *sf_info; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 704 | char value[PROPERTY_VALUE_MAX] = {0}; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 705 | |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 706 | if ((bit_width >= 24) && |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 707 | (devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 708 | int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER); |
| 709 | if (-ENOSYS != bw) |
| 710 | bit_width = (uint32_t)bw; |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 711 | sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 712 | ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__); |
| 713 | } |
| 714 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 715 | property_get("vendor.audio.playback.mch.downsample",value,""); |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 716 | if (!strncmp("true", value, sizeof("true"))) { |
| 717 | if ((popcount(channel_mask) > 2) && |
| 718 | (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 719 | !(flags & (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) { |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 720 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 721 | ALOGD("%s: MCH session defaulting sample rate to %d", |
| 722 | __func__, sample_rate); |
| 723 | } |
| 724 | } |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 725 | |
| 726 | /* Set sampling rate to 176.4 for DSD64 |
| 727 | * and 352.8Khz for DSD128. |
| 728 | * Set Bit Width to 16. output will be 16 bit |
| 729 | * post DoP in ASM. |
| 730 | */ |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 731 | if ((flags & (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) && |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 732 | (format == AUDIO_FORMAT_DSD)) { |
| 733 | bit_width = 16; |
| 734 | if (sample_rate == INPUT_SAMPLING_RATE_DSD64) |
| 735 | sample_rate = OUTPUT_SAMPLING_RATE_DSD64; |
| 736 | else if (sample_rate == INPUT_SAMPLING_RATE_DSD128) |
| 737 | sample_rate = OUTPUT_SAMPLING_RATE_DSD128; |
| 738 | } |
| 739 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 740 | |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 741 | ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d", |
| 742 | __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] | 743 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 744 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 745 | /* Along with flags do profile matching if set at either end.*/ |
| 746 | if (s_info->flags.out_flags == flags && |
| 747 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 748 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 749 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 750 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 751 | if (sf_info->format == format) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 752 | 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] | 753 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 759 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 760 | if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 761 | ALOGV("Compatible output profile not found."); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 762 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
| 763 | app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate; |
| 764 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 765 | ALOGV("%s Default to primary output: App type: %d sample_rate %d", |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 766 | __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] | 767 | return; |
| 768 | } |
| 769 | } |
| 770 | 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] | 771 | app_type_cfg->app_type = platform_get_default_app_type(platform); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 772 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 773 | app_type_cfg->bit_width = 16; |
| 774 | } |
| 775 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 776 | static bool audio_is_this_native_usecase(struct audio_usecase *uc) |
| 777 | { |
| 778 | bool native_usecase = false; |
| 779 | struct stream_out *out = (struct stream_out*) uc->stream.out; |
| 780 | |
| 781 | if (PCM_PLAYBACK == uc->type && out != NULL && |
| 782 | NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() && |
| 783 | is_offload_usecase(uc->id) && |
| 784 | (out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) |
| 785 | native_usecase = true; |
| 786 | |
| 787 | return native_usecase; |
| 788 | } |
| 789 | |
Xiaojun Sang | 785b5da | 2017-08-03 15:52:29 +0800 | [diff] [blame] | 790 | bool audio_extn_is_dsp_bit_width_enforce_mode_supported(audio_output_flags_t flags) |
| 791 | { |
| 792 | /* DSP bitwidth enforce mode for ADM and AFE: |
| 793 | * includes: |
| 794 | * deep buffer, low latency, direct pcm and offload. |
| 795 | * excludes: |
| 796 | * ull(raw+fast), VOIP. |
| 797 | */ |
| 798 | if ((flags & AUDIO_OUTPUT_FLAG_VOIP_RX) || |
| 799 | ((flags & AUDIO_OUTPUT_FLAG_RAW) && |
| 800 | (flags & AUDIO_OUTPUT_FLAG_FAST))) |
| 801 | return false; |
| 802 | |
| 803 | |
| 804 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) || |
| 805 | (flags & AUDIO_OUTPUT_FLAG_DIRECT) || |
| 806 | (flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) || |
| 807 | (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) |
| 808 | return true; |
| 809 | else |
| 810 | return false; |
| 811 | } |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 812 | |
| 813 | static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev)) |
| 814 | { |
| 815 | return adev->vr_audio_mode_enabled; |
| 816 | } |
| 817 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 818 | void audio_extn_utils_update_stream_app_type_cfg_for_usecase( |
| 819 | struct audio_device *adev, |
| 820 | struct audio_usecase *usecase) |
| 821 | { |
| 822 | ALOGV("%s", __func__); |
| 823 | |
| 824 | switch(usecase->type) { |
| 825 | case PCM_PLAYBACK: |
| 826 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 827 | &adev->streams_output_cfg_list, |
| 828 | usecase->stream.out->devices, |
| 829 | usecase->stream.out->flags, |
Aalique Grahame | 65780b5 | 2017-09-27 14:59:56 -0700 | [diff] [blame] | 830 | usecase->stream.out->hal_op_format, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 831 | usecase->stream.out->sample_rate, |
| 832 | usecase->stream.out->bit_width, |
| 833 | usecase->stream.out->channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 834 | usecase->stream.out->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 835 | &usecase->stream.out->app_type_cfg); |
| 836 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type); |
| 837 | break; |
| 838 | case PCM_CAPTURE: |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 839 | if (usecase->id == USECASE_AUDIO_RECORD_VOIP) |
| 840 | usecase->stream.in->app_type_cfg.app_type = APP_TYPE_VOIP_AUDIO; |
| 841 | else |
| 842 | audio_extn_utils_update_stream_input_app_type_cfg(adev->platform, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 843 | &adev->streams_input_cfg_list, |
| 844 | usecase->stream.in->device, |
| 845 | usecase->stream.in->flags, |
| 846 | usecase->stream.in->format, |
| 847 | usecase->stream.in->sample_rate, |
| 848 | usecase->stream.in->bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 849 | usecase->stream.in->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 850 | &usecase->stream.in->app_type_cfg); |
| 851 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type); |
| 852 | break; |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 853 | case TRANSCODE_LOOPBACK : |
| 854 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 855 | &adev->streams_output_cfg_list, |
| 856 | usecase->stream.inout->out_config.devices, |
| 857 | 0, |
| 858 | usecase->stream.inout->out_config.format, |
| 859 | usecase->stream.inout->out_config.sample_rate, |
| 860 | usecase->stream.inout->out_config.bit_width, |
| 861 | usecase->stream.inout->out_config.channel_mask, |
| 862 | usecase->stream.inout->profile, |
| 863 | &usecase->stream.inout->out_app_type_cfg); |
| 864 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.inout->out_app_type_cfg.app_type); |
| 865 | break; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 866 | default: |
| 867 | ALOGE("%s: app type cfg not supported for usecase type (%d)", |
| 868 | __func__, usecase->type); |
| 869 | } |
| 870 | } |
| 871 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 872 | static int send_app_type_cfg_for_device(struct audio_device *adev, |
| 873 | struct audio_usecase *usecase, |
| 874 | int split_snd_device) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 875 | { |
| 876 | char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 877 | size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0}; |
| 878 | int len = 0, rc; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 879 | struct mixer_ctl *ctl; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 880 | int pcm_device_id = 0, acdb_dev_id, app_type; |
| 881 | int snd_device = split_snd_device, snd_device_be_idx = -1; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 882 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 883 | char value[PROPERTY_VALUE_MAX] = {0}; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 884 | struct streams_io_cfg *s_info = NULL; |
| 885 | struct listnode *node = NULL; |
Nikhil Laturkar | ac4a749 | 2017-08-31 18:27:19 +0530 | [diff] [blame] | 886 | int bd_app_type = 0; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 887 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 888 | ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s", |
| 889 | __func__, platform_get_snd_device_name(usecase->out_snd_device), |
| 890 | platform_get_snd_device_name(usecase->in_snd_device), |
| 891 | platform_get_snd_device_name(split_snd_device)); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 892 | |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 893 | if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE && |
| 894 | usecase->type != TRANSCODE_LOOPBACK) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 895 | 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] | 896 | rc = 0; |
| 897 | goto exit_send_app_type_cfg; |
| 898 | } |
| 899 | if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) && |
| 900 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) && |
| 901 | (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) && |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 902 | (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) && |
Vikram Panduranga | 93f080e | 2017-06-07 18:16:14 -0700 | [diff] [blame] | 903 | (usecase->id != USECASE_AUDIO_PLAYBACK_VOIP) && |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 904 | (usecase->id != USECASE_AUDIO_TRANSCODE_LOOPBACK) && |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 905 | (!is_interactive_usecase(usecase->id)) && |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 906 | (!is_offload_usecase(usecase->id)) && |
| 907 | (usecase->type != PCM_CAPTURE)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 908 | 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] | 909 | rc = 0; |
| 910 | goto exit_send_app_type_cfg; |
| 911 | } |
Alexy Joseph | 5e4ccbc | 2017-02-21 14:20:12 -0800 | [diff] [blame] | 912 | |
| 913 | //if VR is active then only send the mixer control |
| 914 | if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) { |
| 915 | ALOGI("ULL doesnt need sending app type cfg, returning"); |
| 916 | rc = 0; |
| 917 | goto exit_send_app_type_cfg; |
| 918 | } |
| 919 | |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 920 | if (usecase->type == PCM_PLAYBACK || usecase->type == TRANSCODE_LOOPBACK) { |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 921 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 922 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 923 | "Audio Stream %d App Type Cfg", pcm_device_id); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 924 | } else if (usecase->type == PCM_CAPTURE) { |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 925 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 926 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 927 | "Audio Stream Capture %d App Type Cfg", pcm_device_id); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 928 | } |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 929 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 930 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 931 | if (!ctl) { |
| 932 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, |
| 933 | mixer_ctl_name); |
| 934 | rc = -EINVAL; |
| 935 | goto exit_send_app_type_cfg; |
| 936 | } |
Aditya Bavanari | 701a699 | 2017-03-30 19:17:16 +0530 | [diff] [blame] | 937 | snd_device = platform_get_spkr_prot_snd_device(snd_device); |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 938 | |
Rohit Kumar | 1181b29 | 2017-01-31 18:07:17 +0530 | [diff] [blame] | 939 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 940 | if (acdb_dev_id <= 0) { |
| 941 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 942 | rc = -EINVAL; |
| 943 | goto exit_send_app_type_cfg; |
| 944 | } |
| 945 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 946 | snd_device_be_idx = platform_get_snd_device_backend_index(snd_device); |
| 947 | if (snd_device_be_idx < 0) { |
| 948 | ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d", |
| 949 | __func__, platform_get_snd_device_name(snd_device), |
| 950 | snd_device_be_idx); |
| 951 | } |
| 952 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 953 | if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) { |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 954 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 955 | property_get("vendor.audio.playback.mch.downsample",value,""); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 956 | if (!strncmp("true", value, sizeof("true"))) { |
| 957 | if ((popcount(usecase->stream.out->channel_mask) > 2) && |
| 958 | (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 959 | !(usecase->stream.out->flags & |
| 960 | (audio_output_flags_t)AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 961 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 962 | } |
Ashish Jain | c02430d | 2016-01-04 10:42:43 +0530 | [diff] [blame] | 963 | |
kunleiz | cdf2594 | 2017-09-20 14:01:21 +0800 | [diff] [blame] | 964 | if (usecase->id == USECASE_AUDIO_PLAYBACK_VOIP) { |
| 965 | usecase->stream.out->app_type_cfg.sample_rate = usecase->stream.out->sample_rate; |
| 966 | } else if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 967 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Ashish Jain | a052e57 | 2016-11-07 16:41:07 +0530 | [diff] [blame] | 968 | } else if ((snd_device == SND_DEVICE_OUT_HDMI || |
| 969 | snd_device == SND_DEVICE_OUT_USB_HEADSET || |
| 970 | snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && |
| 971 | (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) { |
| 972 | /* |
| 973 | * To best utlize DSP, check if the stream sample rate is supported/multiple of |
| 974 | * configured device sample rate, if not update the COPP rate to be equal to the |
| 975 | * device sample rate, else open COPP at stream sample rate |
| 976 | */ |
| 977 | platform_check_and_update_copp_sample_rate(adev->platform, snd_device, |
| 978 | usecase->stream.out->sample_rate, |
| 979 | &usecase->stream.out->app_type_cfg.sample_rate); |
Ashish Jain | 4826f6c | 2017-02-06 13:33:20 +0530 | [diff] [blame] | 980 | } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && |
| 981 | !audio_is_this_native_usecase(usecase)) && |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 982 | usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || |
| 983 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
Ashish Jain | 4826f6c | 2017-02-06 13:33:20 +0530 | [diff] [blame] | 984 | /* Reset to default if no native stream is active*/ |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 985 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Preetam Singh Ranawat | b7475ba | 2017-02-24 18:17:06 +0530 | [diff] [blame] | 986 | } else if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_ALL_A2DP) { |
| 987 | /* |
| 988 | * For a2dp playback get encoder sampling rate and set copp sampling rate, |
| 989 | * for bit width use the stream param only. |
| 990 | */ |
| 991 | audio_extn_a2dp_get_sample_rate(&usecase->stream.out->app_type_cfg.sample_rate); |
| 992 | ALOGI("%s using %d sample rate rate for A2DP CoPP", |
| 993 | __func__, usecase->stream.out->app_type_cfg.sample_rate); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 994 | } |
| 995 | sample_rate = usecase->stream.out->app_type_cfg.sample_rate; |
| 996 | |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 997 | /* Interactive streams are supported with only direct app type id. |
| 998 | * Get Direct profile app type and use it for interactive streams |
| 999 | */ |
| 1000 | list_for_each(node, &adev->streams_output_cfg_list) { |
| 1001 | s_info = node_to_item(node, struct streams_io_cfg, list); |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 1002 | 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] | 1003 | AUDIO_OUTPUT_FLAG_DIRECT_PCM | |
| 1004 | AUDIO_OUTPUT_FLAG_DIRECT)) |
| 1005 | bd_app_type = s_info->app_type_cfg.app_type; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1006 | } |
Aalique Grahame | 5cd12ff | 2017-10-19 10:57:00 -0700 | [diff] [blame] | 1007 | 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] | 1008 | app_type = bd_app_type; |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 1009 | else |
| 1010 | app_type = usecase->stream.out->app_type_cfg.app_type; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1011 | app_type_cfg[len++] = app_type; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 1012 | app_type_cfg[len++] = acdb_dev_id; |
| 1013 | if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) || |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 1014 | (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) || |
| 1015 | (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD)) |
Harsh Bansal | 026d97f | 2017-08-17 17:44:49 +0530 | [diff] [blame] | 1016 | && audio_extn_passthru_is_passthrough_stream(usecase->stream.out) |
| 1017 | && !audio_extn_passthru_is_convert_supported(adev, usecase->stream.out)) { |
Naresh Tanniru | 3a40677 | 2017-05-10 13:09:05 -0700 | [diff] [blame] | 1018 | |
| 1019 | sample_rate = sample_rate * 4; |
| 1020 | if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE) |
| 1021 | sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 1022 | } |
Naresh Tanniru | 3a40677 | 2017-05-10 13:09:05 -0700 | [diff] [blame] | 1023 | app_type_cfg[len++] = sample_rate; |
| 1024 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1025 | if (snd_device_be_idx > 0) |
| 1026 | app_type_cfg[len++] = snd_device_be_idx; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1027 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1028 | ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1029 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1030 | |
| 1031 | } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) { |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1032 | app_type = usecase->stream.in->app_type_cfg.app_type; |
| 1033 | app_type_cfg[len++] = app_type; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1034 | app_type_cfg[len++] = acdb_dev_id; |
kunleiz | cdf2594 | 2017-09-20 14:01:21 +0800 | [diff] [blame] | 1035 | if (usecase->id == USECASE_AUDIO_RECORD_VOIP) |
| 1036 | usecase->stream.in->app_type_cfg.sample_rate = usecase->stream.in->sample_rate; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1037 | sample_rate = usecase->stream.in->app_type_cfg.sample_rate; |
| 1038 | app_type_cfg[len++] = sample_rate; |
| 1039 | if (snd_device_be_idx > 0) |
| 1040 | app_type_cfg[len++] = snd_device_be_idx; |
| 1041 | ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1042 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1043 | } else { |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1044 | app_type = platform_get_default_app_type_v2(adev->platform, usecase->type); |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1045 | if(usecase->type == TRANSCODE_LOOPBACK) { |
| 1046 | sample_rate = usecase->stream.inout->out_config.sample_rate; |
| 1047 | app_type = usecase->stream.inout->out_app_type_cfg.app_type; |
| 1048 | } |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1049 | app_type_cfg[len++] = app_type; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1050 | app_type_cfg[len++] = acdb_dev_id; |
| 1051 | app_type_cfg[len++] = sample_rate; |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1052 | if (snd_device_be_idx > 0) |
| 1053 | app_type_cfg[len++] = snd_device_be_idx; |
| 1054 | ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d", |
| 1055 | __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx); |
Ashish Jain | c02430d | 2016-01-04 10:42:43 +0530 | [diff] [blame] | 1056 | } |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1057 | |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1058 | if(ctl) |
| 1059 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1060 | rc = 0; |
| 1061 | exit_send_app_type_cfg: |
| 1062 | return rc; |
| 1063 | } |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1064 | |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1065 | int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, |
| 1066 | struct audio_usecase *usecase) |
| 1067 | { |
| 1068 | int i, num_devices = 0; |
| 1069 | snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0}; |
| 1070 | int rc = 0; |
| 1071 | |
| 1072 | switch (usecase->type) { |
| 1073 | case PCM_PLAYBACK: |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1074 | case TRANSCODE_LOOPBACK: |
Siena Richard | 7c2db77 | 2016-12-21 11:32:34 -0800 | [diff] [blame] | 1075 | ALOGD("%s: usecase->out_snd_device %s", |
| 1076 | __func__, platform_get_snd_device_name(usecase->out_snd_device)); |
| 1077 | /* check for out combo device */ |
| 1078 | if (platform_split_snd_device(adev->platform, |
| 1079 | usecase->out_snd_device, |
| 1080 | &num_devices, new_snd_devices)) { |
| 1081 | new_snd_devices[0] = usecase->out_snd_device; |
| 1082 | num_devices = 1; |
| 1083 | } |
| 1084 | break; |
| 1085 | case PCM_CAPTURE: |
| 1086 | ALOGD("%s: usecase->in_snd_device %s", |
| 1087 | __func__, platform_get_snd_device_name(usecase->in_snd_device)); |
| 1088 | /* check for in combo device */ |
| 1089 | if (platform_split_snd_device(adev->platform, |
| 1090 | usecase->in_snd_device, |
| 1091 | &num_devices, new_snd_devices)) { |
| 1092 | new_snd_devices[0] = usecase->in_snd_device; |
| 1093 | num_devices = 1; |
| 1094 | } |
| 1095 | break; |
| 1096 | default: |
| 1097 | ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__); |
| 1098 | rc = 0; |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | for (i = 0; i < num_devices; i++) { |
| 1103 | rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]); |
| 1104 | if (rc) |
| 1105 | break; |
| 1106 | } |
| 1107 | |
| 1108 | return rc; |
| 1109 | } |
| 1110 | |
Preetam Singh Ranawat | 9519e9c | 2015-11-18 16:05:55 +0530 | [diff] [blame] | 1111 | int read_line_from_file(const char *path, char *buf, size_t count) |
| 1112 | { |
| 1113 | char * fgets_ret; |
| 1114 | FILE * fd; |
| 1115 | int rv; |
| 1116 | |
| 1117 | fd = fopen(path, "r"); |
| 1118 | if (fd == NULL) |
| 1119 | return -1; |
| 1120 | |
| 1121 | fgets_ret = fgets(buf, (int)count, fd); |
| 1122 | if (NULL != fgets_ret) { |
| 1123 | rv = (int)strlen(buf); |
| 1124 | } else { |
| 1125 | rv = ferror(fd); |
| 1126 | } |
| 1127 | fclose(fd); |
| 1128 | |
| 1129 | return rv; |
| 1130 | } |
| 1131 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1132 | /*Translates ALSA formats to AOSP PCM formats*/ |
| 1133 | audio_format_t alsa_format_to_hal(uint32_t alsa_format) |
| 1134 | { |
| 1135 | audio_format_t format; |
| 1136 | |
| 1137 | switch(alsa_format) { |
| 1138 | case SNDRV_PCM_FORMAT_S16_LE: |
| 1139 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 1140 | break; |
| 1141 | case SNDRV_PCM_FORMAT_S24_3LE: |
| 1142 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 1143 | break; |
| 1144 | case SNDRV_PCM_FORMAT_S24_LE: |
| 1145 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 1146 | break; |
| 1147 | case SNDRV_PCM_FORMAT_S32_LE: |
| 1148 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 1149 | break; |
| 1150 | default: |
| 1151 | ALOGW("Incorrect ALSA format"); |
| 1152 | format = AUDIO_FORMAT_INVALID; |
| 1153 | } |
| 1154 | return format; |
| 1155 | } |
| 1156 | |
| 1157 | /*Translates hal format (AOSP) to alsa formats*/ |
| 1158 | uint32_t hal_format_to_alsa(audio_format_t hal_format) |
| 1159 | { |
| 1160 | uint32_t alsa_format; |
| 1161 | |
| 1162 | switch (hal_format) { |
| 1163 | case AUDIO_FORMAT_PCM_32_BIT: { |
| 1164 | if (platform_supports_true_32bit()) |
| 1165 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 1166 | else |
| 1167 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1168 | } |
| 1169 | break; |
| 1170 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1171 | alsa_format = SNDRV_PCM_FORMAT_S8; |
| 1172 | break; |
| 1173 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1174 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1175 | break; |
| 1176 | case AUDIO_FORMAT_PCM_8_24_BIT: { |
| 1177 | if (platform_supports_true_32bit()) |
| 1178 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 1179 | else |
| 1180 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1181 | } |
| 1182 | break; |
| 1183 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1184 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 1185 | break; |
| 1186 | default: |
| 1187 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1188 | alsa_format = SNDRV_PCM_FORMAT_S16_LE; |
| 1189 | break; |
| 1190 | } |
| 1191 | return alsa_format; |
| 1192 | } |
| 1193 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1194 | /*Translates PCM formats to AOSP formats*/ |
| 1195 | audio_format_t pcm_format_to_hal(uint32_t pcm_format) |
| 1196 | { |
| 1197 | audio_format_t format = AUDIO_FORMAT_INVALID; |
| 1198 | |
| 1199 | switch(pcm_format) { |
| 1200 | case PCM_FORMAT_S16_LE: |
| 1201 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 1202 | break; |
| 1203 | case PCM_FORMAT_S24_3LE: |
| 1204 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 1205 | break; |
| 1206 | case PCM_FORMAT_S24_LE: |
| 1207 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 1208 | break; |
| 1209 | case PCM_FORMAT_S32_LE: |
| 1210 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 1211 | break; |
| 1212 | default: |
| 1213 | ALOGW("Incorrect PCM format"); |
| 1214 | format = AUDIO_FORMAT_INVALID; |
| 1215 | } |
| 1216 | return format; |
| 1217 | } |
| 1218 | |
| 1219 | /*Translates hal format (AOSP) to alsa formats*/ |
| 1220 | uint32_t hal_format_to_pcm(audio_format_t hal_format) |
| 1221 | { |
| 1222 | uint32_t pcm_format; |
| 1223 | |
| 1224 | switch (hal_format) { |
| 1225 | case AUDIO_FORMAT_PCM_32_BIT: |
| 1226 | case AUDIO_FORMAT_PCM_8_24_BIT: |
| 1227 | case AUDIO_FORMAT_PCM_FLOAT: { |
| 1228 | if (platform_supports_true_32bit()) |
| 1229 | pcm_format = PCM_FORMAT_S32_LE; |
| 1230 | else |
| 1231 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1232 | } |
| 1233 | break; |
| 1234 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1235 | pcm_format = PCM_FORMAT_S8; |
| 1236 | break; |
| 1237 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1238 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1239 | break; |
| 1240 | default: |
| 1241 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1242 | pcm_format = PCM_FORMAT_S16_LE; |
| 1243 | break; |
| 1244 | } |
| 1245 | return pcm_format; |
| 1246 | } |
| 1247 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1248 | uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample, |
| 1249 | uint32_t sample_rate, |
| 1250 | uint32_t noOfChannels) |
| 1251 | { |
| 1252 | uint32_t fragment_size = 0; |
| 1253 | uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION; |
| 1254 | |
| 1255 | fragment_size = (pcm_offload_time |
| 1256 | * sample_rate |
| 1257 | * bytes_per_sample |
| 1258 | * noOfChannels)/1000; |
| 1259 | if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1260 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1261 | else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1262 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1263 | /*To have same PCM samples for all channels, the buffer size requires to |
| 1264 | *be multiple of (number of channels * bytes per sample) |
| 1265 | *For writes to succeed, the buffer must be written at address which is multiple of 32 |
| 1266 | */ |
Aalique Grahame | b85f2d9 | 2017-10-16 17:53:23 -0700 | [diff] [blame] | 1267 | fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32)); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1268 | |
| 1269 | ALOGI("PCM offload Fragment size to %d bytes", fragment_size); |
| 1270 | return fragment_size; |
| 1271 | } |
| 1272 | |
| 1273 | /* Calculates the fragment size required to configure compress session. |
| 1274 | * Based on the alsa format selected, decide if conversion is needed in |
| 1275 | |
| 1276 | * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to |
| 1277 | * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver. |
| 1278 | */ |
| 1279 | void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out) |
| 1280 | { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1281 | audio_format_t dst_format = out->hal_op_format; |
| 1282 | audio_format_t src_format = out->hal_ip_format; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1283 | uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format); |
| 1284 | uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format); |
| 1285 | |
| 1286 | out->compr_config.fragment_size = |
| 1287 | get_alsa_fragment_size(hal_op_bytes_per_sample, |
| 1288 | out->sample_rate, |
| 1289 | popcount(out->channel_mask)); |
| 1290 | |
| 1291 | if ((src_format != dst_format) && |
| 1292 | hal_op_bytes_per_sample != hal_ip_bytes_per_sample) { |
| 1293 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1294 | out->hal_fragment_size = |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1295 | ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) / |
| 1296 | hal_op_bytes_per_sample); |
| 1297 | 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] | 1298 | out->hal_fragment_size, src_format, dst_format); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1299 | } else { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1300 | out->hal_fragment_size = out->compr_config.fragment_size; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1304 | /* converts pcm format 24_8 to 8_24 inplace */ |
| 1305 | size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes) |
| 1306 | { |
| 1307 | size_t i = 0; |
| 1308 | int *int_buf_stream = buf; |
| 1309 | |
| 1310 | if ((bytes % 4) != 0) { |
| 1311 | ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__); |
| 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
| 1315 | for (; i < (bytes / 4); i++) |
| 1316 | int_buf_stream[i] >>= 8; |
| 1317 | |
| 1318 | return bytes; |
| 1319 | } |
| 1320 | |
| 1321 | int get_snd_codec_id(audio_format_t format) |
| 1322 | { |
| 1323 | int id = 0; |
| 1324 | |
| 1325 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 1326 | case AUDIO_FORMAT_MP3: |
| 1327 | id = SND_AUDIOCODEC_MP3; |
| 1328 | break; |
| 1329 | case AUDIO_FORMAT_AAC: |
| 1330 | id = SND_AUDIOCODEC_AAC; |
| 1331 | break; |
| 1332 | case AUDIO_FORMAT_AAC_ADTS: |
| 1333 | id = SND_AUDIOCODEC_AAC; |
| 1334 | break; |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 1335 | case AUDIO_FORMAT_AAC_LATM: |
| 1336 | id = SND_AUDIOCODEC_AAC; |
| 1337 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1338 | case AUDIO_FORMAT_PCM: |
| 1339 | id = SND_AUDIOCODEC_PCM; |
| 1340 | break; |
| 1341 | case AUDIO_FORMAT_FLAC: |
| 1342 | id = SND_AUDIOCODEC_FLAC; |
| 1343 | break; |
| 1344 | case AUDIO_FORMAT_ALAC: |
| 1345 | id = SND_AUDIOCODEC_ALAC; |
| 1346 | break; |
| 1347 | case AUDIO_FORMAT_APE: |
| 1348 | id = SND_AUDIOCODEC_APE; |
| 1349 | break; |
| 1350 | case AUDIO_FORMAT_VORBIS: |
| 1351 | id = SND_AUDIOCODEC_VORBIS; |
| 1352 | break; |
| 1353 | case AUDIO_FORMAT_WMA: |
| 1354 | id = SND_AUDIOCODEC_WMA; |
| 1355 | break; |
| 1356 | case AUDIO_FORMAT_WMA_PRO: |
| 1357 | id = SND_AUDIOCODEC_WMA_PRO; |
| 1358 | break; |
Satish Babu Patakokila | 0c31392 | 2016-12-08 12:07:08 +0530 | [diff] [blame] | 1359 | case AUDIO_FORMAT_MP2: |
| 1360 | id = SND_AUDIOCODEC_MP2; |
| 1361 | break; |
Satish Babu Patakokila | 915ecba | 2017-01-10 17:43:56 +0530 | [diff] [blame] | 1362 | case AUDIO_FORMAT_AC3: |
| 1363 | id = SND_AUDIOCODEC_AC3; |
| 1364 | break; |
| 1365 | case AUDIO_FORMAT_E_AC3: |
| 1366 | case AUDIO_FORMAT_E_AC3_JOC: |
| 1367 | id = SND_AUDIOCODEC_EAC3; |
| 1368 | break; |
| 1369 | case AUDIO_FORMAT_DTS: |
| 1370 | case AUDIO_FORMAT_DTS_HD: |
| 1371 | id = SND_AUDIOCODEC_DTS; |
| 1372 | break; |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 1373 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 1374 | id = SND_AUDIOCODEC_TRUEHD; |
| 1375 | break; |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 1376 | case AUDIO_FORMAT_IEC61937: |
| 1377 | id = SND_AUDIOCODEC_IEC61937; |
| 1378 | break; |
Preetam Singh Ranawat | 4277a5a | 2017-01-18 19:02:24 +0530 | [diff] [blame] | 1379 | case AUDIO_FORMAT_DSD: |
| 1380 | id = SND_AUDIOCODEC_DSD; |
| 1381 | break; |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 1382 | case AUDIO_FORMAT_APTX: |
| 1383 | id = SND_AUDIOCODEC_APTX; |
| 1384 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1385 | default: |
| 1386 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
| 1387 | } |
| 1388 | |
| 1389 | return id; |
| 1390 | } |
| 1391 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1392 | void audio_extn_utils_send_audio_calibration(struct audio_device *adev, |
| 1393 | struct audio_usecase *usecase) |
| 1394 | { |
| 1395 | int type = usecase->type; |
| 1396 | |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1397 | if (type == PCM_PLAYBACK && usecase->stream.out != NULL) { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1398 | struct stream_out *out = usecase->stream.out; |
| 1399 | int snd_device = usecase->out_snd_device; |
| 1400 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
Xiaojun Sang | 040cc9f | 2015-08-03 19:38:28 +0800 | [diff] [blame] | 1401 | platform_get_spkr_prot_snd_device(snd_device) : snd_device; |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1402 | platform_send_audio_calibration(adev->platform, usecase, |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1403 | out->app_type_cfg.app_type, |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 1404 | usecase->stream.out->app_type_cfg.sample_rate); |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1405 | } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1406 | platform_send_audio_calibration(adev->platform, usecase, |
| 1407 | usecase->stream.in->app_type_cfg.app_type, |
| 1408 | usecase->stream.in->app_type_cfg.sample_rate); |
Vidyakumar Athota | 653aaef | 2017-03-16 11:11:31 -0700 | [diff] [blame] | 1409 | } else if (type == PCM_HFP_CALL || type == PCM_CAPTURE) { |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1410 | /* when app type is default. the sample rate is not used to send cal */ |
| 1411 | platform_send_audio_calibration(adev->platform, usecase, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1412 | platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 1413 | 48000); |
Siddartha Shaik | 343abc6 | 2017-08-08 11:15:25 +0530 | [diff] [blame] | 1414 | } else if (type == TRANSCODE_LOOPBACK && usecase->stream.inout != NULL) { |
| 1415 | int snd_device = usecase->out_snd_device; |
| 1416 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
| 1417 | platform_get_spkr_prot_snd_device(snd_device) : snd_device; |
| 1418 | platform_send_audio_calibration(adev->platform, usecase, |
| 1419 | platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 1420 | usecase->stream.inout->out_config.sample_rate); |
Vidyakumar Athota | e57f600 | 2017-03-01 13:13:16 -0800 | [diff] [blame] | 1421 | } else { |
| 1422 | /* No need to send audio calibration for voice and voip call usecases */ |
| 1423 | if ((type != VOICE_CALL) && (type != VOIP_CALL)) |
| 1424 | 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] | 1425 | } |
| 1426 | } |
| 1427 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 1428 | // Base64 Encode and Decode |
| 1429 | // Not all features supported. This must be used only with following conditions. |
| 1430 | // Decode Modes: Support with and without padding |
| 1431 | // CRLF not handling. So no CRLF in string to decode. |
| 1432 | // Encode Modes: Supports only padding |
| 1433 | int b64decode(char *inp, int ilen, uint8_t* outp) |
| 1434 | { |
| 1435 | int i, j, k, ii, num; |
| 1436 | int rem, pcnt; |
| 1437 | uint32_t res=0; |
| 1438 | uint8_t getIndex[MAX_BASEINDEX_LEN]; |
| 1439 | uint8_t tmp, cflag; |
| 1440 | |
| 1441 | if(inp == NULL || outp == NULL || ilen <= 0) { |
| 1442 | ALOGE("[%s] received NULL pointer or zero length",__func__); |
| 1443 | return -1; |
| 1444 | } |
| 1445 | |
| 1446 | memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex)); |
| 1447 | for(i=0;i<BASE_TABLE_SIZE;i++) { |
| 1448 | getIndex[(uint8_t)bTable[i]] = (uint8_t)i; |
| 1449 | } |
| 1450 | getIndex[(uint8_t)'=']=0; |
| 1451 | |
| 1452 | j=0;k=0; |
| 1453 | num = ilen/4; |
| 1454 | rem = ilen%4; |
| 1455 | if(rem==0) |
| 1456 | num = num-1; |
| 1457 | cflag=0; |
| 1458 | for(i=0; i<num; i++) { |
| 1459 | res=0; |
| 1460 | for(ii=0;ii<4;ii++) { |
| 1461 | res = res << 6; |
| 1462 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1463 | res = res | tmp; |
| 1464 | cflag = cflag | tmp; |
| 1465 | } |
| 1466 | outp[k++] = (res >> 16)&0xFF; |
| 1467 | outp[k++] = (res >> 8)&0xFF; |
| 1468 | outp[k++] = res & 0xFF; |
| 1469 | } |
| 1470 | |
| 1471 | // Handle last bytes special |
| 1472 | pcnt=0; |
| 1473 | if(rem == 0) { |
| 1474 | //With padding or full data |
| 1475 | res = 0; |
| 1476 | for(ii=0;ii<4;ii++) { |
| 1477 | if(inp[j] == '=') |
| 1478 | pcnt++; |
| 1479 | res = res << 6; |
| 1480 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1481 | res = res | tmp; |
| 1482 | cflag = cflag | tmp; |
| 1483 | } |
| 1484 | outp[k++] = res >> 16; |
| 1485 | if(pcnt == 2) |
| 1486 | goto done; |
| 1487 | outp[k++] = (res>>8)&0xFF; |
| 1488 | if(pcnt == 1) |
| 1489 | goto done; |
| 1490 | outp[k++] = res&0xFF; |
| 1491 | } else { |
| 1492 | //without padding |
| 1493 | res = 0; |
| 1494 | for(i=0;i<rem;i++) { |
| 1495 | res = res << 6; |
| 1496 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1497 | res = res | tmp; |
| 1498 | cflag = cflag | tmp; |
| 1499 | } |
| 1500 | for(i=rem;i<4;i++) { |
| 1501 | res = res << 6; |
| 1502 | pcnt++; |
| 1503 | } |
| 1504 | outp[k++] = res >> 16; |
| 1505 | if(pcnt == 2) |
| 1506 | goto done; |
| 1507 | outp[k++] = (res>>8)&0xFF; |
| 1508 | if(pcnt == 1) |
| 1509 | goto done; |
| 1510 | outp[k++] = res&0xFF; |
| 1511 | } |
| 1512 | done: |
| 1513 | if(cflag == 0xFF) { |
| 1514 | ALOGE("[%s] base64 decode failed. Invalid character found %s", |
| 1515 | __func__, inp); |
| 1516 | return 0; |
| 1517 | } |
| 1518 | return k; |
| 1519 | } |
| 1520 | |
| 1521 | int b64encode(uint8_t *inp, int ilen, char* outp) |
| 1522 | { |
| 1523 | int i,j,k, num; |
| 1524 | int rem=0; |
| 1525 | uint32_t res=0; |
| 1526 | |
| 1527 | if(inp == NULL || outp == NULL || ilen<=0) { |
| 1528 | ALOGE("[%s] received NULL pointer or zero input length",__func__); |
| 1529 | return -1; |
| 1530 | } |
| 1531 | |
| 1532 | num = ilen/3; |
| 1533 | rem = ilen%3; |
| 1534 | j=0;k=0; |
| 1535 | for(i=0; i<num; i++) { |
| 1536 | //prepare index |
| 1537 | res = inp[j++]<<16; |
| 1538 | res = res | inp[j++]<<8; |
| 1539 | res = res | inp[j++]; |
| 1540 | //get output map from index |
| 1541 | outp[k++] = (char) bTable[(res>>18)&0x3F]; |
| 1542 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1543 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 1544 | outp[k++] = (char) bTable[res&0x3F]; |
| 1545 | } |
| 1546 | |
| 1547 | switch(rem) { |
| 1548 | case 1: |
| 1549 | res = inp[j++]<<16; |
| 1550 | outp[k++] = (char) bTable[res>>18]; |
| 1551 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1552 | //outp[k++] = '='; |
| 1553 | //outp[k++] = '='; |
| 1554 | break; |
| 1555 | case 2: |
| 1556 | res = inp[j++]<<16; |
| 1557 | res = res | inp[j++]<<8; |
| 1558 | outp[k++] = (char) bTable[res>>18]; |
| 1559 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1560 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 1561 | //outp[k++] = '='; |
| 1562 | break; |
| 1563 | default: |
| 1564 | break; |
| 1565 | } |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 1566 | outp[k] = '\0'; |
| 1567 | return k; |
| 1568 | } |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1569 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1570 | |
| 1571 | int audio_extn_utils_get_codec_version(const char *snd_card_name, |
| 1572 | int card_num, |
| 1573 | char *codec_version) |
| 1574 | { |
| 1575 | char procfs_path[50]; |
| 1576 | FILE *fp; |
| 1577 | |
| 1578 | if (strstr(snd_card_name, "tasha")) { |
| 1579 | snprintf(procfs_path, sizeof(procfs_path), |
| 1580 | "/proc/asound/card%d/codecs/tasha/version", card_num); |
| 1581 | if ((fp = fopen(procfs_path, "r")) != NULL) { |
| 1582 | fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp); |
| 1583 | fclose(fp); |
| 1584 | } else { |
| 1585 | ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path); |
| 1586 | return -ENOENT; |
| 1587 | } |
| 1588 | ALOGD("%s: codec version %s", __func__, codec_version); |
| 1589 | } |
| 1590 | |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1595 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 1596 | |
| 1597 | void get_default_compressed_channel_status( |
| 1598 | unsigned char *channel_status) |
| 1599 | { |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1600 | memset(channel_status,0,24); |
| 1601 | |
| 1602 | /* block start bit in preamble bit 3 */ |
| 1603 | channel_status[0] |= PROFESSIONAL; |
| 1604 | //compre out |
| 1605 | channel_status[0] |= NON_LPCM; |
| 1606 | // sample rate; fixed 48K for default/transcode |
| 1607 | channel_status[3] |= SR_48000; |
| 1608 | } |
| 1609 | |
| 1610 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 1611 | int32_t get_compressed_channel_status(void *audio_stream_data, |
| 1612 | uint32_t audio_frame_size, |
| 1613 | unsigned char *channel_status, |
| 1614 | enum audio_parser_code_type codec_type) |
| 1615 | // codec_type - AUDIO_PARSER_CODEC_AC3 |
| 1616 | // - AUDIO_PARSER_CODEC_DTS |
| 1617 | { |
| 1618 | unsigned char *stream; |
| 1619 | int ret = 0; |
| 1620 | stream = (unsigned char *)audio_stream_data; |
| 1621 | |
| 1622 | if (audio_stream_data == NULL || audio_frame_size == 0) { |
| 1623 | ALOGW("no buffer to get channel status, return default for compress"); |
| 1624 | get_default_compressed_channel_status(channel_status); |
| 1625 | return ret; |
| 1626 | } |
| 1627 | |
| 1628 | memset(channel_status,0,24); |
| 1629 | if(init_audio_parser(stream, audio_frame_size, codec_type) == -1) |
| 1630 | { |
| 1631 | ALOGE("init audio parser failed"); |
| 1632 | return -1; |
| 1633 | } |
| 1634 | ret = get_channel_status(channel_status, codec_type); |
| 1635 | return ret; |
| 1636 | |
| 1637 | } |
| 1638 | |
| 1639 | #endif |
| 1640 | |
| 1641 | void get_lpcm_channel_status(uint32_t sampleRate, |
| 1642 | unsigned char *channel_status) |
| 1643 | { |
| 1644 | int32_t status = 0; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1645 | memset(channel_status,0,24); |
| 1646 | /* block start bit in preamble bit 3 */ |
| 1647 | channel_status[0] |= PROFESSIONAL; |
| 1648 | //LPCM OUT |
| 1649 | channel_status[0] &= ~NON_LPCM; |
| 1650 | |
| 1651 | switch (sampleRate) { |
| 1652 | case 8000: |
| 1653 | case 11025: |
| 1654 | case 12000: |
| 1655 | case 16000: |
| 1656 | case 22050: |
| 1657 | channel_status[3] |= SR_NOTID; |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 1658 | break; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1659 | case 24000: |
| 1660 | channel_status[3] |= SR_24000; |
| 1661 | break; |
| 1662 | case 32000: |
| 1663 | channel_status[3] |= SR_32000; |
| 1664 | break; |
| 1665 | case 44100: |
| 1666 | channel_status[3] |= SR_44100; |
| 1667 | break; |
| 1668 | case 48000: |
| 1669 | channel_status[3] |= SR_48000; |
| 1670 | break; |
| 1671 | case 88200: |
| 1672 | channel_status[3] |= SR_88200; |
| 1673 | break; |
| 1674 | case 96000: |
| 1675 | channel_status[3] |= SR_96000; |
| 1676 | break; |
| 1677 | case 176400: |
| 1678 | channel_status[3] |= SR_176400; |
| 1679 | break; |
| 1680 | case 192000: |
| 1681 | channel_status[3] |= SR_192000; |
| 1682 | break; |
| 1683 | default: |
| 1684 | ALOGV("Invalid sample_rate %u\n", sampleRate); |
| 1685 | status = -1; |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes) |
| 1691 | { |
| 1692 | unsigned char channel_status[24]={0}; |
| 1693 | struct snd_aes_iec958 iec958; |
| 1694 | const char *mixer_ctl_name = "IEC958 Playback PCM Stream"; |
| 1695 | struct mixer_ctl *ctl; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 1696 | ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes); |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1697 | #ifdef HDMI_PASSTHROUGH_ENABLED |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 1698 | if (audio_extn_utils_is_dolby_format(out->format) && |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1699 | /*TODO:Extend code to support DTS passthrough*/ |
| 1700 | /*set compressed channel status bits*/ |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 1701 | audio_extn_passthru_is_passthrough_stream(out)){ |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1702 | get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3); |
| 1703 | } else |
| 1704 | #endif |
| 1705 | { |
| 1706 | /*set channel status bit for LPCM*/ |
| 1707 | get_lpcm_channel_status(out->sample_rate, channel_status); |
| 1708 | } |
| 1709 | |
| 1710 | memcpy(iec958.status, channel_status,sizeof(iec958.status)); |
| 1711 | ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name); |
| 1712 | if (!ctl) { |
| 1713 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1714 | __func__, mixer_ctl_name); |
| 1715 | return; |
| 1716 | } |
| 1717 | if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) { |
| 1718 | ALOGE("%s: Could not set channel status for ext HDMI ", |
| 1719 | __func__); |
| 1720 | return; |
| 1721 | } |
| 1722 | |
| 1723 | } |
| 1724 | #endif |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1725 | |
| 1726 | int audio_extn_utils_get_avt_device_drift( |
| 1727 | struct audio_usecase *usecase, |
| 1728 | struct audio_avt_device_drift_param *drift_param) |
| 1729 | { |
| 1730 | int ret = 0, count = 0; |
| 1731 | char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0}; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 1732 | const char *backend = NULL; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1733 | struct mixer_ctl *ctl = NULL; |
| 1734 | struct audio_avt_device_drift_stats drift_stats; |
| 1735 | struct audio_device *adev = NULL; |
| 1736 | |
| 1737 | if (usecase != NULL && usecase->type == PCM_PLAYBACK) { |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 1738 | backend = platform_get_snd_device_backend_interface(usecase->out_snd_device); |
| 1739 | if (!backend) { |
| 1740 | ALOGE("%s: Unsupported device %d", __func__, |
| 1741 | usecase->stream.out->devices); |
| 1742 | ret = -EINVAL; |
| 1743 | goto done; |
| 1744 | } |
| 1745 | strlcpy(avt_device_drift_mixer_ctl_name, |
| 1746 | backend, |
| 1747 | MIXER_PATH_MAX_LENGTH); |
| 1748 | |
| 1749 | count = strlen(backend); |
| 1750 | if (MIXER_PATH_MAX_LENGTH - count > 0) { |
| 1751 | strlcat(&avt_device_drift_mixer_ctl_name[count], |
| 1752 | " DRIFT", |
| 1753 | MIXER_PATH_MAX_LENGTH - count); |
| 1754 | } else { |
| 1755 | ret = -EINVAL; |
| 1756 | goto done; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1757 | } |
| 1758 | } else { |
Naresh Tanniru | 7586e29 | 2017-04-13 10:38:13 +0530 | [diff] [blame] | 1759 | ALOGE("%s: Invalid usecase",__func__); |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1760 | ret = -EINVAL; |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 1761 | goto done; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1762 | } |
| 1763 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 1764 | adev = usecase->stream.out->dev; |
Manish Dewangan | 3ccdea5 | 2017-02-13 19:31:54 +0530 | [diff] [blame] | 1765 | ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name); |
| 1766 | if (!ctl) { |
| 1767 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1768 | __func__, avt_device_drift_mixer_ctl_name); |
| 1769 | |
| 1770 | ret = -EINVAL; |
| 1771 | goto done; |
| 1772 | } |
| 1773 | |
| 1774 | ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__, |
| 1775 | avt_device_drift_mixer_ctl_name); |
| 1776 | |
| 1777 | mixer_ctl_update(ctl); |
| 1778 | count = mixer_ctl_get_num_values(ctl); |
| 1779 | if (count != sizeof(struct audio_avt_device_drift_stats)) { |
| 1780 | ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size", |
| 1781 | __func__); |
| 1782 | |
| 1783 | ret = -EINVAL; |
| 1784 | goto done; |
| 1785 | } |
| 1786 | |
| 1787 | ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count); |
| 1788 | if (ret != 0) { |
| 1789 | ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params", |
| 1790 | __func__); |
| 1791 | |
| 1792 | ret = -EINVAL; |
| 1793 | goto done; |
| 1794 | } |
| 1795 | memcpy(drift_param, &drift_stats.drift_param, |
| 1796 | sizeof(struct audio_avt_device_drift_param)); |
| 1797 | done: |
| 1798 | return ret; |
| 1799 | } |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 1800 | |
| 1801 | #ifdef SNDRV_COMPRESS_PATH_DELAY |
| 1802 | int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out) |
| 1803 | { |
| 1804 | int ret = -EINVAL; |
| 1805 | struct snd_compr_metadata metadata; |
| 1806 | int delay_ms = COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
| 1807 | |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 1808 | if (property_get_bool("vendor.audio.playback.dsp.pathdelay", false)) { |
Manish Dewangan | 07de214 | 2017-02-27 19:27:20 +0530 | [diff] [blame] | 1809 | ALOGD("%s:: Quering DSP delay %d",__func__, __LINE__); |
| 1810 | if (!(is_offload_usecase(out->usecase))) { |
| 1811 | ALOGE("%s:: not supported for non offload session", __func__); |
| 1812 | goto exit; |
| 1813 | } |
| 1814 | |
| 1815 | if (!out->compr) { |
| 1816 | ALOGD("%s:: Invalid compress handle,returning default dsp latency", |
| 1817 | __func__); |
| 1818 | goto exit; |
| 1819 | } |
| 1820 | |
| 1821 | metadata.key = SNDRV_COMPRESS_PATH_DELAY; |
| 1822 | ret = compress_get_metadata(out->compr, &metadata); |
| 1823 | if(ret) { |
| 1824 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 1825 | goto exit; |
| 1826 | } |
| 1827 | delay_ms = metadata.value[0] / 1000; /*convert to ms*/ |
| 1828 | } else { |
| 1829 | ALOGD("%s:: Using Fix DSP delay",__func__); |
| 1830 | } |
| 1831 | |
| 1832 | exit: |
| 1833 | ALOGD("%s:: delay in ms is %d",__func__, delay_ms); |
| 1834 | return delay_ms; |
| 1835 | } |
| 1836 | #else |
| 1837 | int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out __unused) |
| 1838 | { |
| 1839 | return COMPRESS_OFFLOAD_PLAYBACK_LATENCY; |
| 1840 | } |
| 1841 | #endif |
Manish Dewangan | 69426c8 | 2017-01-30 17:35:36 +0530 | [diff] [blame] | 1842 | |
| 1843 | #ifdef SNDRV_COMPRESS_RENDER_MODE |
| 1844 | int audio_extn_utils_compress_set_render_mode(struct stream_out *out) |
| 1845 | { |
| 1846 | struct snd_compr_metadata metadata; |
| 1847 | int ret = -EINVAL; |
| 1848 | |
| 1849 | if (!(is_offload_usecase(out->usecase))) { |
| 1850 | ALOGE("%s:: not supported for non offload session", __func__); |
| 1851 | goto exit; |
| 1852 | } |
| 1853 | |
| 1854 | if (!out->compr) { |
| 1855 | ALOGD("%s:: Invalid compress handle", |
| 1856 | __func__); |
| 1857 | goto exit; |
| 1858 | } |
| 1859 | |
| 1860 | ALOGD("%s:: render mode %d", __func__, out->render_mode); |
| 1861 | |
| 1862 | metadata.key = SNDRV_COMPRESS_RENDER_MODE; |
| 1863 | if (out->render_mode == RENDER_MODE_AUDIO_MASTER) { |
| 1864 | metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_AUDIO_MASTER; |
| 1865 | } else if (out->render_mode == RENDER_MODE_AUDIO_STC_MASTER) { |
| 1866 | metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_STC_MASTER; |
| 1867 | } else { |
| 1868 | ret = 0; |
| 1869 | goto exit; |
| 1870 | } |
| 1871 | ret = compress_set_metadata(out->compr, &metadata); |
| 1872 | if(ret) { |
| 1873 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 1874 | } |
| 1875 | exit: |
| 1876 | return ret; |
| 1877 | } |
| 1878 | #else |
| 1879 | int audio_extn_utils_compress_set_render_mode(struct stream_out *out __unused) |
| 1880 | { |
| 1881 | ALOGD("%s:: configuring render mode not supported", __func__); |
| 1882 | return 0; |
| 1883 | } |
| 1884 | #endif |
Manish Dewangan | 5822938 | 2017-02-02 15:48:41 +0530 | [diff] [blame] | 1885 | |
| 1886 | #ifdef SNDRV_COMPRESS_CLK_REC_MODE |
| 1887 | int audio_extn_utils_compress_set_clk_rec_mode( |
| 1888 | struct audio_usecase *usecase) |
| 1889 | { |
| 1890 | struct snd_compr_metadata metadata; |
| 1891 | struct stream_out *out = NULL; |
| 1892 | int ret = -EINVAL; |
| 1893 | |
Naresh Tanniru | 7586e29 | 2017-04-13 10:38:13 +0530 | [diff] [blame] | 1894 | if (usecase == NULL || usecase->type != PCM_PLAYBACK) { |
Manish Dewangan | 5822938 | 2017-02-02 15:48:41 +0530 | [diff] [blame] | 1895 | ALOGE("%s:: Invalid use case", __func__); |
| 1896 | goto exit; |
| 1897 | } |
| 1898 | |
| 1899 | out = usecase->stream.out; |
| 1900 | if (!out) { |
| 1901 | ALOGE("%s:: invalid stream", __func__); |
| 1902 | goto exit; |
| 1903 | } |
| 1904 | |
| 1905 | if (!is_offload_usecase(out->usecase)) { |
| 1906 | ALOGE("%s:: not supported for non offload session", __func__); |
| 1907 | goto exit; |
| 1908 | } |
| 1909 | |
| 1910 | if (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER) { |
| 1911 | ALOGD("%s:: clk recovery is only supported in STC render mode", |
| 1912 | __func__); |
| 1913 | ret = 0; |
| 1914 | goto exit; |
| 1915 | } |
| 1916 | |
| 1917 | if (!out->compr) { |
| 1918 | ALOGD("%s:: Invalid compress handle", |
| 1919 | __func__); |
| 1920 | goto exit; |
| 1921 | } |
| 1922 | metadata.key = SNDRV_COMPRESS_CLK_REC_MODE; |
| 1923 | switch(usecase->out_snd_device) { |
| 1924 | case SND_DEVICE_OUT_HDMI: |
| 1925 | case SND_DEVICE_OUT_SPEAKER_AND_HDMI: |
| 1926 | case SND_DEVICE_OUT_DISPLAY_PORT: |
| 1927 | case SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT: |
| 1928 | metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_NONE; |
| 1929 | break; |
| 1930 | default: |
| 1931 | metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_AUTO; |
| 1932 | break; |
| 1933 | } |
| 1934 | |
| 1935 | ALOGD("%s:: clk recovery mode %d",__func__, metadata.value[0]); |
| 1936 | |
| 1937 | ret = compress_set_metadata(out->compr, &metadata); |
| 1938 | if(ret) { |
| 1939 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 1940 | } |
| 1941 | |
| 1942 | exit: |
| 1943 | return ret; |
| 1944 | } |
| 1945 | #else |
| 1946 | int audio_extn_utils_compress_set_clk_rec_mode( |
| 1947 | struct audio_usecase *usecase __unused) |
| 1948 | { |
| 1949 | ALOGD("%s:: configuring render mode not supported", __func__); |
| 1950 | return 0; |
| 1951 | } |
| 1952 | #endif |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 1953 | |
| 1954 | #ifdef SNDRV_COMPRESS_RENDER_WINDOW |
| 1955 | int audio_extn_utils_compress_set_render_window( |
| 1956 | struct stream_out *out, |
| 1957 | struct audio_out_render_window_param *render_window) |
| 1958 | { |
| 1959 | struct snd_compr_metadata metadata; |
| 1960 | int ret = -EINVAL; |
| 1961 | |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 1962 | if(render_window == NULL) { |
| 1963 | ALOGE("%s:: Invalid render_window", __func__); |
| 1964 | goto exit; |
| 1965 | } |
| 1966 | |
Aniket Kumar Lata | 1e1d366 | 2017-06-01 18:45:48 -0700 | [diff] [blame] | 1967 | ALOGD("%s:: render window start 0x%"PRIx64" end 0x%"PRIx64"", |
| 1968 | __func__,render_window->render_ws, render_window->render_we); |
| 1969 | |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 1970 | if (!is_offload_usecase(out->usecase)) { |
| 1971 | ALOGE("%s:: not supported for non offload session", __func__); |
| 1972 | goto exit; |
| 1973 | } |
| 1974 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 1975 | if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) && |
| 1976 | (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) { |
Manish Dewangan | 2734604 | 2017-03-01 12:56:12 +0530 | [diff] [blame] | 1977 | ALOGD("%s:: only supported in timestamp mode, current " |
| 1978 | "render mode mode %d", __func__, out->render_mode); |
| 1979 | goto exit; |
| 1980 | } |
| 1981 | |
| 1982 | if (!out->compr) { |
| 1983 | ALOGW("%s:: offload session not yet opened," |
| 1984 | "render window will be configure later", __func__); |
| 1985 | /* store render window to reconfigure in start_output_stream() */ |
| 1986 | goto exit; |
| 1987 | } |
| 1988 | |
| 1989 | metadata.key = SNDRV_COMPRESS_RENDER_WINDOW; |
| 1990 | /*render window start value */ |
| 1991 | metadata.value[0] = 0xFFFFFFFF & render_window->render_ws; /* lsb */ |
| 1992 | metadata.value[1] = \ |
| 1993 | (0xFFFFFFFF00000000 & render_window->render_ws) >> 32; /* msb*/ |
| 1994 | /*render window end value */ |
| 1995 | metadata.value[2] = 0xFFFFFFFF & render_window->render_we; /* lsb */ |
| 1996 | metadata.value[3] = \ |
| 1997 | (0xFFFFFFFF00000000 & render_window->render_we) >> 32; /* msb*/ |
| 1998 | |
| 1999 | ret = compress_set_metadata(out->compr, &metadata); |
| 2000 | if(ret) { |
| 2001 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2002 | } |
| 2003 | |
| 2004 | exit: |
| 2005 | return ret; |
| 2006 | } |
| 2007 | #else |
| 2008 | int audio_extn_utils_compress_set_render_window( |
| 2009 | struct stream_out *out __unused, |
| 2010 | struct audio_out_render_window_param *render_window __unused) |
| 2011 | { |
| 2012 | ALOGD("%s:: configuring render window not supported", __func__); |
| 2013 | return 0; |
| 2014 | } |
| 2015 | #endif |
Manish Dewangan | 14956cc | 2017-02-14 18:54:42 +0530 | [diff] [blame] | 2016 | |
| 2017 | #ifdef SNDRV_COMPRESS_START_DELAY |
| 2018 | int audio_extn_utils_compress_set_start_delay( |
| 2019 | struct stream_out *out, |
| 2020 | struct audio_out_start_delay_param *delay_param) |
| 2021 | { |
| 2022 | struct snd_compr_metadata metadata; |
| 2023 | int ret = -EINVAL; |
| 2024 | |
| 2025 | if(delay_param == NULL) { |
| 2026 | ALOGE("%s:: Invalid delay_param", __func__); |
| 2027 | goto exit; |
| 2028 | } |
| 2029 | |
| 2030 | ALOGD("%s:: render start delay 0x%"PRIx64" ", __func__, |
| 2031 | delay_param->start_delay); |
| 2032 | |
| 2033 | if (!is_offload_usecase(out->usecase)) { |
| 2034 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2035 | goto exit; |
| 2036 | } |
| 2037 | |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2038 | if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) && |
| 2039 | (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) { |
Manish Dewangan | 14956cc | 2017-02-14 18:54:42 +0530 | [diff] [blame] | 2040 | ALOGD("%s:: only supported in timestamp mode, current " |
| 2041 | "render mode mode %d", __func__, out->render_mode); |
| 2042 | goto exit; |
| 2043 | } |
| 2044 | |
| 2045 | if (!out->compr) { |
| 2046 | ALOGW("%s:: offload session not yet opened," |
| 2047 | "start delay will be configure later", __func__); |
| 2048 | goto exit; |
| 2049 | } |
| 2050 | |
| 2051 | metadata.key = SNDRV_COMPRESS_START_DELAY; |
| 2052 | metadata.value[0] = 0xFFFFFFFF & delay_param->start_delay; /* lsb */ |
| 2053 | metadata.value[1] = \ |
| 2054 | (0xFFFFFFFF00000000 & delay_param->start_delay) >> 32; /* msb*/ |
| 2055 | |
| 2056 | ret = compress_set_metadata(out->compr, &metadata); |
| 2057 | if(ret) { |
| 2058 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2059 | } |
| 2060 | |
| 2061 | exit: |
| 2062 | return ret; |
| 2063 | } |
| 2064 | #else |
| 2065 | int audio_extn_utils_compress_set_start_delay( |
| 2066 | struct stream_out *out __unused, |
| 2067 | struct audio_out_start_delay_param *delay_param __unused) |
| 2068 | { |
| 2069 | ALOGD("%s:: configuring render window not supported", __func__); |
| 2070 | return 0; |
| 2071 | } |
| 2072 | #endif |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2073 | |
| 2074 | #define MAX_SND_CARD 8 |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2075 | #define RETRY_US 1000000 |
| 2076 | #define RETRY_NUMBER 40 |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2077 | |
| 2078 | int audio_extn_utils_get_snd_card_num() |
| 2079 | { |
| 2080 | |
| 2081 | void *hw_info = NULL; |
| 2082 | struct mixer *mixer = NULL; |
| 2083 | int retry_num = 0; |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2084 | int snd_card_num = 0, min_snd_card_num = 0; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2085 | char* snd_card_name = NULL; |
| 2086 | |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2087 | /* |
| 2088 | * Try with all the sound cards ( 0 to 8 ) and if none of them were detected |
| 2089 | * sleep for 1 sec and try detections with sound card 0 again. |
| 2090 | * If sound card gets detected, check if it is relevant, if not check with the |
| 2091 | * other sound cards. To ensure that the irrelevant sound card is not check again, |
| 2092 | * we maintain it in min_snd_card_num. |
| 2093 | */ |
| 2094 | while (retry_num < RETRY_NUMBER) { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2095 | |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2096 | while (snd_card_num <= MAX_SND_CARD) { |
| 2097 | mixer = mixer_open(snd_card_num); |
| 2098 | if (!mixer) |
| 2099 | snd_card_num++; |
| 2100 | else |
| 2101 | break; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | if (!mixer) { |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2105 | usleep(RETRY_US); |
| 2106 | snd_card_num = min_snd_card_num; |
| 2107 | retry_num++; |
| 2108 | continue; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | snd_card_name = strdup(mixer_get_name(mixer)); |
| 2112 | if (!snd_card_name) { |
| 2113 | ALOGE("failed to allocate memory for snd_card_name\n"); |
| 2114 | mixer_close(mixer); |
| 2115 | return -1; |
| 2116 | } |
| 2117 | ALOGD("%s: snd_card_name: %s", __func__, snd_card_name); |
| 2118 | |
| 2119 | hw_info = hw_info_init(snd_card_name); |
| 2120 | if (hw_info) { |
| 2121 | ALOGD("%s: Opened sound card:%d", __func__, snd_card_num); |
| 2122 | break; |
| 2123 | } |
| 2124 | ALOGE("%s: Failed to init hardware info", __func__); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2125 | min_snd_card_num++; |
| 2126 | snd_card_num = min_snd_card_num; |
| 2127 | |
| 2128 | if (snd_card_num >= MAX_SND_CARD) |
| 2129 | break; |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2130 | |
Dhananjay Kumar | a7e2783 | 2017-07-11 15:40:39 +0530 | [diff] [blame] | 2131 | free(snd_card_name); |
| 2132 | snd_card_name = NULL; |
| 2133 | |
| 2134 | mixer_close(mixer); |
| 2135 | mixer = NULL; |
| 2136 | } |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2137 | if (snd_card_name) |
| 2138 | free(snd_card_name); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2139 | |
Dhananjay Kumar | a7e2783 | 2017-07-11 15:40:39 +0530 | [diff] [blame] | 2140 | if (mixer) |
| 2141 | mixer_close(mixer); |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2142 | |
Dhananjay Kumar | a7e2783 | 2017-07-11 15:40:39 +0530 | [diff] [blame] | 2143 | if (hw_info) |
| 2144 | hw_info_deinit(hw_info); |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2145 | |
Ashish Jain | 30ae894 | 2017-11-05 17:21:23 +0530 | [diff] [blame] | 2146 | if ((snd_card_num >= MAX_SND_CARD) || (retry_num >= RETRY_NUMBER)) { |
Vignesh Kulothungan | 5539688 | 2017-04-20 14:37:02 -0700 | [diff] [blame] | 2147 | ALOGE("%s: Unable to find correct sound card, aborting.", __func__); |
| 2148 | return -1; |
| 2149 | } |
| 2150 | |
| 2151 | return snd_card_num; |
| 2152 | } |
Naresh Tanniru | 6160c71 | 2017-04-17 15:43:48 +0530 | [diff] [blame] | 2153 | |
| 2154 | #ifdef SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK |
| 2155 | int audio_extn_utils_compress_enable_drift_correction( |
| 2156 | struct stream_out *out, |
| 2157 | struct audio_out_enable_drift_correction *drift) |
| 2158 | { |
| 2159 | struct snd_compr_metadata metadata; |
| 2160 | int ret = -EINVAL; |
| 2161 | |
| 2162 | if(drift == NULL) { |
| 2163 | ALOGE("%s:: Invalid param", __func__); |
| 2164 | goto exit; |
| 2165 | } |
| 2166 | |
| 2167 | ALOGD("%s:: drift enable %d", __func__,drift->enable); |
| 2168 | |
| 2169 | if (!is_offload_usecase(out->usecase)) { |
| 2170 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2171 | goto exit; |
| 2172 | } |
| 2173 | |
| 2174 | if (!out->compr) { |
| 2175 | ALOGW("%s:: offload session not yet opened," |
| 2176 | "start delay will be configure later", __func__); |
| 2177 | goto exit; |
| 2178 | } |
| 2179 | |
| 2180 | metadata.key = SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK; |
| 2181 | metadata.value[0] = drift->enable; |
| 2182 | out->drift_correction_enabled = drift->enable; |
| 2183 | |
| 2184 | ret = compress_set_metadata(out->compr, &metadata); |
| 2185 | if(ret) { |
| 2186 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2187 | out->drift_correction_enabled = false; |
| 2188 | } |
| 2189 | |
| 2190 | exit: |
| 2191 | return ret; |
| 2192 | } |
| 2193 | #else |
| 2194 | int audio_extn_utils_compress_enable_drift_correction( |
| 2195 | struct stream_out *out __unused, |
| 2196 | struct audio_out_enable_drift_correction *drift __unused) |
| 2197 | { |
| 2198 | ALOGD("%s:: configuring drift enablement not supported", __func__); |
| 2199 | return 0; |
| 2200 | } |
| 2201 | #endif |
| 2202 | |
| 2203 | #ifdef SNDRV_COMPRESS_ADJUST_SESSION_CLOCK |
| 2204 | int audio_extn_utils_compress_correct_drift( |
| 2205 | struct stream_out *out, |
| 2206 | struct audio_out_correct_drift *drift_param) |
| 2207 | { |
| 2208 | struct snd_compr_metadata metadata; |
| 2209 | int ret = -EINVAL; |
| 2210 | |
| 2211 | if (drift_param == NULL) { |
| 2212 | ALOGE("%s:: Invalid drift_param", __func__); |
| 2213 | goto exit; |
| 2214 | } |
| 2215 | |
| 2216 | ALOGD("%s:: adjust time 0x%"PRIx64" ", __func__, |
| 2217 | drift_param->adjust_time); |
| 2218 | |
| 2219 | if (!is_offload_usecase(out->usecase)) { |
| 2220 | ALOGE("%s:: not supported for non offload session", __func__); |
| 2221 | goto exit; |
| 2222 | } |
| 2223 | |
| 2224 | if (!out->compr) { |
| 2225 | ALOGW("%s:: offload session not yet opened", __func__); |
| 2226 | goto exit; |
| 2227 | } |
| 2228 | |
| 2229 | if (!out->drift_correction_enabled) { |
| 2230 | ALOGE("%s:: drift correction not enabled", __func__); |
| 2231 | goto exit; |
| 2232 | } |
| 2233 | |
| 2234 | metadata.key = SNDRV_COMPRESS_ADJUST_SESSION_CLOCK; |
| 2235 | metadata.value[0] = 0xFFFFFFFF & drift_param->adjust_time; /* lsb */ |
| 2236 | metadata.value[1] = \ |
| 2237 | (0xFFFFFFFF00000000 & drift_param->adjust_time) >> 32; /* msb*/ |
| 2238 | |
| 2239 | ret = compress_set_metadata(out->compr, &metadata); |
| 2240 | if(ret) |
| 2241 | ALOGE("%s::error %s", __func__, compress_get_error(out->compr)); |
| 2242 | exit: |
| 2243 | return ret; |
| 2244 | } |
| 2245 | #else |
| 2246 | int audio_extn_utils_compress_correct_drift( |
| 2247 | struct stream_out *out __unused, |
| 2248 | struct audio_out_correct_drift *drift_param __unused) |
| 2249 | { |
| 2250 | ALOGD("%s:: setting adjust clock not supported", __func__); |
| 2251 | return 0; |
| 2252 | } |
| 2253 | #endif |
Naresh Tanniru | 29bce4e | 2017-04-27 17:54:30 +0530 | [diff] [blame] | 2254 | |
| 2255 | int audio_extn_utils_set_channel_map( |
| 2256 | struct stream_out *out, |
| 2257 | struct audio_out_channel_map_param *channel_map_param) |
| 2258 | { |
| 2259 | int ret = -EINVAL, i = 0; |
| 2260 | int channels = audio_channel_count_from_out_mask(out->channel_mask); |
| 2261 | |
| 2262 | if (channel_map_param == NULL) { |
| 2263 | ALOGE("%s:: Invalid channel_map", __func__); |
| 2264 | goto exit; |
| 2265 | } |
| 2266 | |
| 2267 | if (channel_map_param->channels != channels) { |
| 2268 | ALOGE("%s:: Channels(%d) does not match stream channels(%d)", |
| 2269 | __func__, channel_map_param->channels, channels); |
| 2270 | goto exit; |
| 2271 | } |
| 2272 | |
| 2273 | for ( i = 0; i < channels; i++) { |
| 2274 | ALOGV("%s:: channel_map[%d]- %d", __func__, i, channel_map_param->channel_map[i]); |
| 2275 | out->channel_map_param.channel_map[i] = channel_map_param->channel_map[i]; |
| 2276 | } |
| 2277 | ret = 0; |
| 2278 | exit: |
| 2279 | return ret; |
| 2280 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2281 | |
| 2282 | int audio_extn_utils_set_pan_scale_params( |
| 2283 | struct stream_out *out, |
| 2284 | struct mix_matrix_params *mm_params) |
| 2285 | { |
| 2286 | int ret = -EINVAL, i = 0, j = 0; |
| 2287 | |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 2288 | if (mm_params == NULL || out == NULL) { |
| 2289 | ALOGE("%s:: Invalid mix matrix or out param", __func__); |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2290 | goto exit; |
| 2291 | } |
| 2292 | |
| 2293 | if (mm_params->num_output_channels > MAX_CHANNELS_SUPPORTED || |
| 2294 | mm_params->num_output_channels <= 0 || |
| 2295 | mm_params->num_input_channels > MAX_CHANNELS_SUPPORTED || |
| 2296 | mm_params->num_input_channels <= 0) |
| 2297 | goto exit; |
| 2298 | |
| 2299 | out->pan_scale_params.num_output_channels = mm_params->num_output_channels; |
| 2300 | out->pan_scale_params.num_input_channels = mm_params->num_input_channels; |
| 2301 | out->pan_scale_params.has_output_channel_map = |
| 2302 | mm_params->has_output_channel_map; |
| 2303 | for (i = 0; i < mm_params->num_output_channels; i++) |
| 2304 | out->pan_scale_params.output_channel_map[i] = |
| 2305 | mm_params->output_channel_map[i]; |
| 2306 | |
| 2307 | out->pan_scale_params.has_input_channel_map = |
| 2308 | mm_params->has_input_channel_map; |
| 2309 | for (i = 0; i < mm_params->num_input_channels; i++) |
| 2310 | out->pan_scale_params.input_channel_map[i] = |
| 2311 | mm_params->input_channel_map[i]; |
| 2312 | |
| 2313 | out->pan_scale_params.has_mixer_coeffs = mm_params->has_mixer_coeffs; |
| 2314 | for (i = 0; i < mm_params->num_output_channels; i++) |
| 2315 | for (j = 0; j < mm_params->num_input_channels; j++) { |
| 2316 | //Convert the channel coefficient gains in Q14 format |
| 2317 | out->pan_scale_params.mixer_coeffs[i][j] = |
| 2318 | mm_params->mixer_coeffs[i][j] * (2 << 13); |
| 2319 | } |
| 2320 | |
| 2321 | ret = platform_set_stream_pan_scale_params(out->dev->platform, |
| 2322 | out->pcm_device_id, |
| 2323 | out->pan_scale_params); |
| 2324 | |
| 2325 | exit: |
| 2326 | return ret; |
| 2327 | } |
| 2328 | |
| 2329 | int audio_extn_utils_set_downmix_params( |
| 2330 | struct stream_out *out, |
| 2331 | struct mix_matrix_params *mm_params) |
| 2332 | { |
| 2333 | int ret = -EINVAL, i = 0, j = 0; |
| 2334 | struct audio_usecase *usecase = NULL; |
| 2335 | |
Aniket Kumar Lata | f9f246e | 2017-09-15 15:20:16 -0700 | [diff] [blame] | 2336 | if (mm_params == NULL || out == NULL) { |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 2337 | ALOGE("%s:: Invalid mix matrix or out param", __func__); |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2338 | goto exit; |
| 2339 | } |
| 2340 | |
| 2341 | if (mm_params->num_output_channels > MAX_CHANNELS_SUPPORTED || |
| 2342 | mm_params->num_output_channels <= 0 || |
| 2343 | mm_params->num_input_channels > MAX_CHANNELS_SUPPORTED || |
| 2344 | mm_params->num_input_channels <= 0) |
| 2345 | goto exit; |
| 2346 | |
| 2347 | usecase = get_usecase_from_list(out->dev, out->usecase); |
Varun Balaraj | 003ee75 | 2017-08-07 17:54:55 +0530 | [diff] [blame] | 2348 | if (!usecase) { |
| 2349 | ALOGE("%s: Get usecase list failed!", __func__); |
Aniket Kumar Lata | f9f246e | 2017-09-15 15:20:16 -0700 | [diff] [blame] | 2350 | goto exit; |
| 2351 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2352 | out->downmix_params.num_output_channels = mm_params->num_output_channels; |
| 2353 | out->downmix_params.num_input_channels = mm_params->num_input_channels; |
| 2354 | |
| 2355 | out->downmix_params.has_output_channel_map = |
| 2356 | mm_params->has_output_channel_map; |
| 2357 | for (i = 0; i < mm_params->num_output_channels; i++) { |
| 2358 | out->downmix_params.output_channel_map[i] = |
| 2359 | mm_params->output_channel_map[i]; |
| 2360 | } |
| 2361 | |
| 2362 | out->downmix_params.has_input_channel_map = |
| 2363 | mm_params->has_input_channel_map; |
| 2364 | for (i = 0; i < mm_params->num_input_channels; i++) |
| 2365 | out->downmix_params.input_channel_map[i] = |
| 2366 | mm_params->input_channel_map[i]; |
| 2367 | |
| 2368 | out->downmix_params.has_mixer_coeffs = mm_params->has_mixer_coeffs; |
| 2369 | for (i = 0; i < mm_params->num_output_channels; i++) |
Nikhil Latukar | 2e6f624 | 2017-08-15 13:37:07 +0530 | [diff] [blame] | 2370 | for (j = 0; j < mm_params->num_input_channels; j++) { |
| 2371 | //Convert the channel coefficient gains in Q14 format |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2372 | out->downmix_params.mixer_coeffs[i][j] = |
Nikhil Latukar | 2e6f624 | 2017-08-15 13:37:07 +0530 | [diff] [blame] | 2373 | mm_params->mixer_coeffs[i][j] * (2 << 13); |
| 2374 | } |
Varun Balaraj | e49253e | 2017-07-06 19:48:56 +0530 | [diff] [blame] | 2375 | |
| 2376 | ret = platform_set_stream_downmix_params(out->dev->platform, |
| 2377 | out->pcm_device_id, |
| 2378 | usecase->out_snd_device, |
| 2379 | out->downmix_params); |
| 2380 | |
| 2381 | exit: |
| 2382 | return ret; |
| 2383 | } |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 2384 | |
| 2385 | bool audio_extn_utils_is_dolby_format(audio_format_t format) |
| 2386 | { |
| 2387 | if (format == AUDIO_FORMAT_AC3 || |
| 2388 | format == AUDIO_FORMAT_E_AC3 || |
| 2389 | format == AUDIO_FORMAT_E_AC3_JOC) |
| 2390 | return true; |
| 2391 | else |
| 2392 | return false; |
| 2393 | } |
| 2394 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 2395 | int audio_extn_utils_get_bit_width_from_string(const char *id_string) |
| 2396 | { |
| 2397 | int i; |
| 2398 | const mixer_config_lookup mixer_bitwidth_config[] = {{"S24_3LE", 24}, |
| 2399 | {"S32_LE", 32}, |
| 2400 | {"S24_LE", 24}, |
| 2401 | {"S16_LE", 16}}; |
| 2402 | 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] | 2403 | |
`Deeraj Soman | 676c270 | 2017-09-18 19:25:53 +0530 | [diff] [blame] | 2404 | for (i = 0; i < num_configs; i++) { |
| 2405 | if (!strcmp(id_string, mixer_bitwidth_config[i].id_string)) |
| 2406 | return mixer_bitwidth_config[i].value; |
| 2407 | } |
| 2408 | |
| 2409 | return -EINVAL; |
| 2410 | } |
| 2411 | |
| 2412 | int audio_extn_utils_get_sample_rate_from_string(const char *id_string) |
| 2413 | { |
| 2414 | int i; |
| 2415 | const mixer_config_lookup mixer_samplerate_config[] = {{"KHZ_32", 32000}, |
| 2416 | {"KHZ_48", 48000}, |
| 2417 | {"KHZ_96", 96000}, |
| 2418 | {"KHZ_144", 144000}, |
| 2419 | {"KHZ_192", 192000}, |
| 2420 | {"KHZ_384", 384000}, |
| 2421 | {"KHZ_44P1", 44100}, |
| 2422 | {"KHZ_88P2", 88200}, |
| 2423 | {"KHZ_176P4", 176400}, |
| 2424 | {"KHZ_352P8", 352800}}; |
| 2425 | int num_configs = sizeof(mixer_samplerate_config) / sizeof(mixer_samplerate_config[0]); |
| 2426 | |
| 2427 | for (i = 0; i < num_configs; i++) { |
| 2428 | if (!strcmp(id_string, mixer_samplerate_config[i].id_string)) |
| 2429 | return mixer_samplerate_config[i].value; |
| 2430 | } |
| 2431 | |
| 2432 | return -EINVAL; |
| 2433 | } |
| 2434 | |
| 2435 | int audio_extn_utils_get_channels_from_string(const char *id_string) |
| 2436 | { |
| 2437 | int i; |
| 2438 | const mixer_config_lookup mixer_channels_config[] = {{"One", 1}, |
| 2439 | {"Two", 2}, |
| 2440 | {"Three",3}, |
| 2441 | {"Four", 4}, |
| 2442 | {"Five", 5}, |
| 2443 | {"Six", 6}, |
| 2444 | {"Seven", 7}, |
| 2445 | {"Eight", 8}}; |
| 2446 | int num_configs = sizeof(mixer_channels_config) / sizeof(mixer_channels_config[0]); |
| 2447 | |
| 2448 | for (i = 0; i < num_configs; i++) { |
| 2449 | if (!strcmp(id_string, mixer_channels_config[i].id_string)) |
| 2450 | return mixer_channels_config[i].value; |
| 2451 | } |
| 2452 | |
| 2453 | return -EINVAL; |
| 2454 | } |