blob: ad678810ddedb978ffd2898eb8150e61b00961bb [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__);
yidongh6eb4f752017-04-19 18:20:57 +0800471 free(root);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530472 return;
473 }
474 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700475
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530476 config_load(root, data);
477 load_cfg_list(root, platform, streams_output_cfg_list,
478 streams_input_cfg_list);
479
480 send_app_type_cfg(platform, mixer, streams_output_cfg_list,
481 streams_input_cfg_list);
Alexy Josephaee4fdd2016-01-29 13:02:07 -0800482
483 config_free(root);
yidongh6eb4f752017-04-19 18:20:57 +0800484 free(root);
Alexy Josephaee4fdd2016-01-29 13:02:07 -0800485 free(data);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700486}
487
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530488static void audio_extn_utils_dump_streams_cfg_list(
489 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700490{
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700491 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530492 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700493 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700494 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530495
496 list_for_each(node_i, streams_cfg_list) {
497 s_info = node_to_item(node_i, struct streams_io_cfg, list);
498 ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d",
499 __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate,
500 s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type);
501 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700502 sf_info = node_to_item(node_j, struct stream_format, list);
503 ALOGV("format-%x", sf_info->format);
504 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530505 list_for_each(node_j, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700506 ss_info = node_to_item(node_j, struct stream_sample_rate, list);
507 ALOGV("sample rate-%d", ss_info->sample_rate);
508 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700509 }
510}
511
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530512void audio_extn_utils_dump_streams_cfg_lists(
513 struct listnode *streams_output_cfg_list,
514 struct listnode *streams_input_cfg_list)
515{
516 ALOGV("%s", __func__);
517 audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list);
518 audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list);
519}
520
521static void audio_extn_utils_release_streams_cfg_list(
522 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700523{
524 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530525 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700526
527 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530528
529 while (!list_empty(streams_cfg_list)) {
530 node_i = list_head(streams_cfg_list);
531 s_info = node_to_item(node_i, struct streams_io_cfg, list);
532 while (!list_empty(&s_info->format_list)) {
533 node_j = list_head(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700534 list_remove(node_j);
535 free(node_to_item(node_j, struct stream_format, list));
536 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530537 while (!list_empty(&s_info->sample_rate_list)) {
538 node_j = list_head(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700539 list_remove(node_j);
540 free(node_to_item(node_j, struct stream_sample_rate, list));
541 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700542 list_remove(node_i);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530543 free(node_to_item(node_i, struct streams_io_cfg, list));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700544 }
545}
546
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530547void audio_extn_utils_release_streams_cfg_lists(
548 struct listnode *streams_output_cfg_list,
549 struct listnode *streams_input_cfg_list)
550{
551 ALOGV("%s", __func__);
552 audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list);
553 audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list);
554}
555
556static bool set_app_type_cfg(struct streams_io_cfg *s_info,
557 struct stream_app_type_cfg *app_type_cfg,
558 uint32_t sample_rate, uint32_t bit_width)
Amit Shekhar6f461b12014-08-01 14:52:58 -0700559 {
560 struct listnode *node_i;
561 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530562 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700563 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
564 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530565 (bit_width == s_info->app_type_cfg.bit_width)) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700566
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530567 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700568 app_type_cfg->sample_rate = ss_info->sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530569 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700570 ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
571 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
572 return true;
573 }
574 }
575 /*
576 * Reiterate through the list assuming dafault sample rate.
577 * Handles scenario where input sample rate is higher
578 * than all sample rates in list for the input bit width.
579 */
580 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800581
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530582 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700583 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
584 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530585 (bit_width == s_info->app_type_cfg.bit_width)) {
586 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700587 app_type_cfg->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530588 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800589 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 -0700590 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
591 return true;
592 }
593 }
594 return false;
595}
596
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530597void audio_extn_utils_update_stream_input_app_type_cfg(void *platform,
598 struct listnode *streams_input_cfg_list,
599 audio_devices_t devices __unused,
600 audio_input_flags_t flags,
601 audio_format_t format,
602 uint32_t sample_rate,
603 uint32_t bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530604 char* profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530605 struct stream_app_type_cfg *app_type_cfg)
606{
607 struct listnode *node_i, *node_j;
608 struct streams_io_cfg *s_info;
609 struct stream_format *sf_info;
610
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530611 ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s",
612 __func__, flags, format, sample_rate, profile);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530613
614 list_for_each(node_i, streams_input_cfg_list) {
615 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530616 /* Along with flags do profile matching if set at either end.*/
617 if (s_info->flags.in_flags == flags &&
618 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
619 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530620 list_for_each(node_j, &s_info->format_list) {
621 sf_info = node_to_item(node_j, struct stream_format, list);
622 if (sf_info->format == format) {
623 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
624 return;
625 }
626 }
627 }
628 }
629 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
630 app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
631 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
632 app_type_cfg->bit_width = 16;
633}
634
635void audio_extn_utils_update_stream_output_app_type_cfg(void *platform,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700636 struct listnode *streams_output_cfg_list,
Amit Shekhar1d896042014-10-03 13:16:09 -0700637 audio_devices_t devices,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700638 audio_output_flags_t flags,
639 audio_format_t format,
Amit Shekhar6f461b12014-08-01 14:52:58 -0700640 uint32_t sample_rate,
641 uint32_t bit_width,
Manish Dewangan837dc462015-05-27 10:17:41 +0530642 audio_channel_mask_t channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530643 char *profile,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700644 struct stream_app_type_cfg *app_type_cfg)
645{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530646 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530647 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700648 struct stream_format *sf_info;
Manish Dewangan837dc462015-05-27 10:17:41 +0530649 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700650
Ashish Jain058165c2016-09-28 23:18:48 +0530651 if ((bit_width >= 24) &&
Amit Shekhar1d896042014-10-03 13:16:09 -0700652 (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Amit Shekhar5a39c912014-10-14 15:39:30 -0700653 int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
654 if (-ENOSYS != bw)
655 bit_width = (uint32_t)bw;
Amit Shekhar1d896042014-10-03 13:16:09 -0700656 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
657 ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
658 }
659
Manish Dewangan837dc462015-05-27 10:17:41 +0530660 property_get("audio.playback.mch.downsample",value,"");
661 if (!strncmp("true", value, sizeof("true"))) {
662 if ((popcount(channel_mask) > 2) &&
663 (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
664 !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
665 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
666 ALOGD("%s: MCH session defaulting sample rate to %d",
667 __func__, sample_rate);
668 }
669 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530670
671 /* Set sampling rate to 176.4 for DSD64
672 * and 352.8Khz for DSD128.
673 * Set Bit Width to 16. output will be 16 bit
674 * post DoP in ASM.
675 */
676 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) &&
677 (format == AUDIO_FORMAT_DSD)) {
678 bit_width = 16;
679 if (sample_rate == INPUT_SAMPLING_RATE_DSD64)
680 sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
681 else if (sample_rate == INPUT_SAMPLING_RATE_DSD128)
682 sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
683 }
684
Naresh Tanniruf5ba8d02016-09-29 18:06:37 +0530685 if(devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
686 //TODO: Handle fractional sampling rate configuration for LL
687 audio_extn_a2dp_get_apptype_params(&sample_rate, &bit_width);
688 ALOGI("%s using %d sampling rate %d bit width for A2DP CoPP",
689 __func__, sample_rate, bit_width);
690 }
691
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800692 ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d",
693 __func__, flags, format, sample_rate, profile, app_type_cfg->app_type);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700694 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530695 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530696 /* Along with flags do profile matching if set at either end.*/
697 if (s_info->flags.out_flags == flags &&
698 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
699 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530700 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700701 sf_info = node_to_item(node_j, struct stream_format, list);
702 if (sf_info->format == format) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530703 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
Amit Shekhar6f461b12014-08-01 14:52:58 -0700704 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700705 }
706 }
707 }
708 }
709 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530710 s_info = node_to_item(node_i, struct streams_io_cfg, list);
711 if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700712 ALOGV("Compatible output profile not found.");
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530713 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
714 app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate;
715 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700716 ALOGV("%s Default to primary output: App type: %d sample_rate %d",
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530717 __func__, s_info->app_type_cfg.app_type, app_type_cfg->sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700718 return;
719 }
720 }
721 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700722 app_type_cfg->app_type = platform_get_default_app_type(platform);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700723 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700724 app_type_cfg->bit_width = 16;
725}
726
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530727static bool audio_is_this_native_usecase(struct audio_usecase *uc)
728{
729 bool native_usecase = false;
730 struct stream_out *out = (struct stream_out*) uc->stream.out;
731
732 if (PCM_PLAYBACK == uc->type && out != NULL &&
733 NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() &&
734 is_offload_usecase(uc->id) &&
735 (out->sample_rate == OUTPUT_SAMPLING_RATE_44100))
736 native_usecase = true;
737
738 return native_usecase;
739}
740
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800741
742static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev))
743{
744 return adev->vr_audio_mode_enabled;
745}
746
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530747void audio_extn_utils_update_stream_app_type_cfg_for_usecase(
748 struct audio_device *adev,
749 struct audio_usecase *usecase)
750{
751 ALOGV("%s", __func__);
752
753 switch(usecase->type) {
754 case PCM_PLAYBACK:
755 audio_extn_utils_update_stream_output_app_type_cfg(adev->platform,
756 &adev->streams_output_cfg_list,
757 usecase->stream.out->devices,
758 usecase->stream.out->flags,
759 usecase->stream.out->format,
760 usecase->stream.out->sample_rate,
761 usecase->stream.out->bit_width,
762 usecase->stream.out->channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530763 usecase->stream.out->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530764 &usecase->stream.out->app_type_cfg);
765 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
766 break;
767 case PCM_CAPTURE:
768 audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
769 &adev->streams_input_cfg_list,
770 usecase->stream.in->device,
771 usecase->stream.in->flags,
772 usecase->stream.in->format,
773 usecase->stream.in->sample_rate,
774 usecase->stream.in->bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530775 usecase->stream.in->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530776 &usecase->stream.in->app_type_cfg);
777 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type);
778 break;
779 default:
780 ALOGE("%s: app type cfg not supported for usecase type (%d)",
781 __func__, usecase->type);
782 }
783}
784
Siena Richard7c2db772016-12-21 11:32:34 -0800785static int send_app_type_cfg_for_device(struct audio_device *adev,
786 struct audio_usecase *usecase,
787 int split_snd_device)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700788{
789 char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT];
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530790 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
791 int len = 0, rc;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700792 struct mixer_ctl *ctl;
Siena Richard7c2db772016-12-21 11:32:34 -0800793 int pcm_device_id = 0, acdb_dev_id, app_type;
794 int snd_device = split_snd_device, snd_device_be_idx = -1;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530795 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Manish Dewangan837dc462015-05-27 10:17:41 +0530796 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700797
Siena Richard7c2db772016-12-21 11:32:34 -0800798 ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s",
799 __func__, platform_get_snd_device_name(usecase->out_snd_device),
800 platform_get_snd_device_name(usecase->in_snd_device),
801 platform_get_snd_device_name(split_snd_device));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700802
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530803 if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530804 ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700805 rc = 0;
806 goto exit_send_app_type_cfg;
807 }
808 if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) &&
809 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
810 (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800811 (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530812 (!is_offload_usecase(usecase->id)) &&
813 (usecase->type != PCM_CAPTURE)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530814 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 -0700815 rc = 0;
816 goto exit_send_app_type_cfg;
817 }
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800818
819 //if VR is active then only send the mixer control
820 if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) {
821 ALOGI("ULL doesnt need sending app type cfg, returning");
822 rc = 0;
823 goto exit_send_app_type_cfg;
824 }
825
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530826 if (usecase->type == PCM_PLAYBACK) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700827 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530828 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
829 "Audio Stream %d App Type Cfg", pcm_device_id);
Ben Romberger1fafdde2015-09-09 19:43:15 -0700830 } else if (usecase->type == PCM_CAPTURE) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700831 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530832 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
833 "Audio Stream Capture %d App Type Cfg", pcm_device_id);
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530834 }
Siena Richard7c2db772016-12-21 11:32:34 -0800835
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700836 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
837 if (!ctl) {
838 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__,
839 mixer_ctl_name);
840 rc = -EINVAL;
841 goto exit_send_app_type_cfg;
842 }
Aditya Bavanari701a6992017-03-30 19:17:16 +0530843 snd_device = platform_get_spkr_prot_snd_device(snd_device);
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530844
Rohit Kumar1181b292017-01-31 18:07:17 +0530845 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
846 if (acdb_dev_id <= 0) {
847 ALOGE("%s: Couldn't get the acdb dev id", __func__);
848 rc = -EINVAL;
849 goto exit_send_app_type_cfg;
850 }
851
Siena Richard7c2db772016-12-21 11:32:34 -0800852 snd_device_be_idx = platform_get_snd_device_backend_index(snd_device);
853 if (snd_device_be_idx < 0) {
854 ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d",
855 __func__, platform_get_snd_device_name(snd_device),
856 snd_device_be_idx);
857 }
858
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530859 if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) {
Manish Dewangan837dc462015-05-27 10:17:41 +0530860
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530861 property_get("audio.playback.mch.downsample",value,"");
862 if (!strncmp("true", value, sizeof("true"))) {
863 if ((popcount(usecase->stream.out->channel_mask) > 2) &&
864 (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
865 !(usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
866 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
867 }
Ashish Jainc02430d2016-01-04 10:42:43 +0530868
Ashish Jain4826f6c2017-02-06 13:33:20 +0530869 if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin21854652016-04-13 11:54:02 -0700870 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Ashish Jaina052e572016-11-07 16:41:07 +0530871 } else if ((snd_device == SND_DEVICE_OUT_HDMI ||
872 snd_device == SND_DEVICE_OUT_USB_HEADSET ||
873 snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
874 (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) {
875 /*
876 * To best utlize DSP, check if the stream sample rate is supported/multiple of
877 * configured device sample rate, if not update the COPP rate to be equal to the
878 * device sample rate, else open COPP at stream sample rate
879 */
880 platform_check_and_update_copp_sample_rate(adev->platform, snd_device,
881 usecase->stream.out->sample_rate,
882 &usecase->stream.out->app_type_cfg.sample_rate);
Ashish Jain4826f6c2017-02-06 13:33:20 +0530883 } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
884 !audio_is_this_native_usecase(usecase)) &&
Mingming Yin21854652016-04-13 11:54:02 -0700885 usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
886 (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
Ashish Jain4826f6c2017-02-06 13:33:20 +0530887 /* Reset to default if no native stream is active*/
Mingming Yin21854652016-04-13 11:54:02 -0700888 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
889 }
890 sample_rate = usecase->stream.out->app_type_cfg.sample_rate;
891
Siena Richard7c2db772016-12-21 11:32:34 -0800892 app_type = usecase->stream.out->app_type_cfg.app_type;
893 app_type_cfg[len++] = app_type;
Mingming Yin21854652016-04-13 11:54:02 -0700894 app_type_cfg[len++] = acdb_dev_id;
895 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
896 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530897 && audio_extn_passthru_is_passthrough_stream(usecase->stream.out)) {
Mingming Yin21854652016-04-13 11:54:02 -0700898 app_type_cfg[len++] = sample_rate * 4;
899 } else {
900 app_type_cfg[len++] = sample_rate;
901 }
Siena Richard7c2db772016-12-21 11:32:34 -0800902 if (snd_device_be_idx > 0)
903 app_type_cfg[len++] = snd_device_be_idx;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530904
Siena Richard7c2db772016-12-21 11:32:34 -0800905 ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
906 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530907
908 } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) {
Siena Richard7c2db772016-12-21 11:32:34 -0800909 app_type = usecase->stream.in->app_type_cfg.app_type;
910 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530911 app_type_cfg[len++] = acdb_dev_id;
Siena Richard7c2db772016-12-21 11:32:34 -0800912 sample_rate = usecase->stream.in->app_type_cfg.sample_rate;
913 app_type_cfg[len++] = sample_rate;
914 if (snd_device_be_idx > 0)
915 app_type_cfg[len++] = snd_device_be_idx;
916 ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
917 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530918 } else {
Siena Richard7c2db772016-12-21 11:32:34 -0800919 app_type = platform_get_default_app_type_v2(adev->platform, usecase->type);
920 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530921 app_type_cfg[len++] = acdb_dev_id;
922 app_type_cfg[len++] = sample_rate;
Siena Richard7c2db772016-12-21 11:32:34 -0800923 if (snd_device_be_idx > 0)
924 app_type_cfg[len++] = snd_device_be_idx;
925 ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
926 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Ashish Jainc02430d2016-01-04 10:42:43 +0530927 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530928
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700929 mixer_ctl_set_array(ctl, app_type_cfg, len);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700930 rc = 0;
931exit_send_app_type_cfg:
932 return rc;
933}
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700934
Siena Richard7c2db772016-12-21 11:32:34 -0800935int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
936 struct audio_usecase *usecase)
937{
938 int i, num_devices = 0;
939 snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0};
940 int rc = 0;
941
942 switch (usecase->type) {
943 case PCM_PLAYBACK:
944 ALOGD("%s: usecase->out_snd_device %s",
945 __func__, platform_get_snd_device_name(usecase->out_snd_device));
946 /* check for out combo device */
947 if (platform_split_snd_device(adev->platform,
948 usecase->out_snd_device,
949 &num_devices, new_snd_devices)) {
950 new_snd_devices[0] = usecase->out_snd_device;
951 num_devices = 1;
952 }
953 break;
954 case PCM_CAPTURE:
955 ALOGD("%s: usecase->in_snd_device %s",
956 __func__, platform_get_snd_device_name(usecase->in_snd_device));
957 /* check for in combo device */
958 if (platform_split_snd_device(adev->platform,
959 usecase->in_snd_device,
960 &num_devices, new_snd_devices)) {
961 new_snd_devices[0] = usecase->in_snd_device;
962 num_devices = 1;
963 }
964 break;
965 default:
966 ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__);
967 rc = 0;
968 break;
969 }
970
971 for (i = 0; i < num_devices; i++) {
972 rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]);
973 if (rc)
974 break;
975 }
976
977 return rc;
978}
979
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530980int read_line_from_file(const char *path, char *buf, size_t count)
981{
982 char * fgets_ret;
983 FILE * fd;
984 int rv;
985
986 fd = fopen(path, "r");
987 if (fd == NULL)
988 return -1;
989
990 fgets_ret = fgets(buf, (int)count, fd);
991 if (NULL != fgets_ret) {
992 rv = (int)strlen(buf);
993 } else {
994 rv = ferror(fd);
995 }
996 fclose(fd);
997
998 return rv;
999}
1000
Ashish Jainf1eaa582016-05-23 20:54:24 +05301001/*Translates ALSA formats to AOSP PCM formats*/
1002audio_format_t alsa_format_to_hal(uint32_t alsa_format)
1003{
1004 audio_format_t format;
1005
1006 switch(alsa_format) {
1007 case SNDRV_PCM_FORMAT_S16_LE:
1008 format = AUDIO_FORMAT_PCM_16_BIT;
1009 break;
1010 case SNDRV_PCM_FORMAT_S24_3LE:
1011 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1012 break;
1013 case SNDRV_PCM_FORMAT_S24_LE:
1014 format = AUDIO_FORMAT_PCM_8_24_BIT;
1015 break;
1016 case SNDRV_PCM_FORMAT_S32_LE:
1017 format = AUDIO_FORMAT_PCM_32_BIT;
1018 break;
1019 default:
1020 ALOGW("Incorrect ALSA format");
1021 format = AUDIO_FORMAT_INVALID;
1022 }
1023 return format;
1024}
1025
1026/*Translates hal format (AOSP) to alsa formats*/
1027uint32_t hal_format_to_alsa(audio_format_t hal_format)
1028{
1029 uint32_t alsa_format;
1030
1031 switch (hal_format) {
1032 case AUDIO_FORMAT_PCM_32_BIT: {
1033 if (platform_supports_true_32bit())
1034 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1035 else
1036 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1037 }
1038 break;
1039 case AUDIO_FORMAT_PCM_8_BIT:
1040 alsa_format = SNDRV_PCM_FORMAT_S8;
1041 break;
1042 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1043 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1044 break;
1045 case AUDIO_FORMAT_PCM_8_24_BIT: {
1046 if (platform_supports_true_32bit())
1047 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1048 else
1049 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1050 }
1051 break;
1052 case AUDIO_FORMAT_PCM_FLOAT:
1053 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1054 break;
1055 default:
1056 case AUDIO_FORMAT_PCM_16_BIT:
1057 alsa_format = SNDRV_PCM_FORMAT_S16_LE;
1058 break;
1059 }
1060 return alsa_format;
1061}
1062
Ashish Jain83a6cc22016-06-28 14:34:17 +05301063/*Translates PCM formats to AOSP formats*/
1064audio_format_t pcm_format_to_hal(uint32_t pcm_format)
1065{
1066 audio_format_t format = AUDIO_FORMAT_INVALID;
1067
1068 switch(pcm_format) {
1069 case PCM_FORMAT_S16_LE:
1070 format = AUDIO_FORMAT_PCM_16_BIT;
1071 break;
1072 case PCM_FORMAT_S24_3LE:
1073 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1074 break;
1075 case PCM_FORMAT_S24_LE:
1076 format = AUDIO_FORMAT_PCM_8_24_BIT;
1077 break;
1078 case PCM_FORMAT_S32_LE:
1079 format = AUDIO_FORMAT_PCM_32_BIT;
1080 break;
1081 default:
1082 ALOGW("Incorrect PCM format");
1083 format = AUDIO_FORMAT_INVALID;
1084 }
1085 return format;
1086}
1087
1088/*Translates hal format (AOSP) to alsa formats*/
1089uint32_t hal_format_to_pcm(audio_format_t hal_format)
1090{
1091 uint32_t pcm_format;
1092
1093 switch (hal_format) {
1094 case AUDIO_FORMAT_PCM_32_BIT:
1095 case AUDIO_FORMAT_PCM_8_24_BIT:
1096 case AUDIO_FORMAT_PCM_FLOAT: {
1097 if (platform_supports_true_32bit())
1098 pcm_format = PCM_FORMAT_S32_LE;
1099 else
1100 pcm_format = PCM_FORMAT_S24_3LE;
1101 }
1102 break;
1103 case AUDIO_FORMAT_PCM_8_BIT:
1104 pcm_format = PCM_FORMAT_S8;
1105 break;
1106 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1107 pcm_format = PCM_FORMAT_S24_3LE;
1108 break;
1109 default:
1110 case AUDIO_FORMAT_PCM_16_BIT:
1111 pcm_format = PCM_FORMAT_S16_LE;
1112 break;
1113 }
1114 return pcm_format;
1115}
1116
Ashish Jainf1eaa582016-05-23 20:54:24 +05301117uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
1118 uint32_t sample_rate,
1119 uint32_t noOfChannels)
1120{
1121 uint32_t fragment_size = 0;
1122 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
1123
1124 fragment_size = (pcm_offload_time
1125 * sample_rate
1126 * bytes_per_sample
1127 * noOfChannels)/1000;
1128 if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1129 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1130 else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1131 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1132 /*To have same PCM samples for all channels, the buffer size requires to
1133 *be multiple of (number of channels * bytes per sample)
1134 *For writes to succeed, the buffer must be written at address which is multiple of 32
1135 */
1136 fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32));
1137
1138 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
1139 return fragment_size;
1140}
1141
1142/* Calculates the fragment size required to configure compress session.
1143 * Based on the alsa format selected, decide if conversion is needed in
1144
1145 * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to
1146 * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver.
1147 */
1148void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
1149{
Ashish Jain83a6cc22016-06-28 14:34:17 +05301150 audio_format_t dst_format = out->hal_op_format;
1151 audio_format_t src_format = out->hal_ip_format;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301152 uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format);
1153 uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format);
1154
1155 out->compr_config.fragment_size =
1156 get_alsa_fragment_size(hal_op_bytes_per_sample,
1157 out->sample_rate,
1158 popcount(out->channel_mask));
1159
1160 if ((src_format != dst_format) &&
1161 hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
1162
Ashish Jain83a6cc22016-06-28 14:34:17 +05301163 out->hal_fragment_size =
Ashish Jainf1eaa582016-05-23 20:54:24 +05301164 ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) /
1165 hal_op_bytes_per_sample);
1166 ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x",
Ashish Jain83a6cc22016-06-28 14:34:17 +05301167 out->hal_fragment_size, src_format, dst_format);
Ashish Jainf1eaa582016-05-23 20:54:24 +05301168 } else {
Ashish Jain83a6cc22016-06-28 14:34:17 +05301169 out->hal_fragment_size = out->compr_config.fragment_size;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301170 }
1171}
1172
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301173/* converts pcm format 24_8 to 8_24 inplace */
1174size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes)
1175{
1176 size_t i = 0;
1177 int *int_buf_stream = buf;
1178
1179 if ((bytes % 4) != 0) {
1180 ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__);
1181 return -EINVAL;
1182 }
1183
1184 for (; i < (bytes / 4); i++)
1185 int_buf_stream[i] >>= 8;
1186
1187 return bytes;
1188}
1189
1190int get_snd_codec_id(audio_format_t format)
1191{
1192 int id = 0;
1193
1194 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1195 case AUDIO_FORMAT_MP3:
1196 id = SND_AUDIOCODEC_MP3;
1197 break;
1198 case AUDIO_FORMAT_AAC:
1199 id = SND_AUDIOCODEC_AAC;
1200 break;
1201 case AUDIO_FORMAT_AAC_ADTS:
1202 id = SND_AUDIOCODEC_AAC;
1203 break;
Arun Kumar Dasari3b174182016-12-27 13:01:14 +05301204 case AUDIO_FORMAT_AAC_LATM:
1205 id = SND_AUDIOCODEC_AAC;
1206 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301207 case AUDIO_FORMAT_PCM:
1208 id = SND_AUDIOCODEC_PCM;
1209 break;
1210 case AUDIO_FORMAT_FLAC:
1211 id = SND_AUDIOCODEC_FLAC;
1212 break;
1213 case AUDIO_FORMAT_ALAC:
1214 id = SND_AUDIOCODEC_ALAC;
1215 break;
1216 case AUDIO_FORMAT_APE:
1217 id = SND_AUDIOCODEC_APE;
1218 break;
1219 case AUDIO_FORMAT_VORBIS:
1220 id = SND_AUDIOCODEC_VORBIS;
1221 break;
1222 case AUDIO_FORMAT_WMA:
1223 id = SND_AUDIOCODEC_WMA;
1224 break;
1225 case AUDIO_FORMAT_WMA_PRO:
1226 id = SND_AUDIOCODEC_WMA_PRO;
1227 break;
Satish Babu Patakokila0c313922016-12-08 12:07:08 +05301228 case AUDIO_FORMAT_MP2:
1229 id = SND_AUDIOCODEC_MP2;
1230 break;
Satish Babu Patakokila915ecba2017-01-10 17:43:56 +05301231 case AUDIO_FORMAT_AC3:
1232 id = SND_AUDIOCODEC_AC3;
1233 break;
1234 case AUDIO_FORMAT_E_AC3:
1235 case AUDIO_FORMAT_E_AC3_JOC:
1236 id = SND_AUDIOCODEC_EAC3;
1237 break;
1238 case AUDIO_FORMAT_DTS:
1239 case AUDIO_FORMAT_DTS_HD:
1240 id = SND_AUDIOCODEC_DTS;
1241 break;
Preetam Singh Ranawat4277a5a2017-01-18 19:02:24 +05301242 case AUDIO_FORMAT_DSD:
1243 id = SND_AUDIOCODEC_DSD;
1244 break;
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +05301245 case AUDIO_FORMAT_APTX:
1246 id = SND_AUDIOCODEC_APTX;
1247 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301248 default:
1249 ALOGE("%s: Unsupported audio format :%x", __func__, format);
1250 }
1251
1252 return id;
1253}
1254
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001255void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
1256 struct audio_usecase *usecase)
1257{
1258 int type = usecase->type;
1259
Dhananjay Kumar14245982017-01-16 20:21:00 +05301260 if (type == PCM_PLAYBACK && usecase->stream.out != NULL) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001261 struct stream_out *out = usecase->stream.out;
1262 int snd_device = usecase->out_snd_device;
1263 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08001264 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301265 platform_send_audio_calibration(adev->platform, usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001266 out->app_type_cfg.app_type,
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301267 usecase->stream.out->app_type_cfg.sample_rate);
Dhananjay Kumar14245982017-01-16 20:21:00 +05301268 } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301269 platform_send_audio_calibration(adev->platform, usecase,
1270 usecase->stream.in->app_type_cfg.app_type,
1271 usecase->stream.in->app_type_cfg.sample_rate);
Vidyakumar Athota653aaef2017-03-16 11:11:31 -07001272 } else if (type == PCM_HFP_CALL || type == PCM_CAPTURE) {
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301273 /* when app type is default. the sample rate is not used to send cal */
1274 platform_send_audio_calibration(adev->platform, usecase,
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301275 platform_get_default_app_type_v2(adev->platform, usecase->type),
1276 48000);
Vidyakumar Athotae57f6002017-03-01 13:13:16 -08001277 } else {
1278 /* No need to send audio calibration for voice and voip call usecases */
1279 if ((type != VOICE_CALL) && (type != VOIP_CALL))
1280 ALOGW("%s: No audio calibration for usecase type = %d", __func__, type);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001281 }
1282}
1283
Ben Rombergera04fabc2014-11-14 12:16:03 -08001284// Base64 Encode and Decode
1285// Not all features supported. This must be used only with following conditions.
1286// Decode Modes: Support with and without padding
1287// CRLF not handling. So no CRLF in string to decode.
1288// Encode Modes: Supports only padding
1289int b64decode(char *inp, int ilen, uint8_t* outp)
1290{
1291 int i, j, k, ii, num;
1292 int rem, pcnt;
1293 uint32_t res=0;
1294 uint8_t getIndex[MAX_BASEINDEX_LEN];
1295 uint8_t tmp, cflag;
1296
1297 if(inp == NULL || outp == NULL || ilen <= 0) {
1298 ALOGE("[%s] received NULL pointer or zero length",__func__);
1299 return -1;
1300 }
1301
1302 memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex));
1303 for(i=0;i<BASE_TABLE_SIZE;i++) {
1304 getIndex[(uint8_t)bTable[i]] = (uint8_t)i;
1305 }
1306 getIndex[(uint8_t)'=']=0;
1307
1308 j=0;k=0;
1309 num = ilen/4;
1310 rem = ilen%4;
1311 if(rem==0)
1312 num = num-1;
1313 cflag=0;
1314 for(i=0; i<num; i++) {
1315 res=0;
1316 for(ii=0;ii<4;ii++) {
1317 res = res << 6;
1318 tmp = getIndex[(uint8_t)inp[j++]];
1319 res = res | tmp;
1320 cflag = cflag | tmp;
1321 }
1322 outp[k++] = (res >> 16)&0xFF;
1323 outp[k++] = (res >> 8)&0xFF;
1324 outp[k++] = res & 0xFF;
1325 }
1326
1327 // Handle last bytes special
1328 pcnt=0;
1329 if(rem == 0) {
1330 //With padding or full data
1331 res = 0;
1332 for(ii=0;ii<4;ii++) {
1333 if(inp[j] == '=')
1334 pcnt++;
1335 res = res << 6;
1336 tmp = getIndex[(uint8_t)inp[j++]];
1337 res = res | tmp;
1338 cflag = cflag | tmp;
1339 }
1340 outp[k++] = res >> 16;
1341 if(pcnt == 2)
1342 goto done;
1343 outp[k++] = (res>>8)&0xFF;
1344 if(pcnt == 1)
1345 goto done;
1346 outp[k++] = res&0xFF;
1347 } else {
1348 //without padding
1349 res = 0;
1350 for(i=0;i<rem;i++) {
1351 res = res << 6;
1352 tmp = getIndex[(uint8_t)inp[j++]];
1353 res = res | tmp;
1354 cflag = cflag | tmp;
1355 }
1356 for(i=rem;i<4;i++) {
1357 res = res << 6;
1358 pcnt++;
1359 }
1360 outp[k++] = res >> 16;
1361 if(pcnt == 2)
1362 goto done;
1363 outp[k++] = (res>>8)&0xFF;
1364 if(pcnt == 1)
1365 goto done;
1366 outp[k++] = res&0xFF;
1367 }
1368done:
1369 if(cflag == 0xFF) {
1370 ALOGE("[%s] base64 decode failed. Invalid character found %s",
1371 __func__, inp);
1372 return 0;
1373 }
1374 return k;
1375}
1376
1377int b64encode(uint8_t *inp, int ilen, char* outp)
1378{
1379 int i,j,k, num;
1380 int rem=0;
1381 uint32_t res=0;
1382
1383 if(inp == NULL || outp == NULL || ilen<=0) {
1384 ALOGE("[%s] received NULL pointer or zero input length",__func__);
1385 return -1;
1386 }
1387
1388 num = ilen/3;
1389 rem = ilen%3;
1390 j=0;k=0;
1391 for(i=0; i<num; i++) {
1392 //prepare index
1393 res = inp[j++]<<16;
1394 res = res | inp[j++]<<8;
1395 res = res | inp[j++];
1396 //get output map from index
1397 outp[k++] = (char) bTable[(res>>18)&0x3F];
1398 outp[k++] = (char) bTable[(res>>12)&0x3F];
1399 outp[k++] = (char) bTable[(res>>6)&0x3F];
1400 outp[k++] = (char) bTable[res&0x3F];
1401 }
1402
1403 switch(rem) {
1404 case 1:
1405 res = inp[j++]<<16;
1406 outp[k++] = (char) bTable[res>>18];
1407 outp[k++] = (char) bTable[(res>>12)&0x3F];
1408 //outp[k++] = '=';
1409 //outp[k++] = '=';
1410 break;
1411 case 2:
1412 res = inp[j++]<<16;
1413 res = res | inp[j++]<<8;
1414 outp[k++] = (char) bTable[res>>18];
1415 outp[k++] = (char) bTable[(res>>12)&0x3F];
1416 outp[k++] = (char) bTable[(res>>6)&0x3F];
1417 //outp[k++] = '=';
1418 break;
1419 default:
1420 break;
1421 }
Ben Rombergera04fabc2014-11-14 12:16:03 -08001422 outp[k] = '\0';
1423 return k;
1424}
Ashish Jain81eb2a82015-05-13 10:52:34 +05301425
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301426
1427int audio_extn_utils_get_codec_version(const char *snd_card_name,
1428 int card_num,
1429 char *codec_version)
1430{
1431 char procfs_path[50];
1432 FILE *fp;
1433
1434 if (strstr(snd_card_name, "tasha")) {
1435 snprintf(procfs_path, sizeof(procfs_path),
1436 "/proc/asound/card%d/codecs/tasha/version", card_num);
1437 if ((fp = fopen(procfs_path, "r")) != NULL) {
1438 fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp);
1439 fclose(fp);
1440 } else {
1441 ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path);
1442 return -ENOENT;
1443 }
1444 ALOGD("%s: codec version %s", __func__, codec_version);
1445 }
1446
1447 return 0;
1448}
1449
1450
Ashish Jain81eb2a82015-05-13 10:52:34 +05301451#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
1452
1453void get_default_compressed_channel_status(
1454 unsigned char *channel_status)
1455{
Ashish Jain81eb2a82015-05-13 10:52:34 +05301456 memset(channel_status,0,24);
1457
1458 /* block start bit in preamble bit 3 */
1459 channel_status[0] |= PROFESSIONAL;
1460 //compre out
1461 channel_status[0] |= NON_LPCM;
1462 // sample rate; fixed 48K for default/transcode
1463 channel_status[3] |= SR_48000;
1464}
1465
1466#ifdef HDMI_PASSTHROUGH_ENABLED
1467int32_t get_compressed_channel_status(void *audio_stream_data,
1468 uint32_t audio_frame_size,
1469 unsigned char *channel_status,
1470 enum audio_parser_code_type codec_type)
1471 // codec_type - AUDIO_PARSER_CODEC_AC3
1472 // - AUDIO_PARSER_CODEC_DTS
1473{
1474 unsigned char *stream;
1475 int ret = 0;
1476 stream = (unsigned char *)audio_stream_data;
1477
1478 if (audio_stream_data == NULL || audio_frame_size == 0) {
1479 ALOGW("no buffer to get channel status, return default for compress");
1480 get_default_compressed_channel_status(channel_status);
1481 return ret;
1482 }
1483
1484 memset(channel_status,0,24);
1485 if(init_audio_parser(stream, audio_frame_size, codec_type) == -1)
1486 {
1487 ALOGE("init audio parser failed");
1488 return -1;
1489 }
1490 ret = get_channel_status(channel_status, codec_type);
1491 return ret;
1492
1493}
1494
1495#endif
1496
1497void get_lpcm_channel_status(uint32_t sampleRate,
1498 unsigned char *channel_status)
1499{
1500 int32_t status = 0;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301501 memset(channel_status,0,24);
1502 /* block start bit in preamble bit 3 */
1503 channel_status[0] |= PROFESSIONAL;
1504 //LPCM OUT
1505 channel_status[0] &= ~NON_LPCM;
1506
1507 switch (sampleRate) {
1508 case 8000:
1509 case 11025:
1510 case 12000:
1511 case 16000:
1512 case 22050:
1513 channel_status[3] |= SR_NOTID;
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301514 break;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301515 case 24000:
1516 channel_status[3] |= SR_24000;
1517 break;
1518 case 32000:
1519 channel_status[3] |= SR_32000;
1520 break;
1521 case 44100:
1522 channel_status[3] |= SR_44100;
1523 break;
1524 case 48000:
1525 channel_status[3] |= SR_48000;
1526 break;
1527 case 88200:
1528 channel_status[3] |= SR_88200;
1529 break;
1530 case 96000:
1531 channel_status[3] |= SR_96000;
1532 break;
1533 case 176400:
1534 channel_status[3] |= SR_176400;
1535 break;
1536 case 192000:
1537 channel_status[3] |= SR_192000;
1538 break;
1539 default:
1540 ALOGV("Invalid sample_rate %u\n", sampleRate);
1541 status = -1;
1542 break;
1543 }
1544}
1545
1546void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes)
1547{
1548 unsigned char channel_status[24]={0};
1549 struct snd_aes_iec958 iec958;
1550 const char *mixer_ctl_name = "IEC958 Playback PCM Stream";
1551 struct mixer_ctl *ctl;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301552 ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes);
Ashish Jain81eb2a82015-05-13 10:52:34 +05301553#ifdef HDMI_PASSTHROUGH_ENABLED
1554 if (audio_extn_is_dolby_format(out->format) &&
1555 /*TODO:Extend code to support DTS passthrough*/
1556 /*set compressed channel status bits*/
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05301557 audio_extn_passthru_is_passthrough_stream(out)){
Ashish Jain81eb2a82015-05-13 10:52:34 +05301558 get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3);
1559 } else
1560#endif
1561 {
1562 /*set channel status bit for LPCM*/
1563 get_lpcm_channel_status(out->sample_rate, channel_status);
1564 }
1565
1566 memcpy(iec958.status, channel_status,sizeof(iec958.status));
1567 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name);
1568 if (!ctl) {
1569 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1570 __func__, mixer_ctl_name);
1571 return;
1572 }
1573 if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) {
1574 ALOGE("%s: Could not set channel status for ext HDMI ",
1575 __func__);
1576 return;
1577 }
1578
1579}
1580#endif
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301581
1582int audio_extn_utils_get_avt_device_drift(
1583 struct audio_usecase *usecase,
1584 struct audio_avt_device_drift_param *drift_param)
1585{
1586 int ret = 0, count = 0;
1587 char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
1588 struct mixer_ctl *ctl = NULL;
1589 struct audio_avt_device_drift_stats drift_stats;
1590 struct audio_device *adev = NULL;
1591
1592 if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
1593 adev = usecase->stream.out->dev;
1594 switch(usecase->out_snd_device) {
1595 case SND_DEVICE_OUT_HDMI:
1596 strlcpy(avt_device_drift_mixer_ctl_name,
1597 "HDMI RX Drift",
1598 MIXER_PATH_MAX_LENGTH);
1599 break;
1600 case SND_DEVICE_OUT_DISPLAY_PORT:
1601 strlcpy(avt_device_drift_mixer_ctl_name,
1602 "DISPLAY Port RX Drift",
1603 MIXER_PATH_MAX_LENGTH);
1604 break;
1605 default :
1606 ALOGE("%s: Unsupported device %d",__func__,
1607 usecase->stream.out->devices);
1608 ret = -EINVAL;
1609 }
1610 } else {
1611 ALOGE("%s: Invalid usecase %d ",__func__, usecase->type);
1612 ret = -EINVAL;
1613 }
1614
1615 if(ret)
1616 goto done;
1617
1618 ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name);
1619 if (!ctl) {
1620 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1621 __func__, avt_device_drift_mixer_ctl_name);
1622
1623 ret = -EINVAL;
1624 goto done;
1625 }
1626
1627 ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__,
1628 avt_device_drift_mixer_ctl_name);
1629
1630 mixer_ctl_update(ctl);
1631 count = mixer_ctl_get_num_values(ctl);
1632 if (count != sizeof(struct audio_avt_device_drift_stats)) {
1633 ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size",
1634 __func__);
1635
1636 ret = -EINVAL;
1637 goto done;
1638 }
1639
1640 ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count);
1641 if (ret != 0) {
1642 ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params",
1643 __func__);
1644
1645 ret = -EINVAL;
1646 goto done;
1647 }
1648 memcpy(drift_param, &drift_stats.drift_param,
1649 sizeof(struct audio_avt_device_drift_param));
1650done:
1651 return ret;
1652}