1 /* 2 * Copyright 2017, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MEDIA_CODECS_XML_PARSER_H_ 18 19 #define MEDIA_CODECS_XML_PARSER_H_ 20 21 #include <map> 22 #include <vector> 23 24 #include <media/stagefright/foundation/ABase.h> 25 #include <media/stagefright/foundation/AString.h> 26 27 #include <sys/types.h> 28 #include <utils/Errors.h> 29 #include <utils/Vector.h> 30 #include <utils/StrongPointer.h> 31 32 namespace android { 33 34 struct AMessage; 35 36 // Quirk still supported, even though deprecated 37 enum Quirks { 38 kRequiresAllocateBufferOnInputPorts = 1, 39 kRequiresAllocateBufferOnOutputPorts = 2, 40 41 kQuirksMask = kRequiresAllocateBufferOnInputPorts 42 | kRequiresAllocateBufferOnOutputPorts, 43 }; 44 45 // Lightweight struct for querying components. 46 struct TypeInfo { 47 AString mName; 48 std::map<AString, AString> mStringFeatures; 49 std::map<AString, bool> mBoolFeatures; 50 std::map<AString, AString> mDetails; 51 }; 52 53 struct ProfileLevel { 54 uint32_t mProfile; 55 uint32_t mLevel; 56 }; 57 58 struct CodecInfo { 59 std::vector<TypeInfo> mTypes; 60 std::vector<ProfileLevel> mProfileLevels; 61 std::vector<uint32_t> mColorFormats; 62 uint32_t mFlags; 63 bool mIsEncoder; 64 }; 65 66 class MediaCodecsXmlParser { 67 public: 68 MediaCodecsXmlParser(); 69 ~MediaCodecsXmlParser(); 70 71 void getGlobalSettings(std::map<AString, AString> *settings) const; 72 73 status_t getCodecInfo(const char *name, CodecInfo *info) const; 74 75 status_t getQuirks(const char *name, std::vector<AString> *quirks) const; 76 77 private: 78 enum Section { 79 SECTION_TOPLEVEL, 80 SECTION_SETTINGS, 81 SECTION_DECODERS, 82 SECTION_DECODER, 83 SECTION_DECODER_TYPE, 84 SECTION_ENCODERS, 85 SECTION_ENCODER, 86 SECTION_ENCODER_TYPE, 87 SECTION_INCLUDE, 88 }; 89 90 status_t mInitCheck; 91 Section mCurrentSection; 92 bool mUpdate; 93 Vector<Section> mPastSections; 94 int32_t mDepth; 95 AString mHrefBase; 96 97 std::map<AString, AString> mGlobalSettings; 98 99 // name -> CodecInfo 100 std::map<AString, CodecInfo> mCodecInfos; 101 std::map<AString, std::vector<AString>> mQuirks; 102 AString mCurrentName; 103 std::vector<TypeInfo>::iterator mCurrentType; 104 105 status_t initCheck() const; 106 void parseTopLevelXMLFile(const char *path, bool ignore_errors = false); 107 108 void parseXMLFile(const char *path); 109 110 static void StartElementHandlerWrapper( 111 void *me, const char *name, const char **attrs); 112 113 static void EndElementHandlerWrapper(void *me, const char *name); 114 115 void startElementHandler(const char *name, const char **attrs); 116 void endElementHandler(const char *name); 117 118 status_t includeXMLFile(const char **attrs); 119 status_t addSettingFromAttributes(const char **attrs); 120 status_t addMediaCodecFromAttributes(bool encoder, const char **attrs); 121 void addMediaCodec(bool encoder, const char *name, const char *type = NULL); 122 123 status_t addQuirk(const char **attrs); 124 status_t addTypeFromAttributes(const char **attrs, bool encoder); 125 status_t addLimit(const char **attrs); 126 status_t addFeature(const char **attrs); 127 void addType(const char *name); 128 129 DISALLOW_EVIL_CONSTRUCTORS(MediaCodecsXmlParser); 130 }; 131 132 } // namespace android 133 134 #endif // MEDIA_CODECS_XML_PARSER_H_ 135 136