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 bool ignorePreferredDevice = true, 62 uid_t uid = 0, 63 audio_session_t session = AUDIO_SESSION_NONE, 64 sp<AudioPolicyMix> *mix = nullptr) 65 const override; 66 67 void setStrategyDevices(const sp<ProductStrategy>& strategy, 68 const DeviceVector& devices) override; 69 70 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override; 71 72 private: 73 template<typename T> 74 status_t loadWithFallback(const T& configSource); 75 76 status_t setDefaultDevice(audio_devices_t device); 77 78 void filterOutputDevicesForStrategy(legacy_strategy strategy, 79 DeviceVector& availableOutputDevices, 80 const SwAudioOutputCollection &outputs) const; 81 82 product_strategy_t remapStrategyFromContext(product_strategy_t strategy, 83 const SwAudioOutputCollection &outputs) const; 84 85 DeviceVector getDevicesForStrategyInt(legacy_strategy strategy, 86 DeviceVector availableOutputDevices, 87 const SwAudioOutputCollection &outputs) const; 88 89 sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const; 90 91 product_strategy_t getProductStrategyFromLegacy(legacy_strategy legacyStrategy) const; 92 audio_devices_t getPreferredDeviceTypeForLegacyStrategy( 93 const DeviceVector& availableOutputDevices, legacy_strategy legacyStrategy) const; 94 DeviceVector getPreferredAvailableDevicesForInputSource( 95 const DeviceVector& availableInputDevices, audio_source_t inputSource) const; 96 DeviceVector getDisabledDevicesForInputSource( 97 const DeviceVector& availableInputDevices, audio_source_t inputSource) const; 98 99 bool isBtScoActive(DeviceVector& availableOutputDevices) const; 100 101 std::map<product_strategy_t, legacy_strategy> mLegacyStrategyMap; 102 }; 103 } // namespace audio_policy 104 } // namespace android 105