1 /* 2 * Copyright (c) 2023-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 #ifndef AUDIO_VOLUME_PARSER_H 16 #define AUDIO_VOLUME_PARSER_H 17 18 #include <map> 19 #include <string> 20 #include <vector> 21 #include <unordered_map> 22 #include "audio_errors.h" 23 #include "audio_info.h" 24 #include "audio_policy_log.h" 25 #include "audio_volume_config.h" 26 #include "audio_xml_parser.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 31 class AudioVolumeParser { 32 public: 33 AudioVolumeParser(); 34 virtual ~AudioVolumeParser(); 35 int32_t LoadConfig(StreamVolumeInfoMap &streamVolumeInfoMap); 36 private: 37 #ifdef USE_CONFIG_POLICY 38 static constexpr char AUDIO_VOLUME_CONFIG_FILE[] = "etc/audio/audio_volume_config.xml"; 39 #else 40 static constexpr char AUDIO_VOLUME_CONFIG_FILE[] = "system/etc/audio/audio_volume_config.xml"; 41 #endif 42 std::map<std::string, AudioVolumeType> audioStreamMap_; 43 std::map<std::string, DeviceVolumeType> audioDeviceMap_; 44 45 void ParseStreamInfos(std::shared_ptr<AudioXmlNode> curNode, StreamVolumeInfoMap &streamVolumeInfoMap); 46 int32_t ParseStreamVolumeInfoAttr(std::shared_ptr<AudioXmlNode> curNode, 47 std::shared_ptr<StreamVolumeInfo> &streamVolInfo); 48 void ParseDeviceVolumeInfos(std::shared_ptr<AudioXmlNode> curNode, 49 std::shared_ptr<StreamVolumeInfo> &streamVolInfo); 50 void ParseVolumePoints(std::shared_ptr<AudioXmlNode> curNode, std::shared_ptr<DeviceVolumeInfo> &deviceVolInfo); 51 int32_t ParseVolumeConfig(const char *path, StreamVolumeInfoMap &streamVolumeInfoMap); 52 void WriteVolumeConfigErrorEvent(); 53 }; 54 } // namespace AudioStandard 55 } // namespace OHOS 56 #endif // AUDIO_VOLUME_PARSER_H 57