Iliyan Malchev | 4765c43 | 2012-06-11 14:36:16 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * Copyright (C) 2011, Code Aurora Forum. All rights reserved. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <utils/Timers.h> |
| 22 | #include <utils/Errors.h> |
| 23 | #include <utils/KeyedVector.h> |
| 24 | #include <hardware_legacy/AudioPolicyManagerBase.h> |
| 25 | |
| 26 | |
| 27 | namespace android_audio_legacy { |
| 28 | |
| 29 | // ---------------------------------------------------------------------------- |
| 30 | |
| 31 | #define MAX_DEVICE_ADDRESS_LEN 20 |
| 32 | // Attenuation applied to STRATEGY_SONIFICATION streams when a headset is connected: 6dB |
| 33 | #define SONIFICATION_HEADSET_VOLUME_FACTOR 0.5 |
| 34 | // Min volume for STRATEGY_SONIFICATION streams when limited by music volume: -36dB |
| 35 | #define SONIFICATION_HEADSET_VOLUME_MIN 0.016 |
| 36 | // Time in seconds during which we consider that music is still active after a music |
| 37 | // track was stopped - see computeVolume() |
| 38 | #define SONIFICATION_HEADSET_MUSIC_DELAY 5 |
| 39 | class AudioPolicyManager: public AudioPolicyManagerBase |
| 40 | { |
| 41 | |
| 42 | public: |
| 43 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface) |
| 44 | : AudioPolicyManagerBase(clientInterface) { |
| 45 | mLPADecodeOutput = -1; |
| 46 | mLPAMuted = false; |
| 47 | mLPAStreamType = AudioSystem::DEFAULT; |
| 48 | } |
| 49 | |
| 50 | virtual ~AudioPolicyManager() {} |
| 51 | |
| 52 | // AudioPolicyInterface |
| 53 | virtual status_t setDeviceConnectionState(AudioSystem::audio_devices device, |
| 54 | AudioSystem::device_connection_state state, |
| 55 | const char *device_address); |
| 56 | virtual void setPhoneState(int state); |
| 57 | |
| 58 | // return appropriate device for streams handled by the specified strategy according to current |
| 59 | // phone state, connected devices... |
| 60 | // if fromCache is true, the device is returned from mDeviceForStrategy[], otherwise it is determined |
| 61 | // by current state (device connected, phone state, force use, a2dp output...) |
| 62 | // This allows to: |
| 63 | // 1 speed up process when the state is stable (when starting or stopping an output) |
| 64 | // 2 access to either current device selection (fromCache == true) or |
| 65 | // "future" device selection (fromCache == false) when called from a context |
| 66 | // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND |
| 67 | // before updateDeviceForStrategy() is called. |
| 68 | virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); |
| 69 | |
| 70 | #ifdef TUNNEL_LPA_ENABLED |
| 71 | virtual audio_io_handle_t getSession(AudioSystem::stream_type stream, |
| 72 | uint32_t format, |
| 73 | AudioSystem::output_flags flags, |
| 74 | int32_t sessionId, |
| 75 | uint32_t samplingRate, uint32_t channels); |
| 76 | virtual void pauseSession(audio_io_handle_t output, AudioSystem::stream_type stream); |
| 77 | virtual void resumeSession(audio_io_handle_t output, AudioSystem::stream_type stream); |
| 78 | virtual void releaseSession(audio_io_handle_t output); |
| 79 | #endif |
| 80 | |
| 81 | virtual status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream, int session = 0); |
| 82 | virtual status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream, int session = 0); |
| 83 | virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config); |
| 84 | status_t startInput(audio_io_handle_t input); |
| 85 | |
| 86 | protected: |
| 87 | // true is current platform implements a back microphone |
| 88 | virtual bool hasBackMicrophone() const { return false; } |
| 89 | #ifdef WITH_A2DP |
| 90 | // true is current platform supports suplication of notifications and ringtones over A2DP output |
| 91 | virtual bool a2dpUsedForSonification() const { return true; } |
| 92 | #endif |
| 93 | // change the route of the specified output |
| 94 | void setOutputDevice(audio_io_handle_t output, uint32_t device, bool force = false, int delayMs = 0); |
| 95 | // check that volume change is permitted, compute and send new volume to audio hardware |
| 96 | status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs = 0, bool force = false); |
| 97 | // select input device corresponding to requested audio source |
| 98 | virtual uint32_t getDeviceForInputSource(int inputSource); |
| 99 | // Mute or unmute the stream on the specified output |
| 100 | void setStreamMute(int stream, bool on, audio_io_handle_t output, int delayMs = 0); |
| 101 | audio_io_handle_t mLPADecodeOutput; // active output handler |
| 102 | audio_io_handle_t mLPAActiveOuput; // LPA Output Handler during inactive state |
| 103 | |
| 104 | bool mLPAMuted; |
| 105 | AudioSystem::stream_type mLPAStreamType; |
| 106 | AudioSystem::stream_type mLPAActiveStreamType; |
| 107 | }; |
| 108 | }; |