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_GROUP_MANAGER_H 17 #define ST_AUDIO_GROUP_MANAGER_H 18 19 #include <cstdlib> 20 #include <map> 21 #include <mutex> 22 #include <vector> 23 #include <unordered_map> 24 25 #include "parcel.h" 26 #include "audio_info.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 class AudioRingerModeCallback { 31 public: 32 virtual ~AudioRingerModeCallback() = default; 33 /** 34 * Called when ringer mode is updated. 35 * 36 * @param ringerMode Indicates the updated ringer mode value. 37 * For details, refer RingerMode enum in audio_info.h 38 */ 39 virtual void OnRingerModeUpdated(const AudioRingerMode &ringerMode) = 0; 40 }; 41 42 class AudioManagerMicStateChangeCallback { 43 public: 44 virtual ~AudioManagerMicStateChangeCallback() = default; 45 /** 46 * Called when the microphone state changes 47 * 48 * @param micStateChangeEvent Microphone Status Information. 49 */ 50 virtual void OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) = 0; 51 }; 52 53 class AudioGroupManager { 54 public: 55 AudioGroupManager(int32_t groupId); 56 virtual ~AudioGroupManager(); 57 58 int32_t SetVolume(AudioVolumeType volumeType, int32_t volume); 59 int32_t GetVolume(AudioVolumeType volumeType); 60 int32_t GetMaxVolume(AudioVolumeType volumeType); 61 int32_t GetMinVolume(AudioVolumeType volumeType); 62 int32_t SetMute(AudioVolumeType volumeType, bool mute); 63 int32_t IsStreamMute(AudioVolumeType volumeType, bool &isMute); 64 int32_t Init(); 65 bool IsAlived(); 66 int32_t GetGroupId(); 67 int32_t SetRingerModeCallback(const int32_t clientId, 68 const std::shared_ptr<AudioRingerModeCallback> &callback); 69 int32_t UnsetRingerModeCallback(const int32_t clientId) const; 70 int32_t SetRingerMode(AudioRingerMode ringMode) const; 71 AudioRingerMode GetRingerMode() const; 72 int32_t SetMicrophoneMute(bool isMute); 73 bool IsMicrophoneMute(API_VERSION api_v = API_9); 74 int32_t SetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback); 75 bool IsVolumeUnadjustable(); 76 int32_t AdjustVolumeByStep(VolumeAdjustType adjustType); 77 int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType); 78 float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType); 79 private: 80 int32_t groupId_; 81 ConnectType connectType_ = CONNECT_TYPE_LOCAL; 82 std::string netWorkId_ = LOCAL_NETWORK_ID; 83 int32_t cbClientId_ = -1; 84 static constexpr int32_t MAX_VOLUME_LEVEL = 15; 85 static constexpr int32_t MIN_VOLUME_LEVEL = 0; 86 static constexpr int32_t CONST_FACTOR = 100; 87 }; 88 } // namespace AudioStandard 89 } // namespace OHOS 90 #endif // ST_AUDIO_GROUP_MANAGER_H 91