blob: d5083f0937419e00ac1753d597f9cc838acde626 [file] [log] [blame]
François Gaffie20f06f92015-03-24 09:01:14 +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 Gaffie20f06f92015-03-24 09:01:14 +010021#include <AudioPolicyPluginInterface.h>
22#include "Collection.h"
23
François Gaffief19cf792018-05-30 17:22:17 +020024namespace android {
François Gaffie20f06f92015-03-24 09:01:14 +010025class AudioPolicyManagerObserver;
26
François Gaffief19cf792018-05-30 17:22:17 +020027namespace audio_policy {
François Gaffie20f06f92015-03-24 09:01:14 +010028
29class ParameterManagerWrapper;
30class VolumeProfile;
31
François Gaffiedc7553f2018-11-02 10:39:57 +010032class Engine : public EngineBase, AudioPolicyPluginInterface
François Gaffie20f06f92015-03-24 09:01:14 +010033{
34public:
35 Engine();
Mikhail Naganovabb04782023-05-02 13:56:01 -070036 virtual ~Engine() = default;
François Gaffie20f06f92015-03-24 09:01:14 +010037
38 template <class RequestedInterface>
39 RequestedInterface *queryInterface();
40
François Gaffiedc7553f2018-11-02 10:39:57 +010041 ///
Mikhail Naganovabb04782023-05-02 13:56:01 -070042 /// from EngineInterface
43 ///
44 android::status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override;
45
46 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010047 /// from EngineBase
48 ///
49 android::status_t initCheck() override;
50
François Gaffiedc7553f2018-11-02 10:39:57 +010051 status_t setPhoneState(audio_mode_t mode) override;
François Gaffie20f06f92015-03-24 09:01:14 +010052
François Gaffiedc7553f2018-11-02 10:39:57 +010053 audio_mode_t getPhoneState() const override;
54
55 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override;
56
57 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override;
58
59 android::status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
60 audio_policy_dev_state_t state) override;
61
62 DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
63 const sp<DeviceDescriptor> &preferedDevice = nullptr,
64 bool fromCache = false) const override;
65
66 DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
67 bool fromCache = false) const override;
68
yuanjiahsu0735bf32021-03-18 08:12:54 +080069 sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
70 uid_t uid = 0,
71 sp<AudioPolicyMix> *mix = nullptr)
72 const override;
François Gaffiedc7553f2018-11-02 10:39:57 +010073
François Gaffiedc7553f2018-11-02 10:39:57 +010074 ///
75 /// from AudioPolicyPluginInterface
76 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010077 status_t addStream(const std::string &name, audio_stream_type_t stream) override
78 {
79 return add<audio_stream_type_t>(name, stream);
80 }
François Gaffiedc7553f2018-11-02 10:39:57 +010081 status_t addInputSource(const std::string &name, audio_source_t source) override
82 {
83 return add<audio_source_t>(name, source);
84 }
François Gaffiedc7553f2018-11-02 10:39:57 +010085 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
86 const audio_stream_type_t &volumeProfile) override;
87
Francois Gaffiea12de212021-10-22 10:54:33 +020088 bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override;
89
François Gaffief1e95082018-11-02 13:53:31 +010090 void setDeviceAddressForProductStrategy(product_strategy_t strategy,
91 const std::string &address) override;
92
Francois Gaffiea12de212021-10-22 10:54:33 +020093 bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override;
François Gaffief1e95082018-11-02 13:53:31 +010094
95 product_strategy_t getProductStrategyByName(const std::string &name) override
96 {
97 return EngineBase::getProductStrategyByName(name);
98 }
François Gaffie20f06f92015-03-24 09:01:14 +010099
100private:
101 /* Copy facilities are put private to disable copy. */
102 Engine(const Engine &object);
103 Engine &operator=(const Engine &object);
104
François Gaffie20f06f92015-03-24 09:01:14 +0100105 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
François Gaffie20f06f92015-03-24 09:01:14 +0100106 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
107
108 template <typename Key>
109 status_t add(const std::string &name, const Key &key);
110
111 template <typename Key>
112 Element<Key> *getFromCollection(const Key &key) const;
113
114 template <typename Key>
115 const Collection<Key> &getCollection() const;
116
117 template <typename Key>
118 Collection<Key> &getCollection();
119
120 template <typename Property, typename Key>
121 Property getPropertyForKey(Key key) const;
122
123 template <typename Property, typename Key>
124 bool setPropertyForKey(const Property &property, const Key &key);
125
Mikhail Naganovabb04782023-05-02 13:56:01 -0700126 status_t loadAudioPolicyEngineConfig(const std::string& xmlFilePath);
François Gaffiedc7553f2018-11-02 10:39:57 +0100127
Francois Gaffie6f52ff92020-08-25 08:53:53 +0200128 DeviceVector getCachedDevices(product_strategy_t ps) const;
François Gaffiedc7553f2018-11-02 10:39:57 +0100129
jiabin76e829d2023-04-04 21:02:36 +0000130 ///
131 /// from EngineBase
132 ///
133 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override;
134
François Gaffie20f06f92015-03-24 09:01:14 +0100135 /**
136 * Policy Parameter Manager hidden through a wrapper.
137 */
138 ParameterManagerWrapper *mPolicyParameterMgr;
François Gaffie20f06f92015-03-24 09:01:14 +0100139};
140
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800141} // namespace audio_policy
François Gaffie20f06f92015-03-24 09:01:14 +0100142
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800143} // namespace android