Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 1 | /* |
Karthik Reddy Katta | d633c54 | 2015-07-15 18:18:03 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2015, 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" |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 37 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 38 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 39 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 40 | #include "audio_parsers.h" |
| 41 | #endif |
| 42 | #endif |
| 43 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 44 | #define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf" |
| 45 | |
| 46 | #define OUTPUTS_TAG "outputs" |
| 47 | |
| 48 | #define DYNAMIC_VALUE_TAG "dynamic" |
| 49 | #define FLAGS_TAG "flags" |
| 50 | #define FORMATS_TAG "formats" |
| 51 | #define SAMPLING_RATES_TAG "sampling_rates" |
| 52 | #define BIT_WIDTH_TAG "bit_width" |
| 53 | #define APP_TYPE_TAG "app_type" |
| 54 | |
| 55 | #define STRING_TO_ENUM(string) { #string, string } |
| 56 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 57 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 58 | #define BASE_TABLE_SIZE 64 |
| 59 | #define MAX_BASEINDEX_LEN 256 |
| 60 | |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 61 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 62 | #define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */ |
| 63 | #define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */ |
| 64 | #define SR_44100 (0<<0) /* 44.1kHz */ |
| 65 | #define SR_NOTID (1<<0) /* non indicated */ |
| 66 | #define SR_48000 (2<<0) /* 48kHz */ |
| 67 | #define SR_32000 (3<<0) /* 32kHz */ |
| 68 | #define SR_22050 (4<<0) /* 22.05kHz */ |
| 69 | #define SR_24000 (6<<0) /* 24kHz */ |
| 70 | #define SR_88200 (8<<0) /* 88.2kHz */ |
| 71 | #define SR_96000 (10<<0) /* 96kHz */ |
| 72 | #define SR_176400 (12<<0) /* 176.4kHz */ |
| 73 | #define SR_192000 (14<<0) /* 192kHz */ |
| 74 | |
| 75 | #endif |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 76 | struct string_to_enum { |
| 77 | const char *name; |
| 78 | uint32_t value; |
| 79 | }; |
| 80 | |
| 81 | const struct string_to_enum s_flag_name_to_enum_table[] = { |
| 82 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT), |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 83 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 84 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY), |
| 85 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST), |
| 86 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER), |
| 87 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD), |
| 88 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 89 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 90 | #ifdef INCALL_MUSIC_ENABLED |
| 91 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC), |
| 92 | #endif |
Mingming Yin | 497419f | 2015-07-01 16:57:32 -0700 | [diff] [blame] | 93 | #ifdef HDMI_PASSTHROUGH_ENABLED |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 94 | STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH), |
Mingming Yin | 497419f | 2015-07-01 16:57:32 -0700 | [diff] [blame] | 95 | #endif |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | const struct string_to_enum s_format_name_to_enum_table[] = { |
| 99 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT), |
| 100 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT), |
| 101 | STRING_TO_ENUM(AUDIO_FORMAT_MP3), |
| 102 | STRING_TO_ENUM(AUDIO_FORMAT_AAC), |
| 103 | STRING_TO_ENUM(AUDIO_FORMAT_VORBIS), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 104 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB), |
| 105 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 106 | STRING_TO_ENUM(AUDIO_FORMAT_AC3), |
Mingming Yin | ae3530f | 2014-07-03 16:50:18 -0700 | [diff] [blame] | 107 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3), |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 108 | #ifdef AUDIO_EXTN_FORMATS_ENABLED |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 109 | STRING_TO_ENUM(AUDIO_FORMAT_DTS), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 110 | STRING_TO_ENUM(AUDIO_FORMAT_WMA), |
| 111 | STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO), |
| 112 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 113 | STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS), |
| 114 | STRING_TO_ENUM(AUDIO_FORMAT_EVRC), |
| 115 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCB), |
| 116 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB), |
| 117 | STRING_TO_ENUM(AUDIO_FORMAT_QCELP), |
| 118 | STRING_TO_ENUM(AUDIO_FORMAT_MP2), |
| 119 | STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW), |
| 120 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT_OFFLOAD), |
| 121 | STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_OFFLOAD), |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 122 | STRING_TO_ENUM(AUDIO_FORMAT_FLAC), |
Satya Krishna Pindiproli | 7047160 | 2015-04-24 19:12:43 +0530 | [diff] [blame] | 123 | STRING_TO_ENUM(AUDIO_FORMAT_ALAC), |
| 124 | STRING_TO_ENUM(AUDIO_FORMAT_APE), |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 125 | STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC), |
Alexy Joseph | cd8eaed | 2014-12-11 12:46:53 -0800 | [diff] [blame] | 126 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC), |
| 127 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1), |
| 128 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2), |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 129 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS), |
| 130 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_LC), |
| 131 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_HE_V1), |
| 132 | STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_HE_V2), |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 133 | #endif |
| 134 | }; |
| 135 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 136 | static char bTable[BASE_TABLE_SIZE] = { |
| 137 | 'A','B','C','D','E','F','G','H','I','J','K','L', |
| 138 | 'M','N','O','P','Q','R','S','T','U','V','W','X', |
| 139 | 'Y','Z','a','b','c','d','e','f','g','h','i','j', |
| 140 | 'k','l','m','n','o','p','q','r','s','t','u','v', |
| 141 | 'w','x','y','z','0','1','2','3','4','5','6','7', |
| 142 | '8','9','+','/' |
| 143 | }; |
| 144 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 145 | static uint32_t string_to_enum(const struct string_to_enum *table, size_t size, |
| 146 | const char *name) |
| 147 | { |
| 148 | size_t i; |
| 149 | for (i = 0; i < size; i++) { |
| 150 | if (strcmp(table[i].name, name) == 0) { |
| 151 | ALOGV("%s found %s", __func__, table[i].name); |
| 152 | return table[i].value; |
| 153 | } |
| 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static audio_output_flags_t parse_flag_names(char *name) |
| 159 | { |
| 160 | uint32_t flag = 0; |
| 161 | char *flag_name = strtok(name, "|"); |
| 162 | while (flag_name != NULL) { |
| 163 | if (strlen(flag_name) != 0) { |
| 164 | flag |= string_to_enum(s_flag_name_to_enum_table, |
| 165 | ARRAY_SIZE(s_flag_name_to_enum_table), |
| 166 | flag_name); |
| 167 | } |
| 168 | flag_name = strtok(NULL, "|"); |
| 169 | } |
| 170 | |
| 171 | ALOGV("parse_flag_names: flag - %d", flag); |
| 172 | return (audio_output_flags_t)flag; |
| 173 | } |
| 174 | |
| 175 | static void parse_format_names(char *name, struct streams_output_cfg *so_info) |
| 176 | { |
| 177 | struct stream_format *sf_info = NULL; |
| 178 | char *str = strtok(name, "|"); |
| 179 | |
| 180 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0) |
| 181 | return; |
| 182 | |
| 183 | list_init(&so_info->format_list); |
| 184 | while (str != NULL) { |
| 185 | audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table, |
| 186 | ARRAY_SIZE(s_format_name_to_enum_table), str); |
| 187 | ALOGV("%s: format - %d", __func__, format); |
| 188 | if (format != 0) { |
| 189 | sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 190 | if (sf_info == NULL) |
| 191 | break; /* return whatever was parsed */ |
| 192 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 193 | sf_info->format = format; |
| 194 | list_add_tail(&so_info->format_list, &sf_info->list); |
| 195 | } |
| 196 | str = strtok(NULL, "|"); |
| 197 | } |
| 198 | } |
| 199 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 200 | static void parse_sample_rate_names(char *name, struct streams_output_cfg *so_info) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 201 | { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 202 | struct stream_sample_rate *ss_info = NULL; |
| 203 | uint32_t sample_rate = 48000; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 204 | char *str = strtok(name, "|"); |
| 205 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 206 | if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG)) |
| 207 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 208 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 209 | list_init(&so_info->sample_rate_list); |
| 210 | while (str != NULL) { |
| 211 | sample_rate = (uint32_t)strtol(str, (char **)NULL, 10); |
| 212 | ALOGV("%s: sample_rate - %d", __func__, sample_rate); |
| 213 | if (0 != sample_rate) { |
| 214 | ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate)); |
Chaithanya Krishna Bacharaju | db6236a | 2015-01-30 10:08:33 +0530 | [diff] [blame] | 215 | if (ss_info == NULL) |
| 216 | break; /* return whatever was parsed */ |
| 217 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 218 | ss_info->sample_rate = sample_rate; |
| 219 | list_add_tail(&so_info->sample_rate_list, &ss_info->list); |
| 220 | } |
| 221 | str = strtok(NULL, "|"); |
| 222 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static int parse_bit_width_names(char *name) |
| 226 | { |
| 227 | int bit_width = 16; |
| 228 | char *str = strtok(name, "|"); |
| 229 | |
| 230 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 231 | bit_width = (int)strtol(str, (char **)NULL, 10); |
| 232 | |
| 233 | ALOGV("%s: bit_width - %d", __func__, bit_width); |
| 234 | return bit_width; |
| 235 | } |
| 236 | |
| 237 | static int parse_app_type_names(void *platform, char *name) |
| 238 | { |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 239 | int app_type = platform_get_default_app_type(platform); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 240 | char *str = strtok(name, "|"); |
| 241 | |
| 242 | if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG)) |
| 243 | app_type = (int)strtol(str, (char **)NULL, 10); |
| 244 | |
| 245 | ALOGV("%s: app_type - %d", __func__, app_type); |
| 246 | return app_type; |
| 247 | } |
| 248 | |
| 249 | static void update_streams_output_cfg_list(cnode *root, void *platform, |
| 250 | struct listnode *streams_output_cfg_list) |
| 251 | { |
| 252 | cnode *node = root->first_child; |
| 253 | struct streams_output_cfg *so_info; |
| 254 | |
| 255 | ALOGV("%s", __func__); |
| 256 | so_info = (struct streams_output_cfg *)calloc(1, sizeof(struct streams_output_cfg)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 257 | |
| 258 | if (!so_info) { |
| 259 | ALOGE("failed to allocate mem for so_info list element"); |
| 260 | return; |
| 261 | } |
| 262 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 263 | while (node) { |
| 264 | if (strcmp(node->name, FLAGS_TAG) == 0) { |
| 265 | so_info->flags = parse_flag_names((char *)node->value); |
| 266 | } else if (strcmp(node->name, FORMATS_TAG) == 0) { |
| 267 | parse_format_names((char *)node->value, so_info); |
| 268 | } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 269 | so_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 270 | parse_sample_rate_names((char *)node->value, so_info); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 271 | } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) { |
| 272 | so_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value); |
| 273 | } else if (strcmp(node->name, APP_TYPE_TAG) == 0) { |
| 274 | so_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value); |
| 275 | } |
| 276 | node = node->next; |
| 277 | } |
| 278 | list_add_tail(streams_output_cfg_list, &so_info->list); |
| 279 | } |
| 280 | |
| 281 | static void load_output(cnode *root, void *platform, |
| 282 | struct listnode *streams_output_cfg_list) |
| 283 | { |
| 284 | cnode *node = config_find(root, OUTPUTS_TAG); |
| 285 | if (node == NULL) { |
| 286 | ALOGE("%s: could not load output, node is NULL", __func__); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | node = node->first_child; |
| 291 | while (node) { |
| 292 | ALOGV("%s: loading output %s", __func__, node->name); |
| 293 | update_streams_output_cfg_list(node, platform, streams_output_cfg_list); |
| 294 | node = node->next; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | static void send_app_type_cfg(void *platform, struct mixer *mixer, |
| 299 | struct listnode *streams_output_cfg_list) |
| 300 | { |
| 301 | int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {-1}; |
| 302 | int length = 0, i, num_app_types = 0; |
| 303 | struct listnode *node; |
| 304 | bool update; |
| 305 | struct mixer_ctl *ctl = NULL; |
| 306 | const char *mixer_ctl_name = "App Type Config"; |
| 307 | struct streams_output_cfg *so_info; |
| 308 | |
| 309 | if (!mixer) { |
| 310 | ALOGE("%s: mixer is null",__func__); |
| 311 | return; |
| 312 | } |
| 313 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 314 | if (!ctl) { |
| 315 | ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name); |
| 316 | return; |
| 317 | } |
| 318 | if (streams_output_cfg_list == NULL) { |
| 319 | app_type_cfg[length++] = 1; |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 320 | app_type_cfg[length++] = platform_get_default_app_type(platform); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 321 | app_type_cfg[length++] = 48000; |
| 322 | app_type_cfg[length++] = 16; |
| 323 | mixer_ctl_set_array(ctl, app_type_cfg, length); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | app_type_cfg[length++] = num_app_types; |
| 328 | list_for_each(node, streams_output_cfg_list) { |
| 329 | so_info = node_to_item(node, struct streams_output_cfg, list); |
| 330 | update = true; |
| 331 | for (i=0; i<length; i=i+3) { |
| 332 | if (app_type_cfg[i+1] == -1) |
| 333 | break; |
| 334 | else if (app_type_cfg[i+1] == so_info->app_type_cfg.app_type) { |
| 335 | update = false; |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) { |
| 340 | num_app_types += 1 ; |
| 341 | app_type_cfg[length++] = so_info->app_type_cfg.app_type; |
| 342 | app_type_cfg[length++] = so_info->app_type_cfg.sample_rate; |
| 343 | app_type_cfg[length++] = so_info->app_type_cfg.bit_width; |
| 344 | } |
| 345 | } |
| 346 | ALOGV("%s: num_app_types: %d", __func__, num_app_types); |
| 347 | if (num_app_types) { |
| 348 | app_type_cfg[0] = num_app_types; |
| 349 | mixer_ctl_set_array(ctl, app_type_cfg, length); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | void audio_extn_utils_update_streams_output_cfg_list(void *platform, |
| 354 | struct mixer *mixer, |
| 355 | struct listnode *streams_output_cfg_list) |
| 356 | { |
| 357 | cnode *root; |
| 358 | char *data; |
| 359 | |
| 360 | ALOGV("%s", __func__); |
| 361 | list_init(streams_output_cfg_list); |
| 362 | data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL); |
| 363 | if (data == NULL) { |
| 364 | send_app_type_cfg(platform, mixer, NULL); |
| 365 | ALOGE("%s: could not load output policy config file", __func__); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | root = config_node("", ""); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 370 | if (root == NULL) { |
| 371 | ALOGE("cfg_list, NULL config root"); |
| 372 | return; |
| 373 | } |
| 374 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 375 | config_load(root, data); |
| 376 | load_output(root, platform, streams_output_cfg_list); |
| 377 | |
| 378 | send_app_type_cfg(platform, mixer, streams_output_cfg_list); |
| 379 | } |
| 380 | |
| 381 | void audio_extn_utils_dump_streams_output_cfg_list( |
| 382 | struct listnode *streams_output_cfg_list) |
| 383 | { |
| 384 | int i=0; |
| 385 | struct listnode *node_i, *node_j; |
| 386 | struct streams_output_cfg *so_info; |
| 387 | struct stream_format *sf_info; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 388 | struct stream_sample_rate *ss_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 389 | ALOGV("%s", __func__); |
| 390 | list_for_each(node_i, streams_output_cfg_list) { |
| 391 | so_info = node_to_item(node_i, struct streams_output_cfg, list); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 392 | ALOGV("%s: flags-%d, output_sample_rate-%d, output_bit_width-%d, app_type-%d", |
| 393 | __func__, so_info->flags, so_info->app_type_cfg.sample_rate, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 394 | so_info->app_type_cfg.bit_width, so_info->app_type_cfg.app_type); |
| 395 | list_for_each(node_j, &so_info->format_list) { |
| 396 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 397 | ALOGV("format-%x", sf_info->format); |
| 398 | } |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 399 | list_for_each(node_j, &so_info->sample_rate_list) { |
| 400 | ss_info = node_to_item(node_j, struct stream_sample_rate, list); |
| 401 | ALOGV("sample rate-%d", ss_info->sample_rate); |
| 402 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | void audio_extn_utils_release_streams_output_cfg_list( |
| 407 | struct listnode *streams_output_cfg_list) |
| 408 | { |
| 409 | struct listnode *node_i, *node_j; |
| 410 | struct streams_output_cfg *so_info; |
| 411 | struct stream_format *sf_info; |
| 412 | |
| 413 | ALOGV("%s", __func__); |
| 414 | while (!list_empty(streams_output_cfg_list)) { |
| 415 | node_i = list_head(streams_output_cfg_list); |
| 416 | so_info = node_to_item(node_i, struct streams_output_cfg, list); |
| 417 | while (!list_empty(&so_info->format_list)) { |
| 418 | node_j = list_head(&so_info->format_list); |
| 419 | list_remove(node_j); |
| 420 | free(node_to_item(node_j, struct stream_format, list)); |
| 421 | } |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 422 | while (!list_empty(&so_info->sample_rate_list)) { |
| 423 | node_j = list_head(&so_info->sample_rate_list); |
| 424 | list_remove(node_j); |
| 425 | free(node_to_item(node_j, struct stream_sample_rate, list)); |
| 426 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 427 | list_remove(node_i); |
| 428 | free(node_to_item(node_i, struct streams_output_cfg, list)); |
| 429 | } |
| 430 | } |
| 431 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 432 | static bool set_output_cfg(struct streams_output_cfg *so_info, |
| 433 | struct stream_app_type_cfg *app_type_cfg, |
| 434 | uint32_t sample_rate, uint32_t bit_width) |
| 435 | { |
| 436 | struct listnode *node_i; |
| 437 | struct stream_sample_rate *ss_info; |
| 438 | list_for_each(node_i, &so_info->sample_rate_list) { |
| 439 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 440 | if ((sample_rate <= ss_info->sample_rate) && |
| 441 | (bit_width == so_info->app_type_cfg.bit_width)) { |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 442 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 443 | app_type_cfg->app_type = so_info->app_type_cfg.app_type; |
| 444 | app_type_cfg->sample_rate = ss_info->sample_rate; |
| 445 | app_type_cfg->bit_width = so_info->app_type_cfg.bit_width; |
| 446 | ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d", |
| 447 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 448 | return true; |
| 449 | } |
| 450 | } |
| 451 | /* |
| 452 | * Reiterate through the list assuming dafault sample rate. |
| 453 | * Handles scenario where input sample rate is higher |
| 454 | * than all sample rates in list for the input bit width. |
| 455 | */ |
| 456 | sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 457 | |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 458 | list_for_each(node_i, &so_info->sample_rate_list) { |
| 459 | ss_info = node_to_item(node_i, struct stream_sample_rate, list); |
| 460 | if ((sample_rate <= ss_info->sample_rate) && |
| 461 | (bit_width == so_info->app_type_cfg.bit_width)) { |
| 462 | app_type_cfg->app_type = so_info->app_type_cfg.app_type; |
| 463 | app_type_cfg->sample_rate = sample_rate; |
| 464 | app_type_cfg->bit_width = so_info->app_type_cfg.bit_width; |
Apoorv Raghuvanshi | f59bb22 | 2015-02-18 12:23:23 -0800 | [diff] [blame] | 465 | 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] | 466 | __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width); |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | return false; |
| 471 | } |
| 472 | |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 473 | void audio_extn_utils_update_stream_app_type_cfg(void *platform, |
| 474 | struct listnode *streams_output_cfg_list, |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 475 | audio_devices_t devices, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 476 | audio_output_flags_t flags, |
| 477 | audio_format_t format, |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 478 | uint32_t sample_rate, |
| 479 | uint32_t bit_width, |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 480 | struct stream_app_type_cfg *app_type_cfg) |
| 481 | { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 482 | struct listnode *node_i, *node_j, *node_k; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 483 | struct streams_output_cfg *so_info; |
| 484 | struct stream_format *sf_info; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 485 | struct stream_sample_rate *ss_info; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 486 | |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 487 | if ((24 == bit_width) && |
| 488 | (devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
Amit Shekhar | 5a39c91 | 2014-10-14 15:39:30 -0700 | [diff] [blame] | 489 | int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER); |
| 490 | if (-ENOSYS != bw) |
| 491 | bit_width = (uint32_t)bw; |
Amit Shekhar | 1d89604 | 2014-10-03 13:16:09 -0700 | [diff] [blame] | 492 | sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
| 493 | ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__); |
| 494 | } |
| 495 | |
| 496 | ALOGV("%s: flags: %x, format: %x sample_rate %d", |
| 497 | __func__, flags, format, sample_rate); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 498 | list_for_each(node_i, streams_output_cfg_list) { |
| 499 | so_info = node_to_item(node_i, struct streams_output_cfg, list); |
| 500 | if (so_info->flags == flags) { |
| 501 | list_for_each(node_j, &so_info->format_list) { |
| 502 | sf_info = node_to_item(node_j, struct stream_format, list); |
| 503 | if (sf_info->format == format) { |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 504 | if (set_output_cfg(so_info, app_type_cfg, sample_rate, bit_width)) |
| 505 | return; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | list_for_each(node_i, streams_output_cfg_list) { |
| 511 | so_info = node_to_item(node_i, struct streams_output_cfg, list); |
| 512 | if (so_info->flags == AUDIO_OUTPUT_FLAG_PRIMARY) { |
| 513 | ALOGV("Compatible output profile not found."); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 514 | app_type_cfg->app_type = so_info->app_type_cfg.app_type; |
| 515 | app_type_cfg->sample_rate = so_info->app_type_cfg.sample_rate; |
| 516 | app_type_cfg->bit_width = so_info->app_type_cfg.bit_width; |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 517 | ALOGV("%s Default to primary output: App type: %d sample_rate %d", |
| 518 | __func__, so_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] | 519 | return; |
| 520 | } |
| 521 | } |
| 522 | 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] | 523 | app_type_cfg->app_type = platform_get_default_app_type(platform); |
Amit Shekhar | 6f461b1 | 2014-08-01 14:52:58 -0700 | [diff] [blame] | 524 | app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 525 | app_type_cfg->bit_width = 16; |
| 526 | } |
| 527 | |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 528 | int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, |
| 529 | struct audio_usecase *usecase) |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 530 | { |
| 531 | char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT]; |
| 532 | int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT], len = 0, rc; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 533 | struct mixer_ctl *ctl; |
| 534 | int pcm_device_id, acdb_dev_id, snd_device = usecase->out_snd_device; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 535 | int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 536 | |
| 537 | ALOGV("%s", __func__); |
| 538 | |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 539 | if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) { |
| 540 | ALOGE("%s: not a playback or capture path, no need to cfg app type", __func__); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 541 | rc = 0; |
| 542 | goto exit_send_app_type_cfg; |
| 543 | } |
| 544 | if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) && |
| 545 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) && |
| 546 | (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) && |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 547 | (!is_offload_usecase(usecase->id)) && |
| 548 | (usecase->type != PCM_CAPTURE)) { |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 549 | ALOGV("%s: a rx/tx 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] | 550 | rc = 0; |
| 551 | goto exit_send_app_type_cfg; |
| 552 | } |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 553 | if (usecase->type == PCM_PLAYBACK) { |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 554 | snd_device = usecase->out_snd_device; |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 555 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK); |
| 556 | } else if (usecase->type == PCM_CAPTURE) { |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 557 | snd_device = usecase->in_snd_device; |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 558 | pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 559 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 560 | |
| 561 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 562 | "Audio Stream %d App Type Cfg", pcm_device_id); |
| 563 | |
| 564 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 565 | if (!ctl) { |
| 566 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, |
| 567 | mixer_ctl_name); |
| 568 | rc = -EINVAL; |
| 569 | goto exit_send_app_type_cfg; |
| 570 | } |
| 571 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
| 572 | audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device; |
| 573 | acdb_dev_id = platform_get_snd_device_acdb_id(snd_device); |
| 574 | if (acdb_dev_id < 0) { |
| 575 | ALOGE("%s: Couldn't get the acdb dev id", __func__); |
| 576 | rc = -EINVAL; |
| 577 | goto exit_send_app_type_cfg; |
| 578 | } |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 579 | |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 580 | if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out == NULL)) { |
| 581 | sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Srikanth Uyyala | a1e3235 | 2015-10-09 14:48:04 +0530 | [diff] [blame] | 582 | app_type_cfg[len++] = platform_get_default_app_type_v2(adev->platform, usecase->type); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 583 | app_type_cfg[len++] = acdb_dev_id; |
| 584 | app_type_cfg[len++] = sample_rate; |
| 585 | ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d", |
Srikanth Uyyala | a1e3235 | 2015-10-09 14:48:04 +0530 | [diff] [blame] | 586 | __func__, platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 587 | acdb_dev_id, sample_rate); |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 588 | } else if (usecase->type == PCM_PLAYBACK) { |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 589 | if ((24 == usecase->stream.out->bit_width) && |
| 590 | (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) { |
Dhananjay Kumar | 14170dd | 2015-08-28 13:24:16 +0530 | [diff] [blame] | 591 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 592 | } else if ((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 && |
| 593 | usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) || |
| 594 | (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) { |
Dhananjay Kumar | 14170dd | 2015-08-28 13:24:16 +0530 | [diff] [blame] | 595 | usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE; |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 596 | } |
Dhananjay Kumar | 14170dd | 2015-08-28 13:24:16 +0530 | [diff] [blame] | 597 | sample_rate = usecase->stream.out->app_type_cfg.sample_rate; |
Preetam Singh Ranawat | a4a37d8 | 2014-09-25 16:56:38 +0530 | [diff] [blame] | 598 | |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 599 | app_type_cfg[len++] = usecase->stream.out->app_type_cfg.app_type; |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 600 | app_type_cfg[len++] = acdb_dev_id; |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 601 | if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) || |
| 602 | (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC)) |
Mingming Yin | 497419f | 2015-07-01 16:57:32 -0700 | [diff] [blame] | 603 | #ifdef HDMI_PASSTHROUGH_ENABLED |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 604 | && (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) |
Mingming Yin | 497419f | 2015-07-01 16:57:32 -0700 | [diff] [blame] | 605 | #endif |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 606 | ) |
| 607 | app_type_cfg[len++] = sample_rate * 4; |
| 608 | else |
| 609 | app_type_cfg[len++] = sample_rate; |
| 610 | ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d", |
Ben Romberger | 1fafdde | 2015-09-09 19:43:15 -0700 | [diff] [blame] | 611 | __func__, usecase->stream.out->app_type_cfg.app_type, acdb_dev_id, sample_rate); |
| 612 | } else if (usecase->type == PCM_CAPTURE) { |
Srikanth Uyyala | a1e3235 | 2015-10-09 14:48:04 +0530 | [diff] [blame] | 613 | app_type_cfg[len++] = platform_get_default_app_type_v2(adev->platform, usecase->type); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 614 | app_type_cfg[len++] = acdb_dev_id; |
Pradnya Chaphekar | 80a8cfb | 2014-10-20 16:17:01 -0700 | [diff] [blame] | 615 | app_type_cfg[len++] = sample_rate; |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 616 | ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d", |
Srikanth Uyyala | a1e3235 | 2015-10-09 14:48:04 +0530 | [diff] [blame] | 617 | __func__, platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 618 | acdb_dev_id, sample_rate); |
Srikanth Uyyala | 9d55140 | 2015-08-25 16:03:42 +0530 | [diff] [blame] | 619 | } |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 620 | mixer_ctl_set_array(ctl, app_type_cfg, len); |
Subhash Chandra Bose Naripeddy | 19dc03b | 2014-03-10 14:43:05 -0700 | [diff] [blame] | 621 | rc = 0; |
| 622 | exit_send_app_type_cfg: |
| 623 | return rc; |
| 624 | } |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 625 | |
Preetam Singh Ranawat | 9519e9c | 2015-11-18 16:05:55 +0530 | [diff] [blame^] | 626 | int read_line_from_file(const char *path, char *buf, size_t count) |
| 627 | { |
| 628 | char * fgets_ret; |
| 629 | FILE * fd; |
| 630 | int rv; |
| 631 | |
| 632 | fd = fopen(path, "r"); |
| 633 | if (fd == NULL) |
| 634 | return -1; |
| 635 | |
| 636 | fgets_ret = fgets(buf, (int)count, fd); |
| 637 | if (NULL != fgets_ret) { |
| 638 | rv = (int)strlen(buf); |
| 639 | } else { |
| 640 | rv = ferror(fd); |
| 641 | } |
| 642 | fclose(fd); |
| 643 | |
| 644 | return rv; |
| 645 | } |
| 646 | |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 647 | void audio_extn_utils_send_audio_calibration(struct audio_device *adev, |
| 648 | struct audio_usecase *usecase) |
| 649 | { |
| 650 | int type = usecase->type; |
| 651 | |
| 652 | if (type == PCM_PLAYBACK) { |
| 653 | struct stream_out *out = usecase->stream.out; |
| 654 | int snd_device = usecase->out_snd_device; |
| 655 | snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ? |
| 656 | audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device; |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 657 | platform_send_audio_calibration(adev->platform, usecase, |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 658 | out->app_type_cfg.app_type, |
| 659 | out->app_type_cfg.sample_rate); |
| 660 | } |
| 661 | if ((type == PCM_HFP_CALL) || (type == PCM_CAPTURE)) { |
Preetam Singh Ranawat | 2d0e463 | 2015-02-02 12:40:59 +0530 | [diff] [blame] | 662 | /* when app type is default. the sample rate is not used to send cal */ |
| 663 | platform_send_audio_calibration(adev->platform, usecase, |
Srikanth Uyyala | a1e3235 | 2015-10-09 14:48:04 +0530 | [diff] [blame] | 664 | platform_get_default_app_type_v2(adev->platform, usecase->type), |
| 665 | 48000); |
Subhash Chandra Bose Naripeddy | 5427467 | 2014-03-10 14:51:02 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
Ben Romberger | a04fabc | 2014-11-14 12:16:03 -0800 | [diff] [blame] | 669 | // Base64 Encode and Decode |
| 670 | // Not all features supported. This must be used only with following conditions. |
| 671 | // Decode Modes: Support with and without padding |
| 672 | // CRLF not handling. So no CRLF in string to decode. |
| 673 | // Encode Modes: Supports only padding |
| 674 | int b64decode(char *inp, int ilen, uint8_t* outp) |
| 675 | { |
| 676 | int i, j, k, ii, num; |
| 677 | int rem, pcnt; |
| 678 | uint32_t res=0; |
| 679 | uint8_t getIndex[MAX_BASEINDEX_LEN]; |
| 680 | uint8_t tmp, cflag; |
| 681 | |
| 682 | if(inp == NULL || outp == NULL || ilen <= 0) { |
| 683 | ALOGE("[%s] received NULL pointer or zero length",__func__); |
| 684 | return -1; |
| 685 | } |
| 686 | |
| 687 | memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex)); |
| 688 | for(i=0;i<BASE_TABLE_SIZE;i++) { |
| 689 | getIndex[(uint8_t)bTable[i]] = (uint8_t)i; |
| 690 | } |
| 691 | getIndex[(uint8_t)'=']=0; |
| 692 | |
| 693 | j=0;k=0; |
| 694 | num = ilen/4; |
| 695 | rem = ilen%4; |
| 696 | if(rem==0) |
| 697 | num = num-1; |
| 698 | cflag=0; |
| 699 | for(i=0; i<num; i++) { |
| 700 | res=0; |
| 701 | for(ii=0;ii<4;ii++) { |
| 702 | res = res << 6; |
| 703 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 704 | res = res | tmp; |
| 705 | cflag = cflag | tmp; |
| 706 | } |
| 707 | outp[k++] = (res >> 16)&0xFF; |
| 708 | outp[k++] = (res >> 8)&0xFF; |
| 709 | outp[k++] = res & 0xFF; |
| 710 | } |
| 711 | |
| 712 | // Handle last bytes special |
| 713 | pcnt=0; |
| 714 | if(rem == 0) { |
| 715 | //With padding or full data |
| 716 | res = 0; |
| 717 | for(ii=0;ii<4;ii++) { |
| 718 | if(inp[j] == '=') |
| 719 | pcnt++; |
| 720 | res = res << 6; |
| 721 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 722 | res = res | tmp; |
| 723 | cflag = cflag | tmp; |
| 724 | } |
| 725 | outp[k++] = res >> 16; |
| 726 | if(pcnt == 2) |
| 727 | goto done; |
| 728 | outp[k++] = (res>>8)&0xFF; |
| 729 | if(pcnt == 1) |
| 730 | goto done; |
| 731 | outp[k++] = res&0xFF; |
| 732 | } else { |
| 733 | //without padding |
| 734 | res = 0; |
| 735 | for(i=0;i<rem;i++) { |
| 736 | res = res << 6; |
| 737 | tmp = getIndex[(uint8_t)inp[j++]]; |
| 738 | res = res | tmp; |
| 739 | cflag = cflag | tmp; |
| 740 | } |
| 741 | for(i=rem;i<4;i++) { |
| 742 | res = res << 6; |
| 743 | pcnt++; |
| 744 | } |
| 745 | outp[k++] = res >> 16; |
| 746 | if(pcnt == 2) |
| 747 | goto done; |
| 748 | outp[k++] = (res>>8)&0xFF; |
| 749 | if(pcnt == 1) |
| 750 | goto done; |
| 751 | outp[k++] = res&0xFF; |
| 752 | } |
| 753 | done: |
| 754 | if(cflag == 0xFF) { |
| 755 | ALOGE("[%s] base64 decode failed. Invalid character found %s", |
| 756 | __func__, inp); |
| 757 | return 0; |
| 758 | } |
| 759 | return k; |
| 760 | } |
| 761 | |
| 762 | int b64encode(uint8_t *inp, int ilen, char* outp) |
| 763 | { |
| 764 | int i,j,k, num; |
| 765 | int rem=0; |
| 766 | uint32_t res=0; |
| 767 | |
| 768 | if(inp == NULL || outp == NULL || ilen<=0) { |
| 769 | ALOGE("[%s] received NULL pointer or zero input length",__func__); |
| 770 | return -1; |
| 771 | } |
| 772 | |
| 773 | num = ilen/3; |
| 774 | rem = ilen%3; |
| 775 | j=0;k=0; |
| 776 | for(i=0; i<num; i++) { |
| 777 | //prepare index |
| 778 | res = inp[j++]<<16; |
| 779 | res = res | inp[j++]<<8; |
| 780 | res = res | inp[j++]; |
| 781 | //get output map from index |
| 782 | outp[k++] = (char) bTable[(res>>18)&0x3F]; |
| 783 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 784 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 785 | outp[k++] = (char) bTable[res&0x3F]; |
| 786 | } |
| 787 | |
| 788 | switch(rem) { |
| 789 | case 1: |
| 790 | res = inp[j++]<<16; |
| 791 | outp[k++] = (char) bTable[res>>18]; |
| 792 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 793 | //outp[k++] = '='; |
| 794 | //outp[k++] = '='; |
| 795 | break; |
| 796 | case 2: |
| 797 | res = inp[j++]<<16; |
| 798 | res = res | inp[j++]<<8; |
| 799 | outp[k++] = (char) bTable[res>>18]; |
| 800 | outp[k++] = (char) bTable[(res>>12)&0x3F]; |
| 801 | outp[k++] = (char) bTable[(res>>6)&0x3F]; |
| 802 | //outp[k++] = '='; |
| 803 | break; |
| 804 | default: |
| 805 | break; |
| 806 | } |
| 807 | done: |
| 808 | outp[k] = '\0'; |
| 809 | return k; |
| 810 | } |
Ashish Jain | 81eb2a8 | 2015-05-13 10:52:34 +0530 | [diff] [blame] | 811 | |
| 812 | #ifdef AUDIO_EXTERNAL_HDMI_ENABLED |
| 813 | |
| 814 | void get_default_compressed_channel_status( |
| 815 | unsigned char *channel_status) |
| 816 | { |
| 817 | int32_t status = 0; |
| 818 | unsigned char bit_index; |
| 819 | memset(channel_status,0,24); |
| 820 | |
| 821 | /* block start bit in preamble bit 3 */ |
| 822 | channel_status[0] |= PROFESSIONAL; |
| 823 | //compre out |
| 824 | channel_status[0] |= NON_LPCM; |
| 825 | // sample rate; fixed 48K for default/transcode |
| 826 | channel_status[3] |= SR_48000; |
| 827 | } |
| 828 | |
| 829 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 830 | int32_t get_compressed_channel_status(void *audio_stream_data, |
| 831 | uint32_t audio_frame_size, |
| 832 | unsigned char *channel_status, |
| 833 | enum audio_parser_code_type codec_type) |
| 834 | // codec_type - AUDIO_PARSER_CODEC_AC3 |
| 835 | // - AUDIO_PARSER_CODEC_DTS |
| 836 | { |
| 837 | unsigned char *stream; |
| 838 | int ret = 0; |
| 839 | stream = (unsigned char *)audio_stream_data; |
| 840 | |
| 841 | if (audio_stream_data == NULL || audio_frame_size == 0) { |
| 842 | ALOGW("no buffer to get channel status, return default for compress"); |
| 843 | get_default_compressed_channel_status(channel_status); |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | memset(channel_status,0,24); |
| 848 | if(init_audio_parser(stream, audio_frame_size, codec_type) == -1) |
| 849 | { |
| 850 | ALOGE("init audio parser failed"); |
| 851 | return -1; |
| 852 | } |
| 853 | ret = get_channel_status(channel_status, codec_type); |
| 854 | return ret; |
| 855 | |
| 856 | } |
| 857 | |
| 858 | #endif |
| 859 | |
| 860 | void get_lpcm_channel_status(uint32_t sampleRate, |
| 861 | unsigned char *channel_status) |
| 862 | { |
| 863 | int32_t status = 0; |
| 864 | unsigned char bit_index; |
| 865 | memset(channel_status,0,24); |
| 866 | /* block start bit in preamble bit 3 */ |
| 867 | channel_status[0] |= PROFESSIONAL; |
| 868 | //LPCM OUT |
| 869 | channel_status[0] &= ~NON_LPCM; |
| 870 | |
| 871 | switch (sampleRate) { |
| 872 | case 8000: |
| 873 | case 11025: |
| 874 | case 12000: |
| 875 | case 16000: |
| 876 | case 22050: |
| 877 | channel_status[3] |= SR_NOTID; |
| 878 | case 24000: |
| 879 | channel_status[3] |= SR_24000; |
| 880 | break; |
| 881 | case 32000: |
| 882 | channel_status[3] |= SR_32000; |
| 883 | break; |
| 884 | case 44100: |
| 885 | channel_status[3] |= SR_44100; |
| 886 | break; |
| 887 | case 48000: |
| 888 | channel_status[3] |= SR_48000; |
| 889 | break; |
| 890 | case 88200: |
| 891 | channel_status[3] |= SR_88200; |
| 892 | break; |
| 893 | case 96000: |
| 894 | channel_status[3] |= SR_96000; |
| 895 | break; |
| 896 | case 176400: |
| 897 | channel_status[3] |= SR_176400; |
| 898 | break; |
| 899 | case 192000: |
| 900 | channel_status[3] |= SR_192000; |
| 901 | break; |
| 902 | default: |
| 903 | ALOGV("Invalid sample_rate %u\n", sampleRate); |
| 904 | status = -1; |
| 905 | break; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes) |
| 910 | { |
| 911 | unsigned char channel_status[24]={0}; |
| 912 | struct snd_aes_iec958 iec958; |
| 913 | const char *mixer_ctl_name = "IEC958 Playback PCM Stream"; |
| 914 | struct mixer_ctl *ctl; |
| 915 | int i=0; |
| 916 | #ifdef HDMI_PASSTHROUGH_ENABLED |
| 917 | if (audio_extn_is_dolby_format(out->format) && |
| 918 | /*TODO:Extend code to support DTS passthrough*/ |
| 919 | /*set compressed channel status bits*/ |
| 920 | audio_extn_dolby_is_passthrough_stream(out->flags)){ |
| 921 | get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3); |
| 922 | } else |
| 923 | #endif |
| 924 | { |
| 925 | /*set channel status bit for LPCM*/ |
| 926 | get_lpcm_channel_status(out->sample_rate, channel_status); |
| 927 | } |
| 928 | |
| 929 | memcpy(iec958.status, channel_status,sizeof(iec958.status)); |
| 930 | ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name); |
| 931 | if (!ctl) { |
| 932 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 933 | __func__, mixer_ctl_name); |
| 934 | return; |
| 935 | } |
| 936 | if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) { |
| 937 | ALOGE("%s: Could not set channel status for ext HDMI ", |
| 938 | __func__); |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | } |
| 943 | #endif |