blob: 6ac20cd8ca6f09ffe9b3c8277dc40652a5fadae5 [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();
36 virtual ~Engine();
37
38 template <class RequestedInterface>
39 RequestedInterface *queryInterface();
40
François Gaffiedc7553f2018-11-02 10:39:57 +010041 ///
42 /// from EngineBase
43 ///
44 android::status_t initCheck() override;
45
François Gaffiedc7553f2018-11-02 10:39:57 +010046 status_t setPhoneState(audio_mode_t mode) override;
François Gaffie20f06f92015-03-24 09:01:14 +010047
François Gaffiedc7553f2018-11-02 10:39:57 +010048 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
yuanjiahsu0735bf32021-03-18 08:12:54 +080064 sp<DeviceDescriptor> getInputDeviceForAttributes(const audio_attributes_t &attr,
65 uid_t uid = 0,
Jan Sebechlebsky1a80c062022-08-09 15:21:18 +020066 audio_session_t session = AUDIO_SESSION_NONE,
yuanjiahsu0735bf32021-03-18 08:12:54 +080067 sp<AudioPolicyMix> *mix = nullptr)
68 const override;
François Gaffiedc7553f2018-11-02 10:39:57 +010069
70 void updateDeviceSelectionCache() override;
71
72 ///
73 /// from AudioPolicyPluginInterface
74 ///
François Gaffiedc7553f2018-11-02 10:39:57 +010075 status_t addStream(const std::string &name, audio_stream_type_t stream) override
76 {
77 return add<audio_stream_type_t>(name, stream);
78 }
François Gaffiedc7553f2018-11-02 10:39:57 +010079 status_t addInputSource(const std::string &name, audio_source_t source) override
80 {
81 return add<audio_source_t>(name, source);
82 }
François Gaffiedc7553f2018-11-02 10:39:57 +010083 bool setVolumeProfileForStream(const audio_stream_type_t &stream,
84 const audio_stream_type_t &volumeProfile) override;
85
Francois Gaffiea12de212021-10-22 10:54:33 +020086 bool setDeviceForInputSource(const audio_source_t &inputSource, uint64_t device) override;
87
François Gaffief1e95082018-11-02 13:53:31 +010088 void setDeviceAddressForProductStrategy(product_strategy_t strategy,
89 const std::string &address) override;
90
Francois Gaffiea12de212021-10-22 10:54:33 +020091 bool setDeviceTypesForProductStrategy(product_strategy_t strategy, uint64_t devices) override;
François Gaffief1e95082018-11-02 13:53:31 +010092
93 product_strategy_t getProductStrategyByName(const std::string &name) override
94 {
95 return EngineBase::getProductStrategyByName(name);
96 }
François Gaffie20f06f92015-03-24 09:01:14 +010097
98private:
99 /* Copy facilities are put private to disable copy. */
100 Engine(const Engine &object);
101 Engine &operator=(const Engine &object);
102
François Gaffie20f06f92015-03-24 09:01:14 +0100103 StreamCollection mStreamCollection; /**< Streams indexed by their enum id. */
François Gaffie20f06f92015-03-24 09:01:14 +0100104 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
François Gaffiedc7553f2018-11-02 10:39:57 +0100124 status_t loadAudioPolicyEngineConfig();
125
126 DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const;
Francois Gaffie6f52ff92020-08-25 08:53:53 +0200127 DeviceVector getCachedDevices(product_strategy_t ps) const;
François Gaffiedc7553f2018-11-02 10:39:57 +0100128
François Gaffie20f06f92015-03-24 09:01:14 +0100129 /**
130 * Policy Parameter Manager hidden through a wrapper.
131 */
132 ParameterManagerWrapper *mPolicyParameterMgr;
133
François Gaffiedc7553f2018-11-02 10:39:57 +0100134 DeviceStrategyMap mDevicesForStrategies;
François Gaffie20f06f92015-03-24 09:01:14 +0100135};
136
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800137} // namespace audio_policy
François Gaffie20f06f92015-03-24 09:01:14 +0100138
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800139} // namespace android
François Gaffie20f06f92015-03-24 09:01:14 +0100140