• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum legacy_strategy {
32     STRATEGY_NONE = -1,
33     STRATEGY_MEDIA,
34     STRATEGY_PHONE,
35     STRATEGY_SONIFICATION,
36     STRATEGY_SONIFICATION_RESPECTFUL,
37     STRATEGY_DTMF,
38     STRATEGY_ENFORCED_AUDIBLE,
39     STRATEGY_TRANSMITTED_THROUGH_SPEAKER,
40     STRATEGY_ACCESSIBILITY,
41     STRATEGY_REROUTING,
42     STRATEGY_CALL_ASSISTANT,
43 };
44 
45 class Engine : public EngineBase
46 {
47 public:
48     Engine();
49     virtual ~Engine() = default;
50 
51 private:
52     ///
53     /// from EngineBase, so from EngineInterface
54     ///
55     status_t setForceUse(audio_policy_force_use_t usage,
56                          audio_policy_forced_cfg_t config) override;
57 
58     DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
59                                                const sp<DeviceDescriptor> &preferedDevice = nullptr,
60                                                bool fromCache = false) const override;
61 
62     DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
63                                            bool fromCache = false) const override;
64 
65     sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
66                                                      uid_t uid = 0,
67                                                      sp<AudioPolicyMix> *mix = nullptr)
68                                                      const override;
69 
70     void updateDeviceSelectionCache() override;
71 
72 private:
73     /* Copy facilities are put private to disable copy. */
74     Engine(const Engine &object);
75     Engine &operator=(const Engine &object);
76 
77     status_t setDefaultDevice(audio_devices_t device);
78 
79     void filterOutputDevicesForStrategy(legacy_strategy strategy,
80                                             DeviceVector& availableOutputDevices,
81                                             const SwAudioOutputCollection &outputs) const;
82 
83     product_strategy_t remapStrategyFromContext(product_strategy_t strategy,
84                                             const SwAudioOutputCollection &outputs) const;
85 
86     DeviceVector getDevicesForStrategyInt(legacy_strategy strategy,
87                                           DeviceVector availableOutputDevices,
88                                           const SwAudioOutputCollection &outputs) const;
89 
90     DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const;
91 
92     sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const;
93 
94     product_strategy_t getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const;
95     audio_devices_t getPreferredDeviceTypeForLegacyStrategy(
96         const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const;
97     DeviceVector getPreferredAvailableDevicesForProductStrategy(
98         const DeviceVector& availableOutputDevices, product_strategy_t strategy) const;
99 
100     DeviceStrategyMap mDevicesForStrategies;
101 
102     std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap;
103 };
104 } // namespace audio_policy
105 } // namespace android
106 
107