blob: 00da59950a84a7eb0356dab28cdddcbab34b6d3c [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Ashish Jain40cab3a2016-03-23 11:14:14 +05302 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07003 * 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 Sangle36781612015-05-28 16:15:16 +053021#include <audiopolicy/managerdefault/AudioPolicyManager.h>
22#include <audio_policy_conf.h>
23#include <Volume.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070024
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070025
26namespace android {
Satya Krishna Pindiproli5d82d012015-08-12 18:21:25 +053027#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 Sangle36781612015-05-28 16:15:16 +053033#endif
34
Manish Dewangana6fc5442015-08-24 20:30:31 +053035#ifndef AAC_ADTS_OFFLOAD_ENABLED
36#define AUDIO_FORMAT_AAC_ADTS 0x1E000000UL
37#endif
38
Sharad Sangle4509cef2015-08-19 20:47:12 +053039#ifndef AUDIO_EXTN_AFE_PROXY_ENABLED
Yamit Mehta0abab8b2015-07-14 17:32:52 +053040#define AUDIO_DEVICE_OUT_PROXY 0x1000000
Sharad Sangle36781612015-05-28 16:15:16 +053041#endif
yidonghae28e3a2016-08-19 11:31:15 +080042
43#define MAX_BITRATE_WMA 384000
44#define MAX_BITRATE_WMA_PRO 1536000
45#define MAX_BITRATE_WMA_LOSSLESS 1152000
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070046// ----------------------------------------------------------------------------
47
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070048class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070049{
50
51public:
Sharad Sanglec5766ff2015-06-04 20:24:10 +053052 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070053
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070054 virtual ~AudioPolicyManagerCustom() {}
Mingming Yin0ae14ea2014-07-09 17:55:56 -070055
Sharad Sangle36781612015-05-28 16:15:16 +053056 status_t setDeviceConnectionStateInt(audio_devices_t device,
57 audio_policy_dev_state_t state,
58 const char *device_address,
59 const char *device_name);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070060 virtual void setPhoneState(audio_mode_t state);
Dhananjay Kumar87dea1b2015-09-16 19:44:33 +053061 virtual void setForceUse(audio_policy_force_use_t usage,
62 audio_policy_forced_cfg_t config);
Zhou Songc0d78c22014-06-16 10:48:22 +080063
Naresh Tanniru36c08932014-01-27 18:40:53 +053064 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
65
Sharad Sanglec5766ff2015-06-04 20:24:10 +053066 virtual status_t getInputForAttr(const audio_attributes_t *attr,
67 audio_io_handle_t *input,
68 audio_session_t session,
69 uid_t uid,
70 uint32_t samplingRate,
71 audio_format_t format,
72 audio_channel_mask_t channelMask,
73 audio_input_flags_t flags,
74 audio_port_handle_t selectedDeviceId,
75 input_type_t *inputType);
76 // indicates to the audio policy manager that the input starts being used.
77 virtual status_t startInput(audio_io_handle_t input,
78 audio_session_t session);
79 // indicates to the audio policy manager that the input stops being used.
80 virtual status_t stopInput(audio_io_handle_t input,
81 audio_session_t session);
Preetam Singh Ranawat61716b12015-12-14 11:55:24 +053082
Chaithanya Krishna Bacharaju54177c42015-09-14 15:05:09 +053083 virtual void closeAllInputs();
Sharad Sangledd1e1842015-07-27 15:14:23 +053084
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070085protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070086
Sharad Sangle36781612015-05-28 16:15:16 +053087 status_t checkAndSetVolume(audio_stream_type_t stream,
88 int index,
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +053089 const sp<AudioOutputDescriptor>& outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +053090 audio_devices_t device,
91 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070092
Sharad Sangle36781612015-05-28 16:15:16 +053093 // selects the most appropriate device on output for current state
94 // must be called every time a condition that affects the device choice for a given output is
95 // changed: connected device, phone state, force use, output start, output stop..
96 // see getDeviceForStrategy() for the use of fromCache parameter
97 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
98 bool fromCache);
Preetam Singh Ranawat3db94ec2016-10-13 18:35:12 +053099
100 // avoid invalidation for active music stream on previous outputs
101 // which is supported on the new device.
102 bool isInvalidationOfMusicStreamNeeded(routing_strategy strategy);
103
104 // Must be called before updateDevicesAndOutputs()
105 void checkOutputForStrategy(routing_strategy strategy);
106
Sharad Sangle36781612015-05-28 16:15:16 +0530107 // returns true if given output is direct output
108 bool isDirectOutput(audio_io_handle_t output);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700109
Sharad Sangle36781612015-05-28 16:15:16 +0530110 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
111 // the re-evaluation of the output device.
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +0530112 status_t startSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +0530113 audio_stream_type_t stream,
114 audio_devices_t device,
Lalit Kansaraf803ac52016-05-09 19:12:01 +0530115 const char *address,
Sharad Sangle36781612015-05-28 16:15:16 +0530116 uint32_t *delayMs);
Dhananjay Kumar0ffa7112015-10-20 17:56:50 +0530117 status_t stopSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangle36781612015-05-28 16:15:16 +0530118 audio_stream_type_t stream,
119 bool forceDeviceUpdate);
Sharad Sangle4509cef2015-08-19 20:47:12 +0530120 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON
121 // returns 0 if no mute/unmute event happened, the largest latency of the device where
122 // the mute/unmute happened
Sharad Sangle36781612015-05-28 16:15:16 +0530123 uint32_t handleEventForBeacon(int){return 0;}
124 uint32_t setBeaconMute(bool){return 0;}
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530125#ifdef VOICE_CONCURRENCY
126 static audio_output_flags_t getFallBackPath();
127 int mFallBackflag;
128#endif /*VOICE_CONCURRENCY*/
Ashish Jaine4a22d52016-06-22 11:55:08 +0530129 void moveGlobalEffect();
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700130
Sharad Sangle36781612015-05-28 16:15:16 +0530131 // handle special cases for sonification strategy while in call: mute streams or replace by
132 // a special tone in the device used for communication
133 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700134 //parameter indicates of HDMI speakers disabled
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700135 bool mHdmiAudioDisabled;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700136 //parameter indicates if HDMI plug in/out detected
137 bool mHdmiAudioEvent;
Pavan Chikkala785b6932014-03-24 18:58:11 +0530138private:
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700139 // updates device caching and output for streams that can influence the
140 // routing of notifications
141 void handleNotificationRoutingForStream(audio_stream_type_t stream);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700142 // internal method to return the output handle for the given device and format
143 audio_io_handle_t getOutputForDevice(
144 audio_devices_t device,
Sharad Sangle36781612015-05-28 16:15:16 +0530145 audio_session_t session,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700146 audio_stream_type_t stream,
147 uint32_t samplingRate,
148 audio_format_t format,
149 audio_channel_mask_t channelMask,
150 audio_output_flags_t flags,
151 const audio_offload_info_t *offloadInfo);
vivek mehta0ea887a2015-08-26 14:01:20 -0700152 // internal method to fill offload info in case of Direct PCM
153 status_t getOutputForAttr(const audio_attributes_t *attr,
154 audio_io_handle_t *output,
155 audio_session_t session,
156 audio_stream_type_t *stream,
157 uid_t uid,
158 uint32_t samplingRate,
159 audio_format_t format,
160 audio_channel_mask_t channelMask,
161 audio_output_flags_t flags,
162 audio_port_handle_t selectedDeviceId,
163 const audio_offload_info_t *offloadInfo);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700164 // Used for voip + voice concurrency usecase
165 int mPrevPhoneState;
Ashish Jain40cab3a2016-03-23 11:14:14 +0530166#ifdef VOICE_CONCURRENCY
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700167 int mvoice_call_state;
Ashish Jain40cab3a2016-03-23 11:14:14 +0530168#endif
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530169#ifdef RECORD_PLAY_CONCURRENCY
170 // Used for record + playback concurrency
171 bool mIsInputRequestOnProgress;
172#endif
Haynes Mathew George0b2c3772015-12-14 14:22:07 -0800173 float mPrevFMVolumeDb;
Haynes Mathew George603ae9b2015-12-21 17:23:59 -0800174 bool mFMIsActive;
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700175};
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700176
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700177};