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