1 /* 2 * Copyright (c) 2021-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_SYSTEM_MANAGER_H 17 #define ST_AUDIO_SYSTEM_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_device_descriptor.h" 28 #include "audio_stream_change_info.h" 29 #include "audio_interrupt_callback.h" 30 #include "audio_group_manager.h" 31 #include "audio_routing_manager.h" 32 #include "audio_policy_interface.h" 33 34 namespace OHOS { 35 namespace AudioStandard { 36 37 struct AudioSpatialEnabledStateForDevice { 38 std::shared_ptr<AudioDeviceDescriptor> deviceDescriptor; 39 bool enabled; 40 }; 41 42 struct DistributedRoutingInfo { 43 std::shared_ptr<AudioDeviceDescriptor> descriptor; 44 CastType type; 45 }; 46 47 class InterruptGroupInfo; 48 class InterruptGroupInfo : public Parcelable { 49 friend class AudioSystemManager; 50 public: 51 int32_t interruptGroupId_ = 0; 52 int32_t mappingId_ = 0; 53 std::string groupName_; 54 std::string networkId_; 55 ConnectType connectType_ = CONNECT_TYPE_LOCAL; 56 InterruptGroupInfo(); 57 InterruptGroupInfo(int32_t interruptGroupId, int32_t mappingId, std::string groupName, std::string networkId, 58 ConnectType type); 59 virtual ~InterruptGroupInfo(); 60 bool Marshalling(Parcel &parcel) const override; 61 static sptr<InterruptGroupInfo> Unmarshalling(Parcel &parcel); 62 }; 63 64 class VolumeGroupInfo; 65 class VolumeGroupInfo : public Parcelable { 66 friend class AudioSystemManager; 67 public: 68 int32_t volumeGroupId_ = 0; 69 int32_t mappingId_ = 0; 70 std::string groupName_; 71 std::string networkId_; 72 ConnectType connectType_ = CONNECT_TYPE_LOCAL; 73 74 /** 75 * @brief Volume group info. 76 * 77 * @since 9 78 */ 79 VolumeGroupInfo(); 80 81 /** 82 * @brief Volume group info. 83 * 84 * @param volumeGroupId volumeGroupId 85 * @param mappingId mappingId 86 * @param groupName groupName 87 * @param networkId networkId 88 * @param type type 89 * @since 9 90 */ 91 VolumeGroupInfo(int32_t volumeGroupId, int32_t mappingId, std::string groupName, std::string networkId, 92 ConnectType type); 93 virtual ~VolumeGroupInfo(); 94 95 /** 96 * @brief Marshall. 97 * 98 * @since 8 99 * @return bool 100 */ 101 bool Marshalling(Parcel &parcel) const override; 102 103 /** 104 * @brief Unmarshall. 105 * 106 * @since 8 107 * @return Returns volume group info 108 */ 109 static sptr<VolumeGroupInfo> Unmarshalling(Parcel &parcel); 110 }; 111 112 /** 113 * Describes the mic phone blocked device information. 114 * 115 * @since 13 116 */ 117 struct MicrophoneBlockedInfo { 118 DeviceBlockStatus blockStatus; 119 std::vector<std::shared_ptr<AudioDeviceDescriptor>> devices; 120 }; 121 122 /** 123 * @brief AudioRendererFilter is used for select speficed AudioRenderer. 124 */ 125 class AudioRendererFilter; 126 class AudioRendererFilter : public Parcelable { 127 friend class AudioSystemManager; 128 public: 129 AudioRendererFilter(); 130 virtual ~AudioRendererFilter(); 131 132 int32_t uid = -1; 133 AudioRendererInfo rendererInfo = {}; 134 AudioStreamType streamType = AudioStreamType::STREAM_DEFAULT; 135 int32_t streamId = -1; 136 137 bool Marshalling(Parcel &parcel) const override; 138 static sptr<AudioRendererFilter> Unmarshalling(Parcel &in); 139 }; 140 141 /** 142 * @brief AudioCapturerFilter is used for select speficed audiocapturer. 143 */ 144 class AudioCapturerFilter; 145 class AudioCapturerFilter : public Parcelable { 146 friend class AudioSystemManager; 147 public: 148 AudioCapturerFilter(); 149 virtual ~AudioCapturerFilter(); 150 151 int32_t uid = -1; 152 AudioCapturerInfo capturerInfo = {SOURCE_TYPE_INVALID, 0}; 153 154 bool Marshalling(Parcel &parcel) const override; 155 static sptr<AudioCapturerFilter> Unmarshalling(Parcel &in); 156 }; 157 158 // AudioManagerCallback OnInterrupt is added to handle compilation error in call manager 159 // Once call manager adapt to new interrupt APIs, this will be removed 160 class AudioManagerCallback { 161 public: 162 virtual ~AudioManagerCallback() = default; 163 /** 164 * Called when an interrupt is received. 165 * 166 * @param interruptAction Indicates the InterruptAction information needed by client. 167 * For details, refer InterruptAction struct in audio_info.h 168 */ 169 virtual void OnInterrupt(const InterruptAction &interruptAction) = 0; 170 std::mutex cbMutex_; 171 }; 172 173 class AudioManagerInterruptCallbackImpl : public AudioInterruptCallback { 174 public: 175 explicit AudioManagerInterruptCallbackImpl(); 176 virtual ~AudioManagerInterruptCallbackImpl(); 177 178 /** 179 * Called when an interrupt is received. 180 * 181 * @param interruptAction Indicates the InterruptAction information needed by client. 182 * For details, refer InterruptAction struct in audio_info.h 183 * @since 7 184 */ 185 void OnInterrupt(const InterruptEventInternal &interruptEvent) override; 186 void SaveCallback(const std::weak_ptr<AudioManagerCallback> &callback); 187 private: 188 std::weak_ptr<AudioManagerCallback> callback_; 189 std::shared_ptr<AudioManagerCallback> cb_; 190 }; 191 192 class AudioManagerAvailableDeviceChangeCallback { 193 public: 194 virtual ~AudioManagerAvailableDeviceChangeCallback() = default; 195 /** 196 * Called when an interrupt is received. 197 * 198 * @param deviceChangeAction Indicates the DeviceChangeAction information needed by client. 199 * For details, refer DeviceChangeAction struct 200 * @since 11 201 */ 202 virtual void OnAvailableDeviceChange(const AudioDeviceUsage usage, 203 const DeviceChangeAction &deviceChangeAction) = 0; 204 }; 205 206 class AudioManagerMicrophoneBlockedCallback { 207 public: 208 virtual ~AudioManagerMicrophoneBlockedCallback() = default; 209 /** 210 * Called when micro phone is blocked. 211 * 212 * @param microphoneBlockedInfo Indicates the MisPhoneBlockedInfo information needed by client. 213 * For details, refer MisPhoneBlockedInfo struct 214 * @since 13 215 */ 216 virtual void OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo) = 0; 217 }; 218 219 class AudioParameterCallback { 220 public: 221 virtual ~AudioParameterCallback() = default; 222 /** 223 * @brief AudioParameterCallback will be executed when parameter change. 224 * 225 * @param networkId networkId 226 * @param key Audio paramKey 227 * @param condition condition 228 * @param value value 229 * @since 9 230 */ 231 virtual void OnAudioParameterChange(const std::string networkId, const AudioParamKey key, 232 const std::string& condition, const std::string& value) = 0; 233 }; 234 235 class AudioCapturerSourceCallback { 236 public: 237 virtual ~AudioCapturerSourceCallback() = default; 238 virtual void OnCapturerState(bool isActive) = 0; 239 }; 240 241 class WakeUpSourceCloseCallback { 242 public: 243 virtual ~WakeUpSourceCloseCallback() = default; 244 virtual void OnWakeupClose() = 0; 245 }; 246 247 class WakeUpSourceCallback : public AudioCapturerSourceCallback, public WakeUpSourceCloseCallback { 248 public: 249 virtual ~WakeUpSourceCallback() = default; 250 // Stop all listening capturers from sending false callbacks; 251 // when all capturers have stopped, allow one capturer to start sending true callbacks 252 virtual void OnCapturerState(bool isActive) = 0; 253 virtual void OnWakeupClose() = 0; 254 }; 255 256 class AudioPreferredOutputDeviceChangeCallback; 257 258 class AudioDistributedRoutingRoleCallback { 259 public: 260 virtual ~AudioDistributedRoutingRoleCallback() = default; 261 262 /** 263 * Called when audio device descriptor change. 264 * 265 * @param descriptor Indicates the descriptor needed by client. 266 * For details, refer AudioDeviceDescriptor in audio_system_manager.h 267 * @since 9 268 */ 269 virtual void OnDistributedRoutingRoleChange( 270 std::shared_ptr<AudioDeviceDescriptor>descriptor, const CastType type) = 0; 271 std::mutex cbMutex_; 272 }; 273 274 class AudioDistributedRoutingRoleCallbackImpl : public AudioDistributedRoutingRoleCallback { 275 public: 276 explicit AudioDistributedRoutingRoleCallbackImpl(); 277 virtual ~AudioDistributedRoutingRoleCallbackImpl(); 278 279 /** 280 * Called when audio device descriptor change. 281 * 282 * @param descriptor Indicates the descriptor needed by client. 283 * For details, refer AudioDeviceDescriptor in audio_system_manager.h 284 * @since 9 285 */ 286 void OnDistributedRoutingRoleChange( 287 std::shared_ptr<AudioDeviceDescriptor>descriptor, const CastType type) override; 288 void SaveCallback(const std::shared_ptr<AudioDistributedRoutingRoleCallback> &callback); 289 void RemoveCallback(const std::shared_ptr<AudioDistributedRoutingRoleCallback> &callback); 290 private: 291 std::list<std::shared_ptr<AudioDistributedRoutingRoleCallback>> callbackList_; 292 std::shared_ptr<AudioDistributedRoutingRoleCallback> cb_; 293 std::mutex cbListMutex_; 294 }; 295 296 class AudioDeviceAnahs { 297 public: 298 virtual ~AudioDeviceAnahs() = default; 299 300 virtual int32_t OnExtPnpDeviceStatusChanged(std::string anahsStatus, std::string anahsShowType) = 0; 301 }; 302 303 /** 304 * @brief The AudioSystemManager class is an abstract definition of audio manager. 305 * Provides a series of client/interfaces for audio management 306 */ 307 308 class AudioSystemManager { 309 public: 310 static AudioSystemManager *GetInstance(); 311 312 /** 313 * @brief Map volume to HDI. 314 * 315 * @param volume volume value. 316 * @return Returns current volume. 317 * @since 8 318 */ 319 static float MapVolumeToHDI(int32_t volume); 320 321 /** 322 * @brief Map volume from HDI. 323 * 324 * @param volume volume value. 325 * @return Returns current volume. 326 * @since 8 327 */ 328 static int32_t MapVolumeFromHDI(float volume); 329 330 /** 331 * @brief Get audio streamType. 332 * 333 * @param contentType Enumerates the audio content type. 334 * @param streamUsage Enumerates the stream usage. 335 * @return Returns Audio streamType. 336 * @since 8 337 */ 338 static AudioStreamType GetStreamType(ContentType contentType, StreamUsage streamUsage); 339 340 /** 341 * @brief Set the stream volume. 342 * 343 * @param volumeType Enumerates the audio volume type. 344 * @param volume The volume to be set for the current stream. 345 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 346 * defined in {@link audio_errors.h} otherwise. 347 * @since 8 348 */ 349 int32_t SetVolume(AudioVolumeType volumeType, int32_t volume) const; 350 351 /** 352 * @brief Set the stream volume. 353 * 354 * @param volumeType Enumerates the audio volume type. 355 * @param volume The volume to be set for the current stream. 356 * @param deviceType The volume to be set for the device. 357 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 358 * defined in {@link audio_errors.h} otherwise. 359 * @since 16 360 */ 361 int32_t SetVolumeWithDevice(AudioVolumeType volumeType, int32_t volume, DeviceType deviceType) const; 362 363 /** 364 * @brief Set the app volume. 365 * 366 * @param appUid app uid. 367 * @param volume The volume to be set for the current uid app. 368 * @param flag Is need update ui 369 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 370 * defined in {@link audio_errors.h} otherwise. 371 */ 372 int32_t SetAppVolume(const int32_t appUid, const int32_t volume, const int32_t flag = 0); 373 374 /** 375 * @brief Set self app volume. 376 * 377 * @param volume The volume to be set for the current app. 378 * @param flag Is need update ui 379 * @return self app volume level 380 */ 381 int32_t SetSelfAppVolume(const int32_t volume, const int32_t flag = 0); 382 383 /** 384 * @brief Get uid app volume. 385 * 386 * @param appUid App uid. 387 * @return uid app volume level 388 */ 389 int32_t GetAppVolume(int32_t appUid) const; 390 391 /** 392 * @brief Get the uid app volume. 393 * 394 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 395 * defined in {@link audio_errors.h} otherwise. 396 */ 397 int32_t GetSelfAppVolume() const; 398 399 /** 400 * @brief Set self app volume change callback. 401 * 402 * @param callback callback when app volume change. 403 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 404 * defined in {@link audio_errors.h} otherwise. 405 */ 406 int32_t SetSelfAppVolumeCallback(const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback); 407 408 /** 409 * @brief Unset self app volume change callback. 410 * 411 * @param callback Unset the callback. 412 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 413 * defined in {@link audio_errors.h} otherwise. 414 */ 415 int32_t UnsetSelfAppVolumeCallback(const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback = nullptr); 416 417 /** 418 * @brief Set app volume change callback. 419 * 420 * @param appUid app uid. 421 * @param callback callback when app volume changed 422 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 423 * defined in {@link audio_errors.h} otherwise. 424 */ 425 int32_t SetAppVolumeCallbackForUid(const int32_t appUid, 426 const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback); 427 428 /** 429 * @brief Unset app volume change callback. 430 * 431 * @param callback Unset the callback. 432 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 433 * defined in {@link audio_errors.h} otherwise. 434 */ 435 int32_t UnsetAppVolumeCallbackForUid( 436 const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback = nullptr); 437 438 /** 439 * @brief Set the uid app volume muted. 440 * @param appUid app uid 441 * @param muted muted or unmuted. 442 * @param flag Is need update ui 443 * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code 444 * defined in {@link audio_errors.h} otherwise. 445 */ 446 int32_t SetAppVolumeMuted(const int32_t appUid, const bool muted, const int32_t flag = 0); 447 448 /** 449 * @brief Check the uid app volume is muted. 450 * @param appUid app uid 451 * @param owned If true is passed, the result will be indicated your owned muted statesettings to 452 * this app. Otherwise if false is passed, the result will be indicated the real muted state. 453 * @return the app uid muted status 454 */ 455 bool IsAppVolumeMute(const int32_t appUid, const bool owned); 456 /** 457 * @brief Obtains the current stream volume. 458 * 459 * @param volumeType Enumerates the audio volume type. 460 * @return Returns current stream volume. 461 * @since 8 462 */ 463 int32_t GetVolume(AudioVolumeType volumeType) const; 464 465 /** 466 * @brief Set volume discount factor. 467 * 468 * @param streamId stream Unique identification. 469 * @param volume Adjustment percentage. 470 * @return Whether the operation is effective 471 * @since 9 472 */ 473 int32_t SetLowPowerVolume(int32_t streamId, float volume) const; 474 475 /** 476 * @brief get volume discount factor. 477 * 478 * @param streamId stream Unique identification. 479 * @return Returns current stream volume. 480 * @since 9 481 */ 482 float GetLowPowerVolume(int32_t streamId) const; 483 484 /** 485 * @brief get single stream volume. 486 * 487 * @param streamId stream Unique identification. 488 * @return Returns current stream volume. 489 * @since 9 490 */ 491 float GetSingleStreamVolume(int32_t streamId) const; 492 493 /** 494 * @brief get max stream volume. 495 * 496 * @param volumeType audio volume type. 497 * @return Returns current stream volume. 498 * @since 8 499 */ 500 int32_t GetMaxVolume(AudioVolumeType volumeType); 501 502 /** 503 * @brief get min stream volume. 504 * 505 * @param volumeType audio volume type. 506 * @return Returns current stream volume. 507 * @since 8 508 */ 509 int32_t GetMinVolume(AudioVolumeType volumeType); 510 511 /** 512 * @brief set stream mute. 513 * 514 * @param volumeType audio volume type. 515 * @param mute Specifies whether the stream is muted. 516 * @param deivceType Specifies which device to mute. 517 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 518 * in {@link audio_errors.h} otherwise. 519 * @since 8 520 */ 521 int32_t SetMute(AudioVolumeType volumeType, bool mute, const DeviceType &deviceType = DEVICE_TYPE_NONE) const; 522 523 /** 524 * @brief is stream mute. 525 * 526 * @param volumeType audio volume type. 527 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 528 * @since 8 529 */ 530 bool IsStreamMute(AudioVolumeType volumeType) const; 531 532 /** 533 * @brief Set global microphone mute state. 534 * 535 * @param mute Specifies whether the Microphone is muted. 536 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 537 * in {@link audio_errors.h} otherwise. 538 * @since 8 539 */ 540 int32_t SetMicrophoneMute(bool isMute); 541 542 /** 543 * @brief get global microphone mute state. 544 * 545 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 546 * @since 9 547 */ 548 bool IsMicrophoneMute(); 549 550 /** 551 * @brief Select output device. 552 * 553 * @param audioDeviceDescriptors Output device object. 554 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 555 * in {@link audio_errors.h} otherwise. 556 * @since 9 557 */ 558 int32_t SelectOutputDevice(std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 559 560 /** 561 * @brief Select input device. 562 * 563 * @param audioDeviceDescriptors Output device object. 564 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 565 * in {@link audio_errors.h} otherwise. 566 * @since 9 567 */ 568 int32_t SelectInputDevice(std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 569 570 /** 571 * @brief get selected device info. 572 * 573 * @param uid identifier. 574 * @param pid identifier. 575 * @param streamType audio stream type. 576 * @return Returns device info. 577 * @since 9 578 */ 579 std::string GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType) const; 580 581 /** 582 * @brief Select the audio output device according to the filter conditions. 583 * 584 * @param audioRendererFilter filter conditions. 585 * @param audioDeviceDescriptors Output device object. 586 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 587 * in {@link audio_errors.h} otherwise. 588 * @since 9 589 */ 590 int32_t SelectOutputDevice(sptr<AudioRendererFilter> audioRendererFilter, 591 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 592 593 /** 594 * @brief Select the audio input device according to the filter conditions. 595 * 596 * @param audioRendererFilter filter conditions. 597 * @param audioDeviceDescriptors Output device object. 598 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 599 * in {@link audio_errors.h} otherwise. 600 * @since 9 601 */ 602 int32_t SelectInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter, 603 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 604 605 /** 606 * @brief Exclude the audio output device according to the DeviceUsage. 607 * 608 * @param audioDevUsage AudioDeviceUsage. 609 * @param audioDeviceDescriptors Output device object. 610 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 611 * in {@link audio_errors.h} otherwise. 612 * @since 16 613 */ 614 int32_t ExcludeOutputDevices(AudioDeviceUsage audioDevUsage, 615 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 616 617 /** 618 * @brief Unexclude the audio output device according to the DeviceUsage. 619 * 620 * @param audioDevUsage AudioDeviceUsage. 621 * @param audioDeviceDescriptors Output device object. 622 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 623 * in {@link audio_errors.h} otherwise. 624 * @since 16 625 */ 626 int32_t UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage, 627 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors) const; 628 629 /** 630 * @brief Unexclude the audio output device according to the DeviceUsage. 631 * 632 * @param audioDevUsage AudioDeviceUsage. 633 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 634 * in {@link audio_errors.h} otherwise. 635 * @since 16 636 */ 637 int32_t UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage) const; 638 639 /** 640 * @brief Get the list of excluded audio output devices according to the DeviceUsage. 641 * 642 * @param audioDevUsage AudioDeviceUsage. 643 * @return Returns the device list is obtained. 644 * @since 16 645 */ 646 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetExcludedDevices( 647 AudioDeviceUsage audioDevUsage) const; 648 649 /** 650 * @brief Get the list of audio devices. 651 * 652 * @param deviceFlag Flag of device type. 653 * @param GetAudioParameter Key of audio parameters to be obtained. 654 * @return Returns the device list is obtained. 655 * @since 9 656 */ 657 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevices(DeviceFlag deviceFlag); 658 659 /** 660 * @brief Get the list of audio devices (inner). 661 * 662 * @param deviceFlag Flag of device type. 663 * @return Returns the device list is obtained. 664 * @since 12 665 */ 666 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesInner(DeviceFlag deviceFlag); 667 668 /** 669 * @brief Get the audio output device according to the filter conditions. 670 * 671 * @param AudioRendererFilter filter conditions. 672 * @return Returns the device list is obtained. 673 * @since 12 674 */ 675 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetOutputDevice(sptr<AudioRendererFilter> audioRendererFilter); 676 677 /** 678 * @brief Get the audio input device according to the filter conditions. 679 * 680 * @param AudioCapturerFilter filter conditions. 681 * @return Returns the device list is obtained. 682 * @since 12 683 */ 684 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter); 685 686 /** 687 * @brief Get audio parameter. 688 * 689 * @param key Key of audio parameters to be obtained. 690 * @return Returns the value of the obtained audio parameter 691 * @since 9 692 */ 693 const std::string GetAudioParameter(const std::string key); 694 695 /** 696 * @brief set audio parameter. 697 * 698 * @param key The key of the set audio parameter. 699 * @param value The value of the set audio parameter. 700 * @since 9 701 */ 702 void SetAudioParameter(const std::string &key, const std::string &value); 703 704 /** 705 * @brief set audio parameter. 706 * 707 * @parame key The key of the set audio parameter. 708 * @param value The value of the set audio parameter. 709 * @since 12 710 */ 711 int32_t SetAsrAecMode(const AsrAecMode asrAecMode); 712 /** 713 * @brief set audio parameter. 714 * 715 * @parame key The key of the set audio parameter. 716 * @param value The value of the set audio parameter. 717 * @since 12 718 */ 719 int32_t GetAsrAecMode(AsrAecMode &asrAecMode); 720 /** 721 * @brief set audio parameter. 722 * 723 * @parame key The key of the set audio parameter. 724 * @param value The value of the set audio parameter. 725 * @since 12 726 */ 727 int32_t SetAsrNoiseSuppressionMode(const AsrNoiseSuppressionMode asrNoiseSuppressionMode); 728 /** 729 * @brief set audio parameter. 730 * 731 * @parame key The key of the set audio parameter. 732 * @param value The value of the set audio parameter. 733 * @since 12 734 */ 735 int32_t GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode &asrNoiseSuppressionMode); 736 /** 737 * @brief set audio parameter. 738 * 739 * @parame key The key of the set audio parameter. 740 * @param value The value of the set audio parameter. 741 * @since 12 742 */ 743 int32_t SetAsrWhisperDetectionMode(const AsrWhisperDetectionMode asrWhisperDetectionMode); 744 /** 745 * @brief set audio parameter. 746 * 747 * @parame key The key of the set audio parameter. 748 * @param value The value of the set audio parameter. 749 * @since 12 750 */ 751 int32_t GetAsrWhisperDetectionMode(AsrWhisperDetectionMode &asrWhisperDetectionMode); 752 /** 753 * @brief set audio parameter. 754 * 755 * @parame key The key of the set audio parameter. 756 * @param value The value of the set audio parameter. 757 * @since 12 758 */ 759 int32_t SetAsrVoiceControlMode(const AsrVoiceControlMode asrVoiceControlMode, bool on); 760 /** 761 * @brief set audio parameter. 762 * 763 * @parame key The key of the set audio parameter. 764 * @param value The value of the set audio parameter. 765 * @since 12 766 */ 767 int32_t SetAsrVoiceMuteMode(const AsrVoiceMuteMode asrVoiceMuteMode, bool on); 768 /** 769 * @brief set audio parameter. 770 * 771 * @parame key The key of the set audio parameter. 772 * @param value The value of the set audio parameter. 773 * @since 12 774 */ 775 int32_t IsWhispering(); 776 777 /** 778 * @brief Get audio parameter. 779 * 780 * @param mainKey Main key of audio parameters to be obtained. 781 * @param subKeys subKeys of audio parameters to be obtained. 782 * @param result value of sub key parameters. 783 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 784 * @since 11 785 */ 786 int32_t GetExtraParameters(const std::string &mainKey, 787 const std::vector<std::string> &subKeys, std::vector<std::pair<std::string, std::string>> &result); 788 789 /** 790 * @brief Set audio parameters. 791 * 792 * @param key The main key of the set audio parameter. 793 * @param kvpairs The pairs with sub keys and values of the set audio parameter. 794 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 795 * @since 11 796 */ 797 int32_t SetExtraParameters(const std::string &key, 798 const std::vector<std::pair<std::string, std::string>> &kvpairs); 799 800 /** 801 * @brief Get transaction Id. 802 * 803 * @param deviceType device type. 804 * @param deviceRole device role. 805 * @return Returns transaction Id. 806 * @since 9 807 */ 808 uint64_t GetTransactionId(DeviceType deviceType, DeviceRole deviceRole); 809 810 /** 811 * @brief Set device active. 812 * 813 * @param deviceType device type. 814 * @param flag Device activation status. 815 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 816 * in {@link audio_errors.h} otherwise. 817 * @since 9 818 */ 819 int32_t SetDeviceActive(DeviceType deviceType, bool flag, const int32_t clientUid = -1) const; 820 821 /** 822 * @brief get device active. 823 * 824 * @param deviceType device type. 825 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 826 * @since 9 827 */ 828 bool IsDeviceActive(DeviceType deviceType) const; 829 830 /** 831 * @brief get active output device. 832 * 833 * @return Returns device type. 834 * @since 9 835 */ 836 DeviceType GetActiveOutputDevice(); 837 838 /** 839 * @brief get active input device. 840 * 841 * @return Returns device type. 842 * @since 9 843 */ 844 DeviceType GetActiveInputDevice(); 845 846 /** 847 * @brief Is stream active. 848 * 849 * @param volumeType audio volume type. 850 * @return Returns <b>true</b> if the rendering is successfully started; returns <b>false</b> otherwise. 851 * @since 9 852 */ 853 bool IsStreamActive(AudioVolumeType volumeType) const; 854 855 /** 856 * @brief Set ringer mode. 857 * 858 * @param ringMode audio ringer mode. 859 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 860 * in {@link audio_errors.h} otherwise. 861 * @since 8 862 */ 863 int32_t SetRingerMode(AudioRingerMode ringMode); 864 865 /** 866 * @brief Get ringer mode. 867 * 868 * @return Returns audio ringer mode. 869 * @since 8 870 */ 871 AudioRingerMode GetRingerMode(); 872 873 /** 874 * @brief Set audio scene. 875 * 876 * @param scene audio scene. 877 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 878 * in {@link audio_errors.h} otherwise. 879 * @since 8 880 */ 881 int32_t SetAudioScene(const AudioScene &scene); 882 883 /** 884 * @brief Get audio scene. 885 * 886 * @return Returns audio scene. 887 * @since 8 888 */ 889 AudioScene GetAudioScene() const; 890 891 /** 892 * @brief Registers the deviceChange callback listener. 893 * 894 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 895 * defined in {@link audio_errors.h} otherwise. 896 * @since 8 897 */ 898 int32_t SetDeviceChangeCallback(const DeviceFlag flag, const std::shared_ptr<AudioManagerDeviceChangeCallback> 899 &callback); 900 901 /** 902 * @brief Unregisters the deviceChange callback listener 903 * 904 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 905 * defined in {@link audio_errors.h} otherwise. 906 * @since 8 907 */ 908 int32_t UnsetDeviceChangeCallback(DeviceFlag flag = DeviceFlag::ALL_DEVICES_FLAG, 909 std::shared_ptr<AudioManagerDeviceChangeCallback> callback = nullptr); 910 911 /** 912 * @brief Registers the ringerMode callback listener. 913 * 914 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 915 * defined in {@link audio_errors.h} otherwise. 916 * @since 8 917 */ 918 int32_t SetRingerModeCallback(const int32_t clientId, 919 const std::shared_ptr<AudioRingerModeCallback> &callback); 920 921 /** 922 * @brief Unregisters the VolumeKeyEvent callback listener 923 * 924 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 925 * defined in {@link audio_errors.h} otherwise. 926 * @since 8 927 */ 928 int32_t UnsetRingerModeCallback(const int32_t clientId) const; 929 930 /** 931 * @brief registers the volumeKeyEvent callback listener 932 * 933 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 934 * defined in {@link audio_errors.h} otherwise. 935 * @since 8 936 */ 937 int32_t RegisterVolumeKeyEventCallback(const int32_t clientPid, 938 const std::shared_ptr<VolumeKeyEventCallback> &callback, API_VERSION api_v = API_9); 939 940 /** 941 * @brief Unregisters the volumeKeyEvent callback listener 942 * 943 * @return Returns {@link SUCCESS} if callback unregistration is successful; returns an error code 944 * defined in {@link audio_errors.h} otherwise. 945 * @since 8 946 */ 947 int32_t UnregisterVolumeKeyEventCallback(const int32_t clientPid, 948 const std::shared_ptr<VolumeKeyEventCallback> &callback = nullptr); 949 950 /** 951 * @brief Set mono audio state 952 * 953 * @param monoState mono state 954 * @since 8 955 */ 956 void SetAudioMonoState(bool monoState); 957 958 /** 959 * @brief Set audio balance value 960 * 961 * @param balanceValue balance value 962 * @since 8 963 */ 964 void SetAudioBalanceValue(float balanceValue); 965 966 /** 967 * @brief Set system sound uri 968 * 969 * @param key the key of uri 970 * @param uri the value of uri 971 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 972 * defined in {@link audio_errors.h} otherwise. 973 * @since 10 974 */ 975 int32_t SetSystemSoundUri(const std::string &key, const std::string &uri); 976 977 /** 978 * @brief Get system sound uri 979 * 980 * @param key the key of uri 981 * @return Returns the value of uri for the key 982 * @since 10 983 */ 984 std::string GetSystemSoundUri(const std::string &key); 985 986 // Below APIs are added to handle compilation error in call manager 987 // Once call manager adapt to new interrupt APIs, this will be removed 988 989 /** 990 * @brief registers the audioManager callback listener 991 * 992 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 993 * defined in {@link audio_errors.h} otherwise. 994 * @since 8 995 */ 996 int32_t SetAudioManagerCallback(const AudioVolumeType streamType, 997 const std::shared_ptr<AudioManagerCallback> &callback); 998 999 /** 1000 * @brief Unregisters the audioManager callback listener 1001 * 1002 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1003 * defined in {@link audio_errors.h} otherwise. 1004 * @since 8 1005 */ 1006 int32_t UnsetAudioManagerCallback(const AudioVolumeType streamType) const; 1007 1008 /** 1009 * @brief Activate audio Interrupt 1010 * 1011 * @param audioInterrupt audioInterrupt 1012 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1013 * defined in {@link audio_errors.h} otherwise. 1014 * @since 8 1015 */ 1016 int32_t ActivateAudioInterrupt(AudioInterrupt &audioInterrupt); 1017 1018 /** 1019 * @brief Deactivactivate audio Interrupt 1020 * 1021 * @param audioInterrupt audioInterrupt 1022 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1023 * defined in {@link audio_errors.h} otherwise. 1024 * @since 8 1025 */ 1026 int32_t DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt) const; 1027 1028 /** 1029 * @brief registers the Interrupt callback listener 1030 * 1031 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1032 * defined in {@link audio_errors.h} otherwise. 1033 * @since 8 1034 */ 1035 int32_t SetAudioManagerInterruptCallback(const std::shared_ptr<AudioManagerCallback> &callback); 1036 1037 /** 1038 * @brief Unregisters the Interrupt callback listener 1039 * 1040 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1041 * defined in {@link audio_errors.h} otherwise. 1042 * @since 8 1043 */ 1044 int32_t UnsetAudioManagerInterruptCallback(); 1045 1046 /** 1047 * @brief Request audio focus 1048 * 1049 * @param audioInterrupt audioInterrupt 1050 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1051 * defined in {@link audio_errors.h} otherwise. 1052 * @since 8 1053 */ 1054 int32_t RequestAudioFocus(const AudioInterrupt &audioInterrupt); 1055 1056 /** 1057 * @brief Abandon audio focus 1058 * 1059 * @param audioInterrupt audioInterrupt 1060 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1061 * defined in {@link audio_errors.h} otherwise. 1062 * @since 8 1063 */ 1064 int32_t AbandonAudioFocus(const AudioInterrupt &audioInterrupt); 1065 1066 /** 1067 * @brief Reconfigure audio channel 1068 * 1069 * @param count count 1070 * @param deviceType device type 1071 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1072 * defined in {@link audio_errors.h} otherwise. 1073 * @since 8 1074 */ 1075 int32_t ReconfigureAudioChannel(const uint32_t &count, DeviceType deviceType); 1076 1077 /** 1078 * @brief Request independent interrupt 1079 * 1080 * @param focusType focus type 1081 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 1082 * in {@link audio_errors.h} otherwise. 1083 * @since 8 1084 */ 1085 bool RequestIndependentInterrupt(FocusType focusType); 1086 1087 /** 1088 * @brief Abandon independent interrupt 1089 * 1090 * @param focusType focus type 1091 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 1092 * in {@link audio_errors.h} otherwise. 1093 * @since 8 1094 */ 1095 bool AbandonIndependentInterrupt(FocusType focusType); 1096 1097 /** 1098 * @brief Update stream state 1099 * 1100 * @param clientUid client Uid 1101 * @param streamSetState streamSetState 1102 * @param streamUsage streamUsage 1103 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1104 * defined in {@link audio_errors.h} otherwise. 1105 * @since 8 1106 */ 1107 int32_t UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState, 1108 StreamUsage streamUsage); 1109 1110 /** 1111 * @brief Get Pin Value From Type 1112 * 1113 * @param deviceType deviceType 1114 * @param deviceRole deviceRole 1115 * @return Returns Enumerate AudioPin 1116 * @since 8 1117 */ 1118 AudioPin GetPinValueFromType(DeviceType deviceType, DeviceRole deviceRole) const; 1119 1120 /** 1121 * @brief Get type Value From Pin 1122 * 1123 * @param pin AudioPin 1124 * @return Returns Enumerate DeviceType 1125 * @since 8 1126 */ 1127 DeviceType GetTypeValueFromPin(AudioPin pin) const; 1128 1129 /** 1130 * @brief Get volume groups 1131 * 1132 * @param networkId networkId 1133 * @param info VolumeGroupInfo 1134 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1135 * defined in {@link audio_errors.h} otherwise. 1136 * @since 8 1137 */ 1138 int32_t GetVolumeGroups(std::string networkId, std::vector<sptr<VolumeGroupInfo>> &info); 1139 1140 /** 1141 * @brief Get volume groups manager 1142 * 1143 * @param networkId networkId 1144 * @return Returns AudioGroupManager 1145 * @since 8 1146 */ 1147 std::shared_ptr<AudioGroupManager> GetGroupManager(int32_t groupId); 1148 1149 /** 1150 * @brief Get active output deviceDescriptors 1151 * 1152 * @return Returns AudioDeviceDescriptor 1153 * @since 8 1154 */ 1155 std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetActiveOutputDeviceDescriptors(); 1156 1157 /** 1158 * @brief Get preferred input device deviceDescriptors 1159 * 1160 * @return Returns AudioDeviceDescriptor 1161 * @since 10 1162 */ 1163 int32_t GetPreferredInputDeviceDescriptors(); 1164 1165 /** 1166 * @brief Get audio focus info 1167 * 1168 * @return Returns success or not 1169 * @since 10 1170 */ 1171 int32_t GetAudioFocusInfoList(std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList); 1172 1173 /** 1174 * @brief Register callback to listen audio focus info change event 1175 * 1176 * @return Returns success or not 1177 * @since 10 1178 */ 1179 int32_t RegisterFocusInfoChangeCallback(const std::shared_ptr<AudioFocusInfoChangeCallback> &callback); 1180 1181 /** 1182 * @brief Unregister callback to listen audio focus info change event 1183 * 1184 * @return Returns success or not 1185 * @since 10 1186 */ 1187 int32_t UnregisterFocusInfoChangeCallback( 1188 const std::shared_ptr<AudioFocusInfoChangeCallback> &callback = nullptr); 1189 1190 int32_t SetAudioCapturerSourceCallback(const std::shared_ptr<AudioCapturerSourceCallback> &callback); 1191 1192 int32_t SetWakeUpSourceCloseCallback(const std::shared_ptr<WakeUpSourceCloseCallback> &callback); 1193 1194 /** 1195 * @brief Set whether or not absolute volume is supported for the specified Bluetooth device 1196 * 1197 * @return Returns success or not 1198 * @since 11 1199 */ 1200 int32_t SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support); 1201 1202 /** 1203 * @brief Set the absolute volume value for the specified Bluetooth device 1204 * 1205 * @return Returns success or not 1206 * @since 11 1207 */ 1208 int32_t SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, const bool updateUi); 1209 /** 1210 * @brief Registers the availbale deviceChange callback listener. 1211 * 1212 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1213 * defined in {@link audio_errors.h} otherwise. 1214 * @since 11 1215 */ 1216 int32_t SetAvailableDeviceChangeCallback(const AudioDeviceUsage usage, 1217 const std::shared_ptr<AudioManagerAvailableDeviceChangeCallback>& callback); 1218 /** 1219 * @brief UnRegisters the availbale deviceChange callback listener. 1220 * 1221 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1222 * defined in {@link audio_errors.h} otherwise. 1223 * @since 11 1224 */ 1225 int32_t UnsetAvailableDeviceChangeCallback(AudioDeviceUsage usage); 1226 1227 /** 1228 * @brief Switch the output device accoring different cast type. 1229 * 1230 * @return Returns {@link SUCCESS} if device is successfully switched; returns an error code 1231 * defined in {@link audio_errors.h} otherwise. 1232 * @since 11 1233 */ 1234 int32_t ConfigDistributedRoutingRole(std::shared_ptr<AudioDeviceDescriptor> desciptor, CastType type); 1235 1236 /** 1237 * @brief Registers the descriptor Change callback listener. 1238 * 1239 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1240 * defined in {@link audio_errors.h} otherwise. 1241 * @since 11 1242 */ 1243 int32_t SetDistributedRoutingRoleCallback(const std::shared_ptr<AudioDistributedRoutingRoleCallback> &callback); 1244 1245 /** 1246 * @brief UnRegisters the descriptor Change callback callback listener. 1247 * 1248 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1249 * defined in {@link audio_errors.h} otherwise. 1250 * @since 11 1251 */ 1252 int32_t UnsetDistributedRoutingRoleCallback(const std::shared_ptr<AudioDistributedRoutingRoleCallback> &callback); 1253 1254 /** 1255 * @brief Set device address. 1256 * 1257 * @param deviceType device type. 1258 * @param flag Device activation status. 1259 * @param address Device address 1260 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 1261 * in {@link audio_errors.h} otherwise. 1262 * @since 11 1263 */ 1264 int32_t SetCallDeviceActive(DeviceType deviceType, bool flag, std::string address, 1265 const int32_t clientUid = -1) const; 1266 1267 /** 1268 * @brief get the effect algorithmic latency value for a specified audio stream. 1269 * 1270 * @param sessionId the session ID value for the stream 1271 * @return Returns the effect algorithmic latency in ms. 1272 * @since 12 1273 */ 1274 uint32_t GetEffectLatency(const std::string &sessionId); 1275 1276 /** 1277 * @brief set useraction command 1278 * 1279 * @param actionCommand action command 1280 * @param paramInfo information 1281 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 1282 * in {@link audio_errors.h} otherwise. 1283 * @since 12 1284 */ 1285 int32_t DisableSafeMediaVolume(); 1286 1287 static void AudioServerDied(pid_t pid, pid_t uid); 1288 1289 int32_t SetMicrophoneBlockedCallback(const std::shared_ptr<AudioManagerMicrophoneBlockedCallback>& callback); 1290 int32_t UnsetMicrophoneBlockedCallback(std::shared_ptr<AudioManagerMicrophoneBlockedCallback> callback = nullptr); 1291 1292 /** 1293 * @brief Registers the audioScene change callback listener. 1294 * 1295 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1296 * defined in {@link audio_errors.h} otherwise. 1297 * @since 16 1298 */ 1299 int32_t SetAudioSceneChangeCallback(const std::shared_ptr<AudioManagerAudioSceneChangedCallback>& callback); 1300 1301 /** 1302 * @brief Registers the audioScene change callback listener. 1303 * 1304 * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code 1305 * defined in {@link audio_errors.h} otherwise. 1306 * @since 16 1307 */ 1308 int32_t UnsetAudioSceneChangeCallback(std::shared_ptr<AudioManagerAudioSceneChangedCallback> callback = nullptr); 1309 1310 std::string GetSelfBundleName(int32_t uid); 1311 1312 int32_t SetQueryClientTypeCallback(const std::shared_ptr<AudioQueryClientTypeCallback> &callback); 1313 int32_t SetAudioClientInfoMgrCallback(const std::shared_ptr<AudioClientInfoMgrCallback> &callback); 1314 int32_t SetQueryAllowedPlaybackCallback(const std::shared_ptr<AudioQueryAllowedPlaybackCallback> &callback); 1315 1316 /** 1317 * @brief inject interruption event. 1318 * 1319 * @param networkId networkId. 1320 * @param event Indicates the InterruptEvent information needed by client. 1321 * For details, refer InterruptEvent struct in audio_interrupt_info.h 1322 * @return Returns {@link SUCCESS} if the setting is successful; returns an error code defined 1323 * in {@link audio_errors.h} otherwise. 1324 * @since 12 1325 */ 1326 int32_t InjectInterruption(const std::string networkId, InterruptEvent &event); 1327 1328 /** 1329 * @brief Load the split module for audio stream separation. 1330 * 1331 * @param splitArgs Specifies the types of audio to be split into different streams. 1332 * @param networkId The network identifier of the output device. 1333 * @return Returns {@link SUCCESS} if the module is loaded successfully; otherwise, returns an error code defined 1334 * in {@link audio_errors.h}. 1335 * @since 12 1336 */ 1337 int32_t LoadSplitModule(const std::string &splitArgs, const std::string &networkId); 1338 1339 /** 1340 * @brief Set Custmoized Ring Back Tone mute state. 1341 * 1342 * @param isMute Specifies whether the Customized Ring Back Tone is muted. 1343 * @return Returns {@link SUCCESS} if the settings is successfully; otherwise, returns an error code defined 1344 * in {@link audio_errors.h}. 1345 */ 1346 int32_t SetVoiceRingtoneMute(bool isMute); 1347 1348 /** 1349 * @brief Get standby state. 1350 * 1351 * @param sessionId Specifies which stream to be check. 1352 * @param isStandby true means the stream is in standby status. 1353 * @param enterStandbyTime Specifies when the stream enter standby status, in MONOTONIC time. 1354 * @return Returns {@link SUCCESS} if the operation is successfully. 1355 * @return Returns {@link ERR_ILLEGAL_STATE} if the server is not available. 1356 * @return Returns {@link ERR_INVALID_PARAM} if the sessionId is not exist. 1357 */ 1358 int32_t GetStandbyStatus(uint32_t sessionId, bool &isStandby, int64_t &enterStandbyTime); 1359 1360 #ifdef HAS_FEATURE_INNERCAPTURER 1361 /** 1362 * @brief check capture limit 1363 * 1364 * @param AudioPlaybackCaptureConfig inner capture filter info 1365 * @param innerCapId unique identifier of inner capture 1366 * @return Returns {@link SUCCESS} if the operation is successfully. 1367 * @test 1368 */ 1369 int32_t CheckCaptureLimit(const AudioPlaybackCaptureConfig &config, int32_t &innerCapId); 1370 1371 /** 1372 * @brief release capture limit 1373 * 1374 * @param innerCapId unique identifier of inner capture 1375 * @return Returns {@link SUCCESS} if the operation is successfully. 1376 * @test 1377 */ 1378 int32_t ReleaseCaptureLimit(int32_t innerCapId); 1379 #endif 1380 1381 int32_t GenerateSessionId(uint32_t &sessionId); 1382 int32_t SetAudioInterruptCallback(const uint32_t sessionID, const std::shared_ptr<AudioInterruptCallback> &callback, 1383 uint32_t clientUid, const int32_t zoneID); 1384 int32_t UnsetAudioInterruptCallback(const int32_t zoneId, const uint32_t sessionId); 1385 1386 int32_t SetVirtualCall(const bool isVirtual); 1387 1388 int32_t OnVoiceWakeupState(bool state); 1389 private: 1390 class WakeUpCallbackImpl : public WakeUpSourceCallback { 1391 public: WakeUpCallbackImpl(AudioSystemManager * audioSystemManager)1392 WakeUpCallbackImpl(AudioSystemManager *audioSystemManager) 1393 :audioSystemManager_(audioSystemManager) 1394 { 1395 } OnCapturerState(bool isActive)1396 void OnCapturerState(bool isActive) override 1397 { 1398 auto callback = audioSystemManager_ -> audioCapturerSourceCallback_; 1399 if (callback != nullptr) { 1400 callback -> OnCapturerState(isActive); 1401 } 1402 } OnWakeupClose()1403 void OnWakeupClose() override 1404 { 1405 auto callback = audioSystemManager_ -> audioWakeUpSourceCloseCallback_; 1406 if (callback != nullptr) { 1407 callback -> OnWakeupClose(); 1408 } 1409 } 1410 private: 1411 AudioSystemManager *audioSystemManager_; 1412 }; 1413 1414 static constexpr int32_t MAX_VOLUME_LEVEL = 15; 1415 static constexpr int32_t MIN_VOLUME_LEVEL = 0; 1416 static constexpr int32_t CONST_FACTOR = 100; 1417 static const std::map<std::pair<ContentType, StreamUsage>, AudioStreamType> streamTypeMap_; 1418 1419 AudioSystemManager(); 1420 virtual ~AudioSystemManager(); 1421 1422 static std::map<std::pair<ContentType, StreamUsage>, AudioStreamType> CreateStreamMap(); 1423 static void CreateStreamMap(std::map<std::pair<ContentType, StreamUsage>, AudioStreamType> &streamMap); 1424 int32_t GetCallingPid() const; 1425 std::string GetSelfBundleName(); 1426 1427 int32_t RegisterWakeupSourceCallback(); 1428 void OtherDeviceTypeCases(DeviceType deviceType) const; 1429 1430 int32_t cbClientId_ = -1; 1431 int32_t volumeChangeClientPid_ = -1; 1432 AudioRingerMode ringModeBackup_ = RINGER_MODE_NORMAL; 1433 std::shared_ptr<AudioManagerDeviceChangeCallback> deviceChangeCallback_ = nullptr; 1434 std::shared_ptr<AudioInterruptCallback> audioInterruptCallback_ = nullptr; 1435 std::shared_ptr<AudioRingerModeCallback> ringerModeCallback_ = nullptr; 1436 std::shared_ptr<AudioFocusInfoChangeCallback> audioFocusInfoCallback_ = nullptr; 1437 std::shared_ptr<AudioDistributedRoutingRoleCallback> audioDistributedRoutingRoleCallback_ = nullptr; 1438 std::vector<std::shared_ptr<AudioGroupManager>> groupManagerMap_; 1439 std::mutex ringerModeCallbackMutex_; 1440 std::mutex groupManagerMapMutex_; 1441 1442 std::shared_ptr<AudioCapturerSourceCallback> audioCapturerSourceCallback_ = nullptr; 1443 std::shared_ptr<WakeUpSourceCloseCallback> audioWakeUpSourceCloseCallback_ = nullptr; 1444 1445 std::shared_ptr<WakeUpCallbackImpl> remoteWakeUpCallback_; 1446 }; 1447 } // namespace AudioStandard 1448 } // namespace OHOS 1449 #endif // ST_AUDIO_SYSTEM_MANAGER_H 1450