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 const char *AVCODEC_CONFIG_FILE = "/etc/codec/codec_caps.xml"; 43 AVCodecXmlParser(); 44 ~AVCodecXmlParser(); 45 bool LoadConfiguration(); 46 bool Parse(); 47 void Destroy(); 48 std::vector<CapabilityData> GetCapabilityDataArray(); 49 50 private: 51 bool IsNumberArray(const std::vector<std::string> &strArray); 52 bool TransStrAsRange(const std::string &str, Range &range); 53 bool TransStrAsSize(const std::string &str, ImgSize &size); 54 std::vector<int32_t> TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capabilityMap, 55 std::vector<std::string> &spilt); 56 std::vector<int32_t> TransStrAsIntegerArray(std::vector<std::string> &spilt); 57 bool SpiltKeyList(const std::string &str, const std::string &delim, std::vector<std::string> &spilt); 58 bool SetCapabilityStringData(std::unordered_map<std::string, std::string&> dataMap, 59 const std::string &capabilityKey, const std::string &capabilityValue); 60 bool SetCapabilityIntData(std::unordered_map<std::string, int32_t&> dataMap, 61 const std::string &capabilityKey, const std::string &capabilityValue); 62 bool SetCapabilityBoolData(std::unordered_map<std::string, bool&> dataMap, 63 const std::string &capabilityKey, const std::string &capabilityValue); 64 bool SetCapabilityRangeData(std::unordered_map<std::string, Range&> dataMap, 65 const std::string &capabilityKey, const std::string &capabilityValue); 66 bool SetCapabilityVectorData(std::unordered_map<std::string, std::vector<int32_t>&> dataMap, 67 const std::string &capabilityKey, const std::string &capabilityValue); 68 bool SetCapabilityData(CapabilityData &data, const std::string &capabilityKey, const std::string &capabilityValue); 69 bool SetCapabilitySizeData(std::unordered_map<std::string, ImgSize&> dataMap, 70 const std::string &capabilityKey, const std::string &capabilityValue); 71 bool SetCapabilityHashRangeData(std::unordered_map<std::string, std::map<ImgSize, Range>&> dataMap, 72 const std::string &capabilityKey, const std::string &capabilityValue); 73 74 bool ParseInternal(xmlNode *node); 75 NodeName GetNodeNameAsInt(xmlNode *node); 76 bool ParseData(xmlNode *node); 77 std::vector<CapabilityData> capabilityDataArray_; 78 xmlDoc *mDoc_; 79 std::string capabilityListVal_; 80 std::vector<std::string> capabilityKeys_ = { 81 "codecName", 82 "codecType", 83 "mimeType", 84 "isVendor", 85 "bitrate", 86 "channels", 87 "sampleRate", 88 "format", 89 "profiles", 90 "complexity", 91 "bitrateMode", 92 "alignment", 93 "width", 94 "height", 95 "frameRate", 96 "encodeQuality", 97 "quality", 98 "levels", 99 "blockPerFrame", 100 "blockPerSecond", 101 "blockSize", 102 "profileLevelsMap", 103 "measuredFrameRate", 104 }; 105 }; 106 } // namespace Media 107 } // namespace OHOS 108 #endif // AVCODEC_XML_PARSER_H 109