AudioPolicyManagerBase.h revision 739022f26a7127ba76a98dda65411496086114a7
1de55cfb02db874136caf9c05927cee4028296147Eric Laurent/* 2de55cfb02db874136caf9c05927cee4028296147Eric Laurent * Copyright (C) 2009 The Android Open Source Project 3de55cfb02db874136caf9c05927cee4028296147Eric Laurent * 4de55cfb02db874136caf9c05927cee4028296147Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 5de55cfb02db874136caf9c05927cee4028296147Eric Laurent * you may not use this file except in compliance with the License. 6de55cfb02db874136caf9c05927cee4028296147Eric Laurent * You may obtain a copy of the License at 7de55cfb02db874136caf9c05927cee4028296147Eric Laurent * 8de55cfb02db874136caf9c05927cee4028296147Eric Laurent * http://www.apache.org/licenses/LICENSE-2.0 9de55cfb02db874136caf9c05927cee4028296147Eric Laurent * 10de55cfb02db874136caf9c05927cee4028296147Eric Laurent * Unless required by applicable law or agreed to in writing, software 11de55cfb02db874136caf9c05927cee4028296147Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 12de55cfb02db874136caf9c05927cee4028296147Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13de55cfb02db874136caf9c05927cee4028296147Eric Laurent * See the License for the specific language governing permissions and 14de55cfb02db874136caf9c05927cee4028296147Eric Laurent * limitations under the License. 15de55cfb02db874136caf9c05927cee4028296147Eric Laurent */ 16de55cfb02db874136caf9c05927cee4028296147Eric Laurent 17de55cfb02db874136caf9c05927cee4028296147Eric Laurent 18de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <stdint.h> 19de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <sys/types.h> 205ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent#include <cutils/config_utils.h> 215ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent#include <cutils/misc.h> 22de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <utils/Timers.h> 23de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <utils/Errors.h> 24de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <utils/KeyedVector.h> 25b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent#include <utils/SortedVector.h> 26de55cfb02db874136caf9c05927cee4028296147Eric Laurent#include <hardware_legacy/AudioPolicyInterface.h> 27de55cfb02db874136caf9c05927cee4028296147Eric Laurent 28de55cfb02db874136caf9c05927cee4028296147Eric Laurent 29e81531e91ecae92aff471dbff9cbeb0f95ff4a80Dima Zavinnamespace android_audio_legacy { 30e81531e91ecae92aff471dbff9cbeb0f95ff4a80Dima Zavin using android::KeyedVector; 31b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent using android::DefaultKeyedVector; 32b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent using android::SortedVector; 33de55cfb02db874136caf9c05927cee4028296147Eric Laurent 34de55cfb02db874136caf9c05927cee4028296147Eric Laurent// ---------------------------------------------------------------------------- 35de55cfb02db874136caf9c05927cee4028296147Eric Laurent 36de55cfb02db874136caf9c05927cee4028296147Eric Laurent#define MAX_DEVICE_ADDRESS_LEN 20 37de55cfb02db874136caf9c05927cee4028296147Eric Laurent// Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB 38de55cfb02db874136caf9c05927cee4028296147Eric Laurent#define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5 39de55cfb02db874136caf9c05927cee4028296147Eric Laurent// Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB 40de55cfb02db874136caf9c05927cee4028296147Eric Laurent#define SONIFICATION_HEADSET_VOLUME_MIN 0.016 4136291a74cd212c4172ac054ad0eec686b7e15c96Eric Laurent// Time in milliseconds during which we consider that music is still active after a music 42de55cfb02db874136caf9c05927cee4028296147Eric Laurent// track was stopped - see computeVolume() 4336291a74cd212c4172ac054ad0eec686b7e15c96Eric Laurent#define SONIFICATION_HEADSET_MUSIC_DELAY 5000 4412bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi// Time in milliseconds after media stopped playing during which we consider that the 4512bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi// sonification should be as unobtrusive as during the time media was playing. 4612bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi#define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000 47195368626339aefc4732661d009e8de1aacc24d1Eric Laurent// Time in milliseconds during witch some streams are muted while the audio path 48195368626339aefc4732661d009e8de1aacc24d1Eric Laurent// is switched 49195368626339aefc4732661d009e8de1aacc24d1Eric Laurent#define MUTE_TIME_MS 2000 50de55cfb02db874136caf9c05927cee4028296147Eric Laurent 51de55cfb02db874136caf9c05927cee4028296147Eric Laurent#define NUM_TEST_OUTPUTS 5 52de55cfb02db874136caf9c05927cee4028296147Eric Laurent 53f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Trivi#define NUM_VOL_CURVE_KNEES 2 54f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Trivi 55de55cfb02db874136caf9c05927cee4028296147Eric Laurent// ---------------------------------------------------------------------------- 56de55cfb02db874136caf9c05927cee4028296147Eric Laurent// AudioPolicyManagerBase implements audio policy manager behavior common to all platforms. 57de55cfb02db874136caf9c05927cee4028296147Eric Laurent// Each platform must implement an AudioPolicyManager class derived from AudioPolicyManagerBase 58d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent// and override methods for which the platform specific behavior differs from the implementation 59de55cfb02db874136caf9c05927cee4028296147Eric Laurent// in AudioPolicyManagerBase. Even if no specific behavior is required, the AudioPolicyManager 60de55cfb02db874136caf9c05927cee4028296147Eric Laurent// class must be implemented as well as the class factory function createAudioPolicyManager() 61de55cfb02db874136caf9c05927cee4028296147Eric Laurent// and provided in a shared library libaudiopolicy.so. 62de55cfb02db874136caf9c05927cee4028296147Eric Laurent// ---------------------------------------------------------------------------- 63de55cfb02db874136caf9c05927cee4028296147Eric Laurent 64de55cfb02db874136caf9c05927cee4028296147Eric Laurentclass AudioPolicyManagerBase: public AudioPolicyInterface 65de55cfb02db874136caf9c05927cee4028296147Eric Laurent#ifdef AUDIO_POLICY_TEST 66de55cfb02db874136caf9c05927cee4028296147Eric Laurent , public Thread 67de55cfb02db874136caf9c05927cee4028296147Eric Laurent#endif //AUDIO_POLICY_TEST 68de55cfb02db874136caf9c05927cee4028296147Eric Laurent{ 69de55cfb02db874136caf9c05927cee4028296147Eric Laurent 70de55cfb02db874136caf9c05927cee4028296147Eric Laurentpublic: 71de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioPolicyManagerBase(AudioPolicyClientInterface *clientInterface); 72de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual ~AudioPolicyManagerBase(); 73de55cfb02db874136caf9c05927cee4028296147Eric Laurent 74de55cfb02db874136caf9c05927cee4028296147Eric Laurent // AudioPolicyInterface 75de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device, 76de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioSystem::device_connection_state state, 77de55cfb02db874136caf9c05927cee4028296147Eric Laurent const char *device_address); 78de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual AudioSystem::device_connection_state getDeviceConnectionState(AudioSystem::audio_devices device, 79de55cfb02db874136caf9c05927cee4028296147Eric Laurent const char *device_address); 80de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void setPhoneState(int state); 81de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config); 82de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual AudioSystem::forced_config getForceUse(AudioSystem::force_use usage); 83de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void setSystemProperty(const char* property, const char* value); 8461f357948648ff45d35ec79725db4e1b12c268dcEric Laurent virtual status_t initCheck(); 85de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream, 86d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t samplingRate = 0, 87d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t format = AudioSystem::FORMAT_DEFAULT, 88d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t channels = 0, 89d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent AudioSystem::output_flags flags = 90d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent AudioSystem::OUTPUT_FLAG_INDIRECT); 91d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual status_t startOutput(audio_io_handle_t output, 92d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent AudioSystem::stream_type stream, 93d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent int session = 0); 94d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual status_t stopOutput(audio_io_handle_t output, 95d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent AudioSystem::stream_type stream, 96d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent int session = 0); 97de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void releaseOutput(audio_io_handle_t output); 98de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual audio_io_handle_t getInput(int inputSource, 99de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t samplingRate, 100de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t format, 101de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t channels, 102de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioSystem::audio_in_acoustics acoustics); 103f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 104de55cfb02db874136caf9c05927cee4028296147Eric Laurent // indicates to the audio policy manager that the input starts being used. 105de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual status_t startInput(audio_io_handle_t input); 106f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 107de55cfb02db874136caf9c05927cee4028296147Eric Laurent // indicates to the audio policy manager that the input stops being used. 108de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual status_t stopInput(audio_io_handle_t input); 109de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void releaseInput(audio_io_handle_t input); 110de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual void initStreamVolume(AudioSystem::stream_type stream, 111de55cfb02db874136caf9c05927cee4028296147Eric Laurent int indexMin, 112de55cfb02db874136caf9c05927cee4028296147Eric Laurent int indexMax); 113c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent virtual status_t setStreamVolumeIndex(AudioSystem::stream_type stream, 114c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent int index, 115c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent audio_devices_t device); 116c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent virtual status_t getStreamVolumeIndex(AudioSystem::stream_type stream, 117c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent int *index, 118c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent audio_devices_t device); 119de55cfb02db874136caf9c05927cee4028296147Eric Laurent 120d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent // return the strategy corresponding to a given stream type 121d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual uint32_t getStrategyForStream(AudioSystem::stream_type stream); 122d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 123fafb18fb31cc4ab3c73585ba508f7643c9a9e3adGlenn Kasten // return the enabled output devices for the given stream type 124f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent virtual audio_devices_t getDevicesForStream(AudioSystem::stream_type stream); 125fafb18fb31cc4ab3c73585ba508f7643c9a9e3adGlenn Kasten 126d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc); 127d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual status_t registerEffect(effect_descriptor_t *desc, 1281c65a49da0c89f75e528354ef02de5dc93a28232Eric Laurent audio_io_handle_t io, 129d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t strategy, 130d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent int session, 131d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent int id); 132d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual status_t unregisterEffect(int id); 133582a15744be109fb630db7dbd1d1bdf22ff44f12Eric Laurent virtual status_t setEffectEnabled(int id, bool enabled); 134d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 13536291a74cd212c4172ac054ad0eec686b7e15c96Eric Laurent virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const; 13636291a74cd212c4172ac054ad0eec686b7e15c96Eric Laurent 137de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual status_t dump(int fd); 138de55cfb02db874136caf9c05927cee4028296147Eric Laurent 139de55cfb02db874136caf9c05927cee4028296147Eric Laurentprotected: 140de55cfb02db874136caf9c05927cee4028296147Eric Laurent 141de55cfb02db874136caf9c05927cee4028296147Eric Laurent enum routing_strategy { 142de55cfb02db874136caf9c05927cee4028296147Eric Laurent STRATEGY_MEDIA, 143de55cfb02db874136caf9c05927cee4028296147Eric Laurent STRATEGY_PHONE, 144de55cfb02db874136caf9c05927cee4028296147Eric Laurent STRATEGY_SONIFICATION, 14512bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi STRATEGY_SONIFICATION_RESPECTFUL, 146de55cfb02db874136caf9c05927cee4028296147Eric Laurent STRATEGY_DTMF, 147c16ac09f510437e8340be691720177a490ae78f0Eric Laurent STRATEGY_ENFORCED_AUDIBLE, 148de55cfb02db874136caf9c05927cee4028296147Eric Laurent NUM_STRATEGIES 149de55cfb02db874136caf9c05927cee4028296147Eric Laurent }; 150de55cfb02db874136caf9c05927cee4028296147Eric Laurent 151cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent // 4 points to define the volume attenuation curve, each characterized by the volume 152cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent // index (from 0 to 100) at which they apply, and the attenuation in dB at that index. 153cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent // we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl() 154cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent 155cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent enum { VOLMIN = 0, VOLKNEE1 = 1, VOLKNEE2 = 2, VOLMAX = 3, VOLCNT = 4}; 156cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent 157cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent class VolumeCurvePoint 158cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent { 159cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent public: 160cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent int mIndex; 161cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent float mDBAttenuation; 162cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent }; 163cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent 164e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // device categories used for volume curve management. 165e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent enum device_category { 166e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent DEVICE_CATEGORY_HEADSET, 167e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent DEVICE_CATEGORY_SPEAKER, 168e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent DEVICE_CATEGORY_EARPIECE, 169e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent DEVICE_CATEGORY_CNT 170e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent }; 171e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent 17270c236c9290732782d5267935af1475b8d5ae602Eric Laurent class IOProfile; 17370c236c9290732782d5267935af1475b8d5ae602Eric Laurent 17470c236c9290732782d5267935af1475b8d5ae602Eric Laurent class HwModule { 17570c236c9290732782d5267935af1475b8d5ae602Eric Laurent public: 17670c236c9290732782d5267935af1475b8d5ae602Eric Laurent HwModule(const char *name); 17770c236c9290732782d5267935af1475b8d5ae602Eric Laurent ~HwModule(); 17870c236c9290732782d5267935af1475b8d5ae602Eric Laurent 17970c236c9290732782d5267935af1475b8d5ae602Eric Laurent void dump(int fd); 18070c236c9290732782d5267935af1475b8d5ae602Eric Laurent 18170c236c9290732782d5267935af1475b8d5ae602Eric Laurent const char *const mName; // base name of the audio HW module (primary, a2dp ...) 18270c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_module_handle_t mHandle; 18370c236c9290732782d5267935af1475b8d5ae602Eric Laurent Vector <IOProfile *> mOutputProfiles; // output profiles exposed by this module 18470c236c9290732782d5267935af1475b8d5ae602Eric Laurent Vector <IOProfile *> mInputProfiles; // input profiles exposed by this module 18570c236c9290732782d5267935af1475b8d5ae602Eric Laurent }; 18670c236c9290732782d5267935af1475b8d5ae602Eric Laurent 1875ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // the IOProfile class describes the capabilities of an output or input stream. 1885ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // It is currently assumed that all combination of listed parameters are supported. 1895ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // It is used by the policy manager to determine if an output or input is suitable for 1905ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // a given use case, open/close it accordingly and connect/disconnect audio tracks 1915ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // to/from it. 1925ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent class IOProfile 1935ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent { 19470c236c9290732782d5267935af1475b8d5ae602Eric Laurent public: 19570c236c9290732782d5267935af1475b8d5ae602Eric Laurent IOProfile(HwModule *module); 1965ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent ~IOProfile(); 1975ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 19870c236c9290732782d5267935af1475b8d5ae602Eric Laurent bool isCompatibleProfile(audio_devices_t device, 19970c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t samplingRate, 20070c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t format, 20170c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t channelMask, 2020977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent audio_output_flags_t flags) const; 20370c236c9290732782d5267935af1475b8d5ae602Eric Laurent 2045ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void dump(int fd); 2055ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 2065ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent Vector <uint32_t> mSamplingRates; // supported sampling rates 2075ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks 2085ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent Vector <audio_format_t> mFormats; // supported audio formats 2095ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t mSupportedDevices; // supported devices (devices this output can be 2105ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // routed to) 2110977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent audio_output_flags_t mFlags; // attribute flags (e.g primary output, 2125ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // direct output...). For outputs only. 21370c236c9290732782d5267935af1475b8d5ae602Eric Laurent HwModule *mModule; // audio HW module exposing this I/O stream 2145ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent }; 2155ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 216e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // default volume curve 217e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManagerBase::VOLCNT]; 218e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // default volume curve for media strategy 219e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent static const VolumeCurvePoint sDefaultMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT]; 220e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // volume curve for media strategy on speakers 221e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent static const VolumeCurvePoint sSpeakerMediaVolumeCurve[AudioPolicyManagerBase::VOLCNT]; 222e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // volume curve for sonification strategy on speakers 223e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[AudioPolicyManagerBase::VOLCNT]; 224e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // default volume curves per strategy and device category. See initializeVolumeCurves() 225e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent static const VolumeCurvePoint *sVolumeProfiles[NUM_STRATEGIES][DEVICE_CATEGORY_CNT]; 226cd057ad2774903c62f5c11bc71c4e7357aee71b8Eric Laurent 227de55cfb02db874136caf9c05927cee4028296147Eric Laurent // descriptor for audio outputs. Used to maintain current configuration of each opened audio output 228de55cfb02db874136caf9c05927cee4028296147Eric Laurent // and keep track of the usage of this output by each audio stream type. 229de55cfb02db874136caf9c05927cee4028296147Eric Laurent class AudioOutputDescriptor 230de55cfb02db874136caf9c05927cee4028296147Eric Laurent { 231de55cfb02db874136caf9c05927cee4028296147Eric Laurent public: 2325ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent AudioOutputDescriptor(const IOProfile *profile); 233de55cfb02db874136caf9c05927cee4028296147Eric Laurent 234de55cfb02db874136caf9c05927cee4028296147Eric Laurent status_t dump(int fd); 235de55cfb02db874136caf9c05927cee4028296147Eric Laurent 236f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t device(); 237de55cfb02db874136caf9c05927cee4028296147Eric Laurent void changeRefCount(AudioSystem::stream_type, int delta); 238de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t refCount(); 239de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t strategyRefCount(routing_strategy strategy); 240de55cfb02db874136caf9c05927cee4028296147Eric Laurent bool isUsedByStrategy(routing_strategy strategy) { return (strategyRefCount(strategy) != 0);} 2415ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); } 242f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t supportedDevices(); 2435ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent uint32_t latency(); 2445ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent bool sharesHwModuleWith(const AudioOutputDescriptor *outputDesc); 245de55cfb02db874136caf9c05927cee4028296147Eric Laurent 246de55cfb02db874136caf9c05927cee4028296147Eric Laurent audio_io_handle_t mId; // output handle 247de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mSamplingRate; // 24870c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_format_t mFormat; // 24970c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_channel_mask_t mChannelMask; // output configuration 250de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mLatency; // 2510977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent audio_output_flags_t mFlags; // 252f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t mDevice; // current device this output is routed to 253de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mRefCount[AudioSystem::NUM_STREAM_TYPES]; // number of streams of each type using this output 25436291a74cd212c4172ac054ad0eec686b7e15c96Eric Laurent nsecs_t mStopTime[AudioSystem::NUM_STREAM_TYPES]; 255de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioOutputDescriptor *mOutput1; // used by duplicated outputs: first output 256de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioOutputDescriptor *mOutput2; // used by duplicated outputs: second output 257de55cfb02db874136caf9c05927cee4028296147Eric Laurent float mCurVolume[AudioSystem::NUM_STREAM_TYPES]; // current stream volume 258de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mMuteCount[AudioSystem::NUM_STREAM_TYPES]; // mute request counter 2595ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent const IOProfile *mProfile; // I/O profile this output derives from 2605ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible 2615ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // device selection. See checkDeviceMuteStrategies() 262de55cfb02db874136caf9c05927cee4028296147Eric Laurent }; 263de55cfb02db874136caf9c05927cee4028296147Eric Laurent 264de55cfb02db874136caf9c05927cee4028296147Eric Laurent // descriptor for audio inputs. Used to maintain current configuration of each opened audio input 265de55cfb02db874136caf9c05927cee4028296147Eric Laurent // and keep track of the usage of this input. 266de55cfb02db874136caf9c05927cee4028296147Eric Laurent class AudioInputDescriptor 267de55cfb02db874136caf9c05927cee4028296147Eric Laurent { 268de55cfb02db874136caf9c05927cee4028296147Eric Laurent public: 2695ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent AudioInputDescriptor(const IOProfile *profile); 270de55cfb02db874136caf9c05927cee4028296147Eric Laurent 271de55cfb02db874136caf9c05927cee4028296147Eric Laurent status_t dump(int fd); 272de55cfb02db874136caf9c05927cee4028296147Eric Laurent 273de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mSamplingRate; // 27470c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_format_t mFormat; // input configuration 27570c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_channel_mask_t mChannelMask; // 276f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t mDevice; // current device this input is routed to 277de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mRefCount; // number of AudioRecord clients using this output 278f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent int mInputSource; // input source selected by application (mediarecorder.h) 2795ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent const IOProfile *mProfile; // I/O profile this output derives from 280de55cfb02db874136caf9c05927cee4028296147Eric Laurent }; 281de55cfb02db874136caf9c05927cee4028296147Eric Laurent 282de55cfb02db874136caf9c05927cee4028296147Eric Laurent // stream descriptor used for volume control 283de55cfb02db874136caf9c05927cee4028296147Eric Laurent class StreamDescriptor 284de55cfb02db874136caf9c05927cee4028296147Eric Laurent { 285de55cfb02db874136caf9c05927cee4028296147Eric Laurent public: 286c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent StreamDescriptor(); 287de55cfb02db874136caf9c05927cee4028296147Eric Laurent 288c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent int getVolumeIndex(audio_devices_t device); 289c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent void dump(int fd); 290de55cfb02db874136caf9c05927cee4028296147Eric Laurent 291de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mIndexMin; // min volume index 292de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mIndexMax; // max volume index 293c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent KeyedVector<audio_devices_t, int> mIndexCur; // current volume index per device 294de55cfb02db874136caf9c05927cee4028296147Eric Laurent bool mCanBeMuted; // true is the stream can be muted 295f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Trivi 296e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT]; 297de55cfb02db874136caf9c05927cee4028296147Eric Laurent }; 298de55cfb02db874136caf9c05927cee4028296147Eric Laurent 299d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent // stream descriptor used for volume control 300d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent class EffectDescriptor 301d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent { 302d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent public: 303d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 304d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent status_t dump(int fd); 305d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 3061c65a49da0c89f75e528354ef02de5dc93a28232Eric Laurent int mIo; // io the effect is attached to 307d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent routing_strategy mStrategy; // routing strategy the effect is associated to 308d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent int mSession; // audio session the effect is on 309d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent effect_descriptor_t mDesc; // effect descriptor 310582a15744be109fb630db7dbd1d1bdf22ff44f12Eric Laurent bool mEnabled; // enabled state: CPU load being used or not 311d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent }; 312d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 313de55cfb02db874136caf9c05927cee4028296147Eric Laurent void addOutput(audio_io_handle_t id, AudioOutputDescriptor *outputDesc); 314de55cfb02db874136caf9c05927cee4028296147Eric Laurent 315de55cfb02db874136caf9c05927cee4028296147Eric Laurent // return the strategy corresponding to a given stream type 316de55cfb02db874136caf9c05927cee4028296147Eric Laurent static routing_strategy getStrategy(AudioSystem::stream_type stream); 317f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 318de55cfb02db874136caf9c05927cee4028296147Eric Laurent // return appropriate device for streams handled by the specified strategy according to current 319de55cfb02db874136caf9c05927cee4028296147Eric Laurent // phone state, connected devices... 3205ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // if fromCache is true, the device is returned from mDeviceForStrategy[], 3215ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // otherwise it is determine by current state 3225ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // (device connected,phone state, force use, a2dp output...) 323de55cfb02db874136caf9c05927cee4028296147Eric Laurent // This allows to: 324de55cfb02db874136caf9c05927cee4028296147Eric Laurent // 1 speed up process when the state is stable (when starting or stopping an output) 325de55cfb02db874136caf9c05927cee4028296147Eric Laurent // 2 access to either current device selection (fromCache == true) or 326de55cfb02db874136caf9c05927cee4028296147Eric Laurent // "future" device selection (fromCache == false) when called from a context 327de55cfb02db874136caf9c05927cee4028296147Eric Laurent // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND 328de55cfb02db874136caf9c05927cee4028296147Eric Laurent // before updateDeviceForStrategy() is called. 3295ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, 3305ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent bool fromCache); 331f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 332b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // change the route of the specified output. Returns the number of ms we have slept to 333b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // allow new routing to take effect in certain cases. 334b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent uint32_t setOutputDevice(audio_io_handle_t output, 335f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t device, 336f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent bool force = false, 337f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent int delayMs = 0); 338f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 339de55cfb02db874136caf9c05927cee4028296147Eric Laurent // select input device corresponding to requested audio source 340f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent virtual audio_devices_t getDeviceForInputSource(int inputSource); 341f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 342de55cfb02db874136caf9c05927cee4028296147Eric Laurent // return io handle of active input or 0 if no input is active 343de55cfb02db874136caf9c05927cee4028296147Eric Laurent audio_io_handle_t getActiveInput(); 344f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 345e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // initialize volume curves for each strategy and device category 346e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent void initializeVolumeCurves(); 347f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 348de55cfb02db874136caf9c05927cee4028296147Eric Laurent // compute the actual volume for a given stream according to the requested index and a particular 349de55cfb02db874136caf9c05927cee4028296147Eric Laurent // device 350f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device); 351f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 352de55cfb02db874136caf9c05927cee4028296147Eric Laurent // check that volume change is permitted, compute and send new volume to audio hardware 353f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false); 354f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 355de55cfb02db874136caf9c05927cee4028296147Eric Laurent // apply all stream volumes to the specified output and device 356f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent void applyStreamVolumes(audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false); 357f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 358de55cfb02db874136caf9c05927cee4028296147Eric Laurent // Mute or unmute all streams handled by the specified strategy on the specified output 359de55cfb02db874136caf9c05927cee4028296147Eric Laurent void setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs = 0); 360f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 361de55cfb02db874136caf9c05927cee4028296147Eric Laurent // Mute or unmute the stream on the specified output 362de55cfb02db874136caf9c05927cee4028296147Eric Laurent void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0); 363f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 364de55cfb02db874136caf9c05927cee4028296147Eric Laurent // handle special cases for sonification strategy while in call: mute streams or replace by 365de55cfb02db874136caf9c05927cee4028296147Eric Laurent // a special tone in the device used for communication 366de55cfb02db874136caf9c05927cee4028296147Eric Laurent void handleIncallSonification(int stream, bool starting, bool stateChange); 367f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 3683e480fa067136253ae05faaba77f814f42cd56f0Jean-Michel Trivi // true if device is in a telephony or VoIP call 3693e480fa067136253ae05faaba77f814f42cd56f0Jean-Michel Trivi virtual bool isInCall(); 370f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 3713e480fa067136253ae05faaba77f814f42cd56f0Jean-Michel Trivi // true if given state represents a device in a telephony or VoIP call 3723e480fa067136253ae05faaba77f814f42cd56f0Jean-Michel Trivi virtual bool isStateInCall(int state); 373f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 374b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // when a device is connected, checks if an open output can be routed 375b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // to this device. If none is open, tries to open one of the available outputs. 376b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // Returns an output suitable to this device or 0. 377b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // when a device is disconnected, checks if an output is not used any more and 378b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // returns its handle if any. 379b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // transfers the audio tracks and effects from one output thread to another accordingly. 380f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_io_handle_t checkOutputForDevice(audio_devices_t device, 381b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent AudioSystem::device_connection_state state); 382f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 383b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // close an output and its companion duplicating output. 384b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent void closeOutput(audio_io_handle_t output); 385f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 386b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // checks and if necessary changes outputs used for all strategies. 387b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // must be called every time a condition that affects the output choice for a given strategy 388b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // changes: connected device, phone state, force use... 389de55cfb02db874136caf9c05927cee4028296147Eric Laurent // Must be called before updateDeviceForStrategy() 390d6e68c3ae5677bc6127628d1c700b11c8f0fcdafEric Laurent void checkOutputForStrategy(routing_strategy strategy); 391f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 392de55cfb02db874136caf9c05927cee4028296147Eric Laurent // Same as checkOutputForStrategy() but for a all strategies in order of priority 393d6e68c3ae5677bc6127628d1c700b11c8f0fcdafEric Laurent void checkOutputForAllStrategies(); 394f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 3952f2db765228f110b37a2851d1199d3c72d313c6dEric Laurent // manages A2DP output suspend/restore according to phone state and BT SCO usage 3962f2db765228f110b37a2851d1199d3c72d313c6dEric Laurent void checkA2dpSuspend(); 397f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 398b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent // returns the A2DP output handle if it is open or 0 otherwise 399b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent audio_io_handle_t getA2dpOutput(); 400f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 401de55cfb02db874136caf9c05927cee4028296147Eric Laurent // selects the most appropriate device on output for current state 402de55cfb02db874136caf9c05927cee4028296147Eric Laurent // must be called every time a condition that affects the device choice for a given output is 403de55cfb02db874136caf9c05927cee4028296147Eric Laurent // changed: connected device, phone state, force use, output start, output stop.. 404de55cfb02db874136caf9c05927cee4028296147Eric Laurent // see getDeviceForStrategy() for the use of fromCache parameter 405f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 4065ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache); 407de55cfb02db874136caf9c05927cee4028296147Eric Laurent // updates cache of device used by all strategies (mDeviceForStrategy[]) 408de55cfb02db874136caf9c05927cee4028296147Eric Laurent // must be called every time a condition that affects the device choice for a given strategy is 409de55cfb02db874136caf9c05927cee4028296147Eric Laurent // changed: connected device, phone state, force use... 410de55cfb02db874136caf9c05927cee4028296147Eric Laurent // cached values are used by getDeviceForStrategy() if parameter fromCache is true. 411de55cfb02db874136caf9c05927cee4028296147Eric Laurent // Must be called after checkOutputForAllStrategies() 412f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 413de55cfb02db874136caf9c05927cee4028296147Eric Laurent void updateDeviceForStrategy(); 414f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 41568f279fa86145752e424a9cbed1a2e2ee21e10b1Eric Laurent // true if current platform requires a specific output to be opened for this particular 41668f279fa86145752e424a9cbed1a2e2ee21e10b1Eric Laurent // set of parameters. This function is called by getOutput() and is implemented by platform 41768f279fa86145752e424a9cbed1a2e2ee21e10b1Eric Laurent // specific audio policy manager. 41870c236c9290732782d5267935af1475b8d5ae602Eric Laurent virtual bool needsDirectOuput(audio_stream_type_t stream, 41970c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t samplingRate, 42070c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_format_t format, 42170c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_channel_mask_t channelMask, 4220977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent audio_output_flags_t flags, 42370c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_devices_t device); 424f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 425d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual uint32_t getMaxEffectsCpuLoad(); 426d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent virtual uint32_t getMaxEffectsMemory(); 427de55cfb02db874136caf9c05927cee4028296147Eric Laurent#ifdef AUDIO_POLICY_TEST 428de55cfb02db874136caf9c05927cee4028296147Eric Laurent virtual bool threadLoop(); 429de55cfb02db874136caf9c05927cee4028296147Eric Laurent void exit(); 430de55cfb02db874136caf9c05927cee4028296147Eric Laurent int testOutputIndex(audio_io_handle_t output); 431de55cfb02db874136caf9c05927cee4028296147Eric Laurent#endif //AUDIO_POLICY_TEST 432de55cfb02db874136caf9c05927cee4028296147Eric Laurent 433582a15744be109fb630db7dbd1d1bdf22ff44f12Eric Laurent status_t setEffectEnabled(EffectDescriptor *pDesc, bool enabled); 434582a15744be109fb630db7dbd1d1bdf22ff44f12Eric Laurent 435e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent // returns the category the device belongs to with regard to volume curve management 436f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent static device_category getDeviceCategory(audio_devices_t device); 437f7db03562644b03447eb6351156e53188ea0c616Eric Laurent 438c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent // extract one device relevant for volume control from multiple device selection 439c6f331b3f48455c9a9cdf00fc82894badd0a7da6Eric Laurent static audio_devices_t getDeviceForVolume(audio_devices_t device); 440e43c5c4ca4477a6b384711552c3e990609039d93Eric Laurent 441f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device); 442b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1, 443b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent SortedVector<audio_io_handle_t>& outputs2); 444de55cfb02db874136caf9c05927cee4028296147Eric Laurent 445b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // mute/unmute strategies using an incompatible device combination 446b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // if muting, wait for the audio in pcm buffer to be drained before proceeding 447b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // if unmuting, unmute only after the specified delay 448b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent // Returns the number of ms waited 449b2971bf2ae4e9da3155559aa134e3aa6c2b216a4Eric Laurent uint32_t checkDeviceMuteStrategies(AudioOutputDescriptor *outputDesc, 4509029a4fe8abafd383e6fbb1409d1e2f749b51391Eric Laurent audio_devices_t prevDevice, 4519029a4fe8abafd383e6fbb1409d1e2f749b51391Eric Laurent uint32_t delayMs); 4525ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 4535ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_io_handle_t selectOutput(const SortedVector<audio_io_handle_t>& outputs, 4545ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent AudioSystem::output_flags flags); 4555ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent IOProfile *getInputProfile(audio_devices_t device, 4565ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent uint32_t samplingRate, 4575ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent uint32_t format, 4585ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent uint32_t channelMask); 45970c236c9290732782d5267935af1475b8d5ae602Eric Laurent audio_module_handle_t getModuleForDirectoutput(audio_devices_t device, 46070c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t samplingRate, 46170c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t format, 46270c236c9290732782d5267935af1475b8d5ae602Eric Laurent uint32_t channelMask, 4630977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent audio_output_flags_t flags); 4645ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // 4655ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // Audio policy configuration file parsing (audio_policy.conf) 4665ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // 4675ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent static uint32_t stringToEnum(const struct StringToEnum *table, 4685ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent size_t size, 4695ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent const char *name); 4700977cf534ffb71c2abac622716510ae8ea25f3e9Eric Laurent static audio_output_flags_t parseFlagNames(char *name); 4715ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent static audio_devices_t parseDeviceNames(char *name); 4725ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadSamplingRates(char *name, IOProfile *profile); 4735ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadFormats(char *name, IOProfile *profile); 4745ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadOutChannels(char *name, IOProfile *profile); 4755ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadInChannels(char *name, IOProfile *profile); 47670c236c9290732782d5267935af1475b8d5ae602Eric Laurent status_t loadOutput(cnode *root, HwModule *module); 47770c236c9290732782d5267935af1475b8d5ae602Eric Laurent status_t loadInput(cnode *root, HwModule *module); 4785ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadHwModule(cnode *root); 4795ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadHwModules(cnode *root); 4805ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent void loadGlobalConfig(cnode *root); 4815ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent status_t loadAudioPolicyConfig(const char *path); 482739022f26a7127ba76a98dda65411496086114a7Dima Zavin void defaultAudioPolicyConfig(void); 4835ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 4845ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 485b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent AudioPolicyClientInterface *mpClientInterface; // audio policy client interface 486b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent audio_io_handle_t mPrimaryOutput; // primary output handle 487b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mOutputs; // list of output descriptors 488b4696fc22ba822ed37bd2e3a19bc17514ccc79c8Eric Laurent DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs; // list of input descriptors 4895ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t mAvailableOutputDevices; // bit field of all available output devices 4905ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t mAvailableInputDevices; // bit field of all available input devices 491de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mPhoneState; // current phone state 492de55cfb02db874136caf9c05927cee4028296147Eric Laurent AudioSystem::forced_config mForceUse[AudioSystem::NUM_FORCE_USE]; // current forced use configuration 493de55cfb02db874136caf9c05927cee4028296147Eric Laurent 494de55cfb02db874136caf9c05927cee4028296147Eric Laurent StreamDescriptor mStreams[AudioSystem::NUM_STREAM_TYPES]; // stream descriptors for volume control 495de55cfb02db874136caf9c05927cee4028296147Eric Laurent String8 mA2dpDeviceAddress; // A2DP device MAC address 496de55cfb02db874136caf9c05927cee4028296147Eric Laurent String8 mScoDeviceAddress; // SCO device MAC address 497599a1fc11596ac669499c1caf87c6ceddd0bfee4Eric Laurent String8 mUsbCardAndDevice; // USB audio ALSA card and device numbers: 498599a1fc11596ac669499c1caf87c6ceddd0bfee4Eric Laurent // card=<card_number>;device=<><device_number> 499de55cfb02db874136caf9c05927cee4028296147Eric Laurent bool mLimitRingtoneVolume; // limit ringtone volume to music volume if headset connected 500f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent audio_devices_t mDeviceForStrategy[NUM_STRATEGIES]; 501564c30323762685cdb811e2a985ad374a691745eEric Laurent float mLastVoiceVolume; // last voice volume value sent to audio HAL 502de55cfb02db874136caf9c05927cee4028296147Eric Laurent 503d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent // Maximum CPU load allocated to audio effects in 0.1 MIPS (ARMv5TE, 0 WS memory) units 504d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent static const uint32_t MAX_EFFECTS_CPU_LOAD = 1000; 505d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent // Maximum memory allocated to audio effects in KB 506d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent static const uint32_t MAX_EFFECTS_MEMORY = 512; 507d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t mTotalEffectsCpuLoad; // current CPU load used by effects 508d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent uint32_t mTotalEffectsMemory; // current memory used by effects 509d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent KeyedVector<int, EffectDescriptor *> mEffects; // list of registered audio effects 5102f2db765228f110b37a2851d1199d3c72d313c6dEric Laurent bool mA2dpSuspended; // true if A2DP output is suspended 5115ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent bool mHasA2dp; // true on platforms with support for bluetooth A2DP 512599a1fc11596ac669499c1caf87c6ceddd0bfee4Eric Laurent bool mHasUsb; // true on platforms with support for USB audio 5135ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t mAttachedOutputDevices; // output devices always available on the platform 5145ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent audio_devices_t mDefaultOutputDevice; // output device selected by default at boot time 5155ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent // (must be in mAttachedOutputDevices) 5165ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent 51770c236c9290732782d5267935af1475b8d5ae602Eric Laurent Vector <HwModule *> mHwModules; 5185ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent Vector <IOProfile *> mOutputProfiles; // output profiles loaded from audio_policy.conf 5195ccdf14a85ed66ac54036fb393acc06ea7acfed6Eric Laurent Vector <IOProfile *> mInputProfiles; // input profiles loaded from audio_policy.conf 520d2b227e76033d8c44b71d2982028a63436d3fe84Eric Laurent 521de55cfb02db874136caf9c05927cee4028296147Eric Laurent#ifdef AUDIO_POLICY_TEST 522de55cfb02db874136caf9c05927cee4028296147Eric Laurent Mutex mLock; 523de55cfb02db874136caf9c05927cee4028296147Eric Laurent Condition mWaitWorkCV; 524de55cfb02db874136caf9c05927cee4028296147Eric Laurent 525de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mCurOutput; 526de55cfb02db874136caf9c05927cee4028296147Eric Laurent bool mDirectOutput; 527de55cfb02db874136caf9c05927cee4028296147Eric Laurent audio_io_handle_t mTestOutputs[NUM_TEST_OUTPUTS]; 528de55cfb02db874136caf9c05927cee4028296147Eric Laurent int mTestInput; 529de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mTestDevice; 530de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mTestSamplingRate; 531de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mTestFormat; 532de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mTestChannels; 533de55cfb02db874136caf9c05927cee4028296147Eric Laurent uint32_t mTestLatencyMs; 534de55cfb02db874136caf9c05927cee4028296147Eric Laurent#endif //AUDIO_POLICY_TEST 535f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Trivi 536f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Triviprivate: 537f9a4e2eccfbbe451512337af0806cfc54be0eaf9Eric Laurent static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc, 538f2faac71fd54ef16807b94d19e46d7ad99b001a7Jean-Michel Trivi int indexInUi); 53912bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi // updates device caching and output for streams that can influence the 54012bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi // routing of notifications 54112bd6e4a5c26bd8035bf804d0cc821bd9b8cce9bJean-Michel Trivi void handleNotificationRoutingForStream(AudioSystem::stream_type stream); 542de55cfb02db874136caf9c05927cee4028296147Eric Laurent}; 543de55cfb02db874136caf9c05927cee4028296147Eric Laurent 544de55cfb02db874136caf9c05927cee4028296147Eric Laurent}; 545