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 <AudioPolicyPluginInterface.h> 22 #include "Collection.h" 23 24 namespace android { 25 class AudioPolicyManagerObserver; 26 27 namespace audio_policy { 28 29 class ParameterManagerWrapper; 30 class VolumeProfile; 31 32 class Engine : public EngineBase, AudioPolicyPluginInterface 33 { 34 public: 35 Engine(); 36 virtual ~Engine(); 37 38 template <class RequestedInterface> 39 RequestedInterface *queryInterface(); 40 41 /// 42 /// from EngineBase 43 /// 44 android::status_t initCheck() override; 45 46 status_t setPhoneState(audio_mode_t mode) override; 47 48 audio_mode_t getPhoneState() const override; 49 50 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override; 51 52 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override; 53 54 android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc, 55 audio_policy_dev_state_t state) override; 56 57 DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr, 58 const sp<DeviceDescriptor> &preferedDevice = nullptr, 59 bool fromCache = false) const override; 60 61 DeviceVector getOutputDevicesForStream(audio_stream_type_t stream, 62 bool fromCache = false) const override; 63 64 sp<DeviceDescriptor> getInputDeviceForAttributes( 65 const audio_attributes_t &attr, sp<AudioPolicyMix> *mix = nullptr) const override; 66 67 void updateDeviceSelectionCache() override; 68 69 /// 70 /// from AudioPolicyPluginInterface 71 /// addStream(const std::string & name,audio_stream_type_t stream)72 status_t addStream(const std::string &name, audio_stream_type_t stream) override 73 { 74 return add<audio_stream_type_t>(name, stream); 75 } addInputSource(const std::string & name,audio_source_t source)76 status_t addInputSource(const std::string &name, audio_source_t source) override 77 { 78 return add<audio_source_t>(name, source); 79 } 80 bool setVolumeProfileForStream(const audio_stream_type_t &stream, 81 const audio_stream_type_t &volumeProfile) override; 82 setDeviceForInputSource(const audio_source_t & inputSource,audio_devices_t device)83 bool setDeviceForInputSource(const audio_source_t &inputSource, audio_devices_t device) override 84 { 85 return setPropertyForKey<audio_devices_t, audio_source_t>(device, inputSource); 86 } 87 void setDeviceAddressForProductStrategy(product_strategy_t strategy, 88 const std::string &address) override; 89 90 bool setDeviceTypesForProductStrategy(product_strategy_t strategy, 91 audio_devices_t devices) override; 92 getProductStrategyByName(const std::string & name)93 product_strategy_t getProductStrategyByName(const std::string &name) override 94 { 95 return EngineBase::getProductStrategyByName(name); 96 } 97 98 private: 99 /* Copy facilities are put private to disable copy. */ 100 Engine(const Engine &object); 101 Engine &operator=(const Engine &object); 102 103 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */ 104 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */ 105 106 template <typename Key> 107 status_t add(const std::string &name, const Key &key); 108 109 template <typename Key> 110 Element<Key> *getFromCollection(const Key &key) const; 111 112 template <typename Key> 113 const Collection<Key> &getCollection() const; 114 115 template <typename Key> 116 Collection<Key> &getCollection(); 117 118 template <typename Property, typename Key> 119 Property getPropertyForKey(Key key) const; 120 121 template <typename Property, typename Key> 122 bool setPropertyForKey(const Property &property, const Key &key); 123 124 status_t loadAudioPolicyEngineConfig(); 125 126 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const; 127 128 /** 129 * Policy Parameter Manager hidden through a wrapper. 130 */ 131 ParameterManagerWrapper *mPolicyParameterMgr; 132 133 DeviceStrategyMap mDevicesForStrategies; 134 }; 135 136 } // namespace audio_policy 137 138 } // namespace android 139 140