blob: be7bab1c90aa15db7391fc6cd6ccdc588e924713 [file] [log] [blame]
Jitendra Naruka1b6513f2014-11-22 19:34:13 -08001/*
2 * (C) 2014 DTS, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "audio_hw_dts_eagle"
18/*#define LOG_NDEBUG 0*/
19
20#include <errno.h>
21#include <math.h>
22#include <stdlib.h>
23#include <fcntl.h>
Weiyin Jiang2995f662019-04-17 14:25:12 +080024#include <log/log.h>
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080025#include <cutils/properties.h>
26#include <cutils/str_parms.h>
27#include <sys/ioctl.h>
28#include <sys/stat.h>
29#include <sound/asound.h>
30#include <sound/audio_effects.h>
31#include <sound/devdep_params.h>
32#include "audio_hw.h"
33#include "platform.h"
34#include "platform_api.h"
35
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053036#ifdef DYNAMIC_LOG_ENABLED
37#include <log_xml_parser.h>
38#define LOG_MASK HAL_MOD_FILE_DTS_EAGLE
39#include <log_utils.h>
40#endif
41
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080042#ifdef DTS_EAGLE
43
44#define AUDIO_PARAMETER_KEY_DTS_EAGLE "DTS_EAGLE"
Dhanalakshmi Siddani79b98592015-03-23 11:59:02 +053045#define STATE_NOTIFY_FILE "/data/misc/dts/stream"
46#define FADE_NOTIFY_FILE "/data/misc/dts/fade"
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080047#define DTS_EAGLE_KEY "DTS_EAGLE"
48#define DEVICE_NODE "/dev/snd/hwC0D3"
49#define MAX_LENGTH_OF_INTEGER_IN_STRING 13
50#define PARAM_GET_MAX_SIZE 512
51
52struct dts_eagle_param_desc_alsa {
53 int alsa_effect_ID;
54 struct dts_eagle_param_desc d;
55};
56
57static struct dts_eagle_param_desc_alsa *fade_in_data = NULL;
58static struct dts_eagle_param_desc_alsa *fade_out_data = NULL;
59static int32_t mDevices = 0;
60static int32_t mCurrDevice = 0;
61static const char* DTS_EAGLE_STR = DTS_EAGLE_KEY;
62
63static int do_DTS_Eagle_params_stream(struct stream_out *out, struct dts_eagle_param_desc_alsa *t, bool get) {
64 char mixer_string[128];
Alexy Josephacc655d2014-12-04 08:06:41 -080065 char mixer_str_query[128];
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080066 struct mixer_ctl *ctl;
Alexy Josephacc655d2014-12-04 08:06:41 -080067 struct mixer_ctl *query_ctl;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080068 int pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
69
70 ALOGV("DTS_EAGLE_HAL (%s): enter", __func__);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080071 snprintf(mixer_string, sizeof(mixer_string), "%s %d", "Audio Effects Config", pcm_device_id);
72 ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_string);
73 if (!ctl) {
74 ALOGE("DTS_EAGLE_HAL (%s): failed to open mixer %s", __func__, mixer_string);
75 } else if (t) {
76 int size = t->d.size + sizeof(struct dts_eagle_param_desc_alsa);
77 ALOGD("DTS_EAGLE_HAL (%s): opened mixer %s", __func__, mixer_string);
78 if (get) {
79 ALOGD("DTS_EAGLE_HAL (%s): get request", __func__);
Alexy Josephacc655d2014-12-04 08:06:41 -080080 snprintf(mixer_str_query, sizeof(mixer_str_query), "%s %d", "Query Audio Effect Param", pcm_device_id);
81 query_ctl = mixer_get_ctl_by_name(out->dev->mixer, mixer_str_query);
82 if (!query_ctl) {
83 ALOGE("DTS_EAGLE_HAL (%s): failed to open mixer %s", __func__, mixer_str_query);
84 return -EINVAL;
85 }
86 mixer_ctl_set_array(query_ctl, t, size);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080087 return mixer_ctl_get_array(ctl, t, size);
88 }
89 ALOGD("DTS_EAGLE_HAL (%s): set request", __func__);
90 return mixer_ctl_set_array(ctl, t, size);
91 } else {
92 ALOGD("DTS_EAGLE_HAL (%s): parameter data NULL", __func__);
93 }
94 return -EINVAL;
95}
96
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +053097static int do_DTS_Eagle_params(const struct audio_device *adev, struct dts_eagle_param_desc_alsa *t, bool get, const struct stream_out *out) {
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080098 struct listnode *node;
99 struct audio_usecase *usecase;
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530100 int ret = 0, sent = 0, tret = 0;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800101
102 ALOGV("DTS_EAGLE_HAL (%s): enter", __func__);
103
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530104 if (out) {
105 /* if valid out stream is given, then send params to this stream only */
106 tret = do_DTS_Eagle_params_stream(out, t, get);
107 if (tret < 0)
108 ret = tret;
109 else
110 sent = 1;
111 } else {
112 list_for_each(node, &adev->usecase_list) {
113 usecase = node_to_item(node, struct audio_usecase, list);
114 /* set/get eagle params for offload usecases only */
Sujin Panicker390724d2019-04-26 10:43:36 +0530115 if (usecase->stream.out && (usecase->type == PCM_PLAYBACK) && is_offload_usecase(usecase->id)) {
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530116 tret = do_DTS_Eagle_params_stream(usecase->stream.out, t, get);
117 if (tret < 0)
118 ret = tret;
119 else
120 sent = 1;
121 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800122 }
123 }
124
125 if (!sent) {
126 int fd = open(DEVICE_NODE, O_RDWR);
127
128 if (get) {
129 ALOGD("DTS_EAGLE_HAL (%s): no stream opened, attempting to retrieve directly from cache", __func__);
130 t->d.device &= ~DTS_EAGLE_FLAG_ALSA_GET;
131 } else {
132 ALOGD("DTS_EAGLE_HAL (%s): no stream opened, attempting to send directly to cache", __func__);
133 t->d.device |= DTS_EAGLE_FLAG_IOCTL_JUSTSETCACHE;
134 }
135
136 if (fd > 0) {
137 int cmd = get ? DTS_EAGLE_IOCTL_GET_PARAM : DTS_EAGLE_IOCTL_SET_PARAM;
138 if (ioctl(fd, cmd, &t->d) < 0) {
139 ALOGE("DTS_EAGLE_HAL (%s): error sending/getting param\n", __func__);
140 ret = -EINVAL;
141 } else {
142 ALOGD("DTS_EAGLE_HAL (%s): sent/retrieved param\n", __func__);
143 }
144 close(fd);
145 } else {
146 ALOGE("DTS_EAGLE_HAL (%s): couldn't open device %s\n", __func__, DEVICE_NODE);
147 ret = -EINVAL;
148 }
149 }
150 return ret;
151}
152
153static void fade_node(bool need_data) {
Alexy Josephca2b3e12014-12-15 18:49:53 -0800154 char prop[PROPERTY_VALUE_MAX];
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700155 property_get("vendor.audio.use.dts_eagle", prop, "0");
Alexy Josephca2b3e12014-12-15 18:49:53 -0800156 if (strncmp("true", prop, sizeof("true")))
157 return;
158 int fd, n = 0;
Alexy Joseph7de344d2015-03-30 10:40:03 -0700159 if ((fd = open(FADE_NOTIFY_FILE, O_TRUNC|O_WRONLY)) < 0) {
160 ALOGV("No fade node, create one");
161 fd = creat(FADE_NOTIFY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
162 if (fd < 0) {
163 ALOGE("DTS_EAGLE_HAL (%s): Creating fade notifier node failed", __func__);
164 return;
165 }
166 chmod(FADE_NOTIFY_FILE, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH);
Alexy Josephca2b3e12014-12-15 18:49:53 -0800167 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800168 char *str = need_data ? "need" : "have";
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800169 n = write(fd, str, strlen(str));
170 close(fd);
171 if (n > 0)
172 ALOGI("DTS_EAGLE_HAL (%s): fade notifier node set to \"%s\", %i bytes written", __func__, str, n);
173 else
174 ALOGE("DTS_EAGLE_HAL (%s): error writing to fade notifier node", __func__);
175}
176
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530177int audio_extn_dts_eagle_fade(const struct audio_device *adev, bool fade_in, const struct stream_out *out) {
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800178 char prop[PROPERTY_VALUE_MAX];
179
180 ALOGV("DTS_EAGLE_HAL (%s): enter with fade %s requested", __func__, fade_in ? "in" : "out");
181
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700182 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800183 if (strncmp("true", prop, sizeof("true")))
184 return 0;
185
186 if (!fade_in_data || !fade_out_data)
187 fade_node(true);
188
189 if (fade_in) {
190 if (fade_in_data)
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530191 return do_DTS_Eagle_params(adev, fade_in_data, false, out);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800192 } else {
193 if (fade_out_data)
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530194 return do_DTS_Eagle_params(adev, fade_out_data, false, out);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800195 }
196 return 0;
197}
198
Mingming Yin15dae802015-04-16 18:36:10 -0700199void audio_extn_dts_eagle_send_lic() {
200 char prop[PROPERTY_VALUE_MAX] = {0};
201 bool enabled;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700202 property_get("vendor.audio.use.dts_eagle", prop, "0");
Mingming Yin15dae802015-04-16 18:36:10 -0700203 enabled = !strncmp("true", prop, sizeof("true")) || atoi(prop);
204 if (!enabled)
205 return;
206 int fd = open(DEVICE_NODE, O_RDWR);
207 int index = 1;
208 if (fd >= 0) {
209 if (ioctl(fd, DTS_EAGLE_IOCTL_SEND_LICENSE, &index) < 0) {
210 ALOGE("DTS_EAGLE_HAL: error sending license after adsp ssr");
211 } else {
212 ALOGD("DTS_EAGLE_HAL: sent license after adsp ssr");
213 }
214 close(fd);
215 } else {
216 ALOGE("DTS_EAGLE_HAL: error opening eagle");
217 }
218 return;
219}
220
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800221void audio_extn_dts_eagle_set_parameters(struct audio_device *adev, struct str_parms *parms) {
222 int ret, val;
223 char value[32] = { 0 }, prop[PROPERTY_VALUE_MAX];
224
225 ALOGV("DTS_EAGLE_HAL (%s): enter", __func__);
226
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700227 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800228 if (strncmp("true", prop, sizeof("true")))
229 return;
230
231 memset(value, 0, sizeof(value));
232 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_DTS_EAGLE, value, sizeof(value));
233 if (ret >= 0) {
234 int *data = NULL, id, size, offset, count, dev, dts_found = 0, fade_in = 0;
235 struct dts_eagle_param_desc_alsa *t2 = NULL, **t = &t2;
236
237 ret = str_parms_get_str(parms, "fade", value, sizeof(value));
238 if (ret >= 0) {
239 fade_in = atoi(value);
240 if (fade_in > 0) {
241 t = (fade_in == 1) ? &fade_in_data : &fade_out_data;
242 }
243 }
244
245 ret = str_parms_get_str(parms, "count", value, sizeof(value));
246 if (ret >= 0) {
247 count = atoi(value);
248 if (count > 1) {
249 int tmp_size = count * 32;
250 char *tmp = malloc(tmp_size+1);
251 data = malloc(sizeof(int) * count);
252 ALOGV("DTS_EAGLE_HAL (%s): multi count param detected, count: %d", __func__, count);
253 if (data && tmp) {
254 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_DTS_EAGLE, tmp, tmp_size);
255 if (ret >= 0) {
256 int idx = 0, tidx, tcnt = 0;
257 dts_found = 1;
258 do {
259 sscanf(&tmp[idx], "%i", &data[tcnt]);
260 tidx = strcspn(&tmp[idx], ",");
261 if (idx + tidx >= ret && tcnt < count-1) {
262 ALOGE("DTS_EAGLE_HAL (%s): malformed multi value string.", __func__);
263 dts_found = 0;
264 break;
265 }
266 ALOGD("DTS_EAGLE_HAL (%s): %i:%i (next %s)", __func__, tcnt, data[tcnt], &tmp[idx+tidx]);
267 idx += tidx + 1;
268 tidx = 0;
269 tcnt++;
270 } while (tcnt < count);
271 }
272 } else {
273 ALOGE("DTS_EAGLE_HAL (%s): mem alloc for multi count param parse failed.", __func__);
274 }
275 free(tmp);
276 }
277 }
278
279 if (!dts_found) {
280 data = malloc(sizeof(int));
281 if (data) {
282 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_DTS_EAGLE, value, sizeof(value));
283 if (ret >= 0) {
284 *data = atoi(value);
285 dts_found = 1;
286 count = 1;
287 } else {
288 ALOGE("DTS_EAGLE_HAL (%s): malformed value string.", __func__);
289 }
290 } else {
291 ALOGE("DTS_EAGLE_HAL (%s): mem alloc for param parse failed.", __func__);
292 }
293 }
294
295 if (dts_found) {
296 dts_found = 0;
297 ret = str_parms_get_str(parms, "id", value, sizeof(value));
298 if (ret >= 0) {
299 if (sscanf(value, "%x", &id) == 1) {
300 ret = str_parms_get_str(parms, "size", value, sizeof(value));
301 if (ret >= 0) {
302 size = atoi(value);
303 ret = str_parms_get_str(parms, "offset", value, sizeof(value));
304 if (ret >= 0) {
305 offset = atoi(value);
306 ret = str_parms_get_str(parms, "device", value, sizeof(value));
307 if (ret >= 0) {
308 dev = atoi(value);
309 dts_found = 1;
310 }
311 }
312 }
313 }
314 }
315 }
316
317 if (dts_found && count > 1 && size != (int)(count * sizeof(int))) {
318 ALOGE("DTS_EAGLE_HAL (%s): size/count mismatch (size = %i bytes, count = %i integers / %u bytes).", __func__, size, count, count*sizeof(int));
319 } else if (dts_found) {
320 ALOGI("DTS_EAGLE_HAL (%s): param detected: %s", __func__, str_parms_to_str(parms));
321 if (!(*t))
322 *t = (struct dts_eagle_param_desc_alsa*)malloc(sizeof(struct dts_eagle_param_desc_alsa) + size);
323 if (*t) {
324 (*t)->alsa_effect_ID = DTS_EAGLE_MODULE;
325 (*t)->d.id = id;
326 (*t)->d.size = size;
327 (*t)->d.offset = offset;
328 (*t)->d.device = dev;
329 memcpy((void*)((char*)*t + sizeof(struct dts_eagle_param_desc_alsa)), data, size);
330 ALOGD("DTS_EAGLE_HAL (%s): id: 0x%X, size: %d, offset: %d, device: %d", __func__,
331 (*t)->d.id, (*t)->d.size, (*t)->d.offset, (*t)->d.device);
332 if (!fade_in) {
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530333 ret = do_DTS_Eagle_params(adev, *t, false, NULL);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800334 if (ret < 0)
335 ALOGE("DTS_EAGLE_HAL (%s): failed setting params in kernel with error %i", __func__, ret);
336 }
337 free(t2);
338 } else {
339 ALOGE("DTS_EAGLE_HAL (%s): mem alloc for dsp structure failed.", __func__);
340 }
341 } else {
342 ALOGE("DTS_EAGLE_HAL (%s): param detected but failed parse: %s", __func__, str_parms_to_str(parms));
343 }
344 free(data);
345
346 if (fade_in > 0 && fade_in_data && fade_out_data)
347 fade_node(false);
348 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800349 ALOGV("DTS_EAGLE_HAL (%s): exit", __func__);
350}
351
352int audio_extn_dts_eagle_get_parameters(const struct audio_device *adev,
353 struct str_parms *query, struct str_parms *reply) {
354 int ret, val;
355 char value[32] = { 0 }, prop[PROPERTY_VALUE_MAX];
356 char params[PARAM_GET_MAX_SIZE];
357
358 ALOGV("DTS_EAGLE_HAL (%s): enter", __func__);
359
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700360 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800361 if (strncmp("true", prop, sizeof("true")))
362 return 0;
363
364 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_DTS_EAGLE, value, sizeof(value));
365 if (ret >= 0) {
366 int *data = NULL, id = 0, size = 0, offset = 0,
367 count = 1, dev = 0, idx = 0, dts_found = 0, i = 0;
368 const size_t chars_4_int = 16;
369 ret = str_parms_get_str(query, "count", value, sizeof(value));
370 if (ret >= 0) {
371 count = atoi(value);
372 if (count > 1) {
373 ALOGV("DTS_EAGLE_HAL (%s): multi count param detected, count: %d", __func__, count);
374 } else {
375 count = 1;
376 }
377 }
378
379 ret = str_parms_get_str(query, "id", value, sizeof(value));
380 if (ret >= 0) {
381 if (sscanf(value, "%x", &id) == 1) {
382 ret = str_parms_get_str(query, "size", value, sizeof(value));
383 if (ret >= 0) {
384 size = atoi(value);
385 ret = str_parms_get_str(query, "offset", value, sizeof(value));
386 if (ret >= 0) {
387 offset = atoi(value);
388 ret = str_parms_get_str(query, "device", value, sizeof(value));
389 if (ret >= 0) {
390 dev = atoi(value);
391 dts_found = 1;
392 }
393 }
394 }
395 }
396 }
397
398 if (dts_found) {
399 ALOGI("DTS_EAGLE_HAL (%s): param (get) detected: %s", __func__, str_parms_to_str(query));
400 struct dts_eagle_param_desc_alsa *t = (struct dts_eagle_param_desc_alsa *)params;
401 if (t) {
402 char buf[chars_4_int*count];
403 t->alsa_effect_ID = DTS_EAGLE_MODULE;
404 t->d.id = id;
405 t->d.size = size;
406 t->d.offset = offset;
Alexy Josephacc655d2014-12-04 08:06:41 -0800407 t->d.device = dev;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800408 ALOGV("DTS_EAGLE_HAL (%s): id (get): 0x%X, size: %d, offset: %d, device: %d", __func__,
409 t->d.id, t->d.size, t->d.offset, t->d.device & 0x7FFFFFFF);
410 if ((sizeof(struct dts_eagle_param_desc_alsa) + size) > PARAM_GET_MAX_SIZE) {
411 ALOGE("%s: requested data too large", __func__);
412 return -1;
413 }
Dhanalakshmi Siddani79415e72015-03-23 11:54:47 +0530414 ret = do_DTS_Eagle_params(adev, t, true, NULL);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800415 if (ret >= 0) {
416 data = (int*)(params + sizeof(struct dts_eagle_param_desc_alsa));
417 for (i = 0; i < count; i++)
418 idx += snprintf(&buf[idx], chars_4_int, "%i,", data[i]);
419 buf[idx > 0 ? idx-1 : 0] = 0;
420 ALOGD("DTS_EAGLE_HAL (%s): get result: %s", __func__, buf);
421 str_parms_add_int(reply, "size", size);
422 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_DTS_EAGLE, buf);
423 str_parms_add_int(reply, "count", count);
424 snprintf(value, sizeof(value), "0x%x", id);
425 str_parms_add_str(reply, "id", value);
426 str_parms_add_int(reply, "device", dev);
427 str_parms_add_int(reply, "offset", offset);
428 ALOGV("DTS_EAGLE_HAL (%s): reply: %s", __func__, str_parms_to_str(reply));
429 } else {
430 ALOGE("DTS_EAGLE_HAL (%s): failed getting params from kernel with error %i", __func__, ret);
431 return -1;
432 }
433 } else {
434 ALOGE("DTS_EAGLE_HAL (%s): mem alloc for (get) dsp structure failed.", __func__);
435 return -1;
436 }
437 } else {
438 ALOGE("DTS_EAGLE_HAL (%s): param (get) detected but failed parse: %s", __func__, str_parms_to_str(query));
439 return -1;
440 }
441 }
442
443 ALOGV("DTS_EAGLE_HAL (%s): exit", __func__);
444 return 0;
445}
446
447void audio_extn_dts_create_state_notifier_node(int stream_out)
448{
449 char prop[PROPERTY_VALUE_MAX];
450 char path[PATH_MAX];
451 char value[MAX_LENGTH_OF_INTEGER_IN_STRING];
452 int fd;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700453 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800454 if ((!strncmp("true", prop, sizeof("true")) || atoi(prop))) {
455 ALOGV("DTS_EAGLE_NODE_STREAM (%s): create_state_notifier_node - stream_out: %d", __func__, stream_out);
456 strlcpy(path, STATE_NOTIFY_FILE, sizeof(path));
457 snprintf(value, sizeof(value), "%d", stream_out);
458 strlcat(path, value, sizeof(path));
459
460 if ((fd=open(path, O_RDONLY)) < 0) {
461 ALOGV("DTS_EAGLE_NODE_STREAM (%s): no file exists", __func__);
462 } else {
463 ALOGV("DTS_EAGLE_NODE_STREAM (%s): a file with the same name exists, removing it before creating it", __func__);
464 close(fd);
465 remove(path);
466 }
467 if ((fd=creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
468 ALOGE("DTS_EAGLE_NODE_STREAM (%s): opening state notifier node failed returned", __func__);
469 return;
470 }
471 chmod(path, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH);
472 ALOGV("DTS_EAGLE_NODE_STREAM (%s): opening state notifier node successful", __func__);
473 close(fd);
Alexy Josephca2b3e12014-12-15 18:49:53 -0800474 if (!fade_in_data || !fade_out_data)
475 fade_node(true);
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800476 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800477}
478
479void audio_extn_dts_notify_playback_state(int stream_out, int has_video, int sample_rate,
480 int channels, int is_playing) {
481 char prop[PROPERTY_VALUE_MAX];
482 char path[PATH_MAX];
483 char value[MAX_LENGTH_OF_INTEGER_IN_STRING];
484 char buf[1024];
485 int fd;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700486 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800487 if ((!strncmp("true", prop, sizeof("true")) || atoi(prop))) {
488 ALOGV("DTS_EAGLE_NODE_STREAM (%s): notify_playback_state - is_playing: %d", __func__, is_playing);
489 strlcpy(path, STATE_NOTIFY_FILE, sizeof(path));
490 snprintf(value, sizeof(value), "%d", stream_out);
491 strlcat(path, value, sizeof(path));
492 if ((fd=open(path, O_TRUNC|O_WRONLY)) < 0) {
493 ALOGE("DTS_EAGLE_NODE_STREAM (%s): open state notifier node failed", __func__);
494 } else {
495 snprintf(buf, sizeof(buf), "has_video=%d;sample_rate=%d;channel_mode=%d;playback_state=%d",
496 has_video, sample_rate, channels, is_playing);
497 int n = write(fd, buf, strlen(buf));
498 if (n > 0)
499 ALOGV("DTS_EAGLE_NODE_STREAM (%s): write to state notifier node successful, bytes written: %d", __func__, n);
500 else
501 ALOGE("DTS_EAGLE_NODE_STREAM (%s): write state notifier node failed", __func__);
502 close(fd);
503 }
504 }
505}
506
507void audio_extn_dts_remove_state_notifier_node(int stream_out)
508{
509 char prop[PROPERTY_VALUE_MAX];
510 char path[PATH_MAX];
511 char value[MAX_LENGTH_OF_INTEGER_IN_STRING];
512 int fd;
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700513 property_get("vendor.audio.use.dts_eagle", prop, "0");
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800514 if ((!strncmp("true", prop, sizeof("true")) || atoi(prop)) && (stream_out)) {
515 ALOGV("DTS_EAGLE_NODE_STREAM (%s): remove_state_notifier_node: stream_out - %d", __func__, stream_out);
516 strlcpy(path, STATE_NOTIFY_FILE, sizeof(path));
517 snprintf(value, sizeof(value), "%d", stream_out);
518 strlcat(path, value, sizeof(path));
519 if ((fd=open(path, O_RDONLY)) < 0) {
520 ALOGV("DTS_EAGLE_NODE_STREAM (%s): open state notifier node failed", __func__);
521 } else {
522 ALOGV("DTS_EAGLE_NODE_STREAM (%s): open state notifier node successful, removing the file", __func__);
523 close(fd);
524 remove(path);
525 }
526 }
527}
528
529#endif /* DTS_EAGLE end */