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