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