blob: 303cb63faefc22fd090a2fb5b82de32a8474f3c4 [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
Manish Dewangan27346042017-03-01 12:56:12 +053023#include <inttypes.h>
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070024#include <errno.h>
25#include <cutils/properties.h>
26#include <cutils/config_utils.h>
27#include <stdlib.h>
28#include <dlfcn.h>
29#include <cutils/str_parms.h>
30#include <cutils/log.h>
31#include <cutils/misc.h>
32
Manish Dewangan07de2142017-02-27 19:27:20 +053033
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070034#include "audio_hw.h"
35#include "platform.h"
36#include "platform_api.h"
37#include "audio_extn.h"
Narsinga Rao Chella212e2542014-11-17 19:57:04 -080038#include "voice.h"
Manish Dewangan07de2142017-02-27 19:27:20 +053039#include <sound/compress_params.h>
40#include <sound/compress_offload.h>
41#include <tinycompress/tinycompress.h>
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053042
43#ifdef DYNAMIC_LOG_ENABLED
44#include <log_xml_parser.h>
45#define LOG_MASK HAL_MOD_FILE_UTILS
46#include <log_utils.h>
47#endif
48
Ashish Jain81eb2a82015-05-13 10:52:34 +053049#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
50#ifdef HDMI_PASSTHROUGH_ENABLED
51#include "audio_parsers.h"
52#endif
53#endif
54
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053055#ifdef LINUX_ENABLED
56#define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/etc/audio_output_policy.conf"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053057#define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/etc/audio_io_policy.conf"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053058#else
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070059#define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053060#define AUDIO_IO_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_io_policy.conf"
Yamit Mehtaa0d653a2016-11-25 20:33:25 +053061#endif
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070062
63#define OUTPUTS_TAG "outputs"
Dhananjay Kumard6d32152016-10-13 16:11:03 +053064#define INPUTS_TAG "inputs"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070065
66#define DYNAMIC_VALUE_TAG "dynamic"
67#define FLAGS_TAG "flags"
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +053068#define PROFILES_TAG "profile"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070069#define FORMATS_TAG "formats"
70#define SAMPLING_RATES_TAG "sampling_rates"
71#define BIT_WIDTH_TAG "bit_width"
72#define APP_TYPE_TAG "app_type"
73
74#define STRING_TO_ENUM(string) { #string, string }
75#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
76
Ben Rombergera04fabc2014-11-14 12:16:03 -080077#define BASE_TABLE_SIZE 64
78#define MAX_BASEINDEX_LEN 256
79
Ben Romberger1aaaf862017-04-06 17:49:46 -070080#ifndef SND_AUDIOCODEC_TRUEHD
81#define SND_AUDIOCODEC_TRUEHD 0x00000023
82#endif
83
Ashish Jain81eb2a82015-05-13 10:52:34 +053084#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
85#define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */
86#define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */
87#define SR_44100 (0<<0) /* 44.1kHz */
88#define SR_NOTID (1<<0) /* non indicated */
89#define SR_48000 (2<<0) /* 48kHz */
90#define SR_32000 (3<<0) /* 32kHz */
91#define SR_22050 (4<<0) /* 22.05kHz */
92#define SR_24000 (6<<0) /* 24kHz */
93#define SR_88200 (8<<0) /* 88.2kHz */
94#define SR_96000 (10<<0) /* 96kHz */
95#define SR_176400 (12<<0) /* 176.4kHz */
96#define SR_192000 (14<<0) /* 192kHz */
97
98#endif
Manish Dewangan07de2142017-02-27 19:27:20 +053099
100/* ToDo: Check and update a proper value in msec */
101#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50
102
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700103struct string_to_enum {
104 const char *name;
105 uint32_t value;
106};
107
108const struct string_to_enum s_flag_name_to_enum_table[] = {
109 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
110 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
111 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST),
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800112 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700113 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
114 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
115 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700116 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700117#ifdef INCALL_MUSIC_ENABLED
118 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC),
119#endif
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700120 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH),
Naresh Tanniruee3499a2017-01-05 14:05:35 +0530121 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_TIMESTAMP),
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530122 STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE),
123 STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST),
124 STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
125 STRING_TO_ENUM(AUDIO_INPUT_FLAG_RAW),
126 STRING_TO_ENUM(AUDIO_INPUT_FLAG_SYNC),
Dhananjay Kumaree4d2002016-10-25 18:02:58 +0530127 STRING_TO_ENUM(AUDIO_INPUT_FLAG_TIMESTAMP),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700128};
129
130const struct string_to_enum s_format_name_to_enum_table[] = {
Ashish Jain83a6cc22016-06-28 14:34:17 +0530131 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700132 STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT),
Ashish Jain5106d362016-05-11 19:23:33 +0530133 STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_PACKED),
134 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_24_BIT),
Ashish Jainf1eaa582016-05-23 20:54:24 +0530135 STRING_TO_ENUM(AUDIO_FORMAT_PCM_32_BIT),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700136 STRING_TO_ENUM(AUDIO_FORMAT_MP3),
137 STRING_TO_ENUM(AUDIO_FORMAT_AAC),
138 STRING_TO_ENUM(AUDIO_FORMAT_VORBIS),
Mingming Yinae3530f2014-07-03 16:50:18 -0700139 STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB),
140 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700141 STRING_TO_ENUM(AUDIO_FORMAT_AC3),
Mingming Yinae3530f2014-07-03 16:50:18 -0700142 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700143 STRING_TO_ENUM(AUDIO_FORMAT_DTS),
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530144 STRING_TO_ENUM(AUDIO_FORMAT_DTS_HD),
Ben Romberger1aaaf862017-04-06 17:49:46 -0700145 STRING_TO_ENUM(AUDIO_FORMAT_DOLBY_TRUEHD),
Naresh Tanniru928f0862017-04-07 16:44:23 -0700146 STRING_TO_ENUM(AUDIO_FORMAT_IEC61937),
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530147#ifdef AUDIO_EXTN_FORMATS_ENABLED
148 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700149 STRING_TO_ENUM(AUDIO_FORMAT_WMA),
150 STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO),
151 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700152 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS),
153 STRING_TO_ENUM(AUDIO_FORMAT_EVRC),
154 STRING_TO_ENUM(AUDIO_FORMAT_EVRCB),
155 STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB),
156 STRING_TO_ENUM(AUDIO_FORMAT_QCELP),
157 STRING_TO_ENUM(AUDIO_FORMAT_MP2),
158 STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW),
Amit Shekhar6f461b12014-08-01 14:52:58 -0700159 STRING_TO_ENUM(AUDIO_FORMAT_FLAC),
Satya Krishna Pindiproli70471602015-04-24 19:12:43 +0530160 STRING_TO_ENUM(AUDIO_FORMAT_ALAC),
161 STRING_TO_ENUM(AUDIO_FORMAT_APE),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700162 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Alexy Josephcd8eaed2014-12-11 12:46:53 -0800163 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC),
164 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1),
165 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2),
Manish Dewangana6fc5442015-08-24 20:30:31 +0530166 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS),
Ashish Jaine513a872015-11-19 17:00:56 +0530167 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_LC),
168 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V1),
169 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS_HE_V2),
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530170 STRING_TO_ENUM(AUDIO_FORMAT_DSD),
Arun Kumar Dasari3b174182016-12-27 13:01:14 +0530171 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM),
172 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC),
173 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1),
174 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2),
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +0530175 STRING_TO_ENUM(AUDIO_FORMAT_APTX),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700176#endif
177};
178
Manish Dewangan3ccdea52017-02-13 19:31:54 +0530179/* payload structure avt_device drift query */
180struct audio_avt_device_drift_stats {
181 uint32_t minor_version;
182 /* Indicates the device interface direction as either
183 * source (Tx) or sink (Rx).
184 */
185 uint16_t device_direction;
186 /*params exposed to client */
187 struct audio_avt_device_drift_param drift_param;
188};
189
Ben Rombergera04fabc2014-11-14 12:16:03 -0800190static char bTable[BASE_TABLE_SIZE] = {
191 'A','B','C','D','E','F','G','H','I','J','K','L',
192 'M','N','O','P','Q','R','S','T','U','V','W','X',
193 'Y','Z','a','b','c','d','e','f','g','h','i','j',
194 'k','l','m','n','o','p','q','r','s','t','u','v',
195 'w','x','y','z','0','1','2','3','4','5','6','7',
196 '8','9','+','/'
197};
198
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700199static uint32_t string_to_enum(const struct string_to_enum *table, size_t size,
200 const char *name)
201{
202 size_t i;
203 for (i = 0; i < size; i++) {
204 if (strcmp(table[i].name, name) == 0) {
205 ALOGV("%s found %s", __func__, table[i].name);
206 return table[i].value;
207 }
208 }
209 return 0;
210}
211
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530212static audio_io_flags_t parse_flag_names(char *name)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700213{
214 uint32_t flag = 0;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530215 audio_io_flags_t io_flags;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800216 char *last_r;
217 char *flag_name = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700218 while (flag_name != NULL) {
219 if (strlen(flag_name) != 0) {
220 flag |= string_to_enum(s_flag_name_to_enum_table,
221 ARRAY_SIZE(s_flag_name_to_enum_table),
222 flag_name);
223 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800224 flag_name = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700225 }
226
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800227 ALOGV("parse_flag_names: flag - %x", flag);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530228 io_flags.in_flags = (audio_input_flags_t)flag;
229 io_flags.out_flags = (audio_output_flags_t)flag;
230 return io_flags;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700231}
232
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530233static void parse_format_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700234{
235 struct stream_format *sf_info = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800236 char *last_r;
237 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700238
239 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0)
240 return;
241
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530242 list_init(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700243 while (str != NULL) {
244 audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table,
245 ARRAY_SIZE(s_format_name_to_enum_table), str);
246 ALOGV("%s: format - %d", __func__, format);
247 if (format != 0) {
248 sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700249 if (sf_info == NULL)
250 break; /* return whatever was parsed */
251
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700252 sf_info->format = format;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530253 list_add_tail(&s_info->format_list, &sf_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700254 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800255 str = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700256 }
257}
258
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530259static void parse_sample_rate_names(char *name, struct streams_io_cfg *s_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700260{
Amit Shekhar6f461b12014-08-01 14:52:58 -0700261 struct stream_sample_rate *ss_info = NULL;
262 uint32_t sample_rate = 48000;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800263 char *last_r;
264 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700265
Amit Shekhar6f461b12014-08-01 14:52:58 -0700266 if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG))
267 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700268
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530269 list_init(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700270 while (str != NULL) {
271 sample_rate = (uint32_t)strtol(str, (char **)NULL, 10);
272 ALOGV("%s: sample_rate - %d", __func__, sample_rate);
273 if (0 != sample_rate) {
274 ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate));
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800275 if (!ss_info) {
276 ALOGE("%s: memory allocation failure", __func__);
277 return;
278 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700279 ss_info->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530280 list_add_tail(&s_info->sample_rate_list, &ss_info->list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700281 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800282 str = strtok_r(NULL, "|", &last_r);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700283 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700284}
285
286static int parse_bit_width_names(char *name)
287{
288 int bit_width = 16;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800289 char *last_r;
290 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700291
292 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
293 bit_width = (int)strtol(str, (char **)NULL, 10);
294
295 ALOGV("%s: bit_width - %d", __func__, bit_width);
296 return bit_width;
297}
298
299static int parse_app_type_names(void *platform, char *name)
300{
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700301 int app_type = platform_get_default_app_type(platform);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800302 char *last_r;
303 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700304
305 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
306 app_type = (int)strtol(str, (char **)NULL, 10);
307
308 ALOGV("%s: app_type - %d", __func__, app_type);
309 return app_type;
310}
311
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530312static void update_streams_cfg_list(cnode *root, void *platform,
313 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700314{
315 cnode *node = root->first_child;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530316 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700317
318 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530319 s_info = (struct streams_io_cfg *)calloc(1, sizeof(struct streams_io_cfg));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700320
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530321 if (!s_info) {
322 ALOGE("failed to allocate mem for s_info list element");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700323 return;
324 }
325
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700326 while (node) {
327 if (strcmp(node->name, FLAGS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530328 s_info->flags = parse_flag_names((char *)node->value);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530329 } else if (strcmp(node->name, PROFILES_TAG) == 0) {
330 strlcpy(s_info->profile, (char *)node->value, sizeof(s_info->profile));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700331 } else if (strcmp(node->name, FORMATS_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530332 parse_format_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700333 } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530334 s_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
335 parse_sample_rate_names((char *)node->value, s_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700336 } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530337 s_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700338 } else if (strcmp(node->name, APP_TYPE_TAG) == 0) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530339 s_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700340 }
341 node = node->next;
342 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530343 list_add_tail(streams_cfg_list, &s_info->list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700344}
345
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530346static void load_cfg_list(cnode *root, void *platform,
347 struct listnode *streams_output_cfg_list,
348 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700349{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530350 cnode *node = NULL;
351
352 node = config_find(root, OUTPUTS_TAG);
353 if (node != NULL) {
354 node = node->first_child;
355 while (node) {
356 ALOGV("%s: loading output %s", __func__, node->name);
357 update_streams_cfg_list(node, platform, streams_output_cfg_list);
358 node = node->next;
359 }
360 } else {
361 ALOGI("%s: could not load output, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700362 }
363
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530364 node = config_find(root, INPUTS_TAG);
365 if (node != NULL) {
366 node = node->first_child;
367 while (node) {
368 ALOGV("%s: loading input %s", __func__, node->name);
369 update_streams_cfg_list(node, platform, streams_input_cfg_list);
370 node = node->next;
371 }
372 } else {
373 ALOGI("%s: could not load input, node is NULL", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700374 }
375}
376
377static void send_app_type_cfg(void *platform, struct mixer *mixer,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530378 struct listnode *streams_output_cfg_list,
379 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700380{
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530381 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700382 int length = 0, i, num_app_types = 0;
383 struct listnode *node;
384 bool update;
385 struct mixer_ctl *ctl = NULL;
386 const char *mixer_ctl_name = "App Type Config";
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530387 struct streams_io_cfg *s_info = NULL;
Xiaojun Sang785b5da2017-08-03 15:52:29 +0800388 uint32_t target_bit_width = 0;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700389
390 if (!mixer) {
391 ALOGE("%s: mixer is null",__func__);
392 return;
393 }
394 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
395 if (!ctl) {
396 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
397 return;
398 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530399 app_type_cfg[length++] = num_app_types;
400
401 if (list_empty(streams_output_cfg_list)) {
402 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_PLAYBACK);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700403 app_type_cfg[length++] = 48000;
404 app_type_cfg[length++] = 16;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530405 num_app_types += 1;
406 }
407 if (list_empty(streams_input_cfg_list)) {
408 app_type_cfg[length++] = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
409 app_type_cfg[length++] = 48000;
410 app_type_cfg[length++] = 16;
411 num_app_types += 1;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700412 }
413
Xiaojun Sang785b5da2017-08-03 15:52:29 +0800414 /* get target bit width for ADM enforce mode */
415 target_bit_width = adev_get_dsp_bit_width_enforce_mode();
416
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700417 list_for_each(node, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530418 s_info = node_to_item(node, struct streams_io_cfg, list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700419 update = true;
420 for (i=0; i<length; i=i+3) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530421 if (app_type_cfg[i+1] == 0)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700422 break;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530423 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530424 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530425 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530426 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530427 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
Xiaojun Sang785b5da2017-08-03 15:52:29 +0800428 /* ADM bit width = max(enforce_bit_width, bit_width from s_info */
429 if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) &&
430 (target_bit_width > app_type_cfg[i+3]))
431 app_type_cfg[i+3] = target_bit_width;
432
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700433 update = false;
434 break;
435 }
436 }
437 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530438 num_app_types += 1;
439 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
440 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
Xiaojun Sang785b5da2017-08-03 15:52:29 +0800441 app_type_cfg[length] = s_info->app_type_cfg.bit_width;
442 if (audio_extn_is_dsp_bit_width_enforce_mode_supported(s_info->flags.out_flags) &&
443 (target_bit_width > app_type_cfg[length]))
444 app_type_cfg[length] = target_bit_width;
445
446 length++;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530447 }
448 }
449 list_for_each(node, streams_input_cfg_list) {
450 s_info = node_to_item(node, struct streams_io_cfg, list);
451 update = true;
452 for (i=0; i<length; i=i+3) {
453 if (app_type_cfg[i+1] == 0)
454 break;
455 else if (app_type_cfg[i+1] == (size_t)s_info->app_type_cfg.app_type) {
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530456 if (app_type_cfg[i+2] < (size_t)s_info->app_type_cfg.sample_rate)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530457 app_type_cfg[i+2] = s_info->app_type_cfg.sample_rate;
Dhananjay Kumar9cc498b2016-12-20 21:04:13 +0530458 if (app_type_cfg[i+3] < (size_t)s_info->app_type_cfg.bit_width)
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530459 app_type_cfg[i+3] = s_info->app_type_cfg.bit_width;
460 update = false;
461 break;
462 }
463 }
464 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
465 num_app_types += 1;
466 app_type_cfg[length++] = s_info->app_type_cfg.app_type;
467 app_type_cfg[length++] = s_info->app_type_cfg.sample_rate;
468 app_type_cfg[length++] = s_info->app_type_cfg.bit_width;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700469 }
470 }
471 ALOGV("%s: num_app_types: %d", __func__, num_app_types);
472 if (num_app_types) {
473 app_type_cfg[0] = num_app_types;
474 mixer_ctl_set_array(ctl, app_type_cfg, length);
475 }
476}
477
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530478void audio_extn_utils_update_streams_cfg_lists(void *platform,
479 struct mixer *mixer,
480 struct listnode *streams_output_cfg_list,
481 struct listnode *streams_input_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700482{
483 cnode *root;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530484 char *data = NULL;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700485
486 ALOGV("%s", __func__);
487 list_init(streams_output_cfg_list);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530488 list_init(streams_input_cfg_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700489
490 root = config_node("", "");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700491 if (root == NULL) {
492 ALOGE("cfg_list, NULL config root");
493 return;
494 }
495
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530496 data = (char *)load_file(AUDIO_IO_POLICY_VENDOR_CONFIG_FILE, NULL);
497 if (data == NULL) {
498 ALOGD("%s: failed to open io config file(%s), trying older config file",
499 __func__, AUDIO_IO_POLICY_VENDOR_CONFIG_FILE);
500 data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL);
501 if (data == NULL) {
502 send_app_type_cfg(platform, mixer,
503 streams_output_cfg_list,
504 streams_input_cfg_list);
505 ALOGE("%s: could not load io policy config!", __func__);
yidongh6eb4f752017-04-19 18:20:57 +0800506 free(root);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530507 return;
508 }
509 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700510
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530511 config_load(root, data);
512 load_cfg_list(root, platform, streams_output_cfg_list,
513 streams_input_cfg_list);
514
515 send_app_type_cfg(platform, mixer, streams_output_cfg_list,
516 streams_input_cfg_list);
Alexy Josephaee4fdd2016-01-29 13:02:07 -0800517
518 config_free(root);
yidongh6eb4f752017-04-19 18:20:57 +0800519 free(root);
Alexy Josephaee4fdd2016-01-29 13:02:07 -0800520 free(data);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700521}
522
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530523static void audio_extn_utils_dump_streams_cfg_list(
524 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700525{
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700526 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530527 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700528 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700529 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530530
531 list_for_each(node_i, streams_cfg_list) {
532 s_info = node_to_item(node_i, struct streams_io_cfg, list);
533 ALOGV("%s: flags-%d, sample_rate-%d, bit_width-%d, app_type-%d",
534 __func__, s_info->flags.out_flags, s_info->app_type_cfg.sample_rate,
535 s_info->app_type_cfg.bit_width, s_info->app_type_cfg.app_type);
536 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700537 sf_info = node_to_item(node_j, struct stream_format, list);
538 ALOGV("format-%x", sf_info->format);
539 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530540 list_for_each(node_j, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700541 ss_info = node_to_item(node_j, struct stream_sample_rate, list);
542 ALOGV("sample rate-%d", ss_info->sample_rate);
543 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700544 }
545}
546
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530547void audio_extn_utils_dump_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_dump_streams_cfg_list(streams_output_cfg_list);
553 audio_extn_utils_dump_streams_cfg_list(streams_input_cfg_list);
554}
555
556static void audio_extn_utils_release_streams_cfg_list(
557 struct listnode *streams_cfg_list)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700558{
559 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530560 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700561
562 ALOGV("%s", __func__);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530563
564 while (!list_empty(streams_cfg_list)) {
565 node_i = list_head(streams_cfg_list);
566 s_info = node_to_item(node_i, struct streams_io_cfg, list);
567 while (!list_empty(&s_info->format_list)) {
568 node_j = list_head(&s_info->format_list);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700569 list_remove(node_j);
570 free(node_to_item(node_j, struct stream_format, list));
571 }
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530572 while (!list_empty(&s_info->sample_rate_list)) {
573 node_j = list_head(&s_info->sample_rate_list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700574 list_remove(node_j);
575 free(node_to_item(node_j, struct stream_sample_rate, list));
576 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700577 list_remove(node_i);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530578 free(node_to_item(node_i, struct streams_io_cfg, list));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700579 }
580}
581
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530582void audio_extn_utils_release_streams_cfg_lists(
583 struct listnode *streams_output_cfg_list,
584 struct listnode *streams_input_cfg_list)
585{
586 ALOGV("%s", __func__);
587 audio_extn_utils_release_streams_cfg_list(streams_output_cfg_list);
588 audio_extn_utils_release_streams_cfg_list(streams_input_cfg_list);
589}
590
591static bool set_app_type_cfg(struct streams_io_cfg *s_info,
592 struct stream_app_type_cfg *app_type_cfg,
593 uint32_t sample_rate, uint32_t bit_width)
Amit Shekhar6f461b12014-08-01 14:52:58 -0700594 {
595 struct listnode *node_i;
596 struct stream_sample_rate *ss_info;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530597 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700598 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
599 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530600 (bit_width == s_info->app_type_cfg.bit_width)) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700601
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530602 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700603 app_type_cfg->sample_rate = ss_info->sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530604 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700605 ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
606 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
607 return true;
608 }
609 }
610 /*
611 * Reiterate through the list assuming dafault sample rate.
612 * Handles scenario where input sample rate is higher
613 * than all sample rates in list for the input bit width.
614 */
615 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800616
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530617 list_for_each(node_i, &s_info->sample_rate_list) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700618 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
619 if ((sample_rate <= ss_info->sample_rate) &&
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530620 (bit_width == s_info->app_type_cfg.bit_width)) {
621 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700622 app_type_cfg->sample_rate = sample_rate;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530623 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Apoorv Raghuvanshif59bb222015-02-18 12:23:23 -0800624 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 -0700625 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
626 return true;
627 }
628 }
629 return false;
630}
631
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530632void audio_extn_utils_update_stream_input_app_type_cfg(void *platform,
633 struct listnode *streams_input_cfg_list,
634 audio_devices_t devices __unused,
635 audio_input_flags_t flags,
636 audio_format_t format,
637 uint32_t sample_rate,
638 uint32_t bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530639 char* profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530640 struct stream_app_type_cfg *app_type_cfg)
641{
642 struct listnode *node_i, *node_j;
643 struct streams_io_cfg *s_info;
644 struct stream_format *sf_info;
645
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530646 ALOGV("%s: flags: 0x%x, format: 0x%x sample_rate %d, profile %s",
647 __func__, flags, format, sample_rate, profile);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530648
649 list_for_each(node_i, streams_input_cfg_list) {
650 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530651 /* Along with flags do profile matching if set at either end.*/
652 if (s_info->flags.in_flags == flags &&
653 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
654 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530655 list_for_each(node_j, &s_info->format_list) {
656 sf_info = node_to_item(node_j, struct stream_format, list);
657 if (sf_info->format == format) {
658 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
659 return;
660 }
661 }
662 }
663 }
664 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
665 app_type_cfg->app_type = platform_get_default_app_type_v2(platform, PCM_CAPTURE);
666 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
667 app_type_cfg->bit_width = 16;
668}
669
670void audio_extn_utils_update_stream_output_app_type_cfg(void *platform,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700671 struct listnode *streams_output_cfg_list,
Amit Shekhar1d896042014-10-03 13:16:09 -0700672 audio_devices_t devices,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700673 audio_output_flags_t flags,
674 audio_format_t format,
Amit Shekhar6f461b12014-08-01 14:52:58 -0700675 uint32_t sample_rate,
676 uint32_t bit_width,
Manish Dewangan837dc462015-05-27 10:17:41 +0530677 audio_channel_mask_t channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530678 char *profile,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700679 struct stream_app_type_cfg *app_type_cfg)
680{
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +0530681 struct listnode *node_i, *node_j;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530682 struct streams_io_cfg *s_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700683 struct stream_format *sf_info;
Manish Dewangan837dc462015-05-27 10:17:41 +0530684 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700685
Ashish Jain058165c2016-09-28 23:18:48 +0530686 if ((bit_width >= 24) &&
Amit Shekhar1d896042014-10-03 13:16:09 -0700687 (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Amit Shekhar5a39c912014-10-14 15:39:30 -0700688 int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
689 if (-ENOSYS != bw)
690 bit_width = (uint32_t)bw;
Amit Shekhar1d896042014-10-03 13:16:09 -0700691 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
692 ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
693 }
694
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700695 property_get("vendor.audio.playback.mch.downsample",value,"");
Manish Dewangan837dc462015-05-27 10:17:41 +0530696 if (!strncmp("true", value, sizeof("true"))) {
697 if ((popcount(channel_mask) > 2) &&
698 (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
699 !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
700 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
701 ALOGD("%s: MCH session defaulting sample rate to %d",
702 __func__, sample_rate);
703 }
704 }
Preetam Singh Ranawatcb6212e2016-07-19 18:33:53 +0530705
706 /* Set sampling rate to 176.4 for DSD64
707 * and 352.8Khz for DSD128.
708 * Set Bit Width to 16. output will be 16 bit
709 * post DoP in ASM.
710 */
711 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) &&
712 (format == AUDIO_FORMAT_DSD)) {
713 bit_width = 16;
714 if (sample_rate == INPUT_SAMPLING_RATE_DSD64)
715 sample_rate = OUTPUT_SAMPLING_RATE_DSD64;
716 else if (sample_rate == INPUT_SAMPLING_RATE_DSD128)
717 sample_rate = OUTPUT_SAMPLING_RATE_DSD128;
718 }
719
Naresh Tanniruf5ba8d02016-09-29 18:06:37 +0530720 if(devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
721 //TODO: Handle fractional sampling rate configuration for LL
722 audio_extn_a2dp_get_apptype_params(&sample_rate, &bit_width);
723 ALOGI("%s using %d sampling rate %d bit width for A2DP CoPP",
724 __func__, sample_rate, bit_width);
725 }
726
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800727 ALOGV("%s: flags: %x, format: %x sample_rate %d, profile %s, app_type %d",
728 __func__, flags, format, sample_rate, profile, app_type_cfg->app_type);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700729 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530730 s_info = node_to_item(node_i, struct streams_io_cfg, list);
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530731 /* Along with flags do profile matching if set at either end.*/
732 if (s_info->flags.out_flags == flags &&
733 ((profile[0] == '\0' && s_info->profile[0] == '\0') ||
734 strncmp(s_info->profile, profile, sizeof(s_info->profile)) == 0)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530735 list_for_each(node_j, &s_info->format_list) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700736 sf_info = node_to_item(node_j, struct stream_format, list);
737 if (sf_info->format == format) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530738 if (set_app_type_cfg(s_info, app_type_cfg, sample_rate, bit_width))
Amit Shekhar6f461b12014-08-01 14:52:58 -0700739 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700740 }
741 }
742 }
743 }
744 list_for_each(node_i, streams_output_cfg_list) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530745 s_info = node_to_item(node_i, struct streams_io_cfg, list);
746 if (s_info->flags.out_flags == AUDIO_OUTPUT_FLAG_PRIMARY) {
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700747 ALOGV("Compatible output profile not found.");
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530748 app_type_cfg->app_type = s_info->app_type_cfg.app_type;
749 app_type_cfg->sample_rate = s_info->app_type_cfg.sample_rate;
750 app_type_cfg->bit_width = s_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700751 ALOGV("%s Default to primary output: App type: %d sample_rate %d",
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530752 __func__, s_info->app_type_cfg.app_type, app_type_cfg->sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700753 return;
754 }
755 }
756 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700757 app_type_cfg->app_type = platform_get_default_app_type(platform);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700758 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700759 app_type_cfg->bit_width = 16;
760}
761
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530762static bool audio_is_this_native_usecase(struct audio_usecase *uc)
763{
764 bool native_usecase = false;
765 struct stream_out *out = (struct stream_out*) uc->stream.out;
766
767 if (PCM_PLAYBACK == uc->type && out != NULL &&
768 NATIVE_AUDIO_MODE_INVALID != platform_get_native_support() &&
769 is_offload_usecase(uc->id) &&
770 (out->sample_rate == OUTPUT_SAMPLING_RATE_44100))
771 native_usecase = true;
772
773 return native_usecase;
774}
775
Xiaojun Sang785b5da2017-08-03 15:52:29 +0800776bool audio_extn_is_dsp_bit_width_enforce_mode_supported(audio_output_flags_t flags)
777{
778 /* DSP bitwidth enforce mode for ADM and AFE:
779 * includes:
780 * deep buffer, low latency, direct pcm and offload.
781 * excludes:
782 * ull(raw+fast), VOIP.
783 */
784 if ((flags & AUDIO_OUTPUT_FLAG_VOIP_RX) ||
785 ((flags & AUDIO_OUTPUT_FLAG_RAW) &&
786 (flags & AUDIO_OUTPUT_FLAG_FAST)))
787 return false;
788
789
790 if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) ||
791 (flags & AUDIO_OUTPUT_FLAG_DIRECT) ||
792 (flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) ||
793 (flags & AUDIO_OUTPUT_FLAG_PRIMARY))
794 return true;
795 else
796 return false;
797}
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800798
799static inline bool audio_is_vr_mode_on(struct audio_device *(__attribute__((unused)) adev))
800{
801 return adev->vr_audio_mode_enabled;
802}
803
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530804void audio_extn_utils_update_stream_app_type_cfg_for_usecase(
805 struct audio_device *adev,
806 struct audio_usecase *usecase)
807{
808 ALOGV("%s", __func__);
809
810 switch(usecase->type) {
811 case PCM_PLAYBACK:
812 audio_extn_utils_update_stream_output_app_type_cfg(adev->platform,
813 &adev->streams_output_cfg_list,
814 usecase->stream.out->devices,
815 usecase->stream.out->flags,
816 usecase->stream.out->format,
817 usecase->stream.out->sample_rate,
818 usecase->stream.out->bit_width,
819 usecase->stream.out->channel_mask,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530820 usecase->stream.out->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530821 &usecase->stream.out->app_type_cfg);
822 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
823 break;
824 case PCM_CAPTURE:
825 audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
826 &adev->streams_input_cfg_list,
827 usecase->stream.in->device,
828 usecase->stream.in->flags,
829 usecase->stream.in->format,
830 usecase->stream.in->sample_rate,
831 usecase->stream.in->bit_width,
Dhananjay Kumar4d91c1a2016-12-01 23:27:29 +0530832 usecase->stream.in->profile,
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530833 &usecase->stream.in->app_type_cfg);
834 ALOGV("%s Selected apptype: %d", __func__, usecase->stream.in->app_type_cfg.app_type);
835 break;
836 default:
837 ALOGE("%s: app type cfg not supported for usecase type (%d)",
838 __func__, usecase->type);
839 }
840}
841
Siena Richard7c2db772016-12-21 11:32:34 -0800842static int send_app_type_cfg_for_device(struct audio_device *adev,
843 struct audio_usecase *usecase,
844 int split_snd_device)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700845{
846 char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT];
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530847 size_t app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {0};
848 int len = 0, rc;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700849 struct mixer_ctl *ctl;
Siena Richard7c2db772016-12-21 11:32:34 -0800850 int pcm_device_id = 0, acdb_dev_id, app_type;
851 int snd_device = split_snd_device, snd_device_be_idx = -1;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530852 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Manish Dewangan837dc462015-05-27 10:17:41 +0530853 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700854
Siena Richard7c2db772016-12-21 11:32:34 -0800855 ALOGV("%s: usecase->out_snd_device %s, usecase->in_snd_device %s, split_snd_device %s",
856 __func__, platform_get_snd_device_name(usecase->out_snd_device),
857 platform_get_snd_device_name(usecase->in_snd_device),
858 platform_get_snd_device_name(split_snd_device));
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700859
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530860 if (usecase->type != PCM_PLAYBACK && usecase->type != PCM_CAPTURE) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530861 ALOGE("%s: not a playback/capture path, no need to cfg app type", __func__);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700862 rc = 0;
863 goto exit_send_app_type_cfg;
864 }
865 if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) &&
866 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
867 (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800868 (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530869 (!is_offload_usecase(usecase->id)) &&
870 (usecase->type != PCM_CAPTURE)) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530871 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 -0700872 rc = 0;
873 goto exit_send_app_type_cfg;
874 }
Alexy Joseph5e4ccbc2017-02-21 14:20:12 -0800875
876 //if VR is active then only send the mixer control
877 if (usecase->id == USECASE_AUDIO_PLAYBACK_ULL && !audio_is_vr_mode_on(adev)) {
878 ALOGI("ULL doesnt need sending app type cfg, returning");
879 rc = 0;
880 goto exit_send_app_type_cfg;
881 }
882
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530883 if (usecase->type == PCM_PLAYBACK) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700884 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_PLAYBACK);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530885 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
886 "Audio Stream %d App Type Cfg", pcm_device_id);
Ben Romberger1fafdde2015-09-09 19:43:15 -0700887 } else if (usecase->type == PCM_CAPTURE) {
Ben Romberger1fafdde2015-09-09 19:43:15 -0700888 pcm_device_id = platform_get_pcm_device_id(usecase->id, PCM_CAPTURE);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530889 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
890 "Audio Stream Capture %d App Type Cfg", pcm_device_id);
Srikanth Uyyala9d551402015-08-25 16:03:42 +0530891 }
Siena Richard7c2db772016-12-21 11:32:34 -0800892
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700893 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
894 if (!ctl) {
895 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__,
896 mixer_ctl_name);
897 rc = -EINVAL;
898 goto exit_send_app_type_cfg;
899 }
Aditya Bavanari701a6992017-03-30 19:17:16 +0530900 snd_device = platform_get_spkr_prot_snd_device(snd_device);
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530901
Rohit Kumar1181b292017-01-31 18:07:17 +0530902 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
903 if (acdb_dev_id <= 0) {
904 ALOGE("%s: Couldn't get the acdb dev id", __func__);
905 rc = -EINVAL;
906 goto exit_send_app_type_cfg;
907 }
908
Siena Richard7c2db772016-12-21 11:32:34 -0800909 snd_device_be_idx = platform_get_snd_device_backend_index(snd_device);
910 if (snd_device_be_idx < 0) {
911 ALOGE("%s: Couldn't get the backend index for snd device %s ret=%d",
912 __func__, platform_get_snd_device_name(snd_device),
913 snd_device_be_idx);
914 }
915
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530916 if ((usecase->type == PCM_PLAYBACK) && (usecase->stream.out != NULL)) {
Manish Dewangan837dc462015-05-27 10:17:41 +0530917
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700918 property_get("vendor.audio.playback.mch.downsample",value,"");
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530919 if (!strncmp("true", value, sizeof("true"))) {
920 if ((popcount(usecase->stream.out->channel_mask) > 2) &&
921 (usecase->stream.out->app_type_cfg.sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
922 !(usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
923 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
924 }
Ashish Jainc02430d2016-01-04 10:42:43 +0530925
Ashish Jain4826f6c2017-02-06 13:33:20 +0530926 if (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin21854652016-04-13 11:54:02 -0700927 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Ashish Jaina052e572016-11-07 16:41:07 +0530928 } else if ((snd_device == SND_DEVICE_OUT_HDMI ||
929 snd_device == SND_DEVICE_OUT_USB_HEADSET ||
930 snd_device == SND_DEVICE_OUT_DISPLAY_PORT) &&
931 (usecase->stream.out->sample_rate >= OUTPUT_SAMPLING_RATE_44100)) {
932 /*
933 * To best utlize DSP, check if the stream sample rate is supported/multiple of
934 * configured device sample rate, if not update the COPP rate to be equal to the
935 * device sample rate, else open COPP at stream sample rate
936 */
937 platform_check_and_update_copp_sample_rate(adev->platform, snd_device,
938 usecase->stream.out->sample_rate,
939 &usecase->stream.out->app_type_cfg.sample_rate);
Ashish Jain4826f6c2017-02-06 13:33:20 +0530940 } else if (((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
941 !audio_is_this_native_usecase(usecase)) &&
Mingming Yin21854652016-04-13 11:54:02 -0700942 usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
943 (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
Ashish Jain4826f6c2017-02-06 13:33:20 +0530944 /* Reset to default if no native stream is active*/
Mingming Yin21854652016-04-13 11:54:02 -0700945 usecase->stream.out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
946 }
947 sample_rate = usecase->stream.out->app_type_cfg.sample_rate;
948
Siena Richard7c2db772016-12-21 11:32:34 -0800949 app_type = usecase->stream.out->app_type_cfg.app_type;
950 app_type_cfg[len++] = app_type;
Mingming Yin21854652016-04-13 11:54:02 -0700951 app_type_cfg[len++] = acdb_dev_id;
952 if (((usecase->stream.out->format == AUDIO_FORMAT_E_AC3) ||
Ben Romberger1aaaf862017-04-06 17:49:46 -0700953 (usecase->stream.out->format == AUDIO_FORMAT_E_AC3_JOC) ||
954 (usecase->stream.out->format == AUDIO_FORMAT_DOLBY_TRUEHD))
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530955 && audio_extn_passthru_is_passthrough_stream(usecase->stream.out)) {
Naresh Tanniru3a406772017-05-10 13:09:05 -0700956
957 sample_rate = sample_rate * 4;
958 if (sample_rate > HDMI_PASSTHROUGH_MAX_SAMPLE_RATE)
959 sample_rate = HDMI_PASSTHROUGH_MAX_SAMPLE_RATE;
Mingming Yin21854652016-04-13 11:54:02 -0700960 }
Naresh Tanniru3a406772017-05-10 13:09:05 -0700961 app_type_cfg[len++] = sample_rate;
962
Siena Richard7c2db772016-12-21 11:32:34 -0800963 if (snd_device_be_idx > 0)
964 app_type_cfg[len++] = snd_device_be_idx;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530965
Siena Richard7c2db772016-12-21 11:32:34 -0800966 ALOGI("%s PLAYBACK app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
967 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530968
969 } else if ((usecase->type == PCM_CAPTURE) && (usecase->stream.in != NULL)) {
Siena Richard7c2db772016-12-21 11:32:34 -0800970 app_type = usecase->stream.in->app_type_cfg.app_type;
971 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530972 app_type_cfg[len++] = acdb_dev_id;
Siena Richard7c2db772016-12-21 11:32:34 -0800973 sample_rate = usecase->stream.in->app_type_cfg.sample_rate;
974 app_type_cfg[len++] = sample_rate;
975 if (snd_device_be_idx > 0)
976 app_type_cfg[len++] = snd_device_be_idx;
977 ALOGI("%s CAPTURE app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
978 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530979 } else {
Siena Richard7c2db772016-12-21 11:32:34 -0800980 app_type = platform_get_default_app_type_v2(adev->platform, usecase->type);
981 app_type_cfg[len++] = app_type;
Dhananjay Kumard6d32152016-10-13 16:11:03 +0530982 app_type_cfg[len++] = acdb_dev_id;
983 app_type_cfg[len++] = sample_rate;
Siena Richard7c2db772016-12-21 11:32:34 -0800984 if (snd_device_be_idx > 0)
985 app_type_cfg[len++] = snd_device_be_idx;
986 ALOGI("%s default app_type %d, acdb_dev_id %d, sample_rate %d, snd_device_be_idx %d",
987 __func__, app_type, acdb_dev_id, sample_rate, snd_device_be_idx);
Ashish Jainc02430d2016-01-04 10:42:43 +0530988 }
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +0530989
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700990 mixer_ctl_set_array(ctl, app_type_cfg, len);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700991 rc = 0;
992exit_send_app_type_cfg:
993 return rc;
994}
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700995
Siena Richard7c2db772016-12-21 11:32:34 -0800996int audio_extn_utils_send_app_type_cfg(struct audio_device *adev,
997 struct audio_usecase *usecase)
998{
999 int i, num_devices = 0;
1000 snd_device_t new_snd_devices[SND_DEVICE_OUT_END] = {0};
1001 int rc = 0;
1002
1003 switch (usecase->type) {
1004 case PCM_PLAYBACK:
1005 ALOGD("%s: usecase->out_snd_device %s",
1006 __func__, platform_get_snd_device_name(usecase->out_snd_device));
1007 /* check for out combo device */
1008 if (platform_split_snd_device(adev->platform,
1009 usecase->out_snd_device,
1010 &num_devices, new_snd_devices)) {
1011 new_snd_devices[0] = usecase->out_snd_device;
1012 num_devices = 1;
1013 }
1014 break;
1015 case PCM_CAPTURE:
1016 ALOGD("%s: usecase->in_snd_device %s",
1017 __func__, platform_get_snd_device_name(usecase->in_snd_device));
1018 /* check for in combo device */
1019 if (platform_split_snd_device(adev->platform,
1020 usecase->in_snd_device,
1021 &num_devices, new_snd_devices)) {
1022 new_snd_devices[0] = usecase->in_snd_device;
1023 num_devices = 1;
1024 }
1025 break;
1026 default:
1027 ALOGI("%s: not a playback/capture path, no need to cfg app type", __func__);
1028 rc = 0;
1029 break;
1030 }
1031
1032 for (i = 0; i < num_devices; i++) {
1033 rc = send_app_type_cfg_for_device(adev, usecase, new_snd_devices[i]);
1034 if (rc)
1035 break;
1036 }
1037
1038 return rc;
1039}
1040
Preetam Singh Ranawat9519e9c2015-11-18 16:05:55 +05301041int read_line_from_file(const char *path, char *buf, size_t count)
1042{
1043 char * fgets_ret;
1044 FILE * fd;
1045 int rv;
1046
1047 fd = fopen(path, "r");
1048 if (fd == NULL)
1049 return -1;
1050
1051 fgets_ret = fgets(buf, (int)count, fd);
1052 if (NULL != fgets_ret) {
1053 rv = (int)strlen(buf);
1054 } else {
1055 rv = ferror(fd);
1056 }
1057 fclose(fd);
1058
1059 return rv;
1060}
1061
Ashish Jainf1eaa582016-05-23 20:54:24 +05301062/*Translates ALSA formats to AOSP PCM formats*/
1063audio_format_t alsa_format_to_hal(uint32_t alsa_format)
1064{
1065 audio_format_t format;
1066
1067 switch(alsa_format) {
1068 case SNDRV_PCM_FORMAT_S16_LE:
1069 format = AUDIO_FORMAT_PCM_16_BIT;
1070 break;
1071 case SNDRV_PCM_FORMAT_S24_3LE:
1072 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1073 break;
1074 case SNDRV_PCM_FORMAT_S24_LE:
1075 format = AUDIO_FORMAT_PCM_8_24_BIT;
1076 break;
1077 case SNDRV_PCM_FORMAT_S32_LE:
1078 format = AUDIO_FORMAT_PCM_32_BIT;
1079 break;
1080 default:
1081 ALOGW("Incorrect ALSA format");
1082 format = AUDIO_FORMAT_INVALID;
1083 }
1084 return format;
1085}
1086
1087/*Translates hal format (AOSP) to alsa formats*/
1088uint32_t hal_format_to_alsa(audio_format_t hal_format)
1089{
1090 uint32_t alsa_format;
1091
1092 switch (hal_format) {
1093 case AUDIO_FORMAT_PCM_32_BIT: {
1094 if (platform_supports_true_32bit())
1095 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1096 else
1097 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1098 }
1099 break;
1100 case AUDIO_FORMAT_PCM_8_BIT:
1101 alsa_format = SNDRV_PCM_FORMAT_S8;
1102 break;
1103 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1104 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1105 break;
1106 case AUDIO_FORMAT_PCM_8_24_BIT: {
1107 if (platform_supports_true_32bit())
1108 alsa_format = SNDRV_PCM_FORMAT_S32_LE;
1109 else
1110 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1111 }
1112 break;
1113 case AUDIO_FORMAT_PCM_FLOAT:
1114 alsa_format = SNDRV_PCM_FORMAT_S24_3LE;
1115 break;
1116 default:
1117 case AUDIO_FORMAT_PCM_16_BIT:
1118 alsa_format = SNDRV_PCM_FORMAT_S16_LE;
1119 break;
1120 }
1121 return alsa_format;
1122}
1123
Ashish Jain83a6cc22016-06-28 14:34:17 +05301124/*Translates PCM formats to AOSP formats*/
1125audio_format_t pcm_format_to_hal(uint32_t pcm_format)
1126{
1127 audio_format_t format = AUDIO_FORMAT_INVALID;
1128
1129 switch(pcm_format) {
1130 case PCM_FORMAT_S16_LE:
1131 format = AUDIO_FORMAT_PCM_16_BIT;
1132 break;
1133 case PCM_FORMAT_S24_3LE:
1134 format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
1135 break;
1136 case PCM_FORMAT_S24_LE:
1137 format = AUDIO_FORMAT_PCM_8_24_BIT;
1138 break;
1139 case PCM_FORMAT_S32_LE:
1140 format = AUDIO_FORMAT_PCM_32_BIT;
1141 break;
1142 default:
1143 ALOGW("Incorrect PCM format");
1144 format = AUDIO_FORMAT_INVALID;
1145 }
1146 return format;
1147}
1148
1149/*Translates hal format (AOSP) to alsa formats*/
1150uint32_t hal_format_to_pcm(audio_format_t hal_format)
1151{
1152 uint32_t pcm_format;
1153
1154 switch (hal_format) {
1155 case AUDIO_FORMAT_PCM_32_BIT:
1156 case AUDIO_FORMAT_PCM_8_24_BIT:
1157 case AUDIO_FORMAT_PCM_FLOAT: {
1158 if (platform_supports_true_32bit())
1159 pcm_format = PCM_FORMAT_S32_LE;
1160 else
1161 pcm_format = PCM_FORMAT_S24_3LE;
1162 }
1163 break;
1164 case AUDIO_FORMAT_PCM_8_BIT:
1165 pcm_format = PCM_FORMAT_S8;
1166 break;
1167 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1168 pcm_format = PCM_FORMAT_S24_3LE;
1169 break;
1170 default:
1171 case AUDIO_FORMAT_PCM_16_BIT:
1172 pcm_format = PCM_FORMAT_S16_LE;
1173 break;
1174 }
1175 return pcm_format;
1176}
1177
Ashish Jainf1eaa582016-05-23 20:54:24 +05301178uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
1179 uint32_t sample_rate,
1180 uint32_t noOfChannels)
1181{
1182 uint32_t fragment_size = 0;
1183 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
1184
1185 fragment_size = (pcm_offload_time
1186 * sample_rate
1187 * bytes_per_sample
1188 * noOfChannels)/1000;
1189 if (fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
1190 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
1191 else if (fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
1192 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
1193 /*To have same PCM samples for all channels, the buffer size requires to
1194 *be multiple of (number of channels * bytes per sample)
1195 *For writes to succeed, the buffer must be written at address which is multiple of 32
1196 */
1197 fragment_size = ALIGN(fragment_size, (bytes_per_sample * noOfChannels * 32));
1198
1199 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
1200 return fragment_size;
1201}
1202
1203/* Calculates the fragment size required to configure compress session.
1204 * Based on the alsa format selected, decide if conversion is needed in
1205
1206 * HAL ( e.g. convert AUDIO_FORMAT_PCM_FLOAT input format to
1207 * AUDIO_FORMAT_PCM_24_BIT_PACKED before writing to the compress driver.
1208 */
1209void audio_extn_utils_update_direct_pcm_fragment_size(struct stream_out *out)
1210{
Ashish Jain83a6cc22016-06-28 14:34:17 +05301211 audio_format_t dst_format = out->hal_op_format;
1212 audio_format_t src_format = out->hal_ip_format;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301213 uint32_t hal_op_bytes_per_sample = audio_bytes_per_sample(dst_format);
1214 uint32_t hal_ip_bytes_per_sample = audio_bytes_per_sample(src_format);
1215
1216 out->compr_config.fragment_size =
1217 get_alsa_fragment_size(hal_op_bytes_per_sample,
1218 out->sample_rate,
1219 popcount(out->channel_mask));
1220
1221 if ((src_format != dst_format) &&
1222 hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {
1223
Ashish Jain83a6cc22016-06-28 14:34:17 +05301224 out->hal_fragment_size =
Ashish Jainf1eaa582016-05-23 20:54:24 +05301225 ((out->compr_config.fragment_size * hal_ip_bytes_per_sample) /
1226 hal_op_bytes_per_sample);
1227 ALOGI("enable conversion hal_input_fragment_size is %d src_format %x dst_format %x",
Ashish Jain83a6cc22016-06-28 14:34:17 +05301228 out->hal_fragment_size, src_format, dst_format);
Ashish Jainf1eaa582016-05-23 20:54:24 +05301229 } else {
Ashish Jain83a6cc22016-06-28 14:34:17 +05301230 out->hal_fragment_size = out->compr_config.fragment_size;
Ashish Jainf1eaa582016-05-23 20:54:24 +05301231 }
1232}
1233
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301234/* converts pcm format 24_8 to 8_24 inplace */
1235size_t audio_extn_utils_convert_format_24_8_to_8_24(void *buf, size_t bytes)
1236{
1237 size_t i = 0;
1238 int *int_buf_stream = buf;
1239
1240 if ((bytes % 4) != 0) {
1241 ALOGE("%s: wrong inout buffer! ... is not 32 bit aligned ", __func__);
1242 return -EINVAL;
1243 }
1244
1245 for (; i < (bytes / 4); i++)
1246 int_buf_stream[i] >>= 8;
1247
1248 return bytes;
1249}
1250
1251int get_snd_codec_id(audio_format_t format)
1252{
1253 int id = 0;
1254
1255 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1256 case AUDIO_FORMAT_MP3:
1257 id = SND_AUDIOCODEC_MP3;
1258 break;
1259 case AUDIO_FORMAT_AAC:
1260 id = SND_AUDIOCODEC_AAC;
1261 break;
1262 case AUDIO_FORMAT_AAC_ADTS:
1263 id = SND_AUDIOCODEC_AAC;
1264 break;
Arun Kumar Dasari3b174182016-12-27 13:01:14 +05301265 case AUDIO_FORMAT_AAC_LATM:
1266 id = SND_AUDIOCODEC_AAC;
1267 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301268 case AUDIO_FORMAT_PCM:
1269 id = SND_AUDIOCODEC_PCM;
1270 break;
1271 case AUDIO_FORMAT_FLAC:
1272 id = SND_AUDIOCODEC_FLAC;
1273 break;
1274 case AUDIO_FORMAT_ALAC:
1275 id = SND_AUDIOCODEC_ALAC;
1276 break;
1277 case AUDIO_FORMAT_APE:
1278 id = SND_AUDIOCODEC_APE;
1279 break;
1280 case AUDIO_FORMAT_VORBIS:
1281 id = SND_AUDIOCODEC_VORBIS;
1282 break;
1283 case AUDIO_FORMAT_WMA:
1284 id = SND_AUDIOCODEC_WMA;
1285 break;
1286 case AUDIO_FORMAT_WMA_PRO:
1287 id = SND_AUDIOCODEC_WMA_PRO;
1288 break;
Satish Babu Patakokila0c313922016-12-08 12:07:08 +05301289 case AUDIO_FORMAT_MP2:
1290 id = SND_AUDIOCODEC_MP2;
1291 break;
Satish Babu Patakokila915ecba2017-01-10 17:43:56 +05301292 case AUDIO_FORMAT_AC3:
1293 id = SND_AUDIOCODEC_AC3;
1294 break;
1295 case AUDIO_FORMAT_E_AC3:
1296 case AUDIO_FORMAT_E_AC3_JOC:
1297 id = SND_AUDIOCODEC_EAC3;
1298 break;
1299 case AUDIO_FORMAT_DTS:
1300 case AUDIO_FORMAT_DTS_HD:
1301 id = SND_AUDIOCODEC_DTS;
1302 break;
Ben Romberger1aaaf862017-04-06 17:49:46 -07001303 case AUDIO_FORMAT_DOLBY_TRUEHD:
1304 id = SND_AUDIOCODEC_TRUEHD;
1305 break;
Naresh Tanniru928f0862017-04-07 16:44:23 -07001306 case AUDIO_FORMAT_IEC61937:
1307 id = SND_AUDIOCODEC_IEC61937;
1308 break;
Preetam Singh Ranawat4277a5a2017-01-18 19:02:24 +05301309 case AUDIO_FORMAT_DSD:
1310 id = SND_AUDIOCODEC_DSD;
1311 break;
Dhanalakshmi Siddani18737932016-11-29 17:33:17 +05301312 case AUDIO_FORMAT_APTX:
1313 id = SND_AUDIOCODEC_APTX;
1314 break;
Dhananjay Kumaree4d2002016-10-25 18:02:58 +05301315 default:
1316 ALOGE("%s: Unsupported audio format :%x", __func__, format);
1317 }
1318
1319 return id;
1320}
1321
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001322void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
1323 struct audio_usecase *usecase)
1324{
1325 int type = usecase->type;
1326
Dhananjay Kumar14245982017-01-16 20:21:00 +05301327 if (type == PCM_PLAYBACK && usecase->stream.out != NULL) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001328 struct stream_out *out = usecase->stream.out;
1329 int snd_device = usecase->out_snd_device;
1330 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
Xiaojun Sang040cc9f2015-08-03 19:38:28 +08001331 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301332 platform_send_audio_calibration(adev->platform, usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001333 out->app_type_cfg.app_type,
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301334 usecase->stream.out->app_type_cfg.sample_rate);
Dhananjay Kumar14245982017-01-16 20:21:00 +05301335 } else if (type == PCM_CAPTURE && usecase->stream.in != NULL) {
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301336 platform_send_audio_calibration(adev->platform, usecase,
1337 usecase->stream.in->app_type_cfg.app_type,
1338 usecase->stream.in->app_type_cfg.sample_rate);
Vidyakumar Athota653aaef2017-03-16 11:11:31 -07001339 } else if (type == PCM_HFP_CALL || type == PCM_CAPTURE) {
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301340 /* when app type is default. the sample rate is not used to send cal */
1341 platform_send_audio_calibration(adev->platform, usecase,
Dhananjay Kumard6d32152016-10-13 16:11:03 +05301342 platform_get_default_app_type_v2(adev->platform, usecase->type),
1343 48000);
Vidyakumar Athotae57f6002017-03-01 13:13:16 -08001344 } else {
1345 /* No need to send audio calibration for voice and voip call usecases */
1346 if ((type != VOICE_CALL) && (type != VOIP_CALL))
1347 ALOGW("%s: No audio calibration for usecase type = %d", __func__, type);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001348 }
1349}
1350
Ben Rombergera04fabc2014-11-14 12:16:03 -08001351// Base64 Encode and Decode
1352// Not all features supported. This must be used only with following conditions.
1353// Decode Modes: Support with and without padding
1354// CRLF not handling. So no CRLF in string to decode.
1355// Encode Modes: Supports only padding
1356int b64decode(char *inp, int ilen, uint8_t* outp)
1357{
1358 int i, j, k, ii, num;
1359 int rem, pcnt;
1360 uint32_t res=0;
1361 uint8_t getIndex[MAX_BASEINDEX_LEN];
1362 uint8_t tmp, cflag;
1363
1364 if(inp == NULL || outp == NULL || ilen <= 0) {
1365 ALOGE("[%s] received NULL pointer or zero length",__func__);
1366 return -1;
1367 }
1368
1369 memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex));
1370 for(i=0;i<BASE_TABLE_SIZE;i++) {
1371 getIndex[(uint8_t)bTable[i]] = (uint8_t)i;
1372 }
1373 getIndex[(uint8_t)'=']=0;
1374
1375 j=0;k=0;
1376 num = ilen/4;
1377 rem = ilen%4;
1378 if(rem==0)
1379 num = num-1;
1380 cflag=0;
1381 for(i=0; i<num; i++) {
1382 res=0;
1383 for(ii=0;ii<4;ii++) {
1384 res = res << 6;
1385 tmp = getIndex[(uint8_t)inp[j++]];
1386 res = res | tmp;
1387 cflag = cflag | tmp;
1388 }
1389 outp[k++] = (res >> 16)&0xFF;
1390 outp[k++] = (res >> 8)&0xFF;
1391 outp[k++] = res & 0xFF;
1392 }
1393
1394 // Handle last bytes special
1395 pcnt=0;
1396 if(rem == 0) {
1397 //With padding or full data
1398 res = 0;
1399 for(ii=0;ii<4;ii++) {
1400 if(inp[j] == '=')
1401 pcnt++;
1402 res = res << 6;
1403 tmp = getIndex[(uint8_t)inp[j++]];
1404 res = res | tmp;
1405 cflag = cflag | tmp;
1406 }
1407 outp[k++] = res >> 16;
1408 if(pcnt == 2)
1409 goto done;
1410 outp[k++] = (res>>8)&0xFF;
1411 if(pcnt == 1)
1412 goto done;
1413 outp[k++] = res&0xFF;
1414 } else {
1415 //without padding
1416 res = 0;
1417 for(i=0;i<rem;i++) {
1418 res = res << 6;
1419 tmp = getIndex[(uint8_t)inp[j++]];
1420 res = res | tmp;
1421 cflag = cflag | tmp;
1422 }
1423 for(i=rem;i<4;i++) {
1424 res = res << 6;
1425 pcnt++;
1426 }
1427 outp[k++] = res >> 16;
1428 if(pcnt == 2)
1429 goto done;
1430 outp[k++] = (res>>8)&0xFF;
1431 if(pcnt == 1)
1432 goto done;
1433 outp[k++] = res&0xFF;
1434 }
1435done:
1436 if(cflag == 0xFF) {
1437 ALOGE("[%s] base64 decode failed. Invalid character found %s",
1438 __func__, inp);
1439 return 0;
1440 }
1441 return k;
1442}
1443
1444int b64encode(uint8_t *inp, int ilen, char* outp)
1445{
1446 int i,j,k, num;
1447 int rem=0;
1448 uint32_t res=0;
1449
1450 if(inp == NULL || outp == NULL || ilen<=0) {
1451 ALOGE("[%s] received NULL pointer or zero input length",__func__);
1452 return -1;
1453 }
1454
1455 num = ilen/3;
1456 rem = ilen%3;
1457 j=0;k=0;
1458 for(i=0; i<num; i++) {
1459 //prepare index
1460 res = inp[j++]<<16;
1461 res = res | inp[j++]<<8;
1462 res = res | inp[j++];
1463 //get output map from index
1464 outp[k++] = (char) bTable[(res>>18)&0x3F];
1465 outp[k++] = (char) bTable[(res>>12)&0x3F];
1466 outp[k++] = (char) bTable[(res>>6)&0x3F];
1467 outp[k++] = (char) bTable[res&0x3F];
1468 }
1469
1470 switch(rem) {
1471 case 1:
1472 res = inp[j++]<<16;
1473 outp[k++] = (char) bTable[res>>18];
1474 outp[k++] = (char) bTable[(res>>12)&0x3F];
1475 //outp[k++] = '=';
1476 //outp[k++] = '=';
1477 break;
1478 case 2:
1479 res = inp[j++]<<16;
1480 res = res | inp[j++]<<8;
1481 outp[k++] = (char) bTable[res>>18];
1482 outp[k++] = (char) bTable[(res>>12)&0x3F];
1483 outp[k++] = (char) bTable[(res>>6)&0x3F];
1484 //outp[k++] = '=';
1485 break;
1486 default:
1487 break;
1488 }
Ben Rombergera04fabc2014-11-14 12:16:03 -08001489 outp[k] = '\0';
1490 return k;
1491}
Ashish Jain81eb2a82015-05-13 10:52:34 +05301492
Sidipotu Ashoke6f78cb2015-11-05 14:42:20 +05301493
1494int audio_extn_utils_get_codec_version(const char *snd_card_name,
1495 int card_num,
1496 char *codec_version)
1497{
1498 char procfs_path[50];
1499 FILE *fp;
1500
1501 if (strstr(snd_card_name, "tasha")) {
1502 snprintf(procfs_path, sizeof(procfs_path),
1503 "/proc/asound/card%d/codecs/tasha/version", card_num);
1504 if ((fp = fopen(procfs_path, "r")) != NULL) {
1505 fgets(codec_version, CODEC_VERSION_MAX_LENGTH, fp);
1506 fclose(fp);
1507 } else {
1508 ALOGE("%s: ERROR. cannot open %s", __func__, procfs_path);
1509 return -ENOENT;
1510 }
1511 ALOGD("%s: codec version %s", __func__, codec_version);
1512 }
1513
1514 return 0;
1515}
1516
1517
Ashish Jain81eb2a82015-05-13 10:52:34 +05301518#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
1519
1520void get_default_compressed_channel_status(
1521 unsigned char *channel_status)
1522{
Ashish Jain81eb2a82015-05-13 10:52:34 +05301523 memset(channel_status,0,24);
1524
1525 /* block start bit in preamble bit 3 */
1526 channel_status[0] |= PROFESSIONAL;
1527 //compre out
1528 channel_status[0] |= NON_LPCM;
1529 // sample rate; fixed 48K for default/transcode
1530 channel_status[3] |= SR_48000;
1531}
1532
1533#ifdef HDMI_PASSTHROUGH_ENABLED
1534int32_t get_compressed_channel_status(void *audio_stream_data,
1535 uint32_t audio_frame_size,
1536 unsigned char *channel_status,
1537 enum audio_parser_code_type codec_type)
1538 // codec_type - AUDIO_PARSER_CODEC_AC3
1539 // - AUDIO_PARSER_CODEC_DTS
1540{
1541 unsigned char *stream;
1542 int ret = 0;
1543 stream = (unsigned char *)audio_stream_data;
1544
1545 if (audio_stream_data == NULL || audio_frame_size == 0) {
1546 ALOGW("no buffer to get channel status, return default for compress");
1547 get_default_compressed_channel_status(channel_status);
1548 return ret;
1549 }
1550
1551 memset(channel_status,0,24);
1552 if(init_audio_parser(stream, audio_frame_size, codec_type) == -1)
1553 {
1554 ALOGE("init audio parser failed");
1555 return -1;
1556 }
1557 ret = get_channel_status(channel_status, codec_type);
1558 return ret;
1559
1560}
1561
1562#endif
1563
1564void get_lpcm_channel_status(uint32_t sampleRate,
1565 unsigned char *channel_status)
1566{
1567 int32_t status = 0;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301568 memset(channel_status,0,24);
1569 /* block start bit in preamble bit 3 */
1570 channel_status[0] |= PROFESSIONAL;
1571 //LPCM OUT
1572 channel_status[0] &= ~NON_LPCM;
1573
1574 switch (sampleRate) {
1575 case 8000:
1576 case 11025:
1577 case 12000:
1578 case 16000:
1579 case 22050:
1580 channel_status[3] |= SR_NOTID;
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +05301581 break;
Ashish Jain81eb2a82015-05-13 10:52:34 +05301582 case 24000:
1583 channel_status[3] |= SR_24000;
1584 break;
1585 case 32000:
1586 channel_status[3] |= SR_32000;
1587 break;
1588 case 44100:
1589 channel_status[3] |= SR_44100;
1590 break;
1591 case 48000:
1592 channel_status[3] |= SR_48000;
1593 break;
1594 case 88200:
1595 channel_status[3] |= SR_88200;
1596 break;
1597 case 96000:
1598 channel_status[3] |= SR_96000;
1599 break;
1600 case 176400:
1601 channel_status[3] |= SR_176400;
1602 break;
1603 case 192000:
1604 channel_status[3] |= SR_192000;
1605 break;
1606 default:
1607 ALOGV("Invalid sample_rate %u\n", sampleRate);
1608 status = -1;
1609 break;
1610 }
1611}
1612
1613void audio_utils_set_hdmi_channel_status(struct stream_out *out, char * buffer, size_t bytes)
1614{
1615 unsigned char channel_status[24]={0};
1616 struct snd_aes_iec958 iec958;
1617 const char *mixer_ctl_name = "IEC958 Playback PCM Stream";
1618 struct mixer_ctl *ctl;
Satya Krishna Pindiprolif1cd92b2016-04-14 19:05:23 +05301619 ALOGV("%s: buffer %s bytes %zd", __func__, buffer, bytes);
Ashish Jain81eb2a82015-05-13 10:52:34 +05301620#ifdef HDMI_PASSTHROUGH_ENABLED
1621 if (audio_extn_is_dolby_format(out->format) &&
1622 /*TODO:Extend code to support DTS passthrough*/
1623 /*set compressed channel status bits*/
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +05301624 audio_extn_passthru_is_passthrough_stream(out)){
Ashish Jain81eb2a82015-05-13 10:52:34 +05301625 get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3);
1626 } else
1627#endif
1628 {
1629 /*set channel status bit for LPCM*/
1630 get_lpcm_channel_status(out->sample_rate, channel_status);
1631 }
1632
1633 memcpy(iec958.status, channel_status,sizeof(iec958.status));
1634 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name);
1635 if (!ctl) {
1636 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1637 __func__, mixer_ctl_name);
1638 return;
1639 }
1640 if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) {
1641 ALOGE("%s: Could not set channel status for ext HDMI ",
1642 __func__);
1643 return;
1644 }
1645
1646}
1647#endif
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301648
1649int audio_extn_utils_get_avt_device_drift(
1650 struct audio_usecase *usecase,
1651 struct audio_avt_device_drift_param *drift_param)
1652{
1653 int ret = 0, count = 0;
1654 char avt_device_drift_mixer_ctl_name[MIXER_PATH_MAX_LENGTH] = {0};
Naresh Tanniru6160c712017-04-17 15:43:48 +05301655 const char *backend = NULL;
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301656 struct mixer_ctl *ctl = NULL;
1657 struct audio_avt_device_drift_stats drift_stats;
1658 struct audio_device *adev = NULL;
1659
1660 if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
Naresh Tanniru6160c712017-04-17 15:43:48 +05301661 backend = platform_get_snd_device_backend_interface(usecase->out_snd_device);
1662 if (!backend) {
1663 ALOGE("%s: Unsupported device %d", __func__,
1664 usecase->stream.out->devices);
1665 ret = -EINVAL;
1666 goto done;
1667 }
1668 strlcpy(avt_device_drift_mixer_ctl_name,
1669 backend,
1670 MIXER_PATH_MAX_LENGTH);
1671
1672 count = strlen(backend);
1673 if (MIXER_PATH_MAX_LENGTH - count > 0) {
1674 strlcat(&avt_device_drift_mixer_ctl_name[count],
1675 " DRIFT",
1676 MIXER_PATH_MAX_LENGTH - count);
1677 } else {
1678 ret = -EINVAL;
1679 goto done;
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301680 }
1681 } else {
Naresh Tanniru7586e292017-04-13 10:38:13 +05301682 ALOGE("%s: Invalid usecase",__func__);
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301683 ret = -EINVAL;
Naresh Tanniru6160c712017-04-17 15:43:48 +05301684 goto done;
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301685 }
1686
Naresh Tanniru6160c712017-04-17 15:43:48 +05301687 adev = usecase->stream.out->dev;
Manish Dewangan3ccdea52017-02-13 19:31:54 +05301688 ctl = mixer_get_ctl_by_name(adev->mixer, avt_device_drift_mixer_ctl_name);
1689 if (!ctl) {
1690 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1691 __func__, avt_device_drift_mixer_ctl_name);
1692
1693 ret = -EINVAL;
1694 goto done;
1695 }
1696
1697 ALOGV("%s: Getting AV Timer vs Device Drift mixer ctrl name %s", __func__,
1698 avt_device_drift_mixer_ctl_name);
1699
1700 mixer_ctl_update(ctl);
1701 count = mixer_ctl_get_num_values(ctl);
1702 if (count != sizeof(struct audio_avt_device_drift_stats)) {
1703 ALOGE("%s: mixer_ctl_get_num_values() invalid drift_stats data size",
1704 __func__);
1705
1706 ret = -EINVAL;
1707 goto done;
1708 }
1709
1710 ret = mixer_ctl_get_array(ctl, (void *)&drift_stats, count);
1711 if (ret != 0) {
1712 ALOGE("%s: mixer_ctl_get_array() failed to get drift_stats Params",
1713 __func__);
1714
1715 ret = -EINVAL;
1716 goto done;
1717 }
1718 memcpy(drift_param, &drift_stats.drift_param,
1719 sizeof(struct audio_avt_device_drift_param));
1720done:
1721 return ret;
1722}
Manish Dewangan07de2142017-02-27 19:27:20 +05301723
1724#ifdef SNDRV_COMPRESS_PATH_DELAY
1725int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out)
1726{
1727 int ret = -EINVAL;
1728 struct snd_compr_metadata metadata;
1729 int delay_ms = COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
1730
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -07001731 if (property_get_bool("vendor.audio.playback.dsp.pathdelay", false)) {
Manish Dewangan07de2142017-02-27 19:27:20 +05301732 ALOGD("%s:: Quering DSP delay %d",__func__, __LINE__);
1733 if (!(is_offload_usecase(out->usecase))) {
1734 ALOGE("%s:: not supported for non offload session", __func__);
1735 goto exit;
1736 }
1737
1738 if (!out->compr) {
1739 ALOGD("%s:: Invalid compress handle,returning default dsp latency",
1740 __func__);
1741 goto exit;
1742 }
1743
1744 metadata.key = SNDRV_COMPRESS_PATH_DELAY;
1745 ret = compress_get_metadata(out->compr, &metadata);
1746 if(ret) {
1747 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
1748 goto exit;
1749 }
1750 delay_ms = metadata.value[0] / 1000; /*convert to ms*/
1751 } else {
1752 ALOGD("%s:: Using Fix DSP delay",__func__);
1753 }
1754
1755exit:
1756 ALOGD("%s:: delay in ms is %d",__func__, delay_ms);
1757 return delay_ms;
1758}
1759#else
1760int audio_extn_utils_compress_get_dsp_latency(struct stream_out *out __unused)
1761{
1762 return COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
1763}
1764#endif
Manish Dewangan69426c82017-01-30 17:35:36 +05301765
1766#ifdef SNDRV_COMPRESS_RENDER_MODE
1767int audio_extn_utils_compress_set_render_mode(struct stream_out *out)
1768{
1769 struct snd_compr_metadata metadata;
1770 int ret = -EINVAL;
1771
1772 if (!(is_offload_usecase(out->usecase))) {
1773 ALOGE("%s:: not supported for non offload session", __func__);
1774 goto exit;
1775 }
1776
1777 if (!out->compr) {
1778 ALOGD("%s:: Invalid compress handle",
1779 __func__);
1780 goto exit;
1781 }
1782
1783 ALOGD("%s:: render mode %d", __func__, out->render_mode);
1784
1785 metadata.key = SNDRV_COMPRESS_RENDER_MODE;
1786 if (out->render_mode == RENDER_MODE_AUDIO_MASTER) {
1787 metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_AUDIO_MASTER;
1788 } else if (out->render_mode == RENDER_MODE_AUDIO_STC_MASTER) {
1789 metadata.value[0] = SNDRV_COMPRESS_RENDER_MODE_STC_MASTER;
1790 } else {
1791 ret = 0;
1792 goto exit;
1793 }
1794 ret = compress_set_metadata(out->compr, &metadata);
1795 if(ret) {
1796 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
1797 }
1798exit:
1799 return ret;
1800}
1801#else
1802int audio_extn_utils_compress_set_render_mode(struct stream_out *out __unused)
1803{
1804 ALOGD("%s:: configuring render mode not supported", __func__);
1805 return 0;
1806}
1807#endif
Manish Dewangan58229382017-02-02 15:48:41 +05301808
1809#ifdef SNDRV_COMPRESS_CLK_REC_MODE
1810int audio_extn_utils_compress_set_clk_rec_mode(
1811 struct audio_usecase *usecase)
1812{
1813 struct snd_compr_metadata metadata;
1814 struct stream_out *out = NULL;
1815 int ret = -EINVAL;
1816
Naresh Tanniru7586e292017-04-13 10:38:13 +05301817 if (usecase == NULL || usecase->type != PCM_PLAYBACK) {
Manish Dewangan58229382017-02-02 15:48:41 +05301818 ALOGE("%s:: Invalid use case", __func__);
1819 goto exit;
1820 }
1821
1822 out = usecase->stream.out;
1823 if (!out) {
1824 ALOGE("%s:: invalid stream", __func__);
1825 goto exit;
1826 }
1827
1828 if (!is_offload_usecase(out->usecase)) {
1829 ALOGE("%s:: not supported for non offload session", __func__);
1830 goto exit;
1831 }
1832
1833 if (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER) {
1834 ALOGD("%s:: clk recovery is only supported in STC render mode",
1835 __func__);
1836 ret = 0;
1837 goto exit;
1838 }
1839
1840 if (!out->compr) {
1841 ALOGD("%s:: Invalid compress handle",
1842 __func__);
1843 goto exit;
1844 }
1845 metadata.key = SNDRV_COMPRESS_CLK_REC_MODE;
1846 switch(usecase->out_snd_device) {
1847 case SND_DEVICE_OUT_HDMI:
1848 case SND_DEVICE_OUT_SPEAKER_AND_HDMI:
1849 case SND_DEVICE_OUT_DISPLAY_PORT:
1850 case SND_DEVICE_OUT_SPEAKER_AND_DISPLAY_PORT:
1851 metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_NONE;
1852 break;
1853 default:
1854 metadata.value[0] = SNDRV_COMPRESS_CLK_REC_MODE_AUTO;
1855 break;
1856 }
1857
1858 ALOGD("%s:: clk recovery mode %d",__func__, metadata.value[0]);
1859
1860 ret = compress_set_metadata(out->compr, &metadata);
1861 if(ret) {
1862 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
1863 }
1864
1865exit:
1866 return ret;
1867}
1868#else
1869int audio_extn_utils_compress_set_clk_rec_mode(
1870 struct audio_usecase *usecase __unused)
1871{
1872 ALOGD("%s:: configuring render mode not supported", __func__);
1873 return 0;
1874}
1875#endif
Manish Dewangan27346042017-03-01 12:56:12 +05301876
1877#ifdef SNDRV_COMPRESS_RENDER_WINDOW
1878int audio_extn_utils_compress_set_render_window(
1879 struct stream_out *out,
1880 struct audio_out_render_window_param *render_window)
1881{
1882 struct snd_compr_metadata metadata;
1883 int ret = -EINVAL;
1884
Manish Dewangan27346042017-03-01 12:56:12 +05301885 if(render_window == NULL) {
1886 ALOGE("%s:: Invalid render_window", __func__);
1887 goto exit;
1888 }
1889
Aniket Kumar Lata1e1d3662017-06-01 18:45:48 -07001890 ALOGD("%s:: render window start 0x%"PRIx64" end 0x%"PRIx64"",
1891 __func__,render_window->render_ws, render_window->render_we);
1892
Manish Dewangan27346042017-03-01 12:56:12 +05301893 if (!is_offload_usecase(out->usecase)) {
1894 ALOGE("%s:: not supported for non offload session", __func__);
1895 goto exit;
1896 }
1897
Naresh Tanniru6160c712017-04-17 15:43:48 +05301898 if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) &&
1899 (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) {
Manish Dewangan27346042017-03-01 12:56:12 +05301900 ALOGD("%s:: only supported in timestamp mode, current "
1901 "render mode mode %d", __func__, out->render_mode);
1902 goto exit;
1903 }
1904
1905 if (!out->compr) {
1906 ALOGW("%s:: offload session not yet opened,"
1907 "render window will be configure later", __func__);
1908 /* store render window to reconfigure in start_output_stream() */
1909 goto exit;
1910 }
1911
1912 metadata.key = SNDRV_COMPRESS_RENDER_WINDOW;
1913 /*render window start value */
1914 metadata.value[0] = 0xFFFFFFFF & render_window->render_ws; /* lsb */
1915 metadata.value[1] = \
1916 (0xFFFFFFFF00000000 & render_window->render_ws) >> 32; /* msb*/
1917 /*render window end value */
1918 metadata.value[2] = 0xFFFFFFFF & render_window->render_we; /* lsb */
1919 metadata.value[3] = \
1920 (0xFFFFFFFF00000000 & render_window->render_we) >> 32; /* msb*/
1921
1922 ret = compress_set_metadata(out->compr, &metadata);
1923 if(ret) {
1924 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
1925 }
1926
1927exit:
1928 return ret;
1929}
1930#else
1931int audio_extn_utils_compress_set_render_window(
1932 struct stream_out *out __unused,
1933 struct audio_out_render_window_param *render_window __unused)
1934{
1935 ALOGD("%s:: configuring render window not supported", __func__);
1936 return 0;
1937}
1938#endif
Manish Dewangan14956cc2017-02-14 18:54:42 +05301939
1940#ifdef SNDRV_COMPRESS_START_DELAY
1941int audio_extn_utils_compress_set_start_delay(
1942 struct stream_out *out,
1943 struct audio_out_start_delay_param *delay_param)
1944{
1945 struct snd_compr_metadata metadata;
1946 int ret = -EINVAL;
1947
1948 if(delay_param == NULL) {
1949 ALOGE("%s:: Invalid delay_param", __func__);
1950 goto exit;
1951 }
1952
1953 ALOGD("%s:: render start delay 0x%"PRIx64" ", __func__,
1954 delay_param->start_delay);
1955
1956 if (!is_offload_usecase(out->usecase)) {
1957 ALOGE("%s:: not supported for non offload session", __func__);
1958 goto exit;
1959 }
1960
Naresh Tanniru6160c712017-04-17 15:43:48 +05301961 if ((out->render_mode != RENDER_MODE_AUDIO_MASTER) &&
1962 (out->render_mode != RENDER_MODE_AUDIO_STC_MASTER)) {
Manish Dewangan14956cc2017-02-14 18:54:42 +05301963 ALOGD("%s:: only supported in timestamp mode, current "
1964 "render mode mode %d", __func__, out->render_mode);
1965 goto exit;
1966 }
1967
1968 if (!out->compr) {
1969 ALOGW("%s:: offload session not yet opened,"
1970 "start delay will be configure later", __func__);
1971 goto exit;
1972 }
1973
1974 metadata.key = SNDRV_COMPRESS_START_DELAY;
1975 metadata.value[0] = 0xFFFFFFFF & delay_param->start_delay; /* lsb */
1976 metadata.value[1] = \
1977 (0xFFFFFFFF00000000 & delay_param->start_delay) >> 32; /* msb*/
1978
1979 ret = compress_set_metadata(out->compr, &metadata);
1980 if(ret) {
1981 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
1982 }
1983
1984exit:
1985 return ret;
1986}
1987#else
1988int audio_extn_utils_compress_set_start_delay(
1989 struct stream_out *out __unused,
1990 struct audio_out_start_delay_param *delay_param __unused)
1991{
1992 ALOGD("%s:: configuring render window not supported", __func__);
1993 return 0;
1994}
1995#endif
Vignesh Kulothungan55396882017-04-20 14:37:02 -07001996
1997#define MAX_SND_CARD 8
1998#define RETRY_US 500000
1999#define RETRY_NUMBER 10
2000
2001int audio_extn_utils_get_snd_card_num()
2002{
2003
2004 void *hw_info = NULL;
2005 struct mixer *mixer = NULL;
2006 int retry_num = 0;
2007 int snd_card_num = 0;
2008 char* snd_card_name = NULL;
2009
2010 while (snd_card_num < MAX_SND_CARD) {
2011 mixer = mixer_open(snd_card_num);
2012
2013 while (!mixer && retry_num < RETRY_NUMBER) {
2014 usleep(RETRY_US);
2015 mixer = mixer_open(snd_card_num);
2016 retry_num++;
2017 }
2018
2019 if (!mixer) {
2020 ALOGE("%s: Unable to open the mixer card: %d", __func__,
2021 snd_card_num);
2022 retry_num = 0;
2023 snd_card_num++;
2024 continue;
2025 }
2026
2027 snd_card_name = strdup(mixer_get_name(mixer));
2028 if (!snd_card_name) {
2029 ALOGE("failed to allocate memory for snd_card_name\n");
2030 mixer_close(mixer);
2031 return -1;
2032 }
2033 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
2034
2035 hw_info = hw_info_init(snd_card_name);
2036 if (hw_info) {
2037 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
2038 break;
2039 }
2040 ALOGE("%s: Failed to init hardware info", __func__);
2041 retry_num = 0;
2042 snd_card_num++;
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002043
Dhananjay Kumara7e27832017-07-11 15:40:39 +05302044 free(snd_card_name);
2045 snd_card_name = NULL;
2046
2047 mixer_close(mixer);
2048 mixer = NULL;
2049 }
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002050 if (snd_card_name)
2051 free(snd_card_name);
Dhananjay Kumara7e27832017-07-11 15:40:39 +05302052 if (mixer)
2053 mixer_close(mixer);
2054 if (hw_info)
2055 hw_info_deinit(hw_info);
Vignesh Kulothungan55396882017-04-20 14:37:02 -07002056
2057 if (snd_card_num >= MAX_SND_CARD) {
2058 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
2059 return -1;
2060 }
2061
2062 return snd_card_num;
2063}
Naresh Tanniru6160c712017-04-17 15:43:48 +05302064
2065#ifdef SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK
2066int audio_extn_utils_compress_enable_drift_correction(
2067 struct stream_out *out,
2068 struct audio_out_enable_drift_correction *drift)
2069{
2070 struct snd_compr_metadata metadata;
2071 int ret = -EINVAL;
2072
2073 if(drift == NULL) {
2074 ALOGE("%s:: Invalid param", __func__);
2075 goto exit;
2076 }
2077
2078 ALOGD("%s:: drift enable %d", __func__,drift->enable);
2079
2080 if (!is_offload_usecase(out->usecase)) {
2081 ALOGE("%s:: not supported for non offload session", __func__);
2082 goto exit;
2083 }
2084
2085 if (!out->compr) {
2086 ALOGW("%s:: offload session not yet opened,"
2087 "start delay will be configure later", __func__);
2088 goto exit;
2089 }
2090
2091 metadata.key = SNDRV_COMPRESS_ENABLE_ADJUST_SESSION_CLOCK;
2092 metadata.value[0] = drift->enable;
2093 out->drift_correction_enabled = drift->enable;
2094
2095 ret = compress_set_metadata(out->compr, &metadata);
2096 if(ret) {
2097 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
2098 out->drift_correction_enabled = false;
2099 }
2100
2101exit:
2102 return ret;
2103}
2104#else
2105int audio_extn_utils_compress_enable_drift_correction(
2106 struct stream_out *out __unused,
2107 struct audio_out_enable_drift_correction *drift __unused)
2108{
2109 ALOGD("%s:: configuring drift enablement not supported", __func__);
2110 return 0;
2111}
2112#endif
2113
2114#ifdef SNDRV_COMPRESS_ADJUST_SESSION_CLOCK
2115int audio_extn_utils_compress_correct_drift(
2116 struct stream_out *out,
2117 struct audio_out_correct_drift *drift_param)
2118{
2119 struct snd_compr_metadata metadata;
2120 int ret = -EINVAL;
2121
2122 if (drift_param == NULL) {
2123 ALOGE("%s:: Invalid drift_param", __func__);
2124 goto exit;
2125 }
2126
2127 ALOGD("%s:: adjust time 0x%"PRIx64" ", __func__,
2128 drift_param->adjust_time);
2129
2130 if (!is_offload_usecase(out->usecase)) {
2131 ALOGE("%s:: not supported for non offload session", __func__);
2132 goto exit;
2133 }
2134
2135 if (!out->compr) {
2136 ALOGW("%s:: offload session not yet opened", __func__);
2137 goto exit;
2138 }
2139
2140 if (!out->drift_correction_enabled) {
2141 ALOGE("%s:: drift correction not enabled", __func__);
2142 goto exit;
2143 }
2144
2145 metadata.key = SNDRV_COMPRESS_ADJUST_SESSION_CLOCK;
2146 metadata.value[0] = 0xFFFFFFFF & drift_param->adjust_time; /* lsb */
2147 metadata.value[1] = \
2148 (0xFFFFFFFF00000000 & drift_param->adjust_time) >> 32; /* msb*/
2149
2150 ret = compress_set_metadata(out->compr, &metadata);
2151 if(ret)
2152 ALOGE("%s::error %s", __func__, compress_get_error(out->compr));
2153exit:
2154 return ret;
2155}
2156#else
2157int audio_extn_utils_compress_correct_drift(
2158 struct stream_out *out __unused,
2159 struct audio_out_correct_drift *drift_param __unused)
2160{
2161 ALOGD("%s:: setting adjust clock not supported", __func__);
2162 return 0;
2163}
2164#endif
Naresh Tanniru29bce4e2017-04-27 17:54:30 +05302165
2166int audio_extn_utils_set_channel_map(
2167 struct stream_out *out,
2168 struct audio_out_channel_map_param *channel_map_param)
2169{
2170 int ret = -EINVAL, i = 0;
2171 int channels = audio_channel_count_from_out_mask(out->channel_mask);
2172
2173 if (channel_map_param == NULL) {
2174 ALOGE("%s:: Invalid channel_map", __func__);
2175 goto exit;
2176 }
2177
2178 if (channel_map_param->channels != channels) {
2179 ALOGE("%s:: Channels(%d) does not match stream channels(%d)",
2180 __func__, channel_map_param->channels, channels);
2181 goto exit;
2182 }
2183
2184 for ( i = 0; i < channels; i++) {
2185 ALOGV("%s:: channel_map[%d]- %d", __func__, i, channel_map_param->channel_map[i]);
2186 out->channel_map_param.channel_map[i] = channel_map_param->channel_map[i];
2187 }
2188 ret = 0;
2189exit:
2190 return ret;
2191}