1 /* 2 * Copyright (c) 2022-2025 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 #include "audio_stream_change_info.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 class DeviceChangeWithInfoCallback { 28 public: 29 virtual ~DeviceChangeWithInfoCallback() = default; 30 31 virtual void OnDeviceChangeWithInfo(const uint32_t sessionId, const AudioDeviceDescriptor &deviceInfo, 32 const AudioStreamDeviceChangeReasonExt reason) = 0; 33 34 virtual void OnRecreateStreamEvent(const uint32_t sessionId, const int32_t streamFlag, 35 const AudioStreamDeviceChangeReasonExt reason) = 0; 36 }; 37 38 class AudioClientTracker { 39 public: 40 virtual ~AudioClientTracker() = default; 41 42 /** 43 * Mute Stream was controlled by system application 44 * 45 * @param streamSetStateEventInternal Contains the set even information. 46 */ 47 virtual void MuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 48 49 /** 50 * Unmute Stream was controlled by system application 51 * 52 * @param streamSetStateEventInternal Contains the set even information. 53 */ 54 virtual void UnmuteStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 55 56 /** 57 * Paused Stream was controlled by system application 58 * 59 * @param streamSetStateEventInternal Contains the set even information. 60 */ 61 virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 62 63 /** 64 * Resumed Stream was controlled by system application 65 * 66 * @param streamSetStateEventInternal Contains the set even information. 67 */ 68 virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 69 70 /** 71 * Set low power volume was controlled by system application 72 * 73 * @param volume volume value. 74 */ 75 virtual void SetLowPowerVolumeImpl(float volume) = 0; 76 77 /** 78 * Get low power volume was controlled by system application 79 * 80 * @param volume volume value. 81 */ 82 virtual void GetLowPowerVolumeImpl(float &volume) = 0; 83 84 /** 85 * Set Stream into a specified Offload state 86 * 87 * @param state power state. 88 * @param isAppBack app state. 89 */ 90 virtual void SetOffloadModeImpl(int32_t state, bool isAppBack) = 0; 91 92 /** 93 * Unset Stream out of Offload state 94 * 95 */ 96 virtual void UnsetOffloadModeImpl() = 0; 97 98 /** 99 * Get single stream was controlled by system application 100 * 101 * @param volume volume value. 102 */ 103 virtual void GetSingleStreamVolumeImpl(float &volume) = 0; 104 }; 105 106 class AudioStreamManager { 107 public: 108 AudioStreamManager() = default; 109 virtual ~AudioStreamManager() = default; 110 111 static AudioStreamManager *GetInstance(); 112 113 /** 114 * @brief Registers the renderer event callback listener. 115 * 116 * @param clientPid client PID 117 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 118 * defined in {@link audio_errors.h} otherwise. 119 * @since 9 120 * @deprecated since 12 121 */ 122 int32_t RegisterAudioRendererEventListener(const int32_t clientPid, 123 const std::shared_ptr<AudioRendererStateChangeCallback> &callback); 124 125 /** 126 * @brief Unregisters the renderer event callback listener. 127 * 128 * @param clientPid client PID 129 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 130 * defined in {@link audio_errors.h} otherwise. 131 * @since 9 132 * @deprecated since 12 133 */ 134 int32_t UnregisterAudioRendererEventListener(const int32_t clientPid); 135 136 /** 137 * @brief Registers the renderer event callback listener. 138 * 139 * @param callback 140 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 141 * defined in {@link audio_errors.h} otherwise. 142 * @since 12 143 */ 144 int32_t RegisterAudioRendererEventListener(const std::shared_ptr<AudioRendererStateChangeCallback> &callback); 145 146 /** 147 * @brief Unregisters the renderer event callback listener. 148 * 149 * @param callback need to unregister. 150 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 151 * defined in {@link audio_errors.h} otherwise. 152 * @since 12 153 */ 154 int32_t UnregisterAudioRendererEventListener(const std::shared_ptr<AudioRendererStateChangeCallback> &callback); 155 156 /** 157 * @brief Registers the capturer event callback listener. 158 * 159 * @param clientPid client PID 160 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 161 * defined in {@link audio_errors.h} otherwise. 162 * @since 9 163 */ 164 int32_t RegisterAudioCapturerEventListener(const int32_t clientPid, 165 const std::shared_ptr<AudioCapturerStateChangeCallback> &callback); 166 167 /** 168 * @brief Unregisters the capturer event callback listener. 169 * 170 * @param clientPid client PID 171 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 172 * defined in {@link audio_errors.h} otherwise. 173 * @since 9 174 */ 175 int32_t UnregisterAudioCapturerEventListener(const int32_t clientPid); 176 177 /** 178 * @brief Get current renderer change Infos. 179 * 180 * @param audioRendererChangeInfos audioRendererChangeInfos 181 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 182 * defined in {@link audio_errors.h} otherwise. 183 * @since 9 184 */ 185 int32_t GetCurrentRendererChangeInfos( 186 std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos); 187 188 /** 189 * @brief Get current capturer change Infos. 190 * 191 * @param audioRendererChangeInfos audioRendererChangeInfos 192 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 193 * defined in {@link audio_errors.h} otherwise. 194 * @since 9 195 */ 196 int32_t GetCurrentCapturerChangeInfos( 197 std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos); 198 199 /** 200 * @brief Get Audio Effect Infos. 201 * 202 * @param AudioSceneEffectInfo AudioSceneEffectInfo 203 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 204 * defined in {@link audio_errors.h} otherwise. 205 * @since 9 206 */ 207 int32_t GetEffectInfoArray(AudioSceneEffectInfo &audioSceneEffectInfo, StreamUsage streamUsage); 208 209 /** 210 * @brief Get Audio render Effect param. 211 * 212 * @param AudioSceneEffectInfo AudioSceneEffectInfo 213 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 214 * defined in {@link audio_errors.h} otherwise. 215 * @since 13 216 */ 217 int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray); 218 219 /** 220 * @brief Get Audio Capture Effect param. 221 * 222 * @param AudioSceneEffectInfo AudioSceneEffectInfo 223 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 224 * defined in {@link audio_errors.h} otherwise. 225 * @since 13 226 */ 227 int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); 228 229 /** 230 * @brief Sets the audio effect Param. 231 * 232 * * @param effectParam The audio effect Param at which the stream needs to be rendered. 233 * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code 234 * defined in {@link audio_errors.h} otherwise. 235 * @since 13 236 */ 237 int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray); 238 239 /** 240 * @brief Gets the audio effect Param. 241 * 242 * * @param effectParam The audio effect moParamde at which the stream needs to be rendered. 243 * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code 244 * defined in {@link audio_errors.h} otherwise. 245 * @since 13 246 */ 247 int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray); 248 249 /** 250 * @brief Sets the audio effect Param. 251 * 252 * * @param effectParam The audio effect Param at which the stream needs to be rendered. 253 * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code 254 * defined in {@link audio_errors.h} otherwise. 255 * @since 13 256 */ 257 int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray); 258 259 /** 260 * @brief Gets the audio effect Param. 261 * 262 * * @param effectParam The audio effect moParamde at which the stream needs to be rendered. 263 * @return Returns {@link SUCCESS} if audio effect Param is successfully set; returns an error code 264 * defined in {@link audio_errors.h} otherwise. 265 * @since 13 266 */ 267 int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray); 268 269 /** 270 * @brief Is stream active. 271 * 272 * @param volumeType audio volume type. 273 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 274 * @since 9 275 */ 276 bool IsStreamActive(AudioVolumeType volumeType) const; 277 278 /** 279 * @brief Gets sampling rate for hardware output. 280 * 281 * @param AudioDeviceDescriptor Target output device. 282 * @return The sampling rate for output. 283 * @since 11 284 */ 285 int32_t GetHardwareOutputSamplingRate(std::shared_ptr<AudioDeviceDescriptor> &desc); 286 287 private: 288 std::mutex rendererStateChangeCallbacksMutex_; 289 std::vector<std::shared_ptr<AudioRendererStateChangeCallback>> rendererStateChangeCallbacks_; 290 }; 291 } // namespace AudioStandard 292 } // namespace OHOS 293 #endif // ST_AUDIO_STREAM_MANAGER_H 294