Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 1 | /* |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 3 | * Not a contribution. |
| 4 | * |
| 5 | * Copyright (C) 2009 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 21 | #include <audiopolicy/managerdefault/AudioPolicyManager.h> |
| 22 | #include <audio_policy_conf.h> |
| 23 | #include <Volume.h> |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 24 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
Satya Krishna Pindiproli | 5d82d01 | 2015-08-12 18:21:25 +0530 | [diff] [blame] | 27 | #ifndef AUDIO_EXTN_FORMATS_ENABLED |
| 28 | #define AUDIO_FORMAT_WMA 0x12000000UL |
| 29 | #define AUDIO_FORMAT_WMA_PRO 0x13000000UL |
| 30 | #define AUDIO_FORMAT_FLAC 0x1B000000UL |
| 31 | #define AUDIO_FORMAT_ALAC 0x1C000000UL |
| 32 | #define AUDIO_FORMAT_APE 0x1D000000UL |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 33 | #endif |
| 34 | |
Weiyin Jiang | 8790b1f | 2017-05-09 18:16:43 +0800 | [diff] [blame] | 35 | #define WMA_STD_NUM_FREQ 7 |
| 36 | #define WMA_STD_NUM_CHANNELS 2 |
| 37 | static uint32_t wmaStdSampleRateTbl[WMA_STD_NUM_FREQ] = |
| 38 | { |
| 39 | 8000, 11025, 16000, 22050, 32000, 44100, 48000 |
| 40 | }; |
| 41 | |
| 42 | static uint32_t wmaStdMinAvgByteRateTbl[WMA_STD_NUM_FREQ][WMA_STD_NUM_CHANNELS] = |
| 43 | { |
| 44 | {128, 12000}, |
| 45 | {8016, 8016}, |
| 46 | {10000, 16000}, |
| 47 | {16016, 20008}, |
| 48 | {20000, 24000}, |
| 49 | {20008, 31960}, |
| 50 | {63000, 63000} |
| 51 | }; |
| 52 | |
| 53 | static uint32_t wmaStdMaxAvgByteRateTbl[WMA_STD_NUM_FREQ][WMA_STD_NUM_CHANNELS] = |
| 54 | { |
| 55 | {8000, 12000}, |
| 56 | {10168, 10168}, |
| 57 | {16000, 20000}, |
| 58 | {20008, 32048}, |
| 59 | {20000, 48000}, |
| 60 | {48024, 320032}, |
| 61 | {256008, 256008} |
| 62 | }; |
| 63 | |
| 64 | #define MAX_BITRATE_WMA_PRO 1536000 |
| 65 | #define MAX_BITRATE_WMA_LOSSLESS 1152000 |
| 66 | |
Manish Dewangan | a6fc544 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 67 | #ifndef AAC_ADTS_OFFLOAD_ENABLED |
| 68 | #define AUDIO_FORMAT_AAC_ADTS 0x1E000000UL |
| 69 | #endif |
| 70 | |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 71 | #ifndef AUDIO_EXTN_AFE_PROXY_ENABLED |
Yamit Mehta | 0abab8b | 2015-07-14 17:32:52 +0530 | [diff] [blame] | 72 | #define AUDIO_DEVICE_OUT_PROXY 0x1000000 |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 73 | #endif |
yidongh | ae28e3a | 2016-08-19 11:31:15 +0800 | [diff] [blame] | 74 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 75 | // ---------------------------------------------------------------------------- |
| 76 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 77 | class AudioPolicyManagerCustom: public AudioPolicyManager |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 78 | { |
| 79 | |
| 80 | public: |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 81 | AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface); |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 82 | |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 83 | virtual ~AudioPolicyManagerCustom() {} |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 84 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 85 | status_t setDeviceConnectionStateInt(audio_devices_t device, |
| 86 | audio_policy_dev_state_t state, |
| 87 | const char *device_address, |
| 88 | const char *device_name); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 89 | virtual void setPhoneState(audio_mode_t state); |
Dhananjay Kumar | 87dea1b | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 90 | virtual void setForceUse(audio_policy_force_use_t usage, |
| 91 | audio_policy_forced_cfg_t config); |
Zhou Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 92 | |
Naresh Tanniru | 36c0893 | 2014-01-27 18:40:53 +0530 | [diff] [blame] | 93 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
| 94 | |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 95 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 96 | audio_io_handle_t *input, |
| 97 | audio_session_t session, |
| 98 | uid_t uid, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 99 | const audio_config_base_t *config, |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 100 | audio_input_flags_t flags, |
| 101 | audio_port_handle_t selectedDeviceId, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 102 | input_type_t *inputType, |
| 103 | audio_port_handle_t *portId); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 104 | // indicates to the audio policy manager that the input starts being used. |
| 105 | virtual status_t startInput(audio_io_handle_t input, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 106 | audio_session_t session, |
| 107 | concurrency_type__mask_t *concurrency); |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 108 | // indicates to the audio policy manager that the input stops being used. |
| 109 | virtual status_t stopInput(audio_io_handle_t input, |
| 110 | audio_session_t session); |
Preetam Singh Ranawat | 61716b1 | 2015-12-14 11:55:24 +0530 | [diff] [blame] | 111 | |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 112 | virtual void closeAllInputs(); |
Sharad Sangle | dd1e184 | 2015-07-27 15:14:23 +0530 | [diff] [blame] | 113 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 114 | protected: |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 115 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 116 | status_t checkAndSetVolume(audio_stream_type_t stream, |
| 117 | int index, |
Dhananjay Kumar | 0ffa711 | 2015-10-20 17:56:50 +0530 | [diff] [blame] | 118 | const sp<AudioOutputDescriptor>& outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 119 | audio_devices_t device, |
| 120 | int delayMs = 0, bool force = false); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 121 | |
Preetam Singh Ranawat | 3db94ec | 2016-10-13 18:35:12 +0530 | [diff] [blame] | 122 | // avoid invalidation for active music stream on previous outputs |
| 123 | // which is supported on the new device. |
| 124 | bool isInvalidationOfMusicStreamNeeded(routing_strategy strategy); |
| 125 | |
| 126 | // Must be called before updateDevicesAndOutputs() |
| 127 | void checkOutputForStrategy(routing_strategy strategy); |
| 128 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 129 | // returns true if given output is direct output |
| 130 | bool isDirectOutput(audio_io_handle_t output); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 131 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 132 | // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force |
| 133 | // the re-evaluation of the output device. |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 134 | status_t startSource(const sp<AudioOutputDescriptor>& outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 135 | audio_stream_type_t stream, |
| 136 | audio_devices_t device, |
Lalit Kansara | f803ac5 | 2016-05-09 19:12:01 +0530 | [diff] [blame] | 137 | const char *address, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 138 | uint32_t *delayMs); |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 139 | status_t stopSource(const sp<AudioOutputDescriptor>& outputDesc, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 140 | audio_stream_type_t stream, |
| 141 | bool forceDeviceUpdate); |
Sharad Sangle | 4509cef | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 142 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON |
| 143 | // returns 0 if no mute/unmute event happened, the largest latency of the device where |
| 144 | // the mute/unmute happened |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 145 | uint32_t handleEventForBeacon(int){return 0;} |
| 146 | uint32_t setBeaconMute(bool){return 0;} |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 147 | #ifdef VOICE_CONCURRENCY |
| 148 | static audio_output_flags_t getFallBackPath(); |
| 149 | int mFallBackflag; |
| 150 | #endif /*VOICE_CONCURRENCY*/ |
Ashish Jain | e4a22d5 | 2016-06-22 11:55:08 +0530 | [diff] [blame] | 151 | void moveGlobalEffect(); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 152 | |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 153 | // handle special cases for sonification strategy while in call: mute streams or replace by |
| 154 | // a special tone in the device used for communication |
| 155 | void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 156 | //parameter indicates of HDMI speakers disabled |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 157 | bool mHdmiAudioDisabled; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 158 | //parameter indicates if HDMI plug in/out detected |
| 159 | bool mHdmiAudioEvent; |
Pavan Chikkala | 785b693 | 2014-03-24 18:58:11 +0530 | [diff] [blame] | 160 | private: |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 161 | // updates device caching and output for streams that can influence the |
| 162 | // routing of notifications |
| 163 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 164 | // internal method to return the output handle for the given device and format |
| 165 | audio_io_handle_t getOutputForDevice( |
| 166 | audio_devices_t device, |
Sharad Sangle | 3678161 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 167 | audio_session_t session, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 168 | uid_t client, |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 169 | audio_stream_type_t stream, |
| 170 | uint32_t samplingRate, |
| 171 | audio_format_t format, |
| 172 | audio_channel_mask_t channelMask, |
| 173 | audio_output_flags_t flags, |
| 174 | const audio_offload_info_t *offloadInfo); |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 175 | // internal method to fill offload info in case of Direct PCM |
| 176 | status_t getOutputForAttr(const audio_attributes_t *attr, |
| 177 | audio_io_handle_t *output, |
| 178 | audio_session_t session, |
| 179 | audio_stream_type_t *stream, |
| 180 | uid_t uid, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 181 | const audio_config_t *config, |
vivek mehta | 0ea887a | 2015-08-26 14:01:20 -0700 | [diff] [blame] | 182 | audio_output_flags_t flags, |
| 183 | audio_port_handle_t selectedDeviceId, |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 184 | audio_port_handle_t *portId); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 185 | // Used for voip + voice concurrency usecase |
| 186 | int mPrevPhoneState; |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 187 | #ifdef VOICE_CONCURRENCY |
Ravi Kumar Alamanda | 1cf2a59 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 188 | int mvoice_call_state; |
Ashish Jain | 40cab3a | 2016-03-23 11:14:14 +0530 | [diff] [blame] | 189 | #endif |
Sharad Sangle | c5766ff | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 190 | #ifdef RECORD_PLAY_CONCURRENCY |
| 191 | // Used for record + playback concurrency |
| 192 | bool mIsInputRequestOnProgress; |
| 193 | #endif |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 194 | |
| 195 | #ifdef FM_POWER_OPT |
Haynes Mathew George | 0b2c377 | 2015-12-14 14:22:07 -0800 | [diff] [blame] | 196 | float mPrevFMVolumeDb; |
Haynes Mathew George | 603ae9b | 2015-12-21 17:23:59 -0800 | [diff] [blame] | 197 | bool mFMIsActive; |
Garmond Leung | fcb00d9 | 2017-01-31 11:12:47 -0800 | [diff] [blame] | 198 | #endif |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 199 | }; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 200 | }; |