1 /* 2 * Copyright (c) 2021-2024 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 I_ST_AUDIO_MANAGER_BASE_H 17 #define I_ST_AUDIO_MANAGER_BASE_H 18 19 #include "ipc_types.h" 20 #include "iremote_broker.h" 21 #include "iremote_proxy.h" 22 #include "iremote_stub.h" 23 #include "audio_effect.h" 24 #include "pulseaudio_ipc_interface_code.h" 25 #include "audio_asr.h" 26 27 namespace OHOS { 28 namespace AudioStandard { 29 class AudioDeviceDescriptor; 30 class IStandardAudioService : public IRemoteBroker { 31 public: 32 /** 33 * Sets Microphone Mute status. 34 * 35 * @param isMute Mute status true or false to be set. 36 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 37 */ 38 virtual int32_t SetMicrophoneMute(bool isMute) = 0; 39 40 /** 41 * @brief Set the Voice Volume. 42 * 43 * @param volume Voice colume to be set. 44 * @return int32_t Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 45 */ 46 virtual int32_t SetVoiceVolume(float volume) = 0; 47 48 virtual int32_t OffloadSetVolume(float volume) = 0; 49 virtual int32_t SuspendRenderSink(const std::string &sinkName) = 0; 50 virtual int32_t RestoreRenderSink(const std::string &sinkName) = 0; 51 52 /** 53 * Sets Audio modes. 54 * 55 * @param audioScene Audio scene type. 56 * @param activeDevice Currently active priority device 57 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 58 */ 59 virtual int32_t SetAudioScene(AudioScene audioScene, std::vector<DeviceType> &activeOutputDevices, 60 DeviceType activeInputDevice, BluetoothOffloadState a2dpOffloadFlag) = 0; 61 62 /** 63 * Set Audio Parameter. 64 * 65 * @param key for the audio parameter to be set 66 * @param value associated with the key for the audio parameter to be set 67 * @return none. 68 */ 69 virtual void SetAudioParameter(const std::string &key, const std::string &value) = 0; 70 71 /** 72 * Set Asr Aec Mode. 73 * 74 * @param key for the audio parameter to be set 75 * @param value associated with the key for the audio parameter to be set 76 * @return none. 77 */ 78 virtual int32_t SetAsrAecMode(AsrAecMode asrAecMode) = 0; 79 80 /** 81 * Set Asr Aec Mode. 82 * 83 * @param key for the audio parameter to be set 84 * @param value associated with the key for the audio parameter to be set 85 * @return none. 86 */ 87 virtual int32_t GetAsrAecMode(AsrAecMode &asrAecMode) = 0; 88 89 /** 90 * Set Asr Aec Mode. 91 * 92 * @param key for the audio parameter to be set 93 * @param value associated with the key for the audio parameter to be set 94 * @return none. 95 */ 96 virtual int32_t SetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode asrNoiseSuppressionMode) = 0; 97 98 /** 99 * Set Asr Aec Mode. 100 * 101 * @param key for the audio parameter to be set 102 * @param value associated with the key for the audio parameter to be set 103 * @return none. 104 */ 105 virtual int32_t GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode &asrNoiseSuppressionMode) = 0; 106 107 /** 108 * Set Asr WhisperDetection Mode. 109 * 110 * @param key for the audio parameter to be set 111 * @param value associated with the key for the audio parameter to be set 112 * @return none. 113 */ 114 virtual int32_t SetAsrWhisperDetectionMode(AsrWhisperDetectionMode asrWhisperDetectionMode) = 0; 115 116 /** 117 * Get Asr WhisperDetection Mode. 118 * 119 * @param key for the audio parameter to be set 120 * @param value associated with the key for the audio parameter to be set 121 * @return none. 122 */ 123 virtual int32_t GetAsrWhisperDetectionMode(AsrWhisperDetectionMode &asrWhisperDetectionMode) = 0; 124 125 /** 126 * Set Voice Control Mode. 127 * 128 * @param key for the audio parameter to be set 129 * @param value associated with the key for the audio parameter to be set 130 * @return none. 131 */ 132 virtual int32_t SetAsrVoiceControlMode(AsrVoiceControlMode asrVoiceControlMode, bool on) = 0; 133 134 /** 135 * Set Voice Mute Mode. 136 * 137 * @param key for the audio parameter to be set 138 * @param value associated with the key for the audio parameter to be set 139 * @return none. 140 */ 141 virtual int32_t SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode, bool on) = 0; 142 143 /** 144 * Set Asr Aec Mode. 145 * 146 * @param key for the audio parameter to be set 147 * @param value associated with the key for the audio parameter to be set 148 * @return none. 149 */ 150 virtual int32_t IsWhispering() = 0; 151 152 /** 153 * Set Audio Parameter. 154 * 155 * @param networkId for the distributed device 156 * @param key for the audio parameter to be set 157 * @param condition for the audio parameter to be set 158 * @param value associated with the key for the audio parameter to be set 159 * @return none. 160 */ 161 virtual void SetAudioParameter(const std::string& networkId, const AudioParamKey key, const std::string& condition, 162 const std::string& value) = 0; 163 164 /** 165 * Get Audio Parameter. 166 * 167 * @param key for the audio parameter to be set 168 * @return Returns value associated to the key requested. 169 */ 170 virtual const std::string GetAudioParameter(const std::string &key) = 0; 171 172 /** 173 * Set Audio Parameter. 174 * 175 * @param networkId for the distributed device 176 * @param key for the audio parameter to be set 177 * @param condition for the audio parameter to be set 178 * @return none. 179 */ 180 virtual const std::string GetAudioParameter(const std::string& networkId, const AudioParamKey key, 181 const std::string& condition) = 0; 182 183 /** 184 * Set Extra Audio Parameters. 185 * 186 * @param key main key for the extra audio parameter to be set 187 * @param kvpairs associated with the sub keys and values for the extra audio parameter to be set 188 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 189 */ 190 virtual int32_t SetExtraParameters(const std::string &key, 191 const std::vector<std::pair<std::string, std::string>> &kvpairs) = 0; 192 193 /** 194 * Get Extra Audio Parameters. 195 * 196 * @param mainKey main key for the extra audio parameter to be get 197 * @param subKeys associated with the key for the extra audio parameter to be get 198 * @param result value of sub key parameters 199 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 200 */ 201 virtual int32_t GetExtraParameters(const std::string &mainKey, 202 const std::vector<std::string> &subKyes, std::vector<std::pair<std::string, std::string>> &result) = 0; 203 204 /** 205 * Update the audio route after device is detected and route is decided 206 * 207 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 208 */ 209 virtual int32_t UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag, 210 BluetoothOffloadState a2dpOffloadFlag) = 0; 211 212 /** 213 * Update the audio route after devices is detected and route is decided 214 * 215 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 216 */ 217 virtual int32_t UpdateActiveDevicesRoute(std::vector<std::pair<DeviceType, DeviceFlag>> &activeDevices, 218 BluetoothOffloadState a2dpOffloadFlag) = 0; 219 220 /** 221 * Update the audio dual tone state after devices is detected and route is decided 222 * 223 * @return Returns 0 if success. Otherwise returns Errocode defined in audio_errors.h. 224 */ 225 virtual int32_t UpdateDualToneState(bool enable, int32_t sessionId) = 0; 226 227 /** 228 * Get the transaction Id 229 * 230 * @return Returns transaction id. 231 */ GetTransactionId(DeviceType deviceType,DeviceRole deviceRole)232 virtual uint64_t GetTransactionId(DeviceType deviceType, DeviceRole deviceRole) 233 { 234 (void)deviceType; 235 (void)deviceRole; 236 return 0; 237 } 238 239 /** 240 * Notify device connect info 241 * 242 * @return Returns transaction id. 243 */ 244 virtual void NotifyDeviceInfo(std::string networkId, bool connected) = 0; 245 246 /** 247 * Check remote device state. 248 * 249 * @return Returns transaction id. 250 */ 251 virtual int32_t CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice) = 0; 252 253 /** 254 * Set parameter callback 255 * 256 * @return Returns the setting result 257 */ 258 virtual int32_t SetParameterCallback(const sptr<IRemoteObject>& object) = 0; 259 260 /** 261 * Set wakeupSource callback 262 * 263 * @return Returns the setting result 264 */ 265 virtual int32_t SetWakeupSourceCallback(const sptr<IRemoteObject>& object) = 0; 266 267 /** 268 * Set audio mono state for accessibility 269 * 270 * @param audioMono the state of mono audio for accessibility 271 * @return none. 272 */ 273 virtual void SetAudioMonoState(bool audioMono) = 0; 274 275 /** 276 * Set audio balance value for accessibility 277 * 278 * @param audioBalance the value of audio balance for accessibility 279 * @return none. 280 */ 281 virtual void SetAudioBalanceValue(float audioBalance) = 0; 282 283 /** 284 * Create AudioProcess for play. 285 * 286 * @param config the config of the AudioProcess 287 * 288 * @return Returns AudioProcess client. 289 */ 290 virtual sptr<IRemoteObject> CreateAudioProcess(const AudioProcessConfig &config, int32_t &errorCode) = 0; 291 292 /** 293 * Use effect manager information to load effect libraries. 294 * 295 * @return true/false. 296 */ 297 virtual bool LoadAudioEffectLibraries(std::vector<Library> libraries, std::vector<Effect> effects, 298 std::vector<Effect> &successEffects) = 0; 299 300 /** 301 * Create effect chain manager for audio effect processing. 302 * 303 * @return true/false. 304 */ 305 virtual bool CreateEffectChainManager(std::vector<EffectChain> &effectChains, 306 const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam) = 0; 307 308 /** 309 * Set output device sink for effect chain manager. 310 * 311 * @return none. 312 */ 313 virtual void SetOutputDeviceSink(int32_t device, std::string &sinkName) = 0; 314 315 /** 316 * Regiest policy provider. 317 * 318 * @return result code. 319 */ 320 virtual int32_t RegiestPolicyProvider(const sptr<IRemoteObject> &object) = 0; 321 322 /** 323 * Request thread priority for client thread. 324 */ 325 virtual void RequestThreadPriority(uint32_t tid, std::string bundleName) = 0; 326 327 /** 328 * Create playback capturer manager. 329 * 330 * @return true/false. 331 */ 332 virtual bool CreatePlaybackCapturerManager() = 0; 333 334 /** 335 * Set StreamUsage set which support playback capturer. 336 * 337 * @param usage value of StreamUsage which support inner capturer. 338 * 339 * @return result of setting. 0 if success, error number else. 340 */ 341 virtual int32_t SetSupportStreamUsage(std::vector<int32_t> usage) = 0; 342 343 /** 344 * Mark if playback capture silently. 345 * 346 * @param state identify the capture state 347 * 348 * @return result of setting. 0 if success, error number else. 349 */ 350 virtual int32_t SetCaptureSilentState(bool state) = 0; 351 352 /** 353 * Update spatialization enabled state and head tracking enabled state. 354 * 355 * @param state identify the enabled state 356 * 357 * @return result of setting. 0 if success, error number else. 358 */ 359 virtual int32_t UpdateSpatializationState(AudioSpatializationState spatializationState) = 0; 360 361 /** 362 * Update spatial device type. 363 * 364 * @param spatialDeviceType identify the spatial device type. 365 * 366 * @return result of setting. 0 if success, error number else. 367 */ 368 virtual int32_t UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType) = 0; 369 370 /** 371 * Notify Stream volume changed. 372 * 373 * @param streamType specified streamType whose volume to be notified 374 * @param volume stream volume in float 375 * 376 * @return result of notify. 0 if success, error number else. 377 */ 378 virtual int32_t NotifyStreamVolumeChanged(AudioStreamType streamType, float volume) = 0; 379 380 /** 381 * Set spatialization rendering scene type. 382 * 383 * @param spatializationSceneType identify the spatialization rendering scene type to be set. 384 * 385 * @return result of setting. 0 if success, error number else. 386 */ 387 virtual int32_t SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType) = 0; 388 389 virtual int32_t ResetRouteForDisconnect(DeviceType type) = 0; 390 391 /** 392 * get the effect algorithmic latency value for a specified audio stream. 393 * 394 * @param sessionId the session ID value for the stream 395 * 396 * @return Returns the effect algorithmic latency in ms. 397 */ 398 virtual uint32_t GetEffectLatency(const std::string &sessionId) = 0; 399 400 virtual void UpdateLatencyTimestamp(std::string ×tamp, bool isRenderer) = 0; 401 402 /** 403 * Get max amplitude for device. 404 * 405 * @param isOutputDevice specified if the device is output device 406 * @param deviceType specified deviceType to get max amplitude 407 * 408 * @return result of max amplitude. 409 */ 410 virtual float GetMaxAmplitude(bool isOutputDevice, int32_t deviceType) = 0; 411 412 /** 413 * Release old endpoint and re-create one. 414 */ 415 virtual void ResetAudioEndpoint() = 0; 416 417 // Check if the multi-channel sound effect is working on the DSP 418 virtual bool GetEffectOffloadEnabled() = 0; 419 420 /** 421 * Load effect hdi model when audio_host online. 422 */ 423 virtual void LoadHdiEffectModel() = 0; 424 425 /** 426 * Update Effect BtOffload Supported state. 427 */ 428 virtual void UpdateEffectBtOffloadSupported(const bool &isSupported) = 0; 429 430 /** 431 * Set Sink Mute For Switch Device. 432 */ 433 virtual int32_t SetSinkMuteForSwitchDevice(const std::string &devceClass, int32_t durationUs, bool mute) = 0; 434 435 /** 436 * Set Rotation To Effect. 437 */ 438 virtual void SetRotationToEffect(const uint32_t rotate) = 0; 439 440 /** 441 * Update Session Connection State 442 */ 443 virtual void UpdateSessionConnectionState(const int32_t &sessionID, const int32_t &state) = 0; 444 445 /** 446 * Set Non Interrupt Mute 447 */ 448 virtual void SetNonInterruptMute(const uint32_t sessionId, const bool muteFlag) = 0; 449 450 /** 451 * Create IpcOfflineStream for audio edition. 452 * 453 * @return Returns IpcOfflineStream client. 454 */ 455 virtual sptr<IRemoteObject> CreateIpcOfflineStream(int32_t &errorCode) = 0; 456 457 /** 458 * Get all offline audio effect chain names for audio edition. 459 * 460 * @return Returns result of querying, 0 if success, error number else. 461 */ 462 virtual int32_t GetOfflineAudioEffectChains(std::vector<std::string> &effectChains) = 0; 463 public: 464 DECLARE_INTERFACE_DESCRIPTOR(u"IStandardAudioService"); 465 }; 466 467 class AudioManagerStub : public IRemoteStub<IStandardAudioService> { 468 public: 469 virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 470 MessageOption &option) override; 471 472 private: 473 int HandleGetAudioParameter(MessageParcel &data, MessageParcel &reply); 474 int HandleSetAudioParameter(MessageParcel &data, MessageParcel &reply); 475 int HandleGetExtraAudioParameters(MessageParcel &data, MessageParcel &reply); 476 int HandleSetExtraAudioParameters(MessageParcel &data, MessageParcel &reply); 477 int HandleSetMicrophoneMute(MessageParcel &data, MessageParcel &reply); 478 int HandleSetAudioScene(MessageParcel &data, MessageParcel &reply); 479 int HandleUpdateActiveDeviceRoute(MessageParcel &data, MessageParcel &reply); 480 int HandleUpdateActiveDevicesRoute(MessageParcel &data, MessageParcel &reply); 481 int HandleDualToneState(MessageParcel &data, MessageParcel &reply); 482 int HandleGetTransactionId(MessageParcel &data, MessageParcel &reply); 483 int HandleSetParameterCallback(MessageParcel &data, MessageParcel &reply); 484 int HandleGetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply); 485 int HandleSetRemoteAudioParameter(MessageParcel &data, MessageParcel &reply); 486 int HandleNotifyDeviceInfo(MessageParcel &data, MessageParcel &reply); 487 int HandleCheckRemoteDeviceState(MessageParcel &data, MessageParcel &reply); 488 int HandleSetVoiceVolume(MessageParcel &data, MessageParcel &reply); 489 int HandleSetAudioMonoState(MessageParcel &data, MessageParcel &reply); 490 int HandleSetAudioBalanceValue(MessageParcel &data, MessageParcel &reply); 491 int HandleCreateAudioProcess(MessageParcel &data, MessageParcel &reply); 492 int HandleLoadAudioEffectLibraries(MessageParcel &data, MessageParcel &reply); 493 int HandleRequestThreadPriority(MessageParcel &data, MessageParcel &reply); 494 int HandleCreateAudioEffectChainManager(MessageParcel &data, MessageParcel &reply); 495 int HandleSetOutputDeviceSink(MessageParcel &data, MessageParcel &reply); 496 int HandleCreatePlaybackCapturerManager(MessageParcel &data, MessageParcel &reply); 497 int HandleSetSupportStreamUsage(MessageParcel &data, MessageParcel &reply); 498 int HandleRegiestPolicyProvider(MessageParcel &data, MessageParcel &reply); 499 int HandleSetWakeupSourceCallback(MessageParcel &data, MessageParcel &reply); 500 int HandleSetCaptureSilentState(MessageParcel &data, MessageParcel &reply); 501 int HandleUpdateSpatializationState(MessageParcel &data, MessageParcel &reply); 502 int HandleUpdateSpatialDeviceType(MessageParcel& data, MessageParcel& reply); 503 int HandleOffloadSetVolume(MessageParcel &data, MessageParcel &reply); 504 int HandleNotifyStreamVolumeChanged(MessageParcel &data, MessageParcel &reply); 505 int HandleSetSpatializationSceneType(MessageParcel &data, MessageParcel &reply); 506 int HandleGetMaxAmplitude(MessageParcel &data, MessageParcel &reply); 507 int HandleResetAudioEndpoint(MessageParcel &data, MessageParcel &reply); 508 int HandleResetRouteForDisconnect(MessageParcel &data, MessageParcel &reply); 509 int HandleGetEffectLatency(MessageParcel &data, MessageParcel &reply); 510 int HandleUpdateLatencyTimestamp(MessageParcel &data, MessageParcel &reply); 511 int HandleSetAsrAecMode(MessageParcel &data, MessageParcel &reply); 512 int HandleGetAsrAecMode(MessageParcel &data, MessageParcel &reply); 513 int HandleSetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply); 514 int HandleGetAsrNoiseSuppressionMode(MessageParcel &data, MessageParcel &reply); 515 int HandleSetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply); 516 int HandleGetAsrWhisperDetectionMode(MessageParcel &data, MessageParcel &reply); 517 int HandleSetAsrVoiceControlMode(MessageParcel &data, MessageParcel &reply); 518 int HandleSetAsrVoiceMuteMode(MessageParcel &data, MessageParcel &reply); 519 int HandleIsWhispering(MessageParcel &data, MessageParcel &reply); 520 int HandleGetEffectOffloadEnabled(MessageParcel &data, MessageParcel &reply); 521 int HandleSuspendRenderSink(MessageParcel &data, MessageParcel &reply); 522 int HandleRestoreRenderSink(MessageParcel &data, MessageParcel &reply); 523 int HandleLoadHdiEffectModel(MessageParcel &data, MessageParcel &reply); 524 int HandleUpdateEffectBtOffloadSupported(MessageParcel &data, MessageParcel &reply); 525 int HandleSetSinkMuteForSwitchDevice(MessageParcel &data, MessageParcel &reply); 526 int HandleSetRotationToEffect(MessageParcel &data, MessageParcel &reply); 527 int HandleUpdateSessionConnectionState(MessageParcel &data, MessageParcel &reply); 528 int HandleSetNonInterruptMute(MessageParcel &data, MessageParcel &reply); 529 int HandleCreateIpcOfflineStream(MessageParcel &data, MessageParcel &reply); 530 int HandleGetOfflineAudioEffectChains(MessageParcel &data, MessageParcel &reply); 531 532 int HandleSecondPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 533 int HandleThirdPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 534 int HandleFourthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 535 int HandleFifthPartCode(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 536 }; 537 } // namespace AudioStandard 538 } // namespace OHOS 539 #endif // I_ST_AUDIO_MANAGER_BASE_H 540