blob: b3f97c6a7f9d90df7642de4df27afbdd2c3e9a0c [file] [log] [blame]
Eric Laurent73fb11d2013-04-09 11:24:13 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
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 "voice_processing"
18/*#define LOG_NDEBUG 0*/
Vineeta Srivastava7c685a12015-03-20 15:34:33 -070019#include <stdlib.h>
Eric Laurentbdfd2922013-05-28 15:02:50 -070020#include <dlfcn.h>
Eric Laurent73fb11d2013-04-09 11:24:13 -070021#include <cutils/log.h>
22#include <cutils/list.h>
23#include <hardware/audio_effect.h>
24#include <audio_effects/effect_aec.h>
25#include <audio_effects/effect_agc.h>
26#include <audio_effects/effect_ns.h>
27
28
29//------------------------------------------------------------------------------
30// local definitions
31//------------------------------------------------------------------------------
32
Eric Laurentbdfd2922013-05-28 15:02:50 -070033#define EFFECTS_DESCRIPTOR_LIBRARY_PATH "/system/lib/soundfx/libqcomvoiceprocessingdescriptors.so"
34
Eric Laurent73fb11d2013-04-09 11:24:13 -070035// types of pre processing modules
36enum effect_id
37{
38 AEC_ID, // Acoustic Echo Canceler
39 NS_ID, // Noise Suppressor
40//ENABLE_AGC AGC_ID, // Automatic Gain Control
41 NUM_ID
42};
43
44// Session state
45enum session_state {
46 SESSION_STATE_INIT, // initialized
47 SESSION_STATE_CONFIG // configuration received
48};
49
50// Effect/Preprocessor state
51enum effect_state {
52 EFFECT_STATE_INIT, // initialized
53 EFFECT_STATE_CREATED, // webRTC engine created
54 EFFECT_STATE_CONFIG, // configuration received/disabled
55 EFFECT_STATE_ACTIVE // active/enabled
56};
57
58// Effect context
59struct effect_s {
60 const struct effect_interface_s *itfe;
61 uint32_t id; // type of pre processor (enum effect_id)
62 uint32_t state; // current state (enum effect_state)
63 struct session_s *session; // session the effect is on
64};
65
66// Session context
67struct session_s {
68 struct listnode node;
69 effect_config_t config;
70 struct effect_s effects[NUM_ID]; // effects in this session
71 uint32_t state; // current state (enum session_state)
72 int id; // audio session ID
73 int io; // handle of input stream this session is on
74 uint32_t created_msk; // bit field containing IDs of crested pre processors
75 uint32_t enabled_msk; // bit field containing IDs of enabled pre processors
76 uint32_t processed_msk; // bit field containing IDs of pre processors already
77};
78
79
80//------------------------------------------------------------------------------
Eric Laurentbdfd2922013-05-28 15:02:50 -070081// Default Effect descriptors. Device specific descriptors should be defined in
82// libqcomvoiceprocessing.<product_name>.so if needed.
Eric Laurent73fb11d2013-04-09 11:24:13 -070083//------------------------------------------------------------------------------
84
85// UUIDs for effect types have been generated from http://www.itu.int/ITU-T/asn1/uuid.html
86// as the pre processing effects are not defined by OpenSL ES
87
88// Acoustic Echo Cancellation
Eric Laurentbdfd2922013-05-28 15:02:50 -070089static const effect_descriptor_t qcom_default_aec_descriptor = {
Eric Laurent73fb11d2013-04-09 11:24:13 -070090 { 0x7b491460, 0x8d4d, 0x11e0, 0xbd61, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
91 { 0x0f8d0d2a, 0x59e5, 0x45fe, 0xb6e4, { 0x24, 0x8c, 0x8a, 0x79, 0x91, 0x09 } }, // uuid
92 EFFECT_CONTROL_API_VERSION,
93 (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
94 0,
95 0,
96 "Acoustic Echo Canceler",
97 "Qualcomm Fluence"
98};
99
100// Noise suppression
Eric Laurentbdfd2922013-05-28 15:02:50 -0700101static const effect_descriptor_t qcom_default_ns_descriptor = {
Eric Laurent73fb11d2013-04-09 11:24:13 -0700102 { 0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
103 { 0x1d97bb0b, 0x9e2f, 0x4403, 0x9ae3, { 0x58, 0xc2, 0x55, 0x43, 0x06, 0xf8 } }, // uuid
104 EFFECT_CONTROL_API_VERSION,
105 (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
106 0,
107 0,
108 "Noise Suppression",
109 "Qualcomm Fluence"
110};
111
112//ENABLE_AGC
113// Automatic Gain Control
Eric Laurentbdfd2922013-05-28 15:02:50 -0700114//static const effect_descriptor_t qcom_default_agc_descriptor = {
Eric Laurent73fb11d2013-04-09 11:24:13 -0700115// { 0x0a8abfe0, 0x654c, 0x11e0, 0xba26, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
116// { 0x0dd49521, 0x8c59, 0x40b1, 0xb403, { 0xe0, 0x8d, 0x5f, 0x01, 0x87, 0x5e } }, // uuid
117// EFFECT_CONTROL_API_VERSION,
118// (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
119// 0,
120// 0,
121// "Automatic Gain Control",
122// "Qualcomm Fluence"
123//};
124
Eric Laurentbdfd2922013-05-28 15:02:50 -0700125const effect_descriptor_t *descriptors[NUM_ID] = {
126 &qcom_default_aec_descriptor,
127 &qcom_default_ns_descriptor,
128//ENABLE_AGC &qcom_default_agc_descriptor,
Eric Laurent73fb11d2013-04-09 11:24:13 -0700129};
130
131
132static int init_status = 1;
133struct listnode session_list;
134static const struct effect_interface_s effect_interface;
135static const effect_uuid_t * uuid_to_id_table[NUM_ID];
136
137//------------------------------------------------------------------------------
138// Helper functions
139//------------------------------------------------------------------------------
140
141static const effect_uuid_t * id_to_uuid(int id)
142{
143 if (id >= NUM_ID)
144 return EFFECT_UUID_NULL;
145
146 return uuid_to_id_table[id];
147}
148
149static uint32_t uuid_to_id(const effect_uuid_t * uuid)
150{
151 size_t i;
152 for (i = 0; i < NUM_ID; i++)
153 if (memcmp(uuid, uuid_to_id_table[i], sizeof(*uuid)) == 0)
154 break;
155
156 return i;
157}
158
159//------------------------------------------------------------------------------
160// Effect functions
161//------------------------------------------------------------------------------
162
163static void session_set_fx_enabled(struct session_s *session, uint32_t id, bool enabled);
164
165#define BAD_STATE_ABORT(from, to) \
166 LOG_ALWAYS_FATAL("Bad state transition from %d to %d", from, to);
167
168static int effect_set_state(struct effect_s *effect, uint32_t state)
169{
170 int status = 0;
171 ALOGV("effect_set_state() id %d, new %d old %d", effect->id, state, effect->state);
172 switch(state) {
173 case EFFECT_STATE_INIT:
174 switch(effect->state) {
175 case EFFECT_STATE_ACTIVE:
176 session_set_fx_enabled(effect->session, effect->id, false);
177 case EFFECT_STATE_CONFIG:
178 case EFFECT_STATE_CREATED:
179 case EFFECT_STATE_INIT:
180 break;
181 default:
182 BAD_STATE_ABORT(effect->state, state);
183 }
184 break;
185 case EFFECT_STATE_CREATED:
186 switch(effect->state) {
187 case EFFECT_STATE_INIT:
188 break;
189 case EFFECT_STATE_CREATED:
190 case EFFECT_STATE_ACTIVE:
191 case EFFECT_STATE_CONFIG:
192 ALOGE("effect_set_state() invalid transition");
193 status = -ENOSYS;
194 break;
195 default:
196 BAD_STATE_ABORT(effect->state, state);
197 }
198 break;
199 case EFFECT_STATE_CONFIG:
200 switch(effect->state) {
201 case EFFECT_STATE_INIT:
202 ALOGE("effect_set_state() invalid transition");
203 status = -ENOSYS;
204 break;
205 case EFFECT_STATE_ACTIVE:
206 session_set_fx_enabled(effect->session, effect->id, false);
207 break;
208 case EFFECT_STATE_CREATED:
209 case EFFECT_STATE_CONFIG:
210 break;
211 default:
212 BAD_STATE_ABORT(effect->state, state);
213 }
214 break;
215 case EFFECT_STATE_ACTIVE:
216 switch(effect->state) {
217 case EFFECT_STATE_INIT:
218 case EFFECT_STATE_CREATED:
219 ALOGE("effect_set_state() invalid transition");
220 status = -ENOSYS;
221 break;
222 case EFFECT_STATE_ACTIVE:
223 // enabling an already enabled effect is just ignored
224 break;
225 case EFFECT_STATE_CONFIG:
226 session_set_fx_enabled(effect->session, effect->id, true);
227 break;
228 default:
229 BAD_STATE_ABORT(effect->state, state);
230 }
231 break;
232 default:
233 BAD_STATE_ABORT(effect->state, state);
234 }
235
236 if (status == 0)
237 effect->state = state;
238
239 return status;
240}
241
242static int effect_init(struct effect_s *effect, uint32_t id)
243{
244 effect->itfe = &effect_interface;
245 effect->id = id;
246 effect->state = EFFECT_STATE_INIT;
247 return 0;
248}
249
250static int effect_create(struct effect_s *effect,
251 struct session_s *session,
252 effect_handle_t *interface)
253{
254 effect->session = session;
255 *interface = (effect_handle_t)&effect->itfe;
256 return effect_set_state(effect, EFFECT_STATE_CREATED);
257}
258
259static int effect_release(struct effect_s *effect)
260{
261 return effect_set_state(effect, EFFECT_STATE_INIT);
262}
263
264
265//------------------------------------------------------------------------------
266// Session functions
267//------------------------------------------------------------------------------
268
269static int session_init(struct session_s *session)
270{
271 size_t i;
272 int status = 0;
273
274 session->state = SESSION_STATE_INIT;
275 session->id = 0;
276 session->io = 0;
277 session->created_msk = 0;
278 for (i = 0; i < NUM_ID && status == 0; i++)
279 status = effect_init(&session->effects[i], i);
280
281 return status;
282}
283
284
285static int session_create_effect(struct session_s *session,
286 int32_t id,
287 effect_handle_t *interface)
288{
289 int status = -ENOMEM;
290
291 ALOGV("session_create_effect() %s, created_msk %08x",
292 id == AEC_ID ? "AEC" : id == NS_ID ? "NS" : "?", session->created_msk);
293
294 if (session->created_msk == 0) {
295 session->config.inputCfg.samplingRate = 16000;
296 session->config.inputCfg.channels = AUDIO_CHANNEL_IN_MONO;
297 session->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
298 session->config.outputCfg.samplingRate = 16000;
299 session->config.outputCfg.channels = AUDIO_CHANNEL_IN_MONO;
300 session->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
301 session->enabled_msk = 0;
302 session->processed_msk = 0;
303 }
304 status = effect_create(&session->effects[id], session, interface);
305 if (status < 0)
306 goto error;
307
308 ALOGV("session_create_effect() OK");
309 session->created_msk |= (1<<id);
310 return status;
311
312error:
313 return status;
314}
315
316static int session_release_effect(struct session_s *session,
317 struct effect_s *fx)
318{
319 ALOGW_IF(effect_release(fx) != 0, " session_release_effect() failed for id %d", fx->id);
320
321 session->created_msk &= ~(1<<fx->id);
322 if (session->created_msk == 0)
323 {
324 ALOGV("session_release_effect() last effect: removing session");
325 list_remove(&session->node);
326 free(session);
327 }
328
329 return 0;
330}
331
332
333static int session_set_config(struct session_s *session, effect_config_t *config)
334{
335 int status;
336
337 if (config->inputCfg.samplingRate != config->outputCfg.samplingRate ||
338 config->inputCfg.format != config->outputCfg.format ||
339 config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT)
340 return -EINVAL;
341
342 ALOGV("session_set_config() sampling rate %d channels %08x",
343 config->inputCfg.samplingRate, config->inputCfg.channels);
344
345 // if at least one process is enabled, do not accept configuration changes
346 if (session->enabled_msk) {
347 if (session->config.inputCfg.samplingRate != config->inputCfg.samplingRate ||
348 session->config.inputCfg.channels != config->inputCfg.channels ||
349 session->config.outputCfg.channels != config->outputCfg.channels)
350 return -ENOSYS;
351 else
352 return 0;
353 }
354
355 memcpy(&session->config, config, sizeof(effect_config_t));
356
357 session->state = SESSION_STATE_CONFIG;
358 return 0;
359}
360
361static void session_get_config(struct session_s *session, effect_config_t *config)
362{
363 memcpy(config, &session->config, sizeof(effect_config_t));
364
365 config->inputCfg.mask = config->outputCfg.mask =
366 (EFFECT_CONFIG_SMP_RATE | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT);
367}
368
369
370static void session_set_fx_enabled(struct session_s *session, uint32_t id, bool enabled)
371{
372 if (enabled) {
373 if(session->enabled_msk == 0) {
374 /* do first enable here */
375 }
376 session->enabled_msk |= (1 << id);
377 } else {
378 session->enabled_msk &= ~(1 << id);
379 if(session->enabled_msk == 0) {
380 /* do last enable here */
381 }
382 }
383 ALOGV("session_set_fx_enabled() id %d, enabled %d enabled_msk %08x",
384 id, enabled, session->enabled_msk);
385 session->processed_msk = 0;
386}
387
388//------------------------------------------------------------------------------
389// Global functions
390//------------------------------------------------------------------------------
391
392static struct session_s *get_session(int32_t id, int32_t sessionId, int32_t ioId)
393{
394 size_t i;
395 int free = -1;
396 struct listnode *node;
397 struct session_s *session;
398
399 list_for_each(node, &session_list) {
400 session = node_to_item(node, struct session_s, node);
401 if (session->io == ioId) {
402 if (session->created_msk & (1 << id)) {
403 ALOGV("get_session() effect %d already created", id);
404 return NULL;
405 }
406 ALOGV("get_session() found session %p", session);
407 return session;
408 }
409 }
410
411 session = (struct session_s *)calloc(1, sizeof(struct session_s));
412 session_init(session);
413 session->id = sessionId;
414 session->io = ioId;
415 list_add_tail(&session_list, &session->node);
416
417 ALOGV("get_session() created session %p", session);
418
419 return session;
420}
421
422static int init() {
Eric Laurentbdfd2922013-05-28 15:02:50 -0700423 void *lib_handle;
424 const effect_descriptor_t *desc;
Eric Laurent73fb11d2013-04-09 11:24:13 -0700425
426 if (init_status <= 0)
427 return init_status;
428
Eric Laurentbdfd2922013-05-28 15:02:50 -0700429 if (access(EFFECTS_DESCRIPTOR_LIBRARY_PATH, R_OK) == 0) {
430 lib_handle = dlopen(EFFECTS_DESCRIPTOR_LIBRARY_PATH, RTLD_NOW);
431 if (lib_handle == NULL) {
432 ALOGE("%s: DLOPEN failed for %s", __func__, EFFECTS_DESCRIPTOR_LIBRARY_PATH);
433 } else {
434 ALOGV("%s: DLOPEN successful for %s", __func__, EFFECTS_DESCRIPTOR_LIBRARY_PATH);
435 desc = (const effect_descriptor_t *)dlsym(lib_handle,
436 "qcom_product_aec_descriptor");
437 if (desc)
438 descriptors[AEC_ID] = desc;
439
440 desc = (const effect_descriptor_t *)dlsym(lib_handle,
441 "qcom_product_ns_descriptor");
442 if (desc)
443 descriptors[NS_ID] = desc;
444
445//ENABLE_AGC
446// desc = (const effect_descriptor_t *)dlsym(lib_handle,
447// "qcom_product_agc_descriptor");
448// if (desc)
449// descriptors[AGC_ID] = desc;
450 }
451 }
452
Eric Laurent73fb11d2013-04-09 11:24:13 -0700453 uuid_to_id_table[AEC_ID] = FX_IID_AEC;
454 uuid_to_id_table[NS_ID] = FX_IID_NS;
Eric Laurentbdfd2922013-05-28 15:02:50 -0700455//ENABLE_AGC uuid_to_id_table[AGC_ID] = FX_IID_AGC;
Eric Laurent73fb11d2013-04-09 11:24:13 -0700456
457 list_init(&session_list);
458
459 init_status = 0;
460 return init_status;
461}
462
463static const effect_descriptor_t *get_descriptor(const effect_uuid_t *uuid)
464{
465 size_t i;
466 for (i = 0; i < NUM_ID; i++)
467 if (memcmp(&descriptors[i]->uuid, uuid, sizeof(effect_uuid_t)) == 0)
468 return descriptors[i];
469
470 return NULL;
471}
472
473
474//------------------------------------------------------------------------------
475// Effect Control Interface Implementation
476//------------------------------------------------------------------------------
477
478static int fx_process(effect_handle_t self,
479 audio_buffer_t *inBuffer,
480 audio_buffer_t *outBuffer)
481{
482 struct effect_s *effect = (struct effect_s *)self;
483 struct session_s *session;
484
485 if (effect == NULL) {
486 ALOGV("fx_process() ERROR effect == NULL");
487 return -EINVAL;
488 }
489
490 if (inBuffer == NULL || inBuffer->raw == NULL ||
491 outBuffer == NULL || outBuffer->raw == NULL) {
492 ALOGW("fx_process() ERROR bad pointer");
493 return -EINVAL;
494 }
495
496 session = (struct session_s *)effect->session;
497
498 session->processed_msk |= (1<<effect->id);
499
500 if ((session->processed_msk & session->enabled_msk) == session->enabled_msk) {
501 effect->session->processed_msk = 0;
502 return 0;
503 } else
504 return -ENODATA;
505}
506
507static int fx_command(effect_handle_t self,
508 uint32_t cmdCode,
509 uint32_t cmdSize,
510 void *pCmdData,
511 uint32_t *replySize,
512 void *pReplyData)
513{
514 struct effect_s *effect = (struct effect_s *)self;
515
516 if (effect == NULL)
517 return -EINVAL;
518
519 //ALOGV("fx_command: command %d cmdSize %d",cmdCode, cmdSize);
520
521 switch (cmdCode) {
522 case EFFECT_CMD_INIT:
523 if (pReplyData == NULL || *replySize != sizeof(int))
524 return -EINVAL;
525
526 *(int *)pReplyData = 0;
527 break;
528
529 case EFFECT_CMD_SET_CONFIG: {
530 if (pCmdData == NULL||
531 cmdSize != sizeof(effect_config_t)||
532 pReplyData == NULL||
533 *replySize != sizeof(int)) {
534 ALOGV("fx_command() EFFECT_CMD_SET_CONFIG invalid args");
535 return -EINVAL;
536 }
537 *(int *)pReplyData = session_set_config(effect->session, (effect_config_t *)pCmdData);
538 if (*(int *)pReplyData != 0)
539 break;
540
541 if (effect->state != EFFECT_STATE_ACTIVE)
542 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_CONFIG);
543
544 } break;
545
546 case EFFECT_CMD_GET_CONFIG:
547 if (pReplyData == NULL ||
548 *replySize != sizeof(effect_config_t)) {
549 ALOGV("fx_command() EFFECT_CMD_GET_CONFIG invalid args");
550 return -EINVAL;
551 }
552
553 session_get_config(effect->session, (effect_config_t *)pReplyData);
554 break;
555
556 case EFFECT_CMD_RESET:
557 break;
558
559 case EFFECT_CMD_GET_PARAM: {
560 if (pCmdData == NULL ||
561 cmdSize < (int)sizeof(effect_param_t) ||
562 pReplyData == NULL ||
563 *replySize < (int)sizeof(effect_param_t)) {
564 ALOGV("fx_command() EFFECT_CMD_GET_PARAM invalid args");
565 return -EINVAL;
566 }
567 effect_param_t *p = (effect_param_t *)pCmdData;
568
569 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
570 p = (effect_param_t *)pReplyData;
571 p->status = -ENOSYS;
572
573 } break;
574
575 case EFFECT_CMD_SET_PARAM: {
576 if (pCmdData == NULL||
577 cmdSize < (int)sizeof(effect_param_t) ||
578 pReplyData == NULL ||
579 *replySize != sizeof(int32_t)) {
580 ALOGV("fx_command() EFFECT_CMD_SET_PARAM invalid args");
581 return -EINVAL;
582 }
583 effect_param_t *p = (effect_param_t *) pCmdData;
584
585 if (p->psize != sizeof(int32_t)) {
586 ALOGV("fx_command() EFFECT_CMD_SET_PARAM invalid param format");
587 return -EINVAL;
588 }
589 *(int *)pReplyData = -ENOSYS;
590 } break;
591
592 case EFFECT_CMD_ENABLE:
593 if (pReplyData == NULL || *replySize != sizeof(int)) {
594 ALOGV("fx_command() EFFECT_CMD_ENABLE invalid args");
595 return -EINVAL;
596 }
597 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_ACTIVE);
598 break;
599
600 case EFFECT_CMD_DISABLE:
601 if (pReplyData == NULL || *replySize != sizeof(int)) {
602 ALOGV("fx_command() EFFECT_CMD_DISABLE invalid args");
603 return -EINVAL;
604 }
605 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_CONFIG);
606 break;
607
608 case EFFECT_CMD_SET_DEVICE:
609 case EFFECT_CMD_SET_INPUT_DEVICE:
610 case EFFECT_CMD_SET_VOLUME:
611 case EFFECT_CMD_SET_AUDIO_MODE:
612 if (pCmdData == NULL ||
613 cmdSize != sizeof(uint32_t)) {
614 ALOGV("fx_command() %s invalid args",
615 cmdCode == EFFECT_CMD_SET_DEVICE ? "EFFECT_CMD_SET_DEVICE" :
616 cmdCode == EFFECT_CMD_SET_INPUT_DEVICE ? "EFFECT_CMD_SET_INPUT_DEVICE" :
617 cmdCode == EFFECT_CMD_SET_VOLUME ? "EFFECT_CMD_SET_VOLUME" :
618 cmdCode == EFFECT_CMD_SET_AUDIO_MODE ? "EFFECT_CMD_SET_AUDIO_MODE" :
619 "");
620 return -EINVAL;
621 }
622 ALOGV("fx_command() %s value %08x",
623 cmdCode == EFFECT_CMD_SET_DEVICE ? "EFFECT_CMD_SET_DEVICE" :
624 cmdCode == EFFECT_CMD_SET_INPUT_DEVICE ? "EFFECT_CMD_SET_INPUT_DEVICE" :
625 cmdCode == EFFECT_CMD_SET_VOLUME ? "EFFECT_CMD_SET_VOLUME" :
626 cmdCode == EFFECT_CMD_SET_AUDIO_MODE ? "EFFECT_CMD_SET_AUDIO_MODE":
627 "",
628 *(int *)pCmdData);
629 break;
630
631 default:
632 return -EINVAL;
633 }
634 return 0;
635}
636
637
638static int fx_get_descriptor(effect_handle_t self,
639 effect_descriptor_t *pDescriptor)
640{
641 struct effect_s *effect = (struct effect_s *)self;
642
643 if (effect == NULL || pDescriptor == NULL)
644 return -EINVAL;
645
646 *pDescriptor = *descriptors[effect->id];
647
648 return 0;
649}
650
651
652// effect_handle_t interface implementation for effect
653static const struct effect_interface_s effect_interface = {
654 fx_process,
655 fx_command,
656 fx_get_descriptor,
657 NULL
658};
659
660//------------------------------------------------------------------------------
661// Effect Library Interface Implementation
662//------------------------------------------------------------------------------
663
664static int lib_create(const effect_uuid_t *uuid,
665 int32_t sessionId,
666 int32_t ioId,
667 effect_handle_t *pInterface)
668{
669 ALOGV("lib_create: uuid: %08x session %d IO: %d", uuid->timeLow, sessionId, ioId);
670
671 int status;
672 const effect_descriptor_t *desc;
673 struct session_s *session;
674 uint32_t id;
675
676 if (init() != 0)
677 return init_status;
678
679 desc = get_descriptor(uuid);
680
681 if (desc == NULL) {
682 ALOGW("lib_create: fx not found uuid: %08x", uuid->timeLow);
683 return -EINVAL;
684 }
685 id = uuid_to_id(&desc->type);
686
687 session = get_session(id, sessionId, ioId);
688
689 if (session == NULL) {
690 ALOGW("lib_create: no more session available");
691 return -EINVAL;
692 }
693
694 status = session_create_effect(session, id, pInterface);
695
696 if (status < 0 && session->created_msk == 0) {
697 list_remove(&session->node);
698 free(session);
699 }
700 return status;
701}
702
703static int lib_release(effect_handle_t interface)
704{
705 struct listnode *node;
706 struct session_s *session;
707
708 ALOGV("lib_release %p", interface);
709 if (init() != 0)
710 return init_status;
711
712 struct effect_s *fx = (struct effect_s *)interface;
713
714 list_for_each(node, &session_list) {
715 session = node_to_item(node, struct session_s, node);
716 if (session == fx->session) {
717 session_release_effect(fx->session, fx);
718 return 0;
719 }
720 }
721
722 return -EINVAL;
723}
724
725static int lib_get_descriptor(const effect_uuid_t *uuid,
726 effect_descriptor_t *pDescriptor)
727{
728 const effect_descriptor_t *desc;
729
730 if (pDescriptor == NULL || uuid == NULL)
731 return -EINVAL;
732
Eric Laurentbdfd2922013-05-28 15:02:50 -0700733 if (init() != 0)
734 return init_status;
735
Eric Laurent73fb11d2013-04-09 11:24:13 -0700736 desc = get_descriptor(uuid);
737 if (desc == NULL) {
738 ALOGV("lib_get_descriptor() not found");
739 return -EINVAL;
740 }
741
742 ALOGV("lib_get_descriptor() got fx %s", desc->name);
743
744 *pDescriptor = *desc;
745 return 0;
746}
747
748// This is the only symbol that needs to be exported
749__attribute__ ((visibility ("default")))
750audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
synergydev30337432013-10-19 22:28:40 -0700751 .tag = AUDIO_EFFECT_LIBRARY_TAG,
752 .version = EFFECT_LIBRARY_API_VERSION,
753 .name = "MSM8960 Audio Preprocessing Library",
754 .implementor = "The Android Open Source Project",
755 .create_effect = lib_create,
756 .release_effect = lib_release,
757 .get_descriptor = lib_get_descriptor
Eric Laurent73fb11d2013-04-09 11:24:13 -0700758};