1/* 2 * Copyright (C) 2011 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 18#ifndef ANDROID_AUDIO_EFFECT_H 19#define ANDROID_AUDIO_EFFECT_H 20 21#include <errno.h> 22#include <stdint.h> 23#include <strings.h> 24#include <sys/cdefs.h> 25#include <sys/types.h> 26 27#include <cutils/bitops.h> 28 29#include <system/audio.h> 30 31 32__BEGIN_DECLS 33 34 35///////////////////////////////////////////////// 36// Common Definitions 37///////////////////////////////////////////////// 38 39// 40//--- Effect descriptor structure effect_descriptor_t 41// 42 43// Unique effect ID (can be generated from the following site: 44// http://www.itu.int/ITU-T/asn1/uuid.html) 45// This format is used for both "type" and "uuid" fields of the effect descriptor structure. 46// - When used for effect type and the engine is implementing and effect corresponding to a standard 47// OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface. 48// - When used as uuid, it should be a unique UUID for this particular implementation. 49typedef struct effect_uuid_s { 50 uint32_t timeLow; 51 uint16_t timeMid; 52 uint16_t timeHiAndVersion; 53 uint16_t clockSeq; 54 uint8_t node[6]; 55} effect_uuid_t; 56 57// Maximum length of character strings in structures defines by this API. 58#define EFFECT_STRING_LEN_MAX 64 59 60// NULL UUID definition (matches SL_IID_NULL_) 61#define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \ 62 { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } 63static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER; 64static const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_; 65static const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210"; 66 67 68// The effect descriptor contains necessary information to facilitate the enumeration of the effect 69// engines present in a library. 70typedef struct effect_descriptor_s { 71 effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect 72 effect_uuid_t uuid; // UUID for this particular implementation 73 uint32_t apiVersion; // Version of the effect control API implemented 74 uint32_t flags; // effect engine capabilities/requirements flags (see below) 75 uint16_t cpuLoad; // CPU load indication (see below) 76 uint16_t memoryUsage; // Data Memory usage (see below) 77 char name[EFFECT_STRING_LEN_MAX]; // human readable effect name 78 char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name 79} effect_descriptor_t; 80 81// CPU load and memory usage indication: each effect implementation must provide an indication of 82// its CPU and memory usage for the audio effect framework to limit the number of effects 83// instantiated at a given time on a given platform. 84// The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS. 85// The memory usage is expressed in KB and includes only dynamically allocated memory 86 87// Definitions for flags field of effect descriptor. 88// +---------------------------+-----------+----------------------------------- 89// | description | bits | values 90// +---------------------------+-----------+----------------------------------- 91// | connection mode | 0..2 | 0 insert: after track process 92// | | | 1 auxiliary: connect to track auxiliary 93// | | | output and use send level 94// | | | 2 replace: replaces track process function; 95// | | | must implement SRC, volume and mono to stereo. 96// | | | 3 pre processing: applied below audio HAL on input 97// | | | 4 post processing: applied below audio HAL on output 98// | | | 5 - 7 reserved 99// +---------------------------+-----------+----------------------------------- 100// | insertion preference | 3..5 | 0 none 101// | | | 1 first of the chain 102// | | | 2 last of the chain 103// | | | 3 exclusive (only effect in the insert chain) 104// | | | 4..7 reserved 105// +---------------------------+-----------+----------------------------------- 106// | Volume management | 6..8 | 0 none 107// | | | 1 implements volume control 108// | | | 2 requires volume indication 109// | | | 4 reserved 110// +---------------------------+-----------+----------------------------------- 111// | Device indication | 9..11 | 0 none 112// | | | 1 requires device updates 113// | | | 2, 4 reserved 114// +---------------------------+-----------+----------------------------------- 115// | Sample input mode | 12..13 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG 116// | | | command must specify a buffer descriptor 117// | | | 2 provider: process() function uses the 118// | | | bufferProvider indicated by the 119// | | | EFFECT_CMD_SET_CONFIG command to request input. 120// | | | buffers. 121// | | | 3 both: both input modes are supported 122// +---------------------------+-----------+----------------------------------- 123// | Sample output mode | 14..15 | 1 direct: process() function or EFFECT_CMD_SET_CONFIG 124// | | | command must specify a buffer descriptor 125// | | | 2 provider: process() function uses the 126// | | | bufferProvider indicated by the 127// | | | EFFECT_CMD_SET_CONFIG command to request output 128// | | | buffers. 129// | | | 3 both: both output modes are supported 130// +---------------------------+-----------+----------------------------------- 131// | Hardware acceleration | 16..17 | 0 No hardware acceleration 132// | | | 1 non tunneled hw acceleration: the process() function 133// | | | reads the samples, send them to HW accelerated 134// | | | effect processor, reads back the processed samples 135// | | | and returns them to the output buffer. 136// | | | 2 tunneled hw acceleration: the process() function is 137// | | | transparent. The effect interface is only used to 138// | | | control the effect engine. This mode is relevant for 139// | | | global effects actually applied by the audio 140// | | | hardware on the output stream. 141// +---------------------------+-----------+----------------------------------- 142// | Audio Mode indication | 18..19 | 0 none 143// | | | 1 requires audio mode updates 144// | | | 2..3 reserved 145// +---------------------------+-----------+----------------------------------- 146// | Audio source indication | 20..21 | 0 none 147// | | | 1 requires audio source updates 148// | | | 2..3 reserved 149// +---------------------------+-----------+----------------------------------- 150// | Effect offload supported | 22 | 0 The effect cannot be offloaded to an audio DSP 151// | | | 1 The effect can be offloaded to an audio DSP 152// +---------------------------+-----------+----------------------------------- 153// | Process function not | 23 | 0 The effect implements a process function. 154// | implemented | | 1 The effect does not implement a process function: 155// | | | enabling the effect has no impact on latency or 156// | | | CPU load. 157// | | | Effect implementations setting this flag do not have 158// | | | to implement a process function. 159// +---------------------------+-----------+----------------------------------- 160 161// Insert mode 162#define EFFECT_FLAG_TYPE_SHIFT 0 163#define EFFECT_FLAG_TYPE_SIZE 3 164#define EFFECT_FLAG_TYPE_MASK (((1 << EFFECT_FLAG_TYPE_SIZE) -1) \ 165 << EFFECT_FLAG_TYPE_SHIFT) 166#define EFFECT_FLAG_TYPE_INSERT (0 << EFFECT_FLAG_TYPE_SHIFT) 167#define EFFECT_FLAG_TYPE_AUXILIARY (1 << EFFECT_FLAG_TYPE_SHIFT) 168#define EFFECT_FLAG_TYPE_REPLACE (2 << EFFECT_FLAG_TYPE_SHIFT) 169#define EFFECT_FLAG_TYPE_PRE_PROC (3 << EFFECT_FLAG_TYPE_SHIFT) 170#define EFFECT_FLAG_TYPE_POST_PROC (4 << EFFECT_FLAG_TYPE_SHIFT) 171 172// Insert preference 173#define EFFECT_FLAG_INSERT_SHIFT (EFFECT_FLAG_TYPE_SHIFT + EFFECT_FLAG_TYPE_SIZE) 174#define EFFECT_FLAG_INSERT_SIZE 3 175#define EFFECT_FLAG_INSERT_MASK (((1 << EFFECT_FLAG_INSERT_SIZE) -1) \ 176 << EFFECT_FLAG_INSERT_SHIFT) 177#define EFFECT_FLAG_INSERT_ANY (0 << EFFECT_FLAG_INSERT_SHIFT) 178#define EFFECT_FLAG_INSERT_FIRST (1 << EFFECT_FLAG_INSERT_SHIFT) 179#define EFFECT_FLAG_INSERT_LAST (2 << EFFECT_FLAG_INSERT_SHIFT) 180#define EFFECT_FLAG_INSERT_EXCLUSIVE (3 << EFFECT_FLAG_INSERT_SHIFT) 181 182 183// Volume control 184#define EFFECT_FLAG_VOLUME_SHIFT (EFFECT_FLAG_INSERT_SHIFT + EFFECT_FLAG_INSERT_SIZE) 185#define EFFECT_FLAG_VOLUME_SIZE 3 186#define EFFECT_FLAG_VOLUME_MASK (((1 << EFFECT_FLAG_VOLUME_SIZE) -1) \ 187 << EFFECT_FLAG_VOLUME_SHIFT) 188#define EFFECT_FLAG_VOLUME_CTRL (1 << EFFECT_FLAG_VOLUME_SHIFT) 189#define EFFECT_FLAG_VOLUME_IND (2 << EFFECT_FLAG_VOLUME_SHIFT) 190#define EFFECT_FLAG_VOLUME_NONE (0 << EFFECT_FLAG_VOLUME_SHIFT) 191 192// Device indication 193#define EFFECT_FLAG_DEVICE_SHIFT (EFFECT_FLAG_VOLUME_SHIFT + EFFECT_FLAG_VOLUME_SIZE) 194#define EFFECT_FLAG_DEVICE_SIZE 3 195#define EFFECT_FLAG_DEVICE_MASK (((1 << EFFECT_FLAG_DEVICE_SIZE) -1) \ 196 << EFFECT_FLAG_DEVICE_SHIFT) 197#define EFFECT_FLAG_DEVICE_IND (1 << EFFECT_FLAG_DEVICE_SHIFT) 198#define EFFECT_FLAG_DEVICE_NONE (0 << EFFECT_FLAG_DEVICE_SHIFT) 199 200// Sample input modes 201#define EFFECT_FLAG_INPUT_SHIFT (EFFECT_FLAG_DEVICE_SHIFT + EFFECT_FLAG_DEVICE_SIZE) 202#define EFFECT_FLAG_INPUT_SIZE 2 203#define EFFECT_FLAG_INPUT_MASK (((1 << EFFECT_FLAG_INPUT_SIZE) -1) \ 204 << EFFECT_FLAG_INPUT_SHIFT) 205#define EFFECT_FLAG_INPUT_DIRECT (1 << EFFECT_FLAG_INPUT_SHIFT) 206#define EFFECT_FLAG_INPUT_PROVIDER (2 << EFFECT_FLAG_INPUT_SHIFT) 207#define EFFECT_FLAG_INPUT_BOTH (3 << EFFECT_FLAG_INPUT_SHIFT) 208 209// Sample output modes 210#define EFFECT_FLAG_OUTPUT_SHIFT (EFFECT_FLAG_INPUT_SHIFT + EFFECT_FLAG_INPUT_SIZE) 211#define EFFECT_FLAG_OUTPUT_SIZE 2 212#define EFFECT_FLAG_OUTPUT_MASK (((1 << EFFECT_FLAG_OUTPUT_SIZE) -1) \ 213 << EFFECT_FLAG_OUTPUT_SHIFT) 214#define EFFECT_FLAG_OUTPUT_DIRECT (1 << EFFECT_FLAG_OUTPUT_SHIFT) 215#define EFFECT_FLAG_OUTPUT_PROVIDER (2 << EFFECT_FLAG_OUTPUT_SHIFT) 216#define EFFECT_FLAG_OUTPUT_BOTH (3 << EFFECT_FLAG_OUTPUT_SHIFT) 217 218// Hardware acceleration mode 219#define EFFECT_FLAG_HW_ACC_SHIFT (EFFECT_FLAG_OUTPUT_SHIFT + EFFECT_FLAG_OUTPUT_SIZE) 220#define EFFECT_FLAG_HW_ACC_SIZE 2 221#define EFFECT_FLAG_HW_ACC_MASK (((1 << EFFECT_FLAG_HW_ACC_SIZE) -1) \ 222 << EFFECT_FLAG_HW_ACC_SHIFT) 223#define EFFECT_FLAG_HW_ACC_SIMPLE (1 << EFFECT_FLAG_HW_ACC_SHIFT) 224#define EFFECT_FLAG_HW_ACC_TUNNEL (2 << EFFECT_FLAG_HW_ACC_SHIFT) 225 226// Audio mode indication 227#define EFFECT_FLAG_AUDIO_MODE_SHIFT (EFFECT_FLAG_HW_ACC_SHIFT + EFFECT_FLAG_HW_ACC_SIZE) 228#define EFFECT_FLAG_AUDIO_MODE_SIZE 2 229#define EFFECT_FLAG_AUDIO_MODE_MASK (((1 << EFFECT_FLAG_AUDIO_MODE_SIZE) -1) \ 230 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 231#define EFFECT_FLAG_AUDIO_MODE_IND (1 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 232#define EFFECT_FLAG_AUDIO_MODE_NONE (0 << EFFECT_FLAG_AUDIO_MODE_SHIFT) 233 234// Audio source indication 235#define EFFECT_FLAG_AUDIO_SOURCE_SHIFT (EFFECT_FLAG_AUDIO_MODE_SHIFT + EFFECT_FLAG_AUDIO_MODE_SIZE) 236#define EFFECT_FLAG_AUDIO_SOURCE_SIZE 2 237#define EFFECT_FLAG_AUDIO_SOURCE_MASK (((1 << EFFECT_FLAG_AUDIO_SOURCE_SIZE) -1) \ 238 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT) 239#define EFFECT_FLAG_AUDIO_SOURCE_IND (1 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT) 240#define EFFECT_FLAG_AUDIO_SOURCE_NONE (0 << EFFECT_FLAG_AUDIO_SOURCE_SHIFT) 241 242// Effect offload indication 243#define EFFECT_FLAG_OFFLOAD_SHIFT (EFFECT_FLAG_AUDIO_SOURCE_SHIFT + \ 244 EFFECT_FLAG_AUDIO_SOURCE_SIZE) 245#define EFFECT_FLAG_OFFLOAD_SIZE 1 246#define EFFECT_FLAG_OFFLOAD_MASK (((1 << EFFECT_FLAG_OFFLOAD_SIZE) -1) \ 247 << EFFECT_FLAG_OFFLOAD_SHIFT) 248#define EFFECT_FLAG_OFFLOAD_SUPPORTED (1 << EFFECT_FLAG_OFFLOAD_SHIFT) 249 250// Effect has no process indication 251#define EFFECT_FLAG_NO_PROCESS_SHIFT (EFFECT_FLAG_OFFLOAD_SHIFT + \ 252 EFFECT_FLAG_OFFLOAD_SIZE) 253#define EFFECT_FLAG_NO_PROCESS_SIZE 1 254#define EFFECT_FLAG_NO_PROCESS_MASK (((1 << EFFECT_FLAG_NO_PROCESS_SIZE) -1) \ 255 << EFFECT_FLAG_NO_PROCESS_SHIFT) 256#define EFFECT_FLAG_NO_PROCESS (1 << EFFECT_FLAG_NO_PROCESS_SHIFT) 257 258#define EFFECT_MAKE_API_VERSION(M, m) (((M)<<16) | ((m) & 0xFFFF)) 259#define EFFECT_API_VERSION_MAJOR(v) ((v)>>16) 260#define EFFECT_API_VERSION_MINOR(v) ((m) & 0xFFFF) 261 262 263 264///////////////////////////////////////////////// 265// Effect control interface 266///////////////////////////////////////////////// 267 268// Effect control interface version 2.0 269#define EFFECT_CONTROL_API_VERSION EFFECT_MAKE_API_VERSION(2,0) 270 271// Effect control interface structure: effect_interface_s 272// The effect control interface is exposed by each effect engine implementation. It consists of 273// a set of functions controlling the configuration, activation and process of the engine. 274// The functions are grouped in a structure of type effect_interface_s. 275// 276// Effect control interface handle: effect_handle_t 277// The effect_handle_t serves two purposes regarding the implementation of the effect engine: 278// - 1 it is the address of a pointer to an effect_interface_s structure where the functions 279// of the effect control API for a particular effect are located. 280// - 2 it is the address of the context of a particular effect instance. 281// A typical implementation in the effect library would define a structure as follows: 282// struct effect_module_s { 283// const struct effect_interface_s *itfe; 284// effect_config_t config; 285// effect_context_t context; 286// } 287// The implementation of EffectCreate() function would then allocate a structure of this 288// type and return its address as effect_handle_t 289typedef struct effect_interface_s **effect_handle_t; 290 291 292// Forward definition of type audio_buffer_t 293typedef struct audio_buffer_s audio_buffer_t; 294 295 296 297 298 299 300// Effect control interface definition 301struct effect_interface_s { 302 //////////////////////////////////////////////////////////////////////////////// 303 // 304 // Function: process 305 // 306 // Description: Effect process function. Takes input samples as specified 307 // (count and location) in input buffer descriptor and output processed 308 // samples as specified in output buffer descriptor. If the buffer descriptor 309 // is not specified the function must use either the buffer or the 310 // buffer provider function installed by the EFFECT_CMD_SET_CONFIG command. 311 // The effect framework will call the process() function after the EFFECT_CMD_ENABLE 312 // command is received and until the EFFECT_CMD_DISABLE is received. When the engine 313 // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully 314 // and when done indicate that it is OK to stop calling the process() function by 315 // returning the -ENODATA status. 316 // 317 // NOTE: the process() function implementation should be "real-time safe" that is 318 // it should not perform blocking calls: malloc/free, sleep, read/write/open/close, 319 // pthread_cond_wait/pthread_mutex_lock... 320 // 321 // Input: 322 // self: handle to the effect interface this function 323 // is called on. 324 // inBuffer: buffer descriptor indicating where to read samples to process. 325 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command. 326 // 327 // outBuffer: buffer descriptor indicating where to write processed samples. 328 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG command. 329 // 330 // Output: 331 // returned value: 0 successful operation 332 // -ENODATA the engine has finished the disable phase and the framework 333 // can stop calling process() 334 // -EINVAL invalid interface handle or 335 // invalid input/output buffer description 336 //////////////////////////////////////////////////////////////////////////////// 337 int32_t (*process)(effect_handle_t self, 338 audio_buffer_t *inBuffer, 339 audio_buffer_t *outBuffer); 340 //////////////////////////////////////////////////////////////////////////////// 341 // 342 // Function: command 343 // 344 // Description: Send a command and receive a response to/from effect engine. 345 // 346 // Input: 347 // self: handle to the effect interface this function 348 // is called on. 349 // cmdCode: command code: the command can be a standardized command defined in 350 // effect_command_e (see below) or a proprietary command. 351 // cmdSize: size of command in bytes 352 // pCmdData: pointer to command data 353 // pReplyData: pointer to reply data 354 // 355 // Input/Output: 356 // replySize: maximum size of reply data as input 357 // actual size of reply data as output 358 // 359 // Output: 360 // returned value: 0 successful operation 361 // -EINVAL invalid interface handle or 362 // invalid command/reply size or format according to 363 // command code 364 // The return code should be restricted to indicate problems related to this API 365 // specification. Status related to the execution of a particular command should be 366 // indicated as part of the reply field. 367 // 368 // *pReplyData updated with command response 369 // 370 //////////////////////////////////////////////////////////////////////////////// 371 int32_t (*command)(effect_handle_t self, 372 uint32_t cmdCode, 373 uint32_t cmdSize, 374 void *pCmdData, 375 uint32_t *replySize, 376 void *pReplyData); 377 //////////////////////////////////////////////////////////////////////////////// 378 // 379 // Function: get_descriptor 380 // 381 // Description: Returns the effect descriptor 382 // 383 // Input: 384 // self: handle to the effect interface this function 385 // is called on. 386 // 387 // Input/Output: 388 // pDescriptor: address where to return the effect descriptor. 389 // 390 // Output: 391 // returned value: 0 successful operation. 392 // -EINVAL invalid interface handle or invalid pDescriptor 393 // *pDescriptor: updated with the effect descriptor. 394 // 395 //////////////////////////////////////////////////////////////////////////////// 396 int32_t (*get_descriptor)(effect_handle_t self, 397 effect_descriptor_t *pDescriptor); 398 //////////////////////////////////////////////////////////////////////////////// 399 // 400 // Function: process_reverse 401 // 402 // Description: Process reverse stream function. This function is used to pass 403 // a reference stream to the effect engine. If the engine does not need a reference 404 // stream, this function pointer can be set to NULL. 405 // This function would typically implemented by an Echo Canceler. 406 // 407 // Input: 408 // self: handle to the effect interface this function 409 // is called on. 410 // inBuffer: buffer descriptor indicating where to read samples to process. 411 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command. 412 // 413 // outBuffer: buffer descriptor indicating where to write processed samples. 414 // If NULL, use the configuration passed by EFFECT_CMD_SET_CONFIG_REVERSE command. 415 // If the buffer and buffer provider in the configuration received by 416 // EFFECT_CMD_SET_CONFIG_REVERSE are also NULL, do not return modified reverse 417 // stream data 418 // 419 // Output: 420 // returned value: 0 successful operation 421 // -ENODATA the engine has finished the disable phase and the framework 422 // can stop calling process_reverse() 423 // -EINVAL invalid interface handle or 424 // invalid input/output buffer description 425 //////////////////////////////////////////////////////////////////////////////// 426 int32_t (*process_reverse)(effect_handle_t self, 427 audio_buffer_t *inBuffer, 428 audio_buffer_t *outBuffer); 429}; 430 431 432// 433//--- Standardized command codes for command() function 434// 435enum effect_command_e { 436 EFFECT_CMD_INIT, // initialize effect engine 437 EFFECT_CMD_SET_CONFIG, // configure effect engine (see effect_config_t) 438 EFFECT_CMD_RESET, // reset effect engine 439 EFFECT_CMD_ENABLE, // enable effect process 440 EFFECT_CMD_DISABLE, // disable effect process 441 EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t) 442 EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred 443 EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred 444 EFFECT_CMD_GET_PARAM, // get parameter 445 EFFECT_CMD_SET_DEVICE, // set audio device (see audio.h, audio_devices_t) 446 EFFECT_CMD_SET_VOLUME, // set volume 447 EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) 448 EFFECT_CMD_SET_CONFIG_REVERSE, // configure effect engine reverse stream(see effect_config_t) 449 EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t) 450 EFFECT_CMD_GET_CONFIG, // read effect engine configuration 451 EFFECT_CMD_GET_CONFIG_REVERSE, // read configure effect engine reverse stream configuration 452 EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS,// get all supported configurations for a feature. 453 EFFECT_CMD_GET_FEATURE_CONFIG, // get current feature configuration 454 EFFECT_CMD_SET_FEATURE_CONFIG, // set current feature configuration 455 EFFECT_CMD_SET_AUDIO_SOURCE, // set the audio source (see audio.h, audio_source_t) 456 EFFECT_CMD_OFFLOAD, // set if effect thread is an offload one, 457 // send the ioHandle of the effect thread 458 EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code 459}; 460 461//================================================================================================== 462// command: EFFECT_CMD_INIT 463//-------------------------------------------------------------------------------------------------- 464// description: 465// Initialize effect engine: All configurations return to default 466//-------------------------------------------------------------------------------------------------- 467// command format: 468// size: 0 469// data: N/A 470//-------------------------------------------------------------------------------------------------- 471// reply format: 472// size: sizeof(int) 473// data: status 474//================================================================================================== 475// command: EFFECT_CMD_SET_CONFIG 476//-------------------------------------------------------------------------------------------------- 477// description: 478// Apply new audio parameters configurations for input and output buffers 479//-------------------------------------------------------------------------------------------------- 480// command format: 481// size: sizeof(effect_config_t) 482// data: effect_config_t 483//-------------------------------------------------------------------------------------------------- 484// reply format: 485// size: sizeof(int) 486// data: status 487//================================================================================================== 488// command: EFFECT_CMD_RESET 489//-------------------------------------------------------------------------------------------------- 490// description: 491// Reset the effect engine. Keep configuration but resets state and buffer content 492//-------------------------------------------------------------------------------------------------- 493// command format: 494// size: 0 495// data: N/A 496//-------------------------------------------------------------------------------------------------- 497// reply format: 498// size: 0 499// data: N/A 500//================================================================================================== 501// command: EFFECT_CMD_ENABLE 502//-------------------------------------------------------------------------------------------------- 503// description: 504// Enable the process. Called by the framework before the first call to process() 505//-------------------------------------------------------------------------------------------------- 506// command format: 507// size: 0 508// data: N/A 509//-------------------------------------------------------------------------------------------------- 510// reply format: 511// size: sizeof(int) 512// data: status 513//================================================================================================== 514// command: EFFECT_CMD_DISABLE 515//-------------------------------------------------------------------------------------------------- 516// description: 517// Disable the process. Called by the framework after the last call to process() 518//-------------------------------------------------------------------------------------------------- 519// command format: 520// size: 0 521// data: N/A 522//-------------------------------------------------------------------------------------------------- 523// reply format: 524// size: sizeof(int) 525// data: status 526//================================================================================================== 527// command: EFFECT_CMD_SET_PARAM 528//-------------------------------------------------------------------------------------------------- 529// description: 530// Set a parameter and apply it immediately 531//-------------------------------------------------------------------------------------------------- 532// command format: 533// size: sizeof(effect_param_t) + size of param and value 534// data: effect_param_t + param + value. See effect_param_t definition below for value offset 535//-------------------------------------------------------------------------------------------------- 536// reply format: 537// size: sizeof(int) 538// data: status 539//================================================================================================== 540// command: EFFECT_CMD_SET_PARAM_DEFERRED 541//-------------------------------------------------------------------------------------------------- 542// description: 543// Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command 544//-------------------------------------------------------------------------------------------------- 545// command format: 546// size: sizeof(effect_param_t) + size of param and value 547// data: effect_param_t + param + value. See effect_param_t definition below for value offset 548//-------------------------------------------------------------------------------------------------- 549// reply format: 550// size: 0 551// data: N/A 552//================================================================================================== 553// command: EFFECT_CMD_SET_PARAM_COMMIT 554//-------------------------------------------------------------------------------------------------- 555// description: 556// Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands 557//-------------------------------------------------------------------------------------------------- 558// command format: 559// size: 0 560// data: N/A 561//-------------------------------------------------------------------------------------------------- 562// reply format: 563// size: sizeof(int) 564// data: status 565//================================================================================================== 566// command: EFFECT_CMD_GET_PARAM 567//-------------------------------------------------------------------------------------------------- 568// description: 569// Get a parameter value 570//-------------------------------------------------------------------------------------------------- 571// command format: 572// size: sizeof(effect_param_t) + size of param 573// data: effect_param_t + param 574//-------------------------------------------------------------------------------------------------- 575// reply format: 576// size: sizeof(effect_param_t) + size of param and value 577// data: effect_param_t + param + value. See effect_param_t definition below for value offset 578//================================================================================================== 579// command: EFFECT_CMD_SET_DEVICE 580//-------------------------------------------------------------------------------------------------- 581// description: 582// Set the rendering device the audio output path is connected to. See audio.h, audio_devices_t 583// for device values. 584// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 585// command when the device changes 586//-------------------------------------------------------------------------------------------------- 587// command format: 588// size: sizeof(uint32_t) 589// data: uint32_t 590//-------------------------------------------------------------------------------------------------- 591// reply format: 592// size: 0 593// data: N/A 594//================================================================================================== 595// command: EFFECT_CMD_SET_VOLUME 596//-------------------------------------------------------------------------------------------------- 597// description: 598// Set and get volume. Used by audio framework to delegate volume control to effect engine. 599// The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in 600// its descriptor to receive this command before every call to process() function 601// If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return 602// the volume that should be applied before the effect is processed. The overall volume (the volume 603// actually applied by the effect engine multiplied by the returned value) should match the value 604// indicated in the command. 605//-------------------------------------------------------------------------------------------------- 606// command format: 607// size: n * sizeof(uint32_t) 608// data: volume for each channel defined in effect_config_t for output buffer expressed in 609// 8.24 fixed point format 610//-------------------------------------------------------------------------------------------------- 611// reply format: 612// size: n * sizeof(uint32_t) / 0 613// data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor: 614// volume for each channel defined in effect_config_t for output buffer expressed in 615// 8.24 fixed point format 616// - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor: 617// N/A 618// It is legal to receive a null pointer as pReplyData in which case the effect framework has 619// delegated volume control to another effect 620//================================================================================================== 621// command: EFFECT_CMD_SET_AUDIO_MODE 622//-------------------------------------------------------------------------------------------------- 623// description: 624// Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its 625// descriptor to receive this command when the audio mode changes. 626//-------------------------------------------------------------------------------------------------- 627// command format: 628// size: sizeof(uint32_t) 629// data: audio_mode_t 630//-------------------------------------------------------------------------------------------------- 631// reply format: 632// size: 0 633// data: N/A 634//================================================================================================== 635// command: EFFECT_CMD_SET_CONFIG_REVERSE 636//-------------------------------------------------------------------------------------------------- 637// description: 638// Apply new audio parameters configurations for input and output buffers of reverse stream. 639// An example of reverse stream is the echo reference supplied to an Acoustic Echo Canceler. 640//-------------------------------------------------------------------------------------------------- 641// command format: 642// size: sizeof(effect_config_t) 643// data: effect_config_t 644//-------------------------------------------------------------------------------------------------- 645// reply format: 646// size: sizeof(int) 647// data: status 648//================================================================================================== 649// command: EFFECT_CMD_SET_INPUT_DEVICE 650//-------------------------------------------------------------------------------------------------- 651// description: 652// Set the capture device the audio input path is connected to. See audio.h, audio_devices_t 653// for device values. 654// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this 655// command when the device changes 656//-------------------------------------------------------------------------------------------------- 657// command format: 658// size: sizeof(uint32_t) 659// data: uint32_t 660//-------------------------------------------------------------------------------------------------- 661// reply format: 662// size: 0 663// data: N/A 664//================================================================================================== 665// command: EFFECT_CMD_GET_CONFIG 666//-------------------------------------------------------------------------------------------------- 667// description: 668// Read audio parameters configurations for input and output buffers 669//-------------------------------------------------------------------------------------------------- 670// command format: 671// size: 0 672// data: N/A 673//-------------------------------------------------------------------------------------------------- 674// reply format: 675// size: sizeof(effect_config_t) 676// data: effect_config_t 677//================================================================================================== 678// command: EFFECT_CMD_GET_CONFIG_REVERSE 679//-------------------------------------------------------------------------------------------------- 680// description: 681// Read audio parameters configurations for input and output buffers of reverse stream 682//-------------------------------------------------------------------------------------------------- 683// command format: 684// size: 0 685// data: N/A 686//-------------------------------------------------------------------------------------------------- 687// reply format: 688// size: sizeof(effect_config_t) 689// data: effect_config_t 690//================================================================================================== 691// command: EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS 692//-------------------------------------------------------------------------------------------------- 693// description: 694// Queries for supported configurations for a particular feature (e.g. get the supported 695// combinations of main and auxiliary channels for a noise suppressor). 696// The command parameter is the feature identifier (See effect_feature_e for a list of defined 697// features) followed by the maximum number of configuration descriptor to return. 698// The reply is composed of: 699// - status (uint32_t): 700// - 0 if feature is supported 701// - -ENOSYS if the feature is not supported, 702// - -ENOMEM if the feature is supported but the total number of supported configurations 703// exceeds the maximum number indicated by the caller. 704// - total number of supported configurations (uint32_t) 705// - an array of configuration descriptors. 706// The actual number of descriptors returned must not exceed the maximum number indicated by 707// the caller. 708//-------------------------------------------------------------------------------------------------- 709// command format: 710// size: 2 x sizeof(uint32_t) 711// data: effect_feature_e + maximum number of configurations to return 712//-------------------------------------------------------------------------------------------------- 713// reply format: 714// size: 2 x sizeof(uint32_t) + n x sizeof (<config descriptor>) 715// data: status + total number of configurations supported + array of n config descriptors 716//================================================================================================== 717// command: EFFECT_CMD_GET_FEATURE_CONFIG 718//-------------------------------------------------------------------------------------------------- 719// description: 720// Retrieves current configuration for a given feature. 721// The reply status is: 722// - 0 if feature is supported 723// - -ENOSYS if the feature is not supported, 724//-------------------------------------------------------------------------------------------------- 725// command format: 726// size: sizeof(uint32_t) 727// data: effect_feature_e 728//-------------------------------------------------------------------------------------------------- 729// reply format: 730// size: sizeof(uint32_t) + sizeof (<config descriptor>) 731// data: status + config descriptor 732//================================================================================================== 733// command: EFFECT_CMD_SET_FEATURE_CONFIG 734//-------------------------------------------------------------------------------------------------- 735// description: 736// Sets current configuration for a given feature. 737// The reply status is: 738// - 0 if feature is supported 739// - -ENOSYS if the feature is not supported, 740// - -EINVAL if the configuration is invalid 741//-------------------------------------------------------------------------------------------------- 742// command format: 743// size: sizeof(uint32_t) + sizeof (<config descriptor>) 744// data: effect_feature_e + config descriptor 745//-------------------------------------------------------------------------------------------------- 746// reply format: 747// size: sizeof(uint32_t) 748// data: status 749//================================================================================================== 750// command: EFFECT_CMD_SET_AUDIO_SOURCE 751//-------------------------------------------------------------------------------------------------- 752// description: 753// Set the audio source the capture path is configured for (Camcorder, voice recognition...). 754// See audio.h, audio_source_t for values. 755//-------------------------------------------------------------------------------------------------- 756// command format: 757// size: sizeof(uint32_t) 758// data: uint32_t 759//-------------------------------------------------------------------------------------------------- 760// reply format: 761// size: 0 762// data: N/A 763//================================================================================================== 764// command: EFFECT_CMD_OFFLOAD 765//-------------------------------------------------------------------------------------------------- 766// description: 767// 1.indicate if the playback thread the effect is attached to is offloaded or not 768// 2.update the io handle of the playback thread the effect is attached to 769//-------------------------------------------------------------------------------------------------- 770// command format: 771// size: sizeof(effect_offload_param_t) 772// data: effect_offload_param_t 773//-------------------------------------------------------------------------------------------------- 774// reply format: 775// size: sizeof(uint32_t) 776// data: uint32_t 777//-------------------------------------------------------------------------------------------------- 778// command: EFFECT_CMD_FIRST_PROPRIETARY 779//-------------------------------------------------------------------------------------------------- 780// description: 781// All proprietary effect commands must use command codes above this value. The size and format of 782// command and response fields is free in this case 783//================================================================================================== 784 785 786// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t 787// structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with 788// regard to the channel mask definition in audio.h, audio_channel_mask_t e.g : 789// Stereo: left, right 790// 5 point 1: front left, front right, front center, low frequency, back left, back right 791// The buffer size is expressed in frame count, a frame being composed of samples for all 792// channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by 793// definition 794struct audio_buffer_s { 795 size_t frameCount; // number of frames in buffer 796 union { 797 void* raw; // raw pointer to start of buffer 798 int32_t* s32; // pointer to signed 32 bit data at start of buffer 799 int16_t* s16; // pointer to signed 16 bit data at start of buffer 800 uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer 801 }; 802}; 803 804// The buffer_provider_s structure contains functions that can be used 805// by the effect engine process() function to query and release input 806// or output audio buffer. 807// The getBuffer() function is called to retrieve a buffer where data 808// should read from or written to by process() function. 809// The releaseBuffer() function MUST be called when the buffer retrieved 810// with getBuffer() is not needed anymore. 811// The process function should use the buffer provider mechanism to retrieve 812// input or output buffer if the inBuffer or outBuffer passed as argument is NULL 813// and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_SET_CONFIG 814// command did not specify an audio buffer. 815 816typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer); 817 818typedef struct buffer_provider_s { 819 buffer_function_t getBuffer; // retrieve next buffer 820 buffer_function_t releaseBuffer; // release used buffer 821 void *cookie; // for use by client of buffer provider functions 822} buffer_provider_t; 823 824 825// The buffer_config_s structure specifies the input or output audio format 826// to be used by the effect engine. It is part of the effect_config_t 827// structure that defines both input and output buffer configurations and is 828// passed by the EFFECT_CMD_SET_CONFIG or EFFECT_CMD_SET_CONFIG_REVERSE command. 829typedef struct buffer_config_s { 830 audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly 831 uint32_t samplingRate; // sampling rate 832 uint32_t channels; // channel mask (see audio_channel_mask_t in audio.h) 833 buffer_provider_t bufferProvider; // buffer provider 834 uint8_t format; // Audio format (see audio_format_t in audio.h) 835 uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) 836 uint16_t mask; // indicates which of the above fields is valid 837} buffer_config_t; 838 839// Values for "accessMode" field of buffer_config_t: 840// overwrite, read only, accumulate (read/modify/write) 841enum effect_buffer_access_e { 842 EFFECT_BUFFER_ACCESS_WRITE, 843 EFFECT_BUFFER_ACCESS_READ, 844 EFFECT_BUFFER_ACCESS_ACCUMULATE 845 846}; 847 848// feature identifiers for EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS command 849enum effect_feature_e { 850 EFFECT_FEATURE_AUX_CHANNELS, // supports auxiliary channels (e.g. dual mic noise suppressor) 851 EFFECT_FEATURE_CNT 852}; 853 854// EFFECT_FEATURE_AUX_CHANNELS feature configuration descriptor. Describe a combination 855// of main and auxiliary channels supported 856typedef struct channel_config_s { 857 audio_channel_mask_t main_channels; // channel mask for main channels 858 audio_channel_mask_t aux_channels; // channel mask for auxiliary channels 859} channel_config_t; 860 861 862// Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field 863// in buffer_config_t must be taken into account when executing the EFFECT_CMD_SET_CONFIG command 864#define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account 865#define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account 866#define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account 867#define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account 868#define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account 869#define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account 870#define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \ 871 EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \ 872 EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER) 873 874 875// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_CONFIG 876// command to configure audio parameters and buffers for effect engine input and output. 877typedef struct effect_config_s { 878 buffer_config_t inputCfg; 879 buffer_config_t outputCfg; 880} effect_config_t; 881 882 883// effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM 884// command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command. 885// psize and vsize represent the actual size of parameter and value. 886// 887// NOTE: the start of value field inside the data field is always on a 32 bit boundary: 888// 889// +-----------+ 890// | status | sizeof(int) 891// +-----------+ 892// | psize | sizeof(int) 893// +-----------+ 894// | vsize | sizeof(int) 895// +-----------+ 896// | | | | 897// ~ parameter ~ > psize | 898// | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int) 899// +-----------+ | 900// | padding | | 901// +-----------+ 902// | | | 903// ~ value ~ > vsize 904// | | | 905// +-----------+ 906 907typedef struct effect_param_s { 908 int32_t status; // Transaction status (unused for command, used for reply) 909 uint32_t psize; // Parameter size 910 uint32_t vsize; // Value size 911 char data[]; // Start of Parameter + Value data 912} effect_param_t; 913 914// Maximum effect_param_t size 915#define EFFECT_PARAM_SIZE_MAX 65536 916 917// structure used by EFFECT_CMD_OFFLOAD command 918typedef struct effect_offload_param_s { 919 bool isOffload; // true if the playback thread the effect is attached to is offloaded 920 int ioHandle; // io handle of the playback thread the effect is attached to 921} effect_offload_param_t; 922 923 924///////////////////////////////////////////////// 925// Effect library interface 926///////////////////////////////////////////////// 927 928// Effect library interface version 3.0 929// Note that EffectsFactory.c only checks the major version component, so changes to the minor 930// number can only be used for fully backwards compatible changes 931#define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(3,0) 932 933#define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T')) 934 935// Every effect library must have a data structure named AUDIO_EFFECT_LIBRARY_INFO_SYM 936// and the fields of this data structure must begin with audio_effect_library_t 937 938typedef struct audio_effect_library_s { 939 // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG 940 uint32_t tag; 941 // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor 942 uint32_t version; 943 // Name of this library 944 const char *name; 945 // Author/owner/implementor of the library 946 const char *implementor; 947 948 //////////////////////////////////////////////////////////////////////////////// 949 // 950 // Function: create_effect 951 // 952 // Description: Creates an effect engine of the specified implementation uuid and 953 // returns an effect control interface on this engine. The function will allocate the 954 // resources for an instance of the requested effect engine and return 955 // a handle on the effect control interface. 956 // 957 // Input: 958 // uuid: pointer to the effect uuid. 959 // sessionId: audio session to which this effect instance will be attached. 960 // All effects created with the same session ID are connected in series and process 961 // the same signal stream. Knowing that two effects are part of the same effect 962 // chain can help the library implement some kind of optimizations. 963 // ioId: identifies the output or input stream this effect is directed to in 964 // audio HAL. 965 // For future use especially with tunneled HW accelerated effects 966 // 967 // Input/Output: 968 // pHandle: address where to return the effect interface handle. 969 // 970 // Output: 971 // returned value: 0 successful operation. 972 // -ENODEV library failed to initialize 973 // -EINVAL invalid pEffectUuid or pHandle 974 // -ENOENT no effect with this uuid found 975 // *pHandle: updated with the effect interface handle. 976 // 977 //////////////////////////////////////////////////////////////////////////////// 978 int32_t (*create_effect)(const effect_uuid_t *uuid, 979 int32_t sessionId, 980 int32_t ioId, 981 effect_handle_t *pHandle); 982 983 //////////////////////////////////////////////////////////////////////////////// 984 // 985 // Function: release_effect 986 // 987 // Description: Releases the effect engine whose handle is given as argument. 988 // All resources allocated to this particular instance of the effect are 989 // released. 990 // 991 // Input: 992 // handle: handle on the effect interface to be released. 993 // 994 // Output: 995 // returned value: 0 successful operation. 996 // -ENODEV library failed to initialize 997 // -EINVAL invalid interface handle 998 // 999 //////////////////////////////////////////////////////////////////////////////// 1000 int32_t (*release_effect)(effect_handle_t handle); 1001 1002 //////////////////////////////////////////////////////////////////////////////// 1003 // 1004 // Function: get_descriptor 1005 // 1006 // Description: Returns the descriptor of the effect engine which implementation UUID is 1007 // given as argument. 1008 // 1009 // Input/Output: 1010 // uuid: pointer to the effect uuid. 1011 // pDescriptor: address where to return the effect descriptor. 1012 // 1013 // Output: 1014 // returned value: 0 successful operation. 1015 // -ENODEV library failed to initialize 1016 // -EINVAL invalid pDescriptor or uuid 1017 // *pDescriptor: updated with the effect descriptor. 1018 // 1019 //////////////////////////////////////////////////////////////////////////////// 1020 int32_t (*get_descriptor)(const effect_uuid_t *uuid, 1021 effect_descriptor_t *pDescriptor); 1022} audio_effect_library_t; 1023 1024// Name of the hal_module_info 1025#define AUDIO_EFFECT_LIBRARY_INFO_SYM AELI 1026 1027// Name of the hal_module_info as a string 1028#define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI" 1029 1030__END_DECLS 1031 1032#endif // ANDROID_AUDIO_EFFECT_H 1033