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 | |
| 23 | #include <errno.h> |
| 24 | #include <cutils/properties.h> |
| 25 | #include <cutils/config_utils.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <dlfcn.h> |
| 28 | #include <cutils/str_parms.h> |
| 29 | #include <cutils/log.h> |
| 30 | #include <cutils/misc.h> |
| 31 | |
| 32 | #include "audio_hw.h" |
| 33 | #include "platform.h" |
| 34 | #include "platform_api.h" |
| 35 | #include "audio_extn.h" |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 36 | #include "voice.h" |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 37 | #include "sound/compress_params.h" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 38 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 39 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 40 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 41 | #include "audio_parsers.h" |
| 42 | #endif |
| 43 | #endif |
| 44 | |
Yamit Mehta | a0d653a | 2016-11-25 20:33:25 +0530 | [diff] [blame] | 45 | #ifdef LINUX_ENABLED |
| 46 | #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/etc/audio_output_policy.conf" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 47 | #define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/etc/audio_io_policy.conf" |
Yamit Mehta | a0d653a | 2016-11-25 20:33:25 +0530 | [diff] [blame] | 48 | #else |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 49 | #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] | 50 | #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] | 51 | #endif |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 52 | |
| 53 | #define OUTPUTS_TAG "outputs" |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 54 | #define INPUTS_TAG "inputs" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 55 | |
| 56 | #define DYNAMIC_VALUE_TAG "dynamic" |
| 57 | #define FLAGS_TAG "flags" |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 58 | #define PROFILES_TAG "profile" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 59 | #define FORMATS_TAG "formats" |
| 60 | #define SAMPLING_RATES_TAG "sampling_rates" |
| 61 | #define BIT_WIDTH_TAG "bit_width" |
| 62 | #define APP_TYPE_TAG "app_type" |
| 63 | |
| 64 | #define STRING_TO_ENUM(string) { #string, string } |
| 65 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 66 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 67 | #define BASE_TABLE_SIZE 64 |
| 68 | #define MAX_BASEINDEX_LEN 256 |
| 69 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 70 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 71 | #define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */ |
| 72 | #define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */ |
| 73 | #define SR_44100 (0<<0) /* 44.1kHz */ |
| 74 | #define SR_NOTID (1<<0) /* non indicated */ |
| 75 | #define SR_48000 (2<<0) /* 48kHz */ |
| 76 | #define SR_32000 (3<<0) /* 32kHz */ |
| 77 | #define SR_22050 (4<<0) /* 22.05kHz */ |
| 78 | #define SR_24000 (6<<0) /* 24kHz */ |
| 79 | #define SR_88200 (8<<0) /* 88.2kHz */ |
| 80 | #define SR_96000 (10<<0) /* 96kHz */ |
| 81 | #define SR_176400 (12<<0) /* 176.4kHz */ |
| 82 | #define SR_192000 (14<<0) /* 192kHz */ |
| 83 | |
| 84 | #endif |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 85 | struct string_to_enum { |
| 86 | const char *name; |
| 87 | uint32_t value; |
| 88 | }; |
| 89 | |
| 90 | const struct string_to_enum s_flag_name_to_enum_table[] = { |
| 91 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT), |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 92 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 93 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY), |
| 94 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST), |
| 95 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER), |
| 96 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD), |
| 97 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 98 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 99 | #ifdef INCALL_MUSIC_ENABLED |
| 100 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC), |
| 101 | #endif |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 102 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH), |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 103 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE), |
| 104 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST), |
| 105 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD), |
| 106 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW), |
| 107 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC), |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 108 | STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | const struct string_to_enum s_format_name_to_enum_table[] = { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 112 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 113 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT), |
Ashish Jain | 5106d36 | 2016-05-11 19:23:33 +0530 | [diff] [blame] | 114 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED), |
| 115 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT), |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 116 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 117 | STRING_TO_ENUM(AUDIO_FORMAT_MP3), |
| 118 | STRING_TO_ENUM(AUDIO_FORMAT_AAC), |
| 119 | STRING_TO_ENUM(AUDIO_FORMAT_VORBIS), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 120 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB), |
| 121 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 122 | STRING_TO_ENUM(AUDIO_FORMAT_AC3), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 123 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 124 | STRING_TO_ENUM(AUDIO_FORMAT_DTS), |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 125 | STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD), |
| 126 | #ifdef AUDIO_EXTN_FORMATS_ENABLED |
| 127 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 128 | STRING_TO_ENUM(AUDIO_FORMAT_WMA), |
| 129 | STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO), |
| 130 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 131 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS), |
| 132 | STRING_TO_ENUM(AUDIO_FORMAT_EVRC), |
| 133 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCB), |
| 134 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB), |
| 135 | STRING_TO_ENUM(AUDIO_FORMAT_QCELP), |
| 136 | STRING_TO_ENUM(AUDIO_FORMAT_MP2), |
| 137 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW), |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 138 | STRING_TO_ENUM(AUDIO_FORMAT_FLAC), |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 139 | STRING_TO_ENUM(AUDIO_FORMAT_ALAC), |
| 140 | STRING_TO_ENUM(AUDIO_FORMAT_APE), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 141 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Alexy Joseph | cd8eaed | 2014-12-11 12:46:53 -0800 | [diff] [blame] | 142 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC), |
| 143 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1), |
| 144 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2), |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 145 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS), |
Ashish Jain | e513a87 | 2015-11-19 17:00:56 +0530 | [diff] [blame] | 146 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC), |
| 147 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1), |
| 148 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2), |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 149 | STRING_TO_ENUM(AUDIO_FORMAT_DSD), |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 150 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM), |
| 151 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC), |
| 152 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1), |
| 153 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2), |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 154 | STRING_TO_ENUM(AUDIO_FORMAT_APTX), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 155 | #endif |
| 156 | }; |
| 157 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 158 | static char bTable[BASE_TABLE_SIZE] = { |
| 159 | 'A','B','C','D','E','F','G','H','I','J','K','L', |
| 160 | 'M','N','O','P','Q','R','S','T','U','V','W','X', |
| 161 | 'Y','Z','a','b','c','d','e','f','g','h','i','j', |
| 162 | 'k','l','m','n','o','p','q','r','s','t','u','v', |
| 163 | 'w','x','y','z','0','1','2','3','4','5','6','7', |
| 164 | '8','9','+','/' |
| 165 | }; |
| 166 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 167 | static uint32_t string_to_enum(const struct string_to_enum *table, size_t size, |
| 168 | const char *name) |
| 169 | { |
| 170 | size_t i; |
| 171 | for (i = 0; i < size; i++) { |
| 172 | if (strcmp(table[i].name, name) == 0) { |
| 173 | ALOGV("%s found %s", __func__, table[i].name); |
| 174 | return table[i].value; |
| 175 | } |
| 176 | } |
| 177 | return 0; |
| 178 | } |
| 179 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 180 | static audio_io_flags_t parse_flag_names(char *name) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 181 | { |
| 182 | uint32_t flag = 0; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 183 | audio_io_flags_t io_flags; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 184 | char *last_r; |
| 185 | char *flag_name = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 186 | while (flag_name != NULL) { |
| 187 | if (strlen(flag_name) != 0) { |
| 188 | flag |= string_to_enum(s_flag_name_to_enum_table, |
| 189 | ARRAY_SIZE(s_flag_name_to_enum_table), |
| 190 | flag_name); |
| 191 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 192 | flag_name = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | ALOGV("parse_flag_names: flag - %d", flag); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 196 | io_flags.in_flags = (audio_input_flags_t)flag; |
| 197 | io_flags.out_flags = (audio_output_flags_t)flag; |
| 198 | return io_flags; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 201 | 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] | 202 | { |
| 203 | struct stream_format *sf_info = NULL; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 204 | char *last_r; |
| 205 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 206 | |
| 207 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) |
| 208 | return; |
| 209 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 210 | list_init(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 211 | while (str != NULL) { |
| 212 | audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table, |
| 213 | ARRAY_SIZE(s_format_name_to_enum_table), str); |
| 214 | ALOGV("%s: format - %d", __func__, format); |
| 215 | if (format != 0) { |
| 216 | sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 217 | if (sf_info == NULL) |
| 218 | break; /* return whatever was parsed */ |
| 219 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 220 | sf_info->format = format; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 221 | list_add_tail(&s_info->format_list, &sf_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 222 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 223 | str = strtok_r(NULL, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 227 | 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] | 228 | { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 229 | struct stream_sample_rate *ss_info = NULL; |
| 230 | uint32_t sample_rate = 48000; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 231 | char *last_r; |
| 232 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 233 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 234 | if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG)) |
| 235 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 236 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 237 | list_init(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 238 | while (str != NULL) { |
| 239 | sample_rate = (uint32_t)strtol(str, (char **)NULL, 10); |
| 240 | ALOGV("%s: sample_rate - %d", __func__, sample_rate); |
| 241 | if (0 != sample_rate) { |
| 242 | 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] | 243 | if (!ss_info) { |
| 244 | ALOGE("%s: memory allocation failure", __func__); |
| 245 | return; |
| 246 | } |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 247 | ss_info->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 248 | list_add_tail(&s_info->sample_rate_list, &ss_info->list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 249 | } |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 250 | str = strtok_r(NULL, "|", &last_r); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 251 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static int parse_bit_width_names(char *name) |
| 255 | { |
| 256 | int bit_width = 16; |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 257 | char *last_r; |
| 258 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 259 | |
| 260 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 261 | bit_width = (int)strtol(str, (char **)NULL, 10); |
| 262 | |
| 263 | ALOGV("%s: bit_width - %d", __func__, bit_width); |
| 264 | return bit_width; |
| 265 | } |
| 266 | |
| 267 | static int parse_app_type_names(void *platform, char *name) |
| 268 | { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 269 | int app_type = platform_get_default_app_type(platform); |
Apoorv Raghuvanshi | 8880cac | 2015-02-06 15:33:49 -0800 | [diff] [blame] | 270 | char *last_r; |
| 271 | char *str = strtok_r(name, "|", &last_r); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 272 | |
| 273 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 274 | app_type = (int)strtol(str, (char **)NULL, 10); |
| 275 | |
| 276 | ALOGV("%s: app_type - %d", __func__, app_type); |
| 277 | return app_type; |
| 278 | } |
| 279 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 280 | static void update_streams_cfg_list(cnode *root, void *platform, |
| 281 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 282 | { |
| 283 | cnode *node = root->first_child; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 284 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 285 | |
| 286 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 287 | 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] | 288 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 289 | if (!s_info) { |
| 290 | ALOGE("failed to allocate mem for s_info list element"); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 294 | while (node) { |
| 295 | if (strcmp(node->name, FLAGS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 296 | s_info->flags = parse_flag_names((char *)node->value); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 297 | } else if (strcmp(node->name, PROFILES_TAG) == 0) { |
| 298 | 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] | 299 | } else if (strcmp(node->name, FORMATS_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 300 | parse_format_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 301 | } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 302 | s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 303 | parse_sample_rate_names((char *)node->value, s_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 304 | } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 305 | 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] | 306 | } else if (strcmp(node->name, APP_TYPE_TAG) == 0) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 307 | 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] | 308 | } |
| 309 | node = node->next; |
| 310 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 311 | list_add_tail(streams_cfg_list, &s_info->list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 314 | static void load_cfg_list(cnode *root, void *platform, |
| 315 | struct listnode *streams_output_cfg_list, |
| 316 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 317 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 318 | cnode *node = NULL; |
| 319 | |
| 320 | node = config_find(root, OUTPUTS_TAG); |
| 321 | if (node != NULL) { |
| 322 | node = node->first_child; |
| 323 | while (node) { |
| 324 | ALOGV("%s: loading output %s", __func__, node->name); |
| 325 | update_streams_cfg_list(node, platform, streams_output_cfg_list); |
| 326 | node = node->next; |
| 327 | } |
| 328 | } else { |
| 329 | ALOGI("%s: could not load output, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 332 | node = config_find(root, INPUTS_TAG); |
| 333 | if (node != NULL) { |
| 334 | node = node->first_child; |
| 335 | while (node) { |
| 336 | ALOGV("%s: loading input %s", __func__, node->name); |
| 337 | update_streams_cfg_list(node, platform, streams_input_cfg_list); |
| 338 | node = node->next; |
| 339 | } |
| 340 | } else { |
| 341 | ALOGI("%s: could not load input, node is NULL", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | static void send_app_type_cfg(void *platform, struct mixer *mixer, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 346 | struct listnode *streams_output_cfg_list, |
| 347 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 348 | { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 349 | 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] | 350 | int length = 0, i, num_app_types = 0; |
| 351 | struct listnode *node; |
| 352 | bool update; |
| 353 | struct mixer_ctl *ctl = NULL; |
| 354 | const char *mixer_ctl_name = "App Type Config"; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 355 | struct streams_io_cfg *s_info = NULL; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 356 | |
| 357 | if (!mixer) { |
| 358 | ALOGE("%s: mixer is null",__func__); |
| 359 | return; |
| 360 | } |
| 361 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 362 | if (!ctl) { |
| 363 | ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); |
| 364 | return; |
| 365 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 366 | app_type_cfg[length++] = num_app_types; |
| 367 | |
| 368 | if (list_empty(streams_output_cfg_list)) { |
| 369 | 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] | 370 | app_type_cfg[length++] = 48000; |
| 371 | app_type_cfg[length++] = 16; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 372 | num_app_types += 1; |
| 373 | } |
| 374 | if (list_empty(streams_input_cfg_list)) { |
| 375 | app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 376 | app_type_cfg[length++] = 48000; |
| 377 | app_type_cfg[length++] = 16; |
| 378 | num_app_types += 1; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 381 | list_for_each(node, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 382 | 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] | 383 | update = true; |
| 384 | for (i=0; i<length; i=i+3) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 385 | if (app_type_cfg[i+1] == 0) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 386 | break; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 387 | 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] | 388 | 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] | 389 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 390 | 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] | 391 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 392 | update = false; |
| 393 | break; |
| 394 | } |
| 395 | } |
| 396 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 397 | num_app_types += 1; |
| 398 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 399 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
| 400 | app_type_cfg[length++] = s_info->app_type_cfg.bit_width; |
| 401 | } |
| 402 | } |
| 403 | list_for_each(node, streams_input_cfg_list) { |
| 404 | s_info = node_to_item(node, struct streams_io_cfg, list); |
| 405 | update = true; |
| 406 | for (i=0; i<length; i=i+3) { |
| 407 | if (app_type_cfg[i+1] == 0) |
| 408 | break; |
| 409 | 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] | 410 | 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] | 411 | app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate; |
Dhananjay Kumar | 9cc498b | 2016-12-20 21:04:13 +0530 | [diff] [blame] | 412 | 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] | 413 | app_type_cfg[i+3] = s_info->app_type_cfg.bit_width; |
| 414 | update = false; |
| 415 | break; |
| 416 | } |
| 417 | } |
| 418 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
| 419 | num_app_types += 1; |
| 420 | app_type_cfg[length++] = s_info->app_type_cfg.app_type; |
| 421 | app_type_cfg[length++] = s_info->app_type_cfg.sample_rate; |
| 422 | 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] | 423 | } |
| 424 | } |
| 425 | ALOGV("%s: num_app_types: %d", __func__, num_app_types); |
| 426 | if (num_app_types) { |
| 427 | app_type_cfg[0] = num_app_types; |
| 428 | mixer_ctl_set_array(ctl, app_type_cfg, length); |
| 429 | } |
| 430 | } |
| 431 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 432 | void audio_extn_utils_update_streams_cfg_lists(void *platform, |
| 433 | struct mixer *mixer, |
| 434 | struct listnode *streams_output_cfg_list, |
| 435 | struct listnode *streams_input_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 436 | { |
| 437 | cnode *root; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 438 | char *data = NULL; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 439 | |
| 440 | ALOGV("%s", __func__); |
| 441 | list_init(streams_output_cfg_list); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 442 | list_init(streams_input_cfg_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 443 | |
| 444 | root = config_node("", ""); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 445 | if (root == NULL) { |
| 446 | ALOGE("cfg_list, NULL config root"); |
| 447 | return; |
| 448 | } |
| 449 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 450 | data = (char *)load_file(AUDIO_IO_POLICY_VENDOR_CONFIG_FILE, NULL); |
| 451 | if (data == NULL) { |
| 452 | ALOGD("%s: failed to open io config file(%s), trying older config file", |
| 453 | __func__, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE); |
| 454 | data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL); |
| 455 | if (data == NULL) { |
| 456 | send_app_type_cfg(platform, mixer, |
| 457 | streams_output_cfg_list, |
| 458 | streams_input_cfg_list); |
| 459 | ALOGE("%s: could not load io policy config!", __func__); |
| 460 | return; |
| 461 | } |
| 462 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 463 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 464 | config_load(root, data); |
| 465 | load_cfg_list(root, platform, streams_output_cfg_list, |
| 466 | streams_input_cfg_list); |
| 467 | |
| 468 | send_app_type_cfg(platform, mixer, streams_output_cfg_list, |
| 469 | streams_input_cfg_list); |
Alexy Joseph | aee4fdd | 2016-01-29 13:02:07 -0800 | [diff] [blame] | 470 | |
| 471 | config_free(root); |
| 472 | free(data); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 475 | static void audio_extn_utils_dump_streams_cfg_list( |
| 476 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 477 | { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 478 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 479 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 480 | struct stream_format *sf_info; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 481 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 482 | |
| 483 | list_for_each(node_i, streams_cfg_list) { |
| 484 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 485 | ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d", |
| 486 | __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate, |
| 487 | s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type); |
| 488 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 489 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 490 | ALOGV("format-%x", sf_info->format); |
| 491 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 492 | list_for_each(node_j, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 493 | ss_info = node_to_item(node_j, struct stream_sample_rate, list); |
| 494 | ALOGV("sample rate-%d", ss_info->sample_rate); |
| 495 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 499 | void audio_extn_utils_dump_streams_cfg_lists( |
| 500 | struct listnode *streams_output_cfg_list, |
| 501 | struct listnode *streams_input_cfg_list) |
| 502 | { |
| 503 | ALOGV("%s", __func__); |
| 504 | audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list); |
| 505 | audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list); |
| 506 | } |
| 507 | |
| 508 | static void audio_extn_utils_release_streams_cfg_list( |
| 509 | struct listnode *streams_cfg_list) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 510 | { |
| 511 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 512 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 513 | |
| 514 | ALOGV("%s", __func__); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 515 | |
| 516 | while (!list_empty(streams_cfg_list)) { |
| 517 | node_i = list_head(streams_cfg_list); |
| 518 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 519 | while (!list_empty(&s_info->format_list)) { |
| 520 | node_j = list_head(&s_info->format_list); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 521 | list_remove(node_j); |
| 522 | free(node_to_item(node_j, struct stream_format, list)); |
| 523 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 524 | while (!list_empty(&s_info->sample_rate_list)) { |
| 525 | node_j = list_head(&s_info->sample_rate_list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 526 | list_remove(node_j); |
| 527 | free(node_to_item(node_j, struct stream_sample_rate, list)); |
| 528 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 529 | list_remove(node_i); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 530 | 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] | 531 | } |
| 532 | } |
| 533 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 534 | void audio_extn_utils_release_streams_cfg_lists( |
| 535 | struct listnode *streams_output_cfg_list, |
| 536 | struct listnode *streams_input_cfg_list) |
| 537 | { |
| 538 | ALOGV("%s", __func__); |
| 539 | audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list); |
| 540 | audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list); |
| 541 | } |
| 542 | |
| 543 | static bool set_app_type_cfg(struct streams_io_cfg *s_info, |
| 544 | struct stream_app_type_cfg *app_type_cfg, |
| 545 | uint32_t sample_rate, uint32_t bit_width) |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 546 | { |
| 547 | struct listnode *node_i; |
| 548 | struct stream_sample_rate *ss_info; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 549 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 550 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 551 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 552 | (bit_width == s_info->app_type_cfg.bit_width)) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 553 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 554 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 555 | app_type_cfg->sample_rate = ss_info->sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 556 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 557 | ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d", |
| 558 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 559 | return true; |
| 560 | } |
| 561 | } |
| 562 | /* |
| 563 | * Reiterate through the list assuming dafault sample rate. |
| 564 | * Handles scenario where input sample rate is higher |
| 565 | * than all sample rates in list for the input bit width. |
| 566 | */ |
| 567 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 568 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 569 | list_for_each(node_i, &s_info->sample_rate_list) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 570 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 571 | if ((sample_rate <= ss_info->sample_rate) && |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 572 | (bit_width == s_info->app_type_cfg.bit_width)) { |
| 573 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 574 | app_type_cfg->sample_rate = sample_rate; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 575 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 576 | 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] | 577 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 578 | return true; |
| 579 | } |
| 580 | } |
| 581 | return false; |
| 582 | } |
| 583 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 584 | void audio_extn_utils_update_stream_input_app_type_cfg(void *platform, |
| 585 | struct listnode *streams_input_cfg_list, |
| 586 | audio_devices_t devices __unused, |
| 587 | audio_input_flags_t flags, |
| 588 | audio_format_t format, |
| 589 | uint32_t sample_rate, |
| 590 | uint32_t bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 591 | char* profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 592 | struct stream_app_type_cfg *app_type_cfg) |
| 593 | { |
| 594 | struct listnode *node_i, *node_j; |
| 595 | struct streams_io_cfg *s_info; |
| 596 | struct stream_format *sf_info; |
| 597 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 598 | ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s", |
| 599 | __func__, flags, format, sample_rate, profile); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 600 | |
| 601 | list_for_each(node_i, streams_input_cfg_list) { |
| 602 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 603 | /* Along with flags do profile matching if set at either end.*/ |
| 604 | if (s_info->flags.in_flags == flags && |
| 605 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 606 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 607 | list_for_each(node_j, &s_info->format_list) { |
| 608 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 609 | if (sf_info->format == format) { |
| 610 | if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width)) |
| 611 | return; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | ALOGW("%s: App type could not be selected. Falling back to default", __func__); |
| 617 | app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE); |
| 618 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 619 | app_type_cfg->bit_width = 16; |
| 620 | } |
| 621 | |
| 622 | 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] | 623 | struct listnode *streams_output_cfg_list, |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 624 | audio_devices_t devices, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 625 | audio_output_flags_t flags, |
| 626 | audio_format_t format, |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 627 | uint32_t sample_rate, |
| 628 | uint32_t bit_width, |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 629 | audio_channel_mask_t channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 630 | char *profile, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 631 | struct stream_app_type_cfg *app_type_cfg) |
| 632 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 633 | struct listnode *node_i, *node_j; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 634 | struct streams_io_cfg *s_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 635 | struct stream_format *sf_info; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 636 | char value[PROPERTY_VALUE_MAX] = {0}; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 637 | |
Ashish Jain | 058165c | 2016-09-28 23:18:48 +0530 | [diff] [blame] | 638 | if ((bit_width >= 24) && |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 639 | (devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 640 | int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER); |
| 641 | if (-ENOSYS != bw) |
| 642 | bit_width = (uint32_t)bw; |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 643 | sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 644 | ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__); |
| 645 | } |
| 646 | |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 647 | property_get("audio.playback.mch.downsample",value,""); |
| 648 | if (!strncmp("true", value, sizeof("true"))) { |
| 649 | if ((popcount(channel_mask) > 2) && |
| 650 | (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
| 651 | !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) { |
| 652 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 653 | ALOGD("%s: MCH session defaulting sample rate to %d", |
| 654 | __func__, sample_rate); |
| 655 | } |
| 656 | } |
Preetam Singh Ranawat | cb6212e | 2016-07-19 18:33:53 +0530 | [diff] [blame] | 657 | |
| 658 | /* Set sampling rate to 176.4 for DSD64 |
| 659 | * and 352.8Khz for DSD128. |
| 660 | * Set Bit Width to 16. output will be 16 bit |
| 661 | * post DoP in ASM. |
| 662 | */ |
| 663 | if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) && |
| 664 | (format == AUDIO_FORMAT_DSD)) { |
| 665 | bit_width = 16; |
| 666 | if (sample_rate == INPUT_SAMPLING_RATE_DSD64) |
| 667 | sample_rate = OUTPUT_SAMPLING_RATE_DSD64; |
| 668 | else if (sample_rate == INPUT_SAMPLING_RATE_DSD128) |
| 669 | sample_rate = OUTPUT_SAMPLING_RATE_DSD128; |
| 670 | } |
| 671 | |
Naresh Tanniru | f5ba8d0 | 2016-09-29 18:06:37 +0530 | [diff] [blame] | 672 | if(devices & AUDIO_DEVICE_OUT_ALL_A2DP) { |
| 673 | //TODO: Handle fractional sampling rate configuration for LL |
| 674 | audio_extn_a2dp_get_apptype_params(&sample_rate, &bit_width); |
| 675 | ALOGI("%s using %d sampling rate %d bit width for A2DP CoPP", |
| 676 | __func__, sample_rate, bit_width); |
| 677 | } |
| 678 | |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 679 | ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s", |
| 680 | __func__, flags, format, sample_rate, profile); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 681 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 682 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 683 | /* Along with flags do profile matching if set at either end.*/ |
| 684 | if (s_info->flags.out_flags == flags && |
| 685 | ((profile[0] == '\0' && s_info->profile[0] == '\0') || |
| 686 | strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 687 | list_for_each(node_j, &s_info->format_list) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 688 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 689 | if (sf_info->format == format) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 690 | 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] | 691 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | list_for_each(node_i, streams_output_cfg_list) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 697 | s_info = node_to_item(node_i, struct streams_io_cfg, list); |
| 698 | if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) { |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 699 | ALOGV("Compatible output profile not found."); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 700 | app_type_cfg->app_type = s_info->app_type_cfg.app_type; |
| 701 | app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate; |
| 702 | app_type_cfg->bit_width = s_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 703 | ALOGV("%s Default to primary output: App type: %d sample_rate %d", |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 704 | __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] | 705 | return; |
| 706 | } |
| 707 | } |
| 708 | 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] | 709 | app_type_cfg->app_type = platform_get_default_app_type(platform); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 710 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 711 | app_type_cfg->bit_width = 16; |
| 712 | } |
| 713 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 714 | static bool audio_is_this_native_usecase(struct audio_usecase *uc) |
| 715 | { |
| 716 | bool native_usecase = false; |
| 717 | struct stream_out *out = (struct stream_out*) uc->stream.out; |
| 718 | |
| 719 | if (PCM_PLAYBACK == uc->type && out != NULL && |
| 720 | NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() && |
| 721 | is_offload_usecase(uc->id) && |
| 722 | (out->sample_rate == OUTPUT_SAMPLING_RATE_44100)) |
| 723 | native_usecase = true; |
| 724 | |
| 725 | return native_usecase; |
| 726 | } |
| 727 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 728 | void audio_extn_utils_update_stream_app_type_cfg_for_usecase( |
| 729 | struct audio_device *adev, |
| 730 | struct audio_usecase *usecase) |
| 731 | { |
| 732 | ALOGV("%s", __func__); |
| 733 | |
| 734 | switch(usecase->type) { |
| 735 | case PCM_PLAYBACK: |
| 736 | audio_extn_utils_update_stream_output_app_type_cfg(adev->platform, |
| 737 | &adev->streams_output_cfg_list, |
| 738 | usecase->stream.out->devices, |
| 739 | usecase->stream.out->flags, |
| 740 | usecase->stream.out->format, |
| 741 | usecase->stream.out->sample_rate, |
| 742 | usecase->stream.out->bit_width, |
| 743 | usecase->stream.out->channel_mask, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 744 | usecase->stream.out->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 745 | &usecase->stream.out->app_type_cfg); |
| 746 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type); |
| 747 | break; |
| 748 | case PCM_CAPTURE: |
| 749 | audio_extn_utils_update_stream_input_app_type_cfg(adev->platform, |
| 750 | &adev->streams_input_cfg_list, |
| 751 | usecase->stream.in->device, |
| 752 | usecase->stream.in->flags, |
| 753 | usecase->stream.in->format, |
| 754 | usecase->stream.in->sample_rate, |
| 755 | usecase->stream.in->bit_width, |
Dhananjay Kumar | 4d91c1a | 2016-12-01 23:27:29 +0530 | [diff] [blame] | 756 | usecase->stream.in->profile, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 757 | &usecase->stream.in->app_type_cfg); |
| 758 | ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type); |
| 759 | break; |
| 760 | default: |
| 761 | ALOGE("%s: app type cfg not supported for usecase type (%d)", |
| 762 | __func__, usecase->type); |
| 763 | } |
| 764 | } |
| 765 | |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 766 | int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, |
| 767 | struct audio_usecase *usecase) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 768 | { |
| 769 | char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 770 | size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0}; |
| 771 | int len = 0, rc; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 772 | struct mixer_ctl *ctl; |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 773 | int pcm_device_id, acdb_dev_id = 0, snd_device = usecase->out_snd_device; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 774 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 775 | char value[PROPERTY_VALUE_MAX] = {0}; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 776 | |
| 777 | ALOGV("%s", __func__); |
| 778 | |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 779 | if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 780 | 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] | 781 | rc = 0; |
| 782 | goto exit_send_app_type_cfg; |
| 783 | } |
| 784 | if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) && |
| 785 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) && |
| 786 | (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) && |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 787 | (!is_offload_usecase(usecase->id)) && |
| 788 | (usecase->type != PCM_CAPTURE)) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 789 | 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] | 790 | rc = 0; |
| 791 | goto exit_send_app_type_cfg; |
| 792 | } |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 793 | if (usecase->type == PCM_PLAYBACK) { |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 794 | snd_device = usecase->out_snd_device; |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 795 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 796 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 797 | "Audio Stream %d App Type Cfg", pcm_device_id); |
| 798 | acdb_dev_id = platform_get_snd_device_acdb_id(usecase->out_snd_device); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 799 | } else if (usecase->type == PCM_CAPTURE) { |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 800 | snd_device = usecase->in_snd_device; |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 801 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 802 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 803 | "Audio Stream Capture %d App Type Cfg", pcm_device_id); |
| 804 | acdb_dev_id = platform_get_snd_device_acdb_id(usecase->in_snd_device); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 805 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 806 | if (acdb_dev_id <= 0) { |
| 807 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 808 | rc = -EINVAL; |
| 809 | goto exit_send_app_type_cfg; |
| 810 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 811 | |
| 812 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 813 | if (!ctl) { |
| 814 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, |
| 815 | mixer_ctl_name); |
| 816 | rc = -EINVAL; |
| 817 | goto exit_send_app_type_cfg; |
| 818 | } |
| 819 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
Xiaojun Sang | 040cc9f | 2015-08-03 19:38:28 +0800 | [diff] [blame] | 820 | platform_get_spkr_prot_snd_device(snd_device) : snd_device; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 821 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 822 | if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) { |
| 823 | if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 824 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 825 | } else if ((usecase->stream.out->app_type_cfg.sample_rate == OUTPUT_SAMPLING_RATE_44100 && |
| 826 | !(audio_is_this_native_usecase(usecase))) || |
| 827 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
| 828 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 829 | } |
Venkata Narendra Kumar Gutta | 4bd09d0 | 2016-01-29 15:31:04 +0530 | [diff] [blame] | 830 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 831 | sample_rate = usecase->stream.out->app_type_cfg.sample_rate; |
Manish Dewangan | 837dc46 | 2015-05-27 10:17:41 +0530 | [diff] [blame] | 832 | |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 833 | property_get("audio.playback.mch.downsample",value,""); |
| 834 | if (!strncmp("true", value, sizeof("true"))) { |
| 835 | if ((popcount(usecase->stream.out->channel_mask) > 2) && |
| 836 | (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) && |
| 837 | !(usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) |
| 838 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 839 | } |
Ashish Jain | c02430d | 2016-01-04 10:42:43 +0530 | [diff] [blame] | 840 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 841 | if ((24 == usecase->stream.out->bit_width) && |
| 842 | (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
| 843 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Ashish Jain | a052e57 | 2016-11-07 16:41:07 +0530 | [diff] [blame] | 844 | } else if ((snd_device == SND_DEVICE_OUT_HDMI || |
| 845 | snd_device == SND_DEVICE_OUT_USB_HEADSET || |
| 846 | snd_device == SND_DEVICE_OUT_DISPLAY_PORT) && |
| 847 | (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) { |
| 848 | /* |
| 849 | * To best utlize DSP, check if the stream sample rate is supported/multiple of |
| 850 | * configured device sample rate, if not update the COPP rate to be equal to the |
| 851 | * device sample rate, else open COPP at stream sample rate |
| 852 | */ |
| 853 | platform_check_and_update_copp_sample_rate(adev->platform, snd_device, |
| 854 | usecase->stream.out->sample_rate, |
| 855 | &usecase->stream.out->app_type_cfg.sample_rate); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 856 | } else if ((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && |
| 857 | usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || |
| 858 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
| 859 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 860 | } |
| 861 | sample_rate = usecase->stream.out->app_type_cfg.sample_rate; |
| 862 | |
| 863 | app_type_cfg[len++] = usecase->stream.out->app_type_cfg.app_type; |
| 864 | app_type_cfg[len++] = acdb_dev_id; |
| 865 | if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) || |
| 866 | (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC)) |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 867 | && audio_extn_passthru_is_passthrough_stream(usecase->stream.out)) { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 868 | app_type_cfg[len++] = sample_rate * 4; |
| 869 | } else { |
| 870 | app_type_cfg[len++] = sample_rate; |
| 871 | } |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 872 | |
| 873 | ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d", |
| 874 | __func__, usecase->stream.out->app_type_cfg.app_type, acdb_dev_id, sample_rate); |
| 875 | |
| 876 | } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) { |
| 877 | app_type_cfg[len++] = usecase->stream.in->app_type_cfg.app_type; |
| 878 | app_type_cfg[len++] = acdb_dev_id; |
| 879 | app_type_cfg[len++] = usecase->stream.in->app_type_cfg.sample_rate; |
| 880 | ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d", |
| 881 | __func__, usecase->stream.in->app_type_cfg.app_type, acdb_dev_id, |
| 882 | usecase->stream.in->app_type_cfg.sample_rate); |
| 883 | } else { |
| 884 | app_type_cfg[len++] = platform_get_default_app_type_v2(adev->platform, usecase->type); |
| 885 | app_type_cfg[len++] = acdb_dev_id; |
| 886 | app_type_cfg[len++] = sample_rate; |
| 887 | ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d", |
| 888 | __func__, platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 889 | acdb_dev_id, sample_rate); |
Ashish Jain | c02430d | 2016-01-04 10:42:43 +0530 | [diff] [blame] | 890 | } |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 891 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 892 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 893 | rc = 0; |
| 894 | exit_send_app_type_cfg: |
| 895 | return rc; |
| 896 | } |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 897 | |
Preetam Singh Ranawat | 9519e9c | 2015-11-18 16:05:55 +0530 | [diff] [blame] | 898 | int read_line_from_file(const char *path, char *buf, size_t count) |
| 899 | { |
| 900 | char * fgets_ret; |
| 901 | FILE * fd; |
| 902 | int rv; |
| 903 | |
| 904 | fd = fopen(path, "r"); |
| 905 | if (fd == NULL) |
| 906 | return -1; |
| 907 | |
| 908 | fgets_ret = fgets(buf, (int)count, fd); |
| 909 | if (NULL != fgets_ret) { |
| 910 | rv = (int)strlen(buf); |
| 911 | } else { |
| 912 | rv = ferror(fd); |
| 913 | } |
| 914 | fclose(fd); |
| 915 | |
| 916 | return rv; |
| 917 | } |
| 918 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 919 | /*Translates ALSA formats to AOSP PCM formats*/ |
| 920 | audio_format_t alsa_format_to_hal(uint32_t alsa_format) |
| 921 | { |
| 922 | audio_format_t format; |
| 923 | |
| 924 | switch(alsa_format) { |
| 925 | case SNDRV_PCM_FORMAT_S16_LE: |
| 926 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 927 | break; |
| 928 | case SNDRV_PCM_FORMAT_S24_3LE: |
| 929 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 930 | break; |
| 931 | case SNDRV_PCM_FORMAT_S24_LE: |
| 932 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 933 | break; |
| 934 | case SNDRV_PCM_FORMAT_S32_LE: |
| 935 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 936 | break; |
| 937 | default: |
| 938 | ALOGW("Incorrect ALSA format"); |
| 939 | format = AUDIO_FORMAT_INVALID; |
| 940 | } |
| 941 | return format; |
| 942 | } |
| 943 | |
| 944 | /*Translates hal format (AOSP) to alsa formats*/ |
| 945 | uint32_t hal_format_to_alsa(audio_format_t hal_format) |
| 946 | { |
| 947 | uint32_t alsa_format; |
| 948 | |
| 949 | switch (hal_format) { |
| 950 | case AUDIO_FORMAT_PCM_32_BIT: { |
| 951 | if (platform_supports_true_32bit()) |
| 952 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 953 | else |
| 954 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 955 | } |
| 956 | break; |
| 957 | case AUDIO_FORMAT_PCM_8_BIT: |
| 958 | alsa_format = SNDRV_PCM_FORMAT_S8; |
| 959 | break; |
| 960 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 961 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 962 | break; |
| 963 | case AUDIO_FORMAT_PCM_8_24_BIT: { |
| 964 | if (platform_supports_true_32bit()) |
| 965 | alsa_format = SNDRV_PCM_FORMAT_S32_LE; |
| 966 | else |
| 967 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 968 | } |
| 969 | break; |
| 970 | case AUDIO_FORMAT_PCM_FLOAT: |
| 971 | alsa_format = SNDRV_PCM_FORMAT_S24_3LE; |
| 972 | break; |
| 973 | default: |
| 974 | case AUDIO_FORMAT_PCM_16_BIT: |
| 975 | alsa_format = SNDRV_PCM_FORMAT_S16_LE; |
| 976 | break; |
| 977 | } |
| 978 | return alsa_format; |
| 979 | } |
| 980 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 981 | /*Translates PCM formats to AOSP formats*/ |
| 982 | audio_format_t pcm_format_to_hal(uint32_t pcm_format) |
| 983 | { |
| 984 | audio_format_t format = AUDIO_FORMAT_INVALID; |
| 985 | |
| 986 | switch(pcm_format) { |
| 987 | case PCM_FORMAT_S16_LE: |
| 988 | format = AUDIO_FORMAT_PCM_16_BIT; |
| 989 | break; |
| 990 | case PCM_FORMAT_S24_3LE: |
| 991 | format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 992 | break; |
| 993 | case PCM_FORMAT_S24_LE: |
| 994 | format = AUDIO_FORMAT_PCM_8_24_BIT; |
| 995 | break; |
| 996 | case PCM_FORMAT_S32_LE: |
| 997 | format = AUDIO_FORMAT_PCM_32_BIT; |
| 998 | break; |
| 999 | default: |
| 1000 | ALOGW("Incorrect PCM format"); |
| 1001 | format = AUDIO_FORMAT_INVALID; |
| 1002 | } |
| 1003 | return format; |
| 1004 | } |
| 1005 | |
| 1006 | /*Translates hal format (AOSP) to alsa formats*/ |
| 1007 | uint32_t hal_format_to_pcm(audio_format_t hal_format) |
| 1008 | { |
| 1009 | uint32_t pcm_format; |
| 1010 | |
| 1011 | switch (hal_format) { |
| 1012 | case AUDIO_FORMAT_PCM_32_BIT: |
| 1013 | case AUDIO_FORMAT_PCM_8_24_BIT: |
| 1014 | case AUDIO_FORMAT_PCM_FLOAT: { |
| 1015 | if (platform_supports_true_32bit()) |
| 1016 | pcm_format = PCM_FORMAT_S32_LE; |
| 1017 | else |
| 1018 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1019 | } |
| 1020 | break; |
| 1021 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1022 | pcm_format = PCM_FORMAT_S8; |
| 1023 | break; |
| 1024 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1025 | pcm_format = PCM_FORMAT_S24_3LE; |
| 1026 | break; |
| 1027 | default: |
| 1028 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1029 | pcm_format = PCM_FORMAT_S16_LE; |
| 1030 | break; |
| 1031 | } |
| 1032 | return pcm_format; |
| 1033 | } |
| 1034 | |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1035 | uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample, |
| 1036 | uint32_t sample_rate, |
| 1037 | uint32_t noOfChannels) |
| 1038 | { |
| 1039 | uint32_t fragment_size = 0; |
| 1040 | uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION; |
| 1041 | |
| 1042 | fragment_size = (pcm_offload_time |
| 1043 | * sample_rate |
| 1044 | * bytes_per_sample |
| 1045 | * noOfChannels)/1000; |
| 1046 | if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1047 | fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1048 | else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE) |
| 1049 | fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE; |
| 1050 | /*To have same PCM samples for all channels, the buffer size requires to |
| 1051 | *be multiple of (number of channels * bytes per sample) |
| 1052 | *For writes to succeed, the buffer must be written at address which is multiple of 32 |
| 1053 | */ |
| 1054 | fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32)); |
| 1055 | |
| 1056 | ALOGI("PCM offload Fragment size to %d bytes", fragment_size); |
| 1057 | return fragment_size; |
| 1058 | } |
| 1059 | |
| 1060 | /* Calculates the fragment size required to configure compress session. |
| 1061 | * Based on the alsa format selected, decide if conversion is needed in |
| 1062 | |
| 1063 | * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to |
| 1064 | * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver. |
| 1065 | */ |
| 1066 | void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out) |
| 1067 | { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1068 | audio_format_t dst_format = out->hal_op_format; |
| 1069 | audio_format_t src_format = out->hal_ip_format; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1070 | uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format); |
| 1071 | uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format); |
| 1072 | |
| 1073 | out->compr_config.fragment_size = |
| 1074 | get_alsa_fragment_size(hal_op_bytes_per_sample, |
| 1075 | out->sample_rate, |
| 1076 | popcount(out->channel_mask)); |
| 1077 | |
| 1078 | if ((src_format != dst_format) && |
| 1079 | hal_op_bytes_per_sample != hal_ip_bytes_per_sample) { |
| 1080 | |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1081 | out->hal_fragment_size = |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1082 | ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) / |
| 1083 | hal_op_bytes_per_sample); |
| 1084 | 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] | 1085 | out->hal_fragment_size, src_format, dst_format); |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1086 | } else { |
Ashish Jain | 83a6cc2 | 2016-06-28 14:34:17 +0530 | [diff] [blame] | 1087 | out->hal_fragment_size = out->compr_config.fragment_size; |
Ashish Jain | f1eaa58 | 2016-05-23 20:54:24 +0530 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1091 | /* converts pcm format 24_8 to 8_24 inplace */ |
| 1092 | size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes) |
| 1093 | { |
| 1094 | size_t i = 0; |
| 1095 | int *int_buf_stream = buf; |
| 1096 | |
| 1097 | if ((bytes % 4) != 0) { |
| 1098 | ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__); |
| 1099 | return -EINVAL; |
| 1100 | } |
| 1101 | |
| 1102 | for (; i < (bytes / 4); i++) |
| 1103 | int_buf_stream[i] >>= 8; |
| 1104 | |
| 1105 | return bytes; |
| 1106 | } |
| 1107 | |
| 1108 | int get_snd_codec_id(audio_format_t format) |
| 1109 | { |
| 1110 | int id = 0; |
| 1111 | |
| 1112 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 1113 | case AUDIO_FORMAT_MP3: |
| 1114 | id = SND_AUDIOCODEC_MP3; |
| 1115 | break; |
| 1116 | case AUDIO_FORMAT_AAC: |
| 1117 | id = SND_AUDIOCODEC_AAC; |
| 1118 | break; |
| 1119 | case AUDIO_FORMAT_AAC_ADTS: |
| 1120 | id = SND_AUDIOCODEC_AAC; |
| 1121 | break; |
Arun Kumar Dasari | 3b17418 | 2016-12-27 13:01:14 +0530 | [diff] [blame] | 1122 | case AUDIO_FORMAT_AAC_LATM: |
| 1123 | id = SND_AUDIOCODEC_AAC; |
| 1124 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1125 | case AUDIO_FORMAT_PCM_OFFLOAD: |
| 1126 | case AUDIO_FORMAT_PCM: |
| 1127 | id = SND_AUDIOCODEC_PCM; |
| 1128 | break; |
| 1129 | case AUDIO_FORMAT_FLAC: |
| 1130 | id = SND_AUDIOCODEC_FLAC; |
| 1131 | break; |
| 1132 | case AUDIO_FORMAT_ALAC: |
| 1133 | id = SND_AUDIOCODEC_ALAC; |
| 1134 | break; |
| 1135 | case AUDIO_FORMAT_APE: |
| 1136 | id = SND_AUDIOCODEC_APE; |
| 1137 | break; |
| 1138 | case AUDIO_FORMAT_VORBIS: |
| 1139 | id = SND_AUDIOCODEC_VORBIS; |
| 1140 | break; |
| 1141 | case AUDIO_FORMAT_WMA: |
| 1142 | id = SND_AUDIOCODEC_WMA; |
| 1143 | break; |
| 1144 | case AUDIO_FORMAT_WMA_PRO: |
| 1145 | id = SND_AUDIOCODEC_WMA_PRO; |
| 1146 | break; |
Satish Babu Patakokila | 0c31392 | 2016-12-08 12:07:08 +0530 | [diff] [blame] | 1147 | case AUDIO_FORMAT_MP2: |
| 1148 | id = SND_AUDIOCODEC_MP2; |
| 1149 | break; |
Satish Babu Patakokila | 915ecba | 2017-01-10 17:43:56 +0530 | [diff] [blame] | 1150 | case AUDIO_FORMAT_AC3: |
| 1151 | id = SND_AUDIOCODEC_AC3; |
| 1152 | break; |
| 1153 | case AUDIO_FORMAT_E_AC3: |
| 1154 | case AUDIO_FORMAT_E_AC3_JOC: |
| 1155 | id = SND_AUDIOCODEC_EAC3; |
| 1156 | break; |
| 1157 | case AUDIO_FORMAT_DTS: |
| 1158 | case AUDIO_FORMAT_DTS_HD: |
| 1159 | id = SND_AUDIOCODEC_DTS; |
| 1160 | break; |
Preetam Singh Ranawat | 4277a5a | 2017-01-18 19:02:24 +0530 | [diff] [blame] | 1161 | case AUDIO_FORMAT_DSD: |
| 1162 | id = SND_AUDIOCODEC_DSD; |
| 1163 | break; |
Dhanalakshmi Siddani | 1873793 | 2016-11-29 17:33:17 +0530 | [diff] [blame] | 1164 | case AUDIO_FORMAT_APTX: |
| 1165 | id = SND_AUDIOCODEC_APTX; |
| 1166 | break; |
Dhananjay Kumar | ee4d200 | 2016-10-25 18:02:58 +0530 | [diff] [blame] | 1167 | default: |
| 1168 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
| 1169 | } |
| 1170 | |
| 1171 | return id; |
| 1172 | } |
| 1173 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1174 | void audio_extn_utils_send_audio_calibration(struct audio_device *adev, |
| 1175 | struct audio_usecase *usecase) |
| 1176 | { |
| 1177 | int type = usecase->type; |
| 1178 | |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1179 | if (type == PCM_PLAYBACK && usecase->stream.out != NULL) { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1180 | struct stream_out *out = usecase->stream.out; |
| 1181 | int snd_device = usecase->out_snd_device; |
| 1182 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
Xiaojun Sang | 040cc9f | 2015-08-03 19:38:28 +0800 | [diff] [blame] | 1183 | platform_get_spkr_prot_snd_device(snd_device) : snd_device; |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1184 | platform_send_audio_calibration(adev->platform, usecase, |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1185 | out->app_type_cfg.app_type, |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 1186 | usecase->stream.out->app_type_cfg.sample_rate); |
Dhananjay Kumar | 1424598 | 2017-01-16 20:21:00 +0530 | [diff] [blame] | 1187 | } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) { |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1188 | platform_send_audio_calibration(adev->platform, usecase, |
| 1189 | usecase->stream.in->app_type_cfg.app_type, |
| 1190 | usecase->stream.in->app_type_cfg.sample_rate); |
| 1191 | } else { |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 1192 | /* when app type is default. the sample rate is not used to send cal */ |
| 1193 | platform_send_audio_calibration(adev->platform, usecase, |
Dhananjay Kumar | d6d3215 | 2016-10-13 16:11:03 +0530 | [diff] [blame] | 1194 | platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 1195 | 48000); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 1199 | // Base64 Encode and Decode |
| 1200 | // Not all features supported. This must be used only with following conditions. |
| 1201 | // Decode Modes: Support with and without padding |
| 1202 | // CRLF not handling. So no CRLF in string to decode. |
| 1203 | // Encode Modes: Supports only padding |
| 1204 | int b64decode(char *inp, int ilen, uint8_t* outp) |
| 1205 | { |
| 1206 | int i, j, k, ii, num; |
| 1207 | int rem, pcnt; |
| 1208 | uint32_t res=0; |
| 1209 | uint8_t getIndex[MAX_BASEINDEX_LEN]; |
| 1210 | uint8_t tmp, cflag; |
| 1211 | |
| 1212 | if(inp == NULL || outp == NULL || ilen <= 0) { |
| 1213 | ALOGE("[%s] received NULL pointer or zero length",__func__); |
| 1214 | return -1; |
| 1215 | } |
| 1216 | |
| 1217 | memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex)); |
| 1218 | for(i=0;i<BASE_TABLE_SIZE;i++) { |
| 1219 | getIndex[(uint8_t)bTable[i]] = (uint8_t)i; |
| 1220 | } |
| 1221 | getIndex[(uint8_t)'=']=0; |
| 1222 | |
| 1223 | j=0;k=0; |
| 1224 | num = ilen/4; |
| 1225 | rem = ilen%4; |
| 1226 | if(rem==0) |
| 1227 | num = num-1; |
| 1228 | cflag=0; |
| 1229 | for(i=0; i<num; i++) { |
| 1230 | res=0; |
| 1231 | for(ii=0;ii<4;ii++) { |
| 1232 | res = res << 6; |
| 1233 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1234 | res = res | tmp; |
| 1235 | cflag = cflag | tmp; |
| 1236 | } |
| 1237 | outp[k++] = (res >> 16)&0xFF; |
| 1238 | outp[k++] = (res >> 8)&0xFF; |
| 1239 | outp[k++] = res & 0xFF; |
| 1240 | } |
| 1241 | |
| 1242 | // Handle last bytes special |
| 1243 | pcnt=0; |
| 1244 | if(rem == 0) { |
| 1245 | //With padding or full data |
| 1246 | res = 0; |
| 1247 | for(ii=0;ii<4;ii++) { |
| 1248 | if(inp[j] == '=') |
| 1249 | pcnt++; |
| 1250 | res = res << 6; |
| 1251 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1252 | res = res | tmp; |
| 1253 | cflag = cflag | tmp; |
| 1254 | } |
| 1255 | outp[k++] = res >> 16; |
| 1256 | if(pcnt == 2) |
| 1257 | goto done; |
| 1258 | outp[k++] = (res>>8)&0xFF; |
| 1259 | if(pcnt == 1) |
| 1260 | goto done; |
| 1261 | outp[k++] = res&0xFF; |
| 1262 | } else { |
| 1263 | //without padding |
| 1264 | res = 0; |
| 1265 | for(i=0;i<rem;i++) { |
| 1266 | res = res << 6; |
| 1267 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 1268 | res = res | tmp; |
| 1269 | cflag = cflag | tmp; |
| 1270 | } |
| 1271 | for(i=rem;i<4;i++) { |
| 1272 | res = res << 6; |
| 1273 | pcnt++; |
| 1274 | } |
| 1275 | outp[k++] = res >> 16; |
| 1276 | if(pcnt == 2) |
| 1277 | goto done; |
| 1278 | outp[k++] = (res>>8)&0xFF; |
| 1279 | if(pcnt == 1) |
| 1280 | goto done; |
| 1281 | outp[k++] = res&0xFF; |
| 1282 | } |
| 1283 | done: |
| 1284 | if(cflag == 0xFF) { |
| 1285 | ALOGE("[%s] base64 decode failed. Invalid character found %s", |
| 1286 | __func__, inp); |
| 1287 | return 0; |
| 1288 | } |
| 1289 | return k; |
| 1290 | } |
| 1291 | |
| 1292 | int b64encode(uint8_t *inp, int ilen, char* outp) |
| 1293 | { |
| 1294 | int i,j,k, num; |
| 1295 | int rem=0; |
| 1296 | uint32_t res=0; |
| 1297 | |
| 1298 | if(inp == NULL || outp == NULL || ilen<=0) { |
| 1299 | ALOGE("[%s] received NULL pointer or zero input length",__func__); |
| 1300 | return -1; |
| 1301 | } |
| 1302 | |
| 1303 | num = ilen/3; |
| 1304 | rem = ilen%3; |
| 1305 | j=0;k=0; |
| 1306 | for(i=0; i<num; i++) { |
| 1307 | //prepare index |
| 1308 | res = inp[j++]<<16; |
| 1309 | res = res | inp[j++]<<8; |
| 1310 | res = res | inp[j++]; |
| 1311 | //get output map from index |
| 1312 | outp[k++] = (char) bTable[(res>>18)&0x3F]; |
| 1313 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1314 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 1315 | outp[k++] = (char) bTable[res&0x3F]; |
| 1316 | } |
| 1317 | |
| 1318 | switch(rem) { |
| 1319 | case 1: |
| 1320 | res = inp[j++]<<16; |
| 1321 | outp[k++] = (char) bTable[res>>18]; |
| 1322 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1323 | //outp[k++] = '='; |
| 1324 | //outp[k++] = '='; |
| 1325 | break; |
| 1326 | case 2: |
| 1327 | res = inp[j++]<<16; |
| 1328 | res = res | inp[j++]<<8; |
| 1329 | outp[k++] = (char) bTable[res>>18]; |
| 1330 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 1331 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 1332 | //outp[k++] = '='; |
| 1333 | break; |
| 1334 | default: |
| 1335 | break; |
| 1336 | } |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 1337 | outp[k] = '\0'; |
| 1338 | return k; |
| 1339 | } |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1340 | |
Sidipotu Ashok | e6f78cb | 2015-11-05 14:42:20 +0530 | [diff] [blame] | 1341 | |
| 1342 | int audio_extn_utils_get_codec_version(const char *snd_card_name, |
| 1343 | int card_num, |
| 1344 | char *codec_version) |
| 1345 | { |
| 1346 | char procfs_path[50]; |
| 1347 | FILE *fp; |
| 1348 | |
| 1349 | if (strstr(snd_card_name, "tasha")) { |
| 1350 | snprintf(procfs_path, sizeof(procfs_path), |
| 1351 | "/proc/asound/card%d/codecs/tasha/version", card_num); |
| 1352 | if ((fp = fopen(procfs_path, "r")) != NULL) { |
| 1353 | fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp); |
| 1354 | fclose(fp); |
| 1355 | } else { |
| 1356 | ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path); |
| 1357 | return -ENOENT; |
| 1358 | } |
| 1359 | ALOGD("%s: codec version %s", __func__, codec_version); |
| 1360 | } |
| 1361 | |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1366 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 1367 | |
| 1368 | void get_default_compressed_channel_status( |
| 1369 | unsigned char *channel_status) |
| 1370 | { |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1371 | memset(channel_status,0,24); |
| 1372 | |
| 1373 | /* block start bit in preamble bit 3 */ |
| 1374 | channel_status[0] |= PROFESSIONAL; |
| 1375 | //compre out |
| 1376 | channel_status[0] |= NON_LPCM; |
| 1377 | // sample rate; fixed 48K for default/transcode |
| 1378 | channel_status[3] |= SR_48000; |
| 1379 | } |
| 1380 | |
| 1381 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 1382 | int32_t get_compressed_channel_status(void *audio_stream_data, |
| 1383 | uint32_t audio_frame_size, |
| 1384 | unsigned char *channel_status, |
| 1385 | enum audio_parser_code_type codec_type) |
| 1386 | // codec_type - AUDIO_PARSER_CODEC_AC3 |
| 1387 | // - AUDIO_PARSER_CODEC_DTS |
| 1388 | { |
| 1389 | unsigned char *stream; |
| 1390 | int ret = 0; |
| 1391 | stream = (unsigned char *)audio_stream_data; |
| 1392 | |
| 1393 | if (audio_stream_data == NULL || audio_frame_size == 0) { |
| 1394 | ALOGW("no buffer to get channel status, return default for compress"); |
| 1395 | get_default_compressed_channel_status(channel_status); |
| 1396 | return ret; |
| 1397 | } |
| 1398 | |
| 1399 | memset(channel_status,0,24); |
| 1400 | if(init_audio_parser(stream, audio_frame_size, codec_type) == -1) |
| 1401 | { |
| 1402 | ALOGE("init audio parser failed"); |
| 1403 | return -1; |
| 1404 | } |
| 1405 | ret = get_channel_status(channel_status, codec_type); |
| 1406 | return ret; |
| 1407 | |
| 1408 | } |
| 1409 | |
| 1410 | #endif |
| 1411 | |
| 1412 | void get_lpcm_channel_status(uint32_t sampleRate, |
| 1413 | unsigned char *channel_status) |
| 1414 | { |
| 1415 | int32_t status = 0; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1416 | memset(channel_status,0,24); |
| 1417 | /* block start bit in preamble bit 3 */ |
| 1418 | channel_status[0] |= PROFESSIONAL; |
| 1419 | //LPCM OUT |
| 1420 | channel_status[0] &= ~NON_LPCM; |
| 1421 | |
| 1422 | switch (sampleRate) { |
| 1423 | case 8000: |
| 1424 | case 11025: |
| 1425 | case 12000: |
| 1426 | case 16000: |
| 1427 | case 22050: |
| 1428 | channel_status[3] |= SR_NOTID; |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 1429 | break; |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1430 | case 24000: |
| 1431 | channel_status[3] |= SR_24000; |
| 1432 | break; |
| 1433 | case 32000: |
| 1434 | channel_status[3] |= SR_32000; |
| 1435 | break; |
| 1436 | case 44100: |
| 1437 | channel_status[3] |= SR_44100; |
| 1438 | break; |
| 1439 | case 48000: |
| 1440 | channel_status[3] |= SR_48000; |
| 1441 | break; |
| 1442 | case 88200: |
| 1443 | channel_status[3] |= SR_88200; |
| 1444 | break; |
| 1445 | case 96000: |
| 1446 | channel_status[3] |= SR_96000; |
| 1447 | break; |
| 1448 | case 176400: |
| 1449 | channel_status[3] |= SR_176400; |
| 1450 | break; |
| 1451 | case 192000: |
| 1452 | channel_status[3] |= SR_192000; |
| 1453 | break; |
| 1454 | default: |
| 1455 | ALOGV("Invalid sample_rate %u\n", sampleRate); |
| 1456 | status = -1; |
| 1457 | break; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes) |
| 1462 | { |
| 1463 | unsigned char channel_status[24]={0}; |
| 1464 | struct snd_aes_iec958 iec958; |
| 1465 | const char *mixer_ctl_name = "IEC958 Playback PCM Stream"; |
| 1466 | struct mixer_ctl *ctl; |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 1467 | ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes); |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1468 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 1469 | if (audio_extn_is_dolby_format(out->format) && |
| 1470 | /*TODO:Extend code to support DTS passthrough*/ |
| 1471 | /*set compressed channel status bits*/ |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 1472 | audio_extn_passthru_is_passthrough_stream(out)){ |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 1473 | get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3); |
| 1474 | } else |
| 1475 | #endif |
| 1476 | { |
| 1477 | /*set channel status bit for LPCM*/ |
| 1478 | get_lpcm_channel_status(out->sample_rate, channel_status); |
| 1479 | } |
| 1480 | |
| 1481 | memcpy(iec958.status, channel_status,sizeof(iec958.status)); |
| 1482 | ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name); |
| 1483 | if (!ctl) { |
| 1484 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 1485 | __func__, mixer_ctl_name); |
| 1486 | return; |
| 1487 | } |
| 1488 | if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) { |
| 1489 | ALOGE("%s: Could not set channel status for ext HDMI ", |
| 1490 | __func__); |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | } |
| 1495 | #endif |