blob: b8c9b6e5af12005be0a1edecb58ccc755f47a6f6 [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
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
Sharad Sangleca67a022015-05-28 16:15:16 +053049class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070050{
51
52public:
Sharad Sangleca67a022015-05-28 16:15:16 +053053 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
54 : AudioPolicyManager(clientInterface) {
55 mHdmiAudioDisabled = false;
56 mHdmiAudioEvent = false;}
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070057
Sharad Sangleca67a022015-05-28 16:15:16 +053058 virtual ~AudioPolicyManagerCustom() {}
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070059
Sharad Sangleca67a022015-05-28 16:15:16 +053060 status_t setDeviceConnectionStateInt(audio_devices_t device,
61 audio_policy_dev_state_t state,
62 const char *device_address,
63 const char *device_name);
64 virtual void setPhoneState(audio_mode_t state);
65
66
ApurupaPattapu0c566872014-01-10 14:46:02 -080067 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
Sharad Sangleca67a022015-05-28 16:15:16 +053068
69 // true if given state represents a device in a telephony or VoIP call
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070070protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070071
Sharad Sangleca67a022015-05-28 16:15:16 +053072 status_t checkAndSetVolume(audio_stream_type_t stream,
73 int index,
74 const sp<SwAudioOutputDescriptor>& outputDesc,
75 audio_devices_t device,
76 int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070077
Sharad Sangleca67a022015-05-28 16:15:16 +053078 // selects the most appropriate device on output for current state
79 // must be called every time a condition that affects the device choice for a given output is
80 // changed: connected device, phone state, force use, output start, output stop..
81 // see getDeviceForStrategy() for the use of fromCache parameter
82 audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
83 bool fromCache);
84 // returns true if given output is direct output
Karthik Reddy Katta521934f2014-06-09 12:39:37 +053085 bool isDirectOutput(audio_io_handle_t output);
86
Sharad Sangleca67a022015-05-28 16:15:16 +053087 // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force
88 // the re-evaluation of the output device.
89 status_t startSource(sp<SwAudioOutputDescriptor> outputDesc,
90 audio_stream_type_t stream,
91 audio_devices_t device,
92 uint32_t *delayMs);
93 status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc,
94 audio_stream_type_t stream,
95 bool forceDeviceUpdate);
96 // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON 313
97 // returns 0 if no mute/unmute event happened, the largest latency of the device where 314
98 // the mute/unmute happened 315
99 uint32_t handleEventForBeacon(int){return 0;}
100 uint32_t setBeaconMute(bool){return 0;}
Mingming Yin9d2feb72014-04-29 18:40:21 -0700101
Sharad Sangleca67a022015-05-28 16:15:16 +0530102 // handle special cases for sonification strategy while in call: mute streams or replace by
103 // a special tone in the device used for communication
104 void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
105 //parameter indicates of HDMI speakers disabled
Mingming Yin9d2feb72014-04-29 18:40:21 -0700106 bool mHdmiAudioDisabled;
Mingming Yin9d2feb72014-04-29 18:40:21 -0700107 //parameter indicates if HDMI plug in/out detected
108 bool mHdmiAudioEvent;
Pavan Chikkalae33427d2014-03-24 17:11:50 +0530109private:
Sharad Sangleca67a022015-05-28 16:15:16 +0530110 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
111 int indexInUi);
112 // updates device caching and output for streams that can influence the
113 // routing of notifications
114 void handleNotificationRoutingForStream(audio_stream_type_t stream);
115 static bool isVirtualInputDevice(audio_devices_t device);
116 static bool deviceDistinguishesOnAddress(audio_devices_t device);
117 uint32_t nextUniqueId();
118 // internal method to return the output handle for the given device and format
119 audio_io_handle_t getOutputForDevice(
120 audio_devices_t device,
121 audio_session_t session,
122 audio_stream_type_t stream,
123 uint32_t samplingRate,
124 audio_format_t format,
125 audio_channel_mask_t channelMask,
126 audio_output_flags_t flags,
127 const audio_offload_info_t *offloadInfo);
Mingming Yin9d2feb72014-04-29 18:40:21 -0700128 // Used for voip + voice concurrency usecase
129 int mPrevPhoneState;
Sharad Sangleca67a022015-05-28 16:15:16 +0530130 int mvoice_call_state;
Pavan Chikkalae33427d2014-03-24 17:11:50 +0530131
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700132};
Sharad Sangleca67a022015-05-28 16:15:16 +0530133
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700134};