Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 1 | /* |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 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 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 21 | #include <audiopolicy/AudioPolicyManager.h> |
| 22 | #include <audiopolicy/audio_policy_conf.h> |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 23 | |
| 24 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 25 | |
| 26 | namespace android { |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 27 | |
| 28 | // ---------------------------------------------------------------------------- |
| 29 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 30 | class AudioPolicyManagerCustom: public AudioPolicyManager |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 31 | { |
| 32 | |
| 33 | public: |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 34 | AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface) |
| 35 | : AudioPolicyManager(clientInterface) { |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 36 | mHdmiAudioDisabled = false; |
| 37 | mHdmiAudioEvent = false; } |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 38 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 39 | virtual ~AudioPolicyManagerCustom() {} |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 40 | |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 41 | virtual status_t setDeviceConnectionState(audio_devices_t device, |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 42 | audio_policy_dev_state_t state, |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 43 | const char *device_address); |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 44 | 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 Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 49 | virtual status_t stopOutput(audio_io_handle_t output, |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 50 | audio_stream_type_t stream, |
Zhou Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 51 | int session = 0); |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 52 | 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 Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 58 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 59 | // 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 Tanniru | 36c0893 | 2014-01-27 18:40:53 +0530 | [diff] [blame] | 69 | virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); |
| 70 | |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 71 | // true if given state represents a device in a telephony or VoIP call |
| 72 | virtual bool isStateInCall(int state); |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 73 | protected: |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 74 | // return the strategy corresponding to a given stream type |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 75 | static routing_strategy getStrategy(audio_stream_type_t stream); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 76 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 77 | // 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 Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 89 | bool fromCache); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 90 | // select input device corresponding to requested audio source |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 91 | virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 92 | |
| 93 | // compute the actual volume for a given stream according to the requested index and a particular |
| 94 | // device |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 95 | virtual float computeVolume(audio_stream_type_t stream, int index, |
| 96 | audio_io_handle_t output, audio_devices_t device); |
Ravi Kumar Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 97 | |
| 98 | // check that volume change is permitted, compute and send new volume to audio hardware |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 99 | 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 Alamanda | 88d28cb | 2013-10-15 16:59:57 -0700 | [diff] [blame] | 101 | |
| 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 Finkel | de496d8 | 2014-03-05 23:59:45 +0200 | [diff] [blame] | 105 | |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 106 | //parameter indicates of HDMI speakers disabled |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 107 | bool mHdmiAudioDisabled; |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 108 | //parameter indicates if HDMI plug in/out detected |
| 109 | bool mHdmiAudioEvent; |
Pavan Chikkala | 785b693 | 2014-03-24 18:58:11 +0530 | [diff] [blame] | 110 | private: |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 111 | 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 Song | c0d78c2 | 2014-06-16 10:48:22 +0800 | [diff] [blame] | 128 | |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 129 | // Used for voip + voice concurrency usecase |
| 130 | int mPrevPhoneState; |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 131 | int mvoice_call_state; |
| 132 | #ifdef RECORD_PLAY_CONCURRENCY |
| 133 | // Used for record + playback concurrency |
| 134 | bool mIsInputRequestOnProgress; |
| 135 | #endif |
Mingming Yin | 0670f16 | 2014-06-12 16:05:49 -0700 | [diff] [blame] | 136 | |
Ravi Kumar Alamanda | 89a8142 | 2013-10-08 23:47:55 -0700 | [diff] [blame] | 137 | }; |
Ravi Kumar Alamanda | c95fd32 | 2014-10-29 20:31:15 -0700 | [diff] [blame^] | 138 | |
Mingming Yin | 0ae14ea | 2014-07-09 17:55:56 -0700 | [diff] [blame] | 139 | }; |