François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <AudioPolicyManagerObserver.h> |
| 20 | #include <RoutingStrategy.h> |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 21 | #include <media/AudioCommonTypes.h> |
| 22 | #include <policy.h> |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 23 | #include <Volume.h> |
| 24 | #include <HwModule.h> |
| 25 | #include <DeviceDescriptor.h> |
| 26 | #include <system/audio.h> |
| 27 | #include <system/audio_policy.h> |
| 28 | #include <utils/Errors.h> |
| 29 | #include <utils/Vector.h> |
| 30 | |
| 31 | namespace android { |
| 32 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 33 | using DeviceStrategyMap = std::map<product_strategy_t, DeviceVector>; |
| 34 | using StrategyVector = std::vector<product_strategy_t>; |
| 35 | |
| 36 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 37 | /** |
| 38 | * This interface is dedicated to the policy manager that a Policy Engine shall implement. |
| 39 | */ |
| 40 | class AudioPolicyManagerInterface |
| 41 | { |
| 42 | public: |
| 43 | /** |
| 44 | * Checks if the engine was correctly initialized. |
| 45 | * |
| 46 | * @return NO_ERROR if initialization has been done correctly, error code otherwise.. |
| 47 | */ |
| 48 | virtual status_t initCheck() = 0; |
| 49 | |
| 50 | /** |
| 51 | * Sets the Manager observer that allows the engine to retrieve information on collection |
| 52 | * of devices, streams, HwModules, ... |
| 53 | * |
| 54 | * @param[in] observer handle on the manager. |
| 55 | */ |
| 56 | virtual void setObserver(AudioPolicyManagerObserver *observer) = 0; |
| 57 | |
| 58 | /** |
| 59 | * Get the input device selected for a given input source. |
| 60 | * |
| 61 | * @param[in] inputSource to get the selected input device associated to |
| 62 | * |
| 63 | * @return selected input device for the given input source, may be none if error. |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 64 | * |
| 65 | * @deprecated use getInputDeviceForAttributes |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 66 | */ |
| 67 | virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const = 0; |
| 68 | |
| 69 | /** |
| 70 | * Get the output device associated to a given strategy. |
| 71 | * |
| 72 | * @param[in] stream type for which the selected ouput device is requested. |
| 73 | * |
| 74 | * @return selected ouput device for the given strategy, may be none if error. |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 75 | * |
| 76 | * @deprecated use getOutputDeviceForAttributes |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 77 | */ |
| 78 | virtual audio_devices_t getDeviceForStrategy(routing_strategy stategy) const = 0; |
| 79 | |
| 80 | /** |
| 81 | * Get the strategy selected for a given stream type. |
| 82 | * |
| 83 | * @param[in] stream: for which the selected strategy followed by is requested. |
| 84 | * |
| 85 | * @return strategy to be followed. |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 86 | * |
| 87 | * @deprecated use getOrderedStreams() / getLinkedStreams() to apply operation on stream |
| 88 | * following same former routing_strategy |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 89 | */ |
| 90 | virtual routing_strategy getStrategyForStream(audio_stream_type_t stream) = 0; |
| 91 | |
| 92 | /** |
| 93 | * Get the strategy selected for a given usage. |
| 94 | * |
| 95 | * @param[in] usage to get the selected strategy followed by. |
| 96 | * |
| 97 | * @return strategy to be followed. |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 98 | * |
| 99 | * @deprecated use getProductStrategyForAttributes |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 100 | */ |
| 101 | virtual routing_strategy getStrategyForUsage(audio_usage_t usage) = 0; |
| 102 | |
| 103 | /** |
| 104 | * Set the Telephony Mode. |
| 105 | * |
| 106 | * @param[in] mode: Android Phone state (normal, ringtone, csv, in communication) |
| 107 | * |
| 108 | * @return NO_ERROR if Telephony Mode set correctly, error code otherwise. |
| 109 | */ |
| 110 | virtual status_t setPhoneState(audio_mode_t mode) = 0; |
| 111 | |
| 112 | /** |
| 113 | * Get the telephony Mode |
| 114 | * |
| 115 | * @return the current telephony mode |
| 116 | */ |
| 117 | virtual audio_mode_t getPhoneState() const = 0; |
| 118 | |
| 119 | /** |
| 120 | * Set Force Use config for a given usage. |
| 121 | * |
| 122 | * @param[in] usage for which a configuration shall be forced. |
| 123 | * @param[in] config wished to be forced for the given usage. |
| 124 | * |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 125 | * @return NO_ERROR if the Force Use config was set correctly, error code otherwise (e.g. config |
| 126 | * not allowed a given usage...) |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 127 | */ |
| 128 | virtual status_t setForceUse(audio_policy_force_use_t usage, |
| 129 | audio_policy_forced_cfg_t config) = 0; |
| 130 | |
| 131 | /** |
| 132 | * Get Force Use config for a given usage. |
| 133 | * |
| 134 | * @param[in] usage for which a configuration shall be forced. |
| 135 | * |
| 136 | * @return config wished to be forced for the given usage. |
| 137 | */ |
| 138 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const = 0; |
| 139 | |
| 140 | /** |
| 141 | * Set the connection state of device(s). |
| 142 | * |
| 143 | * @param[in] devDesc for which the state has changed. |
| 144 | * @param[in] state of availability of this(these) device(s). |
| 145 | * |
| 146 | * @return NO_ERROR if devices criterion updated correctly, error code otherwise. |
| 147 | */ |
| 148 | virtual status_t setDeviceConnectionState(const android::sp<android::DeviceDescriptor> devDesc, |
| 149 | audio_policy_dev_state_t state) = 0; |
| 150 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 151 | /** |
| 152 | * Get the strategy selected for a given audio attributes. |
| 153 | * |
| 154 | * @param[in] audio attributes to get the selected @product_strategy_t followed by. |
| 155 | * |
| 156 | * @return @product_strategy_t to be followed. |
| 157 | */ |
| 158 | virtual product_strategy_t getProductStrategyForAttributes( |
| 159 | const audio_attributes_t &attr) const = 0; |
| 160 | |
| 161 | /** |
| 162 | * @brief getOutputDevicesForAttributes retrieves the devices to be used for given |
| 163 | * audio attributes. |
| 164 | * @param attributes of the output requesting Device(s) selection |
| 165 | * @param preferedDevice valid reference if a prefered device is requested, nullptr otherwise. |
| 166 | * @param fromCache if true, the device is returned from internal cache, |
| 167 | * otherwise it is determined by current state (device connected,phone state, |
| 168 | * force use, a2dp output...) |
| 169 | * @return vector of selected device descriptors. |
| 170 | * Appropriate device for streams handled by the specified audio attributes according |
| 171 | * to current phone state, forced states, connected devices... |
| 172 | * if fromCache is true, the device is returned from internal cache, |
| 173 | * otherwise it is determined by current state (device connected,phone state, force use, |
| 174 | * a2dp output...) |
| 175 | * This allows to: |
| 176 | * 1 speed up process when the state is stable (when starting or stopping an output) |
| 177 | * 2 access to either current device selection (fromCache == true) or |
| 178 | * "future" device selection (fromCache == false) when called from a context |
| 179 | * where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND |
| 180 | * before manager updates its outputs. |
| 181 | */ |
| 182 | virtual DeviceVector getOutputDevicesForAttributes( |
| 183 | const audio_attributes_t &attributes, |
| 184 | const sp<DeviceDescriptor> &preferedDevice = nullptr, |
| 185 | bool fromCache = false) const = 0; |
| 186 | |
| 187 | /** |
| 188 | * @brief getOutputDevicesForStream Legacy function retrieving devices from a stream type. |
| 189 | * @param stream type of the output requesting Device(s) selection |
| 190 | * @param fromCache if true, the device is returned from internal cache, |
| 191 | * otherwise it is determined by current state (device connected,phone state, |
| 192 | * force use, a2dp output...) |
| 193 | * @return appropriate device for streams handled by the specified audio attributes according |
| 194 | * to current phone state, forced states, connected devices... |
| 195 | * if fromCache is true, the device is returned from internal cache, |
| 196 | * otherwise it is determined by current state (device connected,phone state, force use, |
| 197 | * a2dp output...) |
| 198 | * This allows to: |
| 199 | * 1 speed up process when the state is stable (when starting or stopping an output) |
| 200 | * 2 access to either current device selection (fromCache == true) or |
| 201 | * "future" device selection (fromCache == false) when called from a context |
| 202 | * where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND |
| 203 | * before manager updates its outputs. |
| 204 | */ |
| 205 | virtual DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, |
| 206 | bool fromCache = false) const = 0; |
| 207 | |
| 208 | /** |
| 209 | * Get the input device selected for given audio attributes. |
| 210 | * |
| 211 | * @param[in] attr audio attributes to consider |
| 212 | * @param[out] mix to be used if a mix has been installed for the given audio attributes. |
| 213 | * @return selected input device for the audio attributes, may be null if error. |
| 214 | */ |
| 215 | virtual sp<DeviceDescriptor> getInputDeviceForAttributes( |
| 216 | const audio_attributes_t &attr, AudioMix **mix = nullptr) const = 0; |
| 217 | |
| 218 | /** |
| 219 | * Get the legacy stream type for a given audio attributes. |
| 220 | * |
| 221 | * @param[in] audio attributes to get the associated audio_stream_type_t. |
| 222 | * |
| 223 | * @return audio_stream_type_t associated to the attributes. |
| 224 | */ |
| 225 | virtual audio_stream_type_t getStreamTypeForAttributes( |
| 226 | const audio_attributes_t &attr) const = 0; |
| 227 | |
| 228 | /** |
| 229 | * @brief getAttributesForStream get the audio attributes from legacy stream type |
| 230 | * @param stream to consider |
| 231 | * @return audio attributes matching the legacy stream type |
| 232 | */ |
| 233 | virtual audio_attributes_t getAttributesForStreamType(audio_stream_type_t stream) const = 0; |
| 234 | |
| 235 | /** |
| 236 | * @brief getStreamTypesForProductStrategy retrieves the list of legacy stream type following |
| 237 | * the given product strategy |
| 238 | * @param ps product strategy to consider |
| 239 | * @return associated legacy Stream Types vector of the given product strategy |
| 240 | */ |
| 241 | virtual StreamTypeVector getStreamTypesForProductStrategy(product_strategy_t ps) const = 0; |
| 242 | |
| 243 | /** |
| 244 | * @brief getAllAttributesForProductStrategy retrieves all the attributes following the given |
| 245 | * product strategy. Any attributes that "matches" with this one will follow the product |
| 246 | * strategy. |
| 247 | * "matching" means the usage shall match if reference attributes has a defined usage, AND |
| 248 | * content type shall match if reference attributes has a defined content type AND |
| 249 | * flags shall match if reference attributes has defined flags AND |
| 250 | * tags shall match if reference attributes has defined tags. |
| 251 | * @param ps product strategy to consider |
| 252 | * @return vector of product strategy ids, empty if unknown strategy. |
| 253 | */ |
| 254 | virtual AttributesVector getAllAttributesForProductStrategy(product_strategy_t ps) const = 0; |
| 255 | |
| 256 | /** |
| 257 | * @brief getOrderedAudioProductStrategies |
| 258 | * @return priority ordered product strategies to help the AudioPolicyManager evaluating the |
| 259 | * device selection per output according to the prioritized strategies. |
| 260 | */ |
| 261 | virtual StrategyVector getOrderedProductStrategies() const = 0; |
| 262 | |
| 263 | /** |
| 264 | * @brief updateDeviceSelectionCache. Device selection for AudioAttribute / Streams is cached |
| 265 | * in the engine in order to speed up process when the audio system is stable. |
| 266 | * When a device is connected, the android mode is changed, engine is notified and can update |
| 267 | * the cache. |
| 268 | * When starting / stopping an output with a stream that can affect notification, the engine |
| 269 | * needs to update the cache upon this function call. |
| 270 | */ |
| 271 | virtual void updateDeviceSelectionCache() = 0; |
| 272 | |
| 273 | virtual void dump(String8 *dst) const = 0; |
| 274 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 275 | protected: |
| 276 | virtual ~AudioPolicyManagerInterface() {} |
| 277 | }; |
| 278 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 279 | } // namespace android |