blob: 2f29c37c34dfceae1a79a55ef51c5021fdc60a3d [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sangle36781612015-05-28 16:15:16 +05302 * Copyright (c) 2013-2015, 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
35#ifndef AFE_PROXY_ENABLED
Yamit Mehta0abab8b2015-07-14 17:32:52 +053036#define AUDIO_DEVICE_OUT_PROXY 0x1000000
Sharad Sangle36781612015-05-28 16:15:16 +053037#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070038// ----------------------------------------------------------------------------
39
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070040class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070041{
42
43public:
Sharad Sanglec5766ff2015-06-04 20:24:10 +053044 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070045
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070046 virtual ~AudioPolicyManagerCustom() {}
Mingming Yin0ae14ea2014-07-09 17:55:56 -070047
Sharad Sangle36781612015-05-28 16:15:16 +053048 status_t setDeviceConnectionStateInt(audio_devices_t device,
49 audio_policy_dev_state_t state,
50 const char *device_address,
51 const char *device_name);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070052 virtual void setPhoneState(audio_mode_t state);
Zhou Songc0d78c22014-06-16 10:48:22 +080053
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070054
Naresh Tanniru36c08932014-01-27 18:40:53 +053055 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
56
Sharad Sanglec5766ff2015-06-04 20:24:10 +053057 virtual status_t getInputForAttr(const audio_attributes_t *attr,
58 audio_io_handle_t *input,
59 audio_session_t session,
60 uid_t uid,
61 uint32_t samplingRate,
62 audio_format_t format,
63 audio_channel_mask_t channelMask,
64 audio_input_flags_t flags,
65 audio_port_handle_t selectedDeviceId,
66 input_type_t *inputType);
67 // indicates to the audio policy manager that the input starts being used.
68 virtual status_t startInput(audio_io_handle_t input,
69 audio_session_t session);
70 // indicates to the audio policy manager that the input stops being used.
71 virtual status_t stopInput(audio_io_handle_t input,
72 audio_session_t session);
Sharad Sanglec60f6fa2015-07-27 15:14:23 +053073 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070074protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070075
Sharad Sangle36781612015-05-28 16:15:16 +053076 status_t checkAndSetVolume(audio_stream_type_t stream,
77 int index,
78 const sp<SwAudioOutputDescriptor>& outputDesc,
79 audio_devices_t device,
80 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070081
Sharad Sangle36781612015-05-28 16:15:16 +053082 // selects the most appropriate device on output for current state
83 // must be called every time a condition that affects the device choice for a given output is
84 // changed: connected device, phone state, force use, output start, output stop..
85 // see getDeviceForStrategy() for the use of fromCache parameter
86 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
87 bool fromCache);
88 // returns true if given output is direct output
89 bool isDirectOutput(audio_io_handle_t output);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070090
Sharad Sangle36781612015-05-28 16:15:16 +053091 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
92 // the re-evaluation of the output device.
93 status_t startSource(sp<SwAudioOutputDescriptor> outputDesc,
94 audio_stream_type_t stream,
95 audio_devices_t device,
96 uint32_t *delayMs);
97 status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc,
98 audio_stream_type_t stream,
99 bool forceDeviceUpdate);
100 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313
101 // returns 0 if no mute/unmute event happened, the largest latency of the device where 314
102 // the mute/unmute happened 315
103 uint32_t handleEventForBeacon(int){return 0;}
104 uint32_t setBeaconMute(bool){return 0;}
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530105#ifdef VOICE_CONCURRENCY
106 static audio_output_flags_t getFallBackPath();
107 int mFallBackflag;
108#endif /*VOICE_CONCURRENCY*/
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700109
Sharad Sangle36781612015-05-28 16:15:16 +0530110 // handle special cases for sonification strategy while in call: mute streams or replace by
111 // a special tone in the device used for communication
112 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700113 //parameter indicates of HDMI speakers disabled
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700114 bool mHdmiAudioDisabled;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700115 //parameter indicates if HDMI plug in/out detected
116 bool mHdmiAudioEvent;
Pavan Chikkala785b6932014-03-24 18:58:11 +0530117private:
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700118 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
119 int indexInUi);
120 // updates device caching and output for streams that can influence the
121 // routing of notifications
122 void handleNotificationRoutingForStream(audio_stream_type_t stream);
123 static bool isVirtualInputDevice(audio_devices_t device);
124 static bool deviceDistinguishesOnAddress(audio_devices_t device);
125 uint32_t nextUniqueId();
126 // internal method to return the output handle for the given device and format
127 audio_io_handle_t getOutputForDevice(
128 audio_devices_t device,
Sharad Sangle36781612015-05-28 16:15:16 +0530129 audio_session_t session,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700130 audio_stream_type_t stream,
131 uint32_t samplingRate,
132 audio_format_t format,
133 audio_channel_mask_t channelMask,
134 audio_output_flags_t flags,
135 const audio_offload_info_t *offloadInfo);
vivek mehta0ea887a2015-08-26 14:01:20 -0700136 // internal method to fill offload info in case of Direct PCM
137 status_t getOutputForAttr(const audio_attributes_t *attr,
138 audio_io_handle_t *output,
139 audio_session_t session,
140 audio_stream_type_t *stream,
141 uid_t uid,
142 uint32_t samplingRate,
143 audio_format_t format,
144 audio_channel_mask_t channelMask,
145 audio_output_flags_t flags,
146 audio_port_handle_t selectedDeviceId,
147 const audio_offload_info_t *offloadInfo);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700148 // Used for voip + voice concurrency usecase
149 int mPrevPhoneState;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700150 int mvoice_call_state;
Sharad Sanglec5766ff2015-06-04 20:24:10 +0530151#ifdef RECORD_PLAY_CONCURRENCY
152 // Used for record + playback concurrency
153 bool mIsInputRequestOnProgress;
154#endif
155
Mingming Yin0670f162014-06-12 16:05:49 -0700156
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700157};
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700158
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700159};