1 /* 2 * Copyright (c) 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 AUDIO_COMMON_UTILS_H 17 #define AUDIO_COMMON_UTILS_H 18 19 #include <unordered_map> 20 #include <set> 21 22 namespace OHOS { 23 namespace AudioStandard { 24 25 class VolumeUtils { 26 public: 27 static AudioVolumeType GetVolumeTypeFromStreamType(AudioStreamType streamType); 28 static void SetPCVolumeEnable(const bool& isPCVolumeEnable); 29 static bool IsPCVolumeEnable(); 30 static AudioVolumeType GetVolumeTypeFromStreamUsage(StreamUsage streamUsage); 31 static std::set<StreamUsage> GetOverlapStreamUsageSet(const std::set<StreamUsage>& streamUsages, 32 AudioVolumeType volumeType); 33 static std::vector<AudioVolumeType> GetSupportedAudioVolumeTypes(); 34 static std::vector<StreamUsage> GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType); 35 static int32_t VolumeDegreeToLevel(int32_t degree); 36 static int32_t VolumeLevelToDegree(int32_t level); 37 private: 38 static std::set<StreamUsage>& GetStreamUsageSetForVolumeType(AudioVolumeType volumeType); 39 40 static std::unordered_map<AudioStreamType, AudioVolumeType> defaultVolumeMap_; 41 static std::unordered_map<AudioStreamType, AudioVolumeType> audioPCVolumeMap_; 42 static std::unordered_map<AudioStreamType, AudioVolumeType>& GetVolumeMap(); 43 static bool isPCVolumeEnable_; 44 static std::unordered_map<AudioVolumeType, std::set<StreamUsage>> defaultVolumeToStreamUsageMap_; 45 static std::unordered_map<AudioVolumeType, std::set<StreamUsage>> pcVolumeToStreamUsageMap_; 46 static std::unordered_map<StreamUsage, AudioStreamType> streamUsageMap_; 47 static std::unordered_set<AudioVolumeType> audioVolumeTypeSet_; 48 }; 49 } // namespace AudioStandard 50 } // namespace OHOS 51 #endif // AUDIO_COMMON_UTILS_H 52