diff options
21 files changed, 908 insertions, 498 deletions
diff --git a/include/media/AudioCommon.h b/include/media/AudioCommon.h deleted file mode 100644 index 245d7606557b..000000000000 --- a/include/media/AudioCommon.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_AUDIOCOMMON_H_ -#define ANDROID_AUDIOCOMMON_H_ - -#if __cplusplus -extern "C" { -#endif - -///////////////////////////////////////////////// -// Common definitions for PCM audio -///////////////////////////////////////////////// - - -// PCM Sample format -enum audio_format_e { - PCM_FORMAT_S15 = 1, // PCM signed 16 bits, must be 1 for backward compatibility - PCM_FORMAT_U8 = 2, // PCM unsigned 8 bits, must be 2 for backward compatibility - PCM_FORMAT_S7_24 // signed 7.24 fixed point representation -}; - -// Channel mask definitions -enum audio_channels_e { - CHANNEL_FRONT_LEFT = 0x4, // front left channel - CHANNEL_FRONT_RIGHT = 0x8, // front right channel - CHANNEL_FRONT_CENTER = 0x10, // front center channel - CHANNEL_LOW_FREQUENCY = 0x20, // low frequency channel - CHANNEL_BACK_LEFT = 0x40, // back left channel - CHANNEL_BACK_RIGHT = 0x80, // back right channel - CHANNEL_FRONT_LEFT_OF_CENTER = 0x100, // front left of center channel - CHANNEL_FRONT_RIGHT_OF_CENTER = 0x200, // front right of center channel - CHANNEL_BACK_CENTER = 0x400, // back center channel - CHANNEL_MONO = CHANNEL_FRONT_LEFT, - CHANNEL_STEREO = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT), - CHANNEL_QUAD = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | - CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), - CHANNEL_SURROUND = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | - CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER), - CHANNEL_5POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | - CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), - CHANNEL_7POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | - CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | - CHANNEL_FRONT_LEFT_OF_CENTER | CHANNEL_FRONT_RIGHT_OF_CENTER), -}; - -// Render device definitions -enum audio_device_e { - DEVICE_EARPIECE = 0x1, // earpiece - DEVICE_SPEAKER = 0x2, // speaker - DEVICE_WIRED_HEADSET = 0x4, // wired headset, with microphone - DEVICE_WIRED_HEADPHONE = 0x8, // wired headphone, without microphone - DEVICE_BLUETOOTH_SCO = 0x10, // generic bluetooth SCO - DEVICE_BLUETOOTH_SCO_HEADSET = 0x20, // bluetooth SCO headset - DEVICE_BLUETOOTH_SCO_CARKIT = 0x40, // bluetooth SCO car kit - DEVICE_BLUETOOTH_A2DP = 0x80, // generic bluetooth A2DP - DEVICE_BLUETOOTH_A2DP_HEADPHONES = 0x100, // bluetooth A2DP headphones - DEVICE_BLUETOOTH_A2DP_SPEAKER = 0x200, // bluetooth A2DP speakers - DEVICE_AUX_DIGITAL = 0x400 // digital output -}; - -#if __cplusplus -} // extern "C" -#endif - - -#endif /*ANDROID_AUDIOCOMMON_H_*/ diff --git a/include/media/AudioEffect.h b/include/media/AudioEffect.h index 2bdba2d3627e..66670f3942d3 100644 --- a/include/media/AudioEffect.h +++ b/include/media/AudioEffect.h @@ -93,14 +93,14 @@ public: /* * Returns the number of effects available. This method together - * with EffectQueryNext() is used to enumerate all effects: + * with queryEffect() is used to enumerate all effects: * The enumeration sequence is: - * QueryNumberEffects(&num_effects); - * while (num_effects--) - * QueryNextEffect(); + * queryNumberEffects(&num_effects); + * for (i = 0; i < num_effects; i++) + * queryEffect(i,...); * * Parameters: - * pNumEffects: address where the number of effects should be returned. + * numEffects: address where the number of effects should be returned. * * Returned status (from utils/Errors.h) can be: * NO_ERROR successful operation. @@ -114,24 +114,24 @@ public: static status_t queryNumberEffects(uint32_t *numEffects); /* - * Returns number effect descriptor during effect + * Returns an effect descriptor during effect * enumeration. * * Parameters: - * pDescriptor: address where the effect descriptor should be returned. + * index: index of the queried effect. + * descriptor: address where the effect descriptor should be returned. * * Returned status (from utils/Errors.h) can be: * NO_ERROR successful operation. - * NAME_NOT_FOUND no more effect available * PERMISSION_DENIED could not get AudioFlinger interface * NO_INIT effect library failed to initialize - * BAD_VALUE invalid descriptor pointer + * BAD_VALUE invalid descriptor pointer or index * INVALID_OPERATION effect list has changed since last execution of queryNumberEffects() * * Returned value * *descriptor: updated with effect descriptor */ - static status_t queryNextEffect(effect_descriptor_t *descriptor); + static status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor); /* diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index f21e83d47dc6..194f23aa5dc8 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -20,7 +20,6 @@ #include <utils/RefBase.h> #include <utils/threads.h> #include <media/IAudioFlinger.h> -#include <media/AudioCommon.h> namespace android { @@ -51,8 +50,8 @@ public: // Audio sub formats (see AudioSystem::audio_format). enum pcm_sub_format { - PCM_SUB_16_BIT = PCM_FORMAT_S15, // must be 1 for backward compatibility - PCM_SUB_8_BIT = PCM_FORMAT_U8, // must be 2 for backward compatibility + PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility + PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility }; // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify @@ -104,21 +103,26 @@ public: // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java enum audio_channels { // output channels - CHANNEL_OUT_FRONT_LEFT = CHANNEL_FRONT_LEFT, - CHANNEL_OUT_FRONT_RIGHT = CHANNEL_FRONT_RIGHT, - CHANNEL_OUT_FRONT_CENTER = CHANNEL_FRONT_CENTER, - CHANNEL_OUT_LOW_FREQUENCY = CHANNEL_LOW_FREQUENCY, - CHANNEL_OUT_BACK_LEFT = CHANNEL_BACK_LEFT, - CHANNEL_OUT_BACK_RIGHT = CHANNEL_BACK_RIGHT, - CHANNEL_OUT_FRONT_LEFT_OF_CENTER = CHANNEL_FRONT_LEFT_OF_CENTER, - CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = CHANNEL_FRONT_RIGHT_OF_CENTER, - CHANNEL_OUT_BACK_CENTER = CHANNEL_BACK_CENTER, - CHANNEL_OUT_MONO = CHANNEL_MONO, - CHANNEL_OUT_STEREO = CHANNEL_STEREO, - CHANNEL_OUT_QUAD = CHANNEL_QUAD, - CHANNEL_OUT_SURROUND = CHANNEL_SURROUND, - CHANNEL_OUT_5POINT1 = CHANNEL_5POINT1, - CHANNEL_OUT_7POINT1 = CHANNEL_7POINT1, + CHANNEL_OUT_FRONT_LEFT = 0x4, + CHANNEL_OUT_FRONT_RIGHT = 0x8, + CHANNEL_OUT_FRONT_CENTER = 0x10, + CHANNEL_OUT_LOW_FREQUENCY = 0x20, + CHANNEL_OUT_BACK_LEFT = 0x40, + CHANNEL_OUT_BACK_RIGHT = 0x80, + CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100, + CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200, + CHANNEL_OUT_BACK_CENTER = 0x400, + CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT, + CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT), + CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | + CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT), + CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | + CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER), + CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | + CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT), + CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | + CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | + CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER), CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER), @@ -238,17 +242,17 @@ public: enum audio_devices { // output devices - DEVICE_OUT_EARPIECE = DEVICE_EARPIECE, - DEVICE_OUT_SPEAKER = DEVICE_SPEAKER, - DEVICE_OUT_WIRED_HEADSET = DEVICE_WIRED_HEADSET, - DEVICE_OUT_WIRED_HEADPHONE = DEVICE_WIRED_HEADPHONE, - DEVICE_OUT_BLUETOOTH_SCO = DEVICE_BLUETOOTH_SCO, - DEVICE_OUT_BLUETOOTH_SCO_HEADSET = DEVICE_BLUETOOTH_SCO_HEADSET, - DEVICE_OUT_BLUETOOTH_SCO_CARKIT = DEVICE_BLUETOOTH_SCO_CARKIT, - DEVICE_OUT_BLUETOOTH_A2DP = DEVICE_BLUETOOTH_A2DP, - DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = DEVICE_BLUETOOTH_A2DP_HEADPHONES, - DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = DEVICE_BLUETOOTH_A2DP_SPEAKER, - DEVICE_OUT_AUX_DIGITAL = DEVICE_AUX_DIGITAL, + DEVICE_OUT_EARPIECE = 0x1, + DEVICE_OUT_SPEAKER = 0x2, + DEVICE_OUT_WIRED_HEADSET = 0x4, + DEVICE_OUT_WIRED_HEADPHONE = 0x8, + DEVICE_OUT_BLUETOOTH_SCO = 0x10, + DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, + DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, + DEVICE_OUT_BLUETOOTH_A2DP = 0x80, + DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, + DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, + DEVICE_OUT_AUX_DIGITAL = 0x400, DEVICE_OUT_DEFAULT = 0x8000, DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET | DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET | diff --git a/include/media/EffectApi.h b/include/media/EffectApi.h index 97874f775a82..b4d738cc9c46 100644 --- a/include/media/EffectApi.h +++ b/include/media/EffectApi.h @@ -20,7 +20,6 @@ #include <errno.h> #include <stdint.h> #include <sys/types.h> -#include <media/AudioCommon.h> #if __cplusplus extern "C" { @@ -65,10 +64,11 @@ typedef struct effect_interface_s **effect_interface_t; //--- Effect descriptor structure effect_descriptor_t // -// Unique effect ID (can be generated from the following site: http://www.itu.int/ITU-T/asn1/uuid.html) +// Unique effect ID (can be generated from the following site: +// http://www.itu.int/ITU-T/asn1/uuid.html) // This format is used for both "type" and "uuid" fields of the effect descriptor structure. -// - When used for effect type and the engine is implementing and effect corresponding to a standard OpenSL ES -// interface, this ID must be the one defined in OpenSLES_IID.h for that interface. +// - When used for effect type and the engine is implementing and effect corresponding to a standard +// OpenSL ES interface, this ID must be the one defined in OpenSLES_IID.h for that interface. // - When used as uuid, it should be a unique UUID for this particular implementation. typedef struct effect_uuid_s { uint32_t timeLow; @@ -79,23 +79,32 @@ typedef struct effect_uuid_s { } effect_uuid_t; // NULL UUID definition (matches SL_IID_NULL_) -#define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } +#define EFFECT_UUID_INITIALIZER { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, \ + { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } } static const effect_uuid_t EFFECT_UUID_NULL_ = EFFECT_UUID_INITIALIZER; const effect_uuid_t * const EFFECT_UUID_NULL = &EFFECT_UUID_NULL_; const char * const EFFECT_UUID_NULL_STR = "ec7178ec-e5e1-4432-a3f4-4657e6795210"; -// the effect descriptor contains necessary information to facilitate the enumeration of the effect +// The effect descriptor contains necessary information to facilitate the enumeration of the effect // engines present in a library. typedef struct effect_descriptor_s { - effect_uuid_t type; // UUID corresponding to the OpenSL ES interface implemented by this effect + effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect effect_uuid_t uuid; // UUID for this particular implementation - uint16_t apiVersion; // Version of the effect API implemented: must match current EFFECT_API_VERSION + uint16_t apiVersion; // Version of the effect API implemented: matches EFFECT_API_VERSION uint32_t flags; // effect engine capabilities/requirements flags (see below) - char name[EFFECT_STRING_LEN_MAX] ; // human readable effect name - char implementor[EFFECT_STRING_LEN_MAX] ; // human readable effect implementor name + uint16_t cpuLoad; // CPU load indication (see below) + uint16_t memoryUsage; // Data Memory usage (see below) + char name[EFFECT_STRING_LEN_MAX]; // human readable effect name + char implementor[EFFECT_STRING_LEN_MAX]; // human readable effect implementor name } effect_descriptor_t; -// definitions for flags field of effect descriptor. +// CPU load and memory usage indication: each effect implementation must provide an indication of +// its CPU and memory usage for the audio effect framework to limit the number of effects +// instantiated at a given time on a given platform. +// The CPU load is expressed in 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS. +// The memory usage is expressed in KB and includes only dynamically allocated memory + +// Definitions for flags field of effect descriptor. // +---------------------------+-----------+----------------------------------- // | description | bits | values // +---------------------------+-----------+----------------------------------- @@ -117,7 +126,7 @@ typedef struct effect_descriptor_s { // | | | 2 requires volume indication // | | | 3 reserved // +---------------------------+-----------+----------------------------------- -// | Device management | 7..8 | 0 none +// | Device indication | 7..8 | 0 none // | | | 1 requires device updates // | | | 2..3 reserved // +---------------------------+-----------+----------------------------------- @@ -125,7 +134,8 @@ typedef struct effect_descriptor_s { // | | | command must specify a buffer descriptor // | | | 1 provider: process() function uses the // | | | bufferProvider indicated by the -// | | | EFFECT_CMD_CONFIGURE command to request input buffers. +// | | | EFFECT_CMD_CONFIGURE command to request input. +// | | | buffers. // | | | 2 both: both input modes are supported // | | | 3 reserved // +---------------------------+-----------+----------------------------------- @@ -133,18 +143,34 @@ typedef struct effect_descriptor_s { // | | | command must specify a buffer descriptor // | | | 1 provider: process() function uses the // | | | bufferProvider indicated by the -// | | | EFFECT_CMD_CONFIGURE command to request output buffers. +// | | | EFFECT_CMD_CONFIGURE command to request output +// | | | buffers. // | | | 2 both: both output modes are supported // | | | 3 reserved // +---------------------------+-----------+----------------------------------- +// | Hardware acceleration | 13..15 | 0 No hardware acceleration +// | | | 1 non tunneled hw acceleration: the process() function +// | | | reads the samples, send them to HW accelerated +// | | | effect processor, reads back the processed samples +// | | | and returns them to the output buffer. +// | | | 2 tunneled hw acceleration: the process() function is +// | | | transparent. The effect interface is only used to +// | | | control the effect engine. This mode is relevant for +// | | | global effects actually applied by the audio +// | | | hardware on the output stream. +// +---------------------------+-----------+----------------------------------- +// | Audio Mode indication | 16..17 | 0 none +// | | | 1 requires audio mode updates +// | | | 2..3 reserved +// +---------------------------+-----------+----------------------------------- -// insert mode +// Insert mode #define EFFECT_FLAG_TYPE_MASK 0x00000003 #define EFFECT_FLAG_TYPE_INSERT 0x00000000 #define EFFECT_FLAG_TYPE_AUXILIARY 0x00000001 #define EFFECT_FLAG_TYPE_REPLACE 0x00000002 -// insert preference +// Insert preference #define EFFECT_FLAG_INSERT_MASK 0x0000001C #define EFFECT_FLAG_INSERT_ANY 0x00000000 #define EFFECT_FLAG_INSERT_FIRST 0x00000004 @@ -152,30 +178,40 @@ typedef struct effect_descriptor_s { #define EFFECT_FLAG_INSERT_EXCLUSIVE 0x0000000C -// volume control +// Volume control #define EFFECT_FLAG_VOLUME_MASK 0x00000060 #define EFFECT_FLAG_VOLUME_CTRL 0x00000020 #define EFFECT_FLAG_VOLUME_IND 0x00000040 #define EFFECT_FLAG_VOLUME_NONE 0x00000000 -// device control +// Device indication #define EFFECT_FLAG_DEVICE_MASK 0x00000180 #define EFFECT_FLAG_DEVICE_IND 0x00000080 #define EFFECT_FLAG_DEVICE_NONE 0x00000000 -// sample input modes +// Sample input modes #define EFFECT_FLAG_INPUT_MASK 0x00000600 #define EFFECT_FLAG_INPUT_DIRECT 0x00000000 #define EFFECT_FLAG_INPUT_PROVIDER 0x00000200 #define EFFECT_FLAG_INPUT_BOTH 0x00000400 -// sample output modes +// Sample output modes #define EFFECT_FLAG_OUTPUT_MASK 0x00001800 #define EFFECT_FLAG_OUTPUT_DIRECT 0x00000000 #define EFFECT_FLAG_OUTPUT_PROVIDER 0x00000800 #define EFFECT_FLAG_OUTPUT_BOTH 0x00001000 -// forward definition of type audio_buffer_t +// Hardware acceleration mode +#define EFFECT_FLAG_HW_ACC_MASK 0x00006000 +#define EFFECT_FLAG_HW_ACC_SIMPLE 0x00002000 +#define EFFECT_FLAG_HW_ACC_TUNNEL 0x00004000 + +// Audio mode indication +#define EFFECT_FLAG_AUDIO_MODE_MASK 0x00018000 +#define EFFECT_FLAG_AUDIO_MODE_IND 0x00008000 +#define EFFECT_FLAG_AUDIO_MODE_NONE 0x00000000 + +// Forward definition of type audio_buffer_t typedef struct audio_buffer_s audio_buffer_t; //////////////////////////////////////////////////////////////////////////////// @@ -206,7 +242,9 @@ typedef struct audio_buffer_s audio_buffer_t; // -EINVAL invalid interface handle or // invalid input/output buffer description //////////////////////////////////////////////////////////////////////////////// -typedef int32_t (*effect_process_t)(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer); +typedef int32_t (*effect_process_t)(effect_interface_t self, + audio_buffer_t *inBuffer, + audio_buffer_t *outBuffer); //////////////////////////////////////////////////////////////////////////////// // @@ -238,7 +276,12 @@ typedef int32_t (*effect_process_t)(effect_interface_t self, audio_buffer_t *inB // *pReplyData updated with command response // //////////////////////////////////////////////////////////////////////////////// -typedef int32_t (*effect_command_t)(effect_interface_t self, int32_t cmdCode, int32_t cmdSize, void *pCmdData, int32_t *replySize, void *pReplyData); +typedef int32_t (*effect_command_t)(effect_interface_t self, + int32_t cmdCode, + int32_t cmdSize, + void *pCmdData, + int32_t *replySize, + void *pReplyData); // Effect control interface definition @@ -248,75 +291,9 @@ struct effect_interface_s { }; -//--- Standardized command codes for command function -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | description | command code | command format | reply format -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Initialize effect engine: | EFFECT_CMD_INIT | size: 0 | size: sizeof(int) -// | All configurations return to | | data: N/A | data: status -// | default | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Apply new audio parameters | EFFECT_CMD_CONFIGURE | size: sizeof(effect_config_t) | size: sizeof(int) -// | configurations for input and | | data: effect_config_t | data: status -// | output buffers | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Reset effect engine: keep | EFFECT_CMD_RESET | size: 0 | size: 0 -// | configuration but reset state | | data: N/A | data: N/A -// | and buffer content. | | | -// | Called by the framework before | | | -// | enabling the effect | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Enable the process | EFFECT_CMD_ENABLE | size: 0 | size: sizeof(int) -// | Called by the framework before | | data: N/A | data: status -// | the first call to process() | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Disable the process | EFFECT_CMD_DISABLE | size: 0 | size: sizeof(int) -// | Called by the framework after | | data: N/A | data: status -// | the last call to process() | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Set a parameter and apply it | EFFECT_CMD_SET_PARAM | size: sizeof(effect_param_t) | size: sizeof(int) -// | immediately | | + size of param + value | data: status -// | | | data: effect_param_t | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Set a parameter but apply it | EFFECT_CMD_SET_PARAM_DEFERRED | size: sizeof(effect_param_t) | size: 0 -// | only when receiving command | | + size of param + value | data: N/A -// | EFFECT_CMD_SET_PARAM_COMMIT | | data: effect_param_t | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Apply all previously received | EFFECT_CMD_SET_PARAM_COMMIT | size: 0 | size: sizeof(int) -// | EFFECT_CMD_SET_PARAM_DEFERRED | | data: N/A | data: status -// | commands | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Get a parameter value | EFFECT_CMD_GET_PARAM | size: sizeof(effect_param_t) | size: sizeof(effect_param_t) -// | | | + size of param | + size of param + value -// | | | data: effect_param_t | data: effect_param_t -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Set the rendering device the | EFFECT_CMD_SET_DEVICE | size: sizeof(uint32_t) | size: 0 -// | audio output path is connected | | data: audio_device_e | data: N/A -// | to. See audio_device_e in | | | -// | AudioCommon.h for device values| | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | Set and get volume. Used by | EFFECT_CMD_SET_VOLUME | size: n * sizeof(uint32_t) | size: n * sizeof(uint32_t) -// | audio framework to delegate | | data: volume for each channel | data: volume for each channel -// | volume control to effect engine| | defined in effect_config_t in | defined in effect_config_t in -// | If volume control flag is set | | 8.24 fixed point format | 8.24 fixed point format -// | in the effect descriptor, the | | | It is legal to receive a null -// | effect engine must return the | | | pointer as pReplyData in which -// | volume that should be applied | | | case the effect framework has -// | before the effect is processed | | | delegated volume control to -// | The overall volume (the volume | | | another effect. -// | actually applied by the effect | | | -// | multiplied by the returned | | | -// | value) should match the | | | -// | requested value | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- -// | All proprietary effect commands| EFFECT_CMD_FIRST_PROPRIETARY | | -// | must use command codes above | | | -// | this value. The size and format| | | -// | of command and response fields | | | -// | is free in this case. | | | -// +--------------------------------+-------------------------------+-------------------------------+-------------------------- - - +// +//--- Standardized command codes for command() function +// enum effect_command_e { EFFECT_CMD_INIT, // initialize effect engine EFFECT_CMD_CONFIGURE, // configure effect engine (see effect_config_t) @@ -327,18 +304,202 @@ enum effect_command_e { EFFECT_CMD_SET_PARAM_DEFERRED, // set parameter deferred EFFECT_CMD_SET_PARAM_COMMIT, // commit previous set parameter deferred EFFECT_CMD_GET_PARAM, // get parameter - EFFECT_CMD_SET_DEVICE, // set audio device (see audio_device_e in AudioCommon.h) + EFFECT_CMD_SET_DEVICE, // set audio device (see audio_device_e) EFFECT_CMD_SET_VOLUME, // set volume + EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code }; -// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t structure -// Multi-channel audio is always interleaved. The channel order is from LSB to MSB with regard to the -// channel mask definition in audio_channels_e (AudioCommon.h) e.g : +//================================================================================================== +// command: EFFECT_CMD_INIT +//-------------------------------------------------------------------------------------------------- +// description: +// Initialize effect engine: All configurations return to default +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_CONFIGURE +//-------------------------------------------------------------------------------------------------- +// description: +// Apply new audio parameters configurations for input and output buffers +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_config_t) +// data: effect_config_t +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_RESET +//-------------------------------------------------------------------------------------------------- +// description: +// Reset the effect engine. Keep configuration but resets state and buffer content +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_ENABLE +//-------------------------------------------------------------------------------------------------- +// description: +// Enable the process. Called by the framework before the first call to process() +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_DISABLE +//-------------------------------------------------------------------------------------------------- +// description: +// Disable the process. Called by the framework after the last call to process() +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM +//-------------------------------------------------------------------------------------------------- +// description: +// Set a parameter and apply it immediately +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM_DEFERRED +//-------------------------------------------------------------------------------------------------- +// description: +// Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM_COMMIT +//-------------------------------------------------------------------------------------------------- +// description: +// Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_GET_PARAM +//-------------------------------------------------------------------------------------------------- +// description: +// Get a parameter value +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param +// data: effect_param_t + param +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//================================================================================================== +// command: EFFECT_CMD_SET_DEVICE +//-------------------------------------------------------------------------------------------------- +// description: +// Set the rendering device the audio output path is connected to. See audio_device_e for device +// values. +// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this +// command when the device changes +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(uint32_t) +// data: audio_device_e +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_SET_VOLUME +//-------------------------------------------------------------------------------------------------- +// description: +// Set and get volume. Used by audio framework to delegate volume control to effect engine. +// The effect implementation must set EFFECT_FLAG_VOLUME_IND and/or EFFECT_FLAG_VOLUME_CTRL flag in +// its descriptor to receive this command before every call to process() function +// If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return +// the volume that should be applied before the effect is processed. The overall volume (the volume +// actually applied by the effect engine multiplied by the returned value) should match the value +// indicated in the command. +//-------------------------------------------------------------------------------------------------- +// command format: +// size: n * sizeof(uint32_t) +// data: volume for each channel defined in effect_config_t for output buffer expressed in +// 8.24 fixed point format +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: n * sizeof(uint32_t) / 0 +// data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor: +// volume for each channel defined in effect_config_t for output buffer expressed in +// 8.24 fixed point format +// - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor: +// N/A +// It is legal to receive a null pointer as pReplyData in which case the effect framework has +// delegated volume control to another effect +//================================================================================================== +// command: EFFECT_CMD_SET_AUDIO_MODE +//-------------------------------------------------------------------------------------------------- +// description: +// Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its +// descriptor to receive this command when the audio mode changes. +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(uint32_t) +// data: audio_mode_e +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_FIRST_PROPRIETARY +//-------------------------------------------------------------------------------------------------- +// description: +// All proprietary effect commands must use command codes above this value. The size and format of +// command and response fields is free in this case +//================================================================================================== + + +// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t +// structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with +// regard to the channel mask definition in audio_channels_e e.g : // Stereo: left, right // 5 point 1: front left, front right, front center, low frequency, back left, back right // The buffer size is expressed in frame count, a frame being composed of samples for all -// channels at a given time +// channels at a given time. Frame size for unspecified format (AUDIO_FORMAT_OTHER) is 8 bit by +// definition struct audio_buffer_s { size_t frameCount; // number of frames in buffer union { @@ -349,7 +510,7 @@ struct audio_buffer_s { }; }; -// the buffer_provider_s structure contains functions that can be used +// The buffer_provider_s structure contains functions that can be used // by the effect engine process() function to query and release input // or output audio buffer. // The getBuffer() function is called to retrieve a buffer where data @@ -369,6 +530,7 @@ typedef struct buffer_provider_s { void *cookie; // for use by client of buffer provider functions } buffer_provider_t; + // The buffer_config_s structure specifies the input or output audio format // to be used by the effect engine. It is part of the effect_config_t // structure that defines both input and output buffer configurations and is @@ -376,14 +538,69 @@ typedef struct buffer_provider_s { typedef struct buffer_config_s { audio_buffer_t buffer; // buffer for use by process() function if not passed explicitly uint32_t samplingRate; // sampling rate - uint32_t channels; // channel mask (see audio_channels_e in AudioCommon.h) + uint32_t channels; // channel mask (see audio_channels_e) buffer_provider_t bufferProvider; // buffer provider - uint8_t format; // PCM format (see audio_format_e in AudioCommon.h) + uint8_t format; // Audio format (see audio_format_e) uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) uint16_t mask; // indicates which of the above fields is valid } buffer_config_t; -// values for "accessMode" field of buffer_config_t: +// Sample format +enum audio_format_e { + SAMPLE_FORMAT_PCM_S15, // PCM signed 16 bits + SAMPLE_FORMAT_PCM_U8, // PCM unsigned 8 bits + SAMPLE_FORMAT_PCM_S7_24, // PCM signed 7.24 fixed point representation + SAMPLE_FORMAT_OTHER // other format (e.g. compressed) +}; + +// Channel mask +enum audio_channels_e { + CHANNEL_FRONT_LEFT = 0x1, // front left channel + CHANNEL_FRONT_RIGHT = 0x2, // front right channel + CHANNEL_FRONT_CENTER = 0x4, // front center channel + CHANNEL_LOW_FREQUENCY = 0x8, // low frequency channel + CHANNEL_BACK_LEFT = 0x10, // back left channel + CHANNEL_BACK_RIGHT = 0x20, // back right channel + CHANNEL_FRONT_LEFT_OF_CENTER = 0x40, // front left of center channel + CHANNEL_FRONT_RIGHT_OF_CENTER = 0x80, // front right of center channel + CHANNEL_BACK_CENTER = 0x100, // back center channel + CHANNEL_MONO = CHANNEL_FRONT_LEFT, + CHANNEL_STEREO = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT), + CHANNEL_QUAD = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), + CHANNEL_SURROUND = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER), + CHANNEL_5POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), + CHANNEL_7POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | + CHANNEL_FRONT_LEFT_OF_CENTER | CHANNEL_FRONT_RIGHT_OF_CENTER), +}; + +// Render device +enum audio_device_e { + DEVICE_EARPIECE = 0x1, // earpiece + DEVICE_SPEAKER = 0x2, // speaker + DEVICE_WIRED_HEADSET = 0x4, // wired headset, with microphone + DEVICE_WIRED_HEADPHONE = 0x8, // wired headphone, without microphone + DEVICE_BLUETOOTH_SCO = 0x10, // generic bluetooth SCO + DEVICE_BLUETOOTH_SCO_HEADSET = 0x20, // bluetooth SCO headset + DEVICE_BLUETOOTH_SCO_CARKIT = 0x40, // bluetooth SCO car kit + DEVICE_BLUETOOTH_A2DP = 0x80, // generic bluetooth A2DP + DEVICE_BLUETOOTH_A2DP_HEADPHONES = 0x100, // bluetooth A2DP headphones + DEVICE_BLUETOOTH_A2DP_SPEAKER = 0x200, // bluetooth A2DP speakers + DEVICE_AUX_DIGITAL = 0x400, // digital output + DEVICE_EXTERNAL_SPEAKER = 0x800 // external speaker (stereo and High quality) +}; + +// Audio mode +enum audio_mode_e { + AUDIO_MODE_NORMAL, // phone idle + AUDIO_MODE_RINGTONE, // phone ringing + AUDIO_MODE_IN_CALL // phone call connected +}; + +// Values for "accessMode" field of buffer_config_t: // overwrite, read only, accumulate (read/modify/write) enum effect_buffer_access_e { EFFECT_BUFFER_ACCESS_WRITE, @@ -392,7 +609,7 @@ enum effect_buffer_access_e { }; -// values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field +// Values for bit field "mask" in buffer_config_t. If a bit is set, the corresponding field // in buffer_config_t must be taken into account when executing the EFFECT_CMD_CONFIGURE command #define EFFECT_CONFIG_BUFFER 0x0001 // buffer field must be taken into account #define EFFECT_CONFIG_SMP_RATE 0x0002 // samplingRate field must be taken into account @@ -404,13 +621,15 @@ enum effect_buffer_access_e { EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \ EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER) -// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_CONFIGURE command -// to configure audio parameters and buffers for effect engine input and output. + +// effect_config_s structure describes the format of the pCmdData argument of EFFECT_CMD_CONFIGURE +// command to configure audio parameters and buffers for effect engine input and output. typedef struct effect_config_s { buffer_config_t inputCfg; buffer_config_t outputCfg;; } effect_config_t; + // effect_param_s structure describes the format of the pCmdData argument of EFFECT_CMD_SET_PARAM // command and pCmdData and pReplyData of EFFECT_CMD_GET_PARAM command. // psize and vsize represent the actual size of parameter and value. @@ -452,7 +671,7 @@ typedef struct effect_param_s { // specified here as the effect framework will get the function address with dlsym(): // // - effect_QueryNumberEffects_t EffectQueryNumberEffects; -// - effect_QueryNextEffect_t EffectQueryNext; +// - effect_QueryEffect_t EffectQueryEffect; // - effect_CreateEffect_t EffectCreate; // - effect_ReleaseEffect_t EffectRelease; @@ -463,11 +682,8 @@ typedef struct effect_param_s { // // Description: Returns the number of different effects exposed by the // library. Each effect must have a unique effect uuid (see -// effect_descriptor_t). This function together with EffectQueryNext() +// effect_descriptor_t). This function together with EffectQueryEffect() // is used to enumerate all effects present in the library. -// Each time EffectQueryNumberEffects() is called, the library must -// reset the index of the effect descriptor returned by next call to -// EffectQueryNext() to restart enumeration from the beginning. // // Input/Output: // pNumEffects: address where the number of effects should be returned. @@ -483,28 +699,33 @@ typedef int32_t (*effect_QueryNumberEffects_t)(uint32_t *pNumEffects); //////////////////////////////////////////////////////////////////////////////// // -// Function: EffectQueryNext +// Function: EffectQueryEffect // -// Description: Returns a descriptor of the next available effect. +// Description: Returns the descriptor of the effect engine which index is +// given as first argument. // See effect_descriptor_t for details on effect descriptors. -// This function together with EffectQueryNext() is used to enumerate all +// This function together with EffectQueryNumberEffects() is used to enumerate all // effects present in the library. The enumeration sequence is: // EffectQueryNumberEffects(&num_effects); -// while (num_effects--) -// EffectQueryNext(); +// for (i = 0; i < num_effects; i++) +// EffectQueryEffect(i,...); // // Input/Output: +// index: index of the effect // pDescriptor: address where to return the effect descriptor. // // Output: // returned value: 0 successful operation. // -ENODEV library failed to initialize -// -EINVAL invalid pDescriptor +// -EINVAL invalid pDescriptor or index +// -ENOSYS effect list has changed since last execution of +// EffectQueryNumberEffects() // -ENOENT no more effect available // *pDescriptor: updated with the effect descriptor. // //////////////////////////////////////////////////////////////////////////////// -typedef int32_t (*effect_QueryNextEffect_t)(effect_descriptor_t *pDescriptor); +typedef int32_t (*effect_QueryEffect_t)(uint32_t index, + effect_descriptor_t *pDescriptor); //////////////////////////////////////////////////////////////////////////////// // @@ -516,7 +737,13 @@ typedef int32_t (*effect_QueryNextEffect_t)(effect_descriptor_t *pDescriptor); // a handle on the effect control interface. // // Input: -// pEffectUuid: pointer to the effect uuid. +// uuid: pointer to the effect uuid. +// sessionId: audio session to which this effect instance will be attached. All effects +// created with the same session ID are connected in series and process the same signal +// stream. Knowing that two effects are part of the same effect chain can help the +// library implement some kind of optimizations. +// ioId: identifies the output or input stream this effect is directed to at audio HAL. +// For future use especially with tunneled HW accelerated effects // // Input/Output: // pInterface: address where to return the effect interface. @@ -529,7 +756,10 @@ typedef int32_t (*effect_QueryNextEffect_t)(effect_descriptor_t *pDescriptor); // *pInterface: updated with the effect interface handle. // //////////////////////////////////////////////////////////////////////////////// -typedef int32_t (*effect_CreateEffect_t)(effect_uuid_t *uuid, effect_interface_t *pInterface); +typedef int32_t (*effect_CreateEffect_t)(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface); //////////////////////////////////////////////////////////////////////////////// // diff --git a/include/media/EffectFactoryApi.h b/include/media/EffectsFactoryApi.h index 6cc9932b16a3..0ed1a1447b8c 100644 --- a/include/media/EffectFactoryApi.h +++ b/include/media/EffectsFactoryApi.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_EFFECTFACTORYAPI_H_ -#define ANDROID_EFFECTFACTORYAPI_H_ +#ifndef ANDROID_EFFECTSFACTORYAPI_H_ +#define ANDROID_EFFECTSFACTORYAPI_H_ #include <errno.h> #include <stdint.h> @@ -36,11 +36,11 @@ extern "C" { // // Description: Returns the number of different effects in all loaded libraries. // Each effect must have a different effect uuid (see -// effect_descriptor_t). This function together with EffectQueryNext() +// effect_descriptor_t). This function together with EffectQueryEffect() // is used to enumerate all effects present in all loaded libraries. // Each time EffectQueryNumberEffects() is called, the factory must // reset the index of the effect descriptor returned by next call to -// EffectQueryNext() to restart enumeration from the beginning. +// EffectQueryEffect() to restart enumeration from the beginning. // // Input/Output: // pNumEffects: address where the number of effects should be returned. @@ -56,28 +56,29 @@ int EffectQueryNumberEffects(uint32_t *pNumEffects); //////////////////////////////////////////////////////////////////////////////// // -// Function: EffectQueryNext +// Function: EffectQueryEffect // // Description: Returns a descriptor of the next available effect. // See effect_descriptor_t for a details on effect descriptor. -// This function together with EffectQueryNext() is used to enumerate all +// This function together with EffectQueryNumberEffects() is used to enumerate all // effects present in all loaded libraries. The enumeration sequence is: // EffectQueryNumberEffects(&num_effects); -// while (num_effects--) -// EffectQueryNext(); +// for (i = 0; i < num_effects; i++) +// EffectQueryEffect(i,...); // // Input/Output: // pDescriptor: address where to return the effect descriptor. // // Output: // returned value: 0 successful operation. +// -ENOENT no more effect available // -ENODEV factory failed to initialize // -EINVAL invalid pDescriptor -// -ENOENT no more effect available +// -ENOSYS effect list has changed since last execution of EffectQueryNumberEffects() // *pDescriptor: updated with the effect descriptor. // //////////////////////////////////////////////////////////////////////////////// -int EffectQueryNext(effect_descriptor_t *pDescriptor); +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor); //////////////////////////////////////////////////////////////////////////////// // @@ -90,6 +91,12 @@ int EffectQueryNext(effect_descriptor_t *pDescriptor); // // Input: // pEffectUuid: pointer to the effect uuid. +// sessionId: audio session to which this effect instance will be attached. All effects created +// with the same session ID are connected in series and process the same signal stream. +// Knowing that two effects are part of the same effect chain can help the library implement +// some kind of optimizations. +// ioId: identifies the output or input stream this effect is directed to at audio HAL. For future +// use especially with tunneled HW accelerated effects // // Input/Output: // pInterface: address where to return the effect interface. @@ -102,7 +109,7 @@ int EffectQueryNext(effect_descriptor_t *pDescriptor); // *pInterface: updated with the effect interface. // //////////////////////////////////////////////////////////////////////////////// -int EffectCreate(effect_uuid_t *pEffectUuid, effect_interface_t *pInterface); +int EffectCreate(effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface); //////////////////////////////////////////////////////////////////////////////// // @@ -211,4 +218,4 @@ int EffectIsNullUuid(effect_uuid_t *pEffectUuid); #endif -#endif /*ANDROID_EFFECTFACTORYAPI_H_*/ +#endif /*ANDROID_EFFECTSFACTORYAPI_H_*/ diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h index ccfa53070dfd..5814fd615acd 100644 --- a/include/media/IAudioFlinger.h +++ b/include/media/IAudioFlinger.h @@ -148,7 +148,7 @@ public: virtual status_t queryNumberEffects(uint32_t *numEffects) = 0; - virtual status_t queryNextEffect(effect_descriptor_t *pDescriptor) = 0; + virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) = 0; virtual status_t getEffectDescriptor(effect_uuid_t *pEffectUUID, effect_descriptor_t *pDescriptor) = 0; diff --git a/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp index 1860793d9fff..48c04a6680c1 100644 --- a/libs/audioflinger/AudioFlinger.cpp +++ b/libs/audioflinger/AudioFlinger.cpp @@ -51,7 +51,7 @@ #include "lifevibes.h" #endif -#include <media/EffectFactoryApi.h> +#include <media/EffectsFactoryApi.h> // ---------------------------------------------------------------------------- // the sim build doesn't have gettid @@ -126,7 +126,8 @@ static bool settingsAllowed() { AudioFlinger::AudioFlinger() : BnAudioFlinger(), - mAudioHardware(0), mMasterVolume(1.0f), mMasterMute(false), mNextUniqueId(1) + mAudioHardware(0), mMasterVolume(1.0f), mMasterMute(false), mNextUniqueId(1), + mTotalEffectsCpuLoad(0), mTotalEffectsMemory(0) { mHardwareStatus = AUDIO_HW_IDLE; @@ -135,8 +136,8 @@ AudioFlinger::AudioFlinger() mHardwareStatus = AUDIO_HW_INIT; if (mAudioHardware->initCheck() == NO_ERROR) { // open 16-bit output stream for s/w mixer - - setMode(AudioSystem::MODE_NORMAL); + mMode = AudioSystem::MODE_NORMAL; + setMode(mMode); setMasterVolume(1.0f); setMasterMute(false); @@ -431,6 +432,8 @@ status_t AudioFlinger::setMasterVolume(float value) status_t AudioFlinger::setMode(int mode) { + status_t ret; + // check calling permissions if (!settingsAllowed()) { return PERMISSION_DENIED; @@ -440,15 +443,23 @@ status_t AudioFlinger::setMode(int mode) return BAD_VALUE; } - AutoMutex lock(mHardwareLock); - mHardwareStatus = AUDIO_HW_SET_MODE; - status_t ret = mAudioHardware->setMode(mode); -#ifdef LVMX + { // scope for the lock + AutoMutex lock(mHardwareLock); + mHardwareStatus = AUDIO_HW_SET_MODE; + ret = mAudioHardware->setMode(mode); + mHardwareStatus = AUDIO_HW_IDLE; + } + if (NO_ERROR == ret) { + Mutex::Autolock _l(mLock); + mMode = mode; + for (uint32_t i = 0; i < mPlaybackThreads.size(); i++) + mPlaybackThreads.valueAt(i)->setMode(mode); +#ifdef LVMX LifeVibes::setMode(mode); - } #endif - mHardwareStatus = AUDIO_HW_IDLE; + } + return ret; } @@ -1385,6 +1396,15 @@ sp<AudioFlinger::EffectChain> AudioFlinger::PlaybackThread::getEffectChain_l(int return chain; } +void AudioFlinger::PlaybackThread::setMode(uint32_t mode) +{ + Mutex::Autolock _l(mLock); + size_t size = mEffectChains.size(); + for (size_t i = 0; i < size; i++) { + mEffectChains[i]->setMode(mode); + } +} + // ---------------------------------------------------------------------------- AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device) @@ -1803,9 +1823,9 @@ void AudioFlinger::MixerThread::invalidateTracks(int streamType) t->mCblk->flags |= CBLK_INVALID_ON; t->mCblk->cv.signal(); t->mCblk->lock.unlock(); - } - } } + } +} // getTrackName_l() must be called with ThreadBase::mLock held @@ -4466,10 +4486,10 @@ status_t AudioFlinger::queryNumberEffects(uint32_t *numEffects) return EffectQueryNumberEffects(numEffects); } -status_t AudioFlinger::queryNextEffect(effect_descriptor_t *descriptor) +status_t AudioFlinger::queryEffect(uint32_t index, effect_descriptor_t *descriptor) { Mutex::Autolock _l(mLock); - return EffectQueryNext(descriptor); + return EffectQueryEffect(index, descriptor); } status_t AudioFlinger::getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *descriptor) @@ -4529,10 +4549,10 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, LOGW("createEffect() error %d from EffectQueryNumberEffects", lStatus); goto Exit; } - for (; numEffects > 0; numEffects--) { - lStatus = EffectQueryNext(&desc); + for (uint32_t i = 0; i < numEffects; i++) { + lStatus = EffectQueryEffect(i, &desc); if (lStatus < 0) { - LOGW("createEffect() error %d from EffectQueryNext", lStatus); + LOGW("createEffect() error %d from EffectQueryEffect", lStatus); continue; } if (memcmp(&desc.type, &pDesc->type, sizeof(effect_uuid_t)) == 0) { @@ -4567,6 +4587,13 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, goto Exit; } + // Session -1 is reserved for output stage effects that can only be created + // by audio policy manager (running in same process) + if (sessionId == -1 && getpid() != IPCThreadState::self()->getCallingPid()) { + lStatus = INVALID_OPERATION; + goto Exit; + } + // return effect descriptor memcpy(pDesc, &desc, sizeof(effect_descriptor_t)); @@ -4574,7 +4601,7 @@ sp<IEffect> AudioFlinger::createEffect(pid_t pid, // output threads. // TODO: allow attachment of effect to inputs if (output == 0) { - if (sessionId == 0) { + if (sessionId <= 0) { // default to first output // TODO: define criteria to choose output when not specified. Or // receive output from audio policy manager @@ -4621,6 +4648,33 @@ Exit: return handle; } +status_t AudioFlinger::registerEffectResource_l(effect_descriptor_t *desc) { + if (mTotalEffectsCpuLoad + desc->cpuLoad > MAX_EFFECTS_CPU_LOAD) { + LOGW("registerEffectResource() CPU Load limit exceeded for Fx %s, CPU %f MIPS", + desc->name, (float)desc->cpuLoad/10); + return INVALID_OPERATION; + } + if (mTotalEffectsMemory + desc->memoryUsage > MAX_EFFECTS_MEMORY) { + LOGW("registerEffectResource() memory limit exceeded for Fx %s, Memory %d KB", + desc->name, desc->memoryUsage); + return INVALID_OPERATION; + } + mTotalEffectsCpuLoad += desc->cpuLoad; + mTotalEffectsMemory += desc->memoryUsage; + LOGV("registerEffectResource_l() effect %s, CPU %d, memory %d", + desc->name, desc->cpuLoad, desc->memoryUsage); + LOGV(" total CPU %d, total memory %d", mTotalEffectsCpuLoad, mTotalEffectsMemory); + return NO_ERROR; +} + +void AudioFlinger::unregisterEffectResource_l(effect_descriptor_t *desc) { + mTotalEffectsCpuLoad -= desc->cpuLoad; + mTotalEffectsMemory -= desc->memoryUsage; + LOGV("unregisterEffectResource_l() effect %s, CPU %d, memory %d", + desc->name, desc->cpuLoad, desc->memoryUsage); + LOGV(" total CPU %d, total memory %d", mTotalEffectsCpuLoad, mTotalEffectsMemory); +} + // PlaybackThread::createEffect_l() must be called with AudioFlinger::mLock held sp<AudioFlinger::EffectHandle> AudioFlinger::PlaybackThread::createEffect_l( const sp<AudioFlinger::Client>& client, @@ -4638,6 +4692,7 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::PlaybackThread::createEffect_l( sp<Track> track; sp<EffectChain> chain; bool effectCreated = false; + bool effectRegistered = false; if (mOutput == 0) { LOGW("createEffect_l() Audio driver not initialized."); @@ -4680,20 +4735,26 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::PlaybackThread::createEffect_l( LOGV("createEffect_l() got effect %p on chain %p", effect == 0 ? 0 : effect.get(), chain.get()); if (effect == 0) { + // Check CPU and memory usage + lStatus = mAudioFlinger->registerEffectResource_l(desc); + if (lStatus != NO_ERROR) { + goto Exit; + } + effectRegistered = true; // create a new effect module if none present in the chain - effectCreated = true; effect = new EffectModule(this, chain, desc, mAudioFlinger->nextUniqueId(), sessionId); lStatus = effect->status(); if (lStatus != NO_ERROR) { goto Exit; } - //TODO: handle CPU load and memory usage here lStatus = chain->addEffect(effect); if (lStatus != NO_ERROR) { goto Exit; } + effectCreated = true; effect->setDevice(mDevice); + effect->setMode(mAudioFlinger->getMode()); } // create effect handle and connect it to effect module handle = new EffectHandle(effect, client, effectClient, priority); @@ -4705,11 +4766,14 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::PlaybackThread::createEffect_l( Exit: if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) { - if (chain != 0 && effectCreated) { + if (effectCreated) { if (chain->removeEffect(effect) == 0) { removeEffectChain_l(chain); } } + if (effectRegistered) { + mAudioFlinger->unregisterEffectResource_l(desc); + } handle.clear(); } @@ -4719,21 +4783,37 @@ Exit: return handle; } +void AudioFlinger::PlaybackThread::disconnectEffect(const sp< EffectModule>& effect, + const wp<EffectHandle>& handle) { + effect_descriptor_t desc = effect->desc(); + Mutex::Autolock _l(mLock); + // delete the effect module if removing last handle on it + if (effect->removeHandle(handle) == 0) { + if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { + detachAuxEffect_l(effect->id()); + } + sp<EffectChain> chain = effect->chain().promote(); + if (chain != 0) { + // remove effect chain if remove last effect + if (chain->removeEffect(effect) == 0) { + removeEffectChain_l(chain); + } + } + mLock.unlock(); + mAudioFlinger->mLock.lock(); + mAudioFlinger->unregisterEffectResource_l(&desc); + mAudioFlinger->mLock.unlock(); + } +} + status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp<EffectChain>& chain) { int session = chain->sessionId(); int16_t *buffer = mMixBuffer; + bool ownsBuffer = false; LOGV("addEffectChain_l() %p on thread %p for session %d", chain.get(), this, session); - if (session == 0) { - chain->setInBuffer(buffer, false); - chain->setOutBuffer(buffer); - // Effect chain for session 0 is inserted at end of effect chains list - // to be processed last as it contains output mix effects to apply after - // all track specific effects - mEffectChains.add(chain); - } else { - bool ownsBuffer = false; + if (session > 0) { // Only one effect chain can be present in direct output thread and it uses // the mix buffer as input if (mType != DIRECT) { @@ -4743,33 +4823,43 @@ status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp<EffectChain>& c LOGV("addEffectChain_l() creating new input buffer %p session %d", buffer, session); ownsBuffer = true; } - chain->setInBuffer(buffer, ownsBuffer); - chain->setOutBuffer(mMixBuffer); - // Effect chain for session other than 0 is inserted at beginning of effect - // chains list to be processed before output mix effects. Relative order between - // sessions other than 0 is not important - mEffectChains.insertAt(chain, 0); - } - // Attach all tracks with same session ID to this chain. - for (size_t i = 0; i < mTracks.size(); ++i) { - sp<Track> track = mTracks[i]; - if (session == track->sessionId()) { - LOGV("addEffectChain_l() track->setMainBuffer track %p buffer %p", track.get(), buffer); - track->setMainBuffer(buffer); + // Attach all tracks with same session ID to this chain. + for (size_t i = 0; i < mTracks.size(); ++i) { + sp<Track> track = mTracks[i]; + if (session == track->sessionId()) { + LOGV("addEffectChain_l() track->setMainBuffer track %p buffer %p", track.get(), buffer); + track->setMainBuffer(buffer); + } } - } - // indicate all active tracks in the chain - for (size_t i = 0 ; i < mActiveTracks.size() ; ++i) { - sp<Track> track = mActiveTracks[i].promote(); - if (track == 0) continue; - if (session == track->sessionId()) { - LOGV("addEffectChain_l() activating track %p on session %d", track.get(), session); - chain->startTrack(); + // indicate all active tracks in the chain + for (size_t i = 0 ; i < mActiveTracks.size() ; ++i) { + sp<Track> track = mActiveTracks[i].promote(); + if (track == 0) continue; + if (session == track->sessionId()) { + LOGV("addEffectChain_l() activating track %p on session %d", track.get(), session); + chain->startTrack(); + } } } + chain->setInBuffer(buffer, ownsBuffer); + chain->setOutBuffer(mMixBuffer); + // Effect chain for session -1 is inserted at end of effect chains list + // in order to be processed last as it contains output stage effects + // Effect chain for session 0 is inserted before session -1 to be processed + // after track specific effects and before output stage + // Effect chain for session other than 0 is inserted at beginning of effect + // chains list to be processed before output mix effects. Relative order between + // sessions other than 0 is not important + size_t size = mEffectChains.size(); + size_t i = 0; + for (i = 0; i < size; i++) { + if (mEffectChains[i]->sessionId() < session) break; + } + mEffectChains.insertAt(chain, i); + return NO_ERROR; } @@ -4884,7 +4974,8 @@ AudioFlinger::EffectModule::EffectModule(const wp<ThreadBase>& wThread, memcpy(&mDescriptor, desc, sizeof(effect_descriptor_t)); // create effect engine from effect factory - mStatus = EffectCreate(&desc->uuid, &mEffectInterface); + mStatus = EffectCreate(&desc->uuid, sessionId, p->id(), &mEffectInterface); + if (mStatus != NO_ERROR) { return; } @@ -4969,22 +5060,11 @@ void AudioFlinger::EffectModule::disconnect(const wp<EffectHandle>& handle) // keep a strong reference on this EffectModule to avoid calling the // destructor before we exit sp<EffectModule> keep(this); - sp<ThreadBase> thread = mThread.promote(); - if (thread != 0) { - Mutex::Autolock _l(thread->mLock); - // delete the effect module if removing last handle on it - if (removeHandle(handle) == 0) { + { + sp<ThreadBase> thread = mThread.promote(); + if (thread != 0) { PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); - if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { - playbackThread->detachAuxEffect_l(mId); - } - sp<EffectChain> chain = mChain.promote(); - if (chain != 0) { - // remove effect chain if remove last effect - if (chain->removeEffect(keep) == 0) { - playbackThread->removeEffectChain_l(chain); - } - } + playbackThread->disconnectEffect(keep, handle); } } } @@ -5007,88 +5087,25 @@ void AudioFlinger::EffectModule::process() // TODO: handle effects with buffer provider if (mState != ACTIVE) { - uint32_t count = mConfig.inputCfg.buffer.frameCount; - int32_t amp = 32767L << 16; - int32_t step = amp / count; - int16_t *pIn = mConfig.inputCfg.buffer.s16; - int16_t *pOut = mConfig.outputCfg.buffer.s16; - int inChannels; - int outChannels; - - if (mConfig.inputCfg.channels == CHANNEL_MONO) { - inChannels = 1; - } else { - inChannels = 2; - } - if (mConfig.outputCfg.channels == CHANNEL_MONO) { - outChannels = 1; - } else { - outChannels = 2; - } - switch (mState) { case RESET: reset(); + mState = STARTING; // clear auxiliary effect input buffer for next accumulation if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { memset(mConfig.inputCfg.buffer.raw, 0, mConfig.inputCfg.buffer.frameCount*sizeof(int32_t)); } - step = -step; - mState = STARTING; - break; + return; case STARTING: start(); - amp = 0; - pOut = mConfig.inputCfg.buffer.s16; - outChannels = inChannels; mState = ACTIVE; break; case STOPPING: - step = -step; - pOut = mConfig.inputCfg.buffer.s16; - outChannels = inChannels; mState = STOPPED; break; case STOPPED: stop(); - amp = 0; mState = IDLE; - break; - } - - // ramp volume down or up before activating or deactivating the effect - if (inChannels == 1) { - if (outChannels == 1) { - while (count--) { - *pOut++ = (int16_t)(((int32_t)*pIn++ * (amp >> 16)) >> 15); - amp += step; - } - } else { - while (count--) { - int32_t smp = (int16_t)(((int32_t)*pIn++ * (amp >> 16)) >> 15); - *pOut++ = smp; - *pOut++ = smp; - amp += step; - } - } - } else { - if (outChannels == 1) { - while (count--) { - int32_t smp = (((int32_t)*pIn * (amp >> 16)) >> 16) + - (((int32_t)*(pIn + 1) * (amp >> 16)) >> 16); - pIn += 2; - *pOut++ = (int16_t)smp; - amp += step; - } - } else { - while (count--) { - *pOut++ = (int16_t)((int32_t)*pIn++ * (amp >> 16)) >> 15; - *pOut++ = (int16_t)((int32_t)*pIn++ * (amp >> 16)) >> 15; - amp += step; - } - } - } - if (mState == STARTING || mState == IDLE) { return; } } @@ -5148,8 +5165,8 @@ status_t AudioFlinger::EffectModule::configure() mConfig.inputCfg.channels = channels; } mConfig.outputCfg.channels = channels; - mConfig.inputCfg.format = PCM_FORMAT_S15; - mConfig.outputCfg.format = PCM_FORMAT_S15; + mConfig.inputCfg.format = SAMPLE_FORMAT_PCM_S15; + mConfig.outputCfg.format = SAMPLE_FORMAT_PCM_S15; mConfig.inputCfg.samplingRate = thread->sampleRate(); mConfig.outputCfg.samplingRate = mConfig.inputCfg.samplingRate; mConfig.inputCfg.bufferProvider.cookie = NULL; @@ -5160,7 +5177,7 @@ status_t AudioFlinger::EffectModule::configure() mConfig.outputCfg.bufferProvider.releaseBuffer = NULL; mConfig.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; // Insert effect: - // - in session 0, always overwrites output buffer: input buffer == output buffer + // - in session 0 or -1, always overwrites output buffer: input buffer == output buffer // - in other sessions: // last effect in the chain accumulates in output buffer: input buffer != output buffer // other effect: overwrites output buffer: input buffer == output buffer @@ -5331,7 +5348,12 @@ status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right, status_t AudioFlinger::EffectModule::setDevice(uint32_t device) { status_t status = NO_ERROR; - if ((mDescriptor.flags & EFFECT_FLAG_DEVICE_MASK) == EFFECT_FLAG_DEVICE_MASK) { + if ((mDescriptor.flags & EFFECT_FLAG_DEVICE_MASK) == EFFECT_FLAG_DEVICE_IND) { + // convert device bit field from AudioSystem to EffectApi format. + device = deviceAudioSystemToEffectApi(device); + if (device == 0) { + return BAD_VALUE; + } status_t cmdStatus; int size = sizeof(status_t); status = (*mEffectInterface)->command(mEffectInterface, EFFECT_CMD_SET_DEVICE, sizeof(uint32_t), &device, &size, &cmdStatus); @@ -5342,6 +5364,70 @@ status_t AudioFlinger::EffectModule::setDevice(uint32_t device) return status; } +status_t AudioFlinger::EffectModule::setMode(uint32_t mode) +{ + status_t status = NO_ERROR; + if ((mDescriptor.flags & EFFECT_FLAG_AUDIO_MODE_MASK) == EFFECT_FLAG_AUDIO_MODE_IND) { + // convert audio mode from AudioSystem to EffectApi format. + int effectMode = modeAudioSystemToEffectApi(mode); + if (effectMode < 0) { + return BAD_VALUE; + } + status_t cmdStatus; + int size = sizeof(status_t); + status = (*mEffectInterface)->command(mEffectInterface, EFFECT_CMD_SET_AUDIO_MODE, sizeof(int), &effectMode, &size, &cmdStatus); + if (status == NO_ERROR) { + status = cmdStatus; + } + } + return status; +} + +// update this table when AudioSystem::audio_devices or audio_device_e (in EffectApi.h) are modified +const uint32_t AudioFlinger::EffectModule::sDeviceConvTable[] = { + DEVICE_EARPIECE, // AudioSystem::DEVICE_OUT_EARPIECE + DEVICE_SPEAKER, // AudioSystem::DEVICE_OUT_SPEAKER + DEVICE_WIRED_HEADSET, // case AudioSystem::DEVICE_OUT_WIRED_HEADSET + DEVICE_WIRED_HEADPHONE, // AudioSystem::DEVICE_OUT_WIRED_HEADPHONE + DEVICE_BLUETOOTH_SCO, // AudioSystem::DEVICE_OUT_BLUETOOTH_SCO + DEVICE_BLUETOOTH_SCO_HEADSET, // AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET + DEVICE_BLUETOOTH_SCO_CARKIT, // AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT + DEVICE_BLUETOOTH_A2DP, // AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP + DEVICE_BLUETOOTH_A2DP_HEADPHONES, // AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES + DEVICE_BLUETOOTH_A2DP_SPEAKER, // AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER + DEVICE_AUX_DIGITAL // AudioSystem::DEVICE_OUT_AUX_DIGITAL +}; + +uint32_t AudioFlinger::EffectModule::deviceAudioSystemToEffectApi(uint32_t device) +{ + uint32_t deviceOut = 0; + while (device) { + const uint32_t i = 31 - __builtin_clz(device); + device &= ~(1 << i); + if (i >= sizeof(sDeviceConvTable)/sizeof(uint32_t)) { + LOGE("device convertion error for AudioSystem device 0x%08x", device); + return 0; + } + deviceOut |= (uint32_t)sDeviceConvTable[i]; + } + return deviceOut; +} + +// update this table when AudioSystem::audio_mode or audio_mode_e (in EffectApi.h) are modified +const uint32_t AudioFlinger::EffectModule::sModeConvTable[] = { + AUDIO_MODE_NORMAL, // AudioSystem::MODE_NORMAL + AUDIO_MODE_RINGTONE, // AudioSystem::MODE_RINGTONE + AUDIO_MODE_IN_CALL // AudioSystem::MODE_IN_CALL +}; + +int AudioFlinger::EffectModule::modeAudioSystemToEffectApi(uint32_t mode) +{ + int modeOut = -1; + if (mode < sizeof(sModeConvTable) / sizeof(uint32_t)) { + modeOut = (int)sModeConvTable[mode]; + } + return modeOut; +} status_t AudioFlinger::EffectModule::dump(int fd, const Vector<String16>& args) { @@ -5525,7 +5611,16 @@ status_t AudioFlinger::EffectHandle::command(int cmdCode, int cmdSize, void *pCm int rsize = sizeof(int); int *p = (int *)(mBuffer + mCblk->serverIndex); int size = *p++; + if (((uint8_t *)p + size) > mBuffer + mCblk->clientIndex) { + LOGW("command(): invalid parameter block size"); + break; + } effect_param_t *param = (effect_param_t *)p; + if (param->psize == 0 || param->vsize == 0) { + LOGW("command(): null parameter or value size"); + mCblk->serverIndex += size; + continue; + } int psize = sizeof(effect_param_t) + ((param->psize - 1) / sizeof(int) + 1) * sizeof(int) + param->vsize; status_t ret = mEffect->command(EFFECT_CMD_SET_PARAM, psize, p, &rsize, &reply); if (ret == NO_ERROR) { @@ -5659,7 +5754,7 @@ void AudioFlinger::EffectChain::process_l() } // if no track is active, input buffer must be cleared here as the mixer process // will not do it - if (mSessionId != 0 && activeTracks() == 0) { + if (mSessionId > 0 && activeTracks() == 0) { sp<ThreadBase> thread = mThread.promote(); if (thread != 0) { size_t numSamples = thread->frameCount() * thread->channelCount(); @@ -5697,15 +5792,16 @@ status_t AudioFlinger::EffectChain::addEffect(sp<EffectModule>& effect) } else { // Insert effects are inserted at the end of mEffects vector as they are processed // after track and auxiliary effects. - // Insert effect order: - // if EFFECT_FLAG_INSERT_FIRST or EFFECT_FLAG_INSERT_EXCLUSIVE insert as first insert effect + // Insert effect order as a function of indicated preference: + // if EFFECT_FLAG_INSERT_EXCLUSIVE, insert in first position or reject if + // another effect is present + // else if EFFECT_FLAG_INSERT_FIRST, insert in first position or after the + // last effect claiming first position + // else if EFFECT_FLAG_INSERT_LAST, insert in last position or before the + // first effect claiming last position // else if EFFECT_FLAG_INSERT_ANY insert after first or before last - // else insert as last insert effect - // Reject insertion if: - // - EFFECT_FLAG_INSERT_EXCLUSIVE and another effect is present - // - an effect with EFFECT_FLAG_INSERT_EXCLUSIVE is present - // - EFFECT_FLAG_INSERT_FIRST or EFFECT_FLAG_INSERT_LAST and an effect with same - // preference is present + // Reject insertion if an effect with EFFECT_FLAG_INSERT_EXCLUSIVE is + // already present int size = (int)mEffects.size(); int idx_insert = size; @@ -5719,35 +5815,40 @@ status_t AudioFlinger::EffectChain::addEffect(sp<EffectModule>& effect) if (iMode == EFFECT_FLAG_TYPE_INSERT) { // check invalid effect chaining combinations if (insertPref == EFFECT_FLAG_INSERT_EXCLUSIVE || - iPref == EFFECT_FLAG_INSERT_EXCLUSIVE || - (insertPref != EFFECT_FLAG_INSERT_ANY - && insertPref == iPref)) { + iPref == EFFECT_FLAG_INSERT_EXCLUSIVE) { + LOGW("addEffect() could not insert effect %s: exclusive conflict with %s", desc.name, d.name); return INVALID_OPERATION; } - // remember position of first insert effect + // remember position of first insert effect and by default + // select this as insert position for new effect if (idx_insert == size) { idx_insert = i; } - // remember position of insert effect claiming - // first place + // remember position of last insert effect claiming + // first position if (iPref == EFFECT_FLAG_INSERT_FIRST) { idx_insert_first = i; } - // remember position of insert effect claiming - // last place - if (iPref == EFFECT_FLAG_INSERT_LAST) { + // remember position of first insert effect claiming + // last position + if (iPref == EFFECT_FLAG_INSERT_LAST && + idx_insert_last == -1) { idx_insert_last = i; } } } - // modify idx_insert from first place if needed - if (idx_insert_first != -1) { - idx_insert = idx_insert_first + 1; - } else if (idx_insert_last != -1) { - idx_insert = idx_insert_last; - } else if (insertPref == EFFECT_FLAG_INSERT_LAST) { - idx_insert = size; + // modify idx_insert from first position if needed + if (insertPref == EFFECT_FLAG_INSERT_LAST) { + if (idx_insert_last != -1) { + idx_insert = idx_insert_last; + } else { + idx_insert = size; + } + } else { + if (idx_insert_first != -1) { + idx_insert = idx_insert_first + 1; + } } // always read samples from chain input buffer @@ -5764,14 +5865,14 @@ status_t AudioFlinger::EffectChain::addEffect(sp<EffectModule>& effect) } else { effect->setOutBuffer(mInBuffer); } - status_t status = mEffects.insertAt(effect, idx_insert); + mEffects.insertAt(effect, idx_insert); // Always give volume control to last effect in chain with volume control capability if (((desc.flags & EFFECT_FLAG_VOLUME_MASK) & EFFECT_FLAG_VOLUME_CTRL) && mVolumeCtrlIdx < idx_insert) { mVolumeCtrlIdx = idx_insert; } - LOGV("addEffect() effect %p, added in chain %p at rank %d status %d", effect.get(), this, idx_insert, status); + LOGV("addEffect() effect %p, added in chain %p at rank %d", effect.get(), this, idx_insert); } effect->configure(); return NO_ERROR; @@ -5823,6 +5924,14 @@ void AudioFlinger::EffectChain::setDevice(uint32_t device) } } +void AudioFlinger::EffectChain::setMode(uint32_t mode) +{ + size_t size = mEffects.size(); + for (size_t i = 0; i < size; i++) { + mEffects[i]->setMode(mode); + } +} + bool AudioFlinger::EffectChain::setVolume(uint32_t *left, uint32_t *right) { uint32_t newLeft = *left; diff --git a/libs/audioflinger/AudioFlinger.h b/libs/audioflinger/AudioFlinger.h index e543334cb714..42dca4c97ece 100644 --- a/libs/audioflinger/AudioFlinger.h +++ b/libs/audioflinger/AudioFlinger.h @@ -149,7 +149,7 @@ public: virtual status_t queryNumberEffects(uint32_t *numEffects); - virtual status_t queryNextEffect(effect_descriptor_t *descriptor); + virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor); virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *descriptor); @@ -163,6 +163,9 @@ public: int *id, int *enabled); + status_t registerEffectResource_l(effect_descriptor_t *desc); + void unregisterEffectResource_l(effect_descriptor_t *desc); + enum hardware_call_state { AUDIO_HW_IDLE = 0, AUDIO_HW_INIT, @@ -200,6 +203,8 @@ public: Parcel* reply, uint32_t flags); + uint32_t getMode() { return mMode; } + private: AudioFlinger(); virtual ~AudioFlinger(); @@ -601,6 +606,8 @@ private: effect_descriptor_t *desc, int *enabled, status_t *status); + void disconnectEffect(const sp< EffectModule>& effect, + const wp<EffectHandle>& handle); bool hasAudioSession(int sessionId); sp<EffectChain> getEffectChain(int sessionId); @@ -614,6 +621,7 @@ private: void detachAuxEffect_l(int effectId); status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId); status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId); + void setMode(uint32_t mode); struct stream_type_t { stream_type_t() @@ -930,9 +938,11 @@ private: size_t removeHandle (const wp<EffectHandle>& handle); effect_descriptor_t& desc() { return mDescriptor; } + wp<EffectChain>& chain() { return mChain; } status_t setDevice(uint32_t device); status_t setVolume(uint32_t *left, uint32_t *right, bool controller); + status_t setMode(uint32_t mode); status_t dump(int fd, const Vector<String16>& args); @@ -944,6 +954,14 @@ private: status_t start(); status_t stop(); + // update this table when AudioSystem::audio_devices or audio_device_e (in EffectApi.h) are modified + static const uint32_t sDeviceConvTable[]; + static uint32_t deviceAudioSystemToEffectApi(uint32_t device); + + // update this table when AudioSystem::audio_mode or audio_mode_e (in EffectApi.h) are modified + static const uint32_t sModeConvTable[]; + static int modeAudioSystemToEffectApi(uint32_t mode); + Mutex mLock; // mutex for process, commands and handles list protection wp<ThreadBase> mThread; // parent thread wp<EffectChain> mChain; // parent effect chain @@ -1042,6 +1060,8 @@ private: sp<EffectModule> getVolumeController(); bool setVolume(uint32_t *left, uint32_t *right); void setDevice(uint32_t device); + void setMode(uint32_t mode); + void setInBuffer(int16_t *buffer, bool ownsBuffer = false) { mInBuffer = buffer; @@ -1104,6 +1124,14 @@ private: #ifdef LVMX int mLifeVibesClientPid; #endif + uint32_t mMode; + + // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units + static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000; + // Maximum memory allocated to audio effects in KB + static const uint32_t MAX_EFFECTS_MEMORY = 512; + uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects + uint32_t mTotalEffectsMemory; // current memory used by effects }; // ---------------------------------------------------------------------------- diff --git a/media/jni/audioeffect/android_media_AudioEffect.cpp b/media/jni/audioeffect/android_media_AudioEffect.cpp index de01dd3e4d54..17f2d8fdd485 100644 --- a/media/jni/audioeffect/android_media_AudioEffect.cpp +++ b/media/jni/audioeffect/android_media_AudioEffect.cpp @@ -758,7 +758,7 @@ android_media_AudioEffect_native_queryEffects(JNIEnv *env, jclass clazz) LOGV("queryEffects() numEffects: %d", numEffects); for (i = 0; i < numEffects; i++) { - if (AudioEffect::queryNextEffect(&desc) != NO_ERROR) { + if (AudioEffect::queryEffect(i, &desc) != NO_ERROR) { goto queryEffects_failure; } diff --git a/media/libeffects/Android.mk b/media/libeffects/Android.mk index ff2145461f7e..b5f1d42ab401 100644 --- a/media/libeffects/Android.mk +++ b/media/libeffects/Android.mk @@ -1,5 +1,8 @@ LOCAL_PATH:= $(call my-dir) +# +TEST_EFFECT_LIBRARIES := true + # Effect factory library include $(CLEAR_VARS) @@ -25,7 +28,8 @@ LOCAL_C_INCLUDES := \ include $(BUILD_SHARED_LIBRARY) -# Default Reverb library +ifeq ($(TEST_EFFECT_LIBRARIES),true) +# Test Reverb library include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ @@ -54,7 +58,7 @@ LOCAL_PRELINK_MODULE := false include $(BUILD_SHARED_LIBRARY) -# Default Equalizer library +# Test Equalizer library include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ @@ -87,4 +91,6 @@ LOCAL_C_INCLUDES := \ LOCAL_PRELINK_MODULE := false -include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file +include $(BUILD_SHARED_LIBRARY) + +endif diff --git a/media/libeffects/AudioCoefInterpolator.cpp b/media/libeffects/AudioCoefInterpolator.cpp index 05898c995225..039ab9f717be 100644 --- a/media/libeffects/AudioCoefInterpolator.cpp +++ b/media/libeffects/AudioCoefInterpolator.cpp @@ -46,7 +46,7 @@ void AudioCoefInterpolator::getCoef(const int intCoord[], uint32_t fracCoord[], while (dim-- > 0) { if (UNLIKELY(intCoord[dim] < 0)) { fracCoord[dim] = 0; - } else if (UNLIKELY(intCoord[dim] >= mInDims[dim] - 1)) { + } else if (UNLIKELY(intCoord[dim] >= (int)mInDims[dim] - 1)) { fracCoord[dim] = 0; index += mInDimOffsets[dim] * (mInDims[dim] - 1); } else { diff --git a/media/libeffects/AudioCommon.h b/media/libeffects/AudioCommon.h index 12d2193e6a10..444f93a016a6 100644 --- a/media/libeffects/AudioCommon.h +++ b/media/libeffects/AudioCommon.h @@ -1,4 +1,4 @@ -/* //device/include/server/AudioFlinger/AudioCommon.h +/* ** ** Copyright 2009, The Android Open Source Project ** diff --git a/media/libeffects/AudioFormatAdapter.h b/media/libeffects/AudioFormatAdapter.h index 8aa5e65119b6..d93ebe99d6f7 100644 --- a/media/libeffects/AudioFormatAdapter.h +++ b/media/libeffects/AudioFormatAdapter.h @@ -75,7 +75,7 @@ public: while (numSamples > 0) { uint32_t numSamplesIter = min(numSamples, mMaxSamplesPerCall); uint32_t nSamplesChannels = numSamplesIter * mNumChannels; - if (mPcmFormat == PCM_FORMAT_S7_24) { + if (mPcmFormat == SAMPLE_FORMAT_PCM_S7_24) { if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { mpProcessor->process( reinterpret_cast<const audio_sample_t *> (pIn), @@ -125,7 +125,7 @@ private: // sample. // numSamples The number of single-channel samples to process. void ConvertInput(const void *& pIn, uint32_t numSamples) { - if (mPcmFormat == PCM_FORMAT_S15) { + if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { const int16_t * pIn16 = reinterpret_cast<const int16_t *>(pIn); audio_sample_t * pOut = mBuffer; while (numSamples-- > 0) { @@ -143,7 +143,7 @@ private: // When function exist will point to the next output sample. // numSamples The number of single-channel samples to process. void ConvertOutput(void *& pOut, uint32_t numSamples) { - if (mPcmFormat == PCM_FORMAT_S15) { + if (mPcmFormat == SAMPLE_FORMAT_PCM_S15) { const audio_sample_t * pIn = mBuffer; int16_t * pOut16 = reinterpret_cast<int16_t *>(pOut); if (mBehavior == EFFECT_BUFFER_ACCESS_WRITE) { diff --git a/media/libeffects/AudioShelvingFilter.cpp b/media/libeffects/AudioShelvingFilter.cpp index d8abbd2c5e61..b8650bac53f2 100644 --- a/media/libeffects/AudioShelvingFilter.cpp +++ b/media/libeffects/AudioShelvingFilter.cpp @@ -50,8 +50,8 @@ AudioCoefInterpolator AudioShelvingFilter::mLoCoefInterp(2, kLoInDims, 5, (const AudioShelvingFilter::AudioShelvingFilter(ShelfType type, int nChannels, int sampleRate) - : mBiquad(nChannels, sampleRate) - , mType(type) { + : mType(type), + mBiquad(nChannels, sampleRate) { configure(nChannels, sampleRate); } diff --git a/media/libeffects/EffectEqualizer.cpp b/media/libeffects/EffectEqualizer.cpp index e39e59542766..d19c6b9fdbcb 100644 --- a/media/libeffects/EffectEqualizer.cpp +++ b/media/libeffects/EffectEqualizer.cpp @@ -39,10 +39,11 @@ const effect_descriptor_t gEqualizerDescriptor = { {0xe25aa840, 0x543b, 0x11df, 0x98a5, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid EFFECT_API_VERSION, (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST), + 0, // TODO + 1, "Graphic Equalizer", "Google Inc.", }; -static int gEffectIndex; /////////////////// BEGIN EQ PRESETS /////////////////////////////////////////// const int kNumBands = 5; @@ -101,7 +102,6 @@ struct EqualizerContext { AudioEqualizer * pEqualizer; }; - //--- local function prototypes int Equalizer_init(EqualizerContext *pContext); @@ -116,22 +116,23 @@ int Equalizer_setParameter(AudioEqualizer * pEqualizer, int32_t *pParam, void *p extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects) { *pNumEffects = 1; - gEffectIndex = 0; return 0; } /* end EffectQueryNumberEffects */ -extern "C" int EffectQueryNext(effect_descriptor_t *pDescriptor) { +extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { if (pDescriptor == NULL) { return -EINVAL; } - if (gEffectIndex++ > 0) { - return -ENOENT; + if (index > 0) { + return -EINVAL; } memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); return 0; } /* end EffectQueryNext */ extern "C" int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, effect_interface_t *pInterface) { int ret; int i; @@ -160,7 +161,7 @@ extern "C" int EffectCreate(effect_uuid_t *uuid, *pInterface = (effect_interface_t)pContext; - LOGV("EffectLibCreateEffect %p", pContext); + LOGV("EffectLibCreateEffect %p, size %d", pContext, AudioEqualizer::GetInstanceSize(kNumBands)+sizeof(EqualizerContext)); return 0; @@ -219,8 +220,8 @@ int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig) CHECK_ARG((pConfig->inputCfg.channels == CHANNEL_MONO) || (pConfig->inputCfg.channels == CHANNEL_STEREO)); CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); - CHECK_ARG(pConfig->inputCfg.format == PCM_FORMAT_S7_24 - || pConfig->inputCfg.format == PCM_FORMAT_S15); + CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S7_24 + || pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15); int channelCount; if (pConfig->inputCfg.channels == CHANNEL_MONO) { @@ -230,6 +231,8 @@ int Equalizer_configure(EqualizerContext *pContext, effect_config_t *pConfig) } CHECK_ARG(channelCount <= AudioBiquadFilter::MAX_CHANNELS); + memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + pContext->pEqualizer->configure(channelCount, pConfig->inputCfg.samplingRate); @@ -268,7 +271,7 @@ int Equalizer_init(EqualizerContext *pContext) pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; pContext->config.inputCfg.channels = CHANNEL_STEREO; - pContext->config.inputCfg.format = PCM_FORMAT_S15; + pContext->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; pContext->config.inputCfg.samplingRate = 44100; pContext->config.inputCfg.bufferProvider.getBuffer = NULL; pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; @@ -276,7 +279,7 @@ int Equalizer_init(EqualizerContext *pContext) pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; pContext->config.outputCfg.channels = CHANNEL_STEREO; - pContext->config.outputCfg.format = PCM_FORMAT_S15; + pContext->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; pContext->config.outputCfg.samplingRate = 44100; pContext->config.outputCfg.bufferProvider.getBuffer = NULL; pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; @@ -526,6 +529,7 @@ extern "C" int Equalizer_process(effect_interface_t self, audio_buffer_t *inBuff } pContext->adapter.process(inBuffer->raw, outBuffer->raw, outBuffer->frameCount); + return 0; } // end Equalizer_process @@ -589,6 +593,17 @@ extern "C" int Equalizer_command(effect_interface_t self, int cmdCode, int cmdSi *(int *)pReplyData = android::Equalizer_setParameter(pEqualizer, (int32_t *)p->data, p->data + p->psize); } break; + case EFFECT_CMD_ENABLE: + case EFFECT_CMD_DISABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_SET_DEVICE: + case EFFECT_CMD_SET_VOLUME: + case EFFECT_CMD_SET_AUDIO_MODE: + break; default: LOGW("Equalizer_command invalid command %d",cmdCode); return -EINVAL; diff --git a/media/libeffects/EffectReverb.c b/media/libeffects/EffectReverb.c index 202f50bbc7f1..ada252c917ec 100644 --- a/media/libeffects/EffectReverb.c +++ b/media/libeffects/EffectReverb.c @@ -24,8 +24,6 @@ #include "EffectReverb.h" #include "EffectsMath.h" -static int gEffectIndex; - // effect_interface_t interface implementation for reverb effect const struct effect_interface_s gReverbInterface = { Reverb_Process, @@ -37,7 +35,10 @@ static const effect_descriptor_t gAuxEnvReverbDescriptor = { {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, {0x1f0ae2e0, 0x4ef7, 0x11df, 0xbc09, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, EFFECT_API_VERSION, - EFFECT_FLAG_TYPE_AUXILIARY, + // flags other than EFFECT_FLAG_TYPE_AUXILIARY set for test purpose + EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_AUDIO_MODE_IND, + 0, // TODO + 33, "Aux Environmental Reverb", "Google Inc." }; @@ -48,6 +49,8 @@ static const effect_descriptor_t gInsertEnvReverbDescriptor = { {0xaa476040, 0x6342, 0x11df, 0x91a4, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, EFFECT_API_VERSION, EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, + 0, // TODO + 33, "Insert Environmental reverb", "Google Inc." }; @@ -58,6 +61,8 @@ static const effect_descriptor_t gAuxPresetReverbDescriptor = { {0x63909320, 0x53a6, 0x11df, 0xbdbd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, EFFECT_API_VERSION, EFFECT_FLAG_TYPE_AUXILIARY, + 0, // TODO + 33, "Aux Preset Reverb", "Google Inc." }; @@ -68,6 +73,8 @@ static const effect_descriptor_t gInsertPresetReverbDescriptor = { {0xd93dc6a0, 0x6342, 0x11df, 0xb128, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, EFFECT_API_VERSION, EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST, + 0, // TODO + 33, "Insert Preset Reverb", "Google Inc." }; @@ -77,8 +84,7 @@ static const effect_descriptor_t * const gDescriptors[] = { &gAuxEnvReverbDescriptor, &gInsertEnvReverbDescriptor, &gAuxPresetReverbDescriptor, - &gInsertPresetReverbDescriptor, - NULL + &gInsertPresetReverbDescriptor }; /*---------------------------------------------------------------------------- @@ -88,25 +94,25 @@ static const effect_descriptor_t * const gDescriptors[] = { /*--- Effect Library Interface Implementation ---*/ int EffectQueryNumberEffects(uint32_t *pNumEffects) { - *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *) - - 1; - gEffectIndex = 0; + *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); return 0; } -int EffectQueryNext(effect_descriptor_t *pDescriptor) { +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { if (pDescriptor == NULL) { return -EINVAL; } - if (gDescriptors[gEffectIndex] == NULL) { - return -ENOENT; + if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) { + return -EINVAL; } - memcpy(pDescriptor, gDescriptors[gEffectIndex++], + memcpy(pDescriptor, gDescriptors[index], sizeof(effect_descriptor_t)); return 0; } int EffectCreate(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, effect_interface_t *pInterface) { int ret; int i; @@ -152,7 +158,7 @@ int EffectCreate(effect_uuid_t *uuid, *pInterface = (effect_interface_t) module; - LOGV("EffectLibCreateEffect %p", module); + LOGV("EffectLibCreateEffect %p ,size %d", module, sizeof(reverb_module_t)); return 0; } @@ -191,8 +197,23 @@ static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, aud //if bypassed or the preset forces the signal to be completely dry if (pReverb->m_bBypass) { - if (inBuffer->raw != outBuffer->raw && !pReverb->m_Aux) { - memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount * NUM_OUTPUT_CHANNELS * sizeof(int16_t)); + if (inBuffer->raw != outBuffer->raw) { + int16_t smp; + pSrc = inBuffer->s16; + pDst = outBuffer->s16; + size_t count = inBuffer->frameCount; + if (pRvbModule->config.inputCfg.channels == pRvbModule->config.outputCfg.channels) { + count *= 2; + while (count--) { + *pDst++ = *pSrc++; + } + } else { + while (count--) { + smp = *pSrc++; + *pDst++ = smp; + *pDst++ = smp; + } + } } return 0; } @@ -226,10 +247,11 @@ static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, aud numSamples -= processedSamples; if (pReverb->m_Aux) { - pDst += processedSamples; + pSrc += processedSamples; } else { pSrc += processedSamples * NUM_OUTPUT_CHANNELS; } + pDst += processedSamples * NUM_OUTPUT_CHANNELS; } return 0; @@ -292,6 +314,35 @@ static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize, *(int *)pReplyData = Reverb_setParameter(pReverb, *(int32_t *)cmd->data, cmd->vsize, cmd->data + sizeof(int32_t)); break; + case EFFECT_CMD_ENABLE: + case EFFECT_CMD_DISABLE: + if (pReplyData == NULL || *replySize != sizeof(int)) { + return -EINVAL; + } + *(int *)pReplyData = 0; + break; + case EFFECT_CMD_SET_DEVICE: + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { + return -EINVAL; + } + LOGV("Reverb_Command EFFECT_CMD_SET_DEVICE: 0x%08x", *(uint32_t *)pCmdData); + break; + case EFFECT_CMD_SET_VOLUME: { + // audio output is always stereo => 2 channel volumes + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t) * 2) { + return -EINVAL; + } + float left = (float)(*(uint32_t *)pCmdData) / (1 << 24); + float right = (float)(*((uint32_t *)pCmdData + 1)) / (1 << 24); + LOGV("Reverb_Command EFFECT_CMD_SET_VOLUME: left %f, right %f ", left, right); + break; + } + case EFFECT_CMD_SET_AUDIO_MODE: + if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) { + return -EINVAL; + } + LOGV("Reverb_Command EFFECT_CMD_SET_AUDIO_MODE: %d", *(uint32_t *)pCmdData); + break; default: LOGW("Reverb_Command invalid command %d",cmdCode); return -EINVAL; @@ -339,7 +390,7 @@ int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset) { } else { pRvbModule->config.inputCfg.channels = CHANNEL_STEREO; } - pRvbModule->config.inputCfg.format = PCM_FORMAT_S15; + pRvbModule->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15; pRvbModule->config.inputCfg.bufferProvider.getBuffer = NULL; pRvbModule->config.inputCfg.bufferProvider.releaseBuffer = NULL; pRvbModule->config.inputCfg.bufferProvider.cookie = NULL; @@ -347,7 +398,7 @@ int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset) { pRvbModule->config.inputCfg.mask = EFFECT_CONFIG_ALL; pRvbModule->config.outputCfg.samplingRate = 44100; pRvbModule->config.outputCfg.channels = CHANNEL_STEREO; - pRvbModule->config.outputCfg.format = PCM_FORMAT_S15; + pRvbModule->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15; pRvbModule->config.outputCfg.bufferProvider.getBuffer = NULL; pRvbModule->config.outputCfg.bufferProvider.releaseBuffer = NULL; pRvbModule->config.outputCfg.bufferProvider.cookie = NULL; @@ -391,8 +442,8 @@ int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig, if (pConfig->inputCfg.samplingRate != pConfig->outputCfg.samplingRate || pConfig->outputCfg.channels != OUTPUT_CHANNELS - || pConfig->inputCfg.format != PCM_FORMAT_S15 - || pConfig->outputCfg.format != PCM_FORMAT_S15) { + || pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15 + || pConfig->outputCfg.format != SAMPLE_FORMAT_PCM_S15) { LOGV("Reverb_Configure invalid config"); return -EINVAL; } @@ -1033,6 +1084,7 @@ int Reverb_setParameter(reverb_object_t *pReverb, int32_t param, size_t size, // Convert milliseconds to => m_nRvbLpfFwd (function of m_nRvbLpfFbk) // convert ms to samples value32 = (value32 * pReverb->m_nSamplingRate) / 1000; + // calculate valid decay time range as a function of current reverb delay and // max feed back gain. Min value <=> -40dB in one pass, Max value <=> feedback gain = -1 dB // Calculate attenuation for each round in late reverb given a total attenuation of -6000 millibels. @@ -1834,7 +1886,6 @@ static int ReverbUpdateRoom(reverb_object_t *pReverb, bool fullUpdate) { //gsReverbObject.m_nXfadeInterval = pPreset->m_nXfadeInterval; pReverb->m_nXfadeCounter = pReverb->m_nXfadeInterval + 1; // force update on first iteration - pReverb->m_nCurrentRoom = pReverb->m_nNextRoom; return 0; diff --git a/media/libeffects/EffectReverb.h b/media/libeffects/EffectReverb.h index 578e09e64266..f5aadfa9cb08 100644 --- a/media/libeffects/EffectReverb.h +++ b/media/libeffects/EffectReverb.h @@ -293,8 +293,8 @@ typedef struct reverb_module_s { *------------------------------------ */ int EffectQueryNumberEffects(uint32_t *pNumEffects); -int EffectQueryNext(effect_descriptor_t *pDescriptor); -int EffectCreate(effect_uuid_t *effectUID, effect_interface_t *pInterface); +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor); +int EffectCreate(effect_uuid_t *effectUID, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface); int EffectRelease(effect_interface_t interface); static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer); diff --git a/media/libeffects/EffectsFactory.c b/media/libeffects/EffectsFactory.c index 6800765727aa..edd6184ff63d 100644 --- a/media/libeffects/EffectsFactory.c +++ b/media/libeffects/EffectsFactory.c @@ -26,11 +26,16 @@ static list_elem_t *gEffectList; // list of effect_entry_t: all currently created effects static list_elem_t *gLibraryList; // list of lib_entry_t: all currently loaded libraries static pthread_mutex_t gLibLock = PTHREAD_MUTEX_INITIALIZER; // controls access to gLibraryList +static uint32_t gNumEffects; // total number number of effects static list_elem_t *gCurLib; // current library in enumeration process static list_elem_t *gCurEffect; // current effect in enumeration process +static uint32_t gCurEffectIdx; // current effect index in enumeration process static const char * const gEffectLibPath = "/system/lib/soundfx"; // path to built-in effect libraries static int gInitDone; // true is global initialization has been preformed +static int gNextLibId; // used by loadLibrary() to allocate unique library handles +static int gCanQueryEffect; // indicates that call to EffectQueryEffect() is valid, i.e. that the list of effects + // was not modified since last call to EffectQueryNumberEffects() ///////////////////////////////////////////////// // Local functions prototypes @@ -39,7 +44,8 @@ static int gInitDone; // true is global initialization has been preformed static int init(); static int loadLibrary(const char *libPath, int *handle); static int unloadLibrary(int handle); -static uint32_t numEffectModules(); +static void resetEffectEnumeration(); +static uint32_t updateNumEffects(); static int findEffect(effect_uuid_t *uuid, lib_entry_t **lib, effect_descriptor_t **desc); static void dumpEffectDescriptor(effect_descriptor_t *desc, char *str, size_t len); @@ -107,38 +113,53 @@ int EffectQueryNumberEffects(uint32_t *pNumEffects) } pthread_mutex_lock(&gLibLock); - *pNumEffects = numEffectModules(); + *pNumEffects = gNumEffects; + gCanQueryEffect = 1; pthread_mutex_unlock(&gLibLock); LOGV("EffectQueryNumberEffects(): %d", *pNumEffects); return ret; } -int EffectQueryNext(effect_descriptor_t *pDescriptor) +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { int ret = init(); if (ret < 0) { return ret; } - if (pDescriptor == NULL) { + if (pDescriptor == NULL || + index >= gNumEffects) { return -EINVAL; } + if (gCanQueryEffect == 0) { + return -ENOSYS; + } pthread_mutex_lock(&gLibLock); ret = -ENOENT; + if (index < gCurEffectIdx) { + resetEffectEnumeration(); + } while (gCurLib) { if (gCurEffect) { - memcpy(pDescriptor, gCurEffect->object, sizeof(effect_descriptor_t)); - gCurEffect = gCurEffect->next; - ret = 0; - break; + if (index == gCurEffectIdx) { + memcpy(pDescriptor, gCurEffect->object, sizeof(effect_descriptor_t)); + ret = 0; + break; + } else { + gCurEffect = gCurEffect->next; + gCurEffectIdx++; + } } else { gCurLib = gCurLib->next; gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; } } + +#if (LOG_NDEBUG == 0) char str[256]; dumpEffectDescriptor(pDescriptor, str, 256); - LOGV("EffectQueryNext() desc:%s", str); + LOGV("EffectQueryEffect() desc:%s", str); +#endif pthread_mutex_unlock(&gLibLock); return ret; } @@ -164,7 +185,7 @@ int EffectGetDescriptor(effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) return ret; } -int EffectCreate(effect_uuid_t *uuid, effect_interface_t *pInterface) +int EffectCreate(effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface) { list_elem_t *e = gLibraryList; lib_entry_t *l = NULL; @@ -198,9 +219,9 @@ int EffectCreate(effect_uuid_t *uuid, effect_interface_t *pInterface) } // create effect in library - ret = l->createFx(uuid, &itfe); - if (ret < 0) { - LOGW("EffectCreate() library %s: could not create fx %s", l->path, d->name); + ret = l->createFx(uuid, sessionId, ioId, &itfe); + if (ret != 0) { + LOGW("EffectCreate() library %s: could not create fx %s, error %d", l->path, d->name, ret); goto exit; } @@ -282,7 +303,10 @@ int EffectLoadLibrary(const char *libPath, int *handle) if (libPath == NULL) { return -EINVAL; } - return loadLibrary(libPath, handle); + + ret = loadLibrary(libPath, handle); + updateNumEffects(); + return ret; } int EffectUnloadLibrary(int handle) @@ -292,7 +316,9 @@ int EffectUnloadLibrary(int handle) return ret; } - return unloadLibrary(handle); + ret = unloadLibrary(handle); + updateNumEffects(); + return ret; } int EffectIsNullUuid(effect_uuid_t *uuid) @@ -339,7 +365,7 @@ int init() { } } closedir(dir); - + updateNumEffects(); gInitDone = 1; LOGV("init() done"); return 0; @@ -350,7 +376,7 @@ int loadLibrary(const char *libPath, int *handle) { void *hdl; effect_QueryNumberEffects_t queryNumFx; - effect_QueryNextEffect_t queryFx; + effect_QueryEffect_t queryFx; effect_CreateEffect_t createFx; effect_ReleaseEffect_t releaseFx; uint32_t numFx; @@ -378,9 +404,9 @@ int loadLibrary(const char *libPath, int *handle) ret = -ENODEV; goto error; } - queryFx = (effect_QueryNextEffect_t)dlsym(hdl, "EffectQueryNext"); + queryFx = (effect_QueryEffect_t)dlsym(hdl, "EffectQueryEffect"); if (queryFx == NULL) { - LOGW("could not get EffectQueryNext from lib %s", libPath); + LOGW("could not get EffectQueryEffect from lib %s", libPath); ret = -ENODEV; goto error; } @@ -409,7 +435,7 @@ int loadLibrary(const char *libPath, int *handle) ret = -ENOMEM; goto error; } - ret = queryFx(d); + ret = queryFx(fx, d); if (ret == 0) { #if (LOG_NDEBUG==0) char s[256]; @@ -434,8 +460,12 @@ int loadLibrary(const char *libPath, int *handle) LOGW("Error querying effect # %d on lib %s", fx, libPath); } } + + pthread_mutex_lock(&gLibLock); + // add entry for library in gLibraryList l = malloc(sizeof(lib_entry_t)); + l->id = ++gNextLibId; l->handle = hdl; strncpy(l->path, libPath, PATH_MAX); l->createFx = createFx; @@ -444,14 +474,13 @@ int loadLibrary(const char *libPath, int *handle) pthread_mutex_init(&l->lock, NULL); e = malloc(sizeof(list_elem_t)); - pthread_mutex_lock(&gLibLock); e->next = gLibraryList; e->object = l; gLibraryList = e; pthread_mutex_unlock(&gLibLock); LOGV("loadLibrary() linked library %p", l); - *handle = (int)hdl; + *handle = l->id; return 0; @@ -480,7 +509,7 @@ int unloadLibrary(int handle) el2 = NULL; while (el1) { l = (lib_entry_t *)el1->object; - if (handle == (int)l->handle) { + if (handle == l->id) { if (el2) { el2->next = el1->next; } else { @@ -508,6 +537,7 @@ int unloadLibrary(int handle) // disable all effects from this library pthread_mutex_lock(&l->lock); + el1 = gEffectList; while (el1) { fx = (effect_entry_t *)el1->object; @@ -523,17 +553,23 @@ int unloadLibrary(int handle) return 0; } +void resetEffectEnumeration() +{ + gCurLib = gLibraryList; + gCurEffect = NULL; + if (gCurLib) { + gCurEffect = ((lib_entry_t *)gCurLib->object)->effects; + } + gCurEffectIdx = 0; +} - -uint32_t numEffectModules() { - list_elem_t *e = gLibraryList; +uint32_t updateNumEffects() { + list_elem_t *e; uint32_t cnt = 0; - // Reset pointers for EffectQueryNext() - gCurLib = e; - if (e) { - gCurEffect = ((lib_entry_t *)e->object)->effects; - } + resetEffectEnumeration(); + + e = gLibraryList; while (e) { lib_entry_t *l = (lib_entry_t *)e->object; list_elem_t *efx = l->effects; @@ -543,6 +579,8 @@ uint32_t numEffectModules() { } e = e->next; } + gNumEffects = cnt; + gCanQueryEffect = 0; return cnt; } diff --git a/media/libeffects/EffectsFactory.h b/media/libeffects/EffectsFactory.h index 17ad3f01681b..8f543ca5cc3b 100644 --- a/media/libeffects/EffectsFactory.h +++ b/media/libeffects/EffectsFactory.h @@ -20,7 +20,7 @@ #include <cutils/log.h> #include <pthread.h> #include <dirent.h> -#include <media/EffectFactoryApi.h> +#include <media/EffectsFactoryApi.h> #if __cplusplus @@ -35,6 +35,7 @@ typedef struct list_elem_s { typedef struct lib_entry_s { char path[PATH_MAX]; void *handle; + int id; effect_CreateEffect_t createFx; effect_ReleaseEffect_t releaseFx; list_elem_t *effects; //list of effect_descriptor_t diff --git a/media/libmedia/AudioEffect.cpp b/media/libmedia/AudioEffect.cpp index 864821171fba..4afa2dc62a69 100644 --- a/media/libmedia/AudioEffect.cpp +++ b/media/libmedia/AudioEffect.cpp @@ -394,11 +394,11 @@ status_t AudioEffect::queryNumberEffects(uint32_t *numEffects) return af->queryNumberEffects(numEffects); } -status_t AudioEffect::queryNextEffect(effect_descriptor_t *descriptor) +status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descriptor) { const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); if (af == 0) return PERMISSION_DENIED; - return af->queryNextEffect(descriptor); + return af->queryEffect(index, descriptor); } status_t AudioEffect::getEffectDescriptor(effect_uuid_t *uuid, effect_descriptor_t *descriptor) diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp index f2a8db390c30..7d6a5d347666 100644 --- a/media/libmedia/IAudioFlinger.cpp +++ b/media/libmedia/IAudioFlinger.cpp @@ -67,7 +67,7 @@ enum { LOAD_EFFECT_LIBRARY, UNLOAD_EFFECT_LIBRARY, QUERY_NUM_EFFECTS, - QUERY_NEXT_EFFECT, + QUERY_EFFECT, GET_EFFECT_DESCRIPTOR, CREATE_EFFECT }; @@ -586,14 +586,15 @@ public: return NO_ERROR; } - virtual status_t queryNextEffect(effect_descriptor_t *pDescriptor) + virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) { if (pDescriptor == NULL) { return BAD_VALUE; } Parcel data, reply; data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor()); - status_t status = remote()->transact(QUERY_NEXT_EFFECT, data, &reply); + data.writeInt32(index); + status_t status = remote()->transact(QUERY_EFFECT, data, &reply); if (status != NO_ERROR) { return status; } @@ -980,10 +981,10 @@ status_t BnAudioFlinger::onTransact( } return NO_ERROR; } - case QUERY_NEXT_EFFECT: { + case QUERY_EFFECT: { CHECK_INTERFACE(IAudioFlinger, data, reply); effect_descriptor_t desc; - status_t status = queryNextEffect(&desc); + status_t status = queryEffect(data.readInt32(), &desc); reply->writeInt32(status); if (status == NO_ERROR) { reply->write(&desc, sizeof(effect_descriptor_t)); |