blob: 98f59d37e2862aa7fe3b4aba7c1fc56ab82b3530 [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
François Gaffiedc7553f2018-11-02 10:39:57 +010019#include "EngineBase.h"
Mikhail Naganov47835552019-05-14 10:32:51 -070020#include "EngineInterface.h"
François Gaffie2110e042015-03-24 08:41:51 +010021#include <policy.h>
22
23namespace android
24{
25
26class AudioPolicyManagerObserver;
27
28namespace audio_policy
29{
30
François Gaffiedc7553f2018-11-02 10:39:57 +010031enum 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,
Eric Laurent21777f82019-12-06 18:12:06 -080042 STRATEGY_CALL_ASSISTANT,
François Gaffiedc7553f2018-11-02 10:39:57 +010043};
44
45class Engine : public EngineBase
François Gaffie2110e042015-03-24 08:41:51 +010046{
47public:
48 Engine();
François Gaffiedc7553f2018-11-02 10:39:57 +010049 virtual ~Engine() = default;
François Gaffie2110e042015-03-24 08:41:51 +010050
François Gaffie2110e042015-03-24 08:41:51 +010051private:
François Gaffiedc7553f2018-11-02 10:39:57 +010052 ///
Mikhail Naganov47835552019-05-14 10:32:51 -070053 /// from EngineBase, so from EngineInterface
François Gaffiedc7553f2018-11-02 10:39:57 +010054 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010055 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(
Mikhail Naganovbfac5832019-03-05 16:55:28 -080066 const audio_attributes_t &attr, sp<AudioPolicyMix> *mix = nullptr) const override;
François Gaffiedc7553f2018-11-02 10:39:57 +010067
68 void updateDeviceSelectionCache() override;
69
François Gaffie2110e042015-03-24 08:41:51 +010070private:
71 /* Copy facilities are put private to disable copy. */
72 Engine(const Engine &object);
73 Engine &operator=(const Engine &object);
74
François Gaffie2110e042015-03-24 08:41:51 +010075 status_t setDefaultDevice(audio_devices_t device);
76
Eric Laurent2802b862021-03-01 09:36:16 +010077 void filterOutputDevicesForStrategy(legacy_strategy strategy,
78 DeviceVector& availableOutputDevices,
Eric Laurent6cd5f902021-03-23 18:29:58 +010079 const SwAudioOutputCollection &outputs) const;
80
81 product_strategy_t remapStrategyFromContext(product_strategy_t strategy,
Eric Laurent2802b862021-03-01 09:36:16 +010082 const SwAudioOutputCollection &outputs) const;
83
jiabinf502d152019-08-07 14:43:33 -070084 DeviceVector getDevicesForStrategyInt(legacy_strategy strategy,
85 DeviceVector availableOutputDevices,
jiabinf502d152019-08-07 14:43:33 -070086 const SwAudioOutputCollection &outputs) const;
François Gaffie2110e042015-03-24 08:41:51 +010087
François Gaffiedc7553f2018-11-02 10:39:57 +010088 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const;
François Gaffie2110e042015-03-24 08:41:51 +010089
jiabinf502d152019-08-07 14:43:33 -070090 sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const;
François Gaffie6054a772018-11-06 13:10:58 +010091
Eric Laurent2517af32020-11-25 15:31:27 +010092 product_strategy_t getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const;
93 audio_devices_t getPreferredDeviceTypeForLegacyStrategy(
94 const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const;
95 DeviceVector getPreferredAvailableDevicesForProductStrategy(
96 const DeviceVector& availableOutputDevices, product_strategy_t strategy) const;
97
François Gaffiedc7553f2018-11-02 10:39:57 +010098 DeviceStrategyMap mDevicesForStrategies;
99
100 std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap;
François Gaffie2110e042015-03-24 08:41:51 +0100101};
102} // namespace audio_policy
103} // namespace android
104