• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 <EngineConfig.h>
20 #include <AudioPolicyManagerInterface.h>
21 #include <ProductStrategy.h>
22 #include <VolumeGroup.h>
23 
24 namespace android {
25 namespace audio_policy {
26 
27 class EngineBase : public AudioPolicyManagerInterface
28 {
29 public:
30     ///
31     /// from AudioPolicyManagerInterface
32     ///
33     android::status_t initCheck() override;
34 
35     void setObserver(AudioPolicyManagerObserver *observer) override;
36 
37     status_t setPhoneState(audio_mode_t mode) override;
38 
getPhoneState()39     audio_mode_t getPhoneState() const override { return mPhoneState; }
40 
setForceUse(audio_policy_force_use_t usage,audio_policy_forced_cfg_t config)41     status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override
42     {
43         mForceUse[usage] = config;
44         return NO_ERROR;
45     }
46 
getForceUse(audio_policy_force_use_t usage)47     audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override
48     {
49         return mForceUse[usage];
50     }
setDeviceConnectionState(const sp<DeviceDescriptor>,audio_policy_dev_state_t)51     android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> /*devDesc*/,
52                                                audio_policy_dev_state_t /*state*/) override
53     {
54         return NO_ERROR;
55     }
56     product_strategy_t getProductStrategyForAttributes(
57             const audio_attributes_t &attr) const override;
58 
59     audio_stream_type_t getStreamTypeForAttributes(const audio_attributes_t &attr) const override;
60 
61     audio_attributes_t getAttributesForStreamType(audio_stream_type_t stream) const override;
62 
63     StreamTypeVector getStreamTypesForProductStrategy(product_strategy_t ps) const override;
64 
65     AttributesVector getAllAttributesForProductStrategy(product_strategy_t ps) const override;
66 
67     StrategyVector getOrderedProductStrategies() const override;
68 
69     status_t listAudioProductStrategies(AudioProductStrategyVector &strategies) const override;
70 
71     VolumeCurves *getVolumeCurvesForAttributes(const audio_attributes_t &attr) const override;
72 
73     VolumeCurves *getVolumeCurvesForStreamType(audio_stream_type_t stream) const override;
74 
getVolumeCurvesForVolumeGroup(volume_group_t group)75     IVolumeCurves *getVolumeCurvesForVolumeGroup(volume_group_t group) const override
76     {
77        return mVolumeGroups.find(group) != end(mVolumeGroups) ?
78                    mVolumeGroups.at(group)->getVolumeCurves() : nullptr;
79     }
80 
81     VolumeGroupVector getVolumeGroups() const override;
82 
83     volume_group_t getVolumeGroupForAttributes(const audio_attributes_t &attr) const override;
84 
85     volume_group_t getVolumeGroupForStreamType(audio_stream_type_t stream) const override;
86 
87     status_t listAudioVolumeGroups(AudioVolumeGroupVector &groups) const override;
88 
89     void dump(String8 *dst) const override;
90 
91 
92     engineConfig::ParsingResult loadAudioPolicyEngineConfig();
93 
getProductStrategies()94     const ProductStrategyMap &getProductStrategies() const { return mProductStrategies; }
95 
getProductStrategies()96     ProductStrategyMap &getProductStrategies() { return mProductStrategies; }
97 
98     product_strategy_t getProductStrategyForStream(audio_stream_type_t stream) const;
99 
100     product_strategy_t getProductStrategyByName(const std::string &name) const;
101 
getApmObserver()102     AudioPolicyManagerObserver *getApmObserver() const { return mApmObserver; }
103 
isInCall()104     inline bool isInCall() const
105     {
106         return is_state_in_call(getPhoneState());
107     }
108 
toVolumeSource(audio_stream_type_t stream)109     VolumeSource toVolumeSource(audio_stream_type_t stream) const
110     {
111         return static_cast<VolumeSource>(getVolumeGroupForStreamType(stream));
112     }
113 
114     status_t switchVolumeCurve(audio_stream_type_t streamSrc, audio_stream_type_t streamDst);
115 
116     status_t restoreOriginVolumeCurve(audio_stream_type_t stream);
117 
118  private:
119     AudioPolicyManagerObserver *mApmObserver = nullptr;
120 
121     ProductStrategyMap mProductStrategies;
122     VolumeGroupMap mVolumeGroups;
123     audio_mode_t mPhoneState = AUDIO_MODE_NORMAL;  /**< current phone state. */
124 
125     /** current forced use configuration. */
126     audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT] = {};
127 };
128 
129 } // namespace audio_policy
130 } // namespace android
131