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 const std::vector<AudioVolumeType> GET_STREAM_ALL_VOLUME_TYPES { 56 STREAM_MUSIC, 57 STREAM_RING, 58 STREAM_VOICE_CALL, 59 STREAM_VOICE_ASSISTANT 60 }; 61 AudioGroupManager(int32_t groupId); 62 virtual ~AudioGroupManager(); 63 static float MapVolumeToHDI(int32_t volume); 64 static int32_t MapVolumeFromHDI(float volume); 65 int32_t SetVolume(AudioVolumeType volumeType, int32_t volume); 66 int32_t GetVolume(AudioVolumeType volumeType); 67 int32_t GetMaxVolume(AudioVolumeType volumeType); 68 int32_t GetMinVolume(AudioVolumeType volumeType); 69 int32_t SetMute(AudioVolumeType volumeType, bool mute); 70 bool IsStreamMute(AudioVolumeType volumeType); 71 int32_t Init(); 72 bool IsAlived(); 73 int32_t GetGroupId(); 74 int32_t SetRingerModeCallback(const int32_t clientId, 75 const std::shared_ptr<AudioRingerModeCallback> &callback); 76 int32_t UnsetRingerModeCallback(const int32_t clientId) const; 77 int32_t SetRingerMode(AudioRingerMode ringMode) const; 78 AudioRingerMode GetRingerMode() const; 79 int32_t SetMicrophoneMute(bool isMute); 80 bool IsMicrophoneMute(API_VERSION api_v = API_9); 81 int32_t SetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback); 82 private: 83 int32_t groupId_; 84 ConnectType connectType_ = CONNECT_TYPE_LOCAL; 85 std::string netWorkId_ = LOCAL_NETWORK_ID; 86 int32_t cbClientId_ = -1; 87 static constexpr int32_t MAX_VOLUME_LEVEL = 15; 88 static constexpr int32_t MIN_VOLUME_LEVEL = 0; 89 static constexpr int32_t CONST_FACTOR = 100; 90 }; 91 } // namespace AudioStandard 92 } // namespace OHOS 93 #endif // ST_AUDIO_GROUP_MANAGER_H 94