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 RECORDERPROFILES_XML_PARSER_H 17 #define RECORDERPROFILES_XML_PARSER_H 18 19 #include "xml_parse.h" 20 #include "i_recorder_profiles_service.h" 21 22 namespace OHOS { 23 namespace Media { 24 enum class RecorderProfilesNodeName : int32_t { 25 RECORDER_CONFIGURATIONS, 26 RECORDER_CAPS, 27 RECORDER_PROFILES, 28 UNKNOWN, 29 }; 30 31 struct ContainerFormatInfo { 32 std::string name = ""; 33 std::string hasVideo = ""; 34 }; 35 36 class RecorderProfilesXmlParser : public XmlParser { 37 public: 38 RecorderProfilesXmlParser(); 39 ~RecorderProfilesXmlParser(); 40 std::vector<RecorderProfilesData> GetRecorderProfileDataArray(); 41 42 private: 43 bool ParseInternal(xmlNode *node) override; 44 bool SetCapabilityIntData(std::unordered_map<std::string, int32_t&> dataMap, 45 const std::string &capabilityKey, const std::string &capabilityValue) const override; 46 bool SetCapabilityVectorData(std::unordered_map<std::string, std::vector<int32_t>&> dataMap, 47 const std::string &capabilityKey, const std::string &capabilityValue) const override; 48 RecorderProfilesNodeName GetNodeNameAsInt(xmlNode *node); 49 bool SetVideoRecorderProfiles(RecorderProfilesData &data, const std::string &capabilityKey, 50 const std::string &capabilityValue); 51 bool SetAudioRecorderProfiles(RecorderProfilesData &data, const std::string &capabilityKey, 52 const std::string &capabilityValue); 53 bool SetVideoRecorderCaps(RecorderProfilesData &data, const std::string &capabilityKey, 54 const std::string &capabilityValue); 55 bool SetAudioRecorderCaps(RecorderProfilesData &data, const std::string &capabilityKey, 56 const std::string &capabilityValue); 57 bool SetContainerFormat(ContainerFormatInfo &data, const std::string &capabilityKey, 58 const std::string &capabilityValue); 59 bool ParseRecorderCapsData(xmlNode *node); 60 bool ParseRecorderContainerFormatData(xmlNode *node); 61 bool ParseRecorderEncodeCapsData(xmlNode *node, bool isVideo); 62 bool ParseRecorderProfilesData(xmlNode *node); 63 bool ParseRecorderProfilesSourceData(const std::string &sourceType, xmlNode *node); 64 bool ParseRecorderProfileSettingsData(xmlNode *node, RecorderProfilesData &capabilityData); 65 bool ParseRecorderProfileVideoAudioData(xmlNode *node, RecorderProfilesData &capabilityData); 66 void PackageRecorderCaps(); 67 void PackageVideoRecorderCaps(const std::string &formatType); 68 void PackageAudioRecorderCaps(const std::string &formatType); 69 void PaddingVideoCapsByAudioCaps(const std::string &formatType, RecorderProfilesData &videoData); 70 bool ParseAudioRecorderProfiles( 71 xmlNode *node, RecorderProfilesData &capabilityData, const std::string &capabilityKey); 72 bool ParseVideoRecorderProfiles( 73 xmlNode *node, RecorderProfilesData &capabilityData, const std::string &capabilityKey); 74 bool ParseVideoRecorderProfilesForVideoAudioData( 75 xmlNode *node, RecorderProfilesData &capabilityData, const std::string &capabilityKey); 76 77 std::vector<ContainerFormatInfo> containerFormatArray_; 78 std::vector<RecorderProfilesData> videoEncoderCapsArray_; 79 std::vector<RecorderProfilesData> audioEncoderCapsArray_; 80 std::vector<RecorderProfilesData> capabilityDataArray_; 81 std::vector<std::string> capabilityKeys_; 82 }; 83 } // namespace Media 84 } // namespace OHOS 85 #endif // RECORDERPROFILES_XML_PARSER_H