blob: 0f44e9b04a0d514b21eb8ed74d3b8b7acc479c39 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Sharad Sangleca67a022015-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 Sangleca67a022015-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
25
Sharad Sangleca67a022015-05-28 16:15:16 +053026namespace android {
27#ifndef FLAC_OFFLOAD_ENABLED
28#define AUDIO_FORMAT_FLAC 0x1D000000UL
29#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070030
Sharad Sangleca67a022015-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
Ramjee Singhae5f8902015-08-19 20:47:12 +053043#ifndef AUDIO_EXTN_AFE_PROXY_ENABLED
Ramjee Singh58a28312015-08-14 14:40:44 +053044#define AUDIO_DEVICE_OUT_PROXY 0x1000000
Sharad Sangleca67a022015-05-28 16:15:16 +053045#endif
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070046// ----------------------------------------------------------------------------
47
Sharad Sangleca67a022015-05-28 16:15:16 +053048class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070049{
50
51public:
Mingming Yin38877802015-10-05 15:24:04 -070052 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070053
Sharad Sangleca67a022015-05-28 16:15:16 +053054 virtual ~AudioPolicyManagerCustom() {}
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070055
Sharad Sangleca67a022015-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);
60 virtual void setPhoneState(audio_mode_t state);
61
ApurupaPattapu0c566872014-01-10 14:46:02 -080062 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
Sharad Sangleca67a022015-05-28 16:15:16 +053063
64 // true if given state represents a device in a telephony or VoIP call
Ramjee Singh58a28312015-08-14 14:40:44 +053065
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070066protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070067
Sharad Sangleca67a022015-05-28 16:15:16 +053068 status_t checkAndSetVolume(audio_stream_type_t stream,
69 int index,
70 const sp<SwAudioOutputDescriptor>& outputDesc,
71 audio_devices_t device,
72 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070073
Sharad Sangleca67a022015-05-28 16:15:16 +053074 // selects the most appropriate device on output for current state
75 // must be called every time a condition that affects the device choice for a given output is
76 // changed: connected device, phone state, force use, output start, output stop..
77 // see getDeviceForStrategy() for the use of fromCache parameter
78 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
79 bool fromCache);
80 // returns true if given output is direct output
Karthik Reddy Katta521934f2014-06-09 12:39:37 +053081 bool isDirectOutput(audio_io_handle_t output);
82
Sharad Sangleca67a022015-05-28 16:15:16 +053083 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
84 // the re-evaluation of the output device.
Ramjee Singh5b022de2015-09-15 18:25:20 +053085 status_t startSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangleca67a022015-05-28 16:15:16 +053086 audio_stream_type_t stream,
87 audio_devices_t device,
88 uint32_t *delayMs);
Ramjee Singh5b022de2015-09-15 18:25:20 +053089 status_t stopSource(sp<AudioOutputDescriptor> outputDesc,
Sharad Sangleca67a022015-05-28 16:15:16 +053090 audio_stream_type_t stream,
91 bool forceDeviceUpdate);
92 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313
93 // returns 0 if no mute/unmute event happened, the largest latency of the device where 314
94 // the mute/unmute happened 315
95 uint32_t handleEventForBeacon(int){return 0;}
96 uint32_t setBeaconMute(bool){return 0;}
Mingming Yin9d2feb72014-04-29 18:40:21 -070097
Sharad Sangleca67a022015-05-28 16:15:16 +053098 // handle special cases for sonification strategy while in call: mute streams or replace by
99 // a special tone in the device used for communication
100 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
101 //parameter indicates of HDMI speakers disabled
Mingming Yin9d2feb72014-04-29 18:40:21 -0700102 bool mHdmiAudioDisabled;
Mingming Yin9d2feb72014-04-29 18:40:21 -0700103 //parameter indicates if HDMI plug in/out detected
104 bool mHdmiAudioEvent;
Pavan Chikkalae33427d2014-03-24 17:11:50 +0530105private:
Sharad Sangleca67a022015-05-28 16:15:16 +0530106 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
107 int indexInUi);
108 // updates device caching and output for streams that can influence the
109 // routing of notifications
110 void handleNotificationRoutingForStream(audio_stream_type_t stream);
111 static bool isVirtualInputDevice(audio_devices_t device);
112 static bool deviceDistinguishesOnAddress(audio_devices_t device);
113 uint32_t nextUniqueId();
114 // internal method to return the output handle for the given device and format
115 audio_io_handle_t getOutputForDevice(
116 audio_devices_t device,
117 audio_session_t session,
118 audio_stream_type_t stream,
119 uint32_t samplingRate,
120 audio_format_t format,
121 audio_channel_mask_t channelMask,
122 audio_output_flags_t flags,
123 const audio_offload_info_t *offloadInfo);
Mingming Yin9d2feb72014-04-29 18:40:21 -0700124 // Used for voip + voice concurrency usecase
125 int mPrevPhoneState;
Sharad Sangleca67a022015-05-28 16:15:16 +0530126 int mvoice_call_state;
Pavan Chikkalae33427d2014-03-24 17:11:50 +0530127
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700128};
Sharad Sangleca67a022015-05-28 16:15:16 +0530129
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700130};