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