blob: 4f3e620c02f8ee0bde7a3f63d96d3fd7c3b3a3ed [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 ///
Mikhail Naganov9e459d72023-05-05 17:36:39 -070044 status_t loadFromHalConfigWithFallback(
45 const media::audio::common::AudioHalEngineConfig& config) override;
46
47 status_t loadFromXmlConfigWithFallback(const std::string& xmlFilePath = "") override;
Mikhail Naganovabb04782023-05-02 13:56:01 -070048
49 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010050 /// from EngineBase
51 ///
Mikhail Naganov9e459d72023-05-05 17:36:39 -070052 status_t initCheck() override;
François Gaffiedc7553f2018-11-02 10:39:57 +010053
François Gaffiedc7553f2018-11-02 10:39:57 +010054 status_t setPhoneState(audio_mode_t mode) override;
François Gaffie20f06f92015-03-24 09:01:14 +010055
François Gaffiedc7553f2018-11-02 10:39:57 +010056 audio_mode_t getPhoneState() const override;
57
58 status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) override;
59
60 audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) const override;
61
Mikhail Naganov9e459d72023-05-05 17:36:39 -070062 status_t setDeviceConnectionState(const sp<DeviceDescriptor> devDesc,
63 audio_policy_dev_state_t state) override;
François Gaffiedc7553f2018-11-02 10:39:57 +010064
65 DeviceVector getOutputDevicesForAttributes(const audio_attributes_t &attr,
66 const sp<DeviceDescriptor> &preferedDevice = nullptr,
67 bool fromCache = false) const override;
68
69 DeviceVector getOutputDevicesForStream(audio_stream_type_t stream,
70 bool fromCache = false) const override;
71
yuanjiahsu0735bf32021-03-18 08:12:54 +080072 sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
73 uid_t uid = 0,
Jan Sebechlebsky1a80c062022-08-09 15:21:18 +020074 audio_session_t session = AUDIO_SESSION_NONE,
yuanjiahsu0735bf32021-03-18 08:12:54 +080075 sp<AudioPolicyMix> *mix = nullptr)
76 const override;
François Gaffiedc7553f2018-11-02 10:39:57 +010077
Eric Laurent32d01f32022-12-22 16:16:21 +010078 status_t setDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role,
79 const AudioDeviceTypeAddrVector &devices) override;
80
81 status_t removeDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role,
82 const AudioDeviceTypeAddrVector &devices) override;
83 status_t clearDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) override;
84
François Gaffiedc7553f2018-11-02 10:39:57 +010085 ///
86 /// from AudioPolicyPluginInterface
87 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010088 status_t addStream(const std::string &name, audio_stream_type_t stream) override
89 {
90 return add<audio_stream_type_t>(name, stream);
91 }
François Gaffiedc7553f2018-11-02 10:39:57 +010092 status_t addInputSource(const std::string &name, audio_source_t source) override
93 {
94 return add<audio_source_t>(name, source);
95 }
François Gaffiedc7553f2018-11-02 10:39:57 +010096 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
97 const audio_stream_type_t &volumeProfile) override;
98
Francois Gaffiea12de212021-10-22 10:54:33 +020099 bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override;
100
François Gaffief1e95082018-11-02 13:53:31 +0100101 void setDeviceAddressForProductStrategy(product_strategy_t strategy,
102 const std::string &address) override;
103
Francois Gaffiea12de212021-10-22 10:54:33 +0200104 bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override;
François Gaffief1e95082018-11-02 13:53:31 +0100105
106 product_strategy_t getProductStrategyByName(const std::string &name) override
107 {
108 return EngineBase::getProductStrategyByName(name);
109 }
François Gaffie20f06f92015-03-24 09:01:14 +0100110
111private:
Eric Laurent32d01f32022-12-22 16:16:21 +0100112 android::status_t disableDevicesForStrategy(product_strategy_t strategy,
113 const DeviceVector &devicesToDisable);
114 void enableDevicesForStrategy(product_strategy_t strategy, const DeviceVector &devicesToEnable);
115 android::status_t setOutputDevicesConnectionState(const DeviceVector &devices,
116 audio_policy_dev_state_t state);
117
François Gaffie20f06f92015-03-24 09:01:14 +0100118 /* Copy facilities are put private to disable copy. */
119 Engine(const Engine &object);
120 Engine &operator=(const Engine &object);
121
François Gaffie20f06f92015-03-24 09:01:14 +0100122 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
François Gaffie20f06f92015-03-24 09:01:14 +0100123 InputSourceCollection mInputSourceCollection; /**< Input sources indexed by their enum id. */
124
125 template <typename Key>
126 status_t add(const std::string &name, const Key &key);
127
128 template <typename Key>
129 Element<Key> *getFromCollection(const Key &key) const;
130
131 template <typename Key>
132 const Collection<Key> &getCollection() const;
133
134 template <typename Key>
135 Collection<Key> &getCollection();
136
137 template <typename Property, typename Key>
138 Property getPropertyForKey(Key key) const;
139
140 template <typename Property, typename Key>
141 bool setPropertyForKey(const Property &property, const Key &key);
142
Mikhail Naganovabb04782023-05-02 13:56:01 -0700143 status_t loadAudioPolicyEngineConfig(const std::string& xmlFilePath);
François Gaffiedc7553f2018-11-02 10:39:57 +0100144
Francois Gaffie6f52ff92020-08-25 08:53:53 +0200145 DeviceVector getCachedDevices(product_strategy_t ps) const;
François Gaffiedc7553f2018-11-02 10:39:57 +0100146
jiabin29230182023-04-04 21:02:36 +0000147 ///
148 /// from EngineBase
149 ///
150 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const override;
151
François Gaffie20f06f92015-03-24 09:01:14 +0100152 /**
153 * Policy Parameter Manager hidden through a wrapper.
154 */
155 ParameterManagerWrapper *mPolicyParameterMgr;
François Gaffie20f06f92015-03-24 09:01:14 +0100156};
157
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800158} // namespace audio_policy
François Gaffie20f06f92015-03-24 09:01:14 +0100159
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800160} // namespace android