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