• 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 "AudioPolicyManagerInterface.h"
21 #include <AudioGain.h>
22 #include <policy.h>
23 
24 namespace android
25 {
26 
27 class AudioPolicyManagerObserver;
28 
29 namespace audio_policy
30 {
31 
32 enum legacy_strategy {
33     STRATEGY_NONE = -1,
34     STRATEGY_MEDIA,
35     STRATEGY_PHONE,
36     STRATEGY_SONIFICATION,
37     STRATEGY_SONIFICATION_RESPECTFUL,
38     STRATEGY_DTMF,
39     STRATEGY_ENFORCED_AUDIBLE,
40     STRATEGY_TRANSMITTED_THROUGH_SPEAKER,
41     STRATEGY_ACCESSIBILITY,
42     STRATEGY_REROUTING,
43 };
44 
45 class Engine : public EngineBase
46 {
47 public:
48     Engine();
49     virtual ~Engine() = default;
50 
51     template <class RequestedInterface>
52     RequestedInterface *queryInterface();
53 
54 private:
55     ///
56     /// from EngineBase, so from AudioPolicyManagerInterface
57     ///
58     status_t setForceUse(audio_policy_force_use_t usage,
59                          audio_policy_forced_cfg_t config) override;
60 
61     DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
62                                                const sp<DeviceDescriptor> &preferedDevice = nullptr,
63                                                bool fromCache = false) const override;
64 
65     DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
66                                            bool fromCache = false) const override;
67 
68     sp<DeviceDescriptor> getInputDeviceForAttributes(
69             const audio_attributes_t &attr, sp<AudioPolicyMix> *mix = nullptr) const override;
70 
71     void updateDeviceSelectionCache() override;
72 
73 private:
74     /* Copy facilities are put private to disable copy. */
75     Engine(const Engine &object);
76     Engine &operator=(const Engine &object);
77 
78     status_t setDefaultDevice(audio_devices_t device);
79 
80     audio_devices_t getDeviceForStrategyInt(legacy_strategy strategy,
81                                             DeviceVector availableOutputDevices,
82                                             DeviceVector availableInputDevices,
83                                             const SwAudioOutputCollection &outputs,
84                                             uint32_t outputDeviceTypesToIgnore) const;
85 
86     DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const;
87 
88     audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const;
89 
90     DeviceStrategyMap mDevicesForStrategies;
91 
92     std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap;
93 };
94 } // namespace audio_policy
95 } // namespace android
96 
97