diff options
Diffstat (limited to 'include/media')
52 files changed, 3280 insertions, 244 deletions
diff --git a/include/media/AudioEffect.h b/include/media/AudioEffect.h new file mode 100644 index 0000000..c967efb --- /dev/null +++ b/include/media/AudioEffect.h @@ -0,0 +1,470 @@ +/* + * Copyright (C) 2009 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_AUDIOEFFECT_H +#define ANDROID_AUDIOEFFECT_H + +#include <stdint.h> +#include <sys/types.h> + +#include <media/IAudioFlinger.h> +#include <media/IEffect.h> +#include <media/IEffectClient.h> +#include <media/EffectApi.h> +#include <media/AudioSystem.h> + +#include <utils/RefBase.h> +#include <utils/Errors.h> +#include <binder/IInterface.h> + + +namespace android { + +// ---------------------------------------------------------------------------- + +class effect_param_cblk_t; + +// ---------------------------------------------------------------------------- + +class AudioEffect : public RefBase +{ +public: + + /* + * Static methods for effect libraries management. + */ + + /* + * Loads the effect library which path is given as first argument. + * This must be the full path of a dynamic library (.so) implementing one or + * more effect engines and exposing the effect library interface described in + * EffectApi.h. The function returns a handle on the library for use by + * further call to unloadEffectLibrary() to unload the library. + * + * Parameters: + * libPath: full path of the dynamic library file in the file system. + * handle: address where to return the library handle + * + * Returned status (from utils/Errors.h) can be: + * NO_ERROR successful operation. + * PERMISSION_DENIED could not get AudioFlinger interface or + * application does not have permission to configure audio + * NO_INIT effect factory not initialized or + * library could not be loaded or + * library does not implement required functions + * BAD_VALUE invalid libPath string or handle + * + * Returned value: + * *handle updated with library handle + */ + static status_t loadEffectLibrary(const char *libPath, int *handle); + + /* + * Unloads the effect library which handle is given as argument. + * + * Parameters: + * handle: library handle + * + * Returned status (from utils/Errors.h) can be: + * NO_ERROR successful operation. + * PERMISSION_DENIED could not get AudioFlinger interface or + * application does not have permission to configure audio + * NO_INIT effect factory not initialized + * BAD_VALUE invalid handle + */ + static status_t unloadEffectLibrary(int handle); + + /* + * Static methods for effects enumeration. + */ + + /* + * Returns the number of effects available. This method together + * with queryEffect() is used to enumerate all effects: + * The enumeration sequence is: + * queryNumberEffects(&num_effects); + * for (i = 0; i < num_effects; i++) + * queryEffect(i,...); + * + * Parameters: + * numEffects: address where the number of effects should be returned. + * + * Returned status (from utils/Errors.h) can be: + * NO_ERROR successful operation. + * PERMISSION_DENIED could not get AudioFlinger interface + * NO_INIT effect library failed to initialize + * BAD_VALUE invalid numEffects pointer + * + * Returned value + * *numEffects: updated with number of effects available + */ + static status_t queryNumberEffects(uint32_t *numEffects); + + /* + * Returns an effect descriptor during effect + * enumeration. + * + * Parameters: + * index: index of the queried effect. + * descriptor: address where the effect descriptor should be returned. + * + * Returned status (from utils/Errors.h) can be: + * NO_ERROR successful operation. + * PERMISSION_DENIED could not get AudioFlinger interface + * NO_INIT effect library failed to initialize + * BAD_VALUE invalid descriptor pointer or index + * INVALID_OPERATION effect list has changed since last execution of queryNumberEffects() + * + * Returned value + * *descriptor: updated with effect descriptor + */ + static status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor); + + + /* + * Returns the descriptor for the specified effect uuid. + * + * Parameters: + * uuid: pointer to effect uuid. + * descriptor: address where the effect descriptor should be returned. + * + * Returned status (from utils/Errors.h) can be: + * NO_ERROR successful operation. + * PERMISSION_DENIED could not get AudioFlinger interface + * NO_INIT effect library failed to initialize + * BAD_VALUE invalid uuid or descriptor pointers + * NAME_NOT_FOUND no effect with this uuid found + * + * Returned value + * *descriptor updated with effect descriptor + */ + static status_t getEffectDescriptor(effect_uuid_t *uuid, effect_descriptor_t *descriptor); + + + /* + * Events used by callback function (effect_callback_t). + */ + enum event_type { + EVENT_CONTROL_STATUS_CHANGED = 0, + EVENT_ENABLE_STATUS_CHANGED = 1, + EVENT_PARAMETER_CHANGED = 2, + EVENT_ERROR = 3 + }; + + /* Callback function notifying client application of a change in effect engine state or + * configuration. + * An effect engine can be shared by several applications but only one has the control + * of the engine activity and configuration at a time. + * The EVENT_CONTROL_STATUS_CHANGED event is received when an application loses or + * retrieves the control of the effect engine. Loss of control happens + * if another application requests the use of the engine by creating an AudioEffect for + * the same effect type but with a higher priority. Control is returned when the + * application having the control deletes its AudioEffect object. + * The EVENT_ENABLE_STATUS_CHANGED event is received by all applications not having the + * control of the effect engine when the effect is enabled or disabled. + * The EVENT_PARAMETER_CHANGED event is received by all applications not having the + * control of the effect engine when an effect parameter is changed. + * The EVENT_ERROR event is received when the media server process dies. + * + * Parameters: + * + * event: type of event notified (see enum AudioEffect::event_type). + * user: Pointer to context for use by the callback receiver. + * info: Pointer to optional parameter according to event type: + * - EVENT_CONTROL_STATUS_CHANGED: boolean indicating if control is granted (true) + * or stolen (false). + * - EVENT_ENABLE_STATUS_CHANGED: boolean indicating if effect is now enabled (true) + * or disabled (false). + * - EVENT_PARAMETER_CHANGED: pointer to a effect_param_t structure. + * - EVENT_ERROR: status_t indicating the error (DEAD_OBJECT when media server dies). + */ + + typedef void (*effect_callback_t)(int32_t event, void* user, void *info); + + + /* Constructor. + * AudioEffect is the base class for creating and controlling an effect engine from + * the application process. Creating an AudioEffect object will create the effect engine + * in the AudioFlinger if no engine of the specified type exists. If one exists, this engine + * will be used. The application creating the AudioEffect object (or a derived class like + * Reverb for instance) will either receive control of the effect engine or not, depending + * on the priority parameter. If priority is higher than the priority used by the current + * effect engine owner, the control will be transfered to the new application. Otherwise + * control will remain to the previous application. In this case, the new application will be + * notified of changes in effect engine state or control ownership by the effect callback. + * After creating the AudioEffect, the application must call the initCheck() method and + * check the creation status before trying to control the effect engine (see initCheck()). + * If the effect is to be applied to an AudioTrack or MediaPlayer only the application + * must specify the audio session ID corresponding to this player. + */ + + /* Simple Constructor. + */ + AudioEffect(); + + + /* Constructor. + * + * Parameters: + * + * type: type of effect created: can be null if uuid is specified. This corresponds to + * the OpenSL ES interface implemented by this effect. + * uuid: Uuid of effect created: can be null if type is specified. This uuid corresponds to + * a particular implementation of an effect type. + * priority: requested priority for effect control: the priority level corresponds to the + * value of priority parameter: negative values indicate lower priorities, positive values + * higher priorities, 0 being the normal priority. + * cbf: optional callback function (see effect_callback_t) + * user: pointer to context for use by the callback receiver. + * sessionID: audio session this effect is associated to. If 0, the effect will be global to + * the output mix. If not 0, the effect will be applied to all players + * (AudioTrack or MediaPLayer) within the same audio session. + * output: HAL audio output stream to which this effect must be attached. Leave at 0 for + * automatic output selection by AudioFlinger. + */ + + AudioEffect(const effect_uuid_t *type, + const effect_uuid_t *uuid = NULL, + int32_t priority = 0, + effect_callback_t cbf = 0, + void* user = 0, + int sessionId = 0, + audio_io_handle_t output = 0 + ); + + /* Constructor. + * Same as above but with type and uuid specified by character strings + */ + AudioEffect(const char *typeStr, + const char *uuidStr = NULL, + int32_t priority = 0, + effect_callback_t cbf = 0, + void* user = 0, + int sessionId = 0, + audio_io_handle_t output = 0 + ); + + /* Terminates the AudioEffect and unregisters it from AudioFlinger. + * The effect engine is also destroyed if this AudioEffect was the last controlling + * the engine. + */ + ~AudioEffect(); + + /* Initialize an uninitialized AudioEffect. + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR or ALREADY_EXISTS: successful initialization + * - INVALID_OPERATION: AudioEffect is already initialized + * - BAD_VALUE: invalid parameter + * - NO_INIT: audio flinger or audio hardware not initialized + * */ + status_t set(const effect_uuid_t *type, + const effect_uuid_t *uuid = NULL, + int32_t priority = 0, + effect_callback_t cbf = 0, + void* user = 0, + int sessionId = 0, + audio_io_handle_t output = 0 + ); + + /* Result of constructing the AudioEffect. This must be checked + * before using any AudioEffect API. + * initCheck() can return: + * - NO_ERROR: the effect engine is successfully created and the application has control. + * - ALREADY_EXISTS: the effect engine is successfully created but the application does not + * have control. + * - NO_INIT: the effect creation failed. + * + */ + status_t initCheck() const; + + + /* Returns the unique effect Id for the controlled effect engine. This ID is unique + * system wide and is used for instance in the case of auxiliary effects to attach + * the effect to an AudioTrack or MediaPlayer. + * + */ + int32_t id() const { return mId; } + + /* Returns a descriptor for the effect (see effect_descriptor_t in EffectApi.h). + */ + effect_descriptor_t descriptor() const; + + /* Returns effect control priority of this AudioEffect object. + */ + int32_t priority() const { return mPriority; } + + + /* Enables or disables the effect engine. + * + * Parameters: + * enabled: requested enable state. + * + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation + * - INVALID_OPERATION: the application does not have control of the effect engine or the + * effect is already in the requested state. + */ + virtual status_t setEnabled(bool enabled); + bool getEnabled() const; + + /* Sets a parameter value. + * + * Parameters: + * param: pointer to effect_param_t structure containing the parameter + * and its value (See EffectApi.h). + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation. + * - INVALID_OPERATION: the application does not have control of the effect engine. + * - BAD_VALUE: invalid parameter identifier or value. + * - DEAD_OBJECT: the effect engine has been deleted. + */ + virtual status_t setParameter(effect_param_t *param); + + /* Prepare a new parameter value that will be set by next call to + * setParameterCommit(). This method can be used to set multiple parameters + * in a synchronous manner or to avoid multiple binder calls for each + * parameter. + * + * Parameters: + * param: pointer to effect_param_t structure containing the parameter + * and its value (See EffectApi.h). + * + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation. + * - INVALID_OPERATION: the application does not have control of the effect engine. + * - NO_MEMORY: no more space available in shared memory used for deferred parameter + * setting. + */ + virtual status_t setParameterDeferred(effect_param_t *param); + + /* Commit all parameter values previously prepared by setParameterDeferred(). + * + * Parameters: + * none + * + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation. + * - INVALID_OPERATION: No new parameter values ready for commit. + * - BAD_VALUE: invalid parameter identifier or value: there is no indication + * as to which of the parameters caused this error. + * - DEAD_OBJECT: the effect engine has been deleted. + */ + virtual status_t setParameterCommit(); + + /* Gets a parameter value. + * + * Parameters: + * param: pointer to effect_param_t structure containing the parameter + * and the returned value (See EffectApi.h). + * + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation. + * - INVALID_OPERATION: the AudioEffect was not successfully initialized. + * - BAD_VALUE: invalid parameter identifier. + * - DEAD_OBJECT: the effect engine has been deleted. + */ + virtual status_t getParameter(effect_param_t *param); + + /* Sends a command and receives a response to/from effect engine. + * See EffectApi.h for details on effect command() function, valid command codes + * and formats. + */ + virtual status_t command(uint32_t cmdCode, + uint32_t cmdSize, + void *cmdData, + uint32_t *replySize, + void *replyData); + + + /* + * Utility functions. + */ + + /* Converts the string passed as first argument to the effect_uuid_t + * pointed to by second argument + */ + static status_t stringToGuid(const char *str, effect_uuid_t *guid); + /* Converts the effect_uuid_t pointed to by first argument to the + * string passed as second argument + */ + static status_t guidToString(const effect_uuid_t *guid, char *str, size_t maxLen); + +protected: + volatile int32_t mEnabled; // enable state + int32_t mSessionId; // audio session ID + int32_t mPriority; // priority for effect control + status_t mStatus; // effect status + effect_callback_t mCbf; // callback function for status, control and + // parameter changes notifications + void* mUserData; // client context for callback function + effect_descriptor_t mDescriptor; // effect descriptor + int32_t mId; // system wide unique effect engine instance ID + +private: + + // Implements the IEffectClient interface + class EffectClient : public android::BnEffectClient, public android::IBinder::DeathRecipient + { + public: + + EffectClient(AudioEffect *effect) : mEffect(effect){} + + // IEffectClient + virtual void controlStatusChanged(bool controlGranted) { + mEffect->controlStatusChanged(controlGranted); + } + virtual void enableStatusChanged(bool enabled) { + mEffect->enableStatusChanged(enabled); + } + virtual void commandExecuted(uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t replySize, + void *pReplyData) { + mEffect->commandExecuted(cmdCode, cmdSize, pCmdData, replySize, pReplyData); + } + + // IBinder::DeathRecipient + virtual void binderDied(const wp<IBinder>& who) {mEffect->binderDied();} + + private: + AudioEffect *mEffect; + }; + + + friend class EffectClient; + + // IEffectClient + void controlStatusChanged(bool controlGranted); + void enableStatusChanged(bool enabled); + void commandExecuted(uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t replySize, + void *pReplyData); + void binderDied(); + + + sp<IEffect> mIEffect; // IEffect binder interface + sp<EffectClient> mIEffectClient; // IEffectClient implementation + sp<IMemory> mCblkMemory; // shared memory for deferred parameter setting + effect_param_cblk_t* mCblk; // control block for deferred parameter setting +}; + + +}; // namespace android + +#endif // ANDROID_AUDIOEFFECT_H diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h index 92bc126..38e3d44 100644 --- a/include/media/AudioRecord.h +++ b/include/media/AudioRecord.h @@ -100,6 +100,19 @@ public: typedef void (*callback_t)(int event, void* user, void *info); + /* Returns the minimum frame count required for the successful creation of + * an AudioRecord object. + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation + * - NO_INIT: audio server or audio hardware not initialized + * - BAD_VALUE: unsupported configuration + */ + + static status_t getMinFrameCount(int* frameCount, + uint32_t sampleRate, + int format, + int channelCount); + /* Constructs an uninitialized AudioRecord. No connection with * AudioFlinger takes place. */ @@ -142,7 +155,8 @@ public: uint32_t flags = 0, callback_t cbf = 0, void* user = 0, - int notificationFrames = 0); + int notificationFrames = 0, + int sessionId = 0); /* Terminates the AudioRecord and unregisters it from AudioFlinger. @@ -168,7 +182,8 @@ public: callback_t cbf = 0, void* user = 0, int notificationFrames = 0, - bool threadCanCallJava = false); + bool threadCanCallJava = false, + int sessionId = 0); /* Result of constructing the AudioRecord. This must be checked @@ -270,6 +285,16 @@ public: */ audio_io_handle_t getInput(); + /* returns the audio session ID associated to this AudioRecord. + * + * Parameters: + * none. + * + * Returned value: + * AudioRecord session ID. + */ + int getSessionId(); + /* obtains a buffer of "frameCount" frames. The buffer must be * filled entirely. If the track is stopped, obtainBuffer() returns * STOPPED instead of NO_ERROR as long as there are buffers availlable, @@ -356,6 +381,7 @@ private: uint32_t mFlags; uint32_t mChannels; audio_io_handle_t mInput; + int mSessionId; }; }; // namespace android diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index d0ccc50..9fd905f 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -168,6 +168,15 @@ public: TX_DISABLE = 0 }; + // special audio session values + enum audio_sessions { + SESSION_OUTPUT_STAGE = -1, // session for effects attached to a particular output stream + // (value must be less than 0) + SESSION_OUTPUT_MIX = 0, // session for effects applied to output mix. These effects can + // be moved by audio policy manager to another output stream + // (value must be 0) + }; + /* These are static methods to control the system-wide AudioFlinger * only privileged processes can have access to them */ @@ -234,6 +243,8 @@ public: static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT); static unsigned int getInputFramesLost(audio_io_handle_t ioHandle); + + static int newAudioSessionId(); // // AudioPolicyService interface // @@ -351,8 +362,12 @@ public: uint32_t format = FORMAT_DEFAULT, uint32_t channels = CHANNEL_OUT_STEREO, output_flags flags = OUTPUT_FLAG_INDIRECT); - static status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream); - static status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream); + static status_t startOutput(audio_io_handle_t output, + AudioSystem::stream_type stream, + int session = 0); + static status_t stopOutput(audio_io_handle_t output, + AudioSystem::stream_type stream, + int session = 0); static void releaseOutput(audio_io_handle_t output); static audio_io_handle_t getInput(int inputSource, uint32_t samplingRate = 0, @@ -368,6 +383,16 @@ public: static status_t setStreamVolumeIndex(stream_type stream, int index); static status_t getStreamVolumeIndex(stream_type stream, int *index); + static uint32_t getStrategyForStream(stream_type stream); + + static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc); + static status_t registerEffect(effect_descriptor_t *desc, + audio_io_handle_t output, + uint32_t strategy, + int session, + int id); + static status_t unregisterEffect(int id); + static const sp<IAudioPolicyService>& get_audio_policy_service(); // ---------------------------------------------------------------------------- diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index 14b30ae..4475d4a 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -102,6 +102,17 @@ public: typedef void (*callback_t)(int event, void* user, void *info); + /* Returns the minimum frame count required for the successful creation of + * an AudioTrack object. + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation + * - NO_INIT: audio server or audio hardware not initialized + */ + + static status_t getMinFrameCount(int* frameCount, + int streamType =-1, + uint32_t sampleRate = 0); + /* Constructs an uninitialized AudioTrack. No connection with * AudioFlinger takes place. */ @@ -138,7 +149,8 @@ public: uint32_t flags = 0, callback_t cbf = 0, void* user = 0, - int notificationFrames = 0); + int notificationFrames = 0, + int sessionId = 0); /* Creates an audio track and registers it with AudioFlinger. With this constructor, * The PCM data to be rendered by AudioTrack is passed in a shared memory buffer @@ -157,7 +169,8 @@ public: uint32_t flags = 0, callback_t cbf = 0, void* user = 0, - int notificationFrames = 0); + int notificationFrames = 0, + int sessionId = 0); /* Terminates the AudioTrack and unregisters it from AudioFlinger. * Also destroys all resources assotiated with the AudioTrack. @@ -182,7 +195,8 @@ public: void* user = 0, int notificationFrames = 0, const sp<IMemory>& sharedBuffer = 0, - bool threadCanCallJava = false); + bool threadCanCallJava = false, + int sessionId = 0); /* Result of constructing the AudioTrack. This must be checked @@ -239,10 +253,17 @@ public: /* set volume for this track, mostly used for games' sound effects + * left and right volumes. Levels must be <= 1.0. */ - void setVolume(float left, float right); + status_t setVolume(float left, float right); void getVolume(float* left, float* right); + /* set the send level for this track. An auxiliary effect should be attached + * to the track with attachEffect(). Level must be <= 1.0. + */ + status_t setAuxEffectSendLevel(float level); + void getAuxEffectSendLevel(float* level); + /* set sample rate for this track, mostly used for games' sound effects */ status_t setSampleRate(int sampleRate); @@ -340,6 +361,31 @@ public: */ audio_io_handle_t getOutput(); + /* returns the unique ID associated to this track. + * + * Parameters: + * none. + * + * Returned value: + * AudioTrack ID. + */ + int getSessionId(); + + + /* Attach track auxiliary output to specified effect. Used effectId = 0 + * to detach track from effect. + * + * Parameters: + * + * effectId: effectId obtained from AudioEffect::id(). + * + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation + * - INVALID_OPERATION: the effect is not an auxiliary effect. + * - BAD_VALUE: The specified effect ID is invalid + */ + status_t attachAuxEffect(int effectId); + /* obtains a buffer of "frameCount" frames. The buffer must be * filled entirely. If the track is stopped, obtainBuffer() returns * STOPPED instead of NO_ERROR as long as there are buffers availlable, @@ -398,13 +444,15 @@ private: int frameCount, uint32_t flags, const sp<IMemory>& sharedBuffer, - audio_io_handle_t output); + audio_io_handle_t output, + bool enforceFrameCount); sp<IAudioTrack> mAudioTrack; sp<IMemory> mCblkMemory; sp<AudioTrackThread> mAudioTrackThread; float mVolume[2]; + float mSendLevel; uint32_t mFrameCount; audio_track_cblk_t* mCblk; @@ -420,7 +468,8 @@ private: callback_t mCbf; void* mUserData; - uint32_t mNotificationFrames; + uint32_t mNotificationFramesReq; // requested number of frames between each notification callback + uint32_t mNotificationFramesAct; // actual number of frames between each notification callback sp<IMemory> mSharedBuffer; int mLoopCount; uint32_t mRemainingFrames; @@ -429,6 +478,8 @@ private: uint32_t mNewPosition; uint32_t mUpdatePeriod; uint32_t mFlags; + int mSessionId; + int mAuxEffectId; }; diff --git a/include/media/EffectApi.h b/include/media/EffectApi.h new file mode 100644 index 0000000..16fb43c --- /dev/null +++ b/include/media/EffectApi.h @@ -0,0 +1,796 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTAPI_H_ +#define ANDROID_EFFECTAPI_H_ + +#include <errno.h> +#include <stdint.h> +#include <sys/types.h> + +#if __cplusplus +extern "C" { +#endif + +///////////////////////////////////////////////// +// Effect control interface +///////////////////////////////////////////////// + +// 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: +// struct effect_interface_s { +// effect_process_t process; +// effect_command_t command; +// }; + + +// effect_interface_t: Effect control interface handle. +// The effect_interface_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_interface_t +typedef struct effect_interface_s **effect_interface_t; + + +// Effect API version 1.0 +#define EFFECT_API_VERSION 0x0100 // Format 0xMMmm MM: Major version, mm: minor version + +// Maximum length of character strings in structures defines by this API. +#define EFFECT_STRING_LEN_MAX 64 + +// +//--- 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; + +// 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 + uint16_t apiVersion; // Version of the effect API implemented: matches EFFECT_API_VERSION + 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..1 | 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 reserved +// +---------------------------+-----------+----------------------------------- +// | insertion preference | 2..4 | 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 | 5..6 | 0 none +// | | | 1 implements volume control +// | | | 2 requires volume indication +// | | | 3 reserved +// +---------------------------+-----------+----------------------------------- +// | Device indication | 7..8 | 0 none +// | | | 1 requires device updates +// | | | 2..3 reserved +// +---------------------------+-----------+----------------------------------- +// | Sample input mode | 9..10 | 0 direct: process() function or EFFECT_CMD_CONFIGURE +// | | | command must specify a buffer descriptor +// | | | 1 provider: process() function uses the +// | | | bufferProvider indicated by the +// | | | EFFECT_CMD_CONFIGURE command to request input. +// | | | buffers. +// | | | 2 both: both input modes are supported +// | | | 3 reserved +// +---------------------------+-----------+----------------------------------- +// | Sample output mode | 11..12 | 0 direct: process() function or EFFECT_CMD_CONFIGURE +// | | | command must specify a buffer descriptor +// | | | 1 provider: process() function uses the +// | | | bufferProvider indicated by the +// | | | EFFECT_CMD_CONFIGURE command to request output +// | | | buffers. +// | | | 2 both: both output modes are supported +// | | | 3 reserved +// +---------------------------+-----------+----------------------------------- +// | Hardware acceleration | 13..15 | 0 No hardware acceleration +// | | | 1 non tunneled hw acceleration: the process() function +// | | | reads the samples, send them to HW accelerated +// | | | effect processor, reads back the processed samples +// | | | and returns them to the output buffer. +// | | | 2 tunneled hw acceleration: the process() function is +// | | | transparent. The effect interface is only used to +// | | | control the effect engine. This mode is relevant for +// | | | global effects actually applied by the audio +// | | | hardware on the output stream. +// +---------------------------+-----------+----------------------------------- +// | Audio Mode indication | 16..17 | 0 none +// | | | 1 requires audio mode updates +// | | | 2..3 reserved +// +---------------------------+-----------+----------------------------------- + +// Insert mode +#define EFFECT_FLAG_TYPE_MASK 0x00000003 +#define EFFECT_FLAG_TYPE_INSERT 0x00000000 +#define EFFECT_FLAG_TYPE_AUXILIARY 0x00000001 +#define EFFECT_FLAG_TYPE_REPLACE 0x00000002 + +// Insert preference +#define EFFECT_FLAG_INSERT_MASK 0x0000001C +#define EFFECT_FLAG_INSERT_ANY 0x00000000 +#define EFFECT_FLAG_INSERT_FIRST 0x00000004 +#define EFFECT_FLAG_INSERT_LAST 0x00000008 +#define EFFECT_FLAG_INSERT_EXCLUSIVE 0x0000000C + + +// Volume control +#define EFFECT_FLAG_VOLUME_MASK 0x00000060 +#define EFFECT_FLAG_VOLUME_CTRL 0x00000020 +#define EFFECT_FLAG_VOLUME_IND 0x00000040 +#define EFFECT_FLAG_VOLUME_NONE 0x00000000 + +// Device indication +#define EFFECT_FLAG_DEVICE_MASK 0x00000180 +#define EFFECT_FLAG_DEVICE_IND 0x00000080 +#define EFFECT_FLAG_DEVICE_NONE 0x00000000 + +// Sample input modes +#define EFFECT_FLAG_INPUT_MASK 0x00000600 +#define EFFECT_FLAG_INPUT_DIRECT 0x00000000 +#define EFFECT_FLAG_INPUT_PROVIDER 0x00000200 +#define EFFECT_FLAG_INPUT_BOTH 0x00000400 + +// Sample output modes +#define EFFECT_FLAG_OUTPUT_MASK 0x00001800 +#define EFFECT_FLAG_OUTPUT_DIRECT 0x00000000 +#define EFFECT_FLAG_OUTPUT_PROVIDER 0x00000800 +#define EFFECT_FLAG_OUTPUT_BOTH 0x00001000 + +// Hardware acceleration mode +#define EFFECT_FLAG_HW_ACC_MASK 0x00006000 +#define EFFECT_FLAG_HW_ACC_SIMPLE 0x00002000 +#define EFFECT_FLAG_HW_ACC_TUNNEL 0x00004000 + +// Audio mode indication +#define EFFECT_FLAG_AUDIO_MODE_MASK 0x00018000 +#define EFFECT_FLAG_AUDIO_MODE_IND 0x00008000 +#define EFFECT_FLAG_AUDIO_MODE_NONE 0x00000000 + +// Forward definition of type audio_buffer_t +typedef struct audio_buffer_s audio_buffer_t; + +//////////////////////////////////////////////////////////////////////////////// +// +// 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: +// effect_interface_t: 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. +// +// inBuffer: 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 +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_process_t)(effect_interface_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: +// effect_interface_t: 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 +// +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_command_t)(effect_interface_t self, + uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t *replySize, + void *pReplyData); + + +// Effect control interface definition +struct effect_interface_s { + effect_process_t process; + effect_command_t command; +}; + + +// +//--- 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_device_e) + EFFECT_CMD_SET_VOLUME, // set volume + EFFECT_CMD_SET_AUDIO_MODE, // set the audio mode (normal, ring, ...) + EFFECT_CMD_FIRST_PROPRIETARY = 0x10000 // first proprietary command code +}; + +//================================================================================================== +// command: EFFECT_CMD_INIT +//-------------------------------------------------------------------------------------------------- +// description: +// Initialize effect engine: All configurations return to default +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_CONFIGURE +//-------------------------------------------------------------------------------------------------- +// description: +// Apply new audio parameters configurations for input and output buffers +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_config_t) +// data: effect_config_t +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_RESET +//-------------------------------------------------------------------------------------------------- +// description: +// Reset the effect engine. Keep configuration but resets state and buffer content +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_ENABLE +//-------------------------------------------------------------------------------------------------- +// description: +// Enable the process. Called by the framework before the first call to process() +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_DISABLE +//-------------------------------------------------------------------------------------------------- +// description: +// Disable the process. Called by the framework after the last call to process() +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM +//-------------------------------------------------------------------------------------------------- +// description: +// Set a parameter and apply it immediately +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM_DEFERRED +//-------------------------------------------------------------------------------------------------- +// description: +// Set a parameter but apply it only when receiving EFFECT_CMD_SET_PARAM_COMMIT command +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_SET_PARAM_COMMIT +//-------------------------------------------------------------------------------------------------- +// description: +// Apply all previously received EFFECT_CMD_SET_PARAM_DEFERRED commands +//-------------------------------------------------------------------------------------------------- +// command format: +// size: 0 +// data: N/A +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(int) +// data: status +//================================================================================================== +// command: EFFECT_CMD_GET_PARAM +//-------------------------------------------------------------------------------------------------- +// description: +// Get a parameter value +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(effect_param_t) + size of param +// data: effect_param_t + param +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: sizeof(effect_param_t) + size of param and value +// data: effect_param_t + param + value. See effect_param_t definition below for value offset +//================================================================================================== +// command: EFFECT_CMD_SET_DEVICE +//-------------------------------------------------------------------------------------------------- +// description: +// Set the rendering device the audio output path is connected to. See audio_device_e for device +// values. +// The effect implementation must set EFFECT_FLAG_DEVICE_IND flag in its descriptor to receive this +// command when the device changes +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(uint32_t) +// data: audio_device_e +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_SET_VOLUME +//-------------------------------------------------------------------------------------------------- +// description: +// Set and get volume. Used by audio framework to delegate volume control to effect engine. +// The effect implementation must set EFFECT_FLAG_VOLUME_IND or EFFECT_FLAG_VOLUME_CTRL flag in +// its descriptor to receive this command before every call to process() function +// If EFFECT_FLAG_VOLUME_CTRL flag is set in the effect descriptor, the effect engine must return +// the volume that should be applied before the effect is processed. The overall volume (the volume +// actually applied by the effect engine multiplied by the returned value) should match the value +// indicated in the command. +//-------------------------------------------------------------------------------------------------- +// command format: +// size: n * sizeof(uint32_t) +// data: volume for each channel defined in effect_config_t for output buffer expressed in +// 8.24 fixed point format +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: n * sizeof(uint32_t) / 0 +// data: - if EFFECT_FLAG_VOLUME_CTRL is set in effect descriptor: +// volume for each channel defined in effect_config_t for output buffer expressed in +// 8.24 fixed point format +// - if EFFECT_FLAG_VOLUME_CTRL is not set in effect descriptor: +// N/A +// It is legal to receive a null pointer as pReplyData in which case the effect framework has +// delegated volume control to another effect +//================================================================================================== +// command: EFFECT_CMD_SET_AUDIO_MODE +//-------------------------------------------------------------------------------------------------- +// description: +// Set the audio mode. The effect implementation must set EFFECT_FLAG_AUDIO_MODE_IND flag in its +// descriptor to receive this command when the audio mode changes. +//-------------------------------------------------------------------------------------------------- +// command format: +// size: sizeof(uint32_t) +// data: audio_mode_e +//-------------------------------------------------------------------------------------------------- +// reply format: +// size: 0 +// data: N/A +//================================================================================================== +// command: EFFECT_CMD_FIRST_PROPRIETARY +//-------------------------------------------------------------------------------------------------- +// description: +// All proprietary effect commands must use command codes above this value. The size and format of +// command and response fields is free in this case +//================================================================================================== + + +// Audio buffer descriptor used by process(), bufferProvider() functions and buffer_config_t +// structure. Multi-channel audio is always interleaved. The channel order is from LSB to MSB with +// regard to the channel mask definition in audio_channels_e e.g : +// Stereo: left, right +// 5 point 1: front left, front right, front center, low frequency, back left, back right +// The buffer size is expressed in frame count, a frame being composed of samples for all +// channels at a given time. 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 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_e) + buffer_provider_t bufferProvider; // buffer provider + uint8_t format; // Audio format (see audio_format_e) + uint8_t accessMode; // read/write or accumulate in buffer (effect_buffer_access_e) + uint16_t mask; // indicates which of the above fields is valid +} buffer_config_t; + +// Sample format +enum audio_format_e { + SAMPLE_FORMAT_PCM_S15, // PCM signed 16 bits + SAMPLE_FORMAT_PCM_U8, // PCM unsigned 8 bits + SAMPLE_FORMAT_PCM_S7_24, // PCM signed 7.24 fixed point representation + SAMPLE_FORMAT_OTHER // other format (e.g. compressed) +}; + +// Channel mask +enum audio_channels_e { + CHANNEL_FRONT_LEFT = 0x1, // front left channel + CHANNEL_FRONT_RIGHT = 0x2, // front right channel + CHANNEL_FRONT_CENTER = 0x4, // front center channel + CHANNEL_LOW_FREQUENCY = 0x8, // low frequency channel + CHANNEL_BACK_LEFT = 0x10, // back left channel + CHANNEL_BACK_RIGHT = 0x20, // back right channel + CHANNEL_FRONT_LEFT_OF_CENTER = 0x40, // front left of center channel + CHANNEL_FRONT_RIGHT_OF_CENTER = 0x80, // front right of center channel + CHANNEL_BACK_CENTER = 0x100, // back center channel + CHANNEL_MONO = CHANNEL_FRONT_LEFT, + CHANNEL_STEREO = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT), + CHANNEL_QUAD = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), + CHANNEL_SURROUND = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER), + CHANNEL_5POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT), + CHANNEL_7POINT1 = (CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | + CHANNEL_FRONT_LEFT_OF_CENTER | CHANNEL_FRONT_RIGHT_OF_CENTER), +}; + +// Render device +enum audio_device_e { + DEVICE_EARPIECE = 0x1, // earpiece + DEVICE_SPEAKER = 0x2, // speaker + DEVICE_WIRED_HEADSET = 0x4, // wired headset, with microphone + DEVICE_WIRED_HEADPHONE = 0x8, // wired headphone, without microphone + DEVICE_BLUETOOTH_SCO = 0x10, // generic bluetooth SCO + DEVICE_BLUETOOTH_SCO_HEADSET = 0x20, // bluetooth SCO headset + DEVICE_BLUETOOTH_SCO_CARKIT = 0x40, // bluetooth SCO car kit + DEVICE_BLUETOOTH_A2DP = 0x80, // generic bluetooth A2DP + DEVICE_BLUETOOTH_A2DP_HEADPHONES = 0x100, // bluetooth A2DP headphones + DEVICE_BLUETOOTH_A2DP_SPEAKER = 0x200, // bluetooth A2DP speakers + DEVICE_AUX_DIGITAL = 0x400, // digital output + DEVICE_EXTERNAL_SPEAKER = 0x800 // external speaker (stereo and High quality) +}; + +// Audio mode +enum audio_mode_e { + AUDIO_MODE_NORMAL, // phone idle + AUDIO_MODE_RINGTONE, // phone ringing + AUDIO_MODE_IN_CALL // phone call connected +}; + +// Values for "accessMode" field of buffer_config_t: +// overwrite, read only, accumulate (read/modify/write) +enum effect_buffer_access_e { + EFFECT_BUFFER_ACCESS_WRITE, + 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 +///////////////////////////////////////////////// + +// An effect library is required to implement and expose the following functions +// to enable effect enumeration and instantiation. The name of these functions must be as +// specified here as the effect framework will get the function address with dlsym(): +// +// - effect_QueryNumberEffects_t EffectQueryNumberEffects; +// - effect_QueryEffect_t EffectQueryEffect; +// - effect_CreateEffect_t EffectCreate; +// - effect_ReleaseEffect_t EffectRelease; + + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectQueryNumberEffects +// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_QueryNumberEffects_t)(uint32_t *pNumEffects); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectQueryEffect +// +// Description: Returns the descriptor of the effect engine which index is +// given as first argument. +// See effect_descriptor_t for details on effect descriptors. +// This function together with 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. +// +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_QueryEffect_t)(uint32_t index, + effect_descriptor_t *pDescriptor); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectCreate +// +// Description: Creates an effect engine of the specified type 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: +// pInterface: address where to return the effect interface. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV library failed to initialize +// -EINVAL invalid pEffectUuid or pInterface +// -ENOENT no effect with this uuid found +// *pInterface: updated with the effect interface handle. +// +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_CreateEffect_t)(effect_uuid_t *uuid, + int32_t sessionId, + int32_t ioId, + effect_interface_t *pInterface); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectRelease +// +// Description: Releases the effect engine whose handle is given as argument. +// All resources allocated to this particular instance of the effect are +// released. +// +// Input: +// interface: handle on the effect interface to be released. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV library failed to initialize +// -EINVAL invalid interface handle +// +//////////////////////////////////////////////////////////////////////////////// +typedef int32_t (*effect_ReleaseEffect_t)(effect_interface_t interface); + + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTAPI_H_*/ diff --git a/include/media/EffectBassBoostApi.h b/include/media/EffectBassBoostApi.h new file mode 100644 index 0000000..75f8d78 --- /dev/null +++ b/include/media/EffectBassBoostApi.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTBASSBOOSTAPI_H_ +#define ANDROID_EFFECTBASSBOOSTAPI_H_ + +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_BASSBOOST_ = { 0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_BASSBOOST = &SL_IID_BASSBOOST_; +#endif //OPENSL_ES_H_ + +/* enumerated parameter settings for BassBoost effect */ +typedef enum +{ + BASSBOOST_PARAM_STRENGTH_SUPPORTED, + BASSBOOST_PARAM_STRENGTH +} t_bassboost_params; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTBASSBOOSTAPI_H_*/ diff --git a/include/media/EffectEnvironmentalReverbApi.h b/include/media/EffectEnvironmentalReverbApi.h new file mode 100644 index 0000000..2233e3f --- /dev/null +++ b/include/media/EffectEnvironmentalReverbApi.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTENVIRONMENTALREVERBAPI_H_ +#define ANDROID_EFFECTENVIRONMENTALREVERBAPI_H_ + +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_ENVIRONMENTALREVERB_ = { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x6, 0x83, 0x9e } }; +const effect_uuid_t * const SL_IID_ENVIRONMENTALREVERB = &SL_IID_ENVIRONMENTALREVERB_; +#endif //OPENSL_ES_H_ + +/* enumerated parameter settings for environmental reverb effect */ +typedef enum +{ + // Parameters below are as defined in OpenSL ES specification for environmental reverb interface + REVERB_PARAM_ROOM_LEVEL, // in millibels, range -6000 to 0 + REVERB_PARAM_ROOM_HF_LEVEL, // in millibels, range -4000 to 0 + REVERB_PARAM_DECAY_TIME, // in milliseconds, range 100 to 20000 + REVERB_PARAM_DECAY_HF_RATIO, // in permilles, range 100 to 1000 + REVERB_PARAM_REFLECTIONS_LEVEL, // in millibels, range -6000 to 0 + REVERB_PARAM_REFLECTIONS_DELAY, // in milliseconds, range 0 to 65 + REVERB_PARAM_REVERB_LEVEL, // in millibels, range -6000 to 0 + REVERB_PARAM_REVERB_DELAY, // in milliseconds, range 0 to 65 + REVERB_PARAM_DIFFUSION, // in permilles, range 0 to 1000 + REVERB_PARAM_DENSITY, // in permilles, range 0 to 1000 + REVERB_PARAM_PROPERTIES, + REVERB_PARAM_BYPASS +} t_env_reverb_params; + +//t_reverb_settings is equal to SLEnvironmentalReverbSettings defined in OpenSL ES specification. +typedef struct s_reverb_settings { + int16_t roomLevel; + int16_t roomHFLevel; + int32_t decayTime; + int16_t decayHFRatio; + int16_t reflectionsLevel; + int32_t reflectionsDelay; + int16_t reverbLevel; + int32_t reverbDelay; + int16_t diffusion; + int16_t density; +} __attribute__((packed)) t_reverb_settings; + + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTENVIRONMENTALREVERBAPI_H_*/ diff --git a/include/media/EffectEqualizerApi.h b/include/media/EffectEqualizerApi.h new file mode 100644 index 0000000..0492ea0 --- /dev/null +++ b/include/media/EffectEqualizerApi.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTEQUALIZERAPI_H_ +#define ANDROID_EFFECTEQUALIZERAPI_H_ + +#include <media/EffectApi.h> + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_EQUALIZER_ = { 0x0bed4300, 0xddd6, 0x11db, 0x8f34, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_EQUALIZER = &SL_IID_EQUALIZER_; +#endif //OPENSL_ES_H_ + +#if __cplusplus +extern "C" { +#endif + +/* enumerated parameters for Equalizer effect */ +typedef enum +{ + EQ_PARAM_NUM_BANDS, // Gets the number of frequency bands that the equalizer supports. + EQ_PARAM_LEVEL_RANGE, // Returns the minimum and maximum band levels supported. + EQ_PARAM_BAND_LEVEL, // Gets/Sets the gain set for the given equalizer band. + EQ_PARAM_CENTER_FREQ, // Gets the center frequency of the given band. + EQ_PARAM_BAND_FREQ_RANGE, // Gets the frequency range of the given frequency band. + EQ_PARAM_GET_BAND, // Gets the band that has the most effect on the given frequency. + EQ_PARAM_CUR_PRESET, // Gets/Sets the current preset. + EQ_PARAM_GET_NUM_OF_PRESETS, // Gets the total number of presets the equalizer supports. + EQ_PARAM_GET_PRESET_NAME, // Gets the preset name based on the index. + EQ_PARAM_PROPERTIES // Gets/Sets all parameters at a time. +} t_equalizer_params; + +//t_equalizer_settings groups all current equalizer setting for backup and restore. +typedef struct s_equalizer_settings { + uint16_t curPreset; + uint16_t numBands; + uint16_t bandLevels[]; +} t_equalizer_settings; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTEQUALIZERAPI_H_*/ diff --git a/include/media/EffectPresetReverbApi.h b/include/media/EffectPresetReverbApi.h new file mode 100644 index 0000000..53205bb --- /dev/null +++ b/include/media/EffectPresetReverbApi.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTPRESETREVERBAPI_H_ +#define ANDROID_EFFECTPRESETREVERBAPI_H_ + +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_PRESETREVERB_ = { 0x47382d60, 0xddd8, 0x11db, 0xbf3a, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_PRESETREVERB = &SL_IID_PRESETREVERB_; +#endif //OPENSL_ES_H_ + +/* enumerated parameter settings for preset reverb effect */ +typedef enum +{ + REVERB_PARAM_PRESET +} t_preset_reverb_params; + + +typedef enum +{ + REVERB_PRESET_NONE, + REVERB_PRESET_SMALLROOM, + REVERB_PRESET_MEDIUMROOM, + REVERB_PRESET_LARGEROOM, + REVERB_PRESET_MEDIUMHALL, + REVERB_PRESET_LARGEHALL, + REVERB_PRESET_PLATE +} t_reverb_presets; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTPRESETREVERBAPI_H_*/ diff --git a/include/media/EffectVirtualizerApi.h b/include/media/EffectVirtualizerApi.h new file mode 100644 index 0000000..c3d5131 --- /dev/null +++ b/include/media/EffectVirtualizerApi.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTVIRTUALIZERAPI_H_ +#define ANDROID_EFFECTVIRTUALIZERAPI_H_ + +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_VIRTUALIZER_ = { 0x37cc2c00, 0xdddd, 0x11db, 0x8577, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_VIRTUALIZER = &SL_IID_VIRTUALIZER_; +#endif //OPENSL_ES_H_ + +/* enumerated parameter settings for virtualizer effect */ +typedef enum +{ + VIRTUALIZER_PARAM_STRENGTH_SUPPORTED, + VIRTUALIZER_PARAM_STRENGTH +} t_virtualizer_params; + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTVIRTUALIZERAPI_H_*/ diff --git a/include/media/EffectVisualizerApi.h b/include/media/EffectVisualizerApi.h new file mode 100644 index 0000000..bef1a4f --- /dev/null +++ b/include/media/EffectVisualizerApi.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTVISUALIZERAPI_H_ +#define ANDROID_EFFECTVISUALIZERAPI_H_ + +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +#ifndef OPENSL_ES_H_ +static const effect_uuid_t SL_IID_VISUALIZATION_ = + { 0xe46b26a0, 0xdddd, 0x11db, 0x8afd, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }; +const effect_uuid_t * const SL_IID_VISUALIZATION = &SL_IID_VISUALIZATION_; +#endif //OPENSL_ES_H_ + +#define VISUALIZER_CAPTURE_SIZE_MAX 1024 // maximum capture size in samples +#define VISUALIZER_CAPTURE_SIZE_MIN 128 // minimum capture size in samples + +/* enumerated parameters for Visualizer effect */ +typedef enum +{ + VISU_PARAM_CAPTURE_SIZE, // Sets the number PCM samples in the capture. +} t_visualizer_params; + +/* commands */ +typedef enum +{ + VISU_CMD_CAPTURE = EFFECT_CMD_FIRST_PROPRIETARY, // Gets the latest PCM capture. +}t_visualizer_cmds; + +// VISU_CMD_CAPTURE retrieves the latest PCM snapshot captured by the visualizer engine. +// It returns the number of samples specified by VISU_PARAM_CAPTURE_SIZE +// in 8 bit unsigned format (0 = 0x80) + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTVISUALIZERAPI_H_*/ diff --git a/include/media/EffectsFactoryApi.h b/include/media/EffectsFactoryApi.h new file mode 100644 index 0000000..0ed1a14 --- /dev/null +++ b/include/media/EffectsFactoryApi.h @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_EFFECTSFACTORYAPI_H_ +#define ANDROID_EFFECTSFACTORYAPI_H_ + +#include <errno.h> +#include <stdint.h> +#include <sys/types.h> +#include <media/EffectApi.h> + +#if __cplusplus +extern "C" { +#endif + +///////////////////////////////////////////////// +// Effect factory interface +///////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectQueryNumberEffects +// +// Description: Returns the number of different effects in all loaded libraries. +// Each effect must have a different effect uuid (see +// effect_descriptor_t). This function together with EffectQueryEffect() +// is used to enumerate all effects present in all loaded libraries. +// Each time EffectQueryNumberEffects() is called, the factory must +// reset the index of the effect descriptor returned by next call to +// EffectQueryEffect() to restart enumeration from the beginning. +// +// Input/Output: +// pNumEffects: address where the number of effects should be returned. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV factory failed to initialize +// -EINVAL invalid pNumEffects +// *pNumEffects: updated with number of effects in factory +// +//////////////////////////////////////////////////////////////////////////////// +int EffectQueryNumberEffects(uint32_t *pNumEffects); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectQueryEffect +// +// Description: Returns a descriptor of the next available effect. +// See effect_descriptor_t for a details on effect descriptor. +// This function together with EffectQueryNumberEffects() is used to enumerate all +// effects present in all loaded libraries. The enumeration sequence is: +// EffectQueryNumberEffects(&num_effects); +// for (i = 0; i < num_effects; i++) +// EffectQueryEffect(i,...); +// +// Input/Output: +// pDescriptor: address where to return the effect descriptor. +// +// Output: +// returned value: 0 successful operation. +// -ENOENT no more effect available +// -ENODEV factory failed to initialize +// -EINVAL invalid pDescriptor +// -ENOSYS effect list has changed since last execution of EffectQueryNumberEffects() +// *pDescriptor: updated with the effect descriptor. +// +//////////////////////////////////////////////////////////////////////////////// +int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectCreate +// +// Description: Creates an effect engine of the specified type 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 handler on the effect control interface. +// +// Input: +// pEffectUuid: pointer to the effect uuid. +// sessionId: audio session to which this effect instance will be attached. All effects created +// with the same session ID are connected in series and process the same signal stream. +// Knowing that two effects are part of the same effect chain can help the library implement +// some kind of optimizations. +// ioId: identifies the output or input stream this effect is directed to at audio HAL. For future +// use especially with tunneled HW accelerated effects +// +// Input/Output: +// pInterface: address where to return the effect interface. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV factory failed to initialize +// -EINVAL invalid pEffectUuid or pInterface +// -ENOENT no effect with this uuid found +// *pInterface: updated with the effect interface. +// +//////////////////////////////////////////////////////////////////////////////// +int EffectCreate(effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t ioId, effect_interface_t *pInterface); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectRelease +// +// Description: Releases the effect engine whose handler is given as argument. +// All resources allocated to this particular instance of the effect are +// released. +// +// Input: +// interface: handler on the effect interface to be released. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV factory failed to initialize +// -EINVAL invalid interface handler +// +//////////////////////////////////////////////////////////////////////////////// +int EffectRelease(effect_interface_t interface); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectLoadLibrary +// +// Description: Loads the effect library which path is given as first argument. +// This must be the full path of a dynamic library (.so) implementing one or +// more effect engines and exposing the effect library interface described in +// EffectApi.h. The function returns a handle on the library for used by +// further call to EffectUnloadLibrary() to unload the library. +// +// Input: +// libPath: full path of the dynamic library file in the file system. +// +// handle: address where to return the library handle +// +// Output: +// returned value: 0 successful operation. +// -ENODEV effect factory not initialized or +// library could not be loaded or +// library does not implement required functions +// -EINVAL invalid libPath string or handle +// +//////////////////////////////////////////////////////////////////////////////// +int EffectLoadLibrary(const char *libPath, int *handle); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectUnloadLibrary +// +// Description: Unloads the effect library which handle is given as argument. +// +// Input: +// handle: library handle +// +// Output: +// returned value: 0 successful operation. +// -ENODEV effect factory not initialized +// -ENOENT invalid handle +// +//////////////////////////////////////////////////////////////////////////////// +int EffectUnloadLibrary(int handle); + + + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectGetDescriptor +// +// Description: Returns the descriptor of the effect which uuid is pointed +// to by first argument. +// +// Input: +// pEffectUuid: pointer to the effect uuid. +// +// Input/Output: +// pDescriptor: address where to return the effect descriptor. +// +// Output: +// returned value: 0 successful operation. +// -ENODEV factory failed to initialize +// -EINVAL invalid pEffectUuid or pDescriptor +// -ENOENT no effect with this uuid found +// *pDescriptor: updated with the effect descriptor. +// +//////////////////////////////////////////////////////////////////////////////// +int EffectGetDescriptor(effect_uuid_t *pEffectUuid, effect_descriptor_t *pDescriptor); + +//////////////////////////////////////////////////////////////////////////////// +// +// Function: EffectIsNullUuid +// +// Description: Helper function to compare effect uuid to EFFECT_UUID_NULL +// +// Input: +// pEffectUuid: pointer to effect uuid to compare to EFFECT_UUID_NULL. +// +// Output: +// returned value: 0 if uuid is different from EFFECT_UUID_NULL. +// 1 if uuid is equal to EFFECT_UUID_NULL. +// +//////////////////////////////////////////////////////////////////////////////// +int EffectIsNullUuid(effect_uuid_t *pEffectUuid); + +#if __cplusplus +} // extern "C" +#endif + + +#endif /*ANDROID_EFFECTSFACTORYAPI_H_*/ diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h index c147632..70e505e 100644 --- a/include/media/IAudioFlinger.h +++ b/include/media/IAudioFlinger.h @@ -27,6 +27,9 @@ #include <media/IAudioTrack.h> #include <media/IAudioRecord.h> #include <media/IAudioFlingerClient.h> +#include <media/EffectApi.h> +#include <media/IEffect.h> +#include <media/IEffectClient.h> #include <utils/String8.h> namespace android { @@ -51,6 +54,7 @@ public: uint32_t flags, const sp<IMemory>& sharedBuffer, int output, + int *sessionId, status_t *status) = 0; virtual sp<IAudioRecord> openRecord( @@ -61,6 +65,7 @@ public: int channelCount, int frameCount, uint32_t flags, + int *sessionId, status_t *status) = 0; /* query the audio hardware state. This state never changes, @@ -134,6 +139,30 @@ public: virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output) = 0; virtual unsigned int getInputFramesLost(int ioHandle) = 0; + + virtual int newAudioSessionId() = 0; + + virtual status_t loadEffectLibrary(const char *libPath, int *handle) = 0; + + virtual status_t unloadEffectLibrary(int handle) = 0; + + virtual status_t queryNumberEffects(uint32_t *numEffects) = 0; + + virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) = 0; + + virtual status_t getEffectDescriptor(effect_uuid_t *pEffectUUID, effect_descriptor_t *pDescriptor) = 0; + + virtual sp<IEffect> createEffect(pid_t pid, + effect_descriptor_t *pDesc, + const sp<IEffectClient>& client, + int32_t priority, + int output, + int sessionId, + status_t *status, + int *id, + int *enabled) = 0; + + virtual status_t moveEffects(int session, int srcOutput, int dstOutput) = 0; }; diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h index 4804bbd..49eee59 100644 --- a/include/media/IAudioPolicyService.h +++ b/include/media/IAudioPolicyService.h @@ -53,8 +53,12 @@ public: uint32_t format = AudioSystem::FORMAT_DEFAULT, uint32_t channels = 0, AudioSystem::output_flags flags = AudioSystem::OUTPUT_FLAG_INDIRECT) = 0; - virtual status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream) = 0; - virtual status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream) = 0; + virtual status_t startOutput(audio_io_handle_t output, + AudioSystem::stream_type stream, + int session = 0) = 0; + virtual status_t stopOutput(audio_io_handle_t output, + AudioSystem::stream_type stream, + int session = 0) = 0; virtual void releaseOutput(audio_io_handle_t output) = 0; virtual audio_io_handle_t getInput(int inputSource, uint32_t samplingRate = 0, @@ -69,6 +73,14 @@ public: int indexMax) = 0; virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, int index) = 0; virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, int *index) = 0; + virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream) = 0; + virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0; + virtual status_t registerEffect(effect_descriptor_t *desc, + audio_io_handle_t output, + uint32_t strategy, + int session, + int id) = 0; + virtual status_t unregisterEffect(int id) = 0; }; diff --git a/include/media/IAudioTrack.h b/include/media/IAudioTrack.h index de6426a..47d530b 100644 --- a/include/media/IAudioTrack.h +++ b/include/media/IAudioTrack.h @@ -62,6 +62,11 @@ public: */ virtual void pause() = 0; + /* Attach track auxiliary output to specified effect. Use effectId = 0 + * to detach track from effect. + */ + virtual status_t attachAuxEffect(int effectId) = 0; + /* get this tracks control block */ virtual sp<IMemory> getCblk() const = 0; }; diff --git a/include/media/IEffect.h b/include/media/IEffect.h new file mode 100644 index 0000000..ff04869 --- /dev/null +++ b/include/media/IEffect.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IEFFECT_H +#define ANDROID_IEFFECT_H + +#include <utils/RefBase.h> +#include <binder/IInterface.h> +#include <binder/Parcel.h> +#include <binder/IMemory.h> + +namespace android { + +class IEffect: public IInterface +{ +public: + DECLARE_META_INTERFACE(Effect); + + virtual status_t enable() = 0; + + virtual status_t disable() = 0; + + virtual status_t command(uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t *pReplySize, + void *pReplyData) = 0; + + virtual void disconnect() = 0; + + virtual sp<IMemory> getCblk() const = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnEffect: public BnInterface<IEffect> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif // ANDROID_IEFFECT_H diff --git a/include/media/IEffectClient.h b/include/media/IEffectClient.h new file mode 100644 index 0000000..2f78c98 --- /dev/null +++ b/include/media/IEffectClient.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IEFFECTCLIENT_H +#define ANDROID_IEFFECTCLIENT_H + +#include <utils/RefBase.h> +#include <binder/IInterface.h> +#include <binder/Parcel.h> +#include <binder/IMemory.h> + +namespace android { + +class IEffectClient: public IInterface +{ +public: + DECLARE_META_INTERFACE(EffectClient); + + virtual void controlStatusChanged(bool controlGranted) = 0; + virtual void enableStatusChanged(bool enabled) = 0; + virtual void commandExecuted(uint32_t cmdCode, + uint32_t cmdSize, + void *pCmdData, + uint32_t replySize, + void *pReplyData) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnEffectClient: public BnInterface<IEffectClient> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif // ANDROID_IEFFECTCLIENT_H diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h index 2619691..af9a7ed 100644 --- a/include/media/IMediaPlayer.h +++ b/include/media/IMediaPlayer.h @@ -48,6 +48,8 @@ public: virtual status_t setVolume(float leftVolume, float rightVolume) = 0; virtual status_t suspend() = 0; virtual status_t resume() = 0; + virtual status_t setAuxEffectSendLevel(float level) = 0; + virtual status_t attachAuxEffect(int effectId) = 0; // Invoke a generic method on the player by using opaque parcels // for the request and reply. diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h index 31c0991..9416ca1 100644 --- a/include/media/IMediaPlayerService.h +++ b/include/media/IMediaPlayerService.h @@ -40,15 +40,14 @@ public: virtual sp<IMediaRecorder> createMediaRecorder(pid_t pid) = 0; virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid) = 0; - virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url, const KeyedVector<String8, String8> *headers = NULL) = 0; - virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length) = 0; + virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, + const char* url, const KeyedVector<String8, String8> *headers = NULL, + int audioSessionId = 0) = 0; + virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, + int fd, int64_t offset, int64_t length, int audioSessionId) = 0; virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0; virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0; virtual sp<IOMX> getOMX() = 0; - - // Take a peek at currently playing audio, for visualization purposes. - // This returns a buffer of 16 bit mono PCM data, or NULL if no visualization buffer is currently available. - virtual sp<IMemory> snoop() = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h index 73bf2ee..54adca8 100644 --- a/include/media/IMediaRecorder.h +++ b/include/media/IMediaRecorder.h @@ -24,7 +24,7 @@ namespace android { class ISurface; class ICamera; -class IMediaPlayerClient; +class IMediaRecorderClient; class IMediaRecorder: public IInterface { @@ -43,7 +43,7 @@ public: virtual status_t setVideoSize(int width, int height) = 0; virtual status_t setVideoFrameRate(int frames_per_second) = 0; virtual status_t setParameters(const String8& params) = 0; - virtual status_t setListener(const sp<IMediaPlayerClient>& listener) = 0; + virtual status_t setListener(const sp<IMediaRecorderClient>& listener) = 0; virtual status_t prepare() = 0; virtual status_t getMaxAmplitude(int* max) = 0; virtual status_t start() = 0; diff --git a/include/media/IMediaRecorderClient.h b/include/media/IMediaRecorderClient.h new file mode 100644 index 0000000..0058ef2 --- /dev/null +++ b/include/media/IMediaRecorderClient.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_IMEDIARECORDERCLIENT_H +#define ANDROID_IMEDIARECORDERCLIENT_H + +#include <utils/RefBase.h> +#include <binder/IInterface.h> +#include <binder/Parcel.h> + +namespace android { + +class IMediaRecorderClient: public IInterface +{ +public: + DECLARE_META_INTERFACE(MediaRecorderClient); + + virtual void notify(int msg, int ext1, int ext2) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnMediaRecorderClient: public BnInterface<IMediaRecorderClient> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif // ANDROID_IMEDIARECORDERCLIENT_H + diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h index 9e606d9..3662983 100644 --- a/include/media/MediaPlayerInterface.h +++ b/include/media/MediaPlayerInterface.h @@ -39,7 +39,6 @@ template<typename T> class SortedVector; enum player_type { PV_PLAYER = 1, SONIVOX_PLAYER = 2, - VORBIS_PLAYER = 3, STAGEFRIGHT_PLAYER = 4, // Test players are available only in the 'test' and 'eng' builds. // The shared library with the test player is passed passed as an diff --git a/include/media/MediaProfiles.h b/include/media/MediaProfiles.h index a4eea2a..c3cd361 100644 --- a/include/media/MediaProfiles.h +++ b/include/media/MediaProfiles.h @@ -48,8 +48,8 @@ public: static MediaProfiles* getInstance(); /** - * Returns the value for the given param name at the given quality level, - * or -1 if error. + * Returns the value for the given param name for the given camera at + * the given quality level, or -1 if error. * * Supported param name are: * duration - the recording duration. @@ -64,7 +64,8 @@ public: * aud.hz - audio sample rate * aud.ch - number of audio channels */ - int getCamcorderProfileParamByName(const char *name, camcorder_quality quality) const; + int getCamcorderProfileParamByName(const char *name, int cameraId, + camcorder_quality quality) const; /** * Returns the output file formats supported. @@ -124,12 +125,7 @@ public: /** * Returns the number of image encoding quality levels supported. */ - Vector<int> getImageEncodingQualityLevels() const; - - /** - * Returns the maximum amount of memory in bytes we can use for decoding a JPEG file. - */ - int getImageDecodingMaxMemory() const; + Vector<int> getImageEncodingQualityLevels(int cameraId) const; private: MediaProfiles& operator=(const MediaProfiles&); // Don't call me @@ -171,7 +167,8 @@ private: struct CamcorderProfile { CamcorderProfile() - : mFileFormat(OUTPUT_FORMAT_THREE_GPP), + : mCameraId(0), + mFileFormat(OUTPUT_FORMAT_THREE_GPP), mQuality(CAMCORDER_QUALITY_HIGH), mDuration(0), mVideoCodec(0), @@ -182,6 +179,7 @@ private: delete mAudioCodec; } + int mCameraId; output_format mFileFormat; camcorder_quality mQuality; int mDuration; @@ -249,6 +247,11 @@ private: int tag; }; + struct ImageEncodingQualityLevels { + int mCameraId; + Vector<int> mLevels; + }; + // Debug static void logVideoCodec(const VideoCodec& codec); static void logAudioCodec(const AudioCodec& codec); @@ -267,9 +270,11 @@ private: static VideoDecoderCap* createVideoDecoderCap(const char **atts); static VideoEncoderCap* createVideoEncoderCap(const char **atts); static AudioEncoderCap* createAudioEncoderCap(const char **atts); - static CamcorderProfile* createCamcorderProfile(const char **atts); - static int getImageEncodingQualityLevel(const char **atts); - static int getImageDecodingMaxMemory(const char **atts); + static CamcorderProfile* createCamcorderProfile(int cameraId, const char **atts); + static int getCameraId(const char **atts); + + ImageEncodingQualityLevels* findImageEncodingQualityLevels(int cameraId) const; + void addImageEncodingQualityLevel(int cameraId, const char** atts); // Customized element tag handler for parsing the xml configuration file. static void startElementHandler(void *userData, const char *name, const char **atts); @@ -303,6 +308,7 @@ private: static bool sIsInitialized; static MediaProfiles *sInstance; static Mutex sLock; + int mCurrentCameraId; Vector<CamcorderProfile*> mCamcorderProfiles; Vector<AudioEncoderCap*> mAudioEncoders; @@ -310,8 +316,7 @@ private: Vector<AudioDecoderCap*> mAudioDecoders; Vector<VideoDecoderCap*> mVideoDecoders; Vector<output_format> mEncoderOutputFileFormats; - Vector<int> mImageEncodingQualityLevels; - int mImageDecodingMaxMemory; + Vector<ImageEncodingQualityLevels *> mImageEncodingQualityLevels; }; }; // namespace android diff --git a/include/media/MediaRecorderBase.h b/include/media/MediaRecorderBase.h index 5b787a7..5e9e368 100644 --- a/include/media/MediaRecorderBase.h +++ b/include/media/MediaRecorderBase.h @@ -41,13 +41,14 @@ struct MediaRecorderBase { virtual status_t setOutputFile(const char *path) = 0; virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0; virtual status_t setParameters(const String8& params) = 0; - virtual status_t setListener(const sp<IMediaPlayerClient>& listener) = 0; + virtual status_t setListener(const sp<IMediaRecorderClient>& listener) = 0; virtual status_t prepare() = 0; virtual status_t start() = 0; virtual status_t stop() = 0; virtual status_t close() = 0; virtual status_t reset() = 0; virtual status_t getMaxAmplitude(int *max) = 0; + virtual status_t dump(int fd, const Vector<String16>& args) const = 0; private: MediaRecorderBase(const MediaRecorderBase &); diff --git a/include/media/PVMediaRecorder.h b/include/media/PVMediaRecorder.h index 2a1298a..c091c39 100644 --- a/include/media/PVMediaRecorder.h +++ b/include/media/PVMediaRecorder.h @@ -18,7 +18,7 @@ #ifndef ANDROID_PVMEDIARECORDER_H #define ANDROID_PVMEDIARECORDER_H -#include <media/IMediaPlayerClient.h> +#include <media/IMediaRecorderClient.h> #include <media/MediaRecorderBase.h> namespace android { @@ -45,13 +45,14 @@ public: virtual status_t setOutputFile(const char *path); virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); virtual status_t setParameters(const String8& params); - virtual status_t setListener(const sp<IMediaPlayerClient>& listener); + virtual status_t setListener(const sp<IMediaRecorderClient>& listener); virtual status_t prepare(); virtual status_t start(); virtual status_t stop(); virtual status_t close(); virtual status_t reset(); virtual status_t getMaxAmplitude(int *max); + virtual status_t dump(int fd, const Vector<String16>& args) const; private: status_t doStop(); diff --git a/include/media/Visualizer.h b/include/media/Visualizer.h new file mode 100644 index 0000000..5d51de8 --- /dev/null +++ b/include/media/Visualizer.h @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_MEDIA_VISUALIZER_H +#define ANDROID_MEDIA_VISUALIZER_H + +#include <media/AudioEffect.h> +#include <media/EffectVisualizerApi.h> +#include <string.h> + +/** + * The Visualizer class enables application to retrieve part of the currently playing audio for + * visualization purpose. It is not an audio recording interface and only returns partial and low + * quality audio content. However, to protect privacy of certain audio data (e.g voice mail) the use + * of the visualizer requires the permission android.permission.RECORD_AUDIO. + * The audio session ID passed to the constructor indicates which audio content should be + * visualized: + * - If the session is 0, the audio output mix is visualized + * - If the session is not 0, the audio from a particular MediaPlayer or AudioTrack + * using this audio session is visualized + * Two types of representation of audio content can be captured: + * - Waveform data: consecutive 8-bit (unsigned) mono samples by using the getWaveForm() method + * - Frequency data: 8-bit magnitude FFT by using the getFft() method + * + * The length of the capture can be retrieved or specified by calling respectively + * getCaptureSize() and setCaptureSize() methods. Note that the size of the FFT + * is half of the specified capture size but both sides of the spectrum are returned yielding in a + * number of bytes equal to the capture size. The capture size must be a power of 2 in the range + * returned by getMinCaptureSize() and getMaxCaptureSize(). + * In addition to the polling capture mode, a callback mode is also available by installing a + * callback function by use of the setCaptureCallBack() method. The rate at which the callback + * is called as well as the type of data returned is specified. + * Before capturing data, the Visualizer must be enabled by calling the setEnabled() method. + * When data capture is not needed any more, the Visualizer should be disabled. + */ + + +namespace android { + +// ---------------------------------------------------------------------------- + +class Visualizer: public AudioEffect { +public: + + enum callback_flags { + CAPTURE_WAVEFORM = 0x00000001, // capture callback returns a PCM wave form + CAPTURE_FFT = 0x00000002, // apture callback returns a frequency representation + CAPTURE_CALL_JAVA = 0x00000004 // the callback thread can call java + }; + + + /* Constructor. + * See AudioEffect constructor for details on parameters. + */ + Visualizer(int32_t priority = 0, + effect_callback_t cbf = 0, + void* user = 0, + int sessionId = 0); + + ~Visualizer(); + + virtual status_t setEnabled(bool enabled); + + // maximum capture size in samples + static uint32_t getMaxCaptureSize() { return VISUALIZER_CAPTURE_SIZE_MAX; } + // minimum capture size in samples + static uint32_t getMinCaptureSize() { return VISUALIZER_CAPTURE_SIZE_MIN; } + // maximum capture rate in millihertz + static uint32_t getMaxCaptureRate() { return CAPTURE_RATE_MAX; } + + // callback used to return periodic PCM or FFT captures to the application. Either one or both + // types of data are returned (PCM and FFT) according to flags indicated when installing the + // callback. When a type of data is not present, the corresponding size (waveformSize or + // fftSize) is 0. + typedef void (*capture_cbk_t)(void* user, + uint32_t waveformSize, + uint8_t *waveform, + uint32_t fftSize, + uint8_t *fft, + uint32_t samplingrate); + + // install a callback to receive periodic captures. The capture rate is specified in milliHertz + // and the capture format is according to flags (see callback_flags). + status_t setCaptureCallBack(capture_cbk_t cbk, void* user, uint32_t flags, uint32_t rate); + + // set the capture size capture size must be a power of two in the range + // [VISUALIZER_CAPTURE_SIZE_MAX. VISUALIZER_CAPTURE_SIZE_MIN] + // must be called when the visualizer is not enabled + status_t setCaptureSize(uint32_t size); + uint32_t getCaptureSize() { return mCaptureSize; } + + // returns the capture rate indicated when installing the callback + uint32_t getCaptureRate() { return mCaptureRate; } + + // returns the sampling rate of the audio being captured + uint32_t getSamplingRate() { return mSampleRate; } + + // return a capture in PCM 8 bit unsigned format. The size of the capture is equal to + // getCaptureSize() + status_t getWaveForm(uint8_t *waveform); + + // return a capture in FFT 8 bit signed format. The size of the capture is equal to + // getCaptureSize() but the length of the FFT is half of the size (both parts of the spectrum + // are returned + status_t getFft(uint8_t *fft); + +private: + + static const uint32_t CAPTURE_RATE_MAX = 20000; + static const uint32_t CAPTURE_RATE_DEF = 10000; + static const uint32_t CAPTURE_SIZE_DEF = VISUALIZER_CAPTURE_SIZE_MAX; + + /* internal class to handle the callback */ + class CaptureThread : public Thread + { + public: + CaptureThread(Visualizer& receiver, uint32_t captureRate, bool bCanCallJava = false); + + private: + friend class Visualizer; + virtual bool threadLoop(); + virtual status_t readyToRun(); + virtual void onFirstRef(); + Visualizer& mReceiver; + Mutex mLock; + uint32_t mSleepTimeUs; + }; + + status_t doFft(uint8_t *fft, uint8_t *waveform); + void periodicCapture(); + uint32_t initCaptureSize(); + + Mutex mLock; + uint32_t mCaptureRate; + uint32_t mCaptureSize; + uint32_t mSampleRate; + capture_cbk_t mCaptureCallBack; + void *mCaptureCbkUser; + sp<CaptureThread> mCaptureThread; + uint32_t mCaptureFlags; + void *mFftTable; +}; + + +}; // namespace android + +#endif // ANDROID_MEDIA_VISUALIZER_H diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h index 7fad1b7..207191d 100644 --- a/include/media/mediaplayer.h +++ b/include/media/mediaplayer.h @@ -93,6 +93,11 @@ enum media_info_type { // The video is too complex for the decoder: it can't decode frames fast // enough. Possibly only the audio plays fine at this stage. MEDIA_INFO_VIDEO_TRACK_LAGGING = 700, + // MediaPlayer is temporarily pausing playback internally in order to + // buffer more data. + MEDIA_INFO_BUFFERING_START = 701, + // MediaPlayer is resuming playback after filling buffers. + MEDIA_INFO_BUFFERING_END = 702, // 8xx // Bad interleaving means that a media has been improperly interleaved or not // interleaved at all, e.g has all the video samples first then all the audio @@ -161,12 +166,15 @@ public: void notify(int msg, int ext1, int ext2); static sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat); static sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat); - static int snoop(short *data, int len, int kind); status_t invoke(const Parcel& request, Parcel *reply); status_t setMetadataFilter(const Parcel& filter); status_t getMetadata(bool update_only, bool apply_filter, Parcel *metadata); status_t suspend(); status_t resume(); + status_t setAudioSessionId(int sessionId); + int getAudioSessionId(); + status_t setAuxEffectSendLevel(float level); + status_t attachAuxEffect(int effectId); private: void clear_l(); status_t seekTo_l(int msec); @@ -193,6 +201,8 @@ private: float mRightVolume; int mVideoWidth; int mVideoHeight; + int mAudioSessionId; + float mSendLevel; }; }; // namespace android diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h index 9ea6c7b..b21bc4d 100644 --- a/include/media/mediarecorder.h +++ b/include/media/mediarecorder.h @@ -22,7 +22,7 @@ #include <utils/threads.h> #include <utils/List.h> #include <utils/Errors.h> -#include <media/IMediaPlayerClient.h> +#include <media/IMediaRecorderClient.h> #include <media/IMediaDeathNotifier.h> namespace android { @@ -135,7 +135,10 @@ enum media_recorder_error_type { enum media_recorder_info_type { MEDIA_RECORDER_INFO_UNKNOWN = 1, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800, - MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801 + MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801, + MEDIA_RECORDER_INFO_COMPLETION_STATUS = 802, + MEDIA_RECORDER_INFO_PROGRESS_FRAME_STATUS = 803, + MEDIA_RECORDER_INFO_PROGRESS_TIME_STATUS = 804, }; // ---------------------------------------------------------------------------- @@ -146,7 +149,7 @@ public: virtual void notify(int msg, int ext1, int ext2) = 0; }; -class MediaRecorder : public BnMediaPlayerClient, +class MediaRecorder : public BnMediaRecorderClient, public virtual IMediaDeathNotifier { public: diff --git a/include/media/stagefright/AMRWriter.h b/include/media/stagefright/AMRWriter.h index 372909a..813dd43 100644 --- a/include/media/stagefright/AMRWriter.h +++ b/include/media/stagefright/AMRWriter.h @@ -26,6 +26,7 @@ namespace android { struct MediaSource; +struct MetaData; struct AMRWriter : public MediaWriter { AMRWriter(const char *filename); @@ -35,25 +36,30 @@ struct AMRWriter : public MediaWriter { virtual status_t addSource(const sp<MediaSource> &source); virtual bool reachedEOS(); - virtual status_t start(); + virtual status_t start(MetaData *params = NULL); virtual void stop(); + virtual void pause(); protected: virtual ~AMRWriter(); private: - Mutex mLock; - FILE *mFile; status_t mInitCheck; sp<MediaSource> mSource; bool mStarted; + volatile bool mPaused; + volatile bool mResumed; volatile bool mDone; - bool mReachedEOS; + volatile bool mReachedEOS; pthread_t mThread; + int64_t mEstimatedSizeBytes; + int64_t mEstimatedDurationUs; static void *ThreadWrapper(void *); void threadFunc(); + bool exceedsFileSizeLimit(); + bool exceedsFileDurationLimit(); AMRWriter(const AMRWriter &); AMRWriter &operator=(const AMRWriter &); diff --git a/include/media/stagefright/AudioSource.h b/include/media/stagefright/AudioSource.h index eb00140..628200d 100644 --- a/include/media/stagefright/AudioSource.h +++ b/include/media/stagefright/AudioSource.h @@ -39,6 +39,9 @@ struct AudioSource : public MediaSource { virtual status_t stop(); virtual sp<MetaData> getFormat(); + // Returns the maximum amplitude since last call. + int16_t getMaxAmplitude(); + virtual status_t read( MediaBuffer **buffer, const ReadOptions *options = NULL); @@ -46,13 +49,24 @@ protected: virtual ~AudioSource(); private: - enum { kMaxBufferSize = 8192 }; + enum { kMaxBufferSize = 2048 }; AudioRecord *mRecord; status_t mInitCheck; bool mStarted; + + bool mCollectStats; + bool mTrackMaxAmplitude; + int64_t mTotalReadTimeUs; + int64_t mTotalReadBytes; + int64_t mTotalReads; + int64_t mStartTimeUs; + int16_t mMaxAmplitude; + MediaBufferGroup *mGroup; + void trackMaxAmplitude(int16_t *data, int nSamples); + AudioSource(const AudioSource &); AudioSource &operator=(const AudioSource &); }; diff --git a/include/media/stagefright/CachingDataSource.h b/include/media/stagefright/CachingDataSource.h deleted file mode 100644 index 42d50e5..0000000 --- a/include/media/stagefright/CachingDataSource.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2009 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 CACHING_DATASOURCE_H_ - -#define CACHING_DATASOURCE_H_ - -#include <media/stagefright/DataSource.h> -#include <media/stagefright/MediaErrors.h> -#include <utils/threads.h> - -namespace android { - -class CachingDataSource : public DataSource { -public: - CachingDataSource( - const sp<DataSource> &source, size_t pageSize, int numPages); - - virtual status_t initCheck() const; - - virtual ssize_t readAt(off_t offset, void *data, size_t size); - - virtual status_t getSize(off_t *size); - - virtual uint32_t flags(); - -protected: - virtual ~CachingDataSource(); - -private: - struct Page { - Page *mPrev, *mNext; - off_t mOffset; - size_t mLength; - void *mData; - }; - - sp<DataSource> mSource; - void *mData; - size_t mPageSize; - Page *mFirst, *mLast; - - Page *allocate_page(); - - Mutex mLock; - - CachingDataSource(const CachingDataSource &); - CachingDataSource &operator=(const CachingDataSource &); -}; - -} // namespace android - -#endif // CACHING_DATASOURCE_H_ diff --git a/include/media/stagefright/CameraSource.h b/include/media/stagefright/CameraSource.h index ea435de..3192d03 100644 --- a/include/media/stagefright/CameraSource.h +++ b/include/media/stagefright/CameraSource.h @@ -28,18 +28,15 @@ namespace android { class ICamera; class IMemory; -class ISurface; class Camera; -class CameraSource : public MediaSource { +class CameraSource : public MediaSource, public MediaBufferObserver { public: static CameraSource *Create(); - static CameraSource *CreateFromICamera(const sp<ICamera> &icamera); + static CameraSource *CreateFromCamera(const sp<Camera> &camera); virtual ~CameraSource(); - void setPreviewSurface(const sp<ISurface> &surface); - virtual status_t start(MetaData *params = NULL); virtual status_t stop(); @@ -48,25 +45,39 @@ public: virtual status_t read( MediaBuffer **buffer, const ReadOptions *options = NULL); + virtual void signalBufferReturned(MediaBuffer* buffer); + private: friend class CameraSourceListener; sp<Camera> mCamera; - sp<ISurface> mPreviewSurface; + sp<MetaData> mMeta; Mutex mLock; Condition mFrameAvailableCondition; - List<sp<IMemory> > mFrames; + Condition mFrameCompleteCondition; + List<sp<IMemory> > mFramesReceived; + List<sp<IMemory> > mFramesBeingEncoded; List<int64_t> mFrameTimes; - int mWidth, mHeight; + int64_t mStartTimeUs; int64_t mFirstFrameTimeUs; - int32_t mNumFrames; + int64_t mLastFrameTimestampUs; + int32_t mNumFramesReceived; + int32_t mNumFramesEncoded; + int32_t mNumFramesDropped; + int32_t mNumGlitches; + int64_t mGlitchDurationThresholdUs; + bool mCollectStats; bool mStarted; CameraSource(const sp<Camera> &camera); - void dataCallback(int32_t msgType, const sp<IMemory> &data); + void dataCallbackTimestamp( + int64_t timestampUs, int32_t msgType, const sp<IMemory> &data); + + void releaseQueuedFrames(); + void releaseOneRecordingFrame(const sp<IMemory>& frame); CameraSource(const CameraSource &); CameraSource &operator=(const CameraSource &); diff --git a/include/media/stagefright/ColorConverter.h b/include/media/stagefright/ColorConverter.h index 1e341b9..bc3f464 100644 --- a/include/media/stagefright/ColorConverter.h +++ b/include/media/stagefright/ColorConverter.h @@ -58,6 +58,11 @@ private: const void *srcBits, size_t srcSkip, void *dstBits, size_t dstSkip); + void convertYUV420SemiPlanar( + size_t width, size_t height, + const void *srcBits, size_t srcSkip, + void *dstBits, size_t dstSkip); + ColorConverter(const ColorConverter &); ColorConverter &operator=(const ColorConverter &); }; diff --git a/include/media/stagefright/HTTPDataSource.h b/include/media/stagefright/HTTPDataSource.h deleted file mode 100644 index 0400bea..0000000 --- a/include/media/stagefright/HTTPDataSource.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2009 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 HTTP_DATASOURCE_H_ - -#define HTTP_DATASOURCE_H_ - -#include <media/stagefright/DataSource.h> -#include <utils/String8.h> -#include <utils/threads.h> - -namespace android { - -class HTTPStream; - -class HTTPDataSource : public DataSource { -public: - HTTPDataSource( - const char *host, int port, const char *path, - const KeyedVector<String8, String8> *headers = NULL); - - HTTPDataSource( - const char *uri, - const KeyedVector<String8, String8> *headers = NULL); - - status_t connect(); - void disconnect(); - - virtual status_t initCheck() const; - - virtual ssize_t readAt(off_t offset, void *data, size_t size); - - virtual status_t getSize(off_t *size); - - virtual uint32_t flags(); - -protected: - virtual ~HTTPDataSource(); - -private: - enum { - kBufferSize = 64 * 1024, - - // If we encounter a socket-read error we'll try reconnecting - // and restarting the read for at most this many times. - kMaxNumRetries = 3, - }; - - enum State { - DISCONNECTED, - CONNECTING, - CONNECTED - }; - - State mState; - mutable Mutex mStateLock; - - String8 mHeaders; - - String8 mStartingHost; - String8 mStartingPath; - int mStartingPort; - - HTTPStream *mHttp; - - void *mBuffer; - size_t mBufferLength; - off_t mBufferOffset; - - bool mContentLengthValid; - unsigned long long mContentLength; - - int32_t mNumRetriesLeft; - - void init(const KeyedVector<String8, String8> *headers); - - ssize_t sendRangeRequest(size_t offset); - void initHeaders(const KeyedVector<String8, String8> *overrides); - - status_t connectWithRedirectsAndRange(off_t rangeStart); - void applyTimeoutResponse(); - - HTTPDataSource(const HTTPDataSource &); - HTTPDataSource &operator=(const HTTPDataSource &); -}; - -} // namespace android - -#endif // HTTP_DATASOURCE_H_ - diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h index 6b93f19..d0c2dca 100644 --- a/include/media/stagefright/MPEG4Writer.h +++ b/include/media/stagefright/MPEG4Writer.h @@ -36,9 +36,10 @@ public: MPEG4Writer(int fd); virtual status_t addSource(const sp<MediaSource> &source); - virtual status_t start(); + virtual status_t start(MetaData *param = NULL); virtual bool reachedEOS(); virtual void stop(); + virtual void pause(); void beginBox(const char *fourcc); void writeInt8(int8_t x); @@ -49,6 +50,9 @@ public: void writeFourcc(const char *fourcc); void write(const void *data, size_t size); void endBox(); + uint32_t interleaveDuration() const { return mInterleaveDurationUs; } + status_t setInterleaveDuration(uint32_t duration); + int32_t getTimeScale() const { return mTimeScale; } protected: virtual ~MPEG4Writer(); @@ -57,16 +61,43 @@ private: class Track; FILE *mFile; + bool mUse32BitOffset; + bool mPaused; + bool mStarted; off_t mOffset; off_t mMdatOffset; + uint8_t *mMoovBoxBuffer; + off_t mMoovBoxBufferOffset; + bool mWriteMoovBoxToMemory; + off_t mFreeBoxOffset; + bool mStreamableFile; + off_t mEstimatedMoovBoxSize; + uint32_t mInterleaveDurationUs; + int32_t mTimeScale; + int64_t mStartTimestampUs; Mutex mLock; List<Track *> mTracks; List<off_t> mBoxes; - off_t addSample(MediaBuffer *buffer); - off_t addLengthPrefixedSample(MediaBuffer *buffer); + void setStartTimestampUs(int64_t timeUs); + int64_t getStartTimestampUs(); // Not const + status_t startTracks(MetaData *params); + size_t numTracks(); + int64_t estimateMoovBoxSize(int32_t bitRate); + + void lock(); + void unlock(); + + // Acquire lock before calling these methods + off_t addSample_l(MediaBuffer *buffer); + off_t addLengthPrefixedSample_l(MediaBuffer *buffer); + + inline size_t write(const void *ptr, size_t size, size_t nmemb, FILE* stream); + bool exceedsFileSizeLimit(); + bool exceedsFileDurationLimit(); + void trackProgressStatus(const Track* track, int64_t timeUs, status_t err = OK); MPEG4Writer(const MPEG4Writer &); MPEG4Writer &operator=(const MPEG4Writer &); diff --git a/include/media/stagefright/MediaDefs.h b/include/media/stagefright/MediaDefs.h index 207195a..9cddab2 100644 --- a/include/media/stagefright/MediaDefs.h +++ b/include/media/stagefright/MediaDefs.h @@ -22,6 +22,7 @@ namespace android { extern const char *MEDIA_MIMETYPE_IMAGE_JPEG; +extern const char *MEDIA_MIMETYPE_VIDEO_VPX; extern const char *MEDIA_MIMETYPE_VIDEO_AVC; extern const char *MEDIA_MIMETYPE_VIDEO_MPEG4; extern const char *MEDIA_MIMETYPE_VIDEO_H263; @@ -38,6 +39,8 @@ extern const char *MEDIA_MIMETYPE_AUDIO_RAW; extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG4; extern const char *MEDIA_MIMETYPE_CONTAINER_WAV; extern const char *MEDIA_MIMETYPE_CONTAINER_OGG; +extern const char *MEDIA_MIMETYPE_CONTAINER_MATROSKA; +extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG2TS; } // namespace android diff --git a/include/media/stagefright/MediaSource.h b/include/media/stagefright/MediaSource.h index 96d57e7..dafc621 100644 --- a/include/media/stagefright/MediaSource.h +++ b/include/media/stagefright/MediaSource.h @@ -20,6 +20,7 @@ #include <sys/types.h> +#include <media/stagefright/MediaErrors.h> #include <utils/RefBase.h> namespace android { @@ -61,28 +62,56 @@ struct MediaSource : public RefBase { // a) not request a seek // b) not be late, i.e. lateness_us = 0 struct ReadOptions { + enum SeekMode { + SEEK_PREVIOUS_SYNC, + SEEK_NEXT_SYNC, + SEEK_CLOSEST_SYNC, + SEEK_CLOSEST, + }; + ReadOptions(); // Reset everything back to defaults. void reset(); - void setSeekTo(int64_t time_us); + void setSeekTo(int64_t time_us, SeekMode mode = SEEK_CLOSEST_SYNC); void clearSeekTo(); - bool getSeekTo(int64_t *time_us) const; + bool getSeekTo(int64_t *time_us, SeekMode *mode) const; + + // Option allows encoder to skip some frames until the specified + // time stamp. + // To prevent from being abused, when the skipFrame timestamp is + // found to be more than 1 second later than the current timestamp, + // an error will be returned from read(). + void clearSkipFrame(); + bool getSkipFrame(int64_t *timeUs) const; + void setSkipFrame(int64_t timeUs); void setLateBy(int64_t lateness_us); int64_t getLateBy() const; private: enum Options { + // Bit map kSeekTo_Option = 1, + kSkipFrame_Option = 2, }; uint32_t mOptions; int64_t mSeekTimeUs; + SeekMode mSeekMode; int64_t mLatenessUs; + + int64_t mSkipFrameUntilTimeUs; }; + // Causes this source to suspend pulling data from its upstream source + // until a subsequent read-with-seek. Currently only supported by + // OMXCodec. + virtual status_t pause() { + return ERROR_UNSUPPORTED; + } + protected: virtual ~MediaSource(); diff --git a/include/media/stagefright/MediaWriter.h b/include/media/stagefright/MediaWriter.h index b8232c6..8d3a9df 100644 --- a/include/media/stagefright/MediaWriter.h +++ b/include/media/stagefright/MediaWriter.h @@ -19,22 +19,41 @@ #define MEDIA_WRITER_H_ #include <utils/RefBase.h> +#include <media/IMediaRecorderClient.h> namespace android { struct MediaSource; +struct MetaData; struct MediaWriter : public RefBase { - MediaWriter() {} + MediaWriter() + : mMaxFileSizeLimitBytes(0), + mMaxFileDurationLimitUs(0) { + } virtual status_t addSource(const sp<MediaSource> &source) = 0; virtual bool reachedEOS() = 0; - virtual status_t start() = 0; + virtual status_t start(MetaData *params = NULL) = 0; virtual void stop() = 0; + virtual void pause() = 0; + virtual void setMaxFileSize(int64_t bytes) { mMaxFileSizeLimitBytes = bytes; } + virtual void setMaxFileDuration(int64_t durationUs) { mMaxFileDurationLimitUs = durationUs; } + virtual void setListener(const sp<IMediaRecorderClient>& listener) { + mListener = listener; + } protected: virtual ~MediaWriter() {} + int64_t mMaxFileSizeLimitBytes; + int64_t mMaxFileDurationLimitUs; + sp<IMediaRecorderClient> mListener; + void notify(int msg, int ext1, int ext2) { + if (mListener != NULL) { + mListener->notify(msg, ext1, ext2); + } + } private: MediaWriter(const MediaWriter &); MediaWriter &operator=(const MediaWriter &); diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h index dc2bd50..e631c7f 100644 --- a/include/media/stagefright/MetaData.h +++ b/include/media/stagefright/MetaData.h @@ -30,10 +30,13 @@ namespace android { // The following keys map to int32_t data unless indicated otherwise. enum { kKeyMIMEType = 'mime', // cstring - kKeyWidth = 'widt', - kKeyHeight = 'heig', - kKeyChannelCount = '#chn', - kKeySampleRate = 'srte', + kKeyWidth = 'widt', // int32_t + kKeyHeight = 'heig', // int32_t + kKeyIFramesInterval = 'ifiv', // int32_t + kKeyStride = 'strd', // int32_t + kKeySliceHeight = 'slht', // int32_t + kKeyChannelCount = '#chn', // int32_t + kKeySampleRate = 'srte', // int32_t (also video frame rate) kKeyBitRate = 'brte', // int32_t (bps) kKeyESDS = 'esds', // raw data kKeyAVCC = 'avcc', // raw data @@ -43,6 +46,7 @@ enum { kKeyIsSyncFrame = 'sync', // int32_t (bool) kKeyIsCodecConfig = 'conf', // int32_t (bool) kKeyTime = 'time', // int64_t (usecs) + kKeyTargetTime = 'tarT', // int64_t (usecs) kKeyDuration = 'dura', // int64_t (usecs) kKeyColorFormat = 'colf', kKeyPlatformPrivate = 'priv', // pointer @@ -65,6 +69,26 @@ enum { kKeyDiscNumber = 'dnum', // cstring kKeyDate = 'date', // cstring kKeyWriter = 'writ', // cstring + kKeyTimeScale = 'tmsl', // int32_t + + // video profile and level + kKeyVideoProfile = 'vprf', // int32_t + kKeyVideoLevel = 'vlev', // int32_t + + // Set this key to enable authoring files in 64-bit offset + kKey64BitFileOffset = 'fobt', // int32_t (bool) + + // Identify the file output format for authoring + // Please see <media/mediarecorder.h> for the supported + // file output formats. + kKeyFileType = 'ftyp', // int32_t + + // Track authoring progress status + // kKeyTrackTimeStatus is used to track progress in elapsed time + // kKeyTrackFrameStatus is used to track progress in authored frames + kKeyTrackFrameStatus = 'tkfm', // int32_t + kKeyTrackTimeStatus = 'tktm', // int64_t + }; enum { diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h index 1d76a1a..6c6949b 100644 --- a/include/media/stagefright/OMXCodec.h +++ b/include/media/stagefright/OMXCodec.h @@ -27,6 +27,7 @@ namespace android { class MemoryDealer; struct OMXCodecObserver; +struct CodecProfileLevel; struct OMXCodec : public MediaSource, public MediaBufferObserver { @@ -52,6 +53,8 @@ struct OMXCodec : public MediaSource, virtual status_t read( MediaBuffer **buffer, const ReadOptions *options = NULL); + virtual status_t pause(); + void on_message(const omx_message &msg); // from MediaBufferObserver @@ -98,6 +101,7 @@ private: kDecoderLiesAboutNumberOfChannels = 256, kInputBufferSizesAreBogus = 512, kSupportsMultipleFramesPerInputBuffer = 1024, + kAvoidMemcopyInputRecordingFrames = 2048, }; struct BufferInfo { @@ -137,12 +141,17 @@ private: bool mNoMoreOutputData; bool mOutputPortSettingsHaveChanged; int64_t mSeekTimeUs; + ReadOptions::SeekMode mSeekMode; + int64_t mTargetTimeUs; + int64_t mSkipTimeUs; MediaBuffer *mLeftOverBuffer; Mutex mLock; Condition mAsyncCompletion; + bool mPaused; + // A list of indices into mPortStatus[kPortIndexOutput] filled with data. List<size_t> mFilledBuffers; Condition mBufferFilled; @@ -156,8 +165,8 @@ private: void setComponentRole(); - void setAMRFormat(bool isWAMR); - void setAACFormat(int32_t numChannels, int32_t sampleRate); + void setAMRFormat(bool isWAMR, int32_t bitRate); + void setAACFormat(int32_t numChannels, int32_t sampleRate, int32_t bitRate); status_t setVideoPortFormatType( OMX_U32 portIndex, @@ -165,10 +174,19 @@ private: OMX_COLOR_FORMATTYPE colorFormat); void setVideoInputFormat( - const char *mime, OMX_U32 width, OMX_U32 height); - - status_t setupMPEG4EncoderParameters(); - status_t setupAVCEncoderParameters(); + const char *mime, const sp<MetaData>& meta); + + status_t setupBitRate(int32_t bitRate); + status_t setupErrorCorrectionParameters(); + status_t setupH263EncoderParameters(const sp<MetaData>& meta); + status_t setupMPEG4EncoderParameters(const sp<MetaData>& meta); + status_t setupAVCEncoderParameters(const sp<MetaData>& meta); + + // If profile/level is set in the meta data, its value in the meta + // data will be used; otherwise, the default value will be used. + status_t getVideoProfileLevel(const sp<MetaData>& meta, + const CodecProfileLevel& defaultProfileLevel, + CodecProfileLevel& profileLevel); status_t setVideoOutputFormat( const char *mime, OMX_U32 width, OMX_U32 height); diff --git a/include/media/stagefright/foundation/AAtomizer.h b/include/media/stagefright/foundation/AAtomizer.h new file mode 100644 index 0000000..5f3a678 --- /dev/null +++ b/include/media/stagefright/foundation/AAtomizer.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_ATOMIZER_H_ + +#define A_ATOMIZER_H_ + +#include <stdint.h> + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AString.h> +#include <utils/List.h> +#include <utils/Vector.h> +#include <utils/threads.h> + +namespace android { + +struct AAtomizer { + static const char *Atomize(const char *name); + +private: + static AAtomizer gAtomizer; + + Mutex mLock; + Vector<List<AString> > mAtoms; + + AAtomizer(); + + const char *atomize(const char *name); + + static uint32_t Hash(const char *s); + + DISALLOW_EVIL_CONSTRUCTORS(AAtomizer); +}; + +} // namespace android + +#endif // A_ATOMIZER_H_ diff --git a/include/media/stagefright/foundation/ABase.h b/include/media/stagefright/foundation/ABase.h new file mode 100644 index 0000000..9eceea3 --- /dev/null +++ b/include/media/stagefright/foundation/ABase.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_BASE_H_ + +#define A_BASE_H_ + +#define DISALLOW_EVIL_CONSTRUCTORS(name) \ + name(const name &); \ + name &operator=(const name &) + +#endif // A_BASE_H_ diff --git a/include/media/stagefright/foundation/ABuffer.h b/include/media/stagefright/foundation/ABuffer.h new file mode 100644 index 0000000..28f0aed --- /dev/null +++ b/include/media/stagefright/foundation/ABuffer.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_BUFFER_H_ + +#define A_BUFFER_H_ + +#include <sys/types.h> +#include <stdint.h> + +#include <media/stagefright/foundation/ABase.h> +#include <utils/RefBase.h> + +namespace android { + +struct AMessage; + +struct ABuffer : public RefBase { + ABuffer(size_t capacity); + ABuffer(void *data, size_t capacity); + + void setFarewellMessage(const sp<AMessage> msg); + + uint8_t *base() { return (uint8_t *)mData; } + uint8_t *data() { return (uint8_t *)mData + mRangeOffset; } + size_t capacity() const { return mCapacity; } + size_t size() const { return mRangeLength; } + size_t offset() const { return mRangeOffset; } + + void setRange(size_t offset, size_t size); + + void setInt32Data(int32_t data) { mInt32Data = data; } + int32_t int32Data() const { return mInt32Data; } + + sp<AMessage> meta(); + +protected: + virtual ~ABuffer(); + +private: + sp<AMessage> mFarewell; + sp<AMessage> mMeta; + + void *mData; + size_t mCapacity; + size_t mRangeOffset; + size_t mRangeLength; + + int32_t mInt32Data; + + bool mOwnsData; + + DISALLOW_EVIL_CONSTRUCTORS(ABuffer); +}; + +} // namespace android + +#endif // A_BUFFER_H_ diff --git a/include/media/stagefright/foundation/ADebug.h b/include/media/stagefright/foundation/ADebug.h new file mode 100644 index 0000000..0f986a0 --- /dev/null +++ b/include/media/stagefright/foundation/ADebug.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_DEBUG_H_ + +#define A_DEBUG_H_ + +#include <string.h> + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AString.h> + +namespace android { + +enum LogType { + VERBOSE, + INFO, + WARNING, + ERROR, + FATAL, +}; + +struct Logger { + Logger(LogType type); + virtual ~Logger(); + + template<class T> Logger &operator<<(const T &x) { + mMessage.append(x); + + return *this; + } + +private: + android::AString mMessage; + LogType mLogType; + + DISALLOW_EVIL_CONSTRUCTORS(Logger); +}; + +const char *LeafName(const char *s); + +#undef LOG +#define LOG(type) Logger(type) << LeafName(__FILE__) << ":" << __LINE__ << " " + +#define CHECK(condition) \ + do { \ + if (!(condition)) { \ + LOG(FATAL) << "CHECK(" #condition ") failed."; \ + } \ + } while (false) + +#define MAKE_COMPARATOR(suffix,op) \ + template<class A, class B> \ + AString Compare_##suffix(const A &a, const B &b) { \ + AString res; \ + if (!(a op b)) { \ + res.append(a); \ + res.append(" vs. "); \ + res.append(b); \ + } \ + return res; \ + } + +MAKE_COMPARATOR(EQ,==) +MAKE_COMPARATOR(NE,!=) +MAKE_COMPARATOR(LE,<=) +MAKE_COMPARATOR(GE,>=) +MAKE_COMPARATOR(LT,<) +MAKE_COMPARATOR(GT,>) + +#define CHECK_OP(x,y,suffix,op) \ + do { \ + AString ___res = Compare_##suffix(x, y); \ + if (!___res.empty()) { \ + LOG(FATAL) << "CHECK_" #suffix "(" #x "," #y ") failed: " \ + << ___res; \ + } \ + } while (false) + +#define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==) +#define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=) +#define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=) +#define CHECK_LT(x,y) CHECK_OP(x,y,LT,<) +#define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=) +#define CHECK_GT(x,y) CHECK_OP(x,y,GT,>) + +#define TRESPASS() LOG(FATAL) << "Should not be here." + +} // namespace android + +#endif // A_DEBUG_H_ + diff --git a/include/media/stagefright/foundation/AHandler.h b/include/media/stagefright/foundation/AHandler.h new file mode 100644 index 0000000..b008b54 --- /dev/null +++ b/include/media/stagefright/foundation/AHandler.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_HANDLER_H_ + +#define A_HANDLER_H_ + +#include <media/stagefright/foundation/ALooper.h> +#include <utils/RefBase.h> + +namespace android { + +struct AMessage; + +struct AHandler : public RefBase { + AHandler() + : mID(0) { + } + + ALooper::handler_id id() const { + return mID; + } + + sp<ALooper> looper(); + +protected: + virtual void onMessageReceived(const sp<AMessage> &msg) = 0; + +private: + friend struct ALooperRoster; + + ALooper::handler_id mID; + + void setID(ALooper::handler_id id) { + mID = id; + } + + DISALLOW_EVIL_CONSTRUCTORS(AHandler); +}; + +} // namespace android + +#endif // A_HANDLER_H_ diff --git a/include/media/stagefright/foundation/AHandlerReflector.h b/include/media/stagefright/foundation/AHandlerReflector.h new file mode 100644 index 0000000..857866a --- /dev/null +++ b/include/media/stagefright/foundation/AHandlerReflector.h @@ -0,0 +1,32 @@ +#ifndef A_HANDLER_REFLECTOR_H_ + +#define A_HANDLER_REFLECTOR_H_ + +#include <media/stagefright/foundation/AHandler.h> + +namespace android { + +template<class T> +struct AHandlerReflector : public AHandler { + AHandlerReflector(T *target) + : mTarget(target) { + } + +protected: + virtual void onMessageReceived(const sp<AMessage> &msg) { + sp<T> target = mTarget.promote(); + if (target != NULL) { + target->onMessageReceived(msg); + } + } + +private: + wp<T> mTarget; + + AHandlerReflector(const AHandlerReflector<T> &); + AHandlerReflector<T> &operator=(const AHandlerReflector<T> &); +}; + +} // namespace android + +#endif // A_HANDLER_REFLECTOR_H_ diff --git a/include/media/stagefright/foundation/ALooper.h b/include/media/stagefright/foundation/ALooper.h new file mode 100644 index 0000000..153ead9 --- /dev/null +++ b/include/media/stagefright/foundation/ALooper.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_LOOPER_H_ + +#define A_LOOPER_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <utils/Errors.h> +#include <utils/KeyedVector.h> +#include <utils/List.h> +#include <utils/RefBase.h> +#include <utils/threads.h> + +namespace android { + +struct AHandler; +struct AMessage; + +struct ALooper : public RefBase { + typedef int32_t event_id; + typedef int32_t handler_id; + + ALooper(); + + handler_id registerHandler(const sp<AHandler> &handler); + void unregisterHandler(handler_id handlerID); + + status_t start( + bool runOnCallingThread = false, + bool canCallJava = false, + int32_t priority = PRIORITY_DEFAULT + ); + + status_t stop(); + + static int64_t GetNowUs(); + +protected: + virtual ~ALooper(); + +private: + friend struct ALooperRoster; + + struct Event { + int64_t mWhenUs; + sp<AMessage> mMessage; + }; + + Mutex mLock; + Condition mQueueChangedCondition; + + List<Event> mEventQueue; + + struct LooperThread; + sp<LooperThread> mThread; + bool mRunningLocally; + + void post(const sp<AMessage> &msg, int64_t delayUs); + bool loop(); + + DISALLOW_EVIL_CONSTRUCTORS(ALooper); +}; + +} // namespace android + +#endif // A_LOOPER_H_ diff --git a/include/media/stagefright/foundation/ALooperRoster.h b/include/media/stagefright/foundation/ALooperRoster.h new file mode 100644 index 0000000..c1bd4ed --- /dev/null +++ b/include/media/stagefright/foundation/ALooperRoster.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_LOOPER_ROSTER_H_ + +#define A_LOOPER_ROSTER_H_ + +#include <media/stagefright/foundation/ALooper.h> +#include <utils/KeyedVector.h> + +namespace android { + +struct ALooperRoster { + ALooperRoster(); + + ALooper::handler_id registerHandler( + const sp<ALooper> looper, const sp<AHandler> &handler); + + void unregisterHandler(ALooper::handler_id handlerID); + + void postMessage(const sp<AMessage> &msg, int64_t delayUs = 0); + void deliverMessage(const sp<AMessage> &msg); + + sp<ALooper> findLooper(ALooper::handler_id handlerID); + +private: + struct HandlerInfo { + wp<ALooper> mLooper; + wp<AHandler> mHandler; + }; + + Mutex mLock; + KeyedVector<ALooper::handler_id, HandlerInfo> mHandlers; + ALooper::handler_id mNextHandlerID; + + DISALLOW_EVIL_CONSTRUCTORS(ALooperRoster); +}; + +} // namespace android + +#endif // A_LOOPER_ROSTER_H_ diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h new file mode 100644 index 0000000..c674cba --- /dev/null +++ b/include/media/stagefright/foundation/AMessage.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_MESSAGE_H_ + +#define A_MESSAGE_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/ALooper.h> +#include <utils/KeyedVector.h> +#include <utils/RefBase.h> + +namespace android { + +struct AString; + +struct AMessage : public RefBase { + AMessage(uint32_t what = 0, ALooper::handler_id target = 0); + + void setWhat(uint32_t what); + uint32_t what() const; + + void setTarget(ALooper::handler_id target); + ALooper::handler_id target() const; + + void setInt32(const char *name, int32_t value); + void setInt64(const char *name, int64_t value); + void setSize(const char *name, size_t value); + void setFloat(const char *name, float value); + void setDouble(const char *name, double value); + void setPointer(const char *name, void *value); + void setString(const char *name, const char *s, ssize_t len = -1); + void setObject(const char *name, const sp<RefBase> &obj); + void setMessage(const char *name, const sp<AMessage> &obj); + + bool findInt32(const char *name, int32_t *value) const; + bool findInt64(const char *name, int64_t *value) const; + bool findSize(const char *name, size_t *value) const; + bool findFloat(const char *name, float *value) const; + bool findDouble(const char *name, double *value) const; + bool findPointer(const char *name, void **value) const; + bool findString(const char *name, AString *value) const; + bool findObject(const char *name, sp<RefBase> *obj) const; + bool findMessage(const char *name, sp<AMessage> *obj) const; + + void post(int64_t delayUs = 0); + + sp<AMessage> dup() const; + + AString debugString(int32_t indent = 0) const; + +protected: + virtual ~AMessage(); + +private: + enum Type { + kTypeInt32, + kTypeInt64, + kTypeSize, + kTypeFloat, + kTypeDouble, + kTypePointer, + kTypeString, + kTypeObject, + kTypeMessage, + }; + + uint32_t mWhat; + ALooper::handler_id mTarget; + + struct Item { + union { + int32_t int32Value; + int64_t int64Value; + size_t sizeValue; + float floatValue; + double doubleValue; + void *ptrValue; + RefBase *refValue; + AString *stringValue; + } u; + const char *mName; + Type mType; + }; + + enum { + kMaxNumItems = 16 + }; + Item mItems[kMaxNumItems]; + size_t mNumItems; + + void clear(); + Item *allocateItem(const char *name); + void freeItem(Item *item); + const Item *findItem(const char *name, Type type) const; + + DISALLOW_EVIL_CONSTRUCTORS(AMessage); +}; + +} // namespace android + +#endif // A_MESSAGE_H_ diff --git a/include/media/stagefright/foundation/AString.h b/include/media/stagefright/foundation/AString.h new file mode 100644 index 0000000..55ade64 --- /dev/null +++ b/include/media/stagefright/foundation/AString.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef A_STRING_H_ + +#define A_STRING_H_ + +#include <sys/types.h> + +namespace android { + +struct AString { + AString(); + AString(const char *s); + AString(const char *s, size_t size); + AString(const AString &from); + AString(const AString &from, size_t offset, size_t n); + ~AString(); + + AString &operator=(const AString &from); + void setTo(const char *s); + void setTo(const char *s, size_t size); + void setTo(const AString &from, size_t offset, size_t n); + + size_t size() const; + const char *c_str() const; + + bool empty() const; + + void clear(); + void trim(); + void erase(size_t start, size_t n); + + void append(char c) { append(&c, 1); } + void append(const char *s); + void append(const char *s, size_t size); + void append(const AString &from); + void append(const AString &from, size_t offset, size_t n); + void append(int x); + void append(unsigned x); + void append(long x); + void append(unsigned long x); + void append(long long x); + void append(unsigned long long x); + void append(float x); + void append(double x); + void append(void *x); + + void insert(const AString &from, size_t insertionPos); + void insert(const char *from, size_t size, size_t insertionPos); + + ssize_t find(const char *substring, size_t start = 0) const; + + size_t hash() const; + + bool operator==(const AString &other) const; + bool operator<(const AString &other) const; + bool operator>(const AString &other) const; + + int compare(const AString &other) const; + + bool startsWith(const char *prefix) const; + + void tolower(); + +private: + static const char *kEmptyString; + + char *mData; + size_t mSize; + size_t mAllocSize; + + void makeMutable(); +}; + +AString StringPrintf(const char *format, ...); + +} // namespace android + +#endif // A_STRING_H_ + diff --git a/include/media/stagefright/foundation/base64.h b/include/media/stagefright/foundation/base64.h new file mode 100644 index 0000000..e340b89 --- /dev/null +++ b/include/media/stagefright/foundation/base64.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_64_H_ + +#define BASE_64_H_ + +#include <utils/RefBase.h> + +namespace android { + +struct ABuffer; +struct AString; + +sp<ABuffer> decodeBase64(const AString &s); +void encodeBase64(const void *data, size_t size, AString *out); + +} // namespace android + +#endif // BASE_64_H_ diff --git a/include/media/stagefright/foundation/hexdump.h b/include/media/stagefright/foundation/hexdump.h new file mode 100644 index 0000000..f6083a9 --- /dev/null +++ b/include/media/stagefright/foundation/hexdump.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HEXDUMP_H_ + +#define HEXDUMP_H_ + +#include <sys/types.h> + +namespace android { + +void hexdump(const void *_data, size_t size); + +} // namespace android + +#endif // HEXDUMP_H_ |
