blob: 9e58dcf83f0c194a4e0764b59bd03ac16cbe9a64 [file] [log] [blame]
Marko Manef8d7e42018-08-26 23:20:31 +02001/*
2 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
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
21#include <audiopolicy/managerdefault/AudioPolicyManager.h>
22#include <audio_policy_conf.h>
23#include <Volume.h>
24
25
26namespace android {
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
33#endif
34
35#define WMA_STD_NUM_FREQ 7
36#define WMA_STD_NUM_CHANNELS 2
37static uint32_t wmaStdSampleRateTbl[WMA_STD_NUM_FREQ] =
38{
39 8000, 11025, 16000, 22050, 32000, 44100, 48000
40};
41
42static 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
53static 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
67#ifndef AAC_ADTS_OFFLOAD_ENABLED
68#define AUDIO_FORMAT_AAC_ADTS 0x1E000000UL
69#endif
70
71#ifndef AUDIO_EXTN_AFE_PROXY_ENABLED
72#define AUDIO_DEVICE_OUT_PROXY 0x1000000
73#endif
74
75// ----------------------------------------------------------------------------
76
77class AudioPolicyManagerCustom: public AudioPolicyManager
78{
79
80public:
81 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
82
83 virtual ~AudioPolicyManagerCustom() {}
84
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);
89 virtual void setPhoneState(audio_mode_t state);
90 virtual void setForceUse(audio_policy_force_use_t usage,
91 audio_policy_forced_cfg_t config);
92
93 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
94
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,
99 const audio_config_base_t *config,
100 audio_input_flags_t flags,
101 audio_port_handle_t *selectedDeviceId,
102 input_type_t *inputType,
103 audio_port_handle_t *portId);
104 /* count active capture sessions (that are not sound trigger) using one of
105 the specified devices. Ignore devices if AUDIO_DEVICE_IN_DEFAULT is passed */
106 uint32_t activeNonSoundTriggerInputsCountOnDevices(
107 audio_devices_t devices = AUDIO_DEVICE_IN_DEFAULT) const;
108 // indicates to the audio policy manager that the input starts being used.
109 virtual status_t startInput(audio_io_handle_t input,
110 audio_session_t session,
111 bool silenced,
112 concurrency_type__mask_t *concurrency);
113 // indicates to the audio policy manager that the input stops being used.
114 virtual status_t stopInput(audio_io_handle_t input,
115 audio_session_t session);
116
117protected:
118
119 status_t checkAndSetVolume(audio_stream_type_t stream,
120 int index,
121 const sp<AudioOutputDescriptor>& outputDesc,
122 audio_devices_t device,
123 int delayMs = 0, bool force = false);
124
125 // avoid invalidation for active music stream on previous outputs
126 // which is supported on the new device.
127 bool isInvalidationOfMusicStreamNeeded(routing_strategy strategy);
128
129 // Must be called before updateDevicesAndOutputs()
130 void checkOutputForStrategy(routing_strategy strategy);
131
132 // returns true if given output is direct output
133 bool isDirectOutput(audio_io_handle_t output);
134
135 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
136 // the re-evaluation of the output device.
137 status_t startSource(const sp<AudioOutputDescriptor>& outputDesc,
138 audio_stream_type_t stream,
139 audio_devices_t device,
140 const char *address,
141 uint32_t *delayMs);
142 status_t stopSource(const sp<AudioOutputDescriptor>& outputDesc,
143 audio_stream_type_t stream,
144 bool forceDeviceUpdate);
145 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON
146 // returns 0 if no mute/unmute event happened, the largest latency of the device where
147 // the mute/unmute happened
148 uint32_t handleEventForBeacon(int){return 0;}
149 uint32_t setBeaconMute(bool){return 0;}
150#ifdef VOICE_CONCURRENCY
151 static audio_output_flags_t getFallBackPath();
152 int mFallBackflag;
153#endif /*VOICE_CONCURRENCY*/
154 void moveGlobalEffect();
155
156 // handle special cases for sonification strategy while in call: mute streams or replace by
157 // a special tone in the device used for communication
158 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
159 //parameter indicates of HDMI speakers disabled
160 bool mHdmiAudioDisabled;
161 //parameter indicates if HDMI plug in/out detected
162 bool mHdmiAudioEvent;
163private:
164 // updates device caching and output for streams that can influence the
165 // routing of notifications
166 void handleNotificationRoutingForStream(audio_stream_type_t stream);
167 // internal method to return the output handle for the given device and format
168 audio_io_handle_t getOutputForDevice(
169 audio_devices_t device,
170 audio_session_t session,
171 audio_stream_type_t stream,
172 const audio_config_t *config,
173 audio_output_flags_t *flags);
174
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,
181 const audio_config_t *config,
182 audio_output_flags_t *flags,
183 audio_port_handle_t *selectedDeviceId,
184 audio_port_handle_t *portId);
185 // internal method to query hal for whether display-port is connected
186 // and can be used for voip/voice call
187 void chkDpConnAndAllowedForVoice();
188 // Used for voip + voice concurrency usecase
189 int mPrevPhoneState;
190#ifdef VOICE_CONCURRENCY
191 int mvoice_call_state;
192#endif
193#ifdef RECORD_PLAY_CONCURRENCY
194 // Used for record + playback concurrency
195 bool mIsInputRequestOnProgress;
196#endif
197
198#ifdef FM_POWER_OPT
199 float mPrevFMVolumeDb;
200 bool mFMIsActive;
201#endif
202};
203};