blob: 8a15e5e1ce0326ef36d44824c15bdfc0759131ba [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
24namespace android
25{
26class AudioPolicyManagerObserver;
27
28namespace audio_policy
29{
30
31class ParameterManagerWrapper;
32class VolumeProfile;
33
34class Engine
35{
36public:
37 Engine();
38 virtual ~Engine();
39
40 template <class RequestedInterface>
41 RequestedInterface *queryInterface();
42
43private:
44 /// Interface members
45 class ManagerInterfaceImpl : public AudioPolicyManagerInterface
46 {
47 public:
48 ManagerInterfaceImpl(Engine *policyEngine)
49 : mPolicyEngine(policyEngine) {}
50
51 virtual android::status_t initCheck()
52 {
53 return mPolicyEngine->initCheck();
54 }
55 virtual void setObserver(AudioPolicyManagerObserver *observer)
56 {
57 mPolicyEngine->setObserver(observer);
58 }
59 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const
60 {
61 return mPolicyEngine->getPropertyForKey<audio_devices_t, audio_source_t>(inputSource);
62 }
63 virtual audio_devices_t getDeviceForStrategy(routing_strategy stategy) const;
64 virtual routing_strategy getStrategyForStream(audio_stream_type_t stream)
65 {
66 return mPolicyEngine->getPropertyForKey<routing_strategy, audio_stream_type_t>(stream);
67 }
68 virtual routing_strategy getStrategyForUsage(audio_usage_t usage);
69 virtual status_t setPhoneState(audio_mode_t mode)
70 {
71 return mPolicyEngine->setPhoneState(mode);
72 }
73 virtual audio_mode_t getPhoneState() const
74 {
75 return mPolicyEngine->getPhoneState();
76 }
77 virtual status_t setForceUse(audio_policy_force_use_t usage,
78 audio_policy_forced_cfg_t config)
79 {
80 return mPolicyEngine->setForceUse(usage, config);
81 }
82 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
83 {
84 return mPolicyEngine->getForceUse(usage);
85 }
86 virtual android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
87 audio_policy_dev_state_t state)
88 {
François Gaffiea3e696d2015-12-18 09:38:43 +010089 return mPolicyEngine->setDeviceConnectionState(devDesc, state);
François Gaffie20f06f92015-03-24 09:01:14 +010090 }
91 virtual status_t initStreamVolume(audio_stream_type_t stream,
92 int indexMin, int indexMax)
93 {
94 return mPolicyEngine->initStreamVolume(stream, indexMin, indexMax);
95 }
96
97 virtual void initializeVolumeCurves(bool /*isSpeakerDrcEnabled*/) {}
98
François Gaffied0609ad2015-12-01 17:56:08 +010099 virtual float volIndexToDb(device_category deviceCategory,
100 audio_stream_type_t stream,
101 int indexInUi)
François Gaffie20f06f92015-03-24 09:01:14 +0100102 {
103 return mPolicyEngine->volIndexToDb(deviceCategory, stream, indexInUi);
104 }
105
106 private:
107 Engine *mPolicyEngine;
108 } mManagerInterface;
109
110 class PluginInterfaceImpl : public AudioPolicyPluginInterface
111 {
112 public:
113 PluginInterfaceImpl(Engine *policyEngine)
114 : mPolicyEngine(policyEngine) {}
115
116 virtual status_t addStrategy(const std::string &name, routing_strategy strategy)
117 {
118 return mPolicyEngine->add<routing_strategy>(name, strategy);
119 }
120 virtual status_t addStream(const std::string &name, audio_stream_type_t stream)
121 {
122 return mPolicyEngine->add<audio_stream_type_t>(name, stream);
123 }
124 virtual status_t addUsage(const std::string &name, audio_usage_t usage)
125 {
126 return mPolicyEngine->add<audio_usage_t>(name, usage);
127 }
128 virtual status_t addInputSource(const std::string &name, audio_source_t source)
129 {
130 return mPolicyEngine->add<audio_source_t>(name, source);
131 }
132 virtual bool setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices)
133 {
134 return mPolicyEngine->setPropertyForKey<audio_devices_t, routing_strategy>(devices,
135 strategy);
136 }
137 virtual bool setStrategyForStream(const audio_stream_type_t &stream,
138 routing_strategy strategy)
139 {
140 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_stream_type_t>(strategy,
141 stream);
142 }
143 virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream,
François Gaffied0609ad2015-12-01 17:56:08 +0100144 device_category deviceCategory,
François Gaffie20f06f92015-03-24 09:01:14 +0100145 const VolumeCurvePoints &points)
146 {
147 return mPolicyEngine->setVolumeProfileForStream(stream, deviceCategory, points);
148 }
149
150 virtual bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy)
151 {
152 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_usage_t>(strategy,
153 usage);
154 }
155 virtual bool setDeviceForInputSource(const audio_source_t &inputSource,
156 audio_devices_t device)
157 {
158 return mPolicyEngine->setPropertyForKey<audio_devices_t, audio_source_t>(device,
159 inputSource);
160 }
161
162 private:
163 Engine *mPolicyEngine;
164 } mPluginInterface;
165
166private:
167 /* Copy facilities are put private to disable copy. */
168 Engine(const Engine &object);
169 Engine &operator=(const Engine &object);
170
171 void setObserver(AudioPolicyManagerObserver *observer);
172
173 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
François Gaffied0609ad2015-12-01 17:56:08 +0100174 device_category deviceCategory,
François Gaffie20f06f92015-03-24 09:01:14 +0100175 const VolumeCurvePoints &points);
176
177 status_t initCheck();
178 status_t setPhoneState(audio_mode_t mode);
179 audio_mode_t getPhoneState() const;
180 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
181 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const;
François Gaffiea3e696d2015-12-18 09:38:43 +0100182 status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
183 audio_policy_dev_state_t state);
François Gaffied0609ad2015-12-01 17:56:08 +0100184 float volIndexToDb(device_category category, audio_stream_type_t stream, int indexInUi);
François Gaffie20f06f92015-03-24 09:01:14 +0100185 status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
186
187 StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */
188 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
189 UsageCollection mUsageCollection; /**< Usages indexed by their enum id. */
190 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
191
192 template <typename Key>
193 status_t add(const std::string &name, const Key &key);
194
195 template <typename Key>
196 Element<Key> *getFromCollection(const Key &key) const;
197
198 template <typename Key>
199 const Collection<Key> &getCollection() const;
200
201 template <typename Key>
202 Collection<Key> &getCollection();
203
204 template <typename Property, typename Key>
205 Property getPropertyForKey(Key key) const;
206
207 template <typename Property, typename Key>
208 bool setPropertyForKey(const Property &property, const Key &key);
209
210 /**
211 * Policy Parameter Manager hidden through a wrapper.
212 */
213 ParameterManagerWrapper *mPolicyParameterMgr;
214
215 AudioPolicyManagerObserver *mApmObserver;
216};
217
218}; // namespace audio_policy
219
220}; // namespace android
221