blob: 5d98ee1531232121893f772dda3e79cbe8e683c1 [file] [log] [blame]
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001/*
Dhananjay Kumar14245982017-01-16 20:21:00 +05302 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07003 * Not a Contribution.
4 *
5 * Copyright (C) 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "audio_hw_utils"
21/* #define LOG_NDEBUG 0 */
22
23#include <errno.h>
24#include <cutils/properties.h>
25#include <cutils/config_utils.h>
26#include <stdlib.h>
27#include <dlfcn.h>
28#include <cutils/str_parms.h>
29#include <cutils/log.h>
30#include <cutils/misc.h>
31
32#include "audio_hw.h"
33#include "platform.h"
34#include "platform_api.h"
35#include "audio_extn.h"
Narsinga Rao Chella212e2542014-11-17 19:57:04 -080036#include "voice.h"
Dhananjay Kumaree4d2002016-10-25 18:02:58 +053037#include "sound/compress_params.h"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070038
Ashish Jain81eb2a82015-05-13 10:52:34 +053039#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
40#ifdef HDMI_PASSTHROUGH_ENABLED
41#include "audio_parsers.h"
42#endif
43#endif
44
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053045#ifdef LINUX_ENABLED
46#define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/etc/audio_output_policy.conf"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053047#define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/etc/audio_io_policy.conf"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053048#else
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070049#define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053050#define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_io_policy.conf"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053051#endif
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070052
53#define OUTPUTS_TAG "outputs"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053054#define INPUTS_TAG "inputs"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070055
56#define DYNAMIC_VALUE_TAG "dynamic"
57#define FLAGS_TAG "flags"
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +053058#define PROFILES_TAG "profile"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070059#define FORMATS_TAG "formats"
60#define SAMPLING_RATES_TAG "sampling_rates"
61#define BIT_WIDTH_TAG "bit_width"
62#define APP_TYPE_TAG "app_type"
63
64#define STRING_TO_ENUM(string) { #string, string }
65#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
66
Ben Rombergera04fabc2014-11-14 12:16:03 -080067#define BASE_TABLE_SIZE 64
68#define MAX_BASEINDEX_LEN 256
69
Ashish Jain81eb2a82015-05-13 10:52:34 +053070#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
71#define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */
72#define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */
73#define SR_44100 (0<<0) /* 44.1kHz */
74#define SR_NOTID (1<<0) /* non indicated */
75#define SR_48000 (2<<0) /* 48kHz */
76#define SR_32000 (3<<0) /* 32kHz */
77#define SR_22050 (4<<0) /* 22.05kHz */
78#define SR_24000 (6<<0) /* 24kHz */
79#define SR_88200 (8<<0) /* 88.2kHz */
80#define SR_96000 (10<<0) /* 96kHz */
81#define SR_176400 (12<<0) /* 176.4kHz */
82#define SR_192000 (14<<0) /* 192kHz */
83
84#endif
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070085struct string_to_enum {
86 const char *name;
87 uint32_t value;
88};
89
90const struct string_to_enum s_flag_name_to_enum_table[] = {
91 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
92 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
93 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST),
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -080094 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070095 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
96 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
97 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070098 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070099#ifdef INCALL_MUSIC_ENABLED
100 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC),
101#endif
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700102 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH),
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530103 STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE),
104 STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST),
105 STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
106 STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW),
107 STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC),
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530108 STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700109};
110
111const struct string_to_enum s_format_name_to_enum_table[] = {
Ashish Jain83a6cc22016-06-28 14:34:17 +0530112 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700113 STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT),
Ashish Jain5106d362016-05-11 19:23:33 +0530114 STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
115 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
Ashish Jainf1eaa582016-05-23 20:54:24 +0530116 STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700117 STRING_TO_ENUM(AUDIO_FORMAT_MP3),
118 STRING_TO_ENUM(AUDIO_FORMAT_AAC),
119 STRING_TO_ENUM(AUDIO_FORMAT_VORBIS),
Mingming Yinae3530f2014-07-03 16:50:18 -0700120 STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB),
121 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700122 STRING_TO_ENUM(AUDIO_FORMAT_AC3),
Mingming Yinae3530f2014-07-03 16:50:18 -0700123 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700124 STRING_TO_ENUM(AUDIO_FORMAT_DTS),
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530125 STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD),
126#ifdef AUDIO_EXTN_FORMATS_ENABLED
127 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700128 STRING_TO_ENUM(AUDIO_FORMAT_WMA),
129 STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO),
130 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700131 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS),
132 STRING_TO_ENUM(AUDIO_FORMAT_EVRC),
133 STRING_TO_ENUM(AUDIO_FORMAT_EVRCB),
134 STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB),
135 STRING_TO_ENUM(AUDIO_FORMAT_QCELP),
136 STRING_TO_ENUM(AUDIO_FORMAT_MP2),
137 STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW),
Amit Shekhar6f461b12014-08-01 14:52:58 -0700138 STRING_TO_ENUM(AUDIO_FORMAT_FLAC),
Satya Krishna Pindiproli70471602015-04-24 19:12:43 +0530139 STRING_TO_ENUM(AUDIO_FORMAT_ALAC),
140 STRING_TO_ENUM(AUDIO_FORMAT_APE),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700141 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Alexy Josephcd8eaed2014-12-11 12:46:53 -0800142 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC),
143 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1),
144 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2),
Manish Dewangana6fc5442015-08-24 20:30:31 +0530145 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS),
Ashish Jaine513a872015-11-19 17:00:56 +0530146 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC),
147 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1),
148 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2),
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530149 STRING_TO_ENUM(AUDIO_FORMAT_DSD),
Arun Kumar Dasari3b174182016-12-27 13:01:14 +0530150 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM),
151 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC),
152 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1),
153 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2),
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +0530154 STRING_TO_ENUM(AUDIO_FORMAT_APTX),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700155#endif
156};
157
Manish Dewangan3ccdea52017-02-13 19:31:54 +0530158/* payload structure avt_device drift query */
159struct audio_avt_device_drift_stats {
160 uint32_t minor_version;
161 /* Indicates the device interface direction as either
162 * source (Tx) or sink (Rx).
163 */
164 uint16_t device_direction;
165 /*params exposed to client */
166 struct audio_avt_device_drift_param drift_param;
167};
168
Ben Rombergera04fabc2014-11-14 12:16:03 -0800169static char bTable[BASE_TABLE_SIZE] = {
170 'A','B','C','D','E','F','G','H','I','J','K','L',
171 'M','N','O','P','Q','R','S','T','U','V','W','X',
172 'Y','Z','a','b','c','d','e','f','g','h','i','j',
173 'k','l','m','n','o','p','q','r','s','t','u','v',
174 'w','x','y','z','0','1','2','3','4','5','6','7',
175 '8','9','+','/'
176};
177
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700178static uint32_t string_to_enum(const struct string_to_enum *table, size_t size,
179 const char *name)
180{
181 size_t i;
182 for (i = 0; i < size; i++) {
183 if (strcmp(table[i].name, name) == 0) {
184 ALOGV("%s found %s", __func__, table[i].name);
185 return table[i].value;
186 }
187 }
188 return 0;
189}
190
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530191static audio_io_flags_t parse_flag_names(char *name)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700192{
193 uint32_t flag = 0;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530194 audio_io_flags_t io_flags;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800195 char *last_r;
196 char *flag_name = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700197 while (flag_name != NULL) {
198 if (strlen(flag_name) != 0) {
199 flag |= string_to_enum(s_flag_name_to_enum_table,
200 ARRAY_SIZE(s_flag_name_to_enum_table),
201 flag_name);
202 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800203 flag_name = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700204 }
205
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800206 ALOGV("parse_flag_names: flag - %x", flag);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530207 io_flags.in_flags = (audio_input_flags_t)flag;
208 io_flags.out_flags = (audio_output_flags_t)flag;
209 return io_flags;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700210}
211
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530212static void parse_format_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700213{
214 struct stream_format *sf_info = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800215 char *last_r;
216 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700217
218 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0)
219 return;
220
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530221 list_init(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700222 while (str != NULL) {
223 audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table,
224 ARRAY_SIZE(s_format_name_to_enum_table), str);
225 ALOGV("%s: format - %d", __func__, format);
226 if (format != 0) {
227 sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700228 if (sf_info == NULL)
229 break; /* return whatever was parsed */
230
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700231 sf_info->format = format;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530232 list_add_tail(&s_info->format_list, &sf_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700233 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800234 str = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700235 }
236}
237
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530238static void parse_sample_rate_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700239{
Amit Shekhar6f461b12014-08-01 14:52:58 -0700240 struct stream_sample_rate *ss_info = NULL;
241 uint32_t sample_rate = 48000;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800242 char *last_r;
243 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700244
Amit Shekhar6f461b12014-08-01 14:52:58 -0700245 if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG))
246 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700247
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530248 list_init(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700249 while (str != NULL) {
250 sample_rate = (uint32_t)strtol(str, (char **)NULL, 10);
251 ALOGV("%s: sample_rate - %d", __func__, sample_rate);
252 if (0 != sample_rate) {
253 ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate));
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800254 if (!ss_info) {
255 ALOGE("%s: memory allocation failure", __func__);
256 return;
257 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700258 ss_info->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530259 list_add_tail(&s_info->sample_rate_list, &ss_info->list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700260 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800261 str = strtok_r(NULL, "|", &last_r);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700262 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700263}
264
265static int parse_bit_width_names(char *name)
266{
267 int bit_width = 16;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800268 char *last_r;
269 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700270
271 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
272 bit_width = (int)strtol(str, (char **)NULL, 10);
273
274 ALOGV("%s: bit_width - %d", __func__, bit_width);
275 return bit_width;
276}
277
278static int parse_app_type_names(void *platform, char *name)
279{
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700280 int app_type = platform_get_default_app_type(platform);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800281 char *last_r;
282 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700283
284 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
285 app_type = (int)strtol(str, (char **)NULL, 10);
286
287 ALOGV("%s: app_type - %d", __func__, app_type);
288 return app_type;
289}
290
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530291static void update_streams_cfg_list(cnode *root, void *platform,
292 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700293{
294 cnode *node = root->first_child;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530295 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700296
297 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530298 s_info = (struct streams_io_cfg *)calloc(1, sizeof(struct streams_io_cfg));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700299
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530300 if (!s_info) {
301 ALOGE("failed to allocate mem for s_info list element");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700302 return;
303 }
304
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700305 while (node) {
306 if (strcmp(node->name, FLAGS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530307 s_info->flags = parse_flag_names((char *)node->value);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530308 } else if (strcmp(node->name, PROFILES_TAG) == 0) {
309 strlcpy(s_info->profile, (char *)node->value, sizeof(s_info->profile));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700310 } else if (strcmp(node->name, FORMATS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530311 parse_format_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700312 } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530313 s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
314 parse_sample_rate_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700315 } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530316 s_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700317 } else if (strcmp(node->name, APP_TYPE_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530318 s_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700319 }
320 node = node->next;
321 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530322 list_add_tail(streams_cfg_list, &s_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700323}
324
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530325static void load_cfg_list(cnode *root, void *platform,
326 struct listnode *streams_output_cfg_list,
327 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700328{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530329 cnode *node = NULL;
330
331 node = config_find(root, OUTPUTS_TAG);
332 if (node != NULL) {
333 node = node->first_child;
334 while (node) {
335 ALOGV("%s: loading output %s", __func__, node->name);
336 update_streams_cfg_list(node, platform, streams_output_cfg_list);
337 node = node->next;
338 }
339 } else {
340 ALOGI("%s: could not load output, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700341 }
342
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530343 node = config_find(root, INPUTS_TAG);
344 if (node != NULL) {
345 node = node->first_child;
346 while (node) {
347 ALOGV("%s: loading input %s", __func__, node->name);
348 update_streams_cfg_list(node, platform, streams_input_cfg_list);
349 node = node->next;
350 }
351 } else {
352 ALOGI("%s: could not load input, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700353 }
354}
355
356static void send_app_type_cfg(void *platform, struct mixer *mixer,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530357 struct listnode *streams_output_cfg_list,
358 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700359{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530360 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700361 int length = 0, i, num_app_types = 0;
362 struct listnode *node;
363 bool update;
364 struct mixer_ctl *ctl = NULL;
365 const char *mixer_ctl_name = "App Type Config";
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530366 struct streams_io_cfg *s_info = NULL;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700367
368 if (!mixer) {
369 ALOGE("%s: mixer is null",__func__);
370 return;
371 }
372 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
373 if (!ctl) {
374 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
375 return;
376 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530377 app_type_cfg[length++] = num_app_types;
378
379 if (list_empty(streams_output_cfg_list)) {
380 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_PLAYBACK);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700381 app_type_cfg[length++] = 48000;
382 app_type_cfg[length++] = 16;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530383 num_app_types += 1;
384 }
385 if (list_empty(streams_input_cfg_list)) {
386 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
387 app_type_cfg[length++] = 48000;
388 app_type_cfg[length++] = 16;
389 num_app_types += 1;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700390 }
391
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700392 list_for_each(node, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530393 s_info = node_to_item(node, struct streams_io_cfg, list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700394 update = true;
395 for (i=0; i<length; i=i+3) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530396 if (app_type_cfg[i+1] == 0)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700397 break;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530398 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530399 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530400 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530401 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530402 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700403 update = false;
404 break;
405 }
406 }
407 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530408 num_app_types += 1;
409 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
410 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
411 app_type_cfg[length++] = s_info->app_type_cfg.bit_width;
412 }
413 }
414 list_for_each(node, streams_input_cfg_list) {
415 s_info = node_to_item(node, struct streams_io_cfg, list);
416 update = true;
417 for (i=0; i<length; i=i+3) {
418 if (app_type_cfg[i+1] == 0)
419 break;
420 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530421 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530422 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530423 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530424 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
425 update = false;
426 break;
427 }
428 }
429 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
430 num_app_types += 1;
431 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
432 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
433 app_type_cfg[length++] = s_info->app_type_cfg.bit_width;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700434 }
435 }
436 ALOGV("%s: num_app_types: %d", __func__, num_app_types);
437 if (num_app_types) {
438 app_type_cfg[0] = num_app_types;
439 mixer_ctl_set_array(ctl, app_type_cfg, length);
440 }
441}
442
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530443void audio_extn_utils_update_streams_cfg_lists(void *platform,
444 struct mixer *mixer,
445 struct listnode *streams_output_cfg_list,
446 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700447{
448 cnode *root;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530449 char *data = NULL;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700450
451 ALOGV("%s", __func__);
452 list_init(streams_output_cfg_list);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530453 list_init(streams_input_cfg_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700454
455 root = config_node("", "");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700456 if (root == NULL) {
457 ALOGE("cfg_list, NULL config root");
458 return;
459 }
460
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530461 data = (char *)load_file(AUDIO_IO_POLICY_VENDOR_CONFIG_FILE, NULL);
462 if (data == NULL) {
463 ALOGD("%s: failed to open io config file(%s), trying older config file",
464 __func__, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE);
465 data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL);
466 if (data == NULL) {
467 send_app_type_cfg(platform, mixer,
468 streams_output_cfg_list,
469 streams_input_cfg_list);
470 ALOGE("%s: could not load io policy config!", __func__);
471 return;
472 }
473 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700474
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530475 config_load(root, data);
476 load_cfg_list(root, platform, streams_output_cfg_list,
477 streams_input_cfg_list);
478
479 send_app_type_cfg(platform, mixer, streams_output_cfg_list,
480 streams_input_cfg_list);
Alexy Josephaee4fdd2016-01-29 13:02:07 -0800481
482 config_free(root);
483 free(data);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700484}
485
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530486static void audio_extn_utils_dump_streams_cfg_list(
487 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700488{
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700489 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530490 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700491 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700492 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530493
494 list_for_each(node_i, streams_cfg_list) {
495 s_info = node_to_item(node_i, struct streams_io_cfg, list);
496 ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d",
497 __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate,
498 s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type);
499 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700500 sf_info = node_to_item(node_j, struct stream_format, list);
501 ALOGV("format-%x", sf_info->format);
502 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530503 list_for_each(node_j, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700504 ss_info = node_to_item(node_j, struct stream_sample_rate, list);
505 ALOGV("sample rate-%d", ss_info->sample_rate);
506 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700507 }
508}
509
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530510void audio_extn_utils_dump_streams_cfg_lists(
511 struct listnode *streams_output_cfg_list,
512 struct listnode *streams_input_cfg_list)
513{
514 ALOGV("%s", __func__);
515 audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list);
516 audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list);
517}
518
519static void audio_extn_utils_release_streams_cfg_list(
520 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700521{
522 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530523 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700524
525 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530526
527 while (!list_empty(streams_cfg_list)) {
528 node_i = list_head(streams_cfg_list);
529 s_info = node_to_item(node_i, struct streams_io_cfg, list);
530 while (!list_empty(&s_info->format_list)) {
531 node_j = list_head(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700532 list_remove(node_j);
533 free(node_to_item(node_j, struct stream_format, list));
534 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530535 while (!list_empty(&s_info->sample_rate_list)) {
536 node_j = list_head(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700537 list_remove(node_j);
538 free(node_to_item(node_j, struct stream_sample_rate, list));
539 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700540 list_remove(node_i);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530541 free(node_to_item(node_i, struct streams_io_cfg, list));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700542 }
543}
544
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530545void audio_extn_utils_release_streams_cfg_lists(
546 struct listnode *streams_output_cfg_list,
547 struct listnode *streams_input_cfg_list)
548{
549 ALOGV("%s", __func__);
550 audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list);
551 audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list);
552}
553
554static bool set_app_type_cfg(struct streams_io_cfg *s_info,
555 struct stream_app_type_cfg *app_type_cfg,
556 uint32_t sample_rate, uint32_t bit_width)
Amit Shekhar6f461b12014-08-01 14:52:58 -0700557 {
558 struct listnode *node_i;
559 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530560 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700561 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
562 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530563 (bit_width == s_info->app_type_cfg.bit_width)) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700564
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530565 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700566 app_type_cfg->sample_rate = ss_info->sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530567 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700568 ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
569 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
570 return true;
571 }
572 }
573 /*
574 * Reiterate through the list assuming dafault sample rate.
575 * Handles scenario where input sample rate is higher
576 * than all sample rates in list for the input bit width.
577 */
578 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800579
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530580 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700581 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
582 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530583 (bit_width == s_info->app_type_cfg.bit_width)) {
584 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700585 app_type_cfg->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530586 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800587 ALOGV("%s Assuming sample rate. app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
Amit Shekhar6f461b12014-08-01 14:52:58 -0700588 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
589 return true;
590 }
591 }
592 return false;
593}
594
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530595void audio_extn_utils_update_stream_input_app_type_cfg(void *platform,
596 struct listnode *streams_input_cfg_list,
597 audio_devices_t devices __unused,
598 audio_input_flags_t flags,
599 audio_format_t format,
600 uint32_t sample_rate,
601 uint32_t bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530602 char* profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530603 struct stream_app_type_cfg *app_type_cfg)
604{
605 struct listnode *node_i, *node_j;
606 struct streams_io_cfg *s_info;
607 struct stream_format *sf_info;
608
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530609 ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s",
610 __func__, flags, format, sample_rate, profile);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530611
612 list_for_each(node_i, streams_input_cfg_list) {
613 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530614 /* Along with flags do profile matching if set at either end.*/
615 if (s_info->flags.in_flags == flags &&
616 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
617 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530618 list_for_each(node_j, &s_info->format_list) {
619 sf_info = node_to_item(node_j, struct stream_format, list);
620 if (sf_info->format == format) {
621 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
622 return;
623 }
624 }
625 }
626 }
627 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
628 app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
629 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
630 app_type_cfg->bit_width = 16;
631}
632
633void audio_extn_utils_update_stream_output_app_type_cfg(void *platform,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700634 struct listnode *streams_output_cfg_list,
Amit Shekhar1d896042014-10-03 13:16:09 -0700635 audio_devices_t devices,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700636 audio_output_flags_t flags,
637 audio_format_t format,
Amit Shekhar6f461b12014-08-01 14:52:58 -0700638 uint32_t sample_rate,
639 uint32_t bit_width,
Manish Dewangan837dc462015-05-27 10:17:41 +0530640 audio_channel_mask_t channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530641 char *profile,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700642 struct stream_app_type_cfg *app_type_cfg)
643{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530644 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530645 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700646 struct stream_format *sf_info;
Manish Dewangan837dc462015-05-27 10:17:41 +0530647 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700648
Ashish Jain058165c2016-09-28 23:18:48 +0530649 if ((bit_width >= 24) &&
Amit Shekhar1d896042014-10-03 13:16:09 -0700650 (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Amit Shekhar5a39c912014-10-14 15:39:30 -0700651 int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
652 if (-ENOSYS != bw)
653 bit_width = (uint32_t)bw;
Amit Shekhar1d896042014-10-03 13:16:09 -0700654 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
655 ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
656 }
657
Manish Dewangan837dc462015-05-27 10:17:41 +0530658 property_get("audio.playback.mch.downsample",value,"");
659 if (!strncmp("true", value, sizeof("true"))) {
660 if ((popcount(channel_mask) > 2) &&
661 (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
662 !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
663 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
664 ALOGD("%s: MCH session defaulting sample rate to %d",
665 __func__, sample_rate);
666 }
667 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530668
669 /* Set sampling rate to 176.4 for DSD64
670 * and 352.8Khz for DSD128.
671 * Set Bit Width to 16. output will be 16 bit
672 * post DoP in ASM.
673 */
674 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) &&
675 (format == AUDIO_FORMAT_DSD)) {
676 bit_width = 16;
677 if (sample_rate == INPUT_SAMPLING_RATE_DSD64)
678 sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
679 else if (sample_rate == INPUT_SAMPLING_RATE_DSD128)
680 sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
681 }
682
Naresh Tanniruf5ba8d02016-09-29 18:06:37 +0530683 if(devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
684 //TODO: Handle fractional sampling rate configuration for LL
685 audio_extn_a2dp_get_apptype_params(&sample_rate, &bit_width);
686 ALOGI("%s using %d sampling rate %d bit width for A2DP CoPP",
687 __func__, sample_rate, bit_width);
688 }
689
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800690 ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d",
691 __func__, flags, format, sample_rate, profile, app_type_cfg->app_type);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700692 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530693 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530694 /* Along with flags do profile matching if set at either end.*/
695 if (s_info->flags.out_flags == flags &&
696 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
697 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530698 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700699 sf_info = node_to_item(node_j, struct stream_format, list);
700 if (sf_info->format == format) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530701 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
Amit Shekhar6f461b12014-08-01 14:52:58 -0700702 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700703 }
704 }
705 }
706 }
707 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530708 s_info = node_to_item(node_i, struct streams_io_cfg, list);
709 if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700710 ALOGV("Compatible output profile not found.");
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530711 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
712 app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate;
713 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700714 ALOGV("%s Default to primary output: App type: %d sample_rate %d",
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530715 __func__, s_info->app_type_cfg.app_type, app_type_cfg->sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700716 return;
717 }
718 }
719 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700720 app_type_cfg->app_type = platform_get_default_app_type(platform);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700721 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700722 app_type_cfg->bit_width = 16;
723}
724
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530725static bool audio_is_this_native_usecase(struct audio_usecase *uc)
726{
727 bool native_usecase = false;
728 struct stream_out *out = (struct stream_out*) uc->stream.out;
729
730 if (PCM_PLAYBACK == uc->type && out != NULL &&
731 NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() &&
732 is_offload_usecase(uc->id) &&
733 (out->sample_rate == OUTPUT_SAMPLING_RATE_44100))
734 native_usecase = true;
735
736 return native_usecase;
737}
738
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800739
740static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev))
741{
742 return adev->vr_audio_mode_enabled;
743}
744
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530745void audio_extn_utils_update_stream_app_type_cfg_for_usecase(
746 struct audio_device *adev,
747 struct audio_usecase *usecase)
748{
749 ALOGV("%s", __func__);
750
751 switch(usecase->type) {
752 case PCM_PLAYBACK:
753 audio_extn_utils_update_stream_output_app_type_cfg(adev->platform,
754 &adev->streams_output_cfg_list,
755 usecase->stream.out->devices,
756 usecase->stream.out->flags,
757 usecase->stream.out->format,
758 usecase->stream.out->sample_rate,
759 usecase->stream.out->bit_width,
760 usecase->stream.out->channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530761 usecase->stream.out->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530762 &usecase->stream.out->app_type_cfg);
763 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
764 break;
765 case PCM_CAPTURE:
766 audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
767 &adev->streams_input_cfg_list,
768 usecase->stream.in->device,
769 usecase->stream.in->flags,
770 usecase->stream.in->format,
771 usecase->stream.in->sample_rate,
772 usecase->stream.in->bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530773 usecase->stream.in->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530774 &usecase->stream.in->app_type_cfg);
775 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type);
776 break;
777 default:
778 ALOGE("%s: app type cfg not supported for usecase type (%d)",
779 __func__, usecase->type);
780 }
781}
782
Siena Richard7c2db772016-12-21 11:32:34 -0800783static int send_app_type_cfg_for_device(struct audio_device *adev,
784 struct audio_usecase *usecase,
785 int split_snd_device)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700786{
787 char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT];
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530788 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
789 int len = 0, rc;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700790 struct mixer_ctl *ctl;
Siena Richard7c2db772016-12-21 11:32:34 -0800791 int pcm_device_id = 0, acdb_dev_id, app_type;
792 int snd_device = split_snd_device, snd_device_be_idx = -1;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530793 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Manish Dewangan837dc462015-05-27 10:17:41 +0530794 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700795
Siena Richard7c2db772016-12-21 11:32:34 -0800796 ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s",
797 __func__, platform_get_snd_device_name(usecase->out_snd_device),
798 platform_get_snd_device_name(usecase->in_snd_device),
799 platform_get_snd_device_name(split_snd_device));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700800
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530801 if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530802 ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700803 rc = 0;
804 goto exit_send_app_type_cfg;
805 }
806 if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) &&
807 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
808 (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800809 (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530810 (!is_offload_usecase(usecase->id)) &&
811 (usecase->type != PCM_CAPTURE)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530812 ALOGV("%s: a rx/tx/loopback path where app type cfg is not required %d", __func__, usecase->id);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700813 rc = 0;
814 goto exit_send_app_type_cfg;
815 }
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800816
817 //if VR is active then only send the mixer control
818 if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) {
819 ALOGI("ULL doesnt need sending app type cfg, returning");
820 rc = 0;
821 goto exit_send_app_type_cfg;
822 }
823
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530824 if (usecase->type == PCM_PLAYBACK) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700825 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530826 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
827 "Audio Stream %d App Type Cfg", pcm_device_id);
Ben Romberger1fafdde2015-09-09 19:43:15 -0700828 } else if (usecase->type == PCM_CAPTURE) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700829 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530830 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
831 "Audio Stream Capture %d App Type Cfg", pcm_device_id);
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530832 }
Siena Richard7c2db772016-12-21 11:32:34 -0800833
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700834 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
835 if (!ctl) {
836 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__,
837 mixer_ctl_name);
838 rc = -EINVAL;
839 goto exit_send_app_type_cfg;
840 }
841 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +0800842 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530843
Rohit Kumar1181b292017-01-31 18:07:17 +0530844 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
845 if (acdb_dev_id <= 0) {
846 ALOGE("%s: Couldn't get the acdb dev id", __func__);
847 rc = -EINVAL;
848 goto exit_send_app_type_cfg;
849 }
850
Siena Richard7c2db772016-12-21 11:32:34 -0800851 snd_device_be_idx = platform_get_snd_device_backend_index(snd_device);
852 if (snd_device_be_idx < 0) {
853 ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d",
854 __func__, platform_get_snd_device_name(snd_device),
855 snd_device_be_idx);
856 }
857
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530858 if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) {
Manish Dewangan837dc462015-05-27 10:17:41 +0530859
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530860 property_get("audio.playback.mch.downsample",value,"");
861 if (!strncmp("true", value, sizeof("true"))) {
862 if ((popcount(usecase->stream.out->channel_mask) > 2) &&
863 (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
864 !(usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
865 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
866 }
Ashish Jainc02430d2016-01-04 10:42:43 +0530867
Ashish Jain4826f6c2017-02-06 13:33:20 +0530868 if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin21854652016-04-13 11:54:02 -0700869 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Ashish Jaina052e572016-11-07 16:41:07 +0530870 } else if ((snd_device == SND_DEVICE_OUT_HDMI ||
871 snd_device == SND_DEVICE_OUT_USB_HEADSET ||
872 snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
873 (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) {
874 /*
875 * To best utlize DSP, check if the stream sample rate is supported/multiple of
876 * configured device sample rate, if not update the COPP rate to be equal to the
877 * device sample rate, else open COPP at stream sample rate
878 */
879 platform_check_and_update_copp_sample_rate(adev->platform, snd_device,
880 usecase->stream.out->sample_rate,
881 &usecase->stream.out->app_type_cfg.sample_rate);
Ashish Jain4826f6c2017-02-06 13:33:20 +0530882 } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
883 !audio_is_this_native_usecase(usecase)) &&
Mingming Yin21854652016-04-13 11:54:02 -0700884 usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
885 (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
Ashish Jain4826f6c2017-02-06 13:33:20 +0530886 /* Reset to default if no native stream is active*/
Mingming Yin21854652016-04-13 11:54:02 -0700887 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
888 }
889 sample_rate = usecase->stream.out->app_type_cfg.sample_rate;
890
Siena Richard7c2db772016-12-21 11:32:34 -0800891 app_type = usecase->stream.out->app_type_cfg.app_type;
892 app_type_cfg[len++] = app_type;
Mingming Yin21854652016-04-13 11:54:02 -0700893 app_type_cfg[len++] = acdb_dev_id;
894 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
895 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530896 && audio_extn_passthru_is_passthrough_stream(usecase->stream.out)) {
Mingming Yin21854652016-04-13 11:54:02 -0700897 app_type_cfg[len++] = sample_rate * 4;
898 } else {
899 app_type_cfg[len++] = sample_rate;
900 }
Siena Richard7c2db772016-12-21 11:32:34 -0800901 if (snd_device_be_idx > 0)
902 app_type_cfg[len++] = snd_device_be_idx;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530903
Siena Richard7c2db772016-12-21 11:32:34 -0800904 ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
905 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530906
907 } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) {
Siena Richard7c2db772016-12-21 11:32:34 -0800908 app_type = usecase->stream.in->app_type_cfg.app_type;
909 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530910 app_type_cfg[len++] = acdb_dev_id;
Siena Richard7c2db772016-12-21 11:32:34 -0800911 sample_rate = usecase->stream.in->app_type_cfg.sample_rate;
912 app_type_cfg[len++] = sample_rate;
913 if (snd_device_be_idx > 0)
914 app_type_cfg[len++] = snd_device_be_idx;
915 ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
916 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530917 } else {
Siena Richard7c2db772016-12-21 11:32:34 -0800918 app_type = platform_get_default_app_type_v2(adev->platform, usecase->type);
919 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530920 app_type_cfg[len++] = acdb_dev_id;
921 app_type_cfg[len++] = sample_rate;
Siena Richard7c2db772016-12-21 11:32:34 -0800922 if (snd_device_be_idx > 0)
923 app_type_cfg[len++] = snd_device_be_idx;
924 ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
925 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Ashish Jainc02430d2016-01-04 10:42:43 +0530926 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530927
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700928 mixer_ctl_set_array(ctl, app_type_cfg, len);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700929 rc = 0;
930exit_send_app_type_cfg:
931 return rc;
932}
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700933
Siena Richard7c2db772016-12-21 11:32:34 -0800934int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
935 struct audio_usecase *usecase)
936{
937 int i, num_devices = 0;
938 snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0};
939 int rc = 0;
940
941 switch (usecase->type) {
942 case PCM_PLAYBACK:
943 ALOGD("%s: usecase->out_snd_device %s",
944 __func__, platform_get_snd_device_name(usecase->out_snd_device));
945 /* check for out combo device */
946 if (platform_split_snd_device(adev->platform,
947 usecase->out_snd_device,
948 &num_devices, new_snd_devices)) {
949 new_snd_devices[0] = usecase->out_snd_device;
950 num_devices = 1;
951 }
952 break;
953 case PCM_CAPTURE:
954 ALOGD("%s: usecase->in_snd_device %s",
955 __func__, platform_get_snd_device_name(usecase->in_snd_device));
956 /* check for in combo device */
957 if (platform_split_snd_device(adev->platform,
958 usecase->in_snd_device,
959 &num_devices, new_snd_devices)) {
960 new_snd_devices[0] = usecase->in_snd_device;
961 num_devices = 1;
962 }
963 break;
964 default:
965 ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__);
966 rc = 0;
967 break;
968 }
969
970 for (i = 0; i < num_devices; i++) {
971 rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]);
972 if (rc)
973 break;
974 }
975
976 return rc;
977}
978
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530979int read_line_from_file(const char *path, char *buf, size_t count)
980{
981 char * fgets_ret;
982 FILE * fd;
983 int rv;
984
985 fd = fopen(path, "r");
986 if (fd == NULL)
987 return -1;
988
989 fgets_ret = fgets(buf, (int)count, fd);
990 if (NULL != fgets_ret) {
991 rv = (int)strlen(buf);
992 } else {
993 rv = ferror(fd);
994 }
995 fclose(fd);
996
997 return rv;
998}
999
Ashish Jainf1eaa582016-05-23 20:54:24 +05301000/*Translates ALSA formats to AOSP PCM formats*/
1001audio_format_t alsa_format_to_hal(uint32_t alsa_format)
1002{
1003 audio_format_t format;
1004
1005 switch(alsa_format) {
1006 case SNDRV_PCM_FORMAT_S16_LE:
1007 format = AUDIO_FORMAT_PCM_16_BIT;
1008 break;
1009 case SNDRV_PCM_FORMAT_S24_3LE:
1010 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1011 break;
1012 case SNDRV_PCM_FORMAT_S24_LE:
1013 format = AUDIO_FORMAT_PCM_8_24_BIT;
1014 break;
1015 case SNDRV_PCM_FORMAT_S32_LE:
1016 format = AUDIO_FORMAT_PCM_32_BIT;
1017 break;
1018 default:
1019 ALOGW("Incorrect ALSA format");
1020 format = AUDIO_FORMAT_INVALID;
1021 }
1022 return format;
1023}
1024
1025/*Translates hal format (AOSP) to alsa formats*/
1026uint32_t hal_format_to_alsa(audio_format_t hal_format)
1027{
1028 uint32_t alsa_format;
1029
1030 switch (hal_format) {
1031 case AUDIO_FORMAT_PCM_32_BIT: {
1032 if (platform_supports_true_32bit())
1033 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1034 else
1035 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1036 }
1037 break;
1038 case AUDIO_FORMAT_PCM_8_BIT:
1039 alsa_format = SNDRV_PCM_FORMAT_S8;
1040 break;
1041 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1042 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1043 break;
1044 case AUDIO_FORMAT_PCM_8_24_BIT: {
1045 if (platform_supports_true_32bit())
1046 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1047 else
1048 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1049 }
1050 break;
1051 case AUDIO_FORMAT_PCM_FLOAT:
1052 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1053 break;
1054 default:
1055 case AUDIO_FORMAT_PCM_16_BIT:
1056 alsa_format = SNDRV_PCM_FORMAT_S16_LE;
1057 break;
1058 }
1059 return alsa_format;
1060}
1061
Ashish Jain83a6cc22016-06-28 14:34:17 +05301062/*Translates PCM formats to AOSP formats*/
1063audio_format_t pcm_format_to_hal(uint32_t pcm_format)
1064{
1065 audio_format_t format = AUDIO_FORMAT_INVALID;
1066
1067 switch(pcm_format) {
1068 case PCM_FORMAT_S16_LE:
1069 format = AUDIO_FORMAT_PCM_16_BIT;
1070 break;
1071 case PCM_FORMAT_S24_3LE:
1072 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1073 break;
1074 case PCM_FORMAT_S24_LE:
1075 format = AUDIO_FORMAT_PCM_8_24_BIT;
1076 break;
1077 case PCM_FORMAT_S32_LE:
1078 format = AUDIO_FORMAT_PCM_32_BIT;
1079 break;
1080 default:
1081 ALOGW("Incorrect PCM format");
1082 format = AUDIO_FORMAT_INVALID;
1083 }
1084 return format;
1085}
1086
1087/*Translates hal format (AOSP) to alsa formats*/
1088uint32_t hal_format_to_pcm(audio_format_t hal_format)
1089{
1090 uint32_t pcm_format;
1091
1092 switch (hal_format) {
1093 case AUDIO_FORMAT_PCM_32_BIT:
1094 case AUDIO_FORMAT_PCM_8_24_BIT:
1095 case AUDIO_FORMAT_PCM_FLOAT: {
1096 if (platform_supports_true_32bit())
1097 pcm_format = PCM_FORMAT_S32_LE;
1098 else
1099 pcm_format = PCM_FORMAT_S24_3LE;
1100 }
1101 break;
1102 case AUDIO_FORMAT_PCM_8_BIT:
1103 pcm_format = PCM_FORMAT_S8;
1104 break;
1105 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1106 pcm_format = PCM_FORMAT_S24_3LE;
1107 break;
1108 default:
1109 case AUDIO_FORMAT_PCM_16_BIT:
1110 pcm_format = PCM_FORMAT_S16_LE;
1111 break;
1112 }
1113 return pcm_format;
1114}
1115
Ashish Jainf1eaa582016-05-23 20:54:24 +05301116uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
1117 uint32_t sample_rate,
1118 uint32_t noOfChannels)
1119{
1120 uint32_t fragment_size = 0;
1121 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
1122
1123 fragment_size = (pcm_offload_time
1124 * sample_rate
1125 * bytes_per_sample
1126 * noOfChannels)/1000;
1127 if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1128 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1129 else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1130 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1131 /*To have same PCM samples for all channels, the buffer size requires to
1132 *be multiple of (number of channels * bytes per sample)
1133 *For writes to succeed, the buffer must be written at address which is multiple of 32
1134 */
1135 fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32));
1136
1137 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
1138 return fragment_size;
1139}
1140
1141/* Calculates the fragment size required to configure compress session.
1142 * Based on the alsa format selected, decide if conversion is needed in
1143
1144 * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to
1145 * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver.
1146 */
1147void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
1148{
Ashish Jain83a6cc22016-06-28 14:34:17 +05301149 audio_format_t dst_format = out->hal_op_format;
1150 audio_format_t src_format = out->hal_ip_format;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301151 uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format);
1152 uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format);
1153
1154 out->compr_config.fragment_size =
1155 get_alsa_fragment_size(hal_op_bytes_per_sample,
1156 out->sample_rate,
1157 popcount(out->channel_mask));
1158
1159 if ((src_format != dst_format) &&
1160 hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
1161
Ashish Jain83a6cc22016-06-28 14:34:17 +05301162 out->hal_fragment_size =
Ashish Jainf1eaa582016-05-23 20:54:24 +05301163 ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) /
1164 hal_op_bytes_per_sample);
1165 ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x",
Ashish Jain83a6cc22016-06-28 14:34:17 +05301166 out->hal_fragment_size, src_format, dst_format);
Ashish Jainf1eaa582016-05-23 20:54:24 +05301167 } else {
Ashish Jain83a6cc22016-06-28 14:34:17 +05301168 out->hal_fragment_size = out->compr_config.fragment_size;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301169 }
1170}
1171
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301172/* converts pcm format 24_8 to 8_24 inplace */
1173size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes)
1174{
1175 size_t i = 0;
1176 int *int_buf_stream = buf;
1177
1178 if ((bytes % 4) != 0) {
1179 ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__);
1180 return -EINVAL;
1181 }
1182
1183 for (; i < (bytes / 4); i++)
1184 int_buf_stream[i] >>= 8;
1185
1186 return bytes;
1187}
1188
1189int get_snd_codec_id(audio_format_t format)
1190{
1191 int id = 0;
1192
1193 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1194 case AUDIO_FORMAT_MP3:
1195 id = SND_AUDIOCODEC_MP3;
1196 break;
1197 case AUDIO_FORMAT_AAC:
1198 id = SND_AUDIOCODEC_AAC;
1199 break;
1200 case AUDIO_FORMAT_AAC_ADTS:
1201 id = SND_AUDIOCODEC_AAC;
1202 break;
Arun Kumar Dasari3b174182016-12-27 13:01:14 +05301203 case AUDIO_FORMAT_AAC_LATM:
1204 id = SND_AUDIOCODEC_AAC;
1205 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301206 case AUDIO_FORMAT_PCM:
1207 id = SND_AUDIOCODEC_PCM;
1208 break;
1209 case AUDIO_FORMAT_FLAC:
1210 id = SND_AUDIOCODEC_FLAC;
1211 break;
1212 case AUDIO_FORMAT_ALAC:
1213 id = SND_AUDIOCODEC_ALAC;
1214 break;
1215 case AUDIO_FORMAT_APE:
1216 id = SND_AUDIOCODEC_APE;
1217 break;
1218 case AUDIO_FORMAT_VORBIS:
1219 id = SND_AUDIOCODEC_VORBIS;
1220 break;
1221 case AUDIO_FORMAT_WMA:
1222 id = SND_AUDIOCODEC_WMA;
1223 break;
1224 case AUDIO_FORMAT_WMA_PRO:
1225 id = SND_AUDIOCODEC_WMA_PRO;
1226 break;
Satish Babu Patakokila0c313922016-12-08 12:07:08 +05301227 case AUDIO_FORMAT_MP2:
1228 id = SND_AUDIOCODEC_MP2;
1229 break;
Satish Babu Patakokila915ecba2017-01-10 17:43:56 +05301230 case AUDIO_FORMAT_AC3:
1231 id = SND_AUDIOCODEC_AC3;
1232 break;
1233 case AUDIO_FORMAT_E_AC3:
1234 case AUDIO_FORMAT_E_AC3_JOC:
1235 id = SND_AUDIOCODEC_EAC3;
1236 break;
1237 case AUDIO_FORMAT_DTS:
1238 case AUDIO_FORMAT_DTS_HD:
1239 id = SND_AUDIOCODEC_DTS;
1240 break;
Preetam Singh Ranawat4277a5a2017-01-18 19:02:24 +05301241 case AUDIO_FORMAT_DSD:
1242 id = SND_AUDIOCODEC_DSD;
1243 break;
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +05301244 case AUDIO_FORMAT_APTX:
1245 id = SND_AUDIOCODEC_APTX;
1246 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301247 default:
1248 ALOGE("%s: Unsupported audio format :%x", __func__, format);
1249 }
1250
1251 return id;
1252}
1253
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001254void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
1255 struct audio_usecase *usecase)
1256{
1257 int type = usecase->type;
1258
Dhananjay Kumar14245982017-01-16 20:21:00 +05301259 if (type == PCM_PLAYBACK && usecase->stream.out != NULL) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001260 struct stream_out *out = usecase->stream.out;
1261 int snd_device = usecase->out_snd_device;
1262 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08001263 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301264 platform_send_audio_calibration(adev->platform, usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001265 out->app_type_cfg.app_type,
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301266 usecase->stream.out->app_type_cfg.sample_rate);
Dhananjay Kumar14245982017-01-16 20:21:00 +05301267 } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301268 platform_send_audio_calibration(adev->platform, usecase,
1269 usecase->stream.in->app_type_cfg.app_type,
1270 usecase->stream.in->app_type_cfg.sample_rate);
Vidyakumar Athota653aaef2017-03-16 11:11:31 -07001271 } else if (type == PCM_HFP_CALL || type == PCM_CAPTURE) {
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301272 /* when app type is default. the sample rate is not used to send cal */
1273 platform_send_audio_calibration(adev->platform, usecase,
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301274 platform_get_default_app_type_v2(adev->platform, usecase->type),
1275 48000);
Vidyakumar Athotae57f6002017-03-01 13:13:16 -08001276 } else {
1277 /* No need to send audio calibration for voice and voip call usecases */
1278 if ((type != VOICE_CALL) && (type != VOIP_CALL))
1279 ALOGW("%s: No audio calibration for usecase type = %d", __func__, type);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001280 }
1281}
1282
Ben Rombergera04fabc2014-11-14 12:16:03 -08001283// Base64 Encode and Decode
1284// Not all features supported. This must be used only with following conditions.
1285// Decode Modes: Support with and without padding
1286// CRLF not handling. So no CRLF in string to decode.
1287// Encode Modes: Supports only padding
1288int b64decode(char *inp, int ilen, uint8_t* outp)
1289{
1290 int i, j, k, ii, num;
1291 int rem, pcnt;
1292 uint32_t res=0;
1293 uint8_t getIndex[MAX_BASEINDEX_LEN];
1294 uint8_t tmp, cflag;
1295
1296 if(inp == NULL || outp == NULL || ilen <= 0) {
1297 ALOGE("[%s] received NULL pointer or zero length",__func__);
1298 return -1;
1299 }
1300
1301 memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex));
1302 for(i=0;i<BASE_TABLE_SIZE;i++) {
1303 getIndex[(uint8_t)bTable[i]] = (uint8_t)i;
1304 }
1305 getIndex[(uint8_t)'=']=0;
1306
1307 j=0;k=0;
1308 num = ilen/4;
1309 rem = ilen%4;
1310 if(rem==0)
1311 num = num-1;
1312 cflag=0;
1313 for(i=0; i<num; i++) {
1314 res=0;
1315 for(ii=0;ii<4;ii++) {
1316 res = res << 6;
1317 tmp = getIndex[(uint8_t)inp[j++]];
1318 res = res | tmp;
1319 cflag = cflag | tmp;
1320 }
1321 outp[k++] = (res >> 16)&0xFF;
1322 outp[k++] = (res >> 8)&0xFF;
1323 outp[k++] = res & 0xFF;
1324 }
1325
1326 // Handle last bytes special
1327 pcnt=0;
1328 if(rem == 0) {
1329 //With padding or full data
1330 res = 0;
1331 for(ii=0;ii<4;ii++) {
1332 if(inp[j] == '=')
1333 pcnt++;
1334 res = res << 6;
1335 tmp = getIndex[(uint8_t)inp[j++]];
1336 res = res | tmp;
1337 cflag = cflag | tmp;
1338 }
1339 outp[k++] = res >> 16;
1340 if(pcnt == 2)
1341 goto done;
1342 outp[k++] = (res>>8)&0xFF;
1343 if(pcnt == 1)
1344 goto done;
1345 outp[k++] = res&0xFF;
1346 } else {
1347 //without padding
1348 res = 0;
1349 for(i=0;i<rem;i++) {
1350 res = res << 6;
1351 tmp = getIndex[(uint8_t)inp[j++]];
1352 res = res | tmp;
1353 cflag = cflag | tmp;
1354 }
1355 for(i=rem;i<4;i++) {
1356 res = res << 6;
1357 pcnt++;
1358 }
1359 outp[k++] = res >> 16;
1360 if(pcnt == 2)
1361 goto done;
1362 outp[k++] = (res>>8)&0xFF;
1363 if(pcnt == 1)
1364 goto done;
1365 outp[k++] = res&0xFF;
1366 }
1367done:
1368 if(cflag == 0xFF) {
1369 ALOGE("[%s] base64 decode failed. Invalid character found %s",
1370 __func__, inp);
1371 return 0;
1372 }
1373 return k;
1374}
1375
1376int b64encode(uint8_t *inp, int ilen, char* outp)
1377{
1378 int i,j,k, num;
1379 int rem=0;
1380 uint32_t res=0;
1381
1382 if(inp == NULL || outp == NULL || ilen<=0) {
1383 ALOGE("[%s] received NULL pointer or zero input length",__func__);
1384 return -1;
1385 }
1386
1387 num = ilen/3;
1388 rem = ilen%3;
1389 j=0;k=0;
1390 for(i=0; i<num; i++) {
1391 //prepare index
1392 res = inp[j++]<<16;
1393 res = res | inp[j++]<<8;
1394 res = res | inp[j++];
1395 //get output map from index
1396 outp[k++] = (char) bTable[(res>>18)&0x3F];
1397 outp[k++] = (char) bTable[(res>>12)&0x3F];
1398 outp[k++] = (char) bTable[(res>>6)&0x3F];
1399 outp[k++] = (char) bTable[res&0x3F];
1400 }
1401
1402 switch(rem) {
1403 case 1:
1404 res = inp[j++]<<16;
1405 outp[k++] = (char) bTable[res>>18];
1406 outp[k++] = (char) bTable[(res>>12)&0x3F];
1407 //outp[k++] = '=';
1408 //outp[k++] = '=';
1409 break;
1410 case 2:
1411 res = inp[j++]<<16;
1412 res = res | inp[j++]<<8;
1413 outp[k++] = (char) bTable[res>>18];
1414 outp[k++] = (char) bTable[(res>>12)&0x3F];
1415 outp[k++] = (char) bTable[(res>>6)&0x3F];
1416 //outp[k++] = '=';
1417 break;
1418 default:
1419 break;
1420 }
Ben Rombergera04fabc2014-11-14 12:16:03 -08001421 outp[k] = '\0';
1422 return k;
1423}
Ashish Jain81eb2a82015-05-13 10:52:34 +05301424
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301425
1426int audio_extn_utils_get_codec_version(const char *snd_card_name,
1427 int card_num,
1428 char *codec_version)
1429{
1430 char procfs_path[50];
1431 FILE *fp;
1432
1433 if (strstr(snd_card_name, "tasha")) {
1434 snprintf(procfs_path, sizeof(procfs_path),
1435 "/proc/asound/card%d/codecs/tasha/version", card_num);
1436 if ((fp = fopen(procfs_path, "r")) != NULL) {
1437 fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp);
1438 fclose(fp);
1439 } else {
1440 ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path);
1441 return -ENOENT;
1442 }
1443 ALOGD("%s: codec version %s", __func__, codec_version);
1444 }
1445
1446 return 0;
1447}
1448
1449
Ashish Jain81eb2a82015-05-13 10:52:34 +05301450#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
1451
1452void get_default_compressed_channel_status(
1453 unsigned char *channel_status)
1454{
Ashish Jain81eb2a82015-05-13 10:52:34 +05301455 memset(channel_status,0,24);
1456
1457 /* block start bit in preamble bit 3 */
1458 channel_status[0] |= PROFESSIONAL;
1459 //compre out
1460 channel_status[0] |= NON_LPCM;
1461 // sample rate; fixed 48K for default/transcode
1462 channel_status[3] |= SR_48000;
1463}
1464
1465#ifdef HDMI_PASSTHROUGH_ENABLED
1466int32_t get_compressed_channel_status(void *audio_stream_data,
1467 uint32_t audio_frame_size,
1468 unsigned char *channel_status,
1469 enum audio_parser_code_type codec_type)
1470 // codec_type - AUDIO_PARSER_CODEC_AC3
1471 // - AUDIO_PARSER_CODEC_DTS
1472{
1473 unsigned char *stream;
1474 int ret = 0;
1475 stream = (unsigned char *)audio_stream_data;
1476
1477 if (audio_stream_data == NULL || audio_frame_size == 0) {
1478 ALOGW("no buffer to get channel status, return default for compress");
1479 get_default_compressed_channel_status(channel_status);
1480 return ret;
1481 }
1482
1483 memset(channel_status,0,24);
1484 if(init_audio_parser(stream, audio_frame_size, codec_type) == -1)
1485 {
1486 ALOGE("init audio parser failed");
1487 return -1;
1488 }
1489 ret = get_channel_status(channel_status, codec_type);
1490 return ret;
1491
1492}
1493
1494#endif
1495
1496void get_lpcm_channel_status(uint32_t sampleRate,
1497 unsigned char *channel_status)
1498{
1499 int32_t status = 0;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301500 memset(channel_status,0,24);
1501 /* block start bit in preamble bit 3 */
1502 channel_status[0] |= PROFESSIONAL;
1503 //LPCM OUT
1504 channel_status[0] &= ~NON_LPCM;
1505
1506 switch (sampleRate) {
1507 case 8000:
1508 case 11025:
1509 case 12000:
1510 case 16000:
1511 case 22050:
1512 channel_status[3] |= SR_NOTID;
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301513 break;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301514 case 24000:
1515 channel_status[3] |= SR_24000;
1516 break;
1517 case 32000:
1518 channel_status[3] |= SR_32000;
1519 break;
1520 case 44100:
1521 channel_status[3] |= SR_44100;
1522 break;
1523 case 48000:
1524 channel_status[3] |= SR_48000;
1525 break;
1526 case 88200:
1527 channel_status[3] |= SR_88200;
1528 break;
1529 case 96000:
1530 channel_status[3] |= SR_96000;
1531 break;
1532 case 176400:
1533 channel_status[3] |= SR_176400;
1534 break;
1535 case 192000:
1536 channel_status[3] |= SR_192000;
1537 break;
1538 default:
1539 ALOGV("Invalid sample_rate %u\n", sampleRate);
1540 status = -1;
1541 break;
1542 }
1543}
1544
1545void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes)
1546{
1547 unsigned char channel_status[24]={0};
1548 struct snd_aes_iec958 iec958;
1549 const char *mixer_ctl_name = "IEC958 Playback PCM Stream";
1550 struct mixer_ctl *ctl;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301551 ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes);
Ashish Jain81eb2a82015-05-13 10:52:34 +05301552#ifdef HDMI_PASSTHROUGH_ENABLED
1553 if (audio_extn_is_dolby_format(out->format) &&
1554 /*TODO:Extend code to support DTS passthrough*/
1555 /*set compressed channel status bits*/
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05301556 audio_extn_passthru_is_passthrough_stream(out)){
Ashish Jain81eb2a82015-05-13 10:52:34 +05301557 get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3);
1558 } else
1559#endif
1560 {
1561 /*set channel status bit for LPCM*/
1562 get_lpcm_channel_status(out->sample_rate, channel_status);
1563 }
1564
1565 memcpy(iec958.status, channel_status,sizeof(iec958.status));
1566 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name);
1567 if (!ctl) {
1568 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1569 __func__, mixer_ctl_name);
1570 return;
1571 }
1572 if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) {
1573 ALOGE("%s: Could not set channel status for ext HDMI ",
1574 __func__);
1575 return;
1576 }
1577
1578}
1579#endif
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301580
1581int audio_extn_utils_get_avt_device_drift(
1582 struct audio_usecase *usecase,
1583 struct audio_avt_device_drift_param *drift_param)
1584{
1585 int ret = 0, count = 0;
1586 char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
1587 struct mixer_ctl *ctl = NULL;
1588 struct audio_avt_device_drift_stats drift_stats;
1589 struct audio_device *adev = NULL;
1590
1591 if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
1592 adev = usecase->stream.out->dev;
1593 switch(usecase->out_snd_device) {
1594 case SND_DEVICE_OUT_HDMI:
1595 strlcpy(avt_device_drift_mixer_ctl_name,
1596 "HDMI RX Drift",
1597 MIXER_PATH_MAX_LENGTH);
1598 break;
1599 case SND_DEVICE_OUT_DISPLAY_PORT:
1600 strlcpy(avt_device_drift_mixer_ctl_name,
1601 "DISPLAY Port RX Drift",
1602 MIXER_PATH_MAX_LENGTH);
1603 break;
1604 default :
1605 ALOGE("%s: Unsupported device %d",__func__,
1606 usecase->stream.out->devices);
1607 ret = -EINVAL;
1608 }
1609 } else {
1610 ALOGE("%s: Invalid usecase %d ",__func__, usecase->type);
1611 ret = -EINVAL;
1612 }
1613
1614 if(ret)
1615 goto done;
1616
1617 ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name);
1618 if (!ctl) {
1619 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1620 __func__, avt_device_drift_mixer_ctl_name);
1621
1622 ret = -EINVAL;
1623 goto done;
1624 }
1625
1626 ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__,
1627 avt_device_drift_mixer_ctl_name);
1628
1629 mixer_ctl_update(ctl);
1630 count = mixer_ctl_get_num_values(ctl);
1631 if (count != sizeof(struct audio_avt_device_drift_stats)) {
1632 ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size",
1633 __func__);
1634
1635 ret = -EINVAL;
1636 goto done;
1637 }
1638
1639 ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count);
1640 if (ret != 0) {
1641 ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params",
1642 __func__);
1643
1644 ret = -EINVAL;
1645 goto done;
1646 }
1647 memcpy(drift_param, &drift_stats.drift_param,
1648 sizeof(struct audio_avt_device_drift_param));
1649done:
1650 return ret;
1651}