blob: 72e4d84c795dae0a1f76d0697e4cc0a70b64b1f1 [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*/
Mingming Yin497419f2015-07-01 16:57:32 -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));
wjiangebb69fa2014-05-15 19:38:26 +0800412 if (session == NULL) {
413 ALOGE("get_session() fail to allocate memory");
414 return NULL;
415 }
Eric Laurent73fb11d2013-04-09 11:24:13 -0700416 session_init(session);
417 session->id = sessionId;
418 session->io = ioId;
419 list_add_tail(&session_list, &session->node);
420
421 ALOGV("get_session() created session %p", session);
422
423 return session;
424}
425
426static int init() {
Eric Laurentbdfd2922013-05-28 15:02:50 -0700427 void *lib_handle;
428 const effect_descriptor_t *desc;
Eric Laurent73fb11d2013-04-09 11:24:13 -0700429
430 if (init_status <= 0)
431 return init_status;
432
Eric Laurentbdfd2922013-05-28 15:02:50 -0700433 if (access(EFFECTS_DESCRIPTOR_LIBRARY_PATH, R_OK) == 0) {
434 lib_handle = dlopen(EFFECTS_DESCRIPTOR_LIBRARY_PATH, RTLD_NOW);
435 if (lib_handle == NULL) {
436 ALOGE("%s: DLOPEN failed for %s", __func__, EFFECTS_DESCRIPTOR_LIBRARY_PATH);
437 } else {
438 ALOGV("%s: DLOPEN successful for %s", __func__, EFFECTS_DESCRIPTOR_LIBRARY_PATH);
439 desc = (const effect_descriptor_t *)dlsym(lib_handle,
440 "qcom_product_aec_descriptor");
441 if (desc)
442 descriptors[AEC_ID] = desc;
443
444 desc = (const effect_descriptor_t *)dlsym(lib_handle,
445 "qcom_product_ns_descriptor");
446 if (desc)
447 descriptors[NS_ID] = desc;
448
449//ENABLE_AGC
450// desc = (const effect_descriptor_t *)dlsym(lib_handle,
451// "qcom_product_agc_descriptor");
452// if (desc)
453// descriptors[AGC_ID] = desc;
454 }
455 }
456
Eric Laurent73fb11d2013-04-09 11:24:13 -0700457 uuid_to_id_table[AEC_ID] = FX_IID_AEC;
458 uuid_to_id_table[NS_ID] = FX_IID_NS;
Eric Laurentbdfd2922013-05-28 15:02:50 -0700459//ENABLE_AGC uuid_to_id_table[AGC_ID] = FX_IID_AGC;
Eric Laurent73fb11d2013-04-09 11:24:13 -0700460
461 list_init(&session_list);
462
463 init_status = 0;
464 return init_status;
465}
466
467static const effect_descriptor_t *get_descriptor(const effect_uuid_t *uuid)
468{
469 size_t i;
470 for (i = 0; i < NUM_ID; i++)
471 if (memcmp(&descriptors[i]->uuid, uuid, sizeof(effect_uuid_t)) == 0)
472 return descriptors[i];
473
474 return NULL;
475}
476
477
478//------------------------------------------------------------------------------
479// Effect Control Interface Implementation
480//------------------------------------------------------------------------------
481
482static int fx_process(effect_handle_t self,
483 audio_buffer_t *inBuffer,
484 audio_buffer_t *outBuffer)
485{
486 struct effect_s *effect = (struct effect_s *)self;
487 struct session_s *session;
488
489 if (effect == NULL) {
490 ALOGV("fx_process() ERROR effect == NULL");
491 return -EINVAL;
492 }
493
494 if (inBuffer == NULL || inBuffer->raw == NULL ||
495 outBuffer == NULL || outBuffer->raw == NULL) {
496 ALOGW("fx_process() ERROR bad pointer");
497 return -EINVAL;
498 }
499
500 session = (struct session_s *)effect->session;
501
502 session->processed_msk |= (1<<effect->id);
503
504 if ((session->processed_msk & session->enabled_msk) == session->enabled_msk) {
505 effect->session->processed_msk = 0;
506 return 0;
507 } else
508 return -ENODATA;
509}
510
511static int fx_command(effect_handle_t self,
512 uint32_t cmdCode,
513 uint32_t cmdSize,
514 void *pCmdData,
515 uint32_t *replySize,
516 void *pReplyData)
517{
518 struct effect_s *effect = (struct effect_s *)self;
519
520 if (effect == NULL)
521 return -EINVAL;
522
523 //ALOGV("fx_command: command %d cmdSize %d",cmdCode, cmdSize);
524
525 switch (cmdCode) {
526 case EFFECT_CMD_INIT:
527 if (pReplyData == NULL || *replySize != sizeof(int))
528 return -EINVAL;
529
530 *(int *)pReplyData = 0;
531 break;
532
533 case EFFECT_CMD_SET_CONFIG: {
534 if (pCmdData == NULL||
535 cmdSize != sizeof(effect_config_t)||
536 pReplyData == NULL||
537 *replySize != sizeof(int)) {
538 ALOGV("fx_command() EFFECT_CMD_SET_CONFIG invalid args");
539 return -EINVAL;
540 }
541 *(int *)pReplyData = session_set_config(effect->session, (effect_config_t *)pCmdData);
542 if (*(int *)pReplyData != 0)
543 break;
544
545 if (effect->state != EFFECT_STATE_ACTIVE)
546 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_CONFIG);
547
548 } break;
549
550 case EFFECT_CMD_GET_CONFIG:
551 if (pReplyData == NULL ||
552 *replySize != sizeof(effect_config_t)) {
553 ALOGV("fx_command() EFFECT_CMD_GET_CONFIG invalid args");
554 return -EINVAL;
555 }
556
557 session_get_config(effect->session, (effect_config_t *)pReplyData);
558 break;
559
560 case EFFECT_CMD_RESET:
561 break;
562
563 case EFFECT_CMD_GET_PARAM: {
564 if (pCmdData == NULL ||
565 cmdSize < (int)sizeof(effect_param_t) ||
566 pReplyData == NULL ||
567 *replySize < (int)sizeof(effect_param_t)) {
568 ALOGV("fx_command() EFFECT_CMD_GET_PARAM invalid args");
569 return -EINVAL;
570 }
571 effect_param_t *p = (effect_param_t *)pCmdData;
572
573 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
574 p = (effect_param_t *)pReplyData;
575 p->status = -ENOSYS;
576
577 } break;
578
579 case EFFECT_CMD_SET_PARAM: {
580 if (pCmdData == NULL||
581 cmdSize < (int)sizeof(effect_param_t) ||
582 pReplyData == NULL ||
583 *replySize != sizeof(int32_t)) {
584 ALOGV("fx_command() EFFECT_CMD_SET_PARAM invalid args");
585 return -EINVAL;
586 }
587 effect_param_t *p = (effect_param_t *) pCmdData;
588
589 if (p->psize != sizeof(int32_t)) {
590 ALOGV("fx_command() EFFECT_CMD_SET_PARAM invalid param format");
591 return -EINVAL;
592 }
593 *(int *)pReplyData = -ENOSYS;
594 } break;
595
596 case EFFECT_CMD_ENABLE:
597 if (pReplyData == NULL || *replySize != sizeof(int)) {
598 ALOGV("fx_command() EFFECT_CMD_ENABLE invalid args");
599 return -EINVAL;
600 }
601 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_ACTIVE);
602 break;
603
604 case EFFECT_CMD_DISABLE:
605 if (pReplyData == NULL || *replySize != sizeof(int)) {
606 ALOGV("fx_command() EFFECT_CMD_DISABLE invalid args");
607 return -EINVAL;
608 }
609 *(int *)pReplyData = effect_set_state(effect, EFFECT_STATE_CONFIG);
610 break;
611
612 case EFFECT_CMD_SET_DEVICE:
613 case EFFECT_CMD_SET_INPUT_DEVICE:
614 case EFFECT_CMD_SET_VOLUME:
615 case EFFECT_CMD_SET_AUDIO_MODE:
616 if (pCmdData == NULL ||
617 cmdSize != sizeof(uint32_t)) {
618 ALOGV("fx_command() %s invalid args",
619 cmdCode == EFFECT_CMD_SET_DEVICE ? "EFFECT_CMD_SET_DEVICE" :
620 cmdCode == EFFECT_CMD_SET_INPUT_DEVICE ? "EFFECT_CMD_SET_INPUT_DEVICE" :
621 cmdCode == EFFECT_CMD_SET_VOLUME ? "EFFECT_CMD_SET_VOLUME" :
622 cmdCode == EFFECT_CMD_SET_AUDIO_MODE ? "EFFECT_CMD_SET_AUDIO_MODE" :
623 "");
624 return -EINVAL;
625 }
626 ALOGV("fx_command() %s value %08x",
627 cmdCode == EFFECT_CMD_SET_DEVICE ? "EFFECT_CMD_SET_DEVICE" :
628 cmdCode == EFFECT_CMD_SET_INPUT_DEVICE ? "EFFECT_CMD_SET_INPUT_DEVICE" :
629 cmdCode == EFFECT_CMD_SET_VOLUME ? "EFFECT_CMD_SET_VOLUME" :
630 cmdCode == EFFECT_CMD_SET_AUDIO_MODE ? "EFFECT_CMD_SET_AUDIO_MODE":
631 "",
632 *(int *)pCmdData);
633 break;
634
635 default:
636 return -EINVAL;
637 }
638 return 0;
639}
640
641
642static int fx_get_descriptor(effect_handle_t self,
643 effect_descriptor_t *pDescriptor)
644{
645 struct effect_s *effect = (struct effect_s *)self;
646
647 if (effect == NULL || pDescriptor == NULL)
648 return -EINVAL;
649
650 *pDescriptor = *descriptors[effect->id];
651
652 return 0;
653}
654
655
656// effect_handle_t interface implementation for effect
657static const struct effect_interface_s effect_interface = {
658 fx_process,
659 fx_command,
660 fx_get_descriptor,
661 NULL
662};
663
664//------------------------------------------------------------------------------
665// Effect Library Interface Implementation
666//------------------------------------------------------------------------------
667
668static int lib_create(const effect_uuid_t *uuid,
669 int32_t sessionId,
670 int32_t ioId,
671 effect_handle_t *pInterface)
672{
673 ALOGV("lib_create: uuid: %08x session %d IO: %d", uuid->timeLow, sessionId, ioId);
674
675 int status;
676 const effect_descriptor_t *desc;
677 struct session_s *session;
678 uint32_t id;
679
680 if (init() != 0)
681 return init_status;
682
683 desc = get_descriptor(uuid);
684
685 if (desc == NULL) {
686 ALOGW("lib_create: fx not found uuid: %08x", uuid->timeLow);
687 return -EINVAL;
688 }
689 id = uuid_to_id(&desc->type);
wjiangebb69fa2014-05-15 19:38:26 +0800690 if (id >= NUM_ID) {
691 ALOGW("lib_create: fx not found type: %08x", desc->type.timeLow);
692 return -EINVAL;
693 }
Eric Laurent73fb11d2013-04-09 11:24:13 -0700694
695 session = get_session(id, sessionId, ioId);
696
697 if (session == NULL) {
698 ALOGW("lib_create: no more session available");
699 return -EINVAL;
700 }
701
702 status = session_create_effect(session, id, pInterface);
703
704 if (status < 0 && session->created_msk == 0) {
705 list_remove(&session->node);
706 free(session);
707 }
708 return status;
709}
710
711static int lib_release(effect_handle_t interface)
712{
713 struct listnode *node;
714 struct session_s *session;
715
716 ALOGV("lib_release %p", interface);
717 if (init() != 0)
718 return init_status;
719
720 struct effect_s *fx = (struct effect_s *)interface;
721
722 list_for_each(node, &session_list) {
723 session = node_to_item(node, struct session_s, node);
724 if (session == fx->session) {
725 session_release_effect(fx->session, fx);
726 return 0;
727 }
728 }
729
730 return -EINVAL;
731}
732
733static int lib_get_descriptor(const effect_uuid_t *uuid,
734 effect_descriptor_t *pDescriptor)
735{
736 const effect_descriptor_t *desc;
737
738 if (pDescriptor == NULL || uuid == NULL)
739 return -EINVAL;
740
Eric Laurentbdfd2922013-05-28 15:02:50 -0700741 if (init() != 0)
742 return init_status;
743
Eric Laurent73fb11d2013-04-09 11:24:13 -0700744 desc = get_descriptor(uuid);
745 if (desc == NULL) {
746 ALOGV("lib_get_descriptor() not found");
747 return -EINVAL;
748 }
749
750 ALOGV("lib_get_descriptor() got fx %s", desc->name);
751
752 *pDescriptor = *desc;
753 return 0;
754}
755
756// This is the only symbol that needs to be exported
757__attribute__ ((visibility ("default")))
758audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
759 tag : AUDIO_EFFECT_LIBRARY_TAG,
760 version : EFFECT_LIBRARY_API_VERSION,
761 name : "MSM8960 Audio Preprocessing Library",
762 implementor : "The Android Open Source Project",
763 create_effect : lib_create,
764 release_effect : lib_release,
765 get_descriptor : lib_get_descriptor
766};