blob: f44556c25d792ddb062b2d659549caf008985a08 [file] [log] [blame]
François Gaffie2110e042015-03-24 08:41:51 +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 "Gains.h"
22#include <AudioGain.h>
23#include <policy.h>
24
25namespace android
26{
27
28class AudioPolicyManagerObserver;
29
30namespace audio_policy
31{
32
33class Engine
34{
35public:
36 Engine();
37 virtual ~Engine();
38
39 template <class RequestedInterface>
40 RequestedInterface *queryInterface();
41
42private:
43 /// Interface members
44 class ManagerInterfaceImpl : public AudioPolicyManagerInterface
45 {
46 public:
47 ManagerInterfaceImpl(Engine *policyEngine)
48 : mPolicyEngine(policyEngine) {}
49
50 virtual void setObserver(AudioPolicyManagerObserver *observer)
51 {
52 mPolicyEngine->setObserver(observer);
53 }
54 virtual status_t initCheck()
55 {
56 return mPolicyEngine->initCheck();
57 }
58 virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const
59 {
60 return mPolicyEngine->getDeviceForInputSource(inputSource);
61 }
62 virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy) const
63 {
64 return mPolicyEngine->getDeviceForStrategy(strategy);
65 }
66 virtual routing_strategy getStrategyForStream(audio_stream_type_t stream)
67 {
68 return mPolicyEngine->getStrategyForStream(stream);
69 }
70 virtual routing_strategy getStrategyForUsage(audio_usage_t usage)
71 {
72 return mPolicyEngine->getStrategyForUsage(usage);
73 }
74 virtual status_t setPhoneState(audio_mode_t mode)
75 {
76 return mPolicyEngine->setPhoneState(mode);
77 }
78 virtual audio_mode_t getPhoneState() const
79 {
80 return mPolicyEngine->getPhoneState();
81 }
82 virtual status_t setForceUse(audio_policy_force_use_t usage,
83 audio_policy_forced_cfg_t config)
84 {
85 return mPolicyEngine->setForceUse(usage, config);
86 }
87 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
88 {
89 return mPolicyEngine->getForceUse(usage);
90 }
91 virtual status_t setDeviceConnectionState(const sp<DeviceDescriptor> /*devDesc*/,
92 audio_policy_dev_state_t /*state*/)
93 {
94 return NO_ERROR;
95 }
96 virtual status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax)
97 {
98 return mPolicyEngine->initStreamVolume(stream, indexMin, indexMax);
99 }
100 virtual void initializeVolumeCurves(bool isSpeakerDrcEnabled)
101 {
102 return mPolicyEngine->initializeVolumeCurves(isSpeakerDrcEnabled);
103 }
104 virtual float volIndexToAmpl(Volume::device_category deviceCategory,
105 audio_stream_type_t stream,int indexInUi)
106 {
107 return mPolicyEngine->volIndexToAmpl(deviceCategory, stream, indexInUi);
108 }
109 private:
110 Engine *mPolicyEngine;
111 } mManagerInterface;
112
113private:
114 /* Copy facilities are put private to disable copy. */
115 Engine(const Engine &object);
116 Engine &operator=(const Engine &object);
117
118 void setObserver(AudioPolicyManagerObserver *observer);
119
120 status_t initCheck();
121
122 inline bool isInCall() const
123 {
124 return is_state_in_call(mPhoneState);
125 }
126
127 status_t setPhoneState(audio_mode_t mode);
128 audio_mode_t getPhoneState() const
129 {
130 return mPhoneState;
131 }
132 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
133 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const
134 {
135 return mForceUse[usage];
136 }
137 status_t setDefaultDevice(audio_devices_t device);
138
139 routing_strategy getStrategyForStream(audio_stream_type_t stream);
140 routing_strategy getStrategyForUsage(audio_usage_t usage);
141 audio_devices_t getDeviceForStrategy(routing_strategy strategy) const;
142 audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const;
143
144 float volIndexToAmpl(Volume::device_category category,
145 audio_stream_type_t stream, int indexInUi);
146 status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
147 void initializeVolumeCurves(bool isSpeakerDrcEnabled);
148
149 audio_mode_t mPhoneState; /**< current phone state. */
150
151 /** current forced use configuration. */
152 audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT];
153
154 AudioPolicyManagerObserver *mApmObserver;
155};
156} // namespace audio_policy
157} // namespace android
158