Home | History | Annotate | Download | only in hardware_legacy
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 #include <stdint.h>
     19 #include <sys/types.h>
     20 #include <cutils/config_utils.h>
     21 #include <cutils/misc.h>
     22 #include <utils/Timers.h>
     23 #include <utils/Errors.h>
     24 #include <utils/KeyedVector.h>
     25 #include <utils/SortedVector.h>
     26 #include <hardware_legacy/AudioPolicyInterface.h>
     27 
     28 
     29 namespace android_audio_legacy {
     30     using android::KeyedVector;
     31     using android::DefaultKeyedVector;
     32     using android::SortedVector;
     33 
     34 // ----------------------------------------------------------------------------
     35 
     36 #define MAX_DEVICE_ADDRESS_LEN 20
     37 // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB
     38 #define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5
     39 // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB
     40 #define SONIFICATION_HEADSET_VOLUME_MIN  0.016
     41 // Time in milliseconds during which we consider that music is still active after a music
     42 // track was stopped - see computeVolume()
     43 #define SONIFICATION_HEADSET_MUSIC_DELAY  5000
     44 // Time in milliseconds after media stopped playing during which we consider that the
     45 // sonification should be as unobtrusive as during the time media was playing.
     46 #define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000
     47 // Time in milliseconds during witch some streams are muted while the audio path
     48 // is switched
     49 #define MUTE_TIME_MS 2000
     50 
     51 #define NUM_TEST_OUTPUTS 5
     52 
     53 #define NUM_VOL_CURVE_KNEES 2
     54 
     55 // ----------------------------------------------------------------------------
     56 // AudioPolicyManagerBase implements audio policy manager behavior common to all platforms.
     57 // Each platform must implement an AudioPolicyManager class derived from AudioPolicyManagerBase
     58 // and override methods for which the platform specific behavior differs from the implementation
     59 // in AudioPolicyManagerBase. Even if no specific behavior is required, the AudioPolicyManager
     60 // class must be implemented as well as the class factory function createAudioPolicyManager()
     61 // and provided in a shared library libaudiopolicy.so.
     62 // ----------------------------------------------------------------------------
     63 
     64 class AudioPolicyManagerBase: public AudioPolicyInterface
     65 #ifdef AUDIO_POLICY_TEST
     66     , public Thread
     67 #endif //AUDIO_POLICY_TEST
     68 {
     69 
     70 public:
     71                 AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface);
     72         virtual ~AudioPolicyManagerBase();
     73 
     74         // AudioPolicyInterface
     75         virtual status_t setDeviceConnectionState(audio_devices_t device,
     76                                                           AudioSystem::device_connection_state state,
     77                                                           const char *device_address);
     78         virtual AudioSystem::device_connection_state getDeviceConnectionState(audio_devices_t device,
     79                                                                               const char *device_address);
     80         virtual void setPhoneState(int state);
     81         virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
     82         virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage);
     83         virtual void setSystemProperty(const char* property, const char* value);
     84         virtual status_t initCheck();
     85         virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream,
     86                                             uint32_t samplingRate = 0,
     87                                             uint32_t format = AudioSystem::FORMAT_DEFAULT,
     88                                             uint32_t channels = 0,
     89                                             AudioSystem::output_flags flags =
     90                                                     AudioSystem::OUTPUT_FLAG_INDIRECT);
     91         virtual status_t startOutput(audio_io_handle_t output,
     92                                      AudioSystem::stream_type stream,
     93                                      int session = 0);
     94         virtual status_t stopOutput(audio_io_handle_t output,
     95                                     AudioSystem::stream_type stream,
     96                                     int session = 0);
     97         virtual void releaseOutput(audio_io_handle_t output);
     98         virtual audio_io_handle_t getInput(int inputSource,
     99                                             uint32_t samplingRate,
    100                                             uint32_t format,
    101                                             uint32_t channels,
    102                                             AudioSystem::audio_in_acoustics acoustics);
    103 
    104         // indicates to the audio policy manager that the input starts being used.
    105         virtual status_t startInput(audio_io_handle_t input);
    106 
    107         // indicates to the audio policy manager that the input stops being used.
    108         virtual status_t stopInput(audio_io_handle_t input);
    109         virtual void releaseInput(audio_io_handle_t input);
    110         virtual void initStreamVolume(AudioSystem::stream_type stream,
    111                                                     int indexMin,
    112                                                     int indexMax);
    113         virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream,
    114                                               int index,
    115                                               audio_devices_t device);
    116         virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream,
    117                                               int *index,
    118                                               audio_devices_t device);
    119 
    120         // return the strategy corresponding to a given stream type
    121         virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream);
    122 
    123         // return the enabled output devices for the given stream type
    124         virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream);
    125 
    126         virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
    127         virtual status_t registerEffect(const effect_descriptor_t *desc,
    128                                         audio_io_handle_t io,
    129                                         uint32_t strategy,
    130                                         int session,
    131                                         int id);
    132         virtual status_t unregisterEffect(int id);
    133         virtual status_t setEffectEnabled(int id, bool enabled);
    134 
    135         virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const;
    136         virtual bool isSourceActive(audio_source_t source) const;
    137 
    138         virtual status_t dump(int fd);
    139 
    140 protected:
    141 
    142         enum routing_strategy {
    143             STRATEGY_MEDIA,
    144             STRATEGY_PHONE,
    145             STRATEGY_SONIFICATION,
    146             STRATEGY_SONIFICATION_RESPECTFUL,
    147             STRATEGY_DTMF,
    148             STRATEGY_ENFORCED_AUDIBLE,
    149             NUM_STRATEGIES
    150         };
    151 
    152         // 4 points to define the volume attenuation curve, each characterized by the volume
    153         // index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
    154         // we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
    155 
    156         enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4};
    157 
    158         class VolumeCurvePoint
    159         {
    160         public:
    161             int mIndex;
    162             float mDBAttenuation;
    163         };
    164 
    165         // device categories used for volume curve management.
    166         enum device_category {
    167             DEVICE_CATEGORY_HEADSET,
    168             DEVICE_CATEGORY_SPEAKER,
    169             DEVICE_CATEGORY_EARPIECE,
    170             DEVICE_CATEGORY_CNT
    171         };
    172 
    173         class IOProfile;
    174 
    175         class HwModule {
    176         public:
    177                     HwModule(const char *name);
    178                     ~HwModule();
    179 
    180             void dump(int fd);
    181 
    182             const char *const mName; // base name of the audio HW module (primary, a2dp ...)
    183             audio_module_handle_t mHandle;
    184             Vector <IOProfile *> mOutputProfiles; // output profiles exposed by this module
    185             Vector <IOProfile *> mInputProfiles;  // input profiles exposed by this module
    186         };
    187 
    188         // the IOProfile class describes the capabilities of an output or input stream.
    189         // It is currently assumed that all combination of listed parameters are supported.
    190         // It is used by the policy manager to determine if an output or input is suitable for
    191         // a given use case,  open/close it accordingly and connect/disconnect audio tracks
    192         // to/from it.
    193         class IOProfile
    194         {
    195         public:
    196             IOProfile(HwModule *module);
    197             ~IOProfile();
    198 
    199             bool isCompatibleProfile(audio_devices_t device,
    200                                      uint32_t samplingRate,
    201                                      uint32_t format,
    202                                      uint32_t channelMask,
    203                                      audio_output_flags_t flags) const;
    204 
    205             void dump(int fd);
    206 
    207             // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
    208             // indicates the supported parameters should be read from the output stream
    209             // after it is opened for the first time
    210             Vector <uint32_t> mSamplingRates; // supported sampling rates
    211             Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
    212             Vector <audio_format_t> mFormats; // supported audio formats
    213             audio_devices_t mSupportedDevices; // supported devices (devices this output can be
    214                                                // routed to)
    215             audio_output_flags_t mFlags; // attribute flags (e.g primary output,
    216                                                 // direct output...). For outputs only.
    217             HwModule *mModule;                     // audio HW module exposing this I/O stream
    218         };
    219 
    220         // default volume curve
    221         static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    222         // default volume curve for media strategy
    223         static const VolumeCurvePoint sDefaultMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    224         // volume curve for media strategy on speakers
    225         static const VolumeCurvePoint sSpeakerMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    226         // volume curve for sonification strategy on speakers
    227         static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    228         static const VolumeCurvePoint sDefaultSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    229         static const VolumeCurvePoint sHeadsetSystemVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    230         static const VolumeCurvePoint sDefaultVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    231         static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[AudioPolicyManagerBase::VOLCNT];
    232         // default volume curves per stream and device category. See initializeVolumeCurves()
    233         static const VolumeCurvePoint *sVolumeProfiles[AUDIO_STREAM_CNT][DEVICE_CATEGORY_CNT];
    234 
    235         // descriptor for audio outputs. Used to maintain current configuration of each opened audio output
    236         // and keep track of the usage of this output by each audio stream type.
    237         class AudioOutputDescriptor
    238         {
    239         public:
    240             AudioOutputDescriptor(const IOProfile *profile);
    241 
    242             status_t    dump(int fd);
    243 
    244             audio_devices_t device();
    245             void changeRefCount(AudioSystem::stream_type, int delta);
    246             uint32_t refCount();
    247             uint32_t strategyRefCount(routing_strategy strategy);
    248             bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);}
    249             bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
    250             audio_devices_t supportedDevices();
    251             uint32_t latency();
    252             bool sharesHwModuleWith(const AudioOutputDescriptor *outputDesc);
    253 
    254             audio_io_handle_t mId;              // output handle
    255             uint32_t mSamplingRate;             //
    256             audio_format_t mFormat;             //
    257             audio_channel_mask_t mChannelMask;     // output configuration
    258             uint32_t mLatency;                  //
    259             audio_output_flags_t mFlags;   //
    260             audio_devices_t mDevice;                   // current device this output is routed to
    261             uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output
    262             nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES];
    263             AudioOutputDescriptor *mOutput1;    // used by duplicated outputs: first output
    264             AudioOutputDescriptor *mOutput2;    // used by duplicated outputs: second output
    265             float mCurVolume[AudioSystem::NUM_STREAM_TYPES];   // current stream volume
    266             int mMuteCount[AudioSystem::NUM_STREAM_TYPES];     // mute request counter
    267             const IOProfile *mProfile;          // I/O profile this output derives from
    268             bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
    269                                                 // device selection. See checkDeviceMuteStrategies()
    270         };
    271 
    272         // descriptor for audio inputs. Used to maintain current configuration of each opened audio input
    273         // and keep track of the usage of this input.
    274         class AudioInputDescriptor
    275         {
    276         public:
    277             AudioInputDescriptor(const IOProfile *profile);
    278 
    279             status_t    dump(int fd);
    280 
    281             uint32_t mSamplingRate;                     //
    282             audio_format_t mFormat;                     // input configuration
    283             audio_channel_mask_t mChannelMask;             //
    284             audio_devices_t mDevice;                    // current device this input is routed to
    285             uint32_t mRefCount;                         // number of AudioRecord clients using this output
    286             int      mInputSource;                      // input source selected by application (mediarecorder.h)
    287             const IOProfile *mProfile;                  // I/O profile this output derives from
    288         };
    289 
    290         // stream descriptor used for volume control
    291         class StreamDescriptor
    292         {
    293         public:
    294             StreamDescriptor();
    295 
    296             int getVolumeIndex(audio_devices_t device);
    297             void dump(int fd);
    298 
    299             int mIndexMin;      // min volume index
    300             int mIndexMax;      // max volume index
    301             KeyedVector<audio_devices_t, int> mIndexCur;   // current volume index per device
    302             bool mCanBeMuted;   // true is the stream can be muted
    303 
    304             const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT];
    305         };
    306 
    307         // stream descriptor used for volume control
    308         class EffectDescriptor
    309         {
    310         public:
    311 
    312             status_t dump(int fd);
    313 
    314             int mIo;                // io the effect is attached to
    315             routing_strategy mStrategy; // routing strategy the effect is associated to
    316             int mSession;               // audio session the effect is on
    317             effect_descriptor_t mDesc;  // effect descriptor
    318             bool mEnabled;              // enabled state: CPU load being used or not
    319         };
    320 
    321         void addOutput(audio_io_handle_t id, AudioOutputDescriptor *outputDesc);
    322 
    323         // return the strategy corresponding to a given stream type
    324         static routing_strategy getStrategy(AudioSystem::stream_type stream);
    325 
    326         // return appropriate device for streams handled by the specified strategy according to current
    327         // phone state, connected devices...
    328         // if fromCache is true, the device is returned from mDeviceForStrategy[],
    329         // otherwise it is determine by current state
    330         // (device connected,phone state, force use, a2dp output...)
    331         // This allows to:
    332         //  1 speed up process when the state is stable (when starting or stopping an output)
    333         //  2 access to either current device selection (fromCache == true) or
    334         // "future" device selection (fromCache == false) when called from a context
    335         //  where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
    336         //  before updateDevicesAndOutputs() is called.
    337         virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
    338                                                      bool fromCache);
    339 
    340         // change the route of the specified output. Returns the number of ms we have slept to
    341         // allow new routing to take effect in certain cases.
    342         uint32_t setOutputDevice(audio_io_handle_t output,
    343                              audio_devices_t device,
    344                              bool force = false,
    345                              int delayMs = 0);
    346 
    347         // select input device corresponding to requested audio source
    348         virtual audio_devices_t getDeviceForInputSource(int inputSource);
    349 
    350         // return io handle of active input or 0 if no input is active
    351         //    Only considers inputs from physical devices (e.g. main mic, headset mic) when
    352         //    ignoreVirtualInputs is true.
    353         audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true);
    354 
    355         // initialize volume curves for each strategy and device category
    356         void initializeVolumeCurves();
    357 
    358         // compute the actual volume for a given stream according to the requested index and a particular
    359         // device
    360         virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device);
    361 
    362         // check that volume change is permitted, compute and send new volume to audio hardware
    363         status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
    364 
    365         // apply all stream volumes to the specified output and device
    366         void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
    367 
    368         // Mute or unmute all streams handled by the specified strategy on the specified output
    369         void setStrategyMute(routing_strategy strategy,
    370                              bool on,
    371                              audio_io_handle_t output,
    372                              int delayMs = 0,
    373                              audio_devices_t device = (audio_devices_t)0);
    374 
    375         // Mute or unmute the stream on the specified output
    376         void setStreamMute(int stream,
    377                            bool on,
    378                            audio_io_handle_t output,
    379                            int delayMs = 0,
    380                            audio_devices_t device = (audio_devices_t)0);
    381 
    382         // handle special cases for sonification strategy while in call: mute streams or replace by
    383         // a special tone in the device used for communication
    384         void handleIncallSonification(int stream, bool starting, bool stateChange);
    385 
    386         // true if device is in a telephony or VoIP call
    387         virtual bool isInCall();
    388 
    389         // true if given state represents a device in a telephony or VoIP call
    390         virtual bool isStateInCall(int state);
    391 
    392         // when a device is connected, checks if an open output can be routed
    393         // to this device. If none is open, tries to open one of the available outputs.
    394         // Returns an output suitable to this device or 0.
    395         // when a device is disconnected, checks if an output is not used any more and
    396         // returns its handle if any.
    397         // transfers the audio tracks and effects from one output thread to another accordingly.
    398         status_t checkOutputsForDevice(audio_devices_t device,
    399                                        AudioSystem::device_connection_state state,
    400                                        SortedVector<audio_io_handle_t>& outputs);
    401 
    402         // close an output and its companion duplicating output.
    403         void closeOutput(audio_io_handle_t output);
    404 
    405         // checks and if necessary changes outputs used for all strategies.
    406         // must be called every time a condition that affects the output choice for a given strategy
    407         // changes: connected device, phone state, force use...
    408         // Must be called before updateDevicesAndOutputs()
    409         void checkOutputForStrategy(routing_strategy strategy);
    410 
    411         // Same as checkOutputForStrategy() but for a all strategies in order of priority
    412         void checkOutputForAllStrategies();
    413 
    414         // manages A2DP output suspend/restore according to phone state and BT SCO usage
    415         void checkA2dpSuspend();
    416 
    417         // returns the A2DP output handle if it is open or 0 otherwise
    418         audio_io_handle_t getA2dpOutput();
    419 
    420         // selects the most appropriate device on output for current state
    421         // must be called every time a condition that affects the device choice for a given output is
    422         // changed: connected device, phone state, force use, output start, output stop..
    423         // see getDeviceForStrategy() for the use of fromCache parameter
    424 
    425         audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache);
    426         // updates cache of device used by all strategies (mDeviceForStrategy[])
    427         // must be called every time a condition that affects the device choice for a given strategy is
    428         // changed: connected device, phone state, force use...
    429         // cached values are used by getDeviceForStrategy() if parameter fromCache is true.
    430          // Must be called after checkOutputForAllStrategies()
    431 
    432         void updateDevicesAndOutputs();
    433 
    434         // true if current platform requires a specific output to be opened for this particular
    435         // set of parameters. This function is called by getOutput() and is implemented by platform
    436         // specific audio policy manager.
    437         virtual bool needsDirectOuput(audio_stream_type_t stream,
    438                                       uint32_t samplingRate,
    439                                       audio_format_t format,
    440                                       audio_channel_mask_t channelMask,
    441                                       audio_output_flags_t flags,
    442                                       audio_devices_t device);
    443 
    444         virtual uint32_t getMaxEffectsCpuLoad();
    445         virtual uint32_t getMaxEffectsMemory();
    446 #ifdef AUDIO_POLICY_TEST
    447         virtual     bool        threadLoop();
    448                     void        exit();
    449         int testOutputIndex(audio_io_handle_t output);
    450 #endif //AUDIO_POLICY_TEST
    451 
    452         status_t setEffectEnabled(EffectDescriptor *pDesc, bool enabled);
    453 
    454         // returns the category the device belongs to with regard to volume curve management
    455         static device_category getDeviceCategory(audio_devices_t device);
    456 
    457         // extract one device relevant for volume control from multiple device selection
    458         static audio_devices_t getDeviceForVolume(audio_devices_t device);
    459 
    460         SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device,
    461                         DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> openOutputs);
    462         bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
    463                                            SortedVector<audio_io_handle_t>& outputs2);
    464 
    465         // mute/unmute strategies using an incompatible device combination
    466         // if muting, wait for the audio in pcm buffer to be drained before proceeding
    467         // if unmuting, unmute only after the specified delay
    468         // Returns the number of ms waited
    469         uint32_t  checkDeviceMuteStrategies(AudioOutputDescriptor *outputDesc,
    470                                             audio_devices_t prevDevice,
    471                                             uint32_t delayMs);
    472 
    473         audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs,
    474                                        AudioSystem::output_flags flags);
    475         IOProfile *getInputProfile(audio_devices_t device,
    476                                    uint32_t samplingRate,
    477                                    uint32_t format,
    478                                    uint32_t channelMask);
    479         IOProfile *getProfileForDirectOutput(audio_devices_t device,
    480                                                        uint32_t samplingRate,
    481                                                        uint32_t format,
    482                                                        uint32_t channelMask,
    483                                                        audio_output_flags_t flags);
    484         //
    485         // Audio policy configuration file parsing (audio_policy.conf)
    486         //
    487         static uint32_t stringToEnum(const struct StringToEnum *table,
    488                                      size_t size,
    489                                      const char *name);
    490         static audio_output_flags_t parseFlagNames(char *name);
    491         static audio_devices_t parseDeviceNames(char *name);
    492         void loadSamplingRates(char *name, IOProfile *profile);
    493         void loadFormats(char *name, IOProfile *profile);
    494         void loadOutChannels(char *name, IOProfile *profile);
    495         void loadInChannels(char *name, IOProfile *profile);
    496         status_t loadOutput(cnode *root,  HwModule *module);
    497         status_t loadInput(cnode *root,  HwModule *module);
    498         void loadHwModule(cnode *root);
    499         void loadHwModules(cnode *root);
    500         void loadGlobalConfig(cnode *root);
    501         status_t loadAudioPolicyConfig(const char *path);
    502         void defaultAudioPolicyConfig(void);
    503 
    504 
    505         AudioPolicyClientInterface *mpClientInterface;  // audio policy client interface
    506         audio_io_handle_t mPrimaryOutput;              // primary output handle
    507         // list of descriptors for outputs currently opened
    508         DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs;
    509         // copy of mOutputs before setDeviceConnectionState() opens new outputs
    510         // reset to mOutputs when updateDevicesAndOutputs() is called.
    511         DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mPreviousOutputs;
    512         DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs;     // list of input descriptors
    513         audio_devices_t mAvailableOutputDevices; // bit field of all available output devices
    514         audio_devices_t mAvailableInputDevices; // bit field of all available input devices
    515                                                 // without AUDIO_DEVICE_BIT_IN to allow direct bit
    516                                                 // field comparisons
    517         int mPhoneState;                                                    // current phone state
    518         AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE];   // current forced use configuration
    519 
    520         StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES];           // stream descriptors for volume control
    521         String8 mA2dpDeviceAddress;                                         // A2DP device MAC address
    522         String8 mScoDeviceAddress;                                          // SCO device MAC address
    523         String8 mUsbCardAndDevice; // USB audio ALSA card and device numbers:
    524                                    // card=<card_number>;device=<><device_number>
    525         bool    mLimitRingtoneVolume;                                       // limit ringtone volume to music volume if headset connected
    526         audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
    527         float   mLastVoiceVolume;                                           // last voice volume value sent to audio HAL
    528 
    529         // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units
    530         static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000;
    531         // Maximum memory allocated to audio effects in KB
    532         static const uint32_t MAX_EFFECTS_MEMORY = 512;
    533         uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects
    534         uint32_t mTotalEffectsMemory;  // current memory used by effects
    535         KeyedVector<int, EffectDescriptor *> mEffects;  // list of registered audio effects
    536         bool    mA2dpSuspended;  // true if A2DP output is suspended
    537         bool mHasA2dp; // true on platforms with support for bluetooth A2DP
    538         bool mHasUsb; // true on platforms with support for USB audio
    539         bool mHasRemoteSubmix; // true on platforms with support for remote presentation of a submix
    540         audio_devices_t mAttachedOutputDevices; // output devices always available on the platform
    541         audio_devices_t mDefaultOutputDevice; // output device selected by default at boot time
    542                                               // (must be in mAttachedOutputDevices)
    543 
    544         Vector <HwModule *> mHwModules;
    545 
    546 #ifdef AUDIO_POLICY_TEST
    547         Mutex   mLock;
    548         Condition mWaitWorkCV;
    549 
    550         int             mCurOutput;
    551         bool            mDirectOutput;
    552         audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS];
    553         int             mTestInput;
    554         uint32_t        mTestDevice;
    555         uint32_t        mTestSamplingRate;
    556         uint32_t        mTestFormat;
    557         uint32_t        mTestChannels;
    558         uint32_t        mTestLatencyMs;
    559 #endif //AUDIO_POLICY_TEST
    560 
    561 private:
    562         static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
    563                 int indexInUi);
    564         // updates device caching and output for streams that can influence the
    565         //    routing of notifications
    566         void handleNotificationRoutingForStream(AudioSystem::stream_type stream);
    567         static bool isVirtualInputDevice(audio_devices_t device);
    568 };
    569 
    570 };
    571