blob: eb05e38bf07acbfb7252498a7060a64131484a97 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sanglef2e11662015-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 Sanglef2e11662015-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 Alamandac95fd322014-10-29 20:31:15 -070025
26namespace android {
Sharad Sanglef2e11662015-05-28 16:15:16 +053027#ifndef FLAC_OFFLOAD_ENABLED
28#define AUDIO_FORMAT_FLAC 0x1D000000UL
29#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070030
Sharad Sanglef2e11662015-05-28 16:15:16 +053031#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
43
44#ifndef AFE_PROXY_ENABLED
45#define AUDIO_DEVICE_OUT_PROXY 0x40000
46#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070047// ----------------------------------------------------------------------------
48
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070049class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070050{
51
52public:
Sharad Sangle78d53242015-06-04 20:24:10 +053053 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070054
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070055 virtual ~AudioPolicyManagerCustom() {}
Mingming Yin0ae14ea2014-07-09 17:55:56 -070056
Sharad Sanglef2e11662015-05-28 16:15:16 +053057 status_t setDeviceConnectionStateInt(audio_devices_t device,
58 audio_policy_dev_state_t state,
59 const char *device_address,
60 const char *device_name);
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070061 virtual void setPhoneState(audio_mode_t state);
Zhou Songc0d78c22014-06-16 10:48:22 +080062
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -070063
Naresh Tanniru36c08932014-01-27 18:40:53 +053064 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
65
Sharad Sangle78d53242015-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);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070082protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070083
Sharad Sanglef2e11662015-05-28 16:15:16 +053084 status_t checkAndSetVolume(audio_stream_type_t stream,
85 int index,
86 const sp<SwAudioOutputDescriptor>& outputDesc,
87 audio_devices_t device,
88 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070089
Sharad Sanglef2e11662015-05-28 16:15:16 +053090 // selects the most appropriate device on output for current state
91 // must be called every time a condition that affects the device choice for a given output is
92 // changed: connected device, phone state, force use, output start, output stop..
93 // see getDeviceForStrategy() for the use of fromCache parameter
94 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
95 bool fromCache);
96 // returns true if given output is direct output
97 bool isDirectOutput(audio_io_handle_t output);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070098
Sharad Sanglef2e11662015-05-28 16:15:16 +053099 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
100 // the re-evaluation of the output device.
101 status_t startSource(sp<SwAudioOutputDescriptor> outputDesc,
102 audio_stream_type_t stream,
103 audio_devices_t device,
104 uint32_t *delayMs);
105 status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc,
106 audio_stream_type_t stream,
107 bool forceDeviceUpdate);
108 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313
109 // returns 0 if no mute/unmute event happened, the largest latency of the device where 314
110 // the mute/unmute happened 315
111 uint32_t handleEventForBeacon(int){return 0;}
112 uint32_t setBeaconMute(bool){return 0;}
Sharad Sangle78d53242015-06-04 20:24:10 +0530113#ifdef VOICE_CONCURRENCY
114 static audio_output_flags_t getFallBackPath();
115 int mFallBackflag;
116#endif /*VOICE_CONCURRENCY*/
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700117
Sharad Sanglef2e11662015-05-28 16:15:16 +0530118 // handle special cases for sonification strategy while in call: mute streams or replace by
119 // a special tone in the device used for communication
120 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700121 //parameter indicates of HDMI speakers disabled
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700122 bool mHdmiAudioDisabled;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700123 //parameter indicates if HDMI plug in/out detected
124 bool mHdmiAudioEvent;
Pavan Chikkala785b6932014-03-24 18:58:11 +0530125private:
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700126 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
127 int indexInUi);
128 // updates device caching and output for streams that can influence the
129 // routing of notifications
130 void handleNotificationRoutingForStream(audio_stream_type_t stream);
131 static bool isVirtualInputDevice(audio_devices_t device);
132 static bool deviceDistinguishesOnAddress(audio_devices_t device);
133 uint32_t nextUniqueId();
134 // internal method to return the output handle for the given device and format
135 audio_io_handle_t getOutputForDevice(
136 audio_devices_t device,
Sharad Sanglef2e11662015-05-28 16:15:16 +0530137 audio_session_t session,
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700138 audio_stream_type_t stream,
139 uint32_t samplingRate,
140 audio_format_t format,
141 audio_channel_mask_t channelMask,
142 audio_output_flags_t flags,
143 const audio_offload_info_t *offloadInfo);
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700144 // Used for voip + voice concurrency usecase
145 int mPrevPhoneState;
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700146 int mvoice_call_state;
Sharad Sangle78d53242015-06-04 20:24:10 +0530147#ifdef RECORD_PLAY_CONCURRENCY
148 // Used for record + playback concurrency
149 bool mIsInputRequestOnProgress;
150#endif
151
Mingming Yin0670f162014-06-12 16:05:49 -0700152
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700153};
Ravi Kumar Alamandac95fd322014-10-29 20:31:15 -0700154
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700155};