• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <memory>
20 
21 #include "Collection.h"
22 #include "EngineBase.h"
23 #include <AudioPolicyPluginInterface.h>
24 #include <CapEngineConfig.h>
25 #include <EngineInterface.h>
26 #include <ParameterManagerWrapper.h>
27 
28 namespace android {
29 class AudioPolicyManagerObserver;
30 
31 namespace audio_policy {
32 
33 class VolumeProfile;
34 
35 class Engine : public EngineBase, AudioPolicyPluginInterface
36 {
37 public:
38     Engine() = default;
39     virtual ~Engine() = default;
40 
41     template <class RequestedInterface>
42     RequestedInterface *queryInterface();
43 
44     ///
45     /// from EngineInterface
46     ///
47     status_t loadFromHalConfigWithFallback(
48             const media::audio::common::AudioHalEngineConfig& config) override;
49 
50     status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override;
51 
52     ///
53     /// from EngineBase
54     ///
55     status_t initCheck() override;
56 
57     status_t setPhoneState(audio_mode_t mode) override;
58 
59     audio_mode_t getPhoneState() const override;
60 
61     status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override;
62 
63     audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override;
64 
65     status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
66                                       audio_policy_dev_state_t state) override;
67 
68     DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
69                                                const sp<DeviceDescriptor> &preferedDevice = nullptr,
70                                                bool fromCache = false) const override;
71 
72     DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
73                                            bool fromCache = false) const override;
74 
75     sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
76                                                      bool ignorePreferredDevice = true,
77                                                      uid_t uid = 0,
78                                                      audio_session_t session = AUDIO_SESSION_NONE,
79                                                      sp<AudioPolicyMix> *mix = nullptr)
80                                                      const override;
81 
82     status_t setDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role,
83                                        const AudioDeviceTypeAddrVector &devices) override;
84 
85     status_t removeDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role,
86                 const AudioDeviceTypeAddrVector &devices) override;
87     status_t clearDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) override;
88 
89     ///
90     /// from AudioPolicyPluginInterface
91     ///
addStream(const std::string & name,audio_stream_type_t stream)92     status_t addStream(const std::string &name, audio_stream_type_t stream) override
93     {
94         return add<audio_stream_type_t>(name, stream);
95     }
addInputSource(const std::string & name,audio_source_t source)96     status_t addInputSource(const std::string &name, audio_source_t source) override
97     {
98         return add<audio_source_t>(name, source);
99     }
100     bool setVolumeProfileForStream(const audio_stream_type_t &stream,
101                                    const audio_stream_type_t &volumeProfile) override;
102 
103     bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override;
104 
105     void setDeviceAddressForProductStrategy(product_strategy_t strategy,
106                                                     const std::string &address) override;
107 
108     bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override;
109 
getProductStrategyByName(const std::string & name)110     product_strategy_t getProductStrategyByName(const std::string &name) override
111     {
112         return EngineBase::getProductStrategyByName(name);
113     }
getProductStrategyName(product_strategy_t id)114     std::string getProductStrategyName(product_strategy_t id) const override {
115         return EngineBase::getProductStrategyName(id);
116     }
117 
118 private:
119     template<typename T>
120     status_t loadWithFallback(const T& configSource);
121 
122     android::status_t disableDevicesForStrategy(product_strategy_t strategy,
123             const DeviceVector &devicesToDisable);
124     void enableDevicesForStrategy(product_strategy_t strategy, const DeviceVector &devicesToEnable);
125     android::status_t setOutputDevicesConnectionState(const DeviceVector &devices,
126                                                       audio_policy_dev_state_t state);
127 
128     /* Copy facilities are put private to disable copy. */
129     Engine(const Engine &object);
130     Engine &operator=(const Engine &object);
131 
132     StreamCollection mStreamCollection; /**< Streams indexed by their enum id.  */
133     InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
134 
135     template <typename Key>
136     status_t add(const std::string &name, const Key &key);
137 
138     template <typename Key>
139     Element<Key> *getFromCollection(const Key &key) const;
140 
141     template <typename Key>
142     const Collection<Key> &getCollection() const;
143 
144     template <typename Key>
145     Collection<Key> &getCollection();
146 
147     template <typename Property, typename Key>
148     Property getPropertyForKey(Key key) const;
149 
150     template <typename Property, typename Key>
151     bool setPropertyForKey(const Property &property, const Key &key);
152 
153     DeviceVector getCachedDevices(product_strategy_t ps) const;
154 
155     ///
156     /// from EngineBase
157     ///
158     DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override;
159 
160     /**
161      * Policy Parameter Manager hidden through a wrapper.
162      */
163     std::unique_ptr<ParameterManagerWrapper> mPolicyParameterMgr;
164 };
165 
166 } // namespace audio_policy
167 
168 } // namespace android
169