diff options
27 files changed, 2729 insertions, 1206 deletions
@@ -1,6 +1,7 @@ # Copyright 2006 The Android Open Source Project # Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand. +SUBDIR_MAKEFILES := $(call all-named-subdir-makefiles,modules tests) LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) @@ -9,30 +10,15 @@ LOCAL_SHARED_LIBRARIES := libcutils LOCAL_INCLUDES += $(LOCAL_PATH) -ifneq ($(TARGET_SIMULATOR),true) - LOCAL_CFLAGS += -DQEMU_HARDWARE - QEMU_HARDWARE := true -endif +LOCAL_CFLAGS += -DQEMU_HARDWARE +QEMU_HARDWARE := true -ifneq ($(TARGET_SIMULATOR),true) LOCAL_SHARED_LIBRARIES += libdl -endif LOCAL_SRC_FILES += hardware.c -# need "-lrt" on Linux simulator to pick up clock_gettime -ifeq ($(TARGET_SIMULATOR),true) - ifeq ($(HOST_OS),linux) - LOCAL_LDLIBS += -lrt -lpthread -ldl - endif -endif - LOCAL_MODULE:= libhardware include $(BUILD_SHARED_LIBRARY) -include $(addsuffix /Android.mk, $(addprefix $(LOCAL_PATH)/, \ - modules/gralloc \ - tests \ - )) -
\ No newline at end of file +include $(SUBDIR_MAKEFILES) @@ -117,13 +117,20 @@ static int load(const char *id, return status; } -int hw_get_module(const char *id, const struct hw_module_t **module) +int hw_get_module_by_class(const char *class_id, const char *inst, + const struct hw_module_t **module) { int status; int i; const struct hw_module_t *hmi = NULL; char prop[PATH_MAX]; char path[PATH_MAX]; + char name[PATH_MAX]; + + if (inst) + snprintf(name, PATH_MAX, "%s.%s", class_id, inst); + else + strlcpy(name, class_id, PATH_MAX); /* * Here we rely on the fact that calling dlopen multiple times on @@ -139,15 +146,15 @@ int hw_get_module(const char *id, const struct hw_module_t **module) continue; } snprintf(path, sizeof(path), "%s/%s.%s.so", - HAL_LIBRARY_PATH1, id, prop); + HAL_LIBRARY_PATH2, name, prop); if (access(path, R_OK) == 0) break; snprintf(path, sizeof(path), "%s/%s.%s.so", - HAL_LIBRARY_PATH2, id, prop); + HAL_LIBRARY_PATH1, name, prop); if (access(path, R_OK) == 0) break; } else { snprintf(path, sizeof(path), "%s/%s.default.so", - HAL_LIBRARY_PATH1, id); + HAL_LIBRARY_PATH1, name); if (access(path, R_OK) == 0) break; } } @@ -156,8 +163,13 @@ int hw_get_module(const char *id, const struct hw_module_t **module) if (i < HAL_VARIANT_KEYS_COUNT+1) { /* load the module, if this fails, we're doomed, and we should not try * to load a different variant. */ - status = load(id, path, module); + status = load(class_id, path, module); } return status; } + +int hw_get_module(const char *id, const struct hw_module_t **module) +{ + return hw_get_module_by_class(id, NULL, module); +} diff --git a/include/hardware/audio.h b/include/hardware/audio.h index 36ff3995..2d7f39d1 100644 --- a/include/hardware/audio.h +++ b/include/hardware/audio.h @@ -43,13 +43,38 @@ __BEGIN_DECLS /**************************************/ -/* standard audio parameters that the HAL may need to handle */ +/** + * standard audio parameters that the HAL may need to handle + */ + +/** + * audio device parameters + */ + +/* BT SCO Noise Reduction + Echo Cancellation parameters */ +#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec" +#define AUDIO_PARAMETER_VALUE_ON "on" +#define AUDIO_PARAMETER_VALUE_OFF "off" + +/* TTY mode selection */ +#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode" +#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off" +#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco" +#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco" +#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full" + +/** + * audio stream parameters + */ + #define AUDIO_PARAMETER_STREAM_ROUTING "routing" #define AUDIO_PARAMETER_STREAM_FORMAT "format" #define AUDIO_PARAMETER_STREAM_CHANNELS "channels" #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" +/**************************************/ + /* common audio stream parameters and operations */ struct audio_stream { diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h index 540f5ed4..5adab12b 100644 --- a/include/hardware/audio_effect.h +++ b/include/hardware/audio_effect.h @@ -14,9 +14,884 @@ * limitations under the License. */ + #ifndef ANDROID_AUDIO_EFFECT_H #define ANDROID_AUDIO_EFFECT_H -typedef void *effect_handle_t; +#include <errno.h> +#include <stdint.h> +#include <strings.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +#include <cutils/bitops.h> + +#include <system/audio.h> + + +__BEGIN_DECLS + + +///////////////////////////////////////////////// +// Common Definitions +///////////////////////////////////////////////// + +// +//--- 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) +// 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 as uuid, it should be a unique UUID for this particular implementation. +typedef struct effect_uuid_s { + uint32_t timeLow; + uint16_t timeMid; + uint16_t timeHiAndVersion; + uint16_t clockSeq; + uint8_t node[6]; +} effect_uuid_t; + +// Maximum length of character strings in structures defines by this API. +#define EFFECT_STRING_LEN_MAX 64 + +// NULL UUID definition (matches SL_IID_NULL_) +#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 +// engines present in a library. +typedef struct effect_descriptor_s { + effect_uuid_t type; // UUID of to the OpenSL ES interface implemented by this effect + effect_uuid_t uuid; // UUID for this particular implementation + uint32_t apiVersion; // Version of the effect control API implemented + uint32_t flags; // effect engine capabilities/requirements flags (see below) + 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; + +// 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 +// +---------------------------+-----------+----------------------------------- +// | connection mode | 0..2 | 0 insert: after track process +// | | | 1 auxiliary: connect to track auxiliary +// | | | output and use send level +// | | | 2 replace: replaces track process function; +// | | | must implement SRC, volume and mono to stereo. +// | | | 3 pre processing: applied below audio HAL on input +// | | | 4 post processing: applied below audio HAL on output +// | | | 5 - 7 reserved +// +---------------------------+-----------+----------------------------------- +// | insertion preference | 3..5 | 0 none +// | | | 1 first of the chain +// | | | 2 last of the chain +// | | | 3 exclusive (only effect in the insert chain) +// | | | 4..7 reserved +// +---------------------------+-----------+----------------------------------- +// | Volume management | 6..8 | 0 none +// | | | 1 implements volume control +// | | | 2 requires volume indication +// | | | 4 reserved +// +---------------------------+-----------+----------------------------------- +// | Device indication | 9..11 | 0 none +// | | | 1 requires device updates +// | | | 2, 4 reserved +// +---------------------------+-----------+----------------------------------- +// | Sample input mode | 12..13 | 1 direct: process() function or EFFECT_CMD_CONFIGURE +// | | | command must specify a buffer descriptor +// | | | 2 provider: process() function uses the +// | | | bufferProvider indicated by the +// | | | EFFECT_CMD_CONFIGURE command to request input. +// | | | buffers. +// | | | 3 both: both input modes are supported +// +---------------------------+-----------+----------------------------------- +// | Sample output mode | 14..15 | 1 direct: process() function or EFFECT_CMD_CONFIGURE +// | | | command must specify a buffer descriptor +// | | | 2 provider: process() function uses the +// | | | bufferProvider indicated by the +// | | | EFFECT_CMD_CONFIGURE command to request output +// | | | buffers. +// | | | 3 both: both output modes are supported +// +---------------------------+-----------+----------------------------------- +// | Hardware acceleration | 16..17 | 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 | 18..19 | 0 none +// | | | 1 requires audio mode updates +// | | | 2..3 reserved +// +---------------------------+-----------+----------------------------------- + +// Insert mode +#define EFFECT_FLAG_TYPE_SHIFT 0 +#define EFFECT_FLAG_TYPE_SIZE 3 +#define EFFECT_FLAG_TYPE_MASK (((1 << EFFECT_FLAG_TYPE_SIZE) -1) \ + << EFFECT_FLAG_TYPE_SHIFT) +#define EFFECT_FLAG_TYPE_INSERT (0 << EFFECT_FLAG_TYPE_SHIFT) +#define EFFECT_FLAG_TYPE_AUXILIARY (1 << EFFECT_FLAG_TYPE_SHIFT) +#define EFFECT_FLAG_TYPE_REPLACE (2 << EFFECT_FLAG_TYPE_SHIFT) +#define EFFECT_FLAG_TYPE_PRE_PROC (3 << EFFECT_FLAG_TYPE_SHIFT) +#define EFFECT_FLAG_TYPE_POST_PROC (4 << EFFECT_FLAG_TYPE_SHIFT) + +// Insert preference +#define EFFECT_FLAG_INSERT_SHIFT (EFFECT_FLAG_TYPE_SHIFT + EFFECT_FLAG_TYPE_SIZE) +#define EFFECT_FLAG_INSERT_SIZE 3 +#define EFFECT_FLAG_INSERT_MASK (((1 << EFFECT_FLAG_INSERT_SIZE) -1) \ + << EFFECT_FLAG_INSERT_SHIFT) +#define EFFECT_FLAG_INSERT_ANY (0 << EFFECT_FLAG_INSERT_SHIFT) +#define EFFECT_FLAG_INSERT_FIRST (1 << EFFECT_FLAG_INSERT_SHIFT) +#define EFFECT_FLAG_INSERT_LAST (2 << EFFECT_FLAG_INSERT_SHIFT) +#define EFFECT_FLAG_INSERT_EXCLUSIVE (3 << EFFECT_FLAG_INSERT_SHIFT) + + +// Volume control +#define EFFECT_FLAG_VOLUME_SHIFT (EFFECT_FLAG_INSERT_SHIFT + EFFECT_FLAG_INSERT_SIZE) +#define EFFECT_FLAG_VOLUME_SIZE 3 +#define EFFECT_FLAG_VOLUME_MASK (((1 << EFFECT_FLAG_VOLUME_SIZE) -1) \ + << EFFECT_FLAG_VOLUME_SHIFT) +#define EFFECT_FLAG_VOLUME_CTRL (1 << EFFECT_FLAG_VOLUME_SHIFT) +#define EFFECT_FLAG_VOLUME_IND (2 << EFFECT_FLAG_VOLUME_SHIFT) +#define EFFECT_FLAG_VOLUME_NONE (0 << EFFECT_FLAG_VOLUME_SHIFT) + +// Device indication +#define EFFECT_FLAG_DEVICE_SHIFT (EFFECT_FLAG_VOLUME_SHIFT + EFFECT_FLAG_VOLUME_SIZE) +#define EFFECT_FLAG_DEVICE_SIZE 3 +#define EFFECT_FLAG_DEVICE_MASK (((1 << EFFECT_FLAG_DEVICE_SIZE) -1) \ + << EFFECT_FLAG_DEVICE_SHIFT) +#define EFFECT_FLAG_DEVICE_IND (1 << EFFECT_FLAG_DEVICE_SHIFT) +#define EFFECT_FLAG_DEVICE_NONE (0 << EFFECT_FLAG_DEVICE_SHIFT) + +// Sample input modes +#define EFFECT_FLAG_INPUT_SHIFT (EFFECT_FLAG_DEVICE_SHIFT + EFFECT_FLAG_DEVICE_SIZE) +#define EFFECT_FLAG_INPUT_SIZE 2 +#define EFFECT_FLAG_INPUT_MASK (((1 << EFFECT_FLAG_INPUT_SIZE) -1) \ + << EFFECT_FLAG_INPUT_SHIFT) +#define EFFECT_FLAG_INPUT_DIRECT (1 << EFFECT_FLAG_INPUT_SHIFT) +#define EFFECT_FLAG_INPUT_PROVIDER (2 << EFFECT_FLAG_INPUT_SHIFT) +#define EFFECT_FLAG_INPUT_BOTH (3 << EFFECT_FLAG_INPUT_SHIFT) + +// Sample output modes +#define EFFECT_FLAG_OUTPUT_SHIFT (EFFECT_FLAG_INPUT_SHIFT + EFFECT_FLAG_INPUT_SIZE) +#define EFFECT_FLAG_OUTPUT_SIZE 2 +#define EFFECT_FLAG_OUTPUT_MASK (((1 << EFFECT_FLAG_OUTPUT_SIZE) -1) \ + << EFFECT_FLAG_OUTPUT_SHIFT) +#define EFFECT_FLAG_OUTPUT_DIRECT (1 << EFFECT_FLAG_OUTPUT_SHIFT) +#define EFFECT_FLAG_OUTPUT_PROVIDER (2 << EFFECT_FLAG_OUTPUT_SHIFT) +#define EFFECT_FLAG_OUTPUT_BOTH (3 << EFFECT_FLAG_OUTPUT_SHIFT) + +// Hardware acceleration mode +#define EFFECT_FLAG_HW_ACC_SHIFT (EFFECT_FLAG_OUTPUT_SHIFT + EFFECT_FLAG_OUTPUT_SIZE) +#define EFFECT_FLAG_HW_ACC_SIZE 2 +#define EFFECT_FLAG_HW_ACC_MASK (((1 << EFFECT_FLAG_HW_ACC_SIZE) -1) \ + << EFFECT_FLAG_HW_ACC_SHIFT) +#define EFFECT_FLAG_HW_ACC_SIMPLE (1 << EFFECT_FLAG_HW_ACC_SHIFT) +#define EFFECT_FLAG_HW_ACC_TUNNEL (2 << EFFECT_FLAG_HW_ACC_SHIFT) + +// Audio mode indication +#define EFFECT_FLAG_AUDIO_MODE_SHIFT (EFFECT_FLAG_HW_ACC_SHIFT + EFFECT_FLAG_HW_ACC_SIZE) +#define EFFECT_FLAG_AUDIO_MODE_SIZE 2 +#define EFFECT_FLAG_AUDIO_MODE_MASK (((1 << EFFECT_FLAG_AUDIO_MODE_SIZE) -1) \ + << EFFECT_FLAG_AUDIO_MODE_SHIFT) +#define EFFECT_FLAG_AUDIO_MODE_IND (1 << EFFECT_FLAG_AUDIO_MODE_SHIFT) +#define EFFECT_FLAG_AUDIO_MODE_NONE (0 << EFFECT_FLAG_AUDIO_MODE_SHIFT) + + +#define EFFECT_MAKE_API_VERSION(M, m) (((M)<<16) | ((m) & 0xFFFF)) +#define EFFECT_API_VERSION_MAJOR(v) ((v)>>16) +#define EFFECT_API_VERSION_MINOR(v) ((m) & 0xFFFF) + + + +///////////////////////////////////////////////// +// Effect control interface +///////////////////////////////////////////////// + +// Effect control interface version 2.0 +#define EFFECT_CONTROL_API_VERSION EFFECT_MAKE_API_VERSION(2,0) + +// Effect control interface structure: effect_interface_s +// The effect control interface is exposed by each effect engine implementation. It consists of +// a set of functions controlling the configuration, activation and process of the engine. +// The functions are grouped in a structure of type effect_interface_s. +// +// Effect control interface handle: effect_handle_t +// The effect_handle_t serves two purposes regarding the implementation of the effect engine: +// - 1 it is the address of a pointer to an effect_interface_s structure where the functions +// of the effect control API for a particular effect are located. +// - 2 it is the address of the context of a particular effect instance. +// A typical implementation in the effect library would define a structure as follows: +// struct effect_module_s { +// const struct effect_interface_s *itfe; +// effect_config_t config; +// effect_context_t context; +// } +// The implementation of EffectCreate() function would then allocate a structure of this +// type and return its address as effect_handle_t +typedef struct effect_interface_s **effect_handle_t; + + +// Forward definition of type audio_buffer_t +typedef struct audio_buffer_s audio_buffer_t; + + + + + + +// Effect control interface definition +struct effect_interface_s { + //////////////////////////////////////////////////////////////////////////////// + // + // Function: process + // + // Description: Effect process function. Takes input samples as specified + // (count and location) in input buffer descriptor and output processed + // samples as specified in output buffer descriptor. If the buffer descriptor + // is not specified the function must use either the buffer or the + // buffer provider function installed by the EFFECT_CMD_CONFIGURE command. + // The effect framework will call the process() function after the EFFECT_CMD_ENABLE + // command is received and until the EFFECT_CMD_DISABLE is received. When the engine + // receives the EFFECT_CMD_DISABLE command it should turn off the effect gracefully + // and when done indicate that it is OK to stop calling the process() function by + // returning the -ENODATA status. + // + // NOTE: the process() function implementation should be "real-time safe" that is + // it should not perform blocking calls: malloc/free, sleep, read/write/open/close, + // pthread_cond_wait/pthread_mutex_lock... + // + // Input: + // self: handle to the effect interface this function + // is called on. + // inBuffer: buffer descriptor indicating where to read samples to process. + // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command. + // + // outBuffer: buffer descriptor indicating where to write processed samples. + // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE command. + // + // Output: + // returned value: 0 successful operation + // -ENODATA the engine has finished the disable phase and the framework + // can stop calling process() + // -EINVAL invalid interface handle or + // invalid input/output buffer description + //////////////////////////////////////////////////////////////////////////////// + int32_t (*process)(effect_handle_t self, + audio_buffer_t *inBuffer, + audio_buffer_t *outBuffer); + //////////////////////////////////////////////////////////////////////////////// + // + // Function: command + // + // Description: Send a command and receive a response to/from effect engine. + // + // Input: + // self: handle to the effect interface this function + // is called on. + // cmdCode: command code: the command can be a standardized command defined in + // effect_command_e (see below) or a proprietary command. + // cmdSize: size of command in bytes + // pCmdData: pointer to command data + // pReplyData: pointer to reply data + // + // Input/Output: + // replySize: maximum size of reply data as input + // actual size of reply data as output + // + // Output: + // returned value: 0 successful operation + // -EINVAL invalid interface handle or + // invalid command/reply size or format according to command code + // The return code should be restricted to indicate problems related to the this + // API specification. Status related to the execution of a particular command should be + // indicated as part of the reply field. + // + // *pReplyData updated with command response + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*command)(effect_handle_t self, + uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t *replySize, + void *pReplyData); + //////////////////////////////////////////////////////////////////////////////// + // + // Function: get_descriptor + // + // Description: Returns the effect descriptor + // + // Input: + // self: handle to the effect interface this function + // is called on. + // + // Input/Output: + // pDescriptor: address where to return the effect descriptor. + // + // Output: + // returned value: 0 successful operation. + // -EINVAL invalid interface handle or invalid pDescriptor + // *pDescriptor: updated with the effect descriptor. + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*get_descriptor)(effect_handle_t self, + effect_descriptor_t *pDescriptor); + //////////////////////////////////////////////////////////////////////////////// + // + // Function: process_reverse + // + // Description: Process reverse stream function. This function is used to pass + // a reference stream to the effect engine. If the engine does not need a reference + // stream, this function pointer can be set to NULL. + // This function would typically implemented by an Echo Canceler. + // + // Input: + // self: handle to the effect interface this function + // is called on. + // inBuffer: buffer descriptor indicating where to read samples to process. + // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE_REVERSE command. + // + // outBuffer: buffer descriptor indicating where to write processed samples. + // If NULL, use the configuration passed by EFFECT_CMD_CONFIGURE_REVERSE command. + // If the buffer and buffer provider in the configuration received by + // EFFECT_CMD_CONFIGURE_REVERSE are also NULL, do not return modified reverse + // stream data + // + // Output: + // returned value: 0 successful operation + // -ENODATA the engine has finished the disable phase and the framework + // can stop calling process_reverse() + // -EINVAL invalid interface handle or + // invalid input/output buffer description + //////////////////////////////////////////////////////////////////////////////// + int32_t (*process_reverse)(effect_handle_t self, + audio_buffer_t *inBuffer, + audio_buffer_t *outBuffer); +}; + + +// +//--- 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) + EFFECT_CMD_RESET, // reset effect engine + EFFECT_CMD_ENABLE, // enable effect process + EFFECT_CMD_DISABLE, // disable effect process + EFFECT_CMD_SET_PARAM, // set parameter immediately (see effect_param_t) + 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.h, audio_devices_t) + EFFECT_CMD_SET_VOLUME, // set volume + EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) + EFFECT_CMD_CONFIGURE_REVERSE, // configure effect engine reverse stream(see effect_config_t) + EFFECT_CMD_SET_INPUT_DEVICE, // set capture device (see audio.h, audio_devices_t) + EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code +}; + +//================================================================================================== +// 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.h, audio_devices_t +// 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: uint32_t +//-------------------------------------------------------------------------------------------------- +// 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 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_CONFIGURE_REVERSE +//-------------------------------------------------------------------------------------------------- +// description: +// Apply new audio parameters configurations for input and output buffers of reverse stream +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_config_t) +// data: effect_config_t +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_SET_INPUT_DEVICE +//-------------------------------------------------------------------------------------------------- +// description: +// Set the capture device the audio input path is connected to. See audio.h, audio_devices_t +// 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: uint32_t +//-------------------------------------------------------------------------------------------------- +// 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.h, audio_channels_t 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. 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 { + void* raw; // raw pointer to start of buffer + int32_t* s32; // pointer to signed 32 bit data at start of buffer + int16_t* s16; // pointer to signed 16 bit data at start of buffer + uint8_t* u8; // pointer to unsigned 8 bit data at start of buffer + }; +}; + +// 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 +// should read from or written to by process() function. +// The releaseBuffer() function MUST be called when the buffer retrieved +// with getBuffer() is not needed anymore. +// The process function should use the buffer provider mechanism to retrieve +// input or output buffer if the inBuffer or outBuffer passed as argument is NULL +// and the buffer configuration (buffer_config_t) given by the EFFECT_CMD_CONFIGURE +// command did not specify an audio buffer. + +typedef int32_t (* buffer_function_t)(void *cookie, audio_buffer_t *buffer); + +typedef struct buffer_provider_s { + buffer_function_t getBuffer; // retrieve next buffer + buffer_function_t releaseBuffer; // release used buffer + 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 +// passed by the EFFECT_CMD_CONFIGURE or EFFECT_CMD_CONFIGURE_REVERSE command. +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_t in audio.h) + buffer_provider_t bufferProvider; // buffer provider + uint8_t format; // Audio format (see see audio_format_t in audio.h) + 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: +// overwrite, read only, accumulate (read/modify/write) +enum effect_buffer_access_e { + EFFECT_BUFFER_ACCESS_WRITE, + EFFECT_BUFFER_ACCESS_READ, + EFFECT_BUFFER_ACCESS_ACCUMULATE + +}; + +// 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 +#define EFFECT_CONFIG_CHANNELS 0x0004 // channels field must be taken into account +#define EFFECT_CONFIG_FORMAT 0x0008 // format field must be taken into account +#define EFFECT_CONFIG_ACC_MODE 0x0010 // accessMode field must be taken into account +#define EFFECT_CONFIG_PROVIDER 0x0020 // bufferProvider field must be taken into account +#define EFFECT_CONFIG_ALL (EFFECT_CONFIG_BUFFER | EFFECT_CONFIG_SMP_RATE | \ + 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. +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. +// +// NOTE: the start of value field inside the data field is always on a 32 bit boundary: +// +// +-----------+ +// | status | sizeof(int) +// +-----------+ +// | psize | sizeof(int) +// +-----------+ +// | vsize | sizeof(int) +// +-----------+ +// | | | | +// ~ parameter ~ > psize | +// | | | > ((psize - 1)/sizeof(int) + 1) * sizeof(int) +// +-----------+ | +// | padding | | +// +-----------+ +// | | | +// ~ value ~ > vsize +// | | | +// +-----------+ + +typedef struct effect_param_s { + int32_t status; // Transaction status (unused for command, used for reply) + uint32_t psize; // Parameter size + uint32_t vsize; // Value size + char data[]; // Start of Parameter + Value data +} effect_param_t; + + + +///////////////////////////////////////////////// +// Effect library interface +///////////////////////////////////////////////// + +// Effect library interface version 2.0 +#define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(2,0) + +#define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T')) + +// Every effect library must have a data structure named AUDIO_EFFECT_LIBRARY_INFO_SYM +// and the fields of this data structure must begin with audio_effect_library_t + +typedef struct audio_effect_library_s { + // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG + uint32_t tag; + // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor + uint32_t version; + // Name of this library + const char *name; + // Author/owner/implementor of the library + const char *implementor; + + //////////////////////////////////////////////////////////////////////////////// + // + // Function: query_num_effects + // + // 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 EffectQueryEffect() + // is used to enumerate all effects present in the library. + // + // Input/Output: + // pNumEffects: address where the number of effects should be returned. + // + // Output: + // returned value: 0 successful operation. + // -ENODEV library failed to initialize + // -EINVAL invalid pNumEffects + // *pNumEffects: updated with number of effects in library + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*query_num_effects)(uint32_t *pNumEffects); + + //////////////////////////////////////////////////////////////////////////////// + // + // Function: query_effect + // + // Description: Returns the descriptor of the effect engine which index is + // given as argument. + // See effect_descriptor_t for details on effect descriptors. + // This function together with EffectQueryNumberEffects() is used to enumerate all + // effects present in the library. The enumeration sequence is: + // EffectQueryNumberEffects(&num_effects); + // 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 or index + // -ENOSYS effect list has changed since last execution of + // EffectQueryNumberEffects() + // -ENOENT no more effect available + // *pDescriptor: updated with the effect descriptor. + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*query_effect)(uint32_t index, + effect_descriptor_t *pDescriptor); + + //////////////////////////////////////////////////////////////////////////////// + // + // Function: create_effect + // + // Description: Creates an effect engine of the specified implementation uuid and + // returns an effect control interface on this engine. The function will allocate the + // resources for an instance of the requested effect engine and return + // a handle on the effect control interface. + // + // Input: + // 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: + // pHandle: address where to return the effect interface handle. + // + // Output: + // returned value: 0 successful operation. + // -ENODEV library failed to initialize + // -EINVAL invalid pEffectUuid or pHandle + // -ENOENT no effect with this uuid found + // *pHandle: updated with the effect interface handle. + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*create_effect)(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_handle_t *pHandle); + + //////////////////////////////////////////////////////////////////////////////// + // + // Function: release_effect + // + // Description: Releases the effect engine whose handle is given as argument. + // All resources allocated to this particular instance of the effect are + // released. + // + // Input: + // handle: handle on the effect interface to be released. + // + // Output: + // returned value: 0 successful operation. + // -ENODEV library failed to initialize + // -EINVAL invalid interface handle + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*release_effect)(effect_handle_t handle); + + //////////////////////////////////////////////////////////////////////////////// + // + // Function: get_descriptor + // + // Description: Returns the descriptor of the effect engine which implementation UUID is + // given as argument. + // + // Input/Output: + // uuid: pointer to the effect uuid. + // pDescriptor: address where to return the effect descriptor. + // + // Output: + // returned value: 0 successful operation. + // -ENODEV library failed to initialize + // -EINVAL invalid pDescriptor or uuid + // *pDescriptor: updated with the effect descriptor. + // + //////////////////////////////////////////////////////////////////////////////// + int32_t (*get_descriptor)(effect_uuid_t *uuid, + effect_descriptor_t *pDescriptor); +} audio_effect_library_t; + +// Name of the hal_module_info +#define AUDIO_EFFECT_LIBRARY_INFO_SYM AELI + +// Name of the hal_module_info as a string +#define AUDIO_EFFECT_LIBRARY_INFO_SYM_AS_STR "AELI" + +__END_DECLS #endif // ANDROID_AUDIO_EFFECT_H diff --git a/include/hardware/audio_policy.h b/include/hardware/audio_policy.h new file mode 100644 index 00000000..fc56e5ef --- /dev/null +++ b/include/hardware/audio_policy.h @@ -0,0 +1,386 @@ +/* + * Copyright (C) 2011 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_AUDIO_POLICY_INTERFACE_H +#define ANDROID_AUDIO_POLICY_INTERFACE_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +#include <hardware/hardware.h> + +#include <system/audio.h> +#include <system/audio_policy.h> + +__BEGIN_DECLS + +/** + * The id of this module + */ +#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy" + +/** + * Name of the audio devices to open + */ +#define AUDIO_POLICY_INTERFACE "policy" + +/* ---------------------------------------------------------------------------- */ + +/* + * The audio_policy and audio_policy_service_ops structs define the + * communication interfaces between the platform specific audio policy manager + * and Android generic audio policy manager. + * The platform specific audio policy manager must implement methods of the + * audio_policy struct. + * This implementation makes use of the audio_policy_service_ops to control + * the activity and configuration of audio input and output streams. + * + * The platform specific audio policy manager is in charge of the audio + * routing and volume control policies for a given platform. + * The main roles of this module are: + * - keep track of current system state (removable device connections, phone + * state, user requests...). + * System state changes and user actions are notified to audio policy + * manager with methods of the audio_policy. + * + * - process get_output() queries received when AudioTrack objects are + * created: Those queries return a handler on an output that has been + * selected, configured and opened by the audio policy manager and that + * must be used by the AudioTrack when registering to the AudioFlinger + * with the createTrack() method. + * When the AudioTrack object is released, a release_output() query + * is received and the audio policy manager can decide to close or + * reconfigure the output depending on other streams using this output and + * current system state. + * + * - similarly process get_input() and release_input() queries received from + * AudioRecord objects and configure audio inputs. + * - process volume control requests: the stream volume is converted from + * an index value (received from UI) to a float value applicable to each + * output as a function of platform specific settings and current output + * route (destination device). It also make sure that streams are not + * muted if not allowed (e.g. camera shutter sound in some countries). + */ + +/* XXX: this should be defined OUTSIDE of frameworks/base */ +struct effect_descriptor_s; + +struct audio_policy { + /* + * configuration functions + */ + + /* indicate a change in device connection status */ + int (*set_device_connection_state)(struct audio_policy *pol, + audio_devices_t device, + audio_policy_dev_state_t state, + const char *device_address); + + /* retreive a device connection status */ + audio_policy_dev_state_t (*get_device_connection_state)( + const struct audio_policy *pol, + audio_devices_t device, + const char *device_address); + + /* indicate a change in phone state. Valid phones states are defined + * by audio_mode_t */ + void (*set_phone_state)(struct audio_policy *pol, int state); + + /* indicate a change in ringer mode */ + void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode, + uint32_t mask); + + /* force using a specific device category for the specified usage */ + void (*set_force_use)(struct audio_policy *pol, + audio_policy_force_use_t usage, + audio_policy_forced_cfg_t config); + + /* retreive current device category forced for a given usage */ + audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol, + audio_policy_force_use_t usage); + + /* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE + * can still be muted. */ + void (*set_can_mute_enforced_audible)(struct audio_policy *pol, + bool can_mute); + + /* check proper initialization */ + int (*init_check)(const struct audio_policy *pol); + + /* + * Audio routing query functions + */ + + /* request an output appriate for playback of the supplied stream type and + * parameters */ + audio_io_handle_t (*get_output)(struct audio_policy *pol, + audio_stream_type_t stream, + uint32_t samplingRate, + uint32_t format, + uint32_t channels, + audio_policy_output_flags_t flags); + + /* indicates to the audio policy manager that the output starts being used + * by corresponding stream. */ + int (*start_output)(struct audio_policy *pol, + audio_io_handle_t output, + audio_stream_type_t stream, + int session); + + /* indicates to the audio policy manager that the output stops being used + * by corresponding stream. */ + int (*stop_output)(struct audio_policy *pol, + audio_io_handle_t output, + audio_stream_type_t stream, + int session); + + /* releases the output. */ + void (*release_output)(struct audio_policy *pol, audio_io_handle_t output); + + /* request an input appriate for record from the supplied device with + * supplied parameters. */ + audio_io_handle_t (*get_input)(struct audio_policy *pol, int inputSource, + uint32_t samplingRate, + uint32_t format, + uint32_t channels, + audio_in_acoustics_t acoustics); + + /* indicates to the audio policy manager that the input starts being used */ + int (*start_input)(struct audio_policy *pol, audio_io_handle_t input); + + /* indicates to the audio policy manager that the input stops being used. */ + int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input); + + /* releases the input. */ + void (*release_input)(struct audio_policy *pol, audio_io_handle_t input); + + /* + * volume control functions + */ + + /* initialises stream volume conversion parameters by specifying volume + * index range. */ + void (*init_stream_volume)(struct audio_policy *pol, + audio_stream_type_t stream, + int index_min, + int index_max); + + /* sets the new stream volume at a level corresponding to the supplied + * index */ + int (*set_stream_volume_index)(struct audio_policy *pol, + audio_stream_type_t stream, + int index); + + /* retreive current volume index for the specified stream */ + int (*get_stream_volume_index)(const struct audio_policy *pol, + audio_stream_type_t stream, + int *index); + + /* return the strategy corresponding to a given stream type */ + uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol, + audio_stream_type_t stream); + + /* return the enabled output devices for the given stream type */ + uint32_t (*get_devices_for_stream)(const struct audio_policy *pol, + audio_stream_type_t stream); + + /* Audio effect management */ + audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol, + struct effect_descriptor_s *desc); + + int (*register_effect)(struct audio_policy *pol, + struct effect_descriptor_s *desc, + audio_io_handle_t output, + uint32_t strategy, + int session, + int id); + + int (*unregister_effect)(struct audio_policy *pol, int id); + + int (*set_effect_enabled)(struct audio_policy *pol, int id, bool enabled); + + bool (*is_stream_active)(const struct audio_policy *pol, + int stream, + uint32_t in_past_ms); + + /* dump state */ + int (*dump)(const struct audio_policy *pol, int fd); +}; + +struct audio_policy_service_ops { + /* + * Audio output Control functions + */ + + /* Opens an audio output with the requested parameters. + * + * The parameter values can indicate to use the default values in case the + * audio policy manager has no specific requirements for the output being + * opened. + * + * When the function returns, the parameter values reflect the actual + * values used by the audio hardware output stream. + * + * The audio policy manager can check if the proposed parameters are + * suitable or not and act accordingly. + */ + audio_io_handle_t (*open_output)(void *service, + uint32_t *pDevices, + uint32_t *pSamplingRate, + uint32_t *pFormat, + uint32_t *pChannels, + uint32_t *pLatencyMs, + audio_policy_output_flags_t flags); + + /* creates a special output that is duplicated to the two outputs passed as + * arguments. The duplication is performed by + * a special mixer thread in the AudioFlinger. + */ + audio_io_handle_t (*open_duplicate_output)(void *service, + audio_io_handle_t output1, + audio_io_handle_t output2); + + /* closes the output stream */ + int (*close_output)(void *service, audio_io_handle_t output); + + /* suspends the output. + * + * When an output is suspended, the corresponding audio hardware output + * stream is placed in standby and the AudioTracks attached to the mixer + * thread are still processed but the output mix is discarded. + */ + int (*suspend_output)(void *service, audio_io_handle_t output); + + /* restores a suspended output. */ + int (*restore_output)(void *service, audio_io_handle_t output); + + /* */ + /* Audio input Control functions */ + /* */ + + /* opens an audio input */ + audio_io_handle_t (*open_input)(void *service, + uint32_t *pDevices, + uint32_t *pSamplingRate, + uint32_t *pFormat, + uint32_t *pChannels, + uint32_t acoustics); + + /* closes an audio input */ + int (*close_input)(void *service, audio_io_handle_t input); + + /* */ + /* misc control functions */ + /* */ + + /* set a stream volume for a particular output. + * + * For the same user setting, a given stream type can have different + * volumes for each output (destination device) it is attached to. + */ + int (*set_stream_volume)(void *service, + audio_stream_type_t stream, + float volume, + audio_io_handle_t output, + int delay_ms); + + /* reroute a given stream type to the specified output */ + int (*set_stream_output)(void *service, + audio_stream_type_t stream, + audio_io_handle_t output); + + /* function enabling to send proprietary informations directly from audio + * policy manager to audio hardware interface. */ + void (*set_parameters)(void *service, + audio_io_handle_t io_handle, + const char *kv_pairs, + int delay_ms); + + /* function enabling to receive proprietary informations directly from + * audio hardware interface to audio policy manager. + * + * Returns a pointer to a heap allocated string. The caller is responsible + * for freeing the memory for it. + */ + + char * (*get_parameters)(void *service, audio_io_handle_t io_handle, + const char *keys); + + /* request the playback of a tone on the specified stream. + * used for instance to replace notification sounds when playing over a + * telephony device during a phone call. + */ + int (*start_tone)(void *service, + audio_policy_tone_t tone, + audio_stream_type_t stream); + + int (*stop_tone)(void *service); + + /* set down link audio volume. */ + int (*set_voice_volume)(void *service, + float volume, + int delay_ms); + + /* move effect to the specified output */ + int (*move_effects)(void *service, + int session, + audio_io_handle_t src_output, + audio_io_handle_t dst_output); +}; + +/**********************************************************************/ + +/** + * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM + * and the fields of this data structure must begin with hw_module_t + * followed by module specific information. + */ +typedef struct audio_policy_module { + struct hw_module_t common; +} audio_policy_module_t; + +struct audio_policy_device { + struct hw_device_t common; + + int (*create_audio_policy)(const struct audio_policy_device *device, + struct audio_policy_service_ops *aps_ops, + void *service, + struct audio_policy **ap); + + int (*destroy_audio_policy)(const struct audio_policy_device *device, + struct audio_policy *ap); +}; + +/** convenience API for opening and closing a supported device */ + +static inline int audio_policy_dev_open(const hw_module_t* module, + struct audio_policy_device** device) +{ + return module->methods->open(module, AUDIO_POLICY_INTERFACE, + (hw_device_t**)device); +} + +static inline int audio_policy_dev_close(struct audio_policy_device* device) +{ + return device->common.close(&device->common); +} + + +__END_DECLS + +#endif // ANDROID_AUDIO_POLICY_INTERFACE_H diff --git a/include/hardware/camera.h b/include/hardware/camera.h new file mode 100644 index 00000000..4d250235 --- /dev/null +++ b/include/hardware/camera.h @@ -0,0 +1,309 @@ +/* + * Copyright (C) 2010-2011 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. + */ + +// FIXME: add well-defined names for cameras + +#ifndef ANDROID_INCLUDE_CAMERA_H +#define ANDROID_INCLUDE_CAMERA_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> +#include <cutils/native_handle.h> +#include <system/camera.h> +#include <hardware/hardware.h> +#include <hardware/gralloc.h> + +__BEGIN_DECLS + +/** + * The id of this module + */ +#define CAMERA_HARDWARE_MODULE_ID "camera" + +struct camera_info { + /** + * The direction that the camera faces to. It should be CAMERA_FACING_BACK + * or CAMERA_FACING_FRONT. + */ + int facing; + + /** + * The orientation of the camera image. The value is the angle that the + * camera image needs to be rotated clockwise so it shows correctly on the + * display in its natural orientation. It should be 0, 90, 180, or 270. + * + * For example, suppose a device has a naturally tall screen. The + * back-facing camera sensor is mounted in landscape. You are looking at + * the screen. If the top side of the camera sensor is aligned with the + * right edge of the screen in natural orientation, the value should be + * 90. If the top side of a front-facing camera sensor is aligned with the + * right of the screen, the value should be 270. + */ + int orientation; +}; + +typedef struct camera_module { + hw_module_t common; + int (*get_number_of_cameras)(void); + int (*get_camera_info)(int camera_id, struct camera_info *info); +} camera_module_t; + +struct camera_memory; +typedef void (*camera_release_memory)(struct camera_memory *mem); + +typedef struct camera_memory { + void *data; + size_t size; + void *handle; + camera_release_memory release; +} camera_memory_t; + +typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs, + void *user); + +typedef void (*camera_notify_callback)(int32_t msg_type, + int32_t ext1, + int32_t ext2, + void *user); + +typedef void (*camera_data_callback)(int32_t msg_type, + const camera_memory_t *data, unsigned int index, + camera_frame_metadata_t *metadata, void *user); + +typedef void (*camera_data_timestamp_callback)(int64_t timestamp, + int32_t msg_type, + const camera_memory_t *data, unsigned int index, + void *user); + +#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d + +typedef struct preview_stream_ops { + int (*dequeue_buffer)(struct preview_stream_ops* w, + buffer_handle_t** buffer, int *stride); + int (*enqueue_buffer)(struct preview_stream_ops* w, + buffer_handle_t* buffer); + int (*cancel_buffer)(struct preview_stream_ops* w, + buffer_handle_t* buffer); + int (*set_buffer_count)(struct preview_stream_ops* w, int count); + int (*set_buffers_geometry)(struct preview_stream_ops* pw, + int w, int h, int format); + int (*set_crop)(struct preview_stream_ops *w, + int left, int top, int right, int bottom); + int (*set_usage)(struct preview_stream_ops* w, int usage); + int (*set_swap_interval)(struct preview_stream_ops *w, int interval); + int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w, + int *count); + int (*lock_buffer)(struct preview_stream_ops* w, + buffer_handle_t* buffer); +} preview_stream_ops_t; + +struct camera_device; +typedef struct camera_device_ops { + /** Set the ANativeWindow to which preview frames are sent */ + int (*set_preview_window)(struct camera_device *, + struct preview_stream_ops *window); + + /** Set the notification and data callbacks */ + void (*set_callbacks)(struct camera_device *, + camera_notify_callback notify_cb, + camera_data_callback data_cb, + camera_data_timestamp_callback data_cb_timestamp, + camera_request_memory get_memory, + void *user); + + /** + * The following three functions all take a msg_type, which is a bitmask of + * the messages defined in include/ui/Camera.h + */ + + /** + * Enable a message, or set of messages. + */ + void (*enable_msg_type)(struct camera_device *, int32_t msg_type); + + /** + * Disable a message, or a set of messages. + * + * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera + * HAL should not rely on its client to call releaseRecordingFrame() to + * release video recording frames sent out by the cameral HAL before and + * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL + * clients must not modify/access any video recording frame after calling + * disableMsgType(CAMERA_MSG_VIDEO_FRAME). + */ + void (*disable_msg_type)(struct camera_device *, int32_t msg_type); + + /** + * Query whether a message, or a set of messages, is enabled. Note that + * this is operates as an AND, if any of the messages queried are off, this + * will return false. + */ + int (*msg_type_enabled)(struct camera_device *, int32_t msg_type); + + /** + * Start preview mode. + */ + int (*start_preview)(struct camera_device *); + + /** + * Stop a previously started preview. + */ + void (*stop_preview)(struct camera_device *); + + /** + * Returns true if preview is enabled. + */ + int (*preview_enabled)(struct camera_device *); + + /** + * Request the camera HAL to store meta data or real YUV data in the video + * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If + * it is not called, the default camera HAL behavior is to store real YUV + * data in the video buffers. + * + * This method should be called before startRecording() in order to be + * effective. + * + * If meta data is stored in the video buffers, it is up to the receiver of + * the video buffers to interpret the contents and to find the actual frame + * data with the help of the meta data in the buffer. How this is done is + * outside of the scope of this method. + * + * Some camera HALs may not support storing meta data in the video buffers, + * but all camera HALs should support storing real YUV data in the video + * buffers. If the camera HAL does not support storing the meta data in the + * video buffers when it is requested to do do, INVALID_OPERATION must be + * returned. It is very useful for the camera HAL to pass meta data rather + * than the actual frame data directly to the video encoder, since the + * amount of the uncompressed frame data can be very large if video size is + * large. + * + * @param enable if true to instruct the camera HAL to store + * meta data in the video buffers; false to instruct + * the camera HAL to store real YUV data in the video + * buffers. + * + * @return OK on success. + */ + int (*store_meta_data_in_buffers)(struct camera_device *, int enable); + + /** + * Start record mode. When a record image is available, a + * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding + * frame. Every record frame must be released by a camera HAL client via + * releaseRecordingFrame() before the client calls + * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls + * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's + * responsibility to manage the life-cycle of the video recording frames, + * and the client must not modify/access any video recording frames. + */ + int (*start_recording)(struct camera_device *); + + /** + * Stop a previously started recording. + */ + void (*stop_recording)(struct camera_device *); + + /** + * Returns true if recording is enabled. + */ + int (*recording_enabled)(struct camera_device *); + + /** + * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. + * + * It is camera HAL client's responsibility to release video recording + * frames sent out by the camera HAL before the camera HAL receives a call + * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to + * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's + * responsibility to manage the life-cycle of the video recording frames. + */ + void (*release_recording_frame)(struct camera_device *, + const void *opaque); + + /** + * Start auto focus, the notification callback routine is called with + * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be + * called again if another auto focus is needed. + */ + int (*auto_focus)(struct camera_device *); + + /** + * Cancels auto-focus function. If the auto-focus is still in progress, + * this function will cancel it. Whether the auto-focus is in progress or + * not, this function will return the focus position to the default. If + * the camera does not support auto-focus, this is a no-op. + */ + int (*cancel_auto_focus)(struct camera_device *); + + /** + * Take a picture. + */ + int (*take_picture)(struct camera_device *); + + /** + * Cancel a picture that was started with takePicture. Calling this method + * when no picture is being taken is a no-op. + */ + int (*cancel_picture)(struct camera_device *); + + /** + * Set the camera parameters. This returns BAD_VALUE if any parameter is + * invalid or not supported. + */ + int (*set_parameters)(struct camera_device *, const char *parms); + + /** Retrieve the camera parameters. The buffer returned by the camera HAL + must be returned back to it with put_parameters, if put_parameters + is not NULL. + */ + char *(*get_parameters)(struct camera_device *); + + /** The camera HAL uses its own memory to pass us the parameters when we + call get_parameters. Use this function to return the memory back to + the camera HAL, if put_parameters is not NULL. If put_parameters + is NULL, then you have to use free() to release the memory. + */ + void (*put_parameters)(struct camera_device *, char *); + + /** + * Send command to camera driver. + */ + int (*send_command)(struct camera_device *, + int32_t cmd, int32_t arg1, int32_t arg2); + + /** + * Release the hardware resources owned by this object. Note that this is + * *not* done in the destructor. + */ + void (*release)(struct camera_device *); + + /** + * Dump state of the camera hardware + */ + int (*dump)(struct camera_device *, int fd); +} camera_device_ops_t; + +typedef struct camera_device { + hw_device_t common; + camera_device_ops_t *ops; + void *priv; +} camera_device_t; + +__END_DECLS + +#endif /* ANDROID_INCLUDE_CAMERA_H */ diff --git a/include/hardware/copybit.h b/include/hardware/copybit.h deleted file mode 100644 index b6302c37..00000000 --- a/include/hardware/copybit.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2008 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_COPYBIT_INTERFACE_H -#define ANDROID_COPYBIT_INTERFACE_H - -#include <hardware/hardware.h> - -#include <stdint.h> -#include <sys/cdefs.h> -#include <sys/types.h> - -__BEGIN_DECLS - -/** - * The id of this module - */ -#define COPYBIT_HARDWARE_MODULE_ID "copybit" - -/** - * Name of the graphics device to open - */ -#define COPYBIT_HARDWARE_COPYBIT0 "copybit0" - -/* supported pixel-formats. these must be compatible with - * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h - */ -enum { - COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, - COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, - COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, - COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, - COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, - COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, - COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, - COPYBIT_FORMAT_YCbCr_422_SP = 0x10, - COPYBIT_FORMAT_YCrCb_420_SP = 0x11, -}; - -/* name for copybit_set_parameter */ -enum { - /* rotation of the source image in degrees (0 to 359) */ - COPYBIT_ROTATION_DEG = 1, - /* plane alpha value */ - COPYBIT_PLANE_ALPHA = 2, - /* enable or disable dithering */ - COPYBIT_DITHER = 3, - /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ - COPYBIT_TRANSFORM = 4, - /* blurs the copied bitmap. The amount of blurring cannot be changed - * at this time. */ - COPYBIT_BLUR = 5 -}; - -/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ -enum { - /* flip source image horizontally */ - COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, - /* flip source image vertically */ - COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, - /* rotate source image 90 degres */ - COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, - /* rotate source image 180 degres */ - COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, - /* rotate source image 270 degres */ - COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, -}; - -/* enable/disable value copybit_set_parameter */ -enum { - COPYBIT_DISABLE = 0, - COPYBIT_ENABLE = 1 -}; - -/* use get_static_info() to query static informations about the hardware */ -enum { - /* Maximum amount of minification supported by the hardware*/ - COPYBIT_MINIFICATION_LIMIT = 1, - /* Maximum amount of magnification supported by the hardware */ - COPYBIT_MAGNIFICATION_LIMIT = 2, - /* Number of fractional bits support by the scaling engine */ - COPYBIT_SCALING_FRAC_BITS = 3, - /* Supported rotation step in degres. */ - COPYBIT_ROTATION_STEP_DEG = 4, -}; - -/* Image structure */ -struct copybit_image_t { - /* width */ - uint32_t w; - /* height */ - uint32_t h; - /* format COPYBIT_FORMAT_xxx */ - int32_t format; - /* base of buffer with image */ - void *base; - /* handle to the image */ - native_handle_t* handle; -}; - -/* Rectangle */ -struct copybit_rect_t { - /* left */ - int l; - /* top */ - int t; - /* right */ - int r; - /* bottom */ - int b; -}; - -/* Region */ -struct copybit_region_t { - int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); -}; - -/** - * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM - * and the fields of this data structure must begin with hw_module_t - * followed by module specific information. - */ -struct copybit_module_t { - struct hw_module_t common; -}; - -/** - * Every device data structure must begin with hw_device_t - * followed by module specific public methods and attributes. - */ -struct copybit_device_t { - struct hw_device_t common; - - /** - * Set a copybit parameter. - * - * @param dev from open - * @param name one for the COPYBIT_NAME_xxx - * @param value one of the COPYBIT_VALUE_xxx - * - * @return 0 if successful - */ - int (*set_parameter)(struct copybit_device_t *dev, int name, int value); - - /** - * Get a static copybit information. - * - * @param dev from open - * @param name one of the COPYBIT_STATIC_xxx - * - * @return value or -EINVAL if error - */ - int (*get)(struct copybit_device_t *dev, int name); - - /** - * Execute the bit blit copy operation - * - * @param dev from open - * @param dst is the destination image - * @param src is the source image - * @param region the clip region - * - * @return 0 if successful - */ - int (*blit)(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_region_t const *region); - - /** - * Execute the stretch bit blit copy operation - * - * @param dev from open - * @param dst is the destination image - * @param src is the source image - * @param dst_rect is the destination rectangle - * @param src_rect is the source rectangle - * @param region the clip region - * - * @return 0 if successful - */ - int (*stretch)(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_rect_t const *dst_rect, - struct copybit_rect_t const *src_rect, - struct copybit_region_t const *region); -}; - - -/** convenience API for opening and closing a device */ - -static inline int copybit_open(const struct hw_module_t* module, - struct copybit_device_t** device) { - return module->methods->open(module, - COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); -} - -static inline int copybit_close(struct copybit_device_t* device) { - return device->common.close(&device->common); -} - - -__END_DECLS - -#endif // ANDROID_COPYBIT_INTERFACE_H diff --git a/include/hardware/fb.h b/include/hardware/fb.h new file mode 100644 index 00000000..ba2f286d --- /dev/null +++ b/include/hardware/fb.h @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2008 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_FB_INTERFACE_H +#define ANDROID_FB_INTERFACE_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +#include <cutils/native_handle.h> + +#include <hardware/hardware.h> + +__BEGIN_DECLS + +#define GRALLOC_HARDWARE_FB0 "fb0" + +/*****************************************************************************/ + + +/*****************************************************************************/ + +typedef struct framebuffer_device_t { + struct hw_device_t common; + + /* flags describing some attributes of the framebuffer */ + const uint32_t flags; + + /* dimensions of the framebuffer in pixels */ + const uint32_t width; + const uint32_t height; + + /* frambuffer stride in pixels */ + const int stride; + + /* framebuffer pixel format */ + const int format; + + /* resolution of the framebuffer's display panel in pixel per inch*/ + const float xdpi; + const float ydpi; + + /* framebuffer's display panel refresh rate in frames per second */ + const float fps; + + /* min swap interval supported by this framebuffer */ + const int minSwapInterval; + + /* max swap interval supported by this framebuffer */ + const int maxSwapInterval; + + int reserved[8]; + + /* + * requests a specific swap-interval (same definition than EGL) + * + * Returns 0 on success or -errno on error. + */ + int (*setSwapInterval)(struct framebuffer_device_t* window, + int interval); + + /* + * This hook is OPTIONAL. + * + * It is non NULL If the framebuffer driver supports "update-on-demand" + * and the given rectangle is the area of the screen that gets + * updated during (*post)(). + * + * This is useful on devices that are able to DMA only a portion of + * the screen to the display panel, upon demand -- as opposed to + * constantly refreshing the panel 60 times per second, for instance. + * + * Only the area defined by this rectangle is guaranteed to be valid, that + * is, the driver is not allowed to post anything outside of this + * rectangle. + * + * The rectangle evaluated during (*post)() and specifies which area + * of the buffer passed in (*post)() shall to be posted. + * + * return -EINVAL if width or height <=0, or if left or top < 0 + */ + int (*setUpdateRect)(struct framebuffer_device_t* window, + int left, int top, int width, int height); + + /* + * Post <buffer> to the display (display it on the screen) + * The buffer must have been allocated with the + * GRALLOC_USAGE_HW_FB usage flag. + * buffer must be the same width and height as the display and must NOT + * be locked. + * + * The buffer is shown during the next VSYNC. + * + * If the same buffer is posted again (possibly after some other buffer), + * post() will block until the the first post is completed. + * + * Internally, post() is expected to lock the buffer so that a + * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or + * USAGE_*_WRITE will block until it is safe; that is typically once this + * buffer is shown and another buffer has been posted. + * + * Returns 0 on success or -errno on error. + */ + int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); + + + /* + * The (*compositionComplete)() method must be called after the + * compositor has finished issuing GL commands for client buffers. + */ + + int (*compositionComplete)(struct framebuffer_device_t* dev); + + /* + * This hook is OPTIONAL. + * + * If non NULL it will be caused by SurfaceFlinger on dumpsys + */ + void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len); + + /* + * (*enableScreen)() is used to either blank (enable=0) or + * unblank (enable=1) the screen this framebuffer is attached to. + * + * Returns 0 on success or -errno on error. + */ + int (*enableScreen)(struct framebuffer_device_t* dev, int enable); + + void* reserved_proc[6]; + +} framebuffer_device_t; + + +/** convenience API for opening and closing a supported device */ + +static inline int framebuffer_open(const struct hw_module_t* module, + struct framebuffer_device_t** device) { + return module->methods->open(module, + GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); +} + +static inline int framebuffer_close(struct framebuffer_device_t* device) { + return device->common.close(&device->common); +} + + +__END_DECLS + +#endif // ANDROID_FB_INTERFACE_H diff --git a/include/hardware/gps.h b/include/hardware/gps.h index 7c3be18f..69bfd507 100644 --- a/include/hardware/gps.h +++ b/include/hardware/gps.h @@ -101,6 +101,8 @@ typedef uint16_t GpsLocationFlags; #define GPS_CAPABILITY_MSA 0x0000004 /** GPS supports single-shot fixes */ #define GPS_CAPABILITY_SINGLE_SHOT 0x0000008 +/** GPS supports on demand time injection */ +#define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010 /** Flags used to specify which aiding data to delete when calling delete_aiding_data(). */ @@ -354,6 +356,9 @@ typedef void (* gps_acquire_wakelock)(); /** Callback utility for releasing the GPS wakelock. */ typedef void (* gps_release_wakelock)(); +/** Callback for requesting NTP time */ +typedef void (* gps_request_utc_time)(); + /** Callback for creating a thread that can call into the Java framework code. * This must be used to create any threads that report events up to the framework. */ @@ -371,6 +376,7 @@ typedef struct { gps_acquire_wakelock acquire_wakelock_cb; gps_release_wakelock release_wakelock_cb; gps_create_thread create_thread_cb; + gps_request_utc_time request_utc_time_cb; } GpsCallbacks; diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h index 5eefe795..9daad1c8 100644 --- a/include/hardware/gralloc.h +++ b/include/hardware/gralloc.h @@ -18,14 +18,18 @@ #ifndef ANDROID_GRALLOC_INTERFACE_H #define ANDROID_GRALLOC_INTERFACE_H -#include <cutils/native_handle.h> - +#include <system/window.h> #include <hardware/hardware.h> #include <stdint.h> #include <sys/cdefs.h> #include <sys/types.h> +#include <cutils/native_handle.h> + +#include <hardware/hardware.h> +#include <hardware/fb.h> + __BEGIN_DECLS #define GRALLOC_API_VERSION 1 @@ -39,7 +43,6 @@ __BEGIN_DECLS * Name of the graphics device to open */ -#define GRALLOC_HARDWARE_FB0 "fb0" #define GRALLOC_HARDWARE_GPU0 "gpu0" enum { @@ -67,6 +70,8 @@ enum { GRALLOC_USAGE_HW_RENDER = 0x00000200, /* buffer will be used by the 2D hardware blitter */ GRALLOC_USAGE_HW_2D = 0x00000400, + /* buffer will be used by the HWComposer HAL module */ + GRALLOC_USAGE_HW_COMPOSER = 0x00000800, /* buffer will be used with the framebuffer device */ GRALLOC_USAGE_HW_FB = 0x00001000, /* mask for the software usage bit-mask */ @@ -95,16 +100,6 @@ enum { /*****************************************************************************/ -typedef const native_handle* buffer_handle_t; - -enum { - /* FIXME: this only exists to work-around some issues with - * the video and camera frameworks. don't implement unless - * you know what you're doing. - */ - GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, -}; - /** * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM * and the fields of this data structure must begin with hw_module_t @@ -247,109 +242,6 @@ typedef struct alloc_device_t { } alloc_device_t; -typedef struct framebuffer_device_t { - struct hw_device_t common; - - /* flags describing some attributes of the framebuffer */ - const uint32_t flags; - - /* dimensions of the framebuffer in pixels */ - const uint32_t width; - const uint32_t height; - - /* frambuffer stride in pixels */ - const int stride; - - /* framebuffer pixel format */ - const int format; - - /* resolution of the framebuffer's display panel in pixel per inch*/ - const float xdpi; - const float ydpi; - - /* framebuffer's display panel refresh rate in frames per second */ - const float fps; - - /* min swap interval supported by this framebuffer */ - const int minSwapInterval; - - /* max swap interval supported by this framebuffer */ - const int maxSwapInterval; - - int reserved[8]; - - /* - * requests a specific swap-interval (same definition than EGL) - * - * Returns 0 on success or -errno on error. - */ - int (*setSwapInterval)(struct framebuffer_device_t* window, - int interval); - - /* - * This hook is OPTIONAL. - * - * It is non NULL If the framebuffer driver supports "update-on-demand" - * and the given rectangle is the area of the screen that gets - * updated during (*post)(). - * - * This is useful on devices that are able to DMA only a portion of - * the screen to the display panel, upon demand -- as opposed to - * constantly refreshing the panel 60 times per second, for instance. - * - * Only the area defined by this rectangle is guaranteed to be valid, that - * is, the driver is not allowed to post anything outside of this - * rectangle. - * - * The rectangle evaluated during (*post)() and specifies which area - * of the buffer passed in (*post)() shall to be posted. - * - * return -EINVAL if width or height <=0, or if left or top < 0 - */ - int (*setUpdateRect)(struct framebuffer_device_t* window, - int left, int top, int width, int height); - - /* - * Post <buffer> to the display (display it on the screen) - * The buffer must have been allocated with the - * GRALLOC_USAGE_HW_FB usage flag. - * buffer must be the same width and height as the display and must NOT - * be locked. - * - * The buffer is shown during the next VSYNC. - * - * If the same buffer is posted again (possibly after some other buffer), - * post() will block until the the first post is completed. - * - * Internally, post() is expected to lock the buffer so that a - * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or - * USAGE_*_WRITE will block until it is safe; that is typically once this - * buffer is shown and another buffer has been posted. - * - * Returns 0 on success or -errno on error. - */ - int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); - - - /* - * The (*compositionComplete)() method must be called after the - * compositor has finished issuing GL commands for client buffers. - */ - - int (*compositionComplete)(struct framebuffer_device_t* dev); - - /* - * This hook is OPTIONAL. - * - * If non NULL it will be caused by SurfaceFlinger on dumpsys - */ - void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len); - - void* reserved_proc[7]; - -} framebuffer_device_t; - - /** convenience API for opening and closing a supported device */ static inline int gralloc_open(const struct hw_module_t* module, @@ -362,18 +254,6 @@ static inline int gralloc_close(struct alloc_device_t* device) { return device->common.close(&device->common); } - -static inline int framebuffer_open(const struct hw_module_t* module, - struct framebuffer_device_t** device) { - return module->methods->open(module, - GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); -} - -static inline int framebuffer_close(struct framebuffer_device_t* device) { - return device->common.close(&device->common); -} - - __END_DECLS #endif // ANDROID_ALLOC_INTERFACE_H diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h index d9cc0dc7..7774b2b6 100644 --- a/include/hardware/hardware.h +++ b/include/hardware/hardware.h @@ -21,6 +21,7 @@ #include <sys/cdefs.h> #include <cutils/native_handle.h> +#include <system/graphics.h> __BEGIN_DECLS @@ -113,92 +114,25 @@ typedef struct hw_device_t { /** * Get the module info associated with a module by id. - * @return: 0 == success, <0 == error and *pHmi == NULL + * + * @return: 0 == success, <0 == error and *module == NULL */ int hw_get_module(const char *id, const struct hw_module_t **module); - -/** - * pixel format definitions - */ - -enum { - HAL_PIXEL_FORMAT_RGBA_8888 = 1, - HAL_PIXEL_FORMAT_RGBX_8888 = 2, - HAL_PIXEL_FORMAT_RGB_888 = 3, - HAL_PIXEL_FORMAT_RGB_565 = 4, - HAL_PIXEL_FORMAT_BGRA_8888 = 5, - HAL_PIXEL_FORMAT_RGBA_5551 = 6, - HAL_PIXEL_FORMAT_RGBA_4444 = 7, - - /* 0x8 - 0xFF range unavailable */ - - /* - * 0x100 - 0x1FF - * - * This range is reserved for pixel formats that are specific to the HAL - * implementation. Implementations can use any value in this range to - * communicate video pixel formats between their HAL modules. These formats - * must not have an alpha channel. Additionally, an EGLimage created from a - * gralloc buffer of one of these formats must be supported for use with the - * GL_OES_EGL_image_external OpenGL ES extension. - */ - - /* - * Android YUV format: - * - * This format is exposed outside of the HAL to software - * decoders and applications. - * EGLImageKHR must support it in conjunction with the - * OES_EGL_image_external extension. - * - * YV12 is 4:2:0 YCrCb planar format comprised of a WxH Y plane followed - * by (W/2) x (H/2) Cr and Cb planes. - * - * This format assumes - * - an even width - * - an even height - * - a horizontal stride multiple of 16 pixels - * - a vertical stride equal to the height - * - * y_size = stride * height - * c_size = ALIGN(stride/2, 16) * height/2 - * size = y_size + c_size * 2 - * cr_offset = y_size - * cb_offset = y_size + c_size - * - */ - HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar - - - - /* Legacy formats (deprecated), used by ImageFormat.java */ - HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16 - HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21 - HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2 -}; - - /** - * Transformation definitions + * Get the module info associated with a module instance by class 'class_id' + * and instance 'inst'. * - * IMPORTANT NOTE: - * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}. + * Some modules types necessitate multiple instances. For example audio supports + * multiple concurrent interfaces and thus 'audio' is the module class + * and 'primary' or 'a2dp' are module interfaces. This implies that the files + * providing these modules would be named audio.primary.<variant>.so and + * audio.a2dp.<variant>.so * + * @return: 0 == success, <0 == error and *module == NULL */ - -enum { - /* flip source image horizontally (around the vertical axis) */ - HAL_TRANSFORM_FLIP_H = 0x01, - /* flip source image vertically (around the horizontal axis)*/ - HAL_TRANSFORM_FLIP_V = 0x02, - /* rotate source image 90 degrees clockwise */ - HAL_TRANSFORM_ROT_90 = 0x04, - /* rotate source image 180 degrees */ - HAL_TRANSFORM_ROT_180 = 0x03, - /* rotate source image 270 degrees clockwise */ - HAL_TRANSFORM_ROT_270 = 0x07, -}; +int hw_get_module_by_class(const char *class_id, const char *inst, + const struct hw_module_t **module); __END_DECLS diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h index 321dfc1f..0fa3512f 100644 --- a/include/hardware/hwcomposer.h +++ b/include/hardware/hwcomposer.h @@ -205,8 +205,26 @@ typedef void* hwc_display_t; /* This represents a surface, typically an EGLSurface object */ typedef void* hwc_surface_t; -/*****************************************************************************/ +/* see hwc_composer_device::registerProcs() + * Any of the callbacks can be NULL, in which case the corresponding + * functionality is not supported. + */ +typedef struct hwc_procs { + /* + * (*invalidate)() triggers a screen refresh, in particular prepare and set + * will be called shortly after this call is made. Note that there is + * NO GUARANTEE that the screen refresh will happen after invalidate() + * returns (in particular, it could happen before). + * invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and + * it is safe to call invalidate() from any of hwc_composer_device + * hooks, unless noted otherwise. + */ + void (*invalidate)(struct hwc_procs* procs); +} hwc_procs_t; + + +/*****************************************************************************/ typedef struct hwc_module { struct hw_module_t common; @@ -281,11 +299,27 @@ typedef struct hwc_composer_device { /* * This hook is OPTIONAL. * - * If non NULL it will be caused by SurfaceFlinger on dumpsys + * If non NULL it will be called by SurfaceFlinger on dumpsys */ void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len); - void* reserved_proc[7]; + /* + * This hook is OPTIONAL. + * + * (*registerProcs)() registers a set of callbacks the h/w composer HAL + * can later use. It is FORBIDDEN to call any of the callbacks from + * within registerProcs(). registerProcs() must save the hwc_procs_t pointer + * which is needed when calling a registered callback. + * Each call to registerProcs replaces the previous set of callbacks. + * registerProcs is called with NULL to unregister all callbacks. + * + * Any of the callbacks can be NULL, in which case the corresponding + * functionality is not supported. + */ + void (*registerProcs)(struct hwc_composer_device* dev, + hwc_procs_t const* procs); + + void* reserved_proc[6]; } hwc_composer_device_t; diff --git a/include/hardware/overlay.h b/include/hardware/overlay.h deleted file mode 100644 index c56a974d..00000000 --- a/include/hardware/overlay.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) 2008 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_OVERLAY_INTERFACE_H -#define ANDROID_OVERLAY_INTERFACE_H - -#include <cutils/native_handle.h> - -#include <hardware/hardware.h> - -#include <stdint.h> -#include <sys/cdefs.h> -#include <sys/types.h> - -__BEGIN_DECLS - -/** - * The id of this module - */ -#define OVERLAY_HARDWARE_MODULE_ID "overlay" - -/** - * Name of the overlay device to open - */ -#define OVERLAY_HARDWARE_CONTROL "control" -#define OVERLAY_HARDWARE_DATA "data" - -/*****************************************************************************/ - -/* possible overlay formats */ -enum { - OVERLAY_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, - OVERLAY_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, - OVERLAY_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, - OVERLAY_FORMAT_YCbYCr_422_I = 0x14, - OVERLAY_FORMAT_CbYCrY_422_I = 0x16, - OVERLAY_FORMAT_DEFAULT = 99 // The actual color format is determined - // by the overlay -}; - -/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ -enum { - /* flip source image horizontally */ - OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, - /* flip source image vertically */ - OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, - /* rotate source image 90 degrees */ - OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, - /* rotate source image 180 degrees */ - OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, - /* rotate source image 270 degrees */ - OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270 -}; - -/* names for setParameter() */ -enum { - /* rotation of the source image in degrees (0 to 359) */ - OVERLAY_ROTATION_DEG = 1, - /* enable or disable dithering */ - OVERLAY_DITHER = 3, - /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ - OVERLAY_TRANSFORM = 4, -}; - -/* enable/disable value setParameter() */ -enum { - OVERLAY_DISABLE = 0, - OVERLAY_ENABLE = 1 -}; - -/* names for get() */ -enum { - /* Maximum amount of minification supported by the hardware*/ - OVERLAY_MINIFICATION_LIMIT = 1, - /* Maximum amount of magnification supported by the hardware */ - OVERLAY_MAGNIFICATION_LIMIT = 2, - /* Number of fractional bits support by the overlay scaling engine */ - OVERLAY_SCALING_FRAC_BITS = 3, - /* Supported rotation step in degrees. */ - OVERLAY_ROTATION_STEP_DEG = 4, - /* horizontal alignment in pixels */ - OVERLAY_HORIZONTAL_ALIGNMENT = 5, - /* vertical alignment in pixels */ - OVERLAY_VERTICAL_ALIGNMENT = 6, - /* width alignment restrictions. negative number for max. power-of-two */ - OVERLAY_WIDTH_ALIGNMENT = 7, - /* height alignment restrictions. negative number for max. power-of-two */ - OVERLAY_HEIGHT_ALIGNMENT = 8, -}; - -/*****************************************************************************/ - -/* opaque reference to an Overlay kernel object */ -typedef const native_handle* overlay_handle_t; - -typedef struct overlay_t { - uint32_t w; - uint32_t h; - int32_t format; - uint32_t w_stride; - uint32_t h_stride; - uint32_t reserved[3]; - /* returns a reference to this overlay's handle (the caller doesn't - * take ownership) */ - overlay_handle_t (*getHandleRef)(struct overlay_t* overlay); - uint32_t reserved_procs[7]; -} overlay_t; - -typedef void* overlay_buffer_t; - -/*****************************************************************************/ - -/** - * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM - * and the fields of this data structure must begin with hw_module_t - * followed by module specific information. - */ -struct overlay_module_t { - struct hw_module_t common; -}; - -/*****************************************************************************/ - -/** - * Every device data structure must begin with hw_device_t - * followed by module specific public methods and attributes. - */ - -struct overlay_control_device_t { - struct hw_device_t common; - - /* get static informations about the capabilities of the overlay engine */ - int (*get)(struct overlay_control_device_t *dev, int name); - - /* creates an overlay matching the given parameters as closely as possible. - * returns an error if no more overlays are available. The actual - * size and format is returned in overlay_t. */ - overlay_t* (*createOverlay)(struct overlay_control_device_t *dev, - uint32_t w, uint32_t h, int32_t format); - - /* destroys an overlay. This call releases all - * resources associated with overlay_t and make it invalid */ - void (*destroyOverlay)(struct overlay_control_device_t *dev, - overlay_t* overlay); - - /* set position and scaling of the given overlay as closely as possible. - * if scaling cannot be performed, overlay must be centered. */ - int (*setPosition)(struct overlay_control_device_t *dev, - overlay_t* overlay, - int x, int y, uint32_t w, uint32_t h); - - /* returns the actual position and size of the overlay */ - int (*getPosition)(struct overlay_control_device_t *dev, - overlay_t* overlay, - int* x, int* y, uint32_t* w, uint32_t* h); - - /* sets configurable parameters for this overlay. returns an error if not - * supported. */ - int (*setParameter)(struct overlay_control_device_t *dev, - overlay_t* overlay, int param, int value); - - int (*stage)(struct overlay_control_device_t *dev, overlay_t* overlay); - int (*commit)(struct overlay_control_device_t *dev, overlay_t* overlay); -}; - - -struct overlay_data_device_t { - struct hw_device_t common; - - /* initialize the overlay from the given handle. this associates this - * overlay data module to its control module */ - int (*initialize)(struct overlay_data_device_t *dev, - overlay_handle_t handle); - - /* can be called to change the width and height of the overlay. */ - int (*resizeInput)(struct overlay_data_device_t *dev, - uint32_t w, uint32_t h); - - int (*setCrop)(struct overlay_data_device_t *dev, - uint32_t x, uint32_t y, uint32_t w, uint32_t h) ; - - int (*getCrop)(struct overlay_data_device_t *dev, - uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) ; - - int (*setParameter)(struct overlay_data_device_t *dev, - int param, int value); - - /* blocks until an overlay buffer is available and return that buffer. */ - int (*dequeueBuffer)(struct overlay_data_device_t *dev, - overlay_buffer_t *buf); - - /* release the overlay buffer and post it */ - int (*queueBuffer)(struct overlay_data_device_t *dev, - overlay_buffer_t buffer); - - /* returns the address of a given buffer if supported, NULL otherwise. */ - void* (*getBufferAddress)(struct overlay_data_device_t *dev, - overlay_buffer_t buffer); - - int (*getBufferCount)(struct overlay_data_device_t *dev); -}; - - -/*****************************************************************************/ - -/** convenience API for opening and closing a device */ - -static inline int overlay_control_open(const struct hw_module_t* module, - struct overlay_control_device_t** device) { - return module->methods->open(module, - OVERLAY_HARDWARE_CONTROL, (struct hw_device_t**)device); -} - -static inline int overlay_control_close(struct overlay_control_device_t* device) { - return device->common.close(&device->common); -} - -static inline int overlay_data_open(const struct hw_module_t* module, - struct overlay_data_device_t** device) { - return module->methods->open(module, - OVERLAY_HARDWARE_DATA, (struct hw_device_t**)device); -} - -static inline int overlay_data_close(struct overlay_data_device_t* device) { - return device->common.close(&device->common); -} - -__END_DECLS - -#endif // ANDROID_OVERLAY_INTERFACE_H diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h index 1dcd5fac..7819a716 100644 --- a/include/hardware/sensors.h +++ b/include/hardware/sensors.h @@ -56,12 +56,13 @@ __BEGIN_DECLS #define SENSOR_TYPE_GYROSCOPE 4 #define SENSOR_TYPE_LIGHT 5 #define SENSOR_TYPE_PRESSURE 6 -#define SENSOR_TYPE_TEMPERATURE 7 +#define SENSOR_TYPE_TEMPERATURE 7 // deprecated #define SENSOR_TYPE_PROXIMITY 8 #define SENSOR_TYPE_GRAVITY 9 #define SENSOR_TYPE_LINEAR_ACCELERATION 10 #define SENSOR_TYPE_ROTATION_VECTOR 11 #define SENSOR_TYPE_RELATIVE_HUMIDITY 12 +#define SENSOR_TYPE_AMBIENT_TEMPERATURE 13 /** * Values returned by the accelerometer in various locations in the universe. @@ -268,6 +269,18 @@ __BEGIN_DECLS * Elements of the rotation vector are unitless. The x, y, and z axis are defined * in the same was as for the acceleration sensor. * + * The reference coordinate system is defined as a direct orthonormal basis, + * where: + * + * - X is defined as the vector product Y.Z (It is tangential to + * the ground at the device's current location and roughly points East). + * + * - Y is tangential to the ground at the device's current location and + * points towards the magnetic North Pole. + * + * - Z points towards the sky and is perpendicular to the ground. + * + * * The rotation-vector is stored as: * * sensors_event_t.data[0] = x*sin(theta/2) @@ -275,6 +288,7 @@ __BEGIN_DECLS * sensors_event_t.data[2] = z*sin(theta/2) * sensors_event_t.data[3] = cos(theta/2) * + * * Relative Humidity * ----------------- * @@ -283,6 +297,16 @@ __BEGIN_DECLS * * Relative humidity sensors report a value only when it changes and each * time the sensor is enabled. setDelay() is ignored. + * + * + * Ambient Temperature + * ------------------- + * + * The ambient (room) temperature in degree Celsius. + * + * Temperature sensors report a value only when it changes and each time the + * sensor is enabled. setDelay() is ignored. + * */ typedef struct { @@ -462,6 +486,4 @@ static inline int sensors_close(struct sensors_poll_device_t* device) { __END_DECLS -#include <hardware/sensors_deprecated.h> - #endif // ANDROID_SENSORS_INTERFACE_H diff --git a/include/hardware/sensors_deprecated.h b/include/hardware/sensors_deprecated.h deleted file mode 100644 index ee667d66..00000000 --- a/include/hardware/sensors_deprecated.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -#define SENSORS_HARDWARE_CONTROL "control" -#define SENSORS_HARDWARE_DATA "data" - -__BEGIN_DECLS - -typedef struct { - int sensor; - union { - sensors_vec_t vector; - sensors_vec_t orientation; - sensors_vec_t acceleration; - sensors_vec_t magnetic; - float temperature; - float distance; - float light; - float pressure; - }; - int64_t time; - uint32_t reserved; -} sensors_data_t; - -struct sensors_control_device_t { - struct hw_device_t common; - native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev); - int (*close_data_source)(struct sensors_control_device_t *dev); - int (*activate)(struct sensors_control_device_t *dev, - int handle, int enabled); - int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms); - int (*wake)(struct sensors_control_device_t *dev); -}; - -struct sensors_data_device_t { - struct hw_device_t common; - int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh); - int (*data_close)(struct sensors_data_device_t *dev); - int (*poll)(struct sensors_data_device_t *dev, - sensors_data_t* data); -}; - -static inline int sensors_control_open(const struct hw_module_t* module, - struct sensors_control_device_t** device) { - return module->methods->open(module, - SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device); -} - -static inline int sensors_control_close(struct sensors_control_device_t* device) { - return device->common.close(&device->common); -} - -static inline int sensors_data_open(const struct hw_module_t* module, - struct sensors_data_device_t** device) { - return module->methods->open(module, - SENSORS_HARDWARE_DATA, (struct hw_device_t**)device); -} - -static inline int sensors_data_close(struct sensors_data_device_t* device) { - return device->common.close(&device->common); -} - -__END_DECLS diff --git a/modules/Android.mk b/modules/Android.mk new file mode 100644 index 00000000..04b91401 --- /dev/null +++ b/modules/Android.mk @@ -0,0 +1,2 @@ +hardware_modules := gralloc hwcomposer audio +include $(call all-named-subdir-makefiles,$(hardware_modules)) diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk new file mode 100644 index 00000000..f7730794 --- /dev/null +++ b/modules/audio/Android.mk @@ -0,0 +1,43 @@ +# Copyright (C) 2011 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. + +LOCAL_PATH := $(call my-dir) + +# The default audio HAL module, which is a stub, that is loaded if no other +# device specific modules are present. The exact load order can be seen in +# libhardware/hardware.c +# +# The format of the name is audio.<type>.<hardware/etc>.so where the only +# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc. +include $(CLEAR_VARS) + +LOCAL_MODULE := audio.primary.default +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw +LOCAL_SRC_FILES := audio_hw.c +LOCAL_SHARED_LIBRARIES := liblog libcutils +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + +# The stub audio policy HAL module that can be used as a skeleton for +# new implementations. +include $(CLEAR_VARS) + +LOCAL_MODULE := audio_policy.stub +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw +LOCAL_SRC_FILES := audio_policy.c +LOCAL_SHARED_LIBRARIES := liblog libcutils +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c new file mode 100644 index 00000000..a4826043 --- /dev/null +++ b/modules/audio/audio_hw.c @@ -0,0 +1,435 @@ +/* + * Copyright (C) 2011 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. + */ + +#define LOG_TAG "audio_hw_default" +//#define LOG_NDEBUG 0 + +#include <errno.h> +#include <pthread.h> +#include <stdint.h> +#include <sys/time.h> + +#include <cutils/log.h> + +#include <hardware/hardware.h> +#include <system/audio.h> +#include <hardware/audio.h> + +struct stub_audio_device { + struct audio_hw_device device; +}; + +struct stub_stream_out { + struct audio_stream_out stream; +}; + +struct stub_stream_in { + struct audio_stream_in stream; +}; + +static uint32_t out_get_sample_rate(const struct audio_stream *stream) +{ + return 44100; +} + +static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) +{ + return 0; +} + +static size_t out_get_buffer_size(const struct audio_stream *stream) +{ + return 4096; +} + +static uint32_t out_get_channels(const struct audio_stream *stream) +{ + return AUDIO_CHANNEL_OUT_STEREO; +} + +static int out_get_format(const struct audio_stream *stream) +{ + return AUDIO_FORMAT_PCM_16_BIT; +} + +static int out_set_format(struct audio_stream *stream, int format) +{ + return 0; +} + +static int out_standby(struct audio_stream *stream) +{ + return 0; +} + +static int out_dump(const struct audio_stream *stream, int fd) +{ + return 0; +} + +static int out_set_parameters(struct audio_stream *stream, const char *kvpairs) +{ + return 0; +} + +static char * out_get_parameters(const struct audio_stream *stream, const char *keys) +{ + return strdup(""); +} + +static uint32_t out_get_latency(const struct audio_stream_out *stream) +{ + return 0; +} + +static int out_set_volume(struct audio_stream_out *stream, float left, + float right) +{ + return 0; +} + +static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, + size_t bytes) +{ + /* XXX: fake timing for audio output */ + usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / + out_get_sample_rate(&stream->common)); + return bytes; +} + +static int out_get_render_position(const struct audio_stream_out *stream, + uint32_t *dsp_frames) +{ + return -EINVAL; +} + +static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +/** audio_stream_in implementation **/ +static uint32_t in_get_sample_rate(const struct audio_stream *stream) +{ + return 8000; +} + +static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate) +{ + return 0; +} + +static size_t in_get_buffer_size(const struct audio_stream *stream) +{ + return 320; +} + +static uint32_t in_get_channels(const struct audio_stream *stream) +{ + return AUDIO_CHANNEL_IN_MONO; +} + +static int in_get_format(const struct audio_stream *stream) +{ + return AUDIO_FORMAT_PCM_16_BIT; +} + +static int in_set_format(struct audio_stream *stream, int format) +{ + return 0; +} + +static int in_standby(struct audio_stream *stream) +{ + return 0; +} + +static int in_dump(const struct audio_stream *stream, int fd) +{ + return 0; +} + +static int in_set_parameters(struct audio_stream *stream, const char *kvpairs) +{ + return 0; +} + +static char * in_get_parameters(const struct audio_stream *stream, + const char *keys) +{ + return strdup(""); +} + +static int in_set_gain(struct audio_stream_in *stream, float gain) +{ + return 0; +} + +static ssize_t in_read(struct audio_stream_in *stream, void* buffer, + size_t bytes) +{ + /* XXX: fake timing for audio input */ + usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / + in_get_sample_rate(&stream->common)); + return bytes; +} + +static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream) +{ + return 0; +} + +static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int adev_open_output_stream(struct audio_hw_device *dev, + uint32_t devices, int *format, + uint32_t *channels, uint32_t *sample_rate, + struct audio_stream_out **stream_out) +{ + struct stub_audio_device *ladev = (struct stub_audio_device *)dev; + struct stub_stream_out *out; + int ret; + + out = (struct stub_stream_out *)calloc(1, sizeof(struct stub_stream_out)); + if (!out) + return -ENOMEM; + + out->stream.common.get_sample_rate = out_get_sample_rate; + out->stream.common.set_sample_rate = out_set_sample_rate; + out->stream.common.get_buffer_size = out_get_buffer_size; + out->stream.common.get_channels = out_get_channels; + out->stream.common.get_format = out_get_format; + out->stream.common.set_format = out_set_format; + out->stream.common.standby = out_standby; + out->stream.common.dump = out_dump; + out->stream.common.set_parameters = out_set_parameters; + out->stream.common.get_parameters = out_get_parameters; + out->stream.common.add_audio_effect = out_add_audio_effect; + out->stream.common.remove_audio_effect = out_remove_audio_effect; + out->stream.get_latency = out_get_latency; + out->stream.set_volume = out_set_volume; + out->stream.write = out_write; + out->stream.get_render_position = out_get_render_position; + + *stream_out = &out->stream; + return 0; + +err_open: + free(out); + *stream_out = NULL; + return ret; +} + +static void adev_close_output_stream(struct audio_hw_device *dev, + struct audio_stream_out *stream) +{ + free(stream); +} + +static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) +{ + return -ENOSYS; +} + +static char * adev_get_parameters(const struct audio_hw_device *dev, + const char *keys) +{ + return NULL; +} + +static int adev_init_check(const struct audio_hw_device *dev) +{ + return 0; +} + +static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) +{ + return -ENOSYS; +} + +static int adev_set_master_volume(struct audio_hw_device *dev, float volume) +{ + return -ENOSYS; +} + +static int adev_set_mode(struct audio_hw_device *dev, int mode) +{ + return 0; +} + +static int adev_set_mic_mute(struct audio_hw_device *dev, bool state) +{ + return -ENOSYS; +} + +static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) +{ + return -ENOSYS; +} + +static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev, + uint32_t sample_rate, int format, + int channel_count) +{ + return 320; +} + +static int adev_open_input_stream(struct audio_hw_device *dev, uint32_t devices, + int *format, uint32_t *channels, + uint32_t *sample_rate, + audio_in_acoustics_t acoustics, + struct audio_stream_in **stream_in) +{ + struct stub_audio_device *ladev = (struct stub_audio_device *)dev; + struct stub_stream_in *in; + int ret; + + in = (struct stub_stream_in *)calloc(1, sizeof(struct stub_stream_in)); + if (!in) + return -ENOMEM; + + in->stream.common.get_sample_rate = in_get_sample_rate; + in->stream.common.set_sample_rate = in_set_sample_rate; + in->stream.common.get_buffer_size = in_get_buffer_size; + in->stream.common.get_channels = in_get_channels; + in->stream.common.get_format = in_get_format; + in->stream.common.set_format = in_set_format; + in->stream.common.standby = in_standby; + in->stream.common.dump = in_dump; + in->stream.common.set_parameters = in_set_parameters; + in->stream.common.get_parameters = in_get_parameters; + in->stream.common.add_audio_effect = in_add_audio_effect; + in->stream.common.remove_audio_effect = in_remove_audio_effect; + in->stream.set_gain = in_set_gain; + in->stream.read = in_read; + in->stream.get_input_frames_lost = in_get_input_frames_lost; + + *stream_in = &in->stream; + return 0; + +err_open: + free(in); + *stream_in = NULL; + return ret; +} + +static void adev_close_input_stream(struct audio_hw_device *dev, + struct audio_stream_in *in) +{ + return; +} + +static int adev_dump(const audio_hw_device_t *device, int fd) +{ + return 0; +} + +static int adev_close(hw_device_t *device) +{ + free(device); + return 0; +} + +static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev) +{ + return (/* OUT */ + AUDIO_DEVICE_OUT_EARPIECE | + AUDIO_DEVICE_OUT_SPEAKER | + AUDIO_DEVICE_OUT_WIRED_HEADSET | + AUDIO_DEVICE_OUT_WIRED_HEADPHONE | + AUDIO_DEVICE_OUT_AUX_DIGITAL | + AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | + AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | + AUDIO_DEVICE_OUT_ALL_SCO | + AUDIO_DEVICE_OUT_DEFAULT | + /* IN */ + AUDIO_DEVICE_IN_COMMUNICATION | + AUDIO_DEVICE_IN_AMBIENT | + AUDIO_DEVICE_IN_BUILTIN_MIC | + AUDIO_DEVICE_IN_WIRED_HEADSET | + AUDIO_DEVICE_IN_AUX_DIGITAL | + AUDIO_DEVICE_IN_BACK_MIC | + AUDIO_DEVICE_IN_ALL_SCO | + AUDIO_DEVICE_IN_DEFAULT); +} + +static int adev_open(const hw_module_t* module, const char* name, + hw_device_t** device) +{ + struct stub_audio_device *adev; + int ret; + + if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) + return -EINVAL; + + adev = calloc(1, sizeof(struct stub_audio_device)); + if (!adev) + return -ENOMEM; + + adev->device.common.tag = HARDWARE_DEVICE_TAG; + adev->device.common.version = 0; + adev->device.common.module = (struct hw_module_t *) module; + adev->device.common.close = adev_close; + + adev->device.get_supported_devices = adev_get_supported_devices; + adev->device.init_check = adev_init_check; + adev->device.set_voice_volume = adev_set_voice_volume; + adev->device.set_master_volume = adev_set_master_volume; + adev->device.set_mode = adev_set_mode; + adev->device.set_mic_mute = adev_set_mic_mute; + adev->device.get_mic_mute = adev_get_mic_mute; + adev->device.set_parameters = adev_set_parameters; + adev->device.get_parameters = adev_get_parameters; + adev->device.get_input_buffer_size = adev_get_input_buffer_size; + adev->device.open_output_stream = adev_open_output_stream; + adev->device.close_output_stream = adev_close_output_stream; + adev->device.open_input_stream = adev_open_input_stream; + adev->device.close_input_stream = adev_close_input_stream; + adev->device.dump = adev_dump; + + *device = &adev->device.common; + + return 0; +} + +static struct hw_module_methods_t hal_module_methods = { + .open = adev_open, +}; + +struct audio_module HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = AUDIO_HARDWARE_MODULE_ID, + .name = "Default audio HW HAL", + .author = "The Android Open Source Project", + .methods = &hal_module_methods, + }, +}; diff --git a/modules/audio/audio_policy.c b/modules/audio/audio_policy.c new file mode 100644 index 00000000..409f0a10 --- /dev/null +++ b/modules/audio/audio_policy.c @@ -0,0 +1,324 @@ +/* + * Copyright (C) 2011 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. + */ + +#define LOG_TAG "audio_policy_default" +//#define LOG_NDEBUG 0 + +#include <errno.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include <hardware/hardware.h> +#include <system/audio.h> +#include <system/audio_policy.h> +#include <hardware/audio_policy.h> + +struct default_ap_module { + struct audio_policy_module module; +}; + +struct default_ap_device { + struct audio_policy_device device; +}; + +struct default_audio_policy { + struct audio_policy policy; + + struct audio_policy_service_ops *aps_ops; + void *service; +}; + +static int ap_set_device_connection_state(struct audio_policy *pol, + audio_devices_t device, + audio_policy_dev_state_t state, + const char *device_address) +{ + return -ENOSYS; +} + +static audio_policy_dev_state_t ap_get_device_connection_state( + const struct audio_policy *pol, + audio_devices_t device, + const char *device_address) +{ + return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; +} + +static void ap_set_phone_state(struct audio_policy *pol, int state) +{ +} + +static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode, + uint32_t mask) +{ +} + +static void ap_set_force_use(struct audio_policy *pol, + audio_policy_force_use_t usage, + audio_policy_forced_cfg_t config) +{ +} + + /* retreive current device category forced for a given usage */ +static audio_policy_forced_cfg_t ap_get_force_use( + const struct audio_policy *pol, + audio_policy_force_use_t usage) +{ + return AUDIO_POLICY_FORCE_NONE; +} + +/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE + * can still be muted. */ +static void ap_set_can_mute_enforced_audible(struct audio_policy *pol, + bool can_mute) +{ +} + +static int ap_init_check(const struct audio_policy *pol) +{ + return 0; +} + +static audio_io_handle_t ap_get_output(struct audio_policy *pol, + audio_stream_type_t stream, + uint32_t sampling_rate, + uint32_t format, + uint32_t channels, + audio_policy_output_flags_t flags) +{ + return 0; +} + +static int ap_start_output(struct audio_policy *pol, audio_io_handle_t output, + audio_stream_type_t stream, int session) +{ + return -ENOSYS; +} + +static int ap_stop_output(struct audio_policy *pol, audio_io_handle_t output, + audio_stream_type_t stream, int session) +{ + return -ENOSYS; +} + +static void ap_release_output(struct audio_policy *pol, + audio_io_handle_t output) +{ +} + +static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource, + uint32_t sampling_rate, + uint32_t format, + uint32_t channels, + audio_in_acoustics_t acoustics) +{ + return 0; +} + +static int ap_start_input(struct audio_policy *pol, audio_io_handle_t input) +{ + return -ENOSYS; +} + +static int ap_stop_input(struct audio_policy *pol, audio_io_handle_t input) +{ + return -ENOSYS; +} + +static void ap_release_input(struct audio_policy *pol, audio_io_handle_t input) +{ +} + +static void ap_init_stream_volume(struct audio_policy *pol, + audio_stream_type_t stream, int index_min, + int index_max) +{ +} + +static int ap_set_stream_volume_index(struct audio_policy *pol, + audio_stream_type_t stream, + int index) +{ + return -ENOSYS; +} + +static int ap_get_stream_volume_index(const struct audio_policy *pol, + audio_stream_type_t stream, + int *index) +{ + return -ENOSYS; +} + +static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol, + audio_stream_type_t stream) +{ + return 0; +} + +static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol, + audio_stream_type_t stream) +{ + return 0; +} + +static audio_io_handle_t ap_get_output_for_effect(struct audio_policy *pol, + struct effect_descriptor_s *desc) +{ + return 0; +} + +static int ap_register_effect(struct audio_policy *pol, + struct effect_descriptor_s *desc, + audio_io_handle_t output, + uint32_t strategy, + int session, + int id) +{ + return -ENOSYS; +} + +static int ap_unregister_effect(struct audio_policy *pol, int id) +{ + return -ENOSYS; +} + +static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled) +{ + return -ENOSYS; +} + +static bool ap_is_stream_active(const struct audio_policy *pol, int stream, + uint32_t in_past_ms) +{ + return false; +} + +static int ap_dump(const struct audio_policy *pol, int fd) +{ + return -ENOSYS; +} + +static int create_default_ap(const struct audio_policy_device *device, + struct audio_policy_service_ops *aps_ops, + void *service, + struct audio_policy **ap) +{ + struct default_ap_device *dev; + struct default_audio_policy *dap; + int ret; + + *ap = NULL; + + if (!service || !aps_ops) + return -EINVAL; + + dap = (struct default_audio_policy *)calloc(1, sizeof(*dap)); + if (!dap) + return -ENOMEM; + + dap->policy.set_device_connection_state = ap_set_device_connection_state; + dap->policy.get_device_connection_state = ap_get_device_connection_state; + dap->policy.set_phone_state = ap_set_phone_state; + dap->policy.set_ringer_mode = ap_set_ringer_mode; + dap->policy.set_force_use = ap_set_force_use; + dap->policy.get_force_use = ap_get_force_use; + dap->policy.set_can_mute_enforced_audible = + ap_set_can_mute_enforced_audible; + dap->policy.init_check = ap_init_check; + dap->policy.get_output = ap_get_output; + dap->policy.start_output = ap_start_output; + dap->policy.stop_output = ap_stop_output; + dap->policy.release_output = ap_release_output; + dap->policy.get_input = ap_get_input; + dap->policy.start_input = ap_start_input; + dap->policy.stop_input = ap_stop_input; + dap->policy.release_input = ap_release_input; + dap->policy.init_stream_volume = ap_init_stream_volume; + dap->policy.set_stream_volume_index = ap_set_stream_volume_index; + dap->policy.get_stream_volume_index = ap_get_stream_volume_index; + dap->policy.get_strategy_for_stream = ap_get_strategy_for_stream; + dap->policy.get_devices_for_stream = ap_get_devices_for_stream; + dap->policy.get_output_for_effect = ap_get_output_for_effect; + dap->policy.register_effect = ap_register_effect; + dap->policy.unregister_effect = ap_unregister_effect; + dap->policy.set_effect_enabled = ap_set_effect_enabled; + dap->policy.is_stream_active = ap_is_stream_active; + dap->policy.dump = ap_dump; + + dap->service = service; + dap->aps_ops = aps_ops; + + *ap = &dap->policy; + return 0; +} + +static int destroy_default_ap(const struct audio_policy_device *ap_dev, + struct audio_policy *ap) +{ + free(ap); + return 0; +} + +static int default_ap_dev_close(hw_device_t* device) +{ + free(device); + return 0; +} + +static int default_ap_dev_open(const hw_module_t* module, const char* name, + hw_device_t** device) +{ + struct default_ap_device *dev; + + *device = NULL; + + if (strcmp(name, AUDIO_POLICY_INTERFACE) != 0) + return -EINVAL; + + dev = (struct default_ap_device *)calloc(1, sizeof(*dev)); + if (!dev) + return -ENOMEM; + + dev->device.common.tag = HARDWARE_DEVICE_TAG; + dev->device.common.version = 0; + dev->device.common.module = (hw_module_t *)module; + dev->device.common.close = default_ap_dev_close; + dev->device.create_audio_policy = create_default_ap; + dev->device.destroy_audio_policy = destroy_default_ap; + + *device = &dev->device.common; + + return 0; +} + +static struct hw_module_methods_t default_ap_module_methods = { + .open = default_ap_dev_open, +}; + +struct default_ap_module HAL_MODULE_INFO_SYM = { + .module = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = AUDIO_POLICY_HARDWARE_MODULE_ID, + .name = "Default audio policy HAL", + .author = "The Android Open Source Project", + .methods = &default_ap_module_methods, + }, + }, +}; diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk index cbfd82b9..b24c4cd1 100644 --- a/modules/gralloc/Android.mk +++ b/modules/gralloc/Android.mk @@ -15,10 +15,10 @@ LOCAL_PATH := $(call my-dir) -# HAL module implemenation, not prelinked and stored in +# HAL module implemenation stored in # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so include $(CLEAR_VARS) -LOCAL_PRELINK_MODULE := false + LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_SHARED_LIBRARIES := liblog libcutils @@ -29,11 +29,5 @@ LOCAL_SRC_FILES := \ LOCAL_MODULE := gralloc.default LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -ifeq ($(BOARD_NO_PAGE_FLIPPING),true) -LOCAL_CFLAGS += -DNO_PAGE_FLIPPING -endif -ifeq ($(BOARD_NO_32BPP),true) -LOCAL_CFLAGS += -DNO_32BPP -endif include $(BUILD_SHARED_LIBRARY) diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp index fe57a8a0..f9089768 100644 --- a/modules/gralloc/framebuffer.cpp +++ b/modules/gralloc/framebuffer.cpp @@ -43,12 +43,7 @@ /*****************************************************************************/ // numbers of buffers for page flipping -#if defined(NO_PAGE_FLIPPING) -// page-flipping is buggy on some devices -#define NUM_BUFFERS 1 -#else #define NUM_BUFFERS 2 -#endif enum { @@ -176,21 +171,6 @@ int mapFrameBufferLocked(struct private_module_t* module) info.yoffset = 0; info.activate = FB_ACTIVATE_NOW; -#if defined(NO_32BPP) - /* - * Explicitly request 5/6/5 - */ - info.bits_per_pixel = 16; - info.red.offset = 11; - info.red.length = 5; - info.green.offset = 5; - info.green.length = 6; - info.blue.offset = 0; - info.blue.length = 5; - info.transp.offset = 0; - info.transp.length = 0; -#endif - /* * Request NUM_BUFFERS screens (at lest 2 for page flipping) */ @@ -357,9 +337,6 @@ int fb_device_open(hw_module_t const* module, const char* name, int format = (m->info.bits_per_pixel == 32) ? HAL_PIXEL_FORMAT_RGBX_8888 : HAL_PIXEL_FORMAT_RGB_565; -#ifdef NO_32BPP - format = HAL_PIXEL_FORMAT_RGB_565; -#endif const_cast<uint32_t&>(dev->device.flags) = 0; const_cast<uint32_t&>(dev->device.width) = m->info.xres; const_cast<uint32_t&>(dev->device.height) = m->info.yres; diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk index 233059b6..f1e819b3 100644 --- a/modules/hwcomposer/Android.mk +++ b/modules/hwcomposer/Android.mk @@ -15,13 +15,14 @@ LOCAL_PATH := $(call my-dir) -# HAL module implemenation, not prelinked and stored in +# HAL module implemenation stored in # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so include $(CLEAR_VARS) -LOCAL_PRELINK_MODULE := false + LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_SHARED_LIBRARIES := liblog libEGL LOCAL_SRC_FILES := hwcomposer.cpp LOCAL_MODULE := hwcomposer.default LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\" +LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) diff --git a/modules/hwcomposer/hwcomposer.cpp b/modules/hwcomposer/hwcomposer.cpp index 939210bf..68b70706 100644 --- a/modules/hwcomposer/hwcomposer.cpp +++ b/modules/hwcomposer/hwcomposer.cpp @@ -15,7 +15,6 @@ */ #include <hardware/hardware.h> -#include <hardware/overlay.h> #include <fcntl.h> #include <errno.h> diff --git a/modules/overlay/Android.mk b/modules/overlay/Android.mk deleted file mode 100644 index 8b7db26b..00000000 --- a/modules/overlay/Android.mk +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2008 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. - - -LOCAL_PATH := $(call my-dir) - -# HAL module implemenation, not prelinked and stored in -# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so -include $(CLEAR_VARS) -LOCAL_PRELINK_MODULE := false -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw -LOCAL_SHARED_LIBRARIES := liblog -LOCAL_SRC_FILES := overlay.cpp -LOCAL_MODULE := overlay.default -include $(BUILD_SHARED_LIBRARY) diff --git a/modules/overlay/README.android b/modules/overlay/README.android deleted file mode 100644 index 971d619d..00000000 --- a/modules/overlay/README.android +++ /dev/null @@ -1,3 +0,0 @@ - -Skeleton for the "overlay" HAL module. - diff --git a/modules/overlay/overlay.cpp b/modules/overlay/overlay.cpp deleted file mode 100644 index 8bb73db2..00000000 --- a/modules/overlay/overlay.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -#define LOG_TAG "Overlay" - -#include <hardware/hardware.h> -#include <hardware/overlay.h> - -#include <fcntl.h> -#include <errno.h> - -#include <cutils/log.h> -#include <cutils/atomic.h> - -/*****************************************************************************/ - -struct overlay_control_context_t { - struct overlay_control_device_t device; - /* our private state goes below here */ -}; - -struct overlay_data_context_t { - struct overlay_data_device_t device; - /* our private state goes below here */ -}; - -static int overlay_device_open(const struct hw_module_t* module, const char* name, - struct hw_device_t** device); - -static struct hw_module_methods_t overlay_module_methods = { - open: overlay_device_open -}; - -struct overlay_module_t HAL_MODULE_INFO_SYM = { - common: { - tag: HARDWARE_MODULE_TAG, - version_major: 1, - version_minor: 0, - id: OVERLAY_HARDWARE_MODULE_ID, - name: "Sample Overlay module", - author: "The Android Open Source Project", - methods: &overlay_module_methods, - } -}; - -/*****************************************************************************/ - -/* - * This is the overlay_t object, it is returned to the user and represents - * an overlay. - * This handles will be passed across processes and possibly given to other - * HAL modules (for instance video decode modules). - */ - -class overlay_object : public overlay_t { - - struct handle_t : public native_handle { - /* add the data fields we need here, for instance: */ - int width; - int height; - }; - - handle_t mHandle; - - static overlay_handle_t getHandleRef(struct overlay_t* overlay) { - /* returns a reference to the handle, caller doesn't take ownership */ - return &(static_cast<overlay_object *>(overlay)->mHandle); - } - -public: - overlay_object() { - this->overlay_t::getHandleRef = getHandleRef; - mHandle.version = sizeof(native_handle); - mHandle.numFds = 0; - mHandle.numInts = 2; // extra ints we have in our handle - } -}; - -// **************************************************************************** -// Control module -// **************************************************************************** - -static int overlay_get(struct overlay_control_device_t *dev, int name) { - int result = -1; - switch (name) { - case OVERLAY_MINIFICATION_LIMIT: - result = 0; // 0 = no limit - break; - case OVERLAY_MAGNIFICATION_LIMIT: - result = 0; // 0 = no limit - break; - case OVERLAY_SCALING_FRAC_BITS: - result = 0; // 0 = infinite - break; - case OVERLAY_ROTATION_STEP_DEG: - result = 90; // 90 rotation steps (for instance) - break; - case OVERLAY_HORIZONTAL_ALIGNMENT: - result = 1; // 1-pixel alignment - break; - case OVERLAY_VERTICAL_ALIGNMENT: - result = 1; // 1-pixel alignment - break; - case OVERLAY_WIDTH_ALIGNMENT: - result = 1; // 1-pixel alignment - break; - case OVERLAY_HEIGHT_ALIGNMENT: - result = 1; // 1-pixel alignment - break; - } - return result; -} - -static overlay_t* overlay_createOverlay(struct overlay_control_device_t *dev, - uint32_t w, uint32_t h, int32_t format) -{ - /* check the input params, reject if not supported or invalid */ - switch (format) { - case OVERLAY_FORMAT_RGBA_8888: - case OVERLAY_FORMAT_RGB_565: - case OVERLAY_FORMAT_BGRA_8888: - // add supported format here (especially YUV formats) - break; - default: - return NULL; - } - - /* Create overlay object. Talk to the h/w here and adjust to what it can - * do. the overlay_t returned can be a C++ object, subclassing overlay_t - * if needed. - * - * we probably want to keep a list of the overlay_t created so they can - * all be cleaned up in overlay_close(). - */ - return new overlay_object( /* pass needed params here*/ ); -} - -static void overlay_destroyOverlay(struct overlay_control_device_t *dev, - overlay_t* overlay) -{ - /* free resources associated with this overlay_t */ - delete overlay; -} - -static int overlay_setPosition(struct overlay_control_device_t *dev, - overlay_t* overlay, - int x, int y, uint32_t w, uint32_t h) { - /* set this overlay's position (talk to the h/w) */ - return -EINVAL; -} - -static int overlay_getPosition(struct overlay_control_device_t *dev, - overlay_t* overlay, - int* x, int* y, uint32_t* w, uint32_t* h) { - /* get this overlay's position */ - return -EINVAL; -} - -static int overlay_setParameter(struct overlay_control_device_t *dev, - overlay_t* overlay, int param, int value) { - - int result = 0; - /* set this overlay's parameter (talk to the h/w) */ - switch (param) { - case OVERLAY_ROTATION_DEG: - /* if only 90 rotations are supported, the call fails - * for other values */ - break; - case OVERLAY_DITHER: - break; - case OVERLAY_TRANSFORM: - // see OVERLAY_TRANSFORM_* - break; - default: - result = -EINVAL; - break; - } - return result; -} - -static int overlay_control_close(struct hw_device_t *dev) -{ - struct overlay_control_context_t* ctx = (struct overlay_control_context_t*)dev; - if (ctx) { - /* free all resources associated with this device here - * in particular the overlay_handle_t, outstanding overlay_t, etc... - */ - free(ctx); - } - return 0; -} - -// **************************************************************************** -// Data module -// **************************************************************************** - -int overlay_initialize(struct overlay_data_device_t *dev, - overlay_handle_t handle) -{ - /* - * overlay_handle_t should contain all the information to "inflate" this - * overlay. Typically it'll have a file descriptor, informations about - * how many buffers are there, etc... - * It is also the place to mmap all buffers associated with this overlay - * (see getBufferAddress). - * - * NOTE: this function doesn't take ownership of overlay_handle_t - * - */ - - return -EINVAL; -} - -int overlay_dequeueBuffer(struct overlay_data_device_t *dev, - overlay_buffer_t* buf) -{ - /* blocks until a buffer is available and return an opaque structure - * representing this buffer. - */ - return -EINVAL; -} - -int overlay_queueBuffer(struct overlay_data_device_t *dev, - overlay_buffer_t buffer) -{ - /* Mark this buffer for posting and recycle or free overlay_buffer_t. */ - return -EINVAL; -} - -void *overlay_getBufferAddress(struct overlay_data_device_t *dev, - overlay_buffer_t buffer) -{ - /* this may fail (NULL) if this feature is not supported. In that case, - * presumably, there is some other HAL module that can fill the buffer, - * using a DSP for instance */ - return NULL; -} - -static int overlay_data_close(struct hw_device_t *dev) -{ - struct overlay_data_context_t* ctx = (struct overlay_data_context_t*)dev; - if (ctx) { - /* free all resources associated with this device here - * in particular all pending overlay_buffer_t if needed. - * - * NOTE: overlay_handle_t passed in initialize() is NOT freed and - * its file descriptors are not closed (this is the responsibility - * of the caller). - */ - free(ctx); - } - return 0; -} - -/*****************************************************************************/ - -static int overlay_device_open(const struct hw_module_t* module, const char* name, - struct hw_device_t** device) -{ - int status = -EINVAL; - if (!strcmp(name, OVERLAY_HARDWARE_CONTROL)) { - struct overlay_control_context_t *dev; - dev = (overlay_control_context_t*)malloc(sizeof(*dev)); - - /* initialize our state here */ - memset(dev, 0, sizeof(*dev)); - - /* initialize the procs */ - dev->device.common.tag = HARDWARE_DEVICE_TAG; - dev->device.common.version = 0; - dev->device.common.module = const_cast<hw_module_t*>(module); - dev->device.common.close = overlay_control_close; - - dev->device.get = overlay_get; - dev->device.createOverlay = overlay_createOverlay; - dev->device.destroyOverlay = overlay_destroyOverlay; - dev->device.setPosition = overlay_setPosition; - dev->device.getPosition = overlay_getPosition; - dev->device.setParameter = overlay_setParameter; - - *device = &dev->device.common; - status = 0; - } else if (!strcmp(name, OVERLAY_HARDWARE_DATA)) { - struct overlay_data_context_t *dev; - dev = (overlay_data_context_t*)malloc(sizeof(*dev)); - - /* initialize our state here */ - memset(dev, 0, sizeof(*dev)); - - /* initialize the procs */ - dev->device.common.tag = HARDWARE_DEVICE_TAG; - dev->device.common.version = 0; - dev->device.common.module = const_cast<hw_module_t*>(module); - dev->device.common.close = overlay_data_close; - - dev->device.initialize = overlay_initialize; - dev->device.dequeueBuffer = overlay_dequeueBuffer; - dev->device.queueBuffer = overlay_queueBuffer; - dev->device.getBufferAddress = overlay_getBufferAddress; - - *device = &dev->device.common; - status = 0; - } - return status; -} diff --git a/tests/nusensors/nusensors.cpp b/tests/nusensors/nusensors.cpp index 9d1a90c6..3c8eae99 100644 --- a/tests/nusensors/nusensors.cpp +++ b/tests/nusensors/nusensors.cpp @@ -23,6 +23,7 @@ #include <cutils/log.h> #include <hardware/sensors.h> +#include <utils/Timers.h> char const* getSensorName(int type) { switch(type) { @@ -32,12 +33,26 @@ char const* getSensorName(int type) { return "Mag"; case SENSOR_TYPE_ORIENTATION: return "Ori"; - case SENSOR_TYPE_PROXIMITY: - return "Prx"; - case SENSOR_TYPE_TEMPERATURE: - return "Tmp"; + case SENSOR_TYPE_GYROSCOPE: + return "Gyr"; case SENSOR_TYPE_LIGHT: return "Lux"; + case SENSOR_TYPE_PRESSURE: + return "Bar"; + case SENSOR_TYPE_TEMPERATURE: + return "Tmp"; + case SENSOR_TYPE_PROXIMITY: + return "Prx"; + case SENSOR_TYPE_GRAVITY: + return "Grv"; + case SENSOR_TYPE_LINEAR_ACCELERATION: + return "Lac"; + case SENSOR_TYPE_ROTATION_VECTOR: + return "Rot"; + case SENSOR_TYPE_RELATIVE_HUMIDITY: + return "Hum"; + case SENSOR_TYPE_AMBIENT_TEMPERATURE: + return "Tam"; } return "ukn"; } @@ -54,8 +69,15 @@ int main(int argc, char** argv) return 0; } + err = sensors_open(&module->common, &device); + if (err != 0) { + printf("sensors_open() failed (%s)\n", strerror(-err)); + return 0; + } + struct sensor_t const* list; int count = module->get_sensors_list(module, &list); + printf("%d sensors found:\n", count); for (int i=0 ; i<count ; i++) { printf("%s\n" "\tvendor: %s\n" @@ -75,13 +97,8 @@ int main(int argc, char** argv) list[i].power); } - sensors_event_t buffer[16]; - - err = sensors_open(&module->common, &device); - if (err != 0) { - printf("sensors_open() failed (%s)\n", strerror(-err)); - return 0; - } + static const size_t numEvents = 16; + sensors_event_t buffer[numEvents]; for (int i=0 ; i<count ; i++) { err = device->activate(device, list[i].handle, 0); @@ -99,11 +116,11 @@ int main(int argc, char** argv) list[i].name, strerror(-err)); return 0; } - device->setDelay(device, list[i].handle, 10000000); + device->setDelay(device, list[i].handle, ms2ns(10)); } do { - int n = device->poll(device, buffer, 16); + int n = device->poll(device, buffer, numEvents); if (n < 0) { printf("poll() failed (%s)\n", strerror(-err)); break; @@ -121,59 +138,42 @@ int main(int argc, char** argv) switch(data.type) { case SENSOR_TYPE_ACCELEROMETER: - printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", - getSensorName(data.type), - data.timestamp, - data.acceleration.x, - data.acceleration.y, - data.acceleration.z); - break; case SENSOR_TYPE_MAGNETIC_FIELD: - printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", - getSensorName(data.type), - data.timestamp, - data.magnetic.x, - data.magnetic.y, - data.magnetic.z); - break; case SENSOR_TYPE_ORIENTATION: + case SENSOR_TYPE_GYROSCOPE: + case SENSOR_TYPE_GRAVITY: + case SENSOR_TYPE_LINEAR_ACCELERATION: + case SENSOR_TYPE_ROTATION_VECTOR: printf("sensor=%s, time=%lld, value=<%5.1f,%5.1f,%5.1f>\n", getSensorName(data.type), data.timestamp, - data.orientation.azimuth, - data.orientation.pitch, - data.orientation.roll); - break; - case SENSOR_TYPE_PROXIMITY: - printf("sensor=%s, time=%lld, value=%f\n", - getSensorName(data.type), - data.timestamp, - data.distance); - break; - case SENSOR_TYPE_TEMPERATURE: - printf("sensor=%s, time=%lld, value=%f\n", - getSensorName(data.type), - data.timestamp, - data.temperature); + data.data[0], + data.data[1], + data.data[2]); break; + case SENSOR_TYPE_LIGHT: + case SENSOR_TYPE_PRESSURE: + case SENSOR_TYPE_TEMPERATURE: + case SENSOR_TYPE_PROXIMITY: + case SENSOR_TYPE_RELATIVE_HUMIDITY: + case SENSOR_TYPE_AMBIENT_TEMPERATURE: printf("sensor=%s, time=%lld, value=%f\n", getSensorName(data.type), data.timestamp, - data.light); + data.data[0]); break; + default: - printf("sensor=%d, time=%lld, value=<%f,%f,%f>\n", + printf("sensor=%d, time=%lld, value=<%f,%f,%f, ...>\n", data.type, data.timestamp, - data.acceleration.x, - data.acceleration.y, - data.acceleration.z); + data.data[0], + data.data[1], + data.data[2]); break; } } - - } while (1); // fix that |