Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 1 | /* |
Sharad Sangle | ca67a02 | 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 | ca67a02 | 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 | |
| 25 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 26 | namespace android { |
| 27 | #ifndef FLAC_OFFLOAD_ENABLED |
| 28 | #define AUDIO_FORMAT_FLAC 0x1D000000UL |
| 29 | #endif |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 30 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 31 | #ifndef WMA_OFFLOAD_ENABLED |
| 32 | #define AUDIO_FORMAT_WMA 0x13000000UL |
| 33 | #define AUDIO_FORMAT_WMA_PRO 0x14000000UL |
| 34 | #endif |
| 35 | |
| 36 | #ifndef ALAC_OFFLOAD_ENABLED |
| 37 | #define AUDIO_FORMAT_ALAC 0x1F000000UL |
| 38 | #endif |
| 39 | |
| 40 | #ifndef APE_OFFLOAD_ENABLED |
| 41 | #define AUDIO_FORMAT_APE 0x20000000UL |
| 42 | #endif |
Ramjee Singh | ae5f890 | 2015-08-19 20:47:12 +0530 | [diff] [blame] | 43 | #ifndef AUDIO_EXTN_AFE_PROXY_ENABLED |
Ramjee Singh | 58a2831 | 2015-08-14 14:40:44 +0530 | [diff] [blame] | 44 | #define AUDIO_DEVICE_OUT_PROXY 0x1000000 |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 45 | #endif |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 46 | // ---------------------------------------------------------------------------- |
| 47 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 48 | class AudioPolicyManagerCustom: public AudioPolicyManager |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 49 | { |
| 50 | |
| 51 | public: |
Mingming Yin | 3887780 | 2015-10-05 15:24:04 -0700 | [diff] [blame^] | 52 | AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface); |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 53 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 54 | virtual ~AudioPolicyManagerCustom() {} |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 55 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 56 | status_t setDeviceConnectionStateInt(audio_devices_t device, |
| 57 | audio_policy_dev_state_t state, |
| 58 | const char *device_address, |
| 59 | const char *device_name); |
| 60 | virtual void setPhoneState(audio_mode_t state); |
| 61 | |
ApurupaPattapu | 0c56687 | 2014-01-10 14:46:02 -0800 | [diff] [blame] | 62 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 63 | |
| 64 | // true if given state represents a device in a telephony or VoIP call |
Ramjee Singh | 58a2831 | 2015-08-14 14:40:44 +0530 | [diff] [blame] | 65 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 66 | protected: |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 67 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 68 | status_t checkAndSetVolume(audio_stream_type_t stream, |
| 69 | int index, |
| 70 | const sp<SwAudioOutputDescriptor>& outputDesc, |
| 71 | audio_devices_t device, |
| 72 | int delayMs = 0, bool force = false); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 73 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 74 | // selects the most appropriate device on output for current state |
| 75 | // must be called every time a condition that affects the device choice for a given output is |
| 76 | // changed: connected device, phone state, force use, output start, output stop.. |
| 77 | // see getDeviceForStrategy() for the use of fromCache parameter |
| 78 | audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc, |
| 79 | bool fromCache); |
| 80 | // returns true if given output is direct output |
Karthik Reddy Katta | 521934f | 2014-06-09 12:39:37 +0530 | [diff] [blame] | 81 | bool isDirectOutput(audio_io_handle_t output); |
| 82 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 83 | // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force |
| 84 | // the re-evaluation of the output device. |
Ramjee Singh | 5b022de | 2015-09-15 18:25:20 +0530 | [diff] [blame] | 85 | status_t startSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 86 | audio_stream_type_t stream, |
| 87 | audio_devices_t device, |
| 88 | uint32_t *delayMs); |
Ramjee Singh | 5b022de | 2015-09-15 18:25:20 +0530 | [diff] [blame] | 89 | status_t stopSource(sp<AudioOutputDescriptor> outputDesc, |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 90 | audio_stream_type_t stream, |
| 91 | bool forceDeviceUpdate); |
| 92 | // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313 |
| 93 | // returns 0 if no mute/unmute event happened, the largest latency of the device where 314 |
| 94 | // the mute/unmute happened 315 |
| 95 | uint32_t handleEventForBeacon(int){return 0;} |
| 96 | uint32_t setBeaconMute(bool){return 0;} |
Mingming Yin | 9d2feb7 | 2014-04-29 18:40:21 -0700 | [diff] [blame] | 97 | |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 98 | // handle special cases for sonification strategy while in call: mute streams or replace by |
| 99 | // a special tone in the device used for communication |
| 100 | void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output); |
| 101 | //parameter indicates of HDMI speakers disabled |
Mingming Yin | 9d2feb7 | 2014-04-29 18:40:21 -0700 | [diff] [blame] | 102 | bool mHdmiAudioDisabled; |
Mingming Yin | 9d2feb7 | 2014-04-29 18:40:21 -0700 | [diff] [blame] | 103 | //parameter indicates if HDMI plug in/out detected |
| 104 | bool mHdmiAudioEvent; |
Pavan Chikkala | e33427d | 2014-03-24 17:11:50 +0530 | [diff] [blame] | 105 | private: |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 106 | static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc, |
| 107 | int indexInUi); |
| 108 | // updates device caching and output for streams that can influence the |
| 109 | // routing of notifications |
| 110 | void handleNotificationRoutingForStream(audio_stream_type_t stream); |
| 111 | static bool isVirtualInputDevice(audio_devices_t device); |
| 112 | static bool deviceDistinguishesOnAddress(audio_devices_t device); |
| 113 | uint32_t nextUniqueId(); |
| 114 | // internal method to return the output handle for the given device and format |
| 115 | audio_io_handle_t getOutputForDevice( |
| 116 | audio_devices_t device, |
| 117 | audio_session_t session, |
| 118 | audio_stream_type_t stream, |
| 119 | uint32_t samplingRate, |
| 120 | audio_format_t format, |
| 121 | audio_channel_mask_t channelMask, |
| 122 | audio_output_flags_t flags, |
| 123 | const audio_offload_info_t *offloadInfo); |
Mingming Yin | 9d2feb7 | 2014-04-29 18:40:21 -0700 | [diff] [blame] | 124 | // Used for voip + voice concurrency usecase |
| 125 | int mPrevPhoneState; |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 126 | int mvoice_call_state; |
Pavan Chikkala | e33427d | 2014-03-24 17:11:50 +0530 | [diff] [blame] | 127 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 128 | }; |
Sharad Sangle | ca67a02 | 2015-05-28 16:15:16 +0530 | [diff] [blame] | 129 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 130 | }; |