1 /* 2 * Copyright (C) 2021 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 AVCODEC_XML_PARSER_H 17 #define AVCODEC_XML_PARSER_H 18 19 #include <vector> 20 #include <string> 21 #include <unordered_map> 22 #include <libxml/parser.h> 23 #include <libxml/tree.h> 24 #include "avcodec_info.h" 25 #include "audio_info.h" 26 27 namespace OHOS { 28 namespace Media { 29 enum NodeName : int32_t { 30 CODECS, 31 AUDIO_CODECS, 32 VIDEO_CODECS, 33 AUDIO_DECODER, 34 AUDIO_ENCODER, 35 VIDEO_DECODER, 36 VIDEO_ENCODER, 37 UNKNOWN 38 }; 39 40 class AVCodecXmlParser { 41 public: 42 AVCodecXmlParser(); 43 ~AVCodecXmlParser(); 44 bool LoadConfiguration(); 45 bool Parse(); 46 void Destroy(); 47 std::vector<CapabilityData> GetCapabilityDataArray() const; 48 49 private: 50 static bool IsNumberArray(const std::vector<std::string> &strArray); 51 static bool TransStrAsRange(const std::string &str, Range &range); 52 static bool TransStrAsSize(const std::string &str, ImgSize &size); 53 static std::vector<int32_t> TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capabilityMap, 54 const std::vector<std::string> &spilt); 55 static std::vector<int32_t> TransStrAsIntegerArray(const std::vector<std::string> &spilt); 56 static bool SpiltKeyList(const std::string &str, const std::string &delim, std::vector<std::string> &spilt); 57 static bool SetCapabilityStringData(std::unordered_map<std::string, std::string&> dataMap, 58 const std::string &capabilityKey, const std::string &capabilityValue); 59 static bool SetCapabilityIntData(std::unordered_map<std::string, int32_t&> dataMap, 60 const std::string &capabilityKey, const std::string &capabilityValue); 61 static bool SetCapabilityBoolData(std::unordered_map<std::string, bool&> dataMap, 62 const std::string &capabilityKey, const std::string &capabilityValue); 63 static bool SetCapabilityRangeData(std::unordered_map<std::string, Range&> dataMap, 64 const std::string &capabilityKey, const std::string &capabilityValue); 65 static bool SetCapabilityVectorData(std::unordered_map<std::string, std::vector<int32_t>&> dataMap, 66 const std::string &capabilityKey, const std::string &capabilityValue); 67 static bool SetCapabilitySizeData(std::unordered_map<std::string, ImgSize&> dataMap, 68 const std::string &capabilityKey, const std::string &capabilityValue); 69 static bool SetCapabilityHashRangeData(std::unordered_map<std::string, std::map<ImgSize, Range>&> dataMap, 70 const std::string &capabilityKey, const std::string &capabilityValue); 71 static NodeName GetNodeNameAsInt(xmlNode *node); 72 bool SetCapabilityData(CapabilityData &data, const std::string &capabilityKey, 73 const std::string &capabilityValue) const; 74 bool ParseInternal(xmlNode *node); 75 bool ParseData(xmlNode *node); 76 std::vector<CapabilityData> capabilityDataArray_; 77 xmlDoc *mDoc_ = nullptr; 78 std::vector<std::string> capabilityKeys_; 79 }; 80 } // namespace Media 81 } // namespace OHOS 82 #endif // AVCODEC_XML_PARSER_H 83