1 /* 2 * Copyright (c) 2023 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_SPATIALIZATION_MANAGER_H 17 #define ST_AUDIO_SPATIALIZATION_MANAGER_H 18 19 #include <cstdlib> 20 #include <list> 21 #include <map> 22 #include <mutex> 23 #include <vector> 24 #include <unordered_map> 25 26 #include "parcel.h" 27 #include "audio_info.h" 28 #include "audio_effect.h" 29 #include "audio_system_manager.h" 30 31 namespace OHOS { 32 namespace AudioStandard { 33 class AudioSpatializationEnabledChangeCallback { 34 public: 35 virtual ~AudioSpatializationEnabledChangeCallback() = default; 36 /** 37 * @brief AudioSpatializationEnabledChangeCallback will be executed when spatialization enabled state changes 38 * 39 * @param enabled the spatialization enabled state. 40 * @since 11 41 */ 42 virtual void OnSpatializationEnabledChange(const bool &enabled) = 0; 43 44 /** 45 * @brief AudioSpatializationEnabledChangeCallback will be executed when spatialization enabled state changes 46 * 47 * @param deviceDescriptor audio device description. 48 * @param enabled the spatialization enabled state. 49 * @since 12 50 */ 51 virtual void OnSpatializationEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor> &deviceDescriptor, 52 const bool &enabled) = 0; 53 }; 54 55 class AudioHeadTrackingEnabledChangeCallback { 56 public: 57 virtual ~AudioHeadTrackingEnabledChangeCallback() = default; 58 /** 59 * @brief AudioHeadTrackingEnabledChangeCallback will be executed when head tracking enabled state changes 60 * 61 * @param enabled the head tracking enabled state. 62 * @since 11 63 */ 64 virtual void OnHeadTrackingEnabledChange(const bool &enabled) = 0; 65 66 /** 67 * @brief AudioHeadTrackingEnabledChangeCallback will be executed when head tracking enabled state changes 68 * 69 * @param deviceDescriptor audio device description. 70 * @param enabled the head tracking enabled state. 71 * @since 12 72 */ 73 virtual void OnHeadTrackingEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor> &deviceDescriptor, 74 const bool &enabled) = 0; 75 }; 76 77 class AudioSpatializationStateChangeCallback { 78 public: 79 virtual ~AudioSpatializationStateChangeCallback() = default; 80 /** 81 * @brief AudioSpatializationStateChangeCallback will be executed when spatialization state changes 82 * 83 * @param enabled the spatialization state. 84 * @since 11 85 */ 86 virtual void OnSpatializationStateChange(const AudioSpatializationState &spatializationState) = 0; 87 }; 88 89 class HeadTrackingDataRequestedChangeCallback { 90 public: 91 virtual ~HeadTrackingDataRequestedChangeCallback() = default; 92 /** 93 * @brief HeadTrackingDataRequestedChangeCallback will be executed when 94 * whether head tracking data is requested changes 95 * 96 * @param isRequested whethet the head tracking data is requested. 97 * @since 12 98 */ 99 virtual void OnHeadTrackingDataRequestedChange(bool isRequested) = 0; 100 }; 101 102 /** 103 * @brief The AudioSpatializationManager class is an abstract definition of audio spatialization manager. 104 * Provides a series of client/interfaces for audio spatialization management 105 */ 106 107 class AudioSpatializationManager { 108 public: 109 static AudioSpatializationManager *GetInstance(); 110 111 /** 112 * @brief Check whether the spatialization is enabled 113 * 114 * @return Returns <b>true</b> if the spatialization is successfully enabled; returns <b>false</b> otherwise. 115 * @since 11 116 */ 117 bool IsSpatializationEnabled(); 118 119 /** 120 * @brief Check whether the spatialization is enabled by the specified device. 121 * 122 * @return Returns <b>true</b> if the spatialization is successfully enabled; returns <b>false</b> otherwise. 123 * @since 12 124 */ 125 bool IsSpatializationEnabled(const sptr<AudioDeviceDescriptor> &selectedAudioDevice); 126 127 /** 128 * @brief Set the spatialization enabled or disabled 129 * 130 * @return Returns success or not 131 * @since 11 132 */ 133 int32_t SetSpatializationEnabled(const bool enable); 134 135 /** 136 * @brief Set the spatialization enabled or disabled by the specified device. 137 * 138 * @return Returns success or not 139 * @since 12 140 */ 141 int32_t SetSpatializationEnabled(const sptr<AudioDeviceDescriptor> &selectedAudioDevice, const bool enable); 142 143 /** 144 * @brief Check whether the head tracking is enabled 145 * 146 * @return Returns <b>true</b> if the head tracking is successfully enabled; returns <b>false</b> otherwise. 147 * @since 11 148 */ 149 bool IsHeadTrackingEnabled(); 150 151 /** 152 * @brief Check whether the head tracking is enabled by the specified device. 153 * 154 * @return Returns <b>true</b> if the head tracking is successfully enabled; returns <b>false</b> otherwise. 155 * @since 12 156 */ 157 bool IsHeadTrackingEnabled(const sptr<AudioDeviceDescriptor> &selectedAudioDevice); 158 159 /** 160 * @brief Set the head tracking enabled or disabled 161 * 162 * @return Returns success or not 163 * @since 11 164 */ 165 int32_t SetHeadTrackingEnabled(const bool enable); 166 167 /** 168 * @brief Set the head tracking enabled or disabled by the specified device. 169 * 170 * @return Returns success or not 171 * @since 12 172 */ 173 int32_t SetHeadTrackingEnabled(const sptr<AudioDeviceDescriptor> &selectedAudioDevice, const bool enable); 174 175 /** 176 * @brief Register the spatialization enabled change callback listener 177 * 178 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 179 * defined in {@link audio_errors.h} otherwise. 180 * @since 11 181 */ 182 int32_t RegisterSpatializationEnabledEventListener( 183 const std::shared_ptr<AudioSpatializationEnabledChangeCallback> &callback); 184 185 /** 186 * @brief Register the head tracking enabled change callback listener 187 * 188 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 189 * defined in {@link audio_errors.h} otherwise. 190 * @since 11 191 */ 192 int32_t RegisterHeadTrackingEnabledEventListener( 193 const std::shared_ptr<AudioHeadTrackingEnabledChangeCallback> &callback); 194 195 /** 196 * @brief Unregister the spatialization enabled change callback listener 197 * 198 * @return Returns {@link SUCCESS} if callback unregistration is successful; returns an error code 199 * defined in {@link audio_errors.h} otherwise. 200 * @since 11 201 */ 202 int32_t UnregisterSpatializationEnabledEventListener(); 203 204 /** 205 * @brief Unregister the head tracking enabled change callback listener 206 * 207 * @return Returns {@link SUCCESS} if callback unregistration is successful; returns an error code 208 * defined in {@link audio_errors.h} otherwise. 209 * @since 11 210 */ 211 int32_t UnregisterHeadTrackingEnabledEventListener(); 212 213 /** 214 * @brief Check whether the spatialization is supported 215 * 216 * @return Returns <b>true</b> if the spatialization is supported; returns <b>false</b> otherwise. 217 * @since 11 218 */ 219 bool IsSpatializationSupported(); 220 221 /** 222 * @brief Check whether the spatialization is supported for some device 223 * 224 * @return Returns <b>true</b> if the spatialization is supported; returns <b>false</b> otherwise. 225 * @since 11 226 */ 227 bool IsSpatializationSupportedForDevice(const sptr<AudioDeviceDescriptor> &selectedAudioDevice); 228 229 /** 230 * @brief Check whether the Head Tracking is supported 231 * 232 * @return Returns <b>true</b> if the Head Tracking is supported; returns <b>false</b> otherwise. 233 * @since 11 234 */ 235 bool IsHeadTrackingSupported(); 236 237 /** 238 * @brief Check whether the head tracking is supported for some device 239 * 240 * @return Returns <b>true</b> if the head tracking is supported; returns <b>false</b> otherwise. 241 * @since 11 242 */ 243 bool IsHeadTrackingSupportedForDevice(const sptr<AudioDeviceDescriptor> &selectedAudioDevice); 244 245 /** 246 * @brief Update the state of the spatial Device 247 * 248 * @since 11 249 */ 250 int32_t UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState); 251 252 /** 253 * @brief Get current spatialization rendering scene type 254 * 255 * @return Returns current spatialization scene type enum defined in {@link audio_effect.h}. 256 * @since 12 257 */ 258 AudioSpatializationSceneType GetSpatializationSceneType(); 259 260 /** 261 * @brief Set spatialization rendering scene type 262 * 263 * @return Returns {@link SUCCESS} if setting spatialization scene type is successful; returns an error code 264 * defined in {@link audio_errors.h} otherwise. 265 * @since 12 266 */ 267 int32_t SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType); 268 269 /** 270 * @brief Check whether head tracking data is requested 271 * 272 * @return Returns <b>true</b> if the head tracking data is requested; returns <b>false</b> otherwise. 273 * @since 12 274 */ 275 bool IsHeadTrackingDataRequested(const std::string &macAddress); 276 277 /** 278 * @brief Register the head tracking data requested change callback listener for the specified device 279 * 280 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 281 * defined in {@link audio_errors.h} otherwise. 282 * @since 12 283 */ 284 int32_t RegisterHeadTrackingDataRequestedEventListener(const std::string &macAddress, 285 const std::shared_ptr<HeadTrackingDataRequestedChangeCallback> &callback); 286 287 /** 288 * @brief Unregister the head tracking data requested change callback listener for the specified device 289 * 290 * @return Returns {@link SUCCESS} if callback unregistration is successful; returns an error code 291 * defined in {@link audio_errors.h} otherwise. 292 * @since 12 293 */ 294 int32_t UnregisterHeadTrackingDataRequestedEventListener(const std::string &macAddress); 295 private: 296 AudioSpatializationManager(); 297 virtual ~AudioSpatializationManager(); 298 }; 299 } // namespace AudioStandard 300 } // namespace OHOS 301 #endif // ST_AUDIO_SPATIALIZATION_MANAGER_H 302