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 23 namespace OHOS { 24 namespace AudioStandard { 25 class AudioRendererStateChangeCallback { 26 public: 27 virtual ~AudioRendererStateChangeCallback() = default; 28 /** 29 * Called when the renderer state changes 30 * 31 * @param rendererChangeInfo Contains the renderer state information. 32 */ 33 virtual void OnRendererStateChange( 34 const std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos) = 0; 35 }; 36 37 class AudioCapturerStateChangeCallback { 38 public: 39 virtual ~AudioCapturerStateChangeCallback() = default; 40 /** 41 * Called when the capturer state changes 42 * 43 * @param capturerChangeInfo Contains the renderer state information. 44 */ 45 virtual void OnCapturerStateChange( 46 const std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos) = 0; 47 }; 48 49 class AudioClientTracker { 50 public: 51 virtual ~AudioClientTracker() = default; 52 53 /** 54 * Paused Stream was controlled by system application 55 * 56 * @param streamSetStateEventInternal Contains the set even information. 57 */ 58 virtual void PausedStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 59 60 /** 61 * Resumed Stream was controlled by system application 62 * 63 * @param streamSetStateEventInternal Contains the set even information. 64 */ 65 virtual void ResumeStreamImpl(const StreamSetStateEventInternal &streamSetStateEventInternal) = 0; 66 67 /** 68 * Set low power volume was controlled by system application 69 * 70 * @param volume volume value. 71 */ 72 virtual void SetLowPowerVolumeImpl(float volume) = 0; 73 74 /** 75 * Get low power volume was controlled by system application 76 * 77 * @param volume volume value. 78 */ 79 virtual void GetLowPowerVolumeImpl(float &volume) = 0; 80 81 /** 82 * Get single stream was controlled by system application 83 * 84 * @param volume volume value. 85 */ 86 virtual void GetSingleStreamVolumeImpl(float &volume) = 0; 87 }; 88 89 class AudioStreamManager { 90 public: 91 AudioStreamManager() = default; 92 virtual ~AudioStreamManager() = default; 93 94 static AudioStreamManager *GetInstance(); 95 96 /** 97 * @brief Registers the renderer event callback listener. 98 * 99 * @param clientPid client PID 100 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 101 * defined in {@link audio_errors.h} otherwise. 102 * @since 9 103 */ 104 int32_t RegisterAudioRendererEventListener(const int32_t clientPid, 105 const std::shared_ptr<AudioRendererStateChangeCallback> &callback); 106 107 /** 108 * @brief Unregisters the renderer event callback listener. 109 * 110 * @param clientPid client PID 111 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 112 * defined in {@link audio_errors.h} otherwise. 113 * @since 9 114 */ 115 int32_t UnregisterAudioRendererEventListener(const int32_t clientPid); 116 117 /** 118 * @brief Registers the capturer event callback listener. 119 * 120 * @param clientPid client PID 121 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 122 * defined in {@link audio_errors.h} otherwise. 123 * @since 9 124 */ 125 int32_t RegisterAudioCapturerEventListener(const int32_t clientPid, 126 const std::shared_ptr<AudioCapturerStateChangeCallback> &callback); 127 128 /** 129 * @brief Unregisters the capturer event callback listener. 130 * 131 * @param clientPid client PID 132 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 133 * defined in {@link audio_errors.h} otherwise. 134 * @since 9 135 */ 136 int32_t UnregisterAudioCapturerEventListener(const int32_t clientPid); 137 138 /** 139 * @brief Get current renderer change Infos. 140 * 141 * @param audioRendererChangeInfos audioRendererChangeInfos 142 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 143 * defined in {@link audio_errors.h} otherwise. 144 * @since 9 145 */ 146 int32_t GetCurrentRendererChangeInfos( 147 std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos); 148 149 /** 150 * @brief Get current capturer change Infos. 151 * 152 * @param audioRendererChangeInfos audioRendererChangeInfos 153 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 154 * defined in {@link audio_errors.h} otherwise. 155 * @since 9 156 */ 157 int32_t GetCurrentCapturerChangeInfos( 158 std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos); 159 160 /** 161 * @brief Is audio renderer low latency supported. 162 * 163 * @param audioStreamInfo audioStreamInfo 164 * @return Returns <b>true</b> if the timestamp is successfully obtained; returns <b>false</b> otherwise. 165 * @since 9 166 */ 167 bool IsAudioRendererLowLatencySupported(const AudioStreamInfo &audioStreamInfo); 168 169 /** 170 * @brief Get Audio Effect Infos. 171 * 172 * @param AudioSceneEffectInfo AudioSceneEffectInfo 173 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 174 * defined in {@link audio_errors.h} otherwise. 175 * @since 9 176 */ 177 int32_t GetEffectInfoArray(AudioSceneEffectInfo &audioSceneEffectInfo, StreamUsage streamUsage); 178 179 /** 180 * @brief Is stream active. 181 * 182 * @param volumeType audio volume type. 183 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 184 * @since 9 185 */ 186 bool IsStreamActive(AudioVolumeType volumeType) const; 187 }; 188 189 static const std::map<std::string, AudioEffectMode> effectModeMap = { 190 {"EFFECT_NONE", EFFECT_NONE}, 191 {"EFFECT_DEFAULT", EFFECT_DEFAULT} 192 }; 193 } // namespace AudioStandard 194 } // namespace OHOS 195 #endif // ST_AUDIO_STREAM_MANAGER_H 196