blob: ba4f8893b9e6ae9178eb827614eeceb5548b0840 [file] [log] [blame]
François Gaffie20f06f92015-03-24 09:01:14 +01001/*
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
François Gaffief19cf792018-05-30 17:22:17 +020024namespace android {
François Gaffie20f06f92015-03-24 09:01:14 +010025class AudioPolicyManagerObserver;
26
François Gaffief19cf792018-05-30 17:22:17 +020027namespace audio_policy {
François Gaffie20f06f92015-03-24 09:01:14 +010028
29class ParameterManagerWrapper;
30class VolumeProfile;
31
32class Engine
33{
34public:
35 Engine();
36 virtual ~Engine();
37
38 template <class RequestedInterface>
39 RequestedInterface *queryInterface();
40
41private:
42 /// Interface members
43 class ManagerInterfaceImpl : public AudioPolicyManagerInterface
44 {
45 public:
46 ManagerInterfaceImpl(Engine *policyEngine)
47 : mPolicyEngine(policyEngine) {}
48
49 virtual android::status_t initCheck()
50 {
51 return mPolicyEngine->initCheck();
52 }
53 virtual void setObserver(AudioPolicyManagerObserver *observer)
54 {
55 mPolicyEngine->setObserver(observer);
56 }
57 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const
58 {
59 return mPolicyEngine->getPropertyForKey<audio_devices_t, audio_source_t>(inputSource);
60 }
61 virtual audio_devices_t getDeviceForStrategy(routing_strategy stategy) const;
62 virtual routing_strategy getStrategyForStream(audio_stream_type_t stream)
63 {
64 return mPolicyEngine->getPropertyForKey<routing_strategy, audio_stream_type_t>(stream);
65 }
66 virtual routing_strategy getStrategyForUsage(audio_usage_t usage);
67 virtual status_t setPhoneState(audio_mode_t mode)
68 {
69 return mPolicyEngine->setPhoneState(mode);
70 }
71 virtual audio_mode_t getPhoneState() const
72 {
73 return mPolicyEngine->getPhoneState();
74 }
75 virtual status_t setForceUse(audio_policy_force_use_t usage,
76 audio_policy_forced_cfg_t config)
77 {
78 return mPolicyEngine->setForceUse(usage, config);
79 }
80 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
81 {
82 return mPolicyEngine->getForceUse(usage);
83 }
84 virtual android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
85 audio_policy_dev_state_t state)
86 {
François Gaffiea3e696d2015-12-18 09:38:43 +010087 return mPolicyEngine->setDeviceConnectionState(devDesc, state);
François Gaffie20f06f92015-03-24 09:01:14 +010088 }
François Gaffie20f06f92015-03-24 09:01:14 +010089
90 private:
91 Engine *mPolicyEngine;
92 } mManagerInterface;
93
94 class PluginInterfaceImpl : public AudioPolicyPluginInterface
95 {
96 public:
97 PluginInterfaceImpl(Engine *policyEngine)
98 : mPolicyEngine(policyEngine) {}
99
100 virtual status_t addStrategy(const std::string &name, routing_strategy strategy)
101 {
102 return mPolicyEngine->add<routing_strategy>(name, strategy);
103 }
104 virtual status_t addStream(const std::string &name, audio_stream_type_t stream)
105 {
106 return mPolicyEngine->add<audio_stream_type_t>(name, stream);
107 }
108 virtual status_t addUsage(const std::string &name, audio_usage_t usage)
109 {
110 return mPolicyEngine->add<audio_usage_t>(name, usage);
111 }
112 virtual status_t addInputSource(const std::string &name, audio_source_t source)
113 {
114 return mPolicyEngine->add<audio_source_t>(name, source);
115 }
116 virtual bool setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices)
117 {
118 return mPolicyEngine->setPropertyForKey<audio_devices_t, routing_strategy>(devices,
119 strategy);
120 }
121 virtual bool setStrategyForStream(const audio_stream_type_t &stream,
122 routing_strategy strategy)
123 {
124 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_stream_type_t>(strategy,
125 stream);
126 }
127 virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream,
François Gaffied1ab2bd2015-12-02 18:20:06 +0100128 const audio_stream_type_t &volumeProfile);
François Gaffie20f06f92015-03-24 09:01:14 +0100129
130 virtual bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy)
131 {
132 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_usage_t>(strategy,
133 usage);
134 }
135 virtual bool setDeviceForInputSource(const audio_source_t &inputSource,
136 audio_devices_t device)
137 {
138 return mPolicyEngine->setPropertyForKey<audio_devices_t, audio_source_t>(device,
139 inputSource);
140 }
141
142 private:
143 Engine *mPolicyEngine;
144 } mPluginInterface;
145
146private:
147 /* Copy facilities are put private to disable copy. */
148 Engine(const Engine &object);
149 Engine &operator=(const Engine &object);
150
151 void setObserver(AudioPolicyManagerObserver *observer);
152
153 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
François Gaffied0609ad2015-12-01 17:56:08 +0100154 device_category deviceCategory,
François Gaffie20f06f92015-03-24 09:01:14 +0100155 const VolumeCurvePoints &points);
156
157 status_t initCheck();
158 status_t setPhoneState(audio_mode_t mode);
159 audio_mode_t getPhoneState() const;
160 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
161 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const;
François Gaffiea3e696d2015-12-18 09:38:43 +0100162 status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
163 audio_policy_dev_state_t state);
François Gaffie20f06f92015-03-24 09:01:14 +0100164 StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */
165 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
166 UsageCollection mUsageCollection; /**< Usages indexed by their enum id. */
167 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
168
169 template <typename Key>
170 status_t add(const std::string &name, const Key &key);
171
172 template <typename Key>
173 Element<Key> *getFromCollection(const Key &key) const;
174
175 template <typename Key>
176 const Collection<Key> &getCollection() const;
177
178 template <typename Key>
179 Collection<Key> &getCollection();
180
181 template <typename Property, typename Key>
182 Property getPropertyForKey(Key key) const;
183
184 template <typename Property, typename Key>
185 bool setPropertyForKey(const Property &property, const Key &key);
186
187 /**
188 * Policy Parameter Manager hidden through a wrapper.
189 */
190 ParameterManagerWrapper *mPolicyParameterMgr;
191
192 AudioPolicyManagerObserver *mApmObserver;
193};
194
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800195} // namespace audio_policy
François Gaffie20f06f92015-03-24 09:01:14 +0100196
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800197} // namespace android
François Gaffie20f06f92015-03-24 09:01:14 +0100198