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" |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 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 | |
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(); |
| 36 | virtual ~Engine(); |
| 37 | |
| 38 | template <class RequestedInterface> |
| 39 | RequestedInterface *queryInterface(); |
| 40 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 41 | /// |
| 42 | /// from EngineBase |
| 43 | /// |
| 44 | android::status_t initCheck() override; |
| 45 | |
| 46 | audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const override |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 47 | { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 48 | return getPropertyForKey<audio_devices_t, audio_source_t>(inputSource); |
| 49 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 50 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 51 | audio_devices_t getDeviceForStrategy(routing_strategy stategy) const override; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 52 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 53 | routing_strategy getStrategyForStream(audio_stream_type_t stream) override |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 54 | { |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 55 | return getPropertyForKey<routing_strategy, audio_stream_type_t>(stream); |
| 56 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 57 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 58 | routing_strategy getStrategyForUsage(audio_usage_t usage) override; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 59 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 60 | status_t setPhoneState(audio_mode_t mode) override; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 61 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 62 | audio_mode_t getPhoneState() const override; |
| 63 | |
| 64 | status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override; |
| 65 | |
| 66 | audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override; |
| 67 | |
| 68 | android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, |
| 69 | audio_policy_dev_state_t state) override; |
| 70 | |
| 71 | DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr, |
| 72 | const sp<DeviceDescriptor> &preferedDevice = nullptr, |
| 73 | bool fromCache = false) const override; |
| 74 | |
| 75 | DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, |
| 76 | bool fromCache = false) const override; |
| 77 | |
| 78 | sp<DeviceDescriptor> getInputDeviceForAttributes( |
| 79 | const audio_attributes_t &attr, AudioMix **mix = nullptr) const override; |
| 80 | |
| 81 | void updateDeviceSelectionCache() override; |
| 82 | |
| 83 | /// |
| 84 | /// from AudioPolicyPluginInterface |
| 85 | /// |
| 86 | status_t addStrategy(const std::string &name, routing_strategy strategy) override |
| 87 | { |
| 88 | return add<routing_strategy>(name, strategy); |
| 89 | } |
| 90 | status_t addStream(const std::string &name, audio_stream_type_t stream) override |
| 91 | { |
| 92 | return add<audio_stream_type_t>(name, stream); |
| 93 | } |
| 94 | status_t addUsage(const std::string &name, audio_usage_t usage) override |
| 95 | { |
| 96 | return add<audio_usage_t>(name, usage); |
| 97 | } |
| 98 | status_t addInputSource(const std::string &name, audio_source_t source) override |
| 99 | { |
| 100 | return add<audio_source_t>(name, source); |
| 101 | } |
| 102 | bool setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices) override |
| 103 | { |
| 104 | return setPropertyForKey<audio_devices_t, routing_strategy>(devices, strategy); |
| 105 | } |
| 106 | bool setStrategyForStream(const audio_stream_type_t &stream, |
| 107 | routing_strategy strategy) override |
| 108 | { |
| 109 | return setPropertyForKey<routing_strategy, audio_stream_type_t>(strategy, stream); |
| 110 | } |
| 111 | bool setVolumeProfileForStream(const audio_stream_type_t &stream, |
| 112 | const audio_stream_type_t &volumeProfile) override; |
| 113 | |
| 114 | bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy) override |
| 115 | { |
| 116 | return setPropertyForKey<routing_strategy, audio_usage_t>(strategy, usage); |
| 117 | } |
| 118 | bool setDeviceForInputSource(const audio_source_t &inputSource, audio_devices_t device) override |
| 119 | { |
| 120 | return setPropertyForKey<audio_devices_t, audio_source_t>(device, inputSource); |
| 121 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 122 | |
| 123 | private: |
| 124 | /* Copy facilities are put private to disable copy. */ |
| 125 | Engine(const Engine &object); |
| 126 | Engine &operator=(const Engine &object); |
| 127 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 128 | StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */ |
| 129 | StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ |
| 130 | UsageCollection mUsageCollection; /**< Usages indexed by their enum id. */ |
| 131 | InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ |
| 132 | |
| 133 | template <typename Key> |
| 134 | status_t add(const std::string &name, const Key &key); |
| 135 | |
| 136 | template <typename Key> |
| 137 | Element<Key> *getFromCollection(const Key &key) const; |
| 138 | |
| 139 | template <typename Key> |
| 140 | const Collection<Key> &getCollection() const; |
| 141 | |
| 142 | template <typename Key> |
| 143 | Collection<Key> &getCollection(); |
| 144 | |
| 145 | template <typename Property, typename Key> |
| 146 | Property getPropertyForKey(Key key) const; |
| 147 | |
| 148 | template <typename Property, typename Key> |
| 149 | bool setPropertyForKey(const Property &property, const Key &key); |
| 150 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 151 | status_t loadAudioPolicyEngineConfig(); |
| 152 | |
| 153 | DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const; |
| 154 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 155 | /** |
| 156 | * Policy Parameter Manager hidden through a wrapper. |
| 157 | */ |
| 158 | ParameterManagerWrapper *mPolicyParameterMgr; |
| 159 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame^] | 160 | DeviceStrategyMap mDevicesForStrategies; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 161 | }; |
| 162 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 163 | } // namespace audio_policy |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 164 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 165 | } // namespace android |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 166 | |