François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +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 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 19 | #include "EngineBase.h" |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 20 | #include <EngineInterface.h> |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 21 | #include <AudioPolicyPluginInterface.h> |
| 22 | #include "Collection.h" |
| 23 | |
François Gaffie | f19cf79 | 2018-05-30 17:22:17 +0200 | [diff] [blame] | 24 | namespace android { |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 25 | class AudioPolicyManagerObserver; |
| 26 | |
François Gaffie | f19cf79 | 2018-05-30 17:22:17 +0200 | [diff] [blame] | 27 | namespace audio_policy { |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 28 | |
| 29 | class ParameterManagerWrapper; |
| 30 | class VolumeProfile; |
| 31 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 32 | class Engine : public EngineBase, AudioPolicyPluginInterface |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 33 | { |
| 34 | public: |
| 35 | Engine(); |
Mikhail Naganov | abb0478 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 36 | virtual ~Engine() = default; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 37 | |
| 38 | template <class RequestedInterface> |
| 39 | RequestedInterface *queryInterface(); |
| 40 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 41 | /// |
Mikhail Naganov | abb0478 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 42 | /// from EngineInterface |
| 43 | /// |
Mikhail Naganov | 9e459d7 | 2023-05-05 17:36:39 -0700 | [diff] [blame] | 44 | status_t loadFromHalConfigWithFallback( |
| 45 | const media::audio::common::AudioHalEngineConfig& config) override; |
| 46 | |
| 47 | status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override; |
Mikhail Naganov | abb0478 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 48 | |
| 49 | /// |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 50 | /// from EngineBase |
| 51 | /// |
Mikhail Naganov | 9e459d7 | 2023-05-05 17:36:39 -0700 | [diff] [blame] | 52 | status_t initCheck() override; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 53 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 54 | status_t setPhoneState(audio_mode_t mode) override; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 55 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 56 | audio_mode_t getPhoneState() const override; |
| 57 | |
| 58 | status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override; |
| 59 | |
| 60 | audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override; |
| 61 | |
Mikhail Naganov | 9e459d7 | 2023-05-05 17:36:39 -0700 | [diff] [blame] | 62 | status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, |
| 63 | audio_policy_dev_state_t state) override; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 64 | |
| 65 | DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr, |
| 66 | const sp<DeviceDescriptor> &preferedDevice = nullptr, |
| 67 | bool fromCache = false) const override; |
| 68 | |
| 69 | DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, |
| 70 | bool fromCache = false) const override; |
| 71 | |
yuanjiahsu | 0735bf3 | 2021-03-18 08:12:54 +0800 | [diff] [blame] | 72 | sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr, |
| 73 | uid_t uid = 0, |
Jan Sebechlebsky | 1a80c06 | 2022-08-09 15:21:18 +0200 | [diff] [blame] | 74 | audio_session_t session = AUDIO_SESSION_NONE, |
yuanjiahsu | 0735bf3 | 2021-03-18 08:12:54 +0800 | [diff] [blame] | 75 | sp<AudioPolicyMix> *mix = nullptr) |
| 76 | const override; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 77 | |
Eric Laurent | 32d01f3 | 2022-12-22 16:16:21 +0100 | [diff] [blame] | 78 | status_t setDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role, |
| 79 | const AudioDeviceTypeAddrVector &devices) override; |
| 80 | |
| 81 | status_t removeDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role, |
| 82 | const AudioDeviceTypeAddrVector &devices) override; |
| 83 | status_t clearDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) override; |
| 84 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 85 | /// |
| 86 | /// from AudioPolicyPluginInterface |
| 87 | /// |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 88 | status_t addStream(const std::string &name, audio_stream_type_t stream) override |
| 89 | { |
| 90 | return add<audio_stream_type_t>(name, stream); |
| 91 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 92 | status_t addInputSource(const std::string &name, audio_source_t source) override |
| 93 | { |
| 94 | return add<audio_source_t>(name, source); |
| 95 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 96 | bool setVolumeProfileForStream(const audio_stream_type_t &stream, |
| 97 | const audio_stream_type_t &volumeProfile) override; |
| 98 | |
Francois Gaffie | a12de21 | 2021-10-22 10:54:33 +0200 | [diff] [blame] | 99 | bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override; |
| 100 | |
François Gaffie | f1e9508 | 2018-11-02 13:53:31 +0100 | [diff] [blame] | 101 | void setDeviceAddressForProductStrategy(product_strategy_t strategy, |
| 102 | const std::string &address) override; |
| 103 | |
Francois Gaffie | a12de21 | 2021-10-22 10:54:33 +0200 | [diff] [blame] | 104 | bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override; |
François Gaffie | f1e9508 | 2018-11-02 13:53:31 +0100 | [diff] [blame] | 105 | |
| 106 | product_strategy_t getProductStrategyByName(const std::string &name) override |
| 107 | { |
| 108 | return EngineBase::getProductStrategyByName(name); |
| 109 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 110 | |
| 111 | private: |
Eric Laurent | 32d01f3 | 2022-12-22 16:16:21 +0100 | [diff] [blame] | 112 | android::status_t disableDevicesForStrategy(product_strategy_t strategy, |
| 113 | const DeviceVector &devicesToDisable); |
| 114 | void enableDevicesForStrategy(product_strategy_t strategy, const DeviceVector &devicesToEnable); |
| 115 | android::status_t setOutputDevicesConnectionState(const DeviceVector &devices, |
| 116 | audio_policy_dev_state_t state); |
| 117 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 118 | /* Copy facilities are put private to disable copy. */ |
| 119 | Engine(const Engine &object); |
| 120 | Engine &operator=(const Engine &object); |
| 121 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 122 | StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 123 | InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ |
| 124 | |
| 125 | template <typename Key> |
| 126 | status_t add(const std::string &name, const Key &key); |
| 127 | |
| 128 | template <typename Key> |
| 129 | Element<Key> *getFromCollection(const Key &key) const; |
| 130 | |
| 131 | template <typename Key> |
| 132 | const Collection<Key> &getCollection() const; |
| 133 | |
| 134 | template <typename Key> |
| 135 | Collection<Key> &getCollection(); |
| 136 | |
| 137 | template <typename Property, typename Key> |
| 138 | Property getPropertyForKey(Key key) const; |
| 139 | |
| 140 | template <typename Property, typename Key> |
| 141 | bool setPropertyForKey(const Property &property, const Key &key); |
| 142 | |
Mikhail Naganov | abb0478 | 2023-05-02 13:56:01 -0700 | [diff] [blame] | 143 | status_t loadAudioPolicyEngineConfig(const std::string& xmlFilePath); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 144 | |
Francois Gaffie | 6f52ff9 | 2020-08-25 08:53:53 +0200 | [diff] [blame] | 145 | DeviceVector getCachedDevices(product_strategy_t ps) const; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 146 | |
jiabin | 2923018 | 2023-04-04 21:02:36 +0000 | [diff] [blame] | 147 | /// |
| 148 | /// from EngineBase |
| 149 | /// |
| 150 | DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override; |
| 151 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 152 | /** |
| 153 | * Policy Parameter Manager hidden through a wrapper. |
| 154 | */ |
| 155 | ParameterManagerWrapper *mPolicyParameterMgr; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 156 | }; |
| 157 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 158 | } // namespace audio_policy |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 159 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 160 | } // namespace android |