xref: /aosp_15_r20/frameworks/av/services/audiopolicy/enginedefault/src/Engine.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
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 #include "EngineBase.h"
20 #include "EngineInterface.h"
21 #include <policy.h>
22 
23 namespace android
24 {
25 
26 class AudioPolicyManagerObserver;
27 
28 namespace audio_policy
29 {
30 
31 class Engine : public EngineBase
32 {
33 public:
34     Engine() = default;
35     virtual ~Engine() = default;
36     Engine(const Engine &object) = delete;
37     Engine &operator=(const Engine &object) = delete;
38 
39     ///
40     /// from EngineInterface
41     ///
42     status_t loadFromHalConfigWithFallback(
43             const media::audio::common::AudioHalEngineConfig& config) override;
44     status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override;
45 
46 private:
47     ///
48     /// from EngineBase, so from EngineInterface
49     ///
50     status_t setForceUse(audio_policy_force_use_t usage,
51                          audio_policy_forced_cfg_t config) override;
52 
53     DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
54                                                const sp<DeviceDescriptor> &preferedDevice = nullptr,
55                                                bool fromCache = false) const override;
56 
57     DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
58                                            bool fromCache = false) const override;
59 
60     sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
61                                                      uid_t uid = 0,
62                                                      audio_session_t session = AUDIO_SESSION_NONE,
63                                                      sp<AudioPolicyMix> *mix = nullptr)
64                                                      const override;
65 
66     void setStrategyDevices(const sp<ProductStrategy>& strategy,
67                             const DeviceVector& devices) override;
68 
69     DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override;
70 
71 private:
72     template<typename T>
73     status_t loadWithFallback(const T& configSource);
74 
75     status_t setDefaultDevice(audio_devices_t device);
76 
77     void filterOutputDevicesForStrategy(legacy_strategy strategy,
78                                             DeviceVector& availableOutputDevices,
79                                             const SwAudioOutputCollection &outputs) const;
80 
81     product_strategy_t remapStrategyFromContext(product_strategy_t strategy,
82                                             const SwAudioOutputCollection &outputs) const;
83 
84     DeviceVector getDevicesForStrategyInt(legacy_strategy strategy,
85                                           DeviceVector availableOutputDevices,
86                                           const SwAudioOutputCollection &outputs) const;
87 
88     sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const;
89 
90     product_strategy_t getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const;
91     audio_devices_t getPreferredDeviceTypeForLegacyStrategy(
92         const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const;
93     DeviceVector getPreferredAvailableDevicesForInputSource(
94             const DeviceVector& availableInputDevices, audio_source_t inputSource) const;
95     DeviceVector getDisabledDevicesForInputSource(
96             const DeviceVector& availableInputDevices, audio_source_t inputSource) const;
97 
98     bool isBtScoActive(DeviceVector& availableOutputDevices) const;
99 
100     std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap;
101 };
102 } // namespace audio_policy
103 } // namespace android
104