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