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 "Collection.h" 20 #include "EngineBase.h" 21 #include <AudioPolicyPluginInterface.h> 22 #include <CapEngineConfig.h> 23 #include <EngineInterface.h> 24 25 namespace android { 26 class AudioPolicyManagerObserver; 27 28 namespace audio_policy { 29 30 class ParameterManagerWrapper; 31 class VolumeProfile; 32 33 class Engine : public EngineBase, AudioPolicyPluginInterface 34 { 35 public: 36 Engine(); 37 virtual ~Engine() = default; 38 39 template <class RequestedInterface> 40 RequestedInterface *queryInterface(); 41 42 /// 43 /// from EngineInterface 44 /// 45 status_t loadFromHalConfigWithFallback( 46 const media::audio::common::AudioHalEngineConfig& config) override; 47 48 status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override; 49 50 /// 51 /// from EngineBase 52 /// 53 status_t initCheck() override; 54 55 status_t setPhoneState(audio_mode_t mode) override; 56 57 audio_mode_t getPhoneState() const override; 58 59 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override; 60 61 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override; 62 63 status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, 64 audio_policy_dev_state_t state) override; 65 66 DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr, 67 const sp<DeviceDescriptor> &preferedDevice = nullptr, 68 bool fromCache = false) const override; 69 70 DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, 71 bool fromCache = false) const override; 72 73 sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr, 74 uid_t uid = 0, 75 audio_session_t session = AUDIO_SESSION_NONE, 76 sp<AudioPolicyMix> *mix = nullptr) 77 const override; 78 79 status_t setDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role, 80 const AudioDeviceTypeAddrVector &devices) override; 81 82 status_t removeDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role, 83 const AudioDeviceTypeAddrVector &devices) override; 84 status_t clearDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) override; 85 86 /// 87 /// from AudioPolicyPluginInterface 88 /// addStream(const std::string & name,audio_stream_type_t stream)89 status_t addStream(const std::string &name, audio_stream_type_t stream) override 90 { 91 return add<audio_stream_type_t>(name, stream); 92 } addInputSource(const std::string & name,audio_source_t source)93 status_t addInputSource(const std::string &name, audio_source_t source) override 94 { 95 return add<audio_source_t>(name, source); 96 } 97 bool setVolumeProfileForStream(const audio_stream_type_t &stream, 98 const audio_stream_type_t &volumeProfile) override; 99 100 bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override; 101 102 void setDeviceAddressForProductStrategy(product_strategy_t strategy, 103 const std::string &address) override; 104 105 bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override; 106 getProductStrategyByName(const std::string & name)107 product_strategy_t getProductStrategyByName(const std::string &name) override 108 { 109 return EngineBase::getProductStrategyByName(name); 110 } getProductStrategyName(product_strategy_t id)111 std::string getProductStrategyName(product_strategy_t id) const override { 112 return EngineBase::getProductStrategyName(id); 113 } 114 115 private: 116 template<typename T> 117 status_t loadWithFallback(const T& configSource); 118 119 android::status_t disableDevicesForStrategy(product_strategy_t strategy, 120 const DeviceVector &devicesToDisable); 121 void enableDevicesForStrategy(product_strategy_t strategy, const DeviceVector &devicesToEnable); 122 android::status_t setOutputDevicesConnectionState(const DeviceVector &devices, 123 audio_policy_dev_state_t state); 124 125 /* Copy facilities are put private to disable copy. */ 126 Engine(const Engine &object); 127 Engine &operator=(const Engine &object); 128 129 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ 130 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ 131 132 template <typename Key> 133 status_t add(const std::string &name, const Key &key); 134 135 template <typename Key> 136 Element<Key> *getFromCollection(const Key &key) const; 137 138 template <typename Key> 139 const Collection<Key> &getCollection() const; 140 141 template <typename Key> 142 Collection<Key> &getCollection(); 143 144 template <typename Property, typename Key> 145 Property getPropertyForKey(Key key) const; 146 147 template <typename Property, typename Key> 148 bool setPropertyForKey(const Property &property, const Key &key); 149 150 DeviceVector getCachedDevices(product_strategy_t ps) const; 151 152 /// 153 /// from EngineBase 154 /// 155 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override; 156 157 /** 158 * Policy Parameter Manager hidden through a wrapper. 159 */ 160 ParameterManagerWrapper *mPolicyParameterMgr; 161 }; 162 163 } // namespace audio_policy 164 165 } // namespace android 166