blob: e9c8ac08db7b62e04fcca7dde03aba8affaeef76 [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),
vivek mehta0ea887a2015-08-26 14:01:20 -070092 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070093 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
94 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST),
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -080095 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070096 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
97 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
98 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070099 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700100#ifdef INCALL_MUSIC_ENABLED
101 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC),
102#endif
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700103 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH),
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530104 STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE),
105 STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST),
106 STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
107 STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW),
108 STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC),
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530109 STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700110};
111
112const struct string_to_enum s_format_name_to_enum_table[] = {
Ashish Jain83a6cc22016-06-28 14:34:17 +0530113 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700114 STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT),
Ashish Jain5106d362016-05-11 19:23:33 +0530115 STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
116 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
Ashish Jainf1eaa582016-05-23 20:54:24 +0530117 STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700118 STRING_TO_ENUM(AUDIO_FORMAT_MP3),
119 STRING_TO_ENUM(AUDIO_FORMAT_AAC),
120 STRING_TO_ENUM(AUDIO_FORMAT_VORBIS),
Mingming Yinae3530f2014-07-03 16:50:18 -0700121 STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB),
122 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700123 STRING_TO_ENUM(AUDIO_FORMAT_AC3),
Mingming Yinae3530f2014-07-03 16:50:18 -0700124 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700125 STRING_TO_ENUM(AUDIO_FORMAT_DTS),
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530126 STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD),
127#ifdef AUDIO_EXTN_FORMATS_ENABLED
128 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700129 STRING_TO_ENUM(AUDIO_FORMAT_WMA),
130 STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO),
131 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700132 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS),
133 STRING_TO_ENUM(AUDIO_FORMAT_EVRC),
134 STRING_TO_ENUM(AUDIO_FORMAT_EVRCB),
135 STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB),
136 STRING_TO_ENUM(AUDIO_FORMAT_QCELP),
137 STRING_TO_ENUM(AUDIO_FORMAT_MP2),
138 STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW),
Amit Shekhar6f461b12014-08-01 14:52:58 -0700139 STRING_TO_ENUM(AUDIO_FORMAT_FLAC),
Satya Krishna Pindiproli70471602015-04-24 19:12:43 +0530140 STRING_TO_ENUM(AUDIO_FORMAT_ALAC),
141 STRING_TO_ENUM(AUDIO_FORMAT_APE),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700142 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Alexy Josephcd8eaed2014-12-11 12:46:53 -0800143 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC),
144 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1),
145 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2),
Manish Dewangana6fc5442015-08-24 20:30:31 +0530146 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS),
Ashish Jaine513a872015-11-19 17:00:56 +0530147 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC),
148 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1),
149 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2),
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530150 STRING_TO_ENUM(AUDIO_FORMAT_DSD),
Arun Kumar Dasari3b174182016-12-27 13:01:14 +0530151 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM),
152 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC),
153 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1),
154 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2),
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +0530155 STRING_TO_ENUM(AUDIO_FORMAT_APTX),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700156#endif
157};
158
Manish Dewangan3ccdea52017-02-13 19:31:54 +0530159/* payload structure avt_device drift query */
160struct audio_avt_device_drift_stats {
161 uint32_t minor_version;
162 /* Indicates the device interface direction as either
163 * source (Tx) or sink (Rx).
164 */
165 uint16_t device_direction;
166 /*params exposed to client */
167 struct audio_avt_device_drift_param drift_param;
168};
169
Ben Rombergera04fabc2014-11-14 12:16:03 -0800170static char bTable[BASE_TABLE_SIZE] = {
171 'A','B','C','D','E','F','G','H','I','J','K','L',
172 'M','N','O','P','Q','R','S','T','U','V','W','X',
173 'Y','Z','a','b','c','d','e','f','g','h','i','j',
174 'k','l','m','n','o','p','q','r','s','t','u','v',
175 'w','x','y','z','0','1','2','3','4','5','6','7',
176 '8','9','+','/'
177};
178
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700179static uint32_t string_to_enum(const struct string_to_enum *table, size_t size,
180 const char *name)
181{
182 size_t i;
183 for (i = 0; i < size; i++) {
184 if (strcmp(table[i].name, name) == 0) {
185 ALOGV("%s found %s", __func__, table[i].name);
186 return table[i].value;
187 }
188 }
189 return 0;
190}
191
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530192static audio_io_flags_t parse_flag_names(char *name)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700193{
194 uint32_t flag = 0;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530195 audio_io_flags_t io_flags;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800196 char *last_r;
197 char *flag_name = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700198 while (flag_name != NULL) {
199 if (strlen(flag_name) != 0) {
200 flag |= string_to_enum(s_flag_name_to_enum_table,
201 ARRAY_SIZE(s_flag_name_to_enum_table),
202 flag_name);
203 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800204 flag_name = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700205 }
206
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800207 ALOGV("parse_flag_names: flag - %x", flag);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530208 io_flags.in_flags = (audio_input_flags_t)flag;
209 io_flags.out_flags = (audio_output_flags_t)flag;
210 return io_flags;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700211}
212
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530213static void parse_format_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700214{
215 struct stream_format *sf_info = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800216 char *last_r;
217 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700218
219 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0)
220 return;
221
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530222 list_init(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700223 while (str != NULL) {
224 audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table,
225 ARRAY_SIZE(s_format_name_to_enum_table), str);
226 ALOGV("%s: format - %d", __func__, format);
227 if (format != 0) {
228 sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700229 if (sf_info == NULL)
230 break; /* return whatever was parsed */
231
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700232 sf_info->format = format;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530233 list_add_tail(&s_info->format_list, &sf_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700234 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800235 str = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700236 }
237}
238
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530239static void parse_sample_rate_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700240{
Amit Shekhar6f461b12014-08-01 14:52:58 -0700241 struct stream_sample_rate *ss_info = NULL;
242 uint32_t sample_rate = 48000;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800243 char *last_r;
244 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700245
Amit Shekhar6f461b12014-08-01 14:52:58 -0700246 if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG))
247 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700248
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530249 list_init(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700250 while (str != NULL) {
251 sample_rate = (uint32_t)strtol(str, (char **)NULL, 10);
252 ALOGV("%s: sample_rate - %d", __func__, sample_rate);
253 if (0 != sample_rate) {
254 ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate));
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800255 if (!ss_info) {
256 ALOGE("%s: memory allocation failure", __func__);
257 return;
258 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700259 ss_info->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530260 list_add_tail(&s_info->sample_rate_list, &ss_info->list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700261 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800262 str = strtok_r(NULL, "|", &last_r);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700263 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700264}
265
266static int parse_bit_width_names(char *name)
267{
268 int bit_width = 16;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800269 char *last_r;
270 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700271
272 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
273 bit_width = (int)strtol(str, (char **)NULL, 10);
274
275 ALOGV("%s: bit_width - %d", __func__, bit_width);
276 return bit_width;
277}
278
279static int parse_app_type_names(void *platform, char *name)
280{
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700281 int app_type = platform_get_default_app_type(platform);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800282 char *last_r;
283 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700284
285 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
286 app_type = (int)strtol(str, (char **)NULL, 10);
287
288 ALOGV("%s: app_type - %d", __func__, app_type);
289 return app_type;
290}
291
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530292static void update_streams_cfg_list(cnode *root, void *platform,
293 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700294{
295 cnode *node = root->first_child;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530296 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700297
298 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530299 s_info = (struct streams_io_cfg *)calloc(1, sizeof(struct streams_io_cfg));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700300
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530301 if (!s_info) {
302 ALOGE("failed to allocate mem for s_info list element");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700303 return;
304 }
305
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700306 while (node) {
307 if (strcmp(node->name, FLAGS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530308 s_info->flags = parse_flag_names((char *)node->value);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530309 } else if (strcmp(node->name, PROFILES_TAG) == 0) {
310 strlcpy(s_info->profile, (char *)node->value, sizeof(s_info->profile));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700311 } else if (strcmp(node->name, FORMATS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530312 parse_format_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700313 } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530314 s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
315 parse_sample_rate_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700316 } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530317 s_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700318 } else if (strcmp(node->name, APP_TYPE_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530319 s_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700320 }
321 node = node->next;
322 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530323 list_add_tail(streams_cfg_list, &s_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700324}
325
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530326static void load_cfg_list(cnode *root, void *platform,
327 struct listnode *streams_output_cfg_list,
328 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700329{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530330 cnode *node = NULL;
331
332 node = config_find(root, OUTPUTS_TAG);
333 if (node != NULL) {
334 node = node->first_child;
335 while (node) {
336 ALOGV("%s: loading output %s", __func__, node->name);
337 update_streams_cfg_list(node, platform, streams_output_cfg_list);
338 node = node->next;
339 }
340 } else {
341 ALOGI("%s: could not load output, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700342 }
343
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530344 node = config_find(root, INPUTS_TAG);
345 if (node != NULL) {
346 node = node->first_child;
347 while (node) {
348 ALOGV("%s: loading input %s", __func__, node->name);
349 update_streams_cfg_list(node, platform, streams_input_cfg_list);
350 node = node->next;
351 }
352 } else {
353 ALOGI("%s: could not load input, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700354 }
355}
356
357static void send_app_type_cfg(void *platform, struct mixer *mixer,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530358 struct listnode *streams_output_cfg_list,
359 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700360{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530361 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700362 int length = 0, i, num_app_types = 0;
363 struct listnode *node;
364 bool update;
365 struct mixer_ctl *ctl = NULL;
366 const char *mixer_ctl_name = "App Type Config";
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530367 struct streams_io_cfg *s_info = NULL;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700368
369 if (!mixer) {
370 ALOGE("%s: mixer is null",__func__);
371 return;
372 }
373 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
374 if (!ctl) {
375 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
376 return;
377 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530378 app_type_cfg[length++] = num_app_types;
379
380 if (list_empty(streams_output_cfg_list)) {
381 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_PLAYBACK);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700382 app_type_cfg[length++] = 48000;
383 app_type_cfg[length++] = 16;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530384 num_app_types += 1;
385 }
386 if (list_empty(streams_input_cfg_list)) {
387 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
388 app_type_cfg[length++] = 48000;
389 app_type_cfg[length++] = 16;
390 num_app_types += 1;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700391 }
392
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700393 list_for_each(node, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530394 s_info = node_to_item(node, struct streams_io_cfg, list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700395 update = true;
396 for (i=0; i<length; i=i+3) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530397 if (app_type_cfg[i+1] == 0)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700398 break;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530399 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530400 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530401 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530402 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530403 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700404 update = false;
405 break;
406 }
407 }
408 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530409 num_app_types += 1;
410 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
411 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
412 app_type_cfg[length++] = s_info->app_type_cfg.bit_width;
413 }
414 }
415 list_for_each(node, streams_input_cfg_list) {
416 s_info = node_to_item(node, struct streams_io_cfg, list);
417 update = true;
418 for (i=0; i<length; i=i+3) {
419 if (app_type_cfg[i+1] == 0)
420 break;
421 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530422 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530423 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530424 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530425 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
426 update = false;
427 break;
428 }
429 }
430 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
431 num_app_types += 1;
432 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
433 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
434 app_type_cfg[length++] = s_info->app_type_cfg.bit_width;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700435 }
436 }
437 ALOGV("%s: num_app_types: %d", __func__, num_app_types);
438 if (num_app_types) {
439 app_type_cfg[0] = num_app_types;
440 mixer_ctl_set_array(ctl, app_type_cfg, length);
441 }
442}
443
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530444void audio_extn_utils_update_streams_cfg_lists(void *platform,
445 struct mixer *mixer,
446 struct listnode *streams_output_cfg_list,
447 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700448{
449 cnode *root;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530450 char *data = NULL;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700451
452 ALOGV("%s", __func__);
453 list_init(streams_output_cfg_list);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530454 list_init(streams_input_cfg_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700455
456 root = config_node("", "");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700457 if (root == NULL) {
458 ALOGE("cfg_list, NULL config root");
459 return;
460 }
461
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530462 data = (char *)load_file(AUDIO_IO_POLICY_VENDOR_CONFIG_FILE, NULL);
463 if (data == NULL) {
464 ALOGD("%s: failed to open io config file(%s), trying older config file",
465 __func__, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE);
466 data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL);
467 if (data == NULL) {
468 send_app_type_cfg(platform, mixer,
469 streams_output_cfg_list,
470 streams_input_cfg_list);
471 ALOGE("%s: could not load io policy config!", __func__);
472 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);
484 free(data);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700485}
486
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530487static void audio_extn_utils_dump_streams_cfg_list(
488 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700489{
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700490 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530491 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700492 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700493 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530494
495 list_for_each(node_i, streams_cfg_list) {
496 s_info = node_to_item(node_i, struct streams_io_cfg, list);
497 ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d",
498 __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate,
499 s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type);
500 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700501 sf_info = node_to_item(node_j, struct stream_format, list);
502 ALOGV("format-%x", sf_info->format);
503 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530504 list_for_each(node_j, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700505 ss_info = node_to_item(node_j, struct stream_sample_rate, list);
506 ALOGV("sample rate-%d", ss_info->sample_rate);
507 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700508 }
509}
510
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530511void audio_extn_utils_dump_streams_cfg_lists(
512 struct listnode *streams_output_cfg_list,
513 struct listnode *streams_input_cfg_list)
514{
515 ALOGV("%s", __func__);
516 audio_extn_utils_dump_streams_cfg_list(streams_output_cfg_list);
517 audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list);
518}
519
520static void audio_extn_utils_release_streams_cfg_list(
521 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700522{
523 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530524 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700525
526 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530527
528 while (!list_empty(streams_cfg_list)) {
529 node_i = list_head(streams_cfg_list);
530 s_info = node_to_item(node_i, struct streams_io_cfg, list);
531 while (!list_empty(&s_info->format_list)) {
532 node_j = list_head(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700533 list_remove(node_j);
534 free(node_to_item(node_j, struct stream_format, list));
535 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530536 while (!list_empty(&s_info->sample_rate_list)) {
537 node_j = list_head(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700538 list_remove(node_j);
539 free(node_to_item(node_j, struct stream_sample_rate, list));
540 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700541 list_remove(node_i);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530542 free(node_to_item(node_i, struct streams_io_cfg, list));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700543 }
544}
545
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530546void audio_extn_utils_release_streams_cfg_lists(
547 struct listnode *streams_output_cfg_list,
548 struct listnode *streams_input_cfg_list)
549{
550 ALOGV("%s", __func__);
551 audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list);
552 audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list);
553}
554
555static bool set_app_type_cfg(struct streams_io_cfg *s_info,
556 struct stream_app_type_cfg *app_type_cfg,
557 uint32_t sample_rate, uint32_t bit_width)
Amit Shekhar6f461b12014-08-01 14:52:58 -0700558 {
559 struct listnode *node_i;
560 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530561 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700562 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
563 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530564 (bit_width == s_info->app_type_cfg.bit_width)) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700565
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530566 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700567 app_type_cfg->sample_rate = ss_info->sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530568 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700569 ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
570 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
571 return true;
572 }
573 }
574 /*
575 * Reiterate through the list assuming dafault sample rate.
576 * Handles scenario where input sample rate is higher
577 * than all sample rates in list for the input bit width.
578 */
579 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800580
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530581 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700582 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
583 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530584 (bit_width == s_info->app_type_cfg.bit_width)) {
585 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700586 app_type_cfg->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530587 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800588 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 -0700589 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
590 return true;
591 }
592 }
593 return false;
594}
595
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530596void audio_extn_utils_update_stream_input_app_type_cfg(void *platform,
597 struct listnode *streams_input_cfg_list,
598 audio_devices_t devices __unused,
599 audio_input_flags_t flags,
600 audio_format_t format,
601 uint32_t sample_rate,
602 uint32_t bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530603 char* profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530604 struct stream_app_type_cfg *app_type_cfg)
605{
606 struct listnode *node_i, *node_j;
607 struct streams_io_cfg *s_info;
608 struct stream_format *sf_info;
609
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530610 ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s",
611 __func__, flags, format, sample_rate, profile);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530612
613 list_for_each(node_i, streams_input_cfg_list) {
614 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530615 /* Along with flags do profile matching if set at either end.*/
616 if (s_info->flags.in_flags == flags &&
617 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
618 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530619 list_for_each(node_j, &s_info->format_list) {
620 sf_info = node_to_item(node_j, struct stream_format, list);
621 if (sf_info->format == format) {
622 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
623 return;
624 }
625 }
626 }
627 }
628 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
629 app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
630 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
631 app_type_cfg->bit_width = 16;
632}
633
634void audio_extn_utils_update_stream_output_app_type_cfg(void *platform,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700635 struct listnode *streams_output_cfg_list,
Amit Shekhar1d896042014-10-03 13:16:09 -0700636 audio_devices_t devices,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700637 audio_output_flags_t flags,
638 audio_format_t format,
Amit Shekhar6f461b12014-08-01 14:52:58 -0700639 uint32_t sample_rate,
640 uint32_t bit_width,
Manish Dewangan837dc462015-05-27 10:17:41 +0530641 audio_channel_mask_t channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530642 char *profile,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700643 struct stream_app_type_cfg *app_type_cfg)
644{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530645 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530646 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700647 struct stream_format *sf_info;
Manish Dewangan837dc462015-05-27 10:17:41 +0530648 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700649
Ashish Jain058165c2016-09-28 23:18:48 +0530650 if ((bit_width >= 24) &&
Amit Shekhar1d896042014-10-03 13:16:09 -0700651 (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Amit Shekhar5a39c912014-10-14 15:39:30 -0700652 int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
653 if (-ENOSYS != bw)
654 bit_width = (uint32_t)bw;
Amit Shekhar1d896042014-10-03 13:16:09 -0700655 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
656 ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
657 }
658
Manish Dewangan837dc462015-05-27 10:17:41 +0530659 property_get("audio.playback.mch.downsample",value,"");
660 if (!strncmp("true", value, sizeof("true"))) {
661 if ((popcount(channel_mask) > 2) &&
662 (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
663 !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
664 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
665 ALOGD("%s: MCH session defaulting sample rate to %d",
666 __func__, sample_rate);
667 }
668 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530669
670 /* Set sampling rate to 176.4 for DSD64
671 * and 352.8Khz for DSD128.
672 * Set Bit Width to 16. output will be 16 bit
673 * post DoP in ASM.
674 */
675 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) &&
676 (format == AUDIO_FORMAT_DSD)) {
677 bit_width = 16;
678 if (sample_rate == INPUT_SAMPLING_RATE_DSD64)
679 sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
680 else if (sample_rate == INPUT_SAMPLING_RATE_DSD128)
681 sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
682 }
683
Naresh Tanniruf5ba8d02016-09-29 18:06:37 +0530684 if(devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
685 //TODO: Handle fractional sampling rate configuration for LL
686 audio_extn_a2dp_get_apptype_params(&sample_rate, &bit_width);
687 ALOGI("%s using %d sampling rate %d bit width for A2DP CoPP",
688 __func__, sample_rate, bit_width);
689 }
690
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800691 ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d",
692 __func__, flags, format, sample_rate, profile, app_type_cfg->app_type);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700693 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530694 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530695 /* Along with flags do profile matching if set at either end.*/
696 if (s_info->flags.out_flags == flags &&
697 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
698 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530699 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700700 sf_info = node_to_item(node_j, struct stream_format, list);
701 if (sf_info->format == format) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530702 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
Amit Shekhar6f461b12014-08-01 14:52:58 -0700703 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700704 }
705 }
706 }
707 }
708 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530709 s_info = node_to_item(node_i, struct streams_io_cfg, list);
710 if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700711 ALOGV("Compatible output profile not found.");
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530712 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
713 app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate;
714 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700715 ALOGV("%s Default to primary output: App type: %d sample_rate %d",
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530716 __func__, s_info->app_type_cfg.app_type, app_type_cfg->sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700717 return;
718 }
719 }
720 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700721 app_type_cfg->app_type = platform_get_default_app_type(platform);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700722 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700723 app_type_cfg->bit_width = 16;
724}
725
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530726static bool audio_is_this_native_usecase(struct audio_usecase *uc)
727{
728 bool native_usecase = false;
729 struct stream_out *out = (struct stream_out*) uc->stream.out;
730
731 if (PCM_PLAYBACK == uc->type && out != NULL &&
732 NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() &&
733 is_offload_usecase(uc->id) &&
734 (out->sample_rate == OUTPUT_SAMPLING_RATE_44100))
735 native_usecase = true;
736
737 return native_usecase;
738}
739
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800740
741static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev))
742{
743 return adev->vr_audio_mode_enabled;
744}
745
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530746void audio_extn_utils_update_stream_app_type_cfg_for_usecase(
747 struct audio_device *adev,
748 struct audio_usecase *usecase)
749{
750 ALOGV("%s", __func__);
751
752 switch(usecase->type) {
753 case PCM_PLAYBACK:
754 audio_extn_utils_update_stream_output_app_type_cfg(adev->platform,
755 &adev->streams_output_cfg_list,
756 usecase->stream.out->devices,
757 usecase->stream.out->flags,
758 usecase->stream.out->format,
759 usecase->stream.out->sample_rate,
760 usecase->stream.out->bit_width,
761 usecase->stream.out->channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530762 usecase->stream.out->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530763 &usecase->stream.out->app_type_cfg);
764 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
765 break;
766 case PCM_CAPTURE:
767 audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
768 &adev->streams_input_cfg_list,
769 usecase->stream.in->device,
770 usecase->stream.in->flags,
771 usecase->stream.in->format,
772 usecase->stream.in->sample_rate,
773 usecase->stream.in->bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530774 usecase->stream.in->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530775 &usecase->stream.in->app_type_cfg);
776 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type);
777 break;
778 default:
779 ALOGE("%s: app type cfg not supported for usecase type (%d)",
780 __func__, usecase->type);
781 }
782}
783
Siena Richard7c2db772016-12-21 11:32:34 -0800784static int send_app_type_cfg_for_device(struct audio_device *adev,
785 struct audio_usecase *usecase,
786 int split_snd_device)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700787{
788 char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT];
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530789 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
790 int len = 0, rc;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700791 struct mixer_ctl *ctl;
Siena Richard7c2db772016-12-21 11:32:34 -0800792 int pcm_device_id = 0, acdb_dev_id, app_type;
793 int snd_device = split_snd_device, snd_device_be_idx = -1;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530794 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Manish Dewangan837dc462015-05-27 10:17:41 +0530795 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700796
Siena Richard7c2db772016-12-21 11:32:34 -0800797 ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s",
798 __func__, platform_get_snd_device_name(usecase->out_snd_device),
799 platform_get_snd_device_name(usecase->in_snd_device),
800 platform_get_snd_device_name(split_snd_device));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700801
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530802 if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530803 ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700804 rc = 0;
805 goto exit_send_app_type_cfg;
806 }
807 if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) &&
808 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
809 (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800810 (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530811 (!is_offload_usecase(usecase->id)) &&
812 (usecase->type != PCM_CAPTURE)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530813 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 -0700814 rc = 0;
815 goto exit_send_app_type_cfg;
816 }
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800817
818 //if VR is active then only send the mixer control
819 if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) {
820 ALOGI("ULL doesnt need sending app type cfg, returning");
821 rc = 0;
822 goto exit_send_app_type_cfg;
823 }
824
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530825 if (usecase->type == PCM_PLAYBACK) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700826 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530827 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
828 "Audio Stream %d App Type Cfg", pcm_device_id);
Ben Romberger1fafdde2015-09-09 19:43:15 -0700829 } else if (usecase->type == PCM_CAPTURE) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700830 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530831 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
832 "Audio Stream Capture %d App Type Cfg", pcm_device_id);
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530833 }
Siena Richard7c2db772016-12-21 11:32:34 -0800834
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700835 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
836 if (!ctl) {
837 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__,
838 mixer_ctl_name);
839 rc = -EINVAL;
840 goto exit_send_app_type_cfg;
841 }
842 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +0800843 platform_get_spkr_prot_snd_device(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 Athotae57f6002017-03-01 13:13:16 -08001272 } else if (type == PCM_HFP_CALL) {
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}