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