blob: 6fa7a139b7c94bd8af558441c26bf865f858f676 [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 {
89 return mPolicyEngine->setDeviceConnectionState(devDesc->type(), state,
90 devDesc->mAddress);
91 }
92 virtual status_t initStreamVolume(audio_stream_type_t stream,
93 int indexMin, int indexMax)
94 {
95 return mPolicyEngine->initStreamVolume(stream, indexMin, indexMax);
96 }
97
98 virtual void initializeVolumeCurves(bool /*isSpeakerDrcEnabled*/) {}
99
100 virtual float volIndexToDb(Volume::device_category deviceCategory,
101 audio_stream_type_t stream,
102 int indexInUi)
103 {
104 return mPolicyEngine->volIndexToDb(deviceCategory, stream, indexInUi);
105 }
106
107 private:
108 Engine *mPolicyEngine;
109 } mManagerInterface;
110
111 class PluginInterfaceImpl : public AudioPolicyPluginInterface
112 {
113 public:
114 PluginInterfaceImpl(Engine *policyEngine)
115 : mPolicyEngine(policyEngine) {}
116
117 virtual status_t addStrategy(const std::string &name, routing_strategy strategy)
118 {
119 return mPolicyEngine->add<routing_strategy>(name, strategy);
120 }
121 virtual status_t addStream(const std::string &name, audio_stream_type_t stream)
122 {
123 return mPolicyEngine->add<audio_stream_type_t>(name, stream);
124 }
125 virtual status_t addUsage(const std::string &name, audio_usage_t usage)
126 {
127 return mPolicyEngine->add<audio_usage_t>(name, usage);
128 }
129 virtual status_t addInputSource(const std::string &name, audio_source_t source)
130 {
131 return mPolicyEngine->add<audio_source_t>(name, source);
132 }
133 virtual bool setDeviceForStrategy(const routing_strategy &strategy, audio_devices_t devices)
134 {
135 return mPolicyEngine->setPropertyForKey<audio_devices_t, routing_strategy>(devices,
136 strategy);
137 }
138 virtual bool setStrategyForStream(const audio_stream_type_t &stream,
139 routing_strategy strategy)
140 {
141 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_stream_type_t>(strategy,
142 stream);
143 }
144 virtual bool setVolumeProfileForStream(const audio_stream_type_t &stream,
145 Volume::device_category deviceCategory,
146 const VolumeCurvePoints &points)
147 {
148 return mPolicyEngine->setVolumeProfileForStream(stream, deviceCategory, points);
149 }
150
151 virtual bool setStrategyForUsage(const audio_usage_t &usage, routing_strategy strategy)
152 {
153 return mPolicyEngine->setPropertyForKey<routing_strategy, audio_usage_t>(strategy,
154 usage);
155 }
156 virtual bool setDeviceForInputSource(const audio_source_t &inputSource,
157 audio_devices_t device)
158 {
159 return mPolicyEngine->setPropertyForKey<audio_devices_t, audio_source_t>(device,
160 inputSource);
161 }
162
163 private:
164 Engine *mPolicyEngine;
165 } mPluginInterface;
166
167private:
168 /* Copy facilities are put private to disable copy. */
169 Engine(const Engine &object);
170 Engine &operator=(const Engine &object);
171
172 void setObserver(AudioPolicyManagerObserver *observer);
173
174 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
175 Volume::device_category deviceCategory,
176 const VolumeCurvePoints &points);
177
178 status_t initCheck();
179 status_t setPhoneState(audio_mode_t mode);
180 audio_mode_t getPhoneState() const;
181 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
182 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const;
183 status_t setDeviceConnectionState(audio_devices_t devices, audio_policy_dev_state_t state,
184 const char *deviceAddress);
185
186 float volIndexToDb(Volume::device_category category,
187 audio_stream_type_t stream,
188 int indexInUi);
189 status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
190
191 StrategyCollection mStrategyCollection; /**< Strategies indexed by their enum id. */
192 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
193 UsageCollection mUsageCollection; /**< Usages indexed by their enum id. */
194 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
195
196 template <typename Key>
197 status_t add(const std::string &name, const Key &key);
198
199 template <typename Key>
200 Element<Key> *getFromCollection(const Key &key) const;
201
202 template <typename Key>
203 const Collection<Key> &getCollection() const;
204
205 template <typename Key>
206 Collection<Key> &getCollection();
207
208 template <typename Property, typename Key>
209 Property getPropertyForKey(Key key) const;
210
211 template <typename Property, typename Key>
212 bool setPropertyForKey(const Property &property, const Key &key);
213
214 /**
215 * Policy Parameter Manager hidden through a wrapper.
216 */
217 ParameterManagerWrapper *mPolicyParameterMgr;
218
219 AudioPolicyManagerObserver *mApmObserver;
220};
221
222}; // namespace audio_policy
223
224}; // namespace android
225