blob: 4b8692bb63230e34b0a1cc56dbf7046347371bd6 [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 }
843 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +0800844 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530845
Rohit Kumar1181b292017-01-31 18:07:17 +0530846 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
847 if (acdb_dev_id <= 0) {
848 ALOGE("%s: Couldn't get the acdb dev id", __func__);
849 rc = -EINVAL;
850 goto exit_send_app_type_cfg;
851 }
852
Siena Richard7c2db772016-12-21 11:32:34 -0800853 snd_device_be_idx = platform_get_snd_device_backend_index(snd_device);
854 if (snd_device_be_idx < 0) {
855 ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d",
856 __func__, platform_get_snd_device_name(snd_device),
857 snd_device_be_idx);
858 }
859
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530860 if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) {
Manish Dewangan837dc462015-05-27 10:17:41 +0530861
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530862 property_get("audio.playback.mch.downsample",value,"");
863 if (!strncmp("true", value, sizeof("true"))) {
864 if ((popcount(usecase->stream.out->channel_mask) > 2) &&
865 (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
866 !(usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
867 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
868 }
Ashish Jainc02430d2016-01-04 10:42:43 +0530869
Ashish Jain4826f6c2017-02-06 13:33:20 +0530870 if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin21854652016-04-13 11:54:02 -0700871 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Ashish Jaina052e572016-11-07 16:41:07 +0530872 } else if ((snd_device == SND_DEVICE_OUT_HDMI ||
873 snd_device == SND_DEVICE_OUT_USB_HEADSET ||
874 snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
875 (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) {
876 /*
877 * To best utlize DSP, check if the stream sample rate is supported/multiple of
878 * configured device sample rate, if not update the COPP rate to be equal to the
879 * device sample rate, else open COPP at stream sample rate
880 */
881 platform_check_and_update_copp_sample_rate(adev->platform, snd_device,
882 usecase->stream.out->sample_rate,
883 &usecase->stream.out->app_type_cfg.sample_rate);
Ashish Jain4826f6c2017-02-06 13:33:20 +0530884 } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
885 !audio_is_this_native_usecase(usecase)) &&
Mingming Yin21854652016-04-13 11:54:02 -0700886 usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
887 (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
Ashish Jain4826f6c2017-02-06 13:33:20 +0530888 /* Reset to default if no native stream is active*/
Mingming Yin21854652016-04-13 11:54:02 -0700889 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
890 }
891 sample_rate = usecase->stream.out->app_type_cfg.sample_rate;
892
Siena Richard7c2db772016-12-21 11:32:34 -0800893 app_type = usecase->stream.out->app_type_cfg.app_type;
894 app_type_cfg[len++] = app_type;
Mingming Yin21854652016-04-13 11:54:02 -0700895 app_type_cfg[len++] = acdb_dev_id;
896 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
897 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC))
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530898 && audio_extn_passthru_is_passthrough_stream(usecase->stream.out)) {
Mingming Yin21854652016-04-13 11:54:02 -0700899 app_type_cfg[len++] = sample_rate * 4;
900 } else {
901 app_type_cfg[len++] = sample_rate;
902 }
Siena Richard7c2db772016-12-21 11:32:34 -0800903 if (snd_device_be_idx > 0)
904 app_type_cfg[len++] = snd_device_be_idx;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530905
Siena Richard7c2db772016-12-21 11:32:34 -0800906 ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
907 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530908
909 } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) {
Siena Richard7c2db772016-12-21 11:32:34 -0800910 app_type = usecase->stream.in->app_type_cfg.app_type;
911 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530912 app_type_cfg[len++] = acdb_dev_id;
Siena Richard7c2db772016-12-21 11:32:34 -0800913 sample_rate = usecase->stream.in->app_type_cfg.sample_rate;
914 app_type_cfg[len++] = sample_rate;
915 if (snd_device_be_idx > 0)
916 app_type_cfg[len++] = snd_device_be_idx;
917 ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
918 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530919 } else {
Siena Richard7c2db772016-12-21 11:32:34 -0800920 app_type = platform_get_default_app_type_v2(adev->platform, usecase->type);
921 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530922 app_type_cfg[len++] = acdb_dev_id;
923 app_type_cfg[len++] = sample_rate;
Siena Richard7c2db772016-12-21 11:32:34 -0800924 if (snd_device_be_idx > 0)
925 app_type_cfg[len++] = snd_device_be_idx;
926 ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
927 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Ashish Jainc02430d2016-01-04 10:42:43 +0530928 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530929
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700930 mixer_ctl_set_array(ctl, app_type_cfg, len);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700931 rc = 0;
932exit_send_app_type_cfg:
933 return rc;
934}
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700935
Siena Richard7c2db772016-12-21 11:32:34 -0800936int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
937 struct audio_usecase *usecase)
938{
939 int i, num_devices = 0;
940 snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0};
941 int rc = 0;
942
943 switch (usecase->type) {
944 case PCM_PLAYBACK:
945 ALOGD("%s: usecase->out_snd_device %s",
946 __func__, platform_get_snd_device_name(usecase->out_snd_device));
947 /* check for out combo device */
948 if (platform_split_snd_device(adev->platform,
949 usecase->out_snd_device,
950 &num_devices, new_snd_devices)) {
951 new_snd_devices[0] = usecase->out_snd_device;
952 num_devices = 1;
953 }
954 break;
955 case PCM_CAPTURE:
956 ALOGD("%s: usecase->in_snd_device %s",
957 __func__, platform_get_snd_device_name(usecase->in_snd_device));
958 /* check for in combo device */
959 if (platform_split_snd_device(adev->platform,
960 usecase->in_snd_device,
961 &num_devices, new_snd_devices)) {
962 new_snd_devices[0] = usecase->in_snd_device;
963 num_devices = 1;
964 }
965 break;
966 default:
967 ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__);
968 rc = 0;
969 break;
970 }
971
972 for (i = 0; i < num_devices; i++) {
973 rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]);
974 if (rc)
975 break;
976 }
977
978 return rc;
979}
980
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +0530981int read_line_from_file(const char *path, char *buf, size_t count)
982{
983 char * fgets_ret;
984 FILE * fd;
985 int rv;
986
987 fd = fopen(path, "r");
988 if (fd == NULL)
989 return -1;
990
991 fgets_ret = fgets(buf, (int)count, fd);
992 if (NULL != fgets_ret) {
993 rv = (int)strlen(buf);
994 } else {
995 rv = ferror(fd);
996 }
997 fclose(fd);
998
999 return rv;
1000}
1001
Ashish Jainf1eaa582016-05-23 20:54:24 +05301002/*Translates ALSA formats to AOSP PCM formats*/
1003audio_format_t alsa_format_to_hal(uint32_t alsa_format)
1004{
1005 audio_format_t format;
1006
1007 switch(alsa_format) {
1008 case SNDRV_PCM_FORMAT_S16_LE:
1009 format = AUDIO_FORMAT_PCM_16_BIT;
1010 break;
1011 case SNDRV_PCM_FORMAT_S24_3LE:
1012 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1013 break;
1014 case SNDRV_PCM_FORMAT_S24_LE:
1015 format = AUDIO_FORMAT_PCM_8_24_BIT;
1016 break;
1017 case SNDRV_PCM_FORMAT_S32_LE:
1018 format = AUDIO_FORMAT_PCM_32_BIT;
1019 break;
1020 default:
1021 ALOGW("Incorrect ALSA format");
1022 format = AUDIO_FORMAT_INVALID;
1023 }
1024 return format;
1025}
1026
1027/*Translates hal format (AOSP) to alsa formats*/
1028uint32_t hal_format_to_alsa(audio_format_t hal_format)
1029{
1030 uint32_t alsa_format;
1031
1032 switch (hal_format) {
1033 case AUDIO_FORMAT_PCM_32_BIT: {
1034 if (platform_supports_true_32bit())
1035 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1036 else
1037 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1038 }
1039 break;
1040 case AUDIO_FORMAT_PCM_8_BIT:
1041 alsa_format = SNDRV_PCM_FORMAT_S8;
1042 break;
1043 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1044 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1045 break;
1046 case AUDIO_FORMAT_PCM_8_24_BIT: {
1047 if (platform_supports_true_32bit())
1048 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1049 else
1050 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1051 }
1052 break;
1053 case AUDIO_FORMAT_PCM_FLOAT:
1054 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1055 break;
1056 default:
1057 case AUDIO_FORMAT_PCM_16_BIT:
1058 alsa_format = SNDRV_PCM_FORMAT_S16_LE;
1059 break;
1060 }
1061 return alsa_format;
1062}
1063
Ashish Jain83a6cc22016-06-28 14:34:17 +05301064/*Translates PCM formats to AOSP formats*/
1065audio_format_t pcm_format_to_hal(uint32_t pcm_format)
1066{
1067 audio_format_t format = AUDIO_FORMAT_INVALID;
1068
1069 switch(pcm_format) {
1070 case PCM_FORMAT_S16_LE:
1071 format = AUDIO_FORMAT_PCM_16_BIT;
1072 break;
1073 case PCM_FORMAT_S24_3LE:
1074 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1075 break;
1076 case PCM_FORMAT_S24_LE:
1077 format = AUDIO_FORMAT_PCM_8_24_BIT;
1078 break;
1079 case PCM_FORMAT_S32_LE:
1080 format = AUDIO_FORMAT_PCM_32_BIT;
1081 break;
1082 default:
1083 ALOGW("Incorrect PCM format");
1084 format = AUDIO_FORMAT_INVALID;
1085 }
1086 return format;
1087}
1088
1089/*Translates hal format (AOSP) to alsa formats*/
1090uint32_t hal_format_to_pcm(audio_format_t hal_format)
1091{
1092 uint32_t pcm_format;
1093
1094 switch (hal_format) {
1095 case AUDIO_FORMAT_PCM_32_BIT:
1096 case AUDIO_FORMAT_PCM_8_24_BIT:
1097 case AUDIO_FORMAT_PCM_FLOAT: {
1098 if (platform_supports_true_32bit())
1099 pcm_format = PCM_FORMAT_S32_LE;
1100 else
1101 pcm_format = PCM_FORMAT_S24_3LE;
1102 }
1103 break;
1104 case AUDIO_FORMAT_PCM_8_BIT:
1105 pcm_format = PCM_FORMAT_S8;
1106 break;
1107 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1108 pcm_format = PCM_FORMAT_S24_3LE;
1109 break;
1110 default:
1111 case AUDIO_FORMAT_PCM_16_BIT:
1112 pcm_format = PCM_FORMAT_S16_LE;
1113 break;
1114 }
1115 return pcm_format;
1116}
1117
Ashish Jainf1eaa582016-05-23 20:54:24 +05301118uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
1119 uint32_t sample_rate,
1120 uint32_t noOfChannels)
1121{
1122 uint32_t fragment_size = 0;
1123 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
1124
1125 fragment_size = (pcm_offload_time
1126 * sample_rate
1127 * bytes_per_sample
1128 * noOfChannels)/1000;
1129 if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1130 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1131 else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1132 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1133 /*To have same PCM samples for all channels, the buffer size requires to
1134 *be multiple of (number of channels * bytes per sample)
1135 *For writes to succeed, the buffer must be written at address which is multiple of 32
1136 */
1137 fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32));
1138
1139 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
1140 return fragment_size;
1141}
1142
1143/* Calculates the fragment size required to configure compress session.
1144 * Based on the alsa format selected, decide if conversion is needed in
1145
1146 * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to
1147 * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver.
1148 */
1149void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
1150{
Ashish Jain83a6cc22016-06-28 14:34:17 +05301151 audio_format_t dst_format = out->hal_op_format;
1152 audio_format_t src_format = out->hal_ip_format;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301153 uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format);
1154 uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format);
1155
1156 out->compr_config.fragment_size =
1157 get_alsa_fragment_size(hal_op_bytes_per_sample,
1158 out->sample_rate,
1159 popcount(out->channel_mask));
1160
1161 if ((src_format != dst_format) &&
1162 hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
1163
Ashish Jain83a6cc22016-06-28 14:34:17 +05301164 out->hal_fragment_size =
Ashish Jainf1eaa582016-05-23 20:54:24 +05301165 ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) /
1166 hal_op_bytes_per_sample);
1167 ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x",
Ashish Jain83a6cc22016-06-28 14:34:17 +05301168 out->hal_fragment_size, src_format, dst_format);
Ashish Jainf1eaa582016-05-23 20:54:24 +05301169 } else {
Ashish Jain83a6cc22016-06-28 14:34:17 +05301170 out->hal_fragment_size = out->compr_config.fragment_size;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301171 }
1172}
1173
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301174/* converts pcm format 24_8 to 8_24 inplace */
1175size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes)
1176{
1177 size_t i = 0;
1178 int *int_buf_stream = buf;
1179
1180 if ((bytes % 4) != 0) {
1181 ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__);
1182 return -EINVAL;
1183 }
1184
1185 for (; i < (bytes / 4); i++)
1186 int_buf_stream[i] >>= 8;
1187
1188 return bytes;
1189}
1190
1191int get_snd_codec_id(audio_format_t format)
1192{
1193 int id = 0;
1194
1195 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1196 case AUDIO_FORMAT_MP3:
1197 id = SND_AUDIOCODEC_MP3;
1198 break;
1199 case AUDIO_FORMAT_AAC:
1200 id = SND_AUDIOCODEC_AAC;
1201 break;
1202 case AUDIO_FORMAT_AAC_ADTS:
1203 id = SND_AUDIOCODEC_AAC;
1204 break;
Arun Kumar Dasari3b174182016-12-27 13:01:14 +05301205 case AUDIO_FORMAT_AAC_LATM:
1206 id = SND_AUDIOCODEC_AAC;
1207 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301208 case AUDIO_FORMAT_PCM:
1209 id = SND_AUDIOCODEC_PCM;
1210 break;
1211 case AUDIO_FORMAT_FLAC:
1212 id = SND_AUDIOCODEC_FLAC;
1213 break;
1214 case AUDIO_FORMAT_ALAC:
1215 id = SND_AUDIOCODEC_ALAC;
1216 break;
1217 case AUDIO_FORMAT_APE:
1218 id = SND_AUDIOCODEC_APE;
1219 break;
1220 case AUDIO_FORMAT_VORBIS:
1221 id = SND_AUDIOCODEC_VORBIS;
1222 break;
1223 case AUDIO_FORMAT_WMA:
1224 id = SND_AUDIOCODEC_WMA;
1225 break;
1226 case AUDIO_FORMAT_WMA_PRO:
1227 id = SND_AUDIOCODEC_WMA_PRO;
1228 break;
Satish Babu Patakokila0c313922016-12-08 12:07:08 +05301229 case AUDIO_FORMAT_MP2:
1230 id = SND_AUDIOCODEC_MP2;
1231 break;
Satish Babu Patakokila915ecba2017-01-10 17:43:56 +05301232 case AUDIO_FORMAT_AC3:
1233 id = SND_AUDIOCODEC_AC3;
1234 break;
1235 case AUDIO_FORMAT_E_AC3:
1236 case AUDIO_FORMAT_E_AC3_JOC:
1237 id = SND_AUDIOCODEC_EAC3;
1238 break;
1239 case AUDIO_FORMAT_DTS:
1240 case AUDIO_FORMAT_DTS_HD:
1241 id = SND_AUDIOCODEC_DTS;
1242 break;
Preetam Singh Ranawat4277a5a2017-01-18 19:02:24 +05301243 case AUDIO_FORMAT_DSD:
1244 id = SND_AUDIOCODEC_DSD;
1245 break;
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +05301246 case AUDIO_FORMAT_APTX:
1247 id = SND_AUDIOCODEC_APTX;
1248 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301249 default:
1250 ALOGE("%s: Unsupported audio format :%x", __func__, format);
1251 }
1252
1253 return id;
1254}
1255
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001256void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
1257 struct audio_usecase *usecase)
1258{
1259 int type = usecase->type;
1260
Dhananjay Kumar14245982017-01-16 20:21:00 +05301261 if (type == PCM_PLAYBACK && usecase->stream.out != NULL) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001262 struct stream_out *out = usecase->stream.out;
1263 int snd_device = usecase->out_snd_device;
1264 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08001265 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301266 platform_send_audio_calibration(adev->platform, usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001267 out->app_type_cfg.app_type,
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301268 usecase->stream.out->app_type_cfg.sample_rate);
Dhananjay Kumar14245982017-01-16 20:21:00 +05301269 } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301270 platform_send_audio_calibration(adev->platform, usecase,
1271 usecase->stream.in->app_type_cfg.app_type,
1272 usecase->stream.in->app_type_cfg.sample_rate);
Vidyakumar Athota653aaef2017-03-16 11:11:31 -07001273 } else if (type == PCM_HFP_CALL || type == PCM_CAPTURE) {
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301274 /* when app type is default. the sample rate is not used to send cal */
1275 platform_send_audio_calibration(adev->platform, usecase,
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301276 platform_get_default_app_type_v2(adev->platform, usecase->type),
1277 48000);
Vidyakumar Athotae57f6002017-03-01 13:13:16 -08001278 } else {
1279 /* No need to send audio calibration for voice and voip call usecases */
1280 if ((type != VOICE_CALL) && (type != VOIP_CALL))
1281 ALOGW("%s: No audio calibration for usecase type = %d", __func__, type);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001282 }
1283}
1284
Ben Rombergera04fabc2014-11-14 12:16:03 -08001285// Base64 Encode and Decode
1286// Not all features supported. This must be used only with following conditions.
1287// Decode Modes: Support with and without padding
1288// CRLF not handling. So no CRLF in string to decode.
1289// Encode Modes: Supports only padding
1290int b64decode(char *inp, int ilen, uint8_t* outp)
1291{
1292 int i, j, k, ii, num;
1293 int rem, pcnt;
1294 uint32_t res=0;
1295 uint8_t getIndex[MAX_BASEINDEX_LEN];
1296 uint8_t tmp, cflag;
1297
1298 if(inp == NULL || outp == NULL || ilen <= 0) {
1299 ALOGE("[%s] received NULL pointer or zero length",__func__);
1300 return -1;
1301 }
1302
1303 memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex));
1304 for(i=0;i<BASE_TABLE_SIZE;i++) {
1305 getIndex[(uint8_t)bTable[i]] = (uint8_t)i;
1306 }
1307 getIndex[(uint8_t)'=']=0;
1308
1309 j=0;k=0;
1310 num = ilen/4;
1311 rem = ilen%4;
1312 if(rem==0)
1313 num = num-1;
1314 cflag=0;
1315 for(i=0; i<num; i++) {
1316 res=0;
1317 for(ii=0;ii<4;ii++) {
1318 res = res << 6;
1319 tmp = getIndex[(uint8_t)inp[j++]];
1320 res = res | tmp;
1321 cflag = cflag | tmp;
1322 }
1323 outp[k++] = (res >> 16)&0xFF;
1324 outp[k++] = (res >> 8)&0xFF;
1325 outp[k++] = res & 0xFF;
1326 }
1327
1328 // Handle last bytes special
1329 pcnt=0;
1330 if(rem == 0) {
1331 //With padding or full data
1332 res = 0;
1333 for(ii=0;ii<4;ii++) {
1334 if(inp[j] == '=')
1335 pcnt++;
1336 res = res << 6;
1337 tmp = getIndex[(uint8_t)inp[j++]];
1338 res = res | tmp;
1339 cflag = cflag | tmp;
1340 }
1341 outp[k++] = res >> 16;
1342 if(pcnt == 2)
1343 goto done;
1344 outp[k++] = (res>>8)&0xFF;
1345 if(pcnt == 1)
1346 goto done;
1347 outp[k++] = res&0xFF;
1348 } else {
1349 //without padding
1350 res = 0;
1351 for(i=0;i<rem;i++) {
1352 res = res << 6;
1353 tmp = getIndex[(uint8_t)inp[j++]];
1354 res = res | tmp;
1355 cflag = cflag | tmp;
1356 }
1357 for(i=rem;i<4;i++) {
1358 res = res << 6;
1359 pcnt++;
1360 }
1361 outp[k++] = res >> 16;
1362 if(pcnt == 2)
1363 goto done;
1364 outp[k++] = (res>>8)&0xFF;
1365 if(pcnt == 1)
1366 goto done;
1367 outp[k++] = res&0xFF;
1368 }
1369done:
1370 if(cflag == 0xFF) {
1371 ALOGE("[%s] base64 decode failed. Invalid character found %s",
1372 __func__, inp);
1373 return 0;
1374 }
1375 return k;
1376}
1377
1378int b64encode(uint8_t *inp, int ilen, char* outp)
1379{
1380 int i,j,k, num;
1381 int rem=0;
1382 uint32_t res=0;
1383
1384 if(inp == NULL || outp == NULL || ilen<=0) {
1385 ALOGE("[%s] received NULL pointer or zero input length",__func__);
1386 return -1;
1387 }
1388
1389 num = ilen/3;
1390 rem = ilen%3;
1391 j=0;k=0;
1392 for(i=0; i<num; i++) {
1393 //prepare index
1394 res = inp[j++]<<16;
1395 res = res | inp[j++]<<8;
1396 res = res | inp[j++];
1397 //get output map from index
1398 outp[k++] = (char) bTable[(res>>18)&0x3F];
1399 outp[k++] = (char) bTable[(res>>12)&0x3F];
1400 outp[k++] = (char) bTable[(res>>6)&0x3F];
1401 outp[k++] = (char) bTable[res&0x3F];
1402 }
1403
1404 switch(rem) {
1405 case 1:
1406 res = inp[j++]<<16;
1407 outp[k++] = (char) bTable[res>>18];
1408 outp[k++] = (char) bTable[(res>>12)&0x3F];
1409 //outp[k++] = '=';
1410 //outp[k++] = '=';
1411 break;
1412 case 2:
1413 res = inp[j++]<<16;
1414 res = res | inp[j++]<<8;
1415 outp[k++] = (char) bTable[res>>18];
1416 outp[k++] = (char) bTable[(res>>12)&0x3F];
1417 outp[k++] = (char) bTable[(res>>6)&0x3F];
1418 //outp[k++] = '=';
1419 break;
1420 default:
1421 break;
1422 }
Ben Rombergera04fabc2014-11-14 12:16:03 -08001423 outp[k] = '\0';
1424 return k;
1425}
Ashish Jain81eb2a82015-05-13 10:52:34 +05301426
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301427
1428int audio_extn_utils_get_codec_version(const char *snd_card_name,
1429 int card_num,
1430 char *codec_version)
1431{
1432 char procfs_path[50];
1433 FILE *fp;
1434
1435 if (strstr(snd_card_name, "tasha")) {
1436 snprintf(procfs_path, sizeof(procfs_path),
1437 "/proc/asound/card%d/codecs/tasha/version", card_num);
1438 if ((fp = fopen(procfs_path, "r")) != NULL) {
1439 fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp);
1440 fclose(fp);
1441 } else {
1442 ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path);
1443 return -ENOENT;
1444 }
1445 ALOGD("%s: codec version %s", __func__, codec_version);
1446 }
1447
1448 return 0;
1449}
1450
1451
Ashish Jain81eb2a82015-05-13 10:52:34 +05301452#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
1453
1454void get_default_compressed_channel_status(
1455 unsigned char *channel_status)
1456{
Ashish Jain81eb2a82015-05-13 10:52:34 +05301457 memset(channel_status,0,24);
1458
1459 /* block start bit in preamble bit 3 */
1460 channel_status[0] |= PROFESSIONAL;
1461 //compre out
1462 channel_status[0] |= NON_LPCM;
1463 // sample rate; fixed 48K for default/transcode
1464 channel_status[3] |= SR_48000;
1465}
1466
1467#ifdef HDMI_PASSTHROUGH_ENABLED
1468int32_t get_compressed_channel_status(void *audio_stream_data,
1469 uint32_t audio_frame_size,
1470 unsigned char *channel_status,
1471 enum audio_parser_code_type codec_type)
1472 // codec_type - AUDIO_PARSER_CODEC_AC3
1473 // - AUDIO_PARSER_CODEC_DTS
1474{
1475 unsigned char *stream;
1476 int ret = 0;
1477 stream = (unsigned char *)audio_stream_data;
1478
1479 if (audio_stream_data == NULL || audio_frame_size == 0) {
1480 ALOGW("no buffer to get channel status, return default for compress");
1481 get_default_compressed_channel_status(channel_status);
1482 return ret;
1483 }
1484
1485 memset(channel_status,0,24);
1486 if(init_audio_parser(stream, audio_frame_size, codec_type) == -1)
1487 {
1488 ALOGE("init audio parser failed");
1489 return -1;
1490 }
1491 ret = get_channel_status(channel_status, codec_type);
1492 return ret;
1493
1494}
1495
1496#endif
1497
1498void get_lpcm_channel_status(uint32_t sampleRate,
1499 unsigned char *channel_status)
1500{
1501 int32_t status = 0;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301502 memset(channel_status,0,24);
1503 /* block start bit in preamble bit 3 */
1504 channel_status[0] |= PROFESSIONAL;
1505 //LPCM OUT
1506 channel_status[0] &= ~NON_LPCM;
1507
1508 switch (sampleRate) {
1509 case 8000:
1510 case 11025:
1511 case 12000:
1512 case 16000:
1513 case 22050:
1514 channel_status[3] |= SR_NOTID;
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301515 break;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301516 case 24000:
1517 channel_status[3] |= SR_24000;
1518 break;
1519 case 32000:
1520 channel_status[3] |= SR_32000;
1521 break;
1522 case 44100:
1523 channel_status[3] |= SR_44100;
1524 break;
1525 case 48000:
1526 channel_status[3] |= SR_48000;
1527 break;
1528 case 88200:
1529 channel_status[3] |= SR_88200;
1530 break;
1531 case 96000:
1532 channel_status[3] |= SR_96000;
1533 break;
1534 case 176400:
1535 channel_status[3] |= SR_176400;
1536 break;
1537 case 192000:
1538 channel_status[3] |= SR_192000;
1539 break;
1540 default:
1541 ALOGV("Invalid sample_rate %u\n", sampleRate);
1542 status = -1;
1543 break;
1544 }
1545}
1546
1547void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes)
1548{
1549 unsigned char channel_status[24]={0};
1550 struct snd_aes_iec958 iec958;
1551 const char *mixer_ctl_name = "IEC958 Playback PCM Stream";
1552 struct mixer_ctl *ctl;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301553 ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes);
Ashish Jain81eb2a82015-05-13 10:52:34 +05301554#ifdef HDMI_PASSTHROUGH_ENABLED
1555 if (audio_extn_is_dolby_format(out->format) &&
1556 /*TODO:Extend code to support DTS passthrough*/
1557 /*set compressed channel status bits*/
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05301558 audio_extn_passthru_is_passthrough_stream(out)){
Ashish Jain81eb2a82015-05-13 10:52:34 +05301559 get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3);
1560 } else
1561#endif
1562 {
1563 /*set channel status bit for LPCM*/
1564 get_lpcm_channel_status(out->sample_rate, channel_status);
1565 }
1566
1567 memcpy(iec958.status, channel_status,sizeof(iec958.status));
1568 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name);
1569 if (!ctl) {
1570 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1571 __func__, mixer_ctl_name);
1572 return;
1573 }
1574 if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) {
1575 ALOGE("%s: Could not set channel status for ext HDMI ",
1576 __func__);
1577 return;
1578 }
1579
1580}
1581#endif
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301582
1583int audio_extn_utils_get_avt_device_drift(
1584 struct audio_usecase *usecase,
1585 struct audio_avt_device_drift_param *drift_param)
1586{
1587 int ret = 0, count = 0;
1588 char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
1589 struct mixer_ctl *ctl = NULL;
1590 struct audio_avt_device_drift_stats drift_stats;
1591 struct audio_device *adev = NULL;
1592
1593 if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
1594 adev = usecase->stream.out->dev;
1595 switch(usecase->out_snd_device) {
1596 case SND_DEVICE_OUT_HDMI:
1597 strlcpy(avt_device_drift_mixer_ctl_name,
1598 "HDMI RX Drift",
1599 MIXER_PATH_MAX_LENGTH);
1600 break;
1601 case SND_DEVICE_OUT_DISPLAY_PORT:
1602 strlcpy(avt_device_drift_mixer_ctl_name,
1603 "DISPLAY Port RX Drift",
1604 MIXER_PATH_MAX_LENGTH);
1605 break;
1606 default :
1607 ALOGE("%s: Unsupported device %d",__func__,
1608 usecase->stream.out->devices);
1609 ret = -EINVAL;
1610 }
1611 } else {
1612 ALOGE("%s: Invalid usecase %d ",__func__, usecase->type);
1613 ret = -EINVAL;
1614 }
1615
1616 if(ret)
1617 goto done;
1618
1619 ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name);
1620 if (!ctl) {
1621 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1622 __func__, avt_device_drift_mixer_ctl_name);
1623
1624 ret = -EINVAL;
1625 goto done;
1626 }
1627
1628 ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__,
1629 avt_device_drift_mixer_ctl_name);
1630
1631 mixer_ctl_update(ctl);
1632 count = mixer_ctl_get_num_values(ctl);
1633 if (count != sizeof(struct audio_avt_device_drift_stats)) {
1634 ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size",
1635 __func__);
1636
1637 ret = -EINVAL;
1638 goto done;
1639 }
1640
1641 ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count);
1642 if (ret != 0) {
1643 ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params",
1644 __func__);
1645
1646 ret = -EINVAL;
1647 goto done;
1648 }
1649 memcpy(drift_param, &drift_stats.drift_param,
1650 sizeof(struct audio_avt_device_drift_param));
1651done:
1652 return ret;
1653}