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(); |
| 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 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 46 | status_t setPhoneState(audio_mode_t mode) 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 | audio_mode_t getPhoneState() const override; |
| 49 | |
| 50 | status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override; |
| 51 | |
| 52 | audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override; |
| 53 | |
| 54 | android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, |
| 55 | audio_policy_dev_state_t state) override; |
| 56 | |
| 57 | DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr, |
| 58 | const sp<DeviceDescriptor> &preferedDevice = nullptr, |
| 59 | bool fromCache = false) const override; |
| 60 | |
| 61 | DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, |
| 62 | bool fromCache = false) const override; |
| 63 | |
yuanjiahsu | 0735bf3 | 2021-03-18 08:12:54 +0800 | [diff] [blame] | 64 | sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr, |
| 65 | uid_t uid = 0, |
| 66 | sp<AudioPolicyMix> *mix = nullptr) |
| 67 | const override; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 68 | |
| 69 | void updateDeviceSelectionCache() override; |
| 70 | |
| 71 | /// |
| 72 | /// from AudioPolicyPluginInterface |
| 73 | /// |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 74 | status_t addStream(const std::string &name, audio_stream_type_t stream) override |
| 75 | { |
| 76 | return add<audio_stream_type_t>(name, stream); |
| 77 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 78 | status_t addInputSource(const std::string &name, audio_source_t source) override |
| 79 | { |
| 80 | return add<audio_source_t>(name, source); |
| 81 | } |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 82 | bool setVolumeProfileForStream(const audio_stream_type_t &stream, |
| 83 | const audio_stream_type_t &volumeProfile) override; |
| 84 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 85 | bool setDeviceForInputSource(const audio_source_t &inputSource, audio_devices_t device) override |
| 86 | { |
| 87 | return setPropertyForKey<audio_devices_t, audio_source_t>(device, inputSource); |
| 88 | } |
François Gaffie | f1e9508 | 2018-11-02 13:53:31 +0100 | [diff] [blame] | 89 | void setDeviceAddressForProductStrategy(product_strategy_t strategy, |
| 90 | const std::string &address) override; |
| 91 | |
| 92 | bool setDeviceTypesForProductStrategy(product_strategy_t strategy, |
| 93 | audio_devices_t devices) override; |
| 94 | |
| 95 | product_strategy_t getProductStrategyByName(const std::string &name) override |
| 96 | { |
| 97 | return EngineBase::getProductStrategyByName(name); |
| 98 | } |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | /* Copy facilities are put private to disable copy. */ |
| 102 | Engine(const Engine &object); |
| 103 | Engine &operator=(const Engine &object); |
| 104 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 105 | StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 106 | InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ |
| 107 | |
| 108 | template <typename Key> |
| 109 | status_t add(const std::string &name, const Key &key); |
| 110 | |
| 111 | template <typename Key> |
| 112 | Element<Key> *getFromCollection(const Key &key) const; |
| 113 | |
| 114 | template <typename Key> |
| 115 | const Collection<Key> &getCollection() const; |
| 116 | |
| 117 | template <typename Key> |
| 118 | Collection<Key> &getCollection(); |
| 119 | |
| 120 | template <typename Property, typename Key> |
| 121 | Property getPropertyForKey(Key key) const; |
| 122 | |
| 123 | template <typename Property, typename Key> |
| 124 | bool setPropertyForKey(const Property &property, const Key &key); |
| 125 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 126 | status_t loadAudioPolicyEngineConfig(); |
| 127 | |
| 128 | DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const; |
| 129 | |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 130 | /** |
| 131 | * Policy Parameter Manager hidden through a wrapper. |
| 132 | */ |
| 133 | ParameterManagerWrapper *mPolicyParameterMgr; |
| 134 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 135 | DeviceStrategyMap mDevicesForStrategies; |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 138 | } // namespace audio_policy |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 139 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 140 | } // namespace android |
François Gaffie | 20f06f9 | 2015-03-24 09:01:14 +0100 | [diff] [blame] | 141 | |