François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 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 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 19 | #include "EngineBase.h" |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 20 | #include "EngineInterface.h" |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 21 | #include <policy.h> |
| 22 | |
| 23 | namespace android |
| 24 | { |
| 25 | |
| 26 | class AudioPolicyManagerObserver; |
| 27 | |
| 28 | namespace audio_policy |
| 29 | { |
| 30 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 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, |
Eric Laurent | 21777f8 | 2019-12-06 18:12:06 -0800 | [diff] [blame] | 42 | STRATEGY_CALL_ASSISTANT, |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | class Engine : public EngineBase |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 46 | { |
| 47 | public: |
| 48 | Engine(); |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 49 | virtual ~Engine() = default; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 50 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 51 | private: |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 52 | /// |
Mikhail Naganov | 4783555 | 2019-05-14 10:32:51 -0700 | [diff] [blame] | 53 | /// from EngineBase, so from EngineInterface |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 54 | /// |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 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( |
Mikhail Naganov | bfac583 | 2019-03-05 16:55:28 -0800 | [diff] [blame] | 66 | const audio_attributes_t &attr, sp<AudioPolicyMix> *mix = nullptr) const override; |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 67 | |
| 68 | void updateDeviceSelectionCache() override; |
| 69 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 70 | private: |
| 71 | /* Copy facilities are put private to disable copy. */ |
| 72 | Engine(const Engine &object); |
| 73 | Engine &operator=(const Engine &object); |
| 74 | |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 75 | status_t setDefaultDevice(audio_devices_t device); |
| 76 | |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 77 | void filterOutputDevicesForStrategy(legacy_strategy strategy, |
| 78 | DeviceVector& availableOutputDevices, |
Eric Laurent | 6cd5f90 | 2021-03-23 18:29:58 +0100 | [diff] [blame^] | 79 | const SwAudioOutputCollection &outputs) const; |
| 80 | |
| 81 | product_strategy_t remapStrategyFromContext(product_strategy_t strategy, |
Eric Laurent | 2802b86 | 2021-03-01 09:36:16 +0100 | [diff] [blame] | 82 | const SwAudioOutputCollection &outputs) const; |
| 83 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 84 | DeviceVector getDevicesForStrategyInt(legacy_strategy strategy, |
| 85 | DeviceVector availableOutputDevices, |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 86 | const SwAudioOutputCollection &outputs) const; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 87 | |
François Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 88 | DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 89 | |
jiabin | f502d15 | 2019-08-07 14:43:33 -0700 | [diff] [blame] | 90 | sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const; |
François Gaffie | 6054a77 | 2018-11-06 13:10:58 +0100 | [diff] [blame] | 91 | |
Eric Laurent | 2517af3 | 2020-11-25 15:31:27 +0100 | [diff] [blame] | 92 | 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 Gaffie | dc7553f | 2018-11-02 10:39:57 +0100 | [diff] [blame] | 98 | DeviceStrategyMap mDevicesForStrategies; |
| 99 | |
| 100 | std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap; |
François Gaffie | 2110e04 | 2015-03-24 08:41:51 +0100 | [diff] [blame] | 101 | }; |
| 102 | } // namespace audio_policy |
| 103 | } // namespace android |
| 104 | |