blob: e91736753e6e1864dee36f85188ca434253a15c7 [file] [log] [blame]
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001/*
Manish Dewangan93672f12015-08-24 20:30:31 +05302 * Copyright (c) 2014-2015, 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"
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070037
Ashish Jain5a97ddd2015-05-13 10:52:34 +053038#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
39#include "audio_parsers.h"
40#endif
41
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070042#define AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_output_policy.conf"
43
44#define OUTPUTS_TAG "outputs"
45
46#define DYNAMIC_VALUE_TAG "dynamic"
47#define FLAGS_TAG "flags"
48#define FORMATS_TAG "formats"
49#define SAMPLING_RATES_TAG "sampling_rates"
50#define BIT_WIDTH_TAG "bit_width"
51#define APP_TYPE_TAG "app_type"
52
53#define STRING_TO_ENUM(string) { #string, string }
54#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
55
Ben Rombergera04fabc2014-11-14 12:16:03 -080056#define BASE_TABLE_SIZE 64
57#define MAX_BASEINDEX_LEN 256
58
Ashish Jain5a97ddd2015-05-13 10:52:34 +053059#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
60#define PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */
61#define NON_LPCM (1<<1) /* 0 = audio, 1 = non-audio */
62#define SR_44100 (0<<0) /* 44.1kHz */
63#define SR_NOTID (1<<0) /* non indicated */
64#define SR_48000 (2<<0) /* 48kHz */
65#define SR_32000 (3<<0) /* 32kHz */
66#define SR_22050 (4<<0) /* 22.05kHz */
67#define SR_24000 (6<<0) /* 24kHz */
68#define SR_88200 (8<<0) /* 88.2kHz */
69#define SR_96000 (10<<0) /* 96kHz */
70#define SR_176400 (12<<0) /* 176.4kHz */
71#define SR_192000 (14<<0) /* 192kHz */
72
73#endif
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070074struct string_to_enum {
75 const char *name;
76 uint32_t value;
77};
78
79const struct string_to_enum s_flag_name_to_enum_table[] = {
80 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
Naresh Tanniru06f99432015-08-26 14:01:20 -070081 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070082 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
83 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST),
84 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DEEP_BUFFER),
85 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD),
86 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_NON_BLOCKING),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070087 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_HW_AV_SYNC),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070088#ifdef INCALL_MUSIC_ENABLED
89 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_INCALL_MUSIC),
90#endif
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070091 STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -070092};
93
94const struct string_to_enum s_format_name_to_enum_table[] = {
95 STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT),
96 STRING_TO_ENUM(AUDIO_FORMAT_PCM_8_BIT),
97 STRING_TO_ENUM(AUDIO_FORMAT_MP3),
98 STRING_TO_ENUM(AUDIO_FORMAT_AAC),
99 STRING_TO_ENUM(AUDIO_FORMAT_VORBIS),
Mingming Yinae3530f2014-07-03 16:50:18 -0700100 STRING_TO_ENUM(AUDIO_FORMAT_AMR_NB),
101 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700102 STRING_TO_ENUM(AUDIO_FORMAT_AC3),
Mingming Yinae3530f2014-07-03 16:50:18 -0700103 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3),
Satya Krishna Pindiproli4cda5352015-08-12 18:21:25 +0530104#ifdef AUDIO_EXTN_FORMATS_ENABLED
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700105 STRING_TO_ENUM(AUDIO_FORMAT_DTS),
106 STRING_TO_ENUM(AUDIO_FORMAT_DTS_LBR),
107 STRING_TO_ENUM(AUDIO_FORMAT_WMA),
108 STRING_TO_ENUM(AUDIO_FORMAT_WMA_PRO),
109 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADIF),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700110 STRING_TO_ENUM(AUDIO_FORMAT_AMR_WB_PLUS),
111 STRING_TO_ENUM(AUDIO_FORMAT_EVRC),
112 STRING_TO_ENUM(AUDIO_FORMAT_EVRCB),
113 STRING_TO_ENUM(AUDIO_FORMAT_EVRCWB),
114 STRING_TO_ENUM(AUDIO_FORMAT_QCELP),
115 STRING_TO_ENUM(AUDIO_FORMAT_MP2),
116 STRING_TO_ENUM(AUDIO_FORMAT_EVRCNW),
117 STRING_TO_ENUM(AUDIO_FORMAT_PCM_16_BIT_OFFLOAD),
118 STRING_TO_ENUM(AUDIO_FORMAT_PCM_24_BIT_OFFLOAD),
Amit Shekhar6f461b12014-08-01 14:52:58 -0700119 STRING_TO_ENUM(AUDIO_FORMAT_FLAC),
Satya Krishna Pindiproli70471602015-04-24 19:12:43 +0530120 STRING_TO_ENUM(AUDIO_FORMAT_ALAC),
121 STRING_TO_ENUM(AUDIO_FORMAT_APE),
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700122 STRING_TO_ENUM(AUDIO_FORMAT_E_AC3_JOC),
Alexy Josephcd8eaed2014-12-11 12:46:53 -0800123 STRING_TO_ENUM(AUDIO_FORMAT_AAC_LC),
124 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V1),
125 STRING_TO_ENUM(AUDIO_FORMAT_AAC_HE_V2),
Manish Dewangan93672f12015-08-24 20:30:31 +0530126 STRING_TO_ENUM(AUDIO_FORMAT_AAC_ADTS),
127 STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_LC),
128 STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_HE_V1),
129 STRING_TO_ENUM(AUDIO_FORMAT_AAC_SUB_HE_V2),
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700130#endif
131};
132
Ben Rombergera04fabc2014-11-14 12:16:03 -0800133static char bTable[BASE_TABLE_SIZE] = {
134 'A','B','C','D','E','F','G','H','I','J','K','L',
135 'M','N','O','P','Q','R','S','T','U','V','W','X',
136 'Y','Z','a','b','c','d','e','f','g','h','i','j',
137 'k','l','m','n','o','p','q','r','s','t','u','v',
138 'w','x','y','z','0','1','2','3','4','5','6','7',
139 '8','9','+','/'
140};
141
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700142static uint32_t string_to_enum(const struct string_to_enum *table, size_t size,
143 const char *name)
144{
145 size_t i;
146 for (i = 0; i < size; i++) {
147 if (strcmp(table[i].name, name) == 0) {
148 ALOGV("%s found %s", __func__, table[i].name);
149 return table[i].value;
150 }
151 }
152 return 0;
153}
154
155static audio_output_flags_t parse_flag_names(char *name)
156{
157 uint32_t flag = 0;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800158 char *last_r;
159 char *flag_name = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700160 while (flag_name != NULL) {
161 if (strlen(flag_name) != 0) {
162 flag |= string_to_enum(s_flag_name_to_enum_table,
163 ARRAY_SIZE(s_flag_name_to_enum_table),
164 flag_name);
165 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800166 flag_name = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700167 }
168
169 ALOGV("parse_flag_names: flag - %d", flag);
170 return (audio_output_flags_t)flag;
171}
172
173static void parse_format_names(char *name, struct streams_output_cfg *so_info)
174{
175 struct stream_format *sf_info = NULL;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800176 char *last_r;
177 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700178
179 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG) == 0)
180 return;
181
182 list_init(&so_info->format_list);
183 while (str != NULL) {
184 audio_format_t format = (audio_format_t)string_to_enum(s_format_name_to_enum_table,
185 ARRAY_SIZE(s_format_name_to_enum_table), str);
186 ALOGV("%s: format - %d", __func__, format);
187 if (format != 0) {
188 sf_info = (struct stream_format *)calloc(1, sizeof(struct stream_format));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700189 if (sf_info == NULL)
190 break; /* return whatever was parsed */
191
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700192 sf_info->format = format;
193 list_add_tail(&so_info->format_list, &sf_info->list);
194 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800195 str = strtok_r(NULL, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700196 }
197}
198
Amit Shekhar6f461b12014-08-01 14:52:58 -0700199static void parse_sample_rate_names(char *name, struct streams_output_cfg *so_info)
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700200{
Amit Shekhar6f461b12014-08-01 14:52:58 -0700201 struct stream_sample_rate *ss_info = NULL;
202 uint32_t sample_rate = 48000;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800203 char *last_r;
204 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700205
Amit Shekhar6f461b12014-08-01 14:52:58 -0700206 if (str != NULL && 0 == strcmp(str, DYNAMIC_VALUE_TAG))
207 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700208
Amit Shekhar6f461b12014-08-01 14:52:58 -0700209 list_init(&so_info->sample_rate_list);
210 while (str != NULL) {
211 sample_rate = (uint32_t)strtol(str, (char **)NULL, 10);
212 ALOGV("%s: sample_rate - %d", __func__, sample_rate);
213 if (0 != sample_rate) {
214 ss_info = (struct stream_sample_rate *)calloc(1, sizeof(struct stream_sample_rate));
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800215 if (!ss_info) {
216 ALOGE("%s: memory allocation failure", __func__);
217 return;
218 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700219 ss_info->sample_rate = sample_rate;
220 list_add_tail(&so_info->sample_rate_list, &ss_info->list);
221 }
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800222 str = strtok_r(NULL, "|", &last_r);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700223 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700224}
225
226static int parse_bit_width_names(char *name)
227{
228 int bit_width = 16;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800229 char *last_r;
230 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700231
232 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
233 bit_width = (int)strtol(str, (char **)NULL, 10);
234
235 ALOGV("%s: bit_width - %d", __func__, bit_width);
236 return bit_width;
237}
238
239static int parse_app_type_names(void *platform, char *name)
240{
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700241 int app_type = platform_get_default_app_type(platform);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800242 char *last_r;
243 char *str = strtok_r(name, "|", &last_r);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700244
245 if (str != NULL && strcmp(str, DYNAMIC_VALUE_TAG))
246 app_type = (int)strtol(str, (char **)NULL, 10);
247
248 ALOGV("%s: app_type - %d", __func__, app_type);
249 return app_type;
250}
251
252static void update_streams_output_cfg_list(cnode *root, void *platform,
253 struct listnode *streams_output_cfg_list)
254{
255 cnode *node = root->first_child;
256 struct streams_output_cfg *so_info;
257
258 ALOGV("%s", __func__);
259 so_info = (struct streams_output_cfg *)calloc(1, sizeof(struct streams_output_cfg));
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700260
261 if (!so_info) {
262 ALOGE("failed to allocate mem for so_info list element");
263 return;
264 }
265
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700266 while (node) {
267 if (strcmp(node->name, FLAGS_TAG) == 0) {
268 so_info->flags = parse_flag_names((char *)node->value);
269 } else if (strcmp(node->name, FORMATS_TAG) == 0) {
270 parse_format_names((char *)node->value, so_info);
271 } else if (strcmp(node->name, SAMPLING_RATES_TAG) == 0) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700272 so_info->app_type_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
273 parse_sample_rate_names((char *)node->value, so_info);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700274 } else if (strcmp(node->name, BIT_WIDTH_TAG) == 0) {
275 so_info->app_type_cfg.bit_width = parse_bit_width_names((char *)node->value);
276 } else if (strcmp(node->name, APP_TYPE_TAG) == 0) {
277 so_info->app_type_cfg.app_type = parse_app_type_names(platform, (char *)node->value);
278 }
279 node = node->next;
280 }
281 list_add_tail(streams_output_cfg_list, &so_info->list);
282}
283
284static void load_output(cnode *root, void *platform,
285 struct listnode *streams_output_cfg_list)
286{
287 cnode *node = config_find(root, OUTPUTS_TAG);
288 if (node == NULL) {
289 ALOGE("%s: could not load output, node is NULL", __func__);
290 return;
291 }
292
293 node = node->first_child;
294 while (node) {
295 ALOGV("%s: loading output %s", __func__, node->name);
296 update_streams_output_cfg_list(node, platform, streams_output_cfg_list);
297 node = node->next;
298 }
299}
300
301static void send_app_type_cfg(void *platform, struct mixer *mixer,
302 struct listnode *streams_output_cfg_list)
303{
304 int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT] = {-1};
305 int length = 0, i, num_app_types = 0;
306 struct listnode *node;
307 bool update;
308 struct mixer_ctl *ctl = NULL;
309 const char *mixer_ctl_name = "App Type Config";
310 struct streams_output_cfg *so_info;
311
312 if (!mixer) {
313 ALOGE("%s: mixer is null",__func__);
314 return;
315 }
316 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
317 if (!ctl) {
318 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
319 return;
320 }
321 if (streams_output_cfg_list == NULL) {
322 app_type_cfg[length++] = 1;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700323 app_type_cfg[length++] = platform_get_default_app_type(platform);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700324 app_type_cfg[length++] = 48000;
325 app_type_cfg[length++] = 16;
326 mixer_ctl_set_array(ctl, app_type_cfg, length);
327 return;
328 }
329
330 app_type_cfg[length++] = num_app_types;
331 list_for_each(node, streams_output_cfg_list) {
332 so_info = node_to_item(node, struct streams_output_cfg, list);
333 update = true;
334 for (i=0; i<length; i=i+3) {
335 if (app_type_cfg[i+1] == -1)
336 break;
337 else if (app_type_cfg[i+1] == so_info->app_type_cfg.app_type) {
338 update = false;
339 break;
340 }
341 }
342 if (update && ((length + 3) <= MAX_LENGTH_MIXER_CONTROL_IN_INT)) {
343 num_app_types += 1 ;
344 app_type_cfg[length++] = so_info->app_type_cfg.app_type;
345 app_type_cfg[length++] = so_info->app_type_cfg.sample_rate;
346 app_type_cfg[length++] = so_info->app_type_cfg.bit_width;
347 }
348 }
349 ALOGV("%s: num_app_types: %d", __func__, num_app_types);
350 if (num_app_types) {
351 app_type_cfg[0] = num_app_types;
352 mixer_ctl_set_array(ctl, app_type_cfg, length);
353 }
354}
355
356void audio_extn_utils_update_streams_output_cfg_list(void *platform,
357 struct mixer *mixer,
358 struct listnode *streams_output_cfg_list)
359{
360 cnode *root;
361 char *data;
362
363 ALOGV("%s", __func__);
364 list_init(streams_output_cfg_list);
365 data = (char *)load_file(AUDIO_OUTPUT_POLICY_VENDOR_CONFIG_FILE, NULL);
366 if (data == NULL) {
367 send_app_type_cfg(platform, mixer, NULL);
368 ALOGE("%s: could not load output policy config file", __func__);
369 return;
370 }
371
372 root = config_node("", "");
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700373 if (root == NULL) {
374 ALOGE("cfg_list, NULL config root");
375 return;
376 }
377
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700378 config_load(root, data);
379 load_output(root, platform, streams_output_cfg_list);
380
381 send_app_type_cfg(platform, mixer, streams_output_cfg_list);
382}
383
384void audio_extn_utils_dump_streams_output_cfg_list(
385 struct listnode *streams_output_cfg_list)
386{
387 int i=0;
388 struct listnode *node_i, *node_j;
389 struct streams_output_cfg *so_info;
390 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700391 struct stream_sample_rate *ss_info;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700392 ALOGV("%s", __func__);
393 list_for_each(node_i, streams_output_cfg_list) {
394 so_info = node_to_item(node_i, struct streams_output_cfg, list);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700395 ALOGV("%s: flags-%d, output_sample_rate-%d, output_bit_width-%d, app_type-%d",
396 __func__, so_info->flags, so_info->app_type_cfg.sample_rate,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700397 so_info->app_type_cfg.bit_width, so_info->app_type_cfg.app_type);
398 list_for_each(node_j, &so_info->format_list) {
399 sf_info = node_to_item(node_j, struct stream_format, list);
400 ALOGV("format-%x", sf_info->format);
401 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700402 list_for_each(node_j, &so_info->sample_rate_list) {
403 ss_info = node_to_item(node_j, struct stream_sample_rate, list);
404 ALOGV("sample rate-%d", ss_info->sample_rate);
405 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700406 }
407}
408
409void audio_extn_utils_release_streams_output_cfg_list(
410 struct listnode *streams_output_cfg_list)
411{
412 struct listnode *node_i, *node_j;
413 struct streams_output_cfg *so_info;
414 struct stream_format *sf_info;
415
416 ALOGV("%s", __func__);
417 while (!list_empty(streams_output_cfg_list)) {
418 node_i = list_head(streams_output_cfg_list);
419 so_info = node_to_item(node_i, struct streams_output_cfg, list);
420 while (!list_empty(&so_info->format_list)) {
421 node_j = list_head(&so_info->format_list);
422 list_remove(node_j);
423 free(node_to_item(node_j, struct stream_format, list));
424 }
Amit Shekhar6f461b12014-08-01 14:52:58 -0700425 while (!list_empty(&so_info->sample_rate_list)) {
426 node_j = list_head(&so_info->sample_rate_list);
427 list_remove(node_j);
428 free(node_to_item(node_j, struct stream_sample_rate, list));
429 }
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700430 list_remove(node_i);
431 free(node_to_item(node_i, struct streams_output_cfg, list));
432 }
433}
434
Amit Shekhar6f461b12014-08-01 14:52:58 -0700435static bool set_output_cfg(struct streams_output_cfg *so_info,
436 struct stream_app_type_cfg *app_type_cfg,
437 uint32_t sample_rate, uint32_t bit_width)
438 {
439 struct listnode *node_i;
440 struct stream_sample_rate *ss_info;
441 list_for_each(node_i, &so_info->sample_rate_list) {
442 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
443 if ((sample_rate <= ss_info->sample_rate) &&
444 (bit_width == so_info->app_type_cfg.bit_width)) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700445
Amit Shekhar6f461b12014-08-01 14:52:58 -0700446 app_type_cfg->app_type = so_info->app_type_cfg.app_type;
447 app_type_cfg->sample_rate = ss_info->sample_rate;
448 app_type_cfg->bit_width = so_info->app_type_cfg.bit_width;
449 ALOGV("%s app_type_cfg->app_type %d, app_type_cfg->sample_rate %d, app_type_cfg->bit_width %d",
450 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
451 return true;
452 }
453 }
454 /*
455 * Reiterate through the list assuming dafault sample rate.
456 * Handles scenario where input sample rate is higher
457 * than all sample rates in list for the input bit width.
458 */
459 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800460
Amit Shekhar6f461b12014-08-01 14:52:58 -0700461 list_for_each(node_i, &so_info->sample_rate_list) {
462 ss_info = node_to_item(node_i, struct stream_sample_rate, list);
463 if ((sample_rate <= ss_info->sample_rate) &&
464 (bit_width == so_info->app_type_cfg.bit_width)) {
465 app_type_cfg->app_type = so_info->app_type_cfg.app_type;
466 app_type_cfg->sample_rate = sample_rate;
467 app_type_cfg->bit_width = so_info->app_type_cfg.bit_width;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800468 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 -0700469 __func__, app_type_cfg->app_type, app_type_cfg->sample_rate, app_type_cfg->bit_width);
470 return true;
471 }
472 }
473 return false;
474}
475
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700476void audio_extn_utils_update_stream_app_type_cfg(void *platform,
477 struct listnode *streams_output_cfg_list,
Amit Shekhar1d896042014-10-03 13:16:09 -0700478 audio_devices_t devices,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700479 audio_output_flags_t flags,
480 audio_format_t format,
Amit Shekhar6f461b12014-08-01 14:52:58 -0700481 uint32_t sample_rate,
482 uint32_t bit_width,
Manish Dewangan837dc462015-05-27 10:17:41 +0530483 audio_channel_mask_t channel_mask,
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700484 struct stream_app_type_cfg *app_type_cfg)
485{
Amit Shekhar6f461b12014-08-01 14:52:58 -0700486 struct listnode *node_i, *node_j, *node_k;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700487 struct streams_output_cfg *so_info;
488 struct stream_format *sf_info;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700489 struct stream_sample_rate *ss_info;
Manish Dewangan837dc462015-05-27 10:17:41 +0530490 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700491
Amit Shekhar1d896042014-10-03 13:16:09 -0700492 if ((24 == bit_width) &&
493 (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Amit Shekhar5a39c912014-10-14 15:39:30 -0700494 int32_t bw = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
495 if (-ENOSYS != bw)
496 bit_width = (uint32_t)bw;
Amit Shekhar1d896042014-10-03 13:16:09 -0700497 sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
498 ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
499 }
500
Manish Dewangan837dc462015-05-27 10:17:41 +0530501 property_get("audio.playback.mch.downsample",value,"");
502 if (!strncmp("true", value, sizeof("true"))) {
503 if ((popcount(channel_mask) > 2) &&
504 (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
505 !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
506 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
507 ALOGD("%s: MCH session defaulting sample rate to %d",
508 __func__, sample_rate);
509 }
510 }
Amit Shekhar1d896042014-10-03 13:16:09 -0700511 ALOGV("%s: flags: %x, format: %x sample_rate %d",
512 __func__, flags, format, sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700513 list_for_each(node_i, streams_output_cfg_list) {
514 so_info = node_to_item(node_i, struct streams_output_cfg, list);
515 if (so_info->flags == flags) {
516 list_for_each(node_j, &so_info->format_list) {
517 sf_info = node_to_item(node_j, struct stream_format, list);
518 if (sf_info->format == format) {
Amit Shekhar6f461b12014-08-01 14:52:58 -0700519 if (set_output_cfg(so_info, app_type_cfg, sample_rate, bit_width))
520 return;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700521 }
522 }
523 }
524 }
525 list_for_each(node_i, streams_output_cfg_list) {
526 so_info = node_to_item(node_i, struct streams_output_cfg, list);
527 if (so_info->flags == AUDIO_OUTPUT_FLAG_PRIMARY) {
528 ALOGV("Compatible output profile not found.");
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700529 app_type_cfg->app_type = so_info->app_type_cfg.app_type;
530 app_type_cfg->sample_rate = so_info->app_type_cfg.sample_rate;
531 app_type_cfg->bit_width = so_info->app_type_cfg.bit_width;
Amit Shekhar6f461b12014-08-01 14:52:58 -0700532 ALOGV("%s Default to primary output: App type: %d sample_rate %d",
533 __func__, so_info->app_type_cfg.app_type, app_type_cfg->sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700534 return;
535 }
536 }
537 ALOGW("%s: App type could not be selected. Falling back to default", __func__);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700538 app_type_cfg->app_type = platform_get_default_app_type(platform);
Amit Shekhar6f461b12014-08-01 14:52:58 -0700539 app_type_cfg->sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700540 app_type_cfg->bit_width = 16;
541}
542
543int audio_extn_utils_send_app_type_cfg(struct audio_usecase *usecase)
544{
545 char mixer_ctl_name[MAX_LENGTH_MIXER_CONTROL_IN_INT];
546 int app_type_cfg[MAX_LENGTH_MIXER_CONTROL_IN_INT], len = 0, rc;
Anish Kumarc8599f22014-07-20 09:36:07 -0700547 struct stream_out *out;
548 struct audio_device *adev;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700549 struct mixer_ctl *ctl;
550 int pcm_device_id, acdb_dev_id, snd_device = usecase->out_snd_device;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530551 int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Manish Dewangan837dc462015-05-27 10:17:41 +0530552 char value[PROPERTY_VALUE_MAX] = {0};
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700553
554 ALOGV("%s", __func__);
555
556 if (usecase->type != PCM_PLAYBACK) {
557 ALOGV("%s: not a playback path, no need to cfg app type", __func__);
558 rc = 0;
559 goto exit_send_app_type_cfg;
560 }
561 if ((usecase->id != USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) &&
562 (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
563 (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
Alexy Joseph2f89cfa2014-10-06 12:15:01 -0700564 (!is_offload_usecase(usecase->id))) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700565 ALOGV("%s: a playback path where app type cfg is not required %d", __func__, usecase->id);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700566 rc = 0;
567 goto exit_send_app_type_cfg;
568 }
Anish Kumarc8599f22014-07-20 09:36:07 -0700569 out = usecase->stream.out;
570 adev = out->dev;
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700571
572 snd_device = usecase->out_snd_device;
573
574 pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
575
576 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
577 "Audio Stream %d App Type Cfg", pcm_device_id);
578
579 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
580 if (!ctl) {
581 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__,
582 mixer_ctl_name);
583 rc = -EINVAL;
584 goto exit_send_app_type_cfg;
585 }
586 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
587 audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device;
588 acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
589 if (acdb_dev_id < 0) {
590 ALOGE("%s: Couldn't get the acdb dev id", __func__);
591 rc = -EINVAL;
592 goto exit_send_app_type_cfg;
593 }
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530594
595 if ((24 == usecase->stream.out->bit_width) &&
Amit Shekhar1d896042014-10-03 13:16:09 -0700596 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
Dhananjay Kumarcb419212015-08-28 13:24:16 +0530597 out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530598 } else if ((snd_device != SND_DEVICE_OUT_HEADPHONES_44_1 &&
599 usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100) ||
600 (usecase->stream.out->sample_rate < OUTPUT_SAMPLING_RATE_44100)) {
Dhananjay Kumarcb419212015-08-28 13:24:16 +0530601 out->app_type_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530602 }
Dhananjay Kumarcb419212015-08-28 13:24:16 +0530603 sample_rate = out->app_type_cfg.sample_rate;
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530604
Manish Dewangan837dc462015-05-27 10:17:41 +0530605 property_get("audio.playback.mch.downsample",value,"");
606 if (!strncmp("true", value, sizeof("true"))) {
607 if ((popcount(out->channel_mask) > 2) &&
608 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
609 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
610 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
611 }
612
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700613 app_type_cfg[len++] = out->app_type_cfg.app_type;
614 app_type_cfg[len++] = acdb_dev_id;
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -0700615 if (((out->format == AUDIO_FORMAT_E_AC3) ||
616 (out->format == AUDIO_FORMAT_E_AC3_JOC)) &&
617 (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
618 app_type_cfg[len++] = sample_rate * 4;
619 else
620 app_type_cfg[len++] = sample_rate;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530621
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700622 mixer_ctl_set_array(ctl, app_type_cfg, len);
Amit Shekhar278e3362014-09-08 14:08:19 -0700623 ALOGI("%s app_type %d, acdb_dev_id %d, sample_rate %d",
Preetam Singh Ranawata4a37d82014-09-25 16:56:38 +0530624 __func__, out->app_type_cfg.app_type, acdb_dev_id, sample_rate);
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -0700625 rc = 0;
626exit_send_app_type_cfg:
627 return rc;
628}
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700629
Laxminath Kasam9e938362015-08-11 12:44:47 +0530630int read_line_from_file(const char *path, char *buf, size_t count)
631{
632 char * fgets_ret;
633 FILE * fd;
634 int rv;
635
636 fd = fopen(path, "r");
637 if (fd == NULL)
638 return -1;
639
640 fgets_ret = fgets(buf, (int)count, fd);
641 if (NULL != fgets_ret) {
642 rv = (int)strlen(buf);
643 } else {
644 rv = ferror(fd);
645 }
646 fclose(fd);
647
648 return rv;
649}
650
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700651void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
652 struct audio_usecase *usecase)
653{
654 int type = usecase->type;
655
656 if (type == PCM_PLAYBACK) {
657 struct stream_out *out = usecase->stream.out;
658 int snd_device = usecase->out_snd_device;
659 snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
660 audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530661 platform_send_audio_calibration(adev->platform, usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700662 out->app_type_cfg.app_type,
663 out->app_type_cfg.sample_rate);
664 }
665 if ((type == PCM_HFP_CALL) || (type == PCM_CAPTURE)) {
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530666 /* when app type is default. the sample rate is not used to send cal */
667 platform_send_audio_calibration(adev->platform, usecase,
668 platform_get_default_app_type(adev->platform),
669 48000);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700670 }
671}
672
Ben Rombergera04fabc2014-11-14 12:16:03 -0800673// Base64 Encode and Decode
674// Not all features supported. This must be used only with following conditions.
675// Decode Modes: Support with and without padding
676// CRLF not handling. So no CRLF in string to decode.
677// Encode Modes: Supports only padding
678int b64decode(char *inp, int ilen, uint8_t* outp)
679{
680 int i, j, k, ii, num;
681 int rem, pcnt;
682 uint32_t res=0;
683 uint8_t getIndex[MAX_BASEINDEX_LEN];
684 uint8_t tmp, cflag;
685
686 if(inp == NULL || outp == NULL || ilen <= 0) {
687 ALOGE("[%s] received NULL pointer or zero length",__func__);
688 return -1;
689 }
690
691 memset(getIndex, MAX_BASEINDEX_LEN-1, sizeof(getIndex));
692 for(i=0;i<BASE_TABLE_SIZE;i++) {
693 getIndex[(uint8_t)bTable[i]] = (uint8_t)i;
694 }
695 getIndex[(uint8_t)'=']=0;
696
697 j=0;k=0;
698 num = ilen/4;
699 rem = ilen%4;
700 if(rem==0)
701 num = num-1;
702 cflag=0;
703 for(i=0; i<num; i++) {
704 res=0;
705 for(ii=0;ii<4;ii++) {
706 res = res << 6;
707 tmp = getIndex[(uint8_t)inp[j++]];
708 res = res | tmp;
709 cflag = cflag | tmp;
710 }
711 outp[k++] = (res >> 16)&0xFF;
712 outp[k++] = (res >> 8)&0xFF;
713 outp[k++] = res & 0xFF;
714 }
715
716 // Handle last bytes special
717 pcnt=0;
718 if(rem == 0) {
719 //With padding or full data
720 res = 0;
721 for(ii=0;ii<4;ii++) {
722 if(inp[j] == '=')
723 pcnt++;
724 res = res << 6;
725 tmp = getIndex[(uint8_t)inp[j++]];
726 res = res | tmp;
727 cflag = cflag | tmp;
728 }
729 outp[k++] = res >> 16;
730 if(pcnt == 2)
731 goto done;
732 outp[k++] = (res>>8)&0xFF;
733 if(pcnt == 1)
734 goto done;
735 outp[k++] = res&0xFF;
736 } else {
737 //without padding
738 res = 0;
739 for(i=0;i<rem;i++) {
740 res = res << 6;
741 tmp = getIndex[(uint8_t)inp[j++]];
742 res = res | tmp;
743 cflag = cflag | tmp;
744 }
745 for(i=rem;i<4;i++) {
746 res = res << 6;
747 pcnt++;
748 }
749 outp[k++] = res >> 16;
750 if(pcnt == 2)
751 goto done;
752 outp[k++] = (res>>8)&0xFF;
753 if(pcnt == 1)
754 goto done;
755 outp[k++] = res&0xFF;
756 }
757done:
758 if(cflag == 0xFF) {
759 ALOGE("[%s] base64 decode failed. Invalid character found %s",
760 __func__, inp);
761 return 0;
762 }
763 return k;
764}
765
766int b64encode(uint8_t *inp, int ilen, char* outp)
767{
768 int i,j,k, num;
769 int rem=0;
770 uint32_t res=0;
771
772 if(inp == NULL || outp == NULL || ilen<=0) {
773 ALOGE("[%s] received NULL pointer or zero input length",__func__);
774 return -1;
775 }
776
777 num = ilen/3;
778 rem = ilen%3;
779 j=0;k=0;
780 for(i=0; i<num; i++) {
781 //prepare index
782 res = inp[j++]<<16;
783 res = res | inp[j++]<<8;
784 res = res | inp[j++];
785 //get output map from index
786 outp[k++] = (char) bTable[(res>>18)&0x3F];
787 outp[k++] = (char) bTable[(res>>12)&0x3F];
788 outp[k++] = (char) bTable[(res>>6)&0x3F];
789 outp[k++] = (char) bTable[res&0x3F];
790 }
791
792 switch(rem) {
793 case 1:
794 res = inp[j++]<<16;
795 outp[k++] = (char) bTable[res>>18];
796 outp[k++] = (char) bTable[(res>>12)&0x3F];
797 //outp[k++] = '=';
798 //outp[k++] = '=';
799 break;
800 case 2:
801 res = inp[j++]<<16;
802 res = res | inp[j++]<<8;
803 outp[k++] = (char) bTable[res>>18];
804 outp[k++] = (char) bTable[(res>>12)&0x3F];
805 outp[k++] = (char) bTable[(res>>6)&0x3F];
806 //outp[k++] = '=';
807 break;
808 default:
809 break;
810 }
811done:
812 outp[k] = '\0';
813 return k;
814}
Ashish Jain5a97ddd2015-05-13 10:52:34 +0530815
816#ifdef AUDIO_EXTERNAL_HDMI_ENABLED
817
818void get_default_compressed_channel_status(
819 unsigned char *channel_status)
820{
821 int32_t status = 0;
822 unsigned char bit_index;
823 memset(channel_status,0,24);
824
825 /* block start bit in preamble bit 3 */
826 channel_status[0] |= PROFESSIONAL;
827 //compre out
828 channel_status[0] |= NON_LPCM;
829 // sample rate; fixed 48K for default/transcode
830 channel_status[3] |= SR_48000;
831}
832
833int32_t get_compressed_channel_status(void *audio_stream_data,
834 uint32_t audio_frame_size,
835 unsigned char *channel_status,
836 enum audio_parser_code_type codec_type)
837 // codec_type - AUDIO_PARSER_CODEC_AC3
838 // - AUDIO_PARSER_CODEC_DTS
839{
840 unsigned char *streamPtr;
841 int ret = 0;
842 streamPtr = (unsigned char *)audio_stream_data;
843
844 if (audio_stream_data == NULL || audio_frame_size == 0) {
845 ALOGW("no buffer to get channel status, return default for compress");
846 get_default_compressed_channel_status(channel_status);
847 return ret;
848 }
849
850 memset(channel_status,0,24);
851 if(init_audio_parser(streamPtr, audio_frame_size, codec_type) == -1)
852 {
853 ALOGE("init audio parser failed");
854 return -1;
855 }
856 ret = get_channel_status(channel_status, codec_type);
857 return ret;
858
859}
860
861void get_linearpcm_channel_status(uint32_t sampleRate,
862 unsigned char *channel_status)
863{
864 int32_t status = 0;
865 unsigned char bit_index;
866 memset(channel_status,0,24);
867 /* block start bit in preamble bit 3 */
868 channel_status[0] |= PROFESSIONAL;
869 //LPCM OUT
870 channel_status[0] &= ~NON_LPCM;
871
872 switch (sampleRate) {
873 case 8000:
874 case 11025:
875 case 12000:
876 case 16000:
877 case 22050:
878 channel_status[3] |= SR_NOTID;
879 case 24000:
880 channel_status[3] |= SR_24000;
881 break;
882 case 32000:
883 channel_status[3] |= SR_32000;
884 break;
885 case 44100:
886 channel_status[3] |= SR_44100;
887 break;
888 case 48000:
889 channel_status[3] |= SR_48000;
890 break;
891 case 88200:
892 channel_status[3] |= SR_88200;
893 break;
894 case 96000:
895 channel_status[3] |= SR_96000;
896 break;
897 case 176400:
898 channel_status[3] |= SR_176400;
899 break;
900 case 192000:
901 channel_status[3] |= SR_192000;
902 break;
903 default:
904 ALOGV("Invalid sample_rate %u\n", sampleRate);
905 status = -1;
906 break;
907 }
908}
909
910void setChannelStatus(struct stream_out *out, char * buffer, size_t bytes)
911{
912 unsigned char channel_status[24]={0};
913 struct snd_aes_iec958 iec958;
914 const char *mixer_ctl_name = "IEC958 Playback PCM Stream";
915 struct mixer_ctl *ctl;
916 int i=0;
917 if (audio_extn_is_dolby_format(out->format) &&
918 /*TODO:Extend code to support DTS passthrough*/
919 /*set compressed channel status bits*/
920 audio_extn_dolby_is_passthrough_stream(out->flags)){
921 get_compressed_channel_status(buffer, bytes, channel_status, AUDIO_PARSER_CODEC_AC3);
922 } else {
923 /*set channel status bit for LPCM*/
924 get_linearpcm_channel_status(out->sample_rate, channel_status);
925 }
926
927 memcpy(iec958.status, channel_status,sizeof(iec958.status));
928 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_ctl_name);
929 if (!ctl) {
930 ALOGE("%s: Could not get ctl for mixer cmd - %s",
931 __func__, mixer_ctl_name);
932 return;
933 }
934 if (mixer_ctl_set_array(ctl, &iec958, sizeof(iec958)) < 0) {
935 ALOGE("%s: Could not set channel status for ext HDMI ",
936 __func__);
937 return;
938 }
939
940}
941#endif