Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 1 | /* |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, 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 | f2e1166 | 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 | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
Satya Krishna Pindiproli | 4cda535 | 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 | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 33 | #endif |
| 34 | |
Manish Dewangan | 93672f1 | 2015-08-24 20:30:31 +0530 | [diff] [blame] | 35 | #ifndef AAC_ADTS_OFFLOAD_ENABLED |
| 36 | #define AUDIO_FORMAT_AAC_ADTS 0x1E000000UL |
| 37 | #endif |
| 38 | |
Sharad Sangle | b53795f | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 39 | #ifndef AUDIO_EXTN_AFE_PROXY_ENABLED |
Yamit Mehta | a46815c | 2015-07-14 17:32:52 +0530 | [diff] [blame] | 40 | #define AUDIO_DEVICE_OUT_PROXY 0x1000000 |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 41 | #endif |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 42 | // ---------------------------------------------------------------------------- |
| 43 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 44 | class AudioPolicyManagerCustom: public AudioPolicyManager |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 45 | { |
| 46 | |
| 47 | public: |
Sharad Sangle | 78d5324 | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 48 | AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface); |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 49 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 50 | virtual ~AudioPolicyManagerCustom() {} |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 51 | |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 52 | status_t setDeviceConnectionStateInt(audio_devices_t device, |
| 53 | audio_policy_dev_state_t state, |
| 54 | const char *device_address, |
| 55 | const char *device_name); |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 56 | virtual void setPhoneState(audio_mode_t state); |
Dhananjay Kumar | 22b3398 | 2015-09-16 19:44:33 +0530 | [diff] [blame] | 57 | virtual void setForceUse(audio_policy_force_use_t usage, |
| 58 | audio_policy_forced_cfg_t config); |
Zhou Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 59 | |
Naresh Tanniru | 36c0893 | 2014-01-27 18:40:53 +0530 | [diff] [blame] | 60 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
| 61 | |
Sharad Sangle | 78d5324 | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 62 | virtual status_t getInputForAttr(const audio_attributes_t *attr, |
| 63 | audio_io_handle_t *input, |
| 64 | audio_session_t session, |
| 65 | uid_t uid, |
| 66 | uint32_t samplingRate, |
| 67 | audio_format_t format, |
| 68 | audio_channel_mask_t channelMask, |
| 69 | audio_input_flags_t flags, |
| 70 | audio_port_handle_t selectedDeviceId, |
| 71 | input_type_t *inputType); |
| 72 | // indicates to the audio policy manager that the input starts being used. |
| 73 | virtual status_t startInput(audio_io_handle_t input, |
| 74 | audio_session_t session); |
| 75 | // indicates to the audio policy manager that the input stops being used. |
| 76 | virtual status_t stopInput(audio_io_handle_t input, |
| 77 | audio_session_t session); |
Chaithanya Krishna Bacharaju | 54177c4 | 2015-09-14 15:05:09 +0530 | [diff] [blame] | 78 | virtual void closeAllInputs(); |
Sharad Sangle | dd1e184 | 2015-07-27 15:14:23 +0530 | [diff] [blame] | 79 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 80 | protected: |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 81 | |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 82 | status_t checkAndSetVolume(audio_stream_type_t stream, |
| 83 | int index, |
| 84 | const sp<SwAudioOutputDescriptor>& outputDesc, |
| 85 | audio_devices_t device, |
| 86 | int delayMs = 0, bool force = false); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 87 | |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 88 | // selects the most appropriate device on output for current state |
| 89 | // must be called every time a condition that affects the device choice for a given output is |
| 90 | // changed: connected device, phone state, force use, output start, output stop.. |
| 91 | // see getDeviceForStrategy() for the use of fromCache parameter |
| 92 | audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
| 93 | bool fromCache); |
| 94 | // returns true if given output is direct output |
| 95 | bool isDirectOutput(audio_io_handle_t output); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 96 | |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 97 | // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force |
| 98 | // the re-evaluation of the output device. |
| 99 | status_t startSource(sp<SwAudioOutputDescriptor> outputDesc, |
| 100 | audio_stream_type_t stream, |
| 101 | audio_devices_t device, |
| 102 | uint32_t *delayMs); |
| 103 | status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc, |
| 104 | audio_stream_type_t stream, |
| 105 | bool forceDeviceUpdate); |
Sharad Sangle | b53795f | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 106 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON |
| 107 | // returns 0 if no mute/unmute event happened, the largest latency of the device where |
| 108 | // the mute/unmute happened |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 109 | uint32_t handleEventForBeacon(int){return 0;} |
| 110 | uint32_t setBeaconMute(bool){return 0;} |
Sharad Sangle | 78d5324 | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 111 | #ifdef VOICE_CONCURRENCY |
| 112 | static audio_output_flags_t getFallBackPath(); |
| 113 | int mFallBackflag; |
| 114 | #endif /*VOICE_CONCURRENCY*/ |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 115 | |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 116 | // handle special cases for sonification strategy while in call: mute streams or replace by |
| 117 | // a special tone in the device used for communication |
| 118 | void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output); |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 119 | //parameter indicates of HDMI speakers disabled |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 120 | bool mHdmiAudioDisabled; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 121 | //parameter indicates if HDMI plug in/out detected |
| 122 | bool mHdmiAudioEvent; |
Pavan Chikkala | 785b693 | 2014-03-24 18:58:11 +0530 | [diff] [blame] | 123 | private: |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 124 | // updates device caching and output for streams that can influence the |
| 125 | // routing of notifications |
| 126 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 127 | // internal method to return the output handle for the given device and format |
| 128 | audio_io_handle_t getOutputForDevice( |
| 129 | audio_devices_t device, |
Sharad Sangle | f2e1166 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 130 | audio_session_t session, |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 131 | audio_stream_type_t stream, |
| 132 | uint32_t samplingRate, |
| 133 | audio_format_t format, |
| 134 | audio_channel_mask_t channelMask, |
| 135 | audio_output_flags_t flags, |
| 136 | const audio_offload_info_t *offloadInfo); |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 137 | // Used for voip + voice concurrency usecase |
| 138 | int mPrevPhoneState; |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 139 | int mvoice_call_state; |
Sharad Sangle | 78d5324 | 2015-06-04 20:24:10 +0530 | [diff] [blame] | 140 | #ifdef RECORD_PLAY_CONCURRENCY |
| 141 | // Used for record + playback concurrency |
| 142 | bool mIsInputRequestOnProgress; |
| 143 | #endif |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 144 | }; |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame] | 145 | |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 146 | }; |