blob: 64a9a010872f0efce6ebd4f76f05b933a9b73f6c [file] [log] [blame]
Uday Kishore Pasupuleti582e0a52016-01-06 19:12:41 -08001/*
2 * Copyright (c) 2013-2015, 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 FLAC_OFFLOAD_ENABLED
28#define AUDIO_FORMAT_FLAC 0x1D000000UL
29#endif
30
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
43#ifndef AUDIO_EXTN_AFE_PROXY_ENABLED
44#define AUDIO_DEVICE_OUT_PROXY 0x1000000
45#endif
46// ----------------------------------------------------------------------------
47
48class AudioPolicyManagerCustom: public AudioPolicyManager
49{
50
51public:
52 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
53
54 virtual ~AudioPolicyManagerCustom() {}
55
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 virtual void setForceUse(audio_policy_force_use_t usage,
62 audio_policy_forced_cfg_t config);
63
64 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
65
66 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);
82
83protected:
84
85#ifdef NON_WEARABLE_TARGET
86 status_t checkAndSetVolume(audio_stream_type_t stream,
87 int index,
88 const sp<AudioOutputDescriptor>& outputDesc,
89 audio_devices_t device,
90 int delayMs = 0, bool force = false);
91#else
92 status_t checkAndSetVolume(audio_stream_type_t stream,
93 int index,
94 const sp<SwAudioOutputDescriptor>& outputDesc,
95 audio_devices_t device,
96 int delayMs = 0, bool force = false);
97#endif
98
99 // selects the most appropriate device on output for current state
100 // must be called every time a condition that affects the device choice for a given output is
101 // changed: connected device, phone state, force use, output start, output stop..
102 // see getDeviceForStrategy() for the use of fromCache parameter
103 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
104 bool fromCache);
105 // returns true if given output is direct output
106 bool isDirectOutput(audio_io_handle_t output);
107
108 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
109 // the re-evaluation of the output device.
110 status_t startSource(sp<AudioOutputDescriptor> outputDesc,
111 audio_stream_type_t stream,
112 audio_devices_t device,
113 uint32_t *delayMs);
114 status_t stopSource(sp<AudioOutputDescriptor> outputDesc,
115 audio_stream_type_t stream,
116 bool forceDeviceUpdate);
117 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313
118 // returns 0 if no mute/unmute event happened, the largest latency of the device where 314
119 // the mute/unmute happened 315
120 uint32_t handleEventForBeacon(int){return 0;}
121 uint32_t setBeaconMute(bool){return 0;}
122#ifdef VOICE_CONCURRENCY
123 static audio_output_flags_t getFallBackPath();
124 int mFallBackflag;
125#endif /*VOICE_CONCURRENCY*/
126
127 // handle special cases for sonification strategy while in call: mute streams or replace by
128 // a special tone in the device used for communication
129 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
130 //parameter indicates of HDMI speakers disabled
131 bool mHdmiAudioDisabled;
132 //parameter indicates if HDMI plug in/out detected
133 bool mHdmiAudioEvent;
134private:
135 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
136 int indexInUi);
137 // updates device caching and output for streams that can influence the
138 // routing of notifications
139 void handleNotificationRoutingForStream(audio_stream_type_t stream);
140 static bool isVirtualInputDevice(audio_devices_t device);
141 static bool deviceDistinguishesOnAddress(audio_devices_t device);
142 uint32_t nextUniqueId();
143 // internal method to return the output handle for the given device and format
144 audio_io_handle_t getOutputForDevice(
145 audio_devices_t device,
146 audio_session_t session,
147 audio_stream_type_t stream,
148 uint32_t samplingRate,
149 audio_format_t format,
150 audio_channel_mask_t channelMask,
151 audio_output_flags_t flags,
152 const audio_offload_info_t *offloadInfo);
153 // Used for voip + voice concurrency usecase
154 int mPrevPhoneState;
155 int mvoice_call_state;
156#ifdef RECORD_PLAY_CONCURRENCY
157 // Used for record + playback concurrency
158 bool mIsInputRequestOnProgress;
159#endif
160
161
162};
163
164};