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