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 | |
| 19 | |
| 20 | #include <AudioPolicyManagerInterface.h> |
| 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 | |
| 32 | class Engine |
| 33 | { |
| 34 | public: |
| 35 | Engine(); |
| 36 | virtual ~Engine(); |
| 37 | |
| 38 | template <class RequestedInterface> |
| 39 | RequestedInterface *queryInterface(); |
| 40 | |
| 41 | private: |
| 42 | /// Interface members |
| 43 | class ManagerInterfaceImpl : public AudioPolicyManagerInterface |
| 44 | { |
| 45 | public: |
| 46 | ManagerInterfaceImpl(Engine *policyEngine) |
| 47 | : mPolicyEngine(policyEngine) {} |
| 48 | |
| 49 | virtual android::status_t initCheck() |
| 50 | { |
| 51 | return mPolicyEngine->initCheck(); |
| 52 | } |
| 53 | virtual void setObserver(AudioPolicyManagerObserver *observer) |
| 54 | { |
| 55 | mPolicyEngine->setObserver(observer); |
| 56 | } |
| 57 | virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const |
| 58 | { |
| 59 | return mPolicyEngine->getPropertyForKey<audio_devices_t, audio_source_t>(inputSource); |
| 60 | } |
| 61 | virtual audio_devices_t getDeviceForStrategy(routing_strategy stategy) const; |
| 62 | virtual routing_strategy getStrategyForStream(audio_stream_type_t stream) |
| 63 | { |
| 64 | return mPolicyEngine->getPropertyForKey<routing_strategy, audio_stream_type_t>(stream); |
| 65 | } |
| 66 | virtual routing_strategy getStrategyForUsage(audio_usage_t usage); |
| 67 | virtual status_t setPhoneState(audio_mode_t mode) |
| 68 | { |
| 69 | return mPolicyEngine->setPhoneState(mode); |
| 70 | } |
| 71 | virtual audio_mode_t getPhoneState() const |
| 72 | { |
| 73 | return mPolicyEngine->getPhoneState(); |
| 74 | } |
| 75 | virtual status_t setForceUse(audio_policy_force_use_t usage, |
| 76 | audio_policy_forced_cfg_t config) |
| 77 | { |
| 78 | return mPolicyEngine->setForceUse(usage, config); |
| 79 | } |
| 80 | virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const |
| 81 | { |
| 82 | return mPolicyEngine->getForceUse(usage); |
| 83 | } |
| 84 | virtual android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, |
| 85 | audio_policy_dev_state_t state) |
| 86 | { |
François Gaffie | a3e696d | 2015-12-18 09:38:43 +0100 | [diff] [blame] | 87 | return mPolicyEngine->setDeviceConnectionState(devDesc, state); |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 88 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | Engine *mPolicyEngine; |
| 92 | } mManagerInterface; |
| 93 | |
| 94 | class PluginInterfaceImpl : public AudioPolicyPluginInterface |
| 95 | { |
| 96 | public: |
| 97 | PluginInterfaceImpl(Engine *policyEngine) |
| 98 | : mPolicyEngine(policyEngine) {} |
| 99 | |
| 100 | virtual status_t addStrategy(const std::string &name, routing_strategy strategy) |
| 101 | { |
| 102 | return mPolicyEngine->add<routing_strategy>(name, strategy); |
| 103 | } |
| 104 | virtual status_t addStream(const std::string &name, audio_stream_type_t stream) |
| 105 | { |
| 106 | return mPolicyEngine->add<audio_stream_type_t>(name, stream); |
| 107 | } |
| 108 | virtual status_t addUsage(const std::string &name, audio_usage_t usage) |
| 109 | { |
| 110 | return mPolicyEngine->add<audio_usage_t>(name, usage); |
| 111 | } |
| 112 | virtual status_t addInputSource(const std::string &name, audio_source_t source) |
| 113 | { |
| 114 | return mPolicyEngine->add<audio_source_t>(name, source); |
| 115 | } |
| 116 | virtual bool setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices) |
| 117 | { |
| 118 | return mPolicyEngine->setPropertyForKey<audio_devices_t, routing_strategy>(devices, |
| 119 | strategy); |
| 120 | } |
| 121 | virtual bool setStrategyForStream(const audio_stream_type_t &stream, |
| 122 | routing_strategy strategy) |
| 123 | { |
| 124 | return mPolicyEngine->setPropertyForKey<routing_strategy, audio_stream_type_t>(strategy, |
| 125 | stream); |
| 126 | } |
| 127 | virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream, |
François Gaffie | d1ab2bd | 2015-12-02 18:20:06 +0100 | [diff] [blame] | 128 | const audio_stream_type_t &volumeProfile); |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 129 | |
| 130 | virtual bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy) |
| 131 | { |
| 132 | return mPolicyEngine->setPropertyForKey<routing_strategy, audio_usage_t>(strategy, |
| 133 | usage); |
| 134 | } |
| 135 | virtual bool setDeviceForInputSource(const audio_source_t &inputSource, |
| 136 | audio_devices_t device) |
| 137 | { |
| 138 | return mPolicyEngine->setPropertyForKey<audio_devices_t, audio_source_t>(device, |
| 139 | inputSource); |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | Engine *mPolicyEngine; |
| 144 | } mPluginInterface; |
| 145 | |
| 146 | private: |
| 147 | /* Copy facilities are put private to disable copy. */ |
| 148 | Engine(const Engine &object); |
| 149 | Engine &operator=(const Engine &object); |
| 150 | |
| 151 | void setObserver(AudioPolicyManagerObserver *observer); |
| 152 | |
| 153 | bool setVolumeProfileForStream(const audio_stream_type_t &stream, |
François Gaffie | d0609ad | 2015-12-01 17:56:08 +0100 | [diff] [blame] | 154 | device_category deviceCategory, |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 155 | const VolumeCurvePoints &points); |
| 156 | |
| 157 | status_t initCheck(); |
| 158 | status_t setPhoneState(audio_mode_t mode); |
| 159 | audio_mode_t getPhoneState() const; |
| 160 | status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config); |
| 161 | audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const; |
François Gaffie | a3e696d | 2015-12-18 09:38:43 +0100 | [diff] [blame] | 162 | status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, |
| 163 | audio_policy_dev_state_t state); |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 164 | StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */ |
| 165 | StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ |
| 166 | UsageCollection mUsageCollection; /**< Usages indexed by their enum id. */ |
| 167 | InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ |
| 168 | |
| 169 | template <typename Key> |
| 170 | status_t add(const std::string &name, const Key &key); |
| 171 | |
| 172 | template <typename Key> |
| 173 | Element<Key> *getFromCollection(const Key &key) const; |
| 174 | |
| 175 | template <typename Key> |
| 176 | const Collection<Key> &getCollection() const; |
| 177 | |
| 178 | template <typename Key> |
| 179 | Collection<Key> &getCollection(); |
| 180 | |
| 181 | template <typename Property, typename Key> |
| 182 | Property getPropertyForKey(Key key) const; |
| 183 | |
| 184 | template <typename Property, typename Key> |
| 185 | bool setPropertyForKey(const Property &property, const Key &key); |
| 186 | |
| 187 | /** |
| 188 | * Policy Parameter Manager hidden through a wrapper. |
| 189 | */ |
| 190 | ParameterManagerWrapper *mPolicyParameterMgr; |
| 191 | |
| 192 | AudioPolicyManagerObserver *mApmObserver; |
| 193 | }; |
| 194 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 195 | } // namespace audio_policy |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 196 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 197 | } // namespace android |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 198 | |