1 | /* |
2 | Copyright 2018 Google Inc. All Rights Reserved. |
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 | #ifndef RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_ |
18 | #define RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_ |
19 | |
20 | #include <functional> |
21 | #include <unordered_map> |
22 | |
23 | #include "base/constants_and_types.h" |
24 | #include "base/source_parameters.h" |
25 | |
26 | namespace vraudio { |
27 | |
28 | // Class that manages the corresponding parameters of each registered source. |
29 | class SourceParametersManager { |
30 | public: |
31 | // Alias for the parameters process closure type. |
32 | using Process = std::function<void(SourceParameters*)>; |
33 | |
34 | // Registers new source parameters for given |source_id|. |
35 | // |
36 | // @param source_id Source id. |
37 | void Register(SourceId source_id); |
38 | |
39 | // Unregisters the source parameters for given |source_id|. |
40 | // |
41 | // @param source_id Source id. |
42 | void Unregister(SourceId source_id); |
43 | |
44 | // Returns read-only source parameters for given |source_id|. |
45 | // |
46 | // @param source_id Source id. |
47 | // @return Read-only source parameters, nullptr if |source_id| not found. |
48 | const SourceParameters* GetParameters(SourceId source_id) const; |
49 | |
50 | // Returns mutable source parameters for given |source_id|. |
51 | // |
52 | // @param source_id Source id. |
53 | // @return Mutable source parameters, nullptr if |source_id| not found. |
54 | SourceParameters* GetMutableParameters(SourceId source_id); |
55 | |
56 | // Executes given |process| for the parameters of each registered source. |
57 | // |
58 | // @param process Parameters processing method. |
59 | void ProcessAllParameters(const Process& process); |
60 | |
61 | private: |
62 | // Registered source parameters. |
63 | std::unordered_map<SourceId, SourceParameters> parameters_; |
64 | }; |
65 | |
66 | } // namespace vraudio |
67 | |
68 | #endif // RESONANCE_AUDIO_GRAPH_SOURCE_PARAMETERS_MANAGER_H_ |
69 | |