1 /*
2 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
5 * Copyright (C) 2013 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 "offload_effect_bass"
21 #define LOG_NDEBUG 0
22
23 #include <cutils/list.h>
24 #include <cutils/log.h>
25 #include <cutils/properties.h>
26 #include <tinyalsa/asoundlib.h>
27 #include <sound/audio_effects.h>
28 #include <audio_effects/effect_bassboost.h>
29 #include <stdlib.h>
30 #include <dlfcn.h>
31
32 #include "effect_api.h"
33 #include "bass_boost.h"
34
35 /* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */
36 const effect_descriptor_t bassboost_descriptor = {
37 {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
38 {0x2c4a8c24, 0x1581, 0x487f, 0x94f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
39 EFFECT_CONTROL_API_VERSION,
40 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL),
41 0, /* TODO */
42 1,
43 "MSM offload bassboost",
44 "The Android Open Source Project",
45 };
46
47 #define LIB_ACDB_LOADER "libacdbloader.so"
48 #define PBE_CONF_APP_ID 0x00011130
49
50 enum {
51 AUDIO_DEVICE_CAL_TYPE = 0,
52 AUDIO_STREAM_CAL_TYPE,
53 };
54
55 typedef struct acdb_audio_cal_cfg {
56 uint32_t persist;
57 uint32_t snd_dev_id;
58 uint32_t dev_id;
59 int32_t acdb_dev_id;
60 uint32_t app_type;
61 uint32_t topo_id;
62 uint32_t sampling_rate;
63 uint32_t cal_type;
64 uint32_t module_id;
65 uint32_t param_id;
66 } acdb_audio_cal_cfg_t;
67
68 typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
69 static int pbe_load_config(struct pbe_params *params);
70
71 /*
72 * Bass operations
73 */
bass_get_parameter(effect_context_t * context,effect_param_t * p,uint32_t * size)74 int bass_get_parameter(effect_context_t *context, effect_param_t *p,
75 uint32_t *size)
76 {
77 bass_context_t *bass_ctxt = (bass_context_t *)context;
78 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
79 int32_t *param_tmp = (int32_t *)p->data;
80 int32_t param = *param_tmp++;
81 void *value = p->data + voffset;
82 int i;
83
84 ALOGV("%s", __func__);
85
86 p->status = 0;
87
88 switch (param) {
89 case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
90 if (p->vsize < sizeof(uint32_t))
91 p->status = -EINVAL;
92 p->vsize = sizeof(uint32_t);
93 break;
94 case BASSBOOST_PARAM_STRENGTH:
95 if (p->vsize < sizeof(int16_t))
96 p->status = -EINVAL;
97 p->vsize = sizeof(int16_t);
98 break;
99 default:
100 p->status = -EINVAL;
101 }
102
103 *size = sizeof(effect_param_t) + voffset + p->vsize;
104
105 if (p->status != 0)
106 return 0;
107
108 switch (param) {
109 case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
110 ALOGV("%s: BASSBOOST_PARAM_STRENGTH_SUPPORTED", __func__);
111 if (bass_ctxt->active_index == BASS_BOOST)
112 *(uint32_t *)value = 1;
113 else
114 *(uint32_t *)value = 0;
115 break;
116
117 case BASSBOOST_PARAM_STRENGTH:
118 ALOGV("%s: BASSBOOST_PARAM_STRENGTH", __func__);
119 if (bass_ctxt->active_index == BASS_BOOST)
120 *(int16_t *)value = bassboost_get_strength(&(bass_ctxt->bassboost_ctxt));
121 else
122 *(int16_t *)value = 0;
123 break;
124
125 default:
126 p->status = -EINVAL;
127 break;
128 }
129
130 return 0;
131 }
132
bass_set_parameter(effect_context_t * context,effect_param_t * p,uint32_t size __unused)133 int bass_set_parameter(effect_context_t *context, effect_param_t *p,
134 uint32_t size __unused)
135 {
136 bass_context_t *bass_ctxt = (bass_context_t *)context;
137 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
138 void *value = p->data + voffset;
139 int32_t *param_tmp = (int32_t *)p->data;
140 int32_t param = *param_tmp++;
141 uint32_t strength;
142
143 ALOGV("%s", __func__);
144
145 p->status = 0;
146
147 switch (param) {
148 case BASSBOOST_PARAM_STRENGTH:
149 ALOGV("%s BASSBOOST_PARAM_STRENGTH", __func__);
150 if (bass_ctxt->active_index == BASS_BOOST) {
151 strength = (uint32_t)(*(int16_t *)value);
152 bassboost_set_strength(&(bass_ctxt->bassboost_ctxt), strength);
153 } else {
154 /* stength supported only for BB and not for PBE, but do not
155 * return error for unsupported case, as it fails cts test
156 */
157 ALOGD("%s ignore set strength, index %d",
158 __func__, bass_ctxt->active_index);
159 break;
160 }
161 break;
162 default:
163 p->status = -EINVAL;
164 break;
165 }
166
167 return 0;
168 }
169
bass_set_device(effect_context_t * context,uint32_t device)170 int bass_set_device(effect_context_t *context, uint32_t device)
171 {
172 bass_context_t *bass_ctxt = (bass_context_t *)context;
173
174 if (device == AUDIO_DEVICE_OUT_SPEAKER) {
175 bass_ctxt->active_index = BASS_PBE;
176 ALOGV("%s: set PBE mode, device: %x", __func__, device);
177 } else if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
178 device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
179 device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP ||
180 device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) {
181 ALOGV("%s: set BB mode, device: %x", __func__, device);
182 bass_ctxt->active_index = BASS_BOOST;
183 } else {
184 ALOGI("%s: disabled by device: %x", __func__, device);
185 bass_ctxt->active_index = BASS_INVALID;
186 }
187
188 bassboost_set_device((effect_context_t *)&(bass_ctxt->bassboost_ctxt), device);
189 pbe_set_device((effect_context_t *)&(bass_ctxt->pbe_ctxt), device);
190
191 return 0;
192 }
193
bass_reset(effect_context_t * context)194 int bass_reset(effect_context_t *context)
195 {
196 bass_context_t *bass_ctxt = (bass_context_t *)context;
197
198 bassboost_reset((effect_context_t *)&(bass_ctxt->bassboost_ctxt));
199 pbe_reset((effect_context_t *)&(bass_ctxt->pbe_ctxt));
200
201 return 0;
202 }
203
bass_init(effect_context_t * context)204 int bass_init(effect_context_t *context)
205 {
206 bass_context_t *bass_ctxt = (bass_context_t *)context;
207
208 // convery i/o channel config to sub effects
209 bass_ctxt->bassboost_ctxt.common.config = context->config;
210 bass_ctxt->pbe_ctxt.common.config = context->config;
211
212 ALOGV("%s", __func__);
213
214 bass_ctxt->active_index = BASS_BOOST;
215
216
217 bassboost_init((effect_context_t *)&(bass_ctxt->bassboost_ctxt));
218 pbe_init((effect_context_t *)&(bass_ctxt->pbe_ctxt));
219
220 return 0;
221 }
222
bass_enable(effect_context_t * context)223 int bass_enable(effect_context_t *context)
224 {
225 bass_context_t *bass_ctxt = (bass_context_t *)context;
226
227 ALOGV("%s", __func__);
228
229 bassboost_enable((effect_context_t *)&(bass_ctxt->bassboost_ctxt));
230 pbe_enable((effect_context_t *)&(bass_ctxt->pbe_ctxt));
231
232 return 0;
233 }
234
bass_disable(effect_context_t * context)235 int bass_disable(effect_context_t *context)
236 {
237 bass_context_t *bass_ctxt = (bass_context_t *)context;
238
239 ALOGV("%s", __func__);
240
241 bassboost_disable((effect_context_t *)&(bass_ctxt->bassboost_ctxt));
242 pbe_disable((effect_context_t *)&(bass_ctxt->pbe_ctxt));
243
244 return 0;
245 }
246
bass_start(effect_context_t * context,output_context_t * output)247 int bass_start(effect_context_t *context, output_context_t *output)
248 {
249 bass_context_t *bass_ctxt = (bass_context_t *)context;
250
251 ALOGV("%s", __func__);
252
253 bassboost_start((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output);
254 pbe_start((effect_context_t *)&(bass_ctxt->pbe_ctxt), output);
255
256 return 0;
257 }
258
bass_stop(effect_context_t * context,output_context_t * output)259 int bass_stop(effect_context_t *context, output_context_t *output)
260 {
261 bass_context_t *bass_ctxt = (bass_context_t *)context;
262
263 ALOGV("%s", __func__);
264
265 bassboost_stop((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output);
266 pbe_stop((effect_context_t *)&(bass_ctxt->pbe_ctxt), output);
267
268 return 0;
269 }
270
271 #undef LOG_TAG
272 #define LOG_TAG "offload_effect_bb"
273 /*
274 * Bassboost operations
275 */
276
bassboost_get_strength(bassboost_context_t * context)277 int bassboost_get_strength(bassboost_context_t *context)
278 {
279 ALOGV("%s: ctxt %p, strength: %d", __func__,
280 context, context->strength);
281 return context->strength;
282 }
283
bassboost_set_strength(bassboost_context_t * context,uint32_t strength)284 int bassboost_set_strength(bassboost_context_t *context, uint32_t strength)
285 {
286 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
287 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
288 context->strength = strength;
289
290 offload_bassboost_set_strength(&(context->offload_bass), strength);
291 if (context->ctl)
292 offload_bassboost_send_params(bass_ctxt->ctl, bass_ctxt->offload_bass,
293 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
294 OFFLOAD_SEND_BASSBOOST_STRENGTH);
295 return 0;
296 }
297
bassboost_set_device(effect_context_t * context,uint32_t device)298 int bassboost_set_device(effect_context_t *context, uint32_t device)
299 {
300 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
301
302 ALOGV("%s: ctxt %p, device 0x%x", __func__, bass_ctxt, device);
303 bass_ctxt->device = device;
304 if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
305 device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
306 device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP ||
307 device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) {
308 if (bass_ctxt->temp_disabled) {
309 if (effect_is_active(&bass_ctxt->common)) {
310 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true);
311 if (bass_ctxt->ctl)
312 offload_bassboost_send_params(bass_ctxt->ctl,
313 bass_ctxt->offload_bass,
314 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
315 }
316 bass_ctxt->temp_disabled = false;
317 }
318 } else {
319 if (!bass_ctxt->temp_disabled) {
320 if (effect_is_active(&bass_ctxt->common)) {
321 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
322 if (bass_ctxt->ctl)
323 offload_bassboost_send_params(bass_ctxt->ctl,
324 bass_ctxt->offload_bass,
325 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
326 }
327 bass_ctxt->temp_disabled = true;
328 }
329 ALOGI("%s: ctxt %p, disabled based on device", __func__, bass_ctxt);
330 }
331 offload_bassboost_set_device(&(bass_ctxt->offload_bass), device);
332 return 0;
333 }
334
bassboost_reset(effect_context_t * context)335 int bassboost_reset(effect_context_t *context)
336 {
337 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
338
339 return 0;
340 }
341
bassboost_init(effect_context_t * context)342 int bassboost_init(effect_context_t *context)
343 {
344 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
345
346 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
347 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
348 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
349 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
350 context->config.inputCfg.samplingRate = 44100;
351 context->config.inputCfg.bufferProvider.getBuffer = NULL;
352 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
353 context->config.inputCfg.bufferProvider.cookie = NULL;
354 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
355 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
356 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
357 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
358 context->config.outputCfg.samplingRate = 44100;
359 context->config.outputCfg.bufferProvider.getBuffer = NULL;
360 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
361 context->config.outputCfg.bufferProvider.cookie = NULL;
362 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
363
364 set_config(context, &context->config);
365
366 bass_ctxt->temp_disabled = false;
367 memset(&(bass_ctxt->offload_bass), 0, sizeof(struct bass_boost_params));
368
369 return 0;
370 }
371
bassboost_enable(effect_context_t * context)372 int bassboost_enable(effect_context_t *context)
373 {
374 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
375
376 ALOGV("%s: ctxt %p, strength %d", __func__, bass_ctxt, bass_ctxt->strength);
377
378 if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) &&
379 !(bass_ctxt->temp_disabled)) {
380 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true);
381 if (bass_ctxt->ctl && bass_ctxt->strength)
382 offload_bassboost_send_params(bass_ctxt->ctl,
383 bass_ctxt->offload_bass,
384 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
385 OFFLOAD_SEND_BASSBOOST_STRENGTH);
386 }
387 return 0;
388 }
389
bassboost_disable(effect_context_t * context)390 int bassboost_disable(effect_context_t *context)
391 {
392 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
393
394 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
395 if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) {
396 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
397 if (bass_ctxt->ctl)
398 offload_bassboost_send_params(bass_ctxt->ctl,
399 bass_ctxt->offload_bass,
400 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
401 }
402 return 0;
403 }
404
bassboost_start(effect_context_t * context,output_context_t * output)405 int bassboost_start(effect_context_t *context, output_context_t *output)
406 {
407 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
408
409 ALOGV("%s: ctxt %p, ctl %p, strength %d", __func__, bass_ctxt,
410 output->ctl, bass_ctxt->strength);
411 bass_ctxt->ctl = output->ctl;
412 if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)))
413 if (bass_ctxt->ctl)
414 offload_bassboost_send_params(bass_ctxt->ctl, bass_ctxt->offload_bass,
415 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
416 OFFLOAD_SEND_BASSBOOST_STRENGTH);
417 return 0;
418 }
419
bassboost_stop(effect_context_t * context,output_context_t * output __unused)420 int bassboost_stop(effect_context_t *context, output_context_t *output __unused)
421 {
422 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
423
424 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
425 bass_ctxt->ctl = NULL;
426 return 0;
427 }
428
429 #undef LOG_TAG
430 #define LOG_TAG "offload_effect_pbe"
431 /*
432 * PBE operations
433 */
434
pbe_set_device(effect_context_t * context,uint32_t device)435 int pbe_set_device(effect_context_t *context, uint32_t device)
436 {
437 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
438 char propValue[PROPERTY_VALUE_MAX];
439 bool pbe_enabled_by_prop = false;
440
441 ALOGV("%s: device: %d", __func__, device);
442 pbe_ctxt->device = device;
443
444 if (property_get("audio.safx.pbe.enabled", propValue, NULL)) {
445 pbe_enabled_by_prop = atoi(propValue) ||
446 !strncmp("true", propValue, 4);
447 }
448
449 if (device == AUDIO_DEVICE_OUT_SPEAKER && pbe_enabled_by_prop == true) {
450 if (pbe_ctxt->temp_disabled) {
451 if (effect_is_active(&pbe_ctxt->common)) {
452 offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true);
453 if (pbe_ctxt->ctl)
454 offload_pbe_send_params(pbe_ctxt->ctl,
455 &pbe_ctxt->offload_pbe,
456 OFFLOAD_SEND_PBE_ENABLE_FLAG |
457 OFFLOAD_SEND_PBE_CONFIG);
458 }
459 pbe_ctxt->temp_disabled = false;
460 }
461 } else {
462 if (!pbe_ctxt->temp_disabled) {
463 if (effect_is_active(&pbe_ctxt->common)) {
464 offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false);
465 if (pbe_ctxt->ctl)
466 offload_pbe_send_params(pbe_ctxt->ctl,
467 &pbe_ctxt->offload_pbe,
468 OFFLOAD_SEND_PBE_ENABLE_FLAG);
469 }
470 pbe_ctxt->temp_disabled = true;
471 }
472 }
473 offload_pbe_set_device(&(pbe_ctxt->offload_pbe), device);
474 return 0;
475 }
476
pbe_reset(effect_context_t * context)477 int pbe_reset(effect_context_t *context)
478 {
479 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
480
481 return 0;
482 }
483
pbe_init(effect_context_t * context)484 int pbe_init(effect_context_t *context)
485 {
486 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
487
488 ALOGV("%s", __func__);
489 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
490 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
491 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
492 context->config.inputCfg.samplingRate = 44100;
493 context->config.inputCfg.bufferProvider.getBuffer = NULL;
494 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
495 context->config.inputCfg.bufferProvider.cookie = NULL;
496 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
497 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
498 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
499 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
500 context->config.outputCfg.samplingRate = 44100;
501 context->config.outputCfg.bufferProvider.getBuffer = NULL;
502 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
503 context->config.outputCfg.bufferProvider.cookie = NULL;
504 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
505
506 set_config(context, &context->config);
507
508 pbe_ctxt->temp_disabled = false;
509 memset(&(pbe_ctxt->offload_pbe), 0, sizeof(struct pbe_params));
510 pbe_load_config(&(pbe_ctxt->offload_pbe));
511
512 return 0;
513 }
514
pbe_enable(effect_context_t * context)515 int pbe_enable(effect_context_t *context)
516 {
517 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
518
519 ALOGV("%s", __func__);
520
521 if (!offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe)) &&
522 !(pbe_ctxt->temp_disabled)) {
523 offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true);
524 if (pbe_ctxt->ctl)
525 offload_pbe_send_params(pbe_ctxt->ctl,
526 &pbe_ctxt->offload_pbe,
527 OFFLOAD_SEND_PBE_ENABLE_FLAG |
528 OFFLOAD_SEND_PBE_CONFIG);
529 }
530 return 0;
531 }
532
pbe_disable(effect_context_t * context)533 int pbe_disable(effect_context_t *context)
534 {
535 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
536
537 ALOGV("%s", __func__);
538 if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) {
539 offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false);
540 if (pbe_ctxt->ctl)
541 offload_pbe_send_params(pbe_ctxt->ctl,
542 &pbe_ctxt->offload_pbe,
543 OFFLOAD_SEND_PBE_ENABLE_FLAG);
544 }
545 return 0;
546 }
547
pbe_start(effect_context_t * context,output_context_t * output)548 int pbe_start(effect_context_t *context, output_context_t *output)
549 {
550 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
551
552 ALOGV("%s", __func__);
553 pbe_ctxt->ctl = output->ctl;
554 ALOGV("output->ctl: %p", output->ctl);
555 if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) {
556 if (pbe_ctxt->ctl)
557 offload_pbe_send_params(pbe_ctxt->ctl, &pbe_ctxt->offload_pbe,
558 OFFLOAD_SEND_PBE_ENABLE_FLAG |
559 OFFLOAD_SEND_PBE_CONFIG);
560 }
561 return 0;
562 }
563
pbe_stop(effect_context_t * context,output_context_t * output __unused)564 int pbe_stop(effect_context_t *context, output_context_t *output __unused)
565 {
566 pbe_context_t *pbe_ctxt = (pbe_context_t *)context;
567
568 ALOGV("%s", __func__);
569 pbe_ctxt->ctl = NULL;
570 return 0;
571 }
572
pbe_load_config(struct pbe_params * params)573 static int pbe_load_config(struct pbe_params *params)
574 {
575 int ret = 0;
576 uint32_t len = 0;
577 uint32_t propValue = 0;
578 uint32_t pbe_app_type = PBE_CONF_APP_ID;
579 char propValueStr[PROPERTY_VALUE_MAX];
580 void *acdb_handle = NULL;
581 acdb_get_audio_cal_t acdb_get_audio_cal = NULL;
582 acdb_audio_cal_cfg_t cal_cfg = {0};
583
584 acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
585 if (acdb_handle == NULL) {
586 ALOGE("%s error opening library %s", __func__, LIB_ACDB_LOADER);
587 return -EFAULT;
588 }
589
590 acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(acdb_handle,
591 "acdb_loader_get_audio_cal_v2");
592 if (acdb_get_audio_cal == NULL) {
593 dlclose(acdb_handle);
594 ALOGE("%s error resolving acdb func symbols", __func__);
595 return -EFAULT;
596 }
597 if (property_get("audio.safx.pbe.app.type", propValueStr, "0")) {
598 propValue = atoll(propValueStr);
599 if (propValue != 0) {
600 pbe_app_type = propValue;
601 }
602 }
603 ALOGD("%s pbe_app_type = 0x%.8x", __func__, pbe_app_type);
604
605 cal_cfg.persist = 1;
606 cal_cfg.cal_type = AUDIO_STREAM_CAL_TYPE;
607 cal_cfg.app_type = pbe_app_type;
608 cal_cfg.module_id = PBE_CONF_MODULE_ID;
609 cal_cfg.param_id = PBE_CONF_PARAM_ID;
610
611 len = sizeof(params->config);
612 ret = acdb_get_audio_cal((void *)&cal_cfg, (void*)&(params->config), &len);
613 ALOGD("%s ret = %d, len = %u", __func__, ret, len);
614 if (ret == 0)
615 params->cfg_len = len;
616
617 dlclose(acdb_handle);
618 return ret;
619 }
620