blob: e37f83f6662325f1880b0d5b7314dd4e6374a693 [file] [log] [blame]
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -07001/*
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -07002 * Copyright (c) 2013-2014, 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
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070021#include <audiopolicy/AudioPolicyManager.h>
22#include <audiopolicy/audio_policy_conf.h>
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070023
24
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070025
26namespace android {
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070027
28// ----------------------------------------------------------------------------
29
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070030class AudioPolicyManagerCustom: public AudioPolicyManager
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070031{
32
33public:
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070034 AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
35 : AudioPolicyManager(clientInterface) {
Mingming Yin0ae14ea2014-07-09 17:55:56 -070036 mHdmiAudioDisabled = false;
37 mHdmiAudioEvent = false; }
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070038
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070039 virtual ~AudioPolicyManagerCustom() {}
Mingming Yin0ae14ea2014-07-09 17:55:56 -070040
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070041 virtual status_t setDeviceConnectionState(audio_devices_t device,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070042 audio_policy_dev_state_t state,
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070043 const char *device_address);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070044 virtual audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device,
45 const char *device_address);
46 virtual void setPhoneState(audio_mode_t state);
47 virtual void setForceUse(audio_policy_force_use_t usage,
48 audio_policy_forced_cfg_t config);
Zhou Songc0d78c22014-06-16 10:48:22 +080049 virtual status_t stopOutput(audio_io_handle_t output,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070050 audio_stream_type_t stream,
Zhou Songc0d78c22014-06-16 10:48:22 +080051 int session = 0);
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070052 virtual audio_io_handle_t getInput(audio_source_t inputSource,
53 uint32_t samplingRate,
54 audio_format_t format,
55 audio_channel_mask_t channelMask,
56 audio_session_t session,
57 audio_input_flags_t flags);
Zhou Songc0d78c22014-06-16 10:48:22 +080058
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070059 // indicates to the audio policy manager that the input starts being used.
60 virtual status_t startInput(audio_io_handle_t input,
61 audio_session_t session);
62
63 // indicates to the audio policy manager that the input stops being used.
64 virtual status_t stopInput(audio_io_handle_t input,
65 audio_session_t session);
66 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
67 int index,
68 audio_devices_t device);
Naresh Tanniru36c08932014-01-27 18:40:53 +053069 virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
70
Mingming Yin0ae14ea2014-07-09 17:55:56 -070071 // true if given state represents a device in a telephony or VoIP call
72 virtual bool isStateInCall(int state);
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070073protected:
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070074 // return the strategy corresponding to a given stream type
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070075 static routing_strategy getStrategy(audio_stream_type_t stream);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070076
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -070077 // return appropriate device for streams handled by the specified strategy according to current
78 // phone state, connected devices...
79 // if fromCache is true, the device is returned from mDeviceForStrategy[],
80 // otherwise it is determine by current state
81 // (device connected,phone state, force use, a2dp output...)
82 // This allows to:
83 // 1 speed up process when the state is stable (when starting or stopping an output)
84 // 2 access to either current device selection (fromCache == true) or
85 // "future" device selection (fromCache == false) when called from a context
86 // where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
87 // before updateDevicesAndOutputs() is called.
88 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070089 bool fromCache);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070090 // select input device corresponding to requested audio source
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070091 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070092
93 // compute the actual volume for a given stream according to the requested index and a particular
94 // device
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070095 virtual float computeVolume(audio_stream_type_t stream, int index,
96 audio_io_handle_t output, audio_devices_t device);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -070097
98 // check that volume change is permitted, compute and send new volume to audio hardware
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -070099 status_t checkAndSetVolume(audio_stream_type_t stream, int index, audio_io_handle_t output,
100 audio_devices_t device, int delayMs = 0, bool force = false);
Ravi Kumar Alamanda88d28cb2013-10-15 16:59:57 -0700101
102 // returns the category the device belongs to with regard to volume curve management
103 static device_category getDeviceCategory(audio_devices_t device);
104
Tanya Finkelde496d82014-03-05 23:59:45 +0200105
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700106 //parameter indicates of HDMI speakers disabled
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700107 bool mHdmiAudioDisabled;
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700108 //parameter indicates if HDMI plug in/out detected
109 bool mHdmiAudioEvent;
Pavan Chikkala785b6932014-03-24 18:58:11 +0530110private:
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700111 static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
112 int indexInUi);
113 // updates device caching and output for streams that can influence the
114 // routing of notifications
115 void handleNotificationRoutingForStream(audio_stream_type_t stream);
116 static bool isVirtualInputDevice(audio_devices_t device);
117 static bool deviceDistinguishesOnAddress(audio_devices_t device);
118 uint32_t nextUniqueId();
119 // internal method to return the output handle for the given device and format
120 audio_io_handle_t getOutputForDevice(
121 audio_devices_t device,
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);
Zhou Songc0d78c22014-06-16 10:48:22 +0800128
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700129 // Used for voip + voice concurrency usecase
130 int mPrevPhoneState;
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700131 int mvoice_call_state;
132#ifdef RECORD_PLAY_CONCURRENCY
133 // Used for record + playback concurrency
134 bool mIsInputRequestOnProgress;
135#endif
Mingming Yin0670f162014-06-12 16:05:49 -0700136
Ravi Kumar Alamanda89a81422013-10-08 23:47:55 -0700137};
Ravi Kumar Alamanda1cf2a592014-10-29 20:31:15 -0700138
Mingming Yin0ae14ea2014-07-09 17:55:56 -0700139};