• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ST_AUDIO_STREAM_MANAGER_H
17 #define ST_AUDIO_STREAM_MANAGER_H
18 
19 #include <iostream>
20 #include <map>
21 #include "audio_effect.h"
22 #include "audio_system_manager.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 class AudioRendererStateChangeCallback {
27 public:
28     virtual ~AudioRendererStateChangeCallback() = default;
29     /**
30      * Called when the renderer state changes
31      *
32      * @param rendererChangeInfo Contains the renderer state information.
33      */
34     virtual void OnRendererStateChange(
35         const std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) = 0;
36 };
37 
38 class OutputDeviceChangeWithInfoCallback {
39 public:
40     virtual ~OutputDeviceChangeWithInfoCallback() = default;
41 
42     virtual void OnOutputDeviceChangeWithInfo(
43         const uint32_t sessionId, const DeviceInfo &deviceInfo, const AudioStreamDeviceChangeReason reason) = 0;
44 };
45 
46 class AudioCapturerStateChangeCallback {
47 public:
48     virtual ~AudioCapturerStateChangeCallback() = default;
49     /**
50      * Called when the capturer state changes
51      *
52      * @param capturerChangeInfo Contains the renderer state information.
53      */
54     virtual void OnCapturerStateChange(
55         const std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) = 0;
56     std::mutex cbMutex_;
57 };
58 
59 class AudioClientTracker {
60 public:
61     virtual ~AudioClientTracker() = default;
62 
63     /**
64      * Paused Stream was controlled by system application
65      *
66      * @param streamSetStateEventInternal Contains the set even information.
67      */
68     virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0;
69 
70      /**
71      * Resumed Stream was controlled by system application
72      *
73      * @param streamSetStateEventInternal Contains the set even information.
74      */
75     virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0;
76 
77     /**
78      * Set low power volume was controlled by system application
79      *
80      * @param volume volume value.
81      */
82     virtual void SetLowPowerVolumeImpl(float volume) = 0;
83 
84     /**
85      * Get low power volume was controlled by system application
86      *
87      * @param volume volume value.
88      */
89     virtual void GetLowPowerVolumeImpl(float &volume) = 0;
90 
91     /**
92      * Set Stream into a specified Offload state
93      *
94      * @param state power state.
95      * @param isAppBack app state.
96      */
97     virtual void SetOffloadModeImpl(int32_t state, bool isAppBack) = 0;
98 
99     /**
100      * Unset Stream out of Offload state
101      *
102      */
103     virtual void UnsetOffloadModeImpl() = 0;
104 
105     /**
106      * Get single stream was controlled by system application
107      *
108      * @param volume volume value.
109      */
110     virtual void GetSingleStreamVolumeImpl(float &volume) = 0;
111 };
112 
113 class AudioStreamManager {
114 public:
115     AudioStreamManager() = default;
116     virtual ~AudioStreamManager() = default;
117 
118     static AudioStreamManager *GetInstance();
119 
120     /**
121      * @brief Registers the renderer event callback listener.
122      *
123      * @param clientPid client PID
124      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
125      * defined in {@link audio_errors.h} otherwise.
126      * @since 9
127      */
128     int32_t RegisterAudioRendererEventListener(const int32_t clientPid,
129                                               const std::shared_ptr<AudioRendererStateChangeCallback> &callback);
130 
131     /**
132      * @brief Unregisters the renderer event callback listener.
133      *
134      * @param clientPid client PID
135      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
136      * defined in {@link audio_errors.h} otherwise.
137      * @since 9
138      */
139     int32_t UnregisterAudioRendererEventListener(const int32_t clientPid);
140 
141     /**
142      * @brief Registers the capturer event callback listener.
143      *
144      * @param clientPid client PID
145      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
146      * defined in {@link audio_errors.h} otherwise.
147      * @since 9
148      */
149     int32_t RegisterAudioCapturerEventListener(const int32_t clientPid,
150         const std::shared_ptr<AudioCapturerStateChangeCallback> &callback);
151 
152     /**
153      * @brief Unregisters the capturer event callback listener.
154      *
155      * @param clientPid client PID
156      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
157      * defined in {@link audio_errors.h} otherwise.
158      * @since 9
159      */
160     int32_t UnregisterAudioCapturerEventListener(const int32_t clientPid);
161 
162     /**
163      * @brief Get current renderer change Infos.
164      *
165      * @param audioRendererChangeInfos  audioRendererChangeInfos
166      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
167      * defined in {@link audio_errors.h} otherwise.
168      * @since 9
169      */
170     int32_t GetCurrentRendererChangeInfos(
171         std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos);
172 
173     /**
174      * @brief Get current capturer change Infos.
175      *
176      * @param audioRendererChangeInfos  audioRendererChangeInfos
177      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
178      * defined in {@link audio_errors.h} otherwise.
179      * @since 9
180      */
181     int32_t GetCurrentCapturerChangeInfos(
182         std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos);
183 
184     /**
185      * @brief Is audio renderer low latency supported.
186      *
187      * @param audioStreamInfo  audioStreamInfo
188      * @return Returns <b>true</b> if the timestamp is successfully obtained; returns <b>false</b> otherwise.
189      * @since 9
190      */
191     bool IsAudioRendererLowLatencySupported(const AudioStreamInfo &audioStreamInfo);
192 
193     /**
194      * @brief Get Audio Effect Infos.
195      *
196      * @param AudioSceneEffectInfo  AudioSceneEffectInfo
197      * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code
198      * defined in {@link audio_errors.h} otherwise.
199      * @since 9
200      */
201     int32_t GetEffectInfoArray(AudioSceneEffectInfo &audioSceneEffectInfo, StreamUsage streamUsage);
202 
203     /**
204      * @brief Is stream active.
205      *
206      * @param volumeType audio volume type.
207      * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise.
208      * @since 9
209      */
210     bool IsStreamActive(AudioVolumeType volumeType) const;
211 
212     /**
213      * @brief Gets sampling rate for hardware output.
214      *
215      * @param AudioDeviceDescriptor Target output device.
216      * @return The sampling rate for output.
217      * @since 11
218      */
219     int32_t GetHardwareOutputSamplingRate(sptr<AudioDeviceDescriptor> &desc);
220 };
221 
222 static const std::map<std::string, AudioEffectMode> effectModeMap = {
223     {"EFFECT_NONE", EFFECT_NONE},
224     {"EFFECT_DEFAULT", EFFECT_DEFAULT}
225 };
226 } // namespace AudioStandard
227 } // namespace OHOS
228 #endif // ST_AUDIO_STREAM_MANAGER_H
229