16ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa/* 26ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * Copyright 2017, The Android Open Source Project 36ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * 46ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * Licensed under the Apache License, Version 2.0 (the "License"); 56ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * you may not use this file except in compliance with the License. 66ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * You may obtain a copy of the License at 76ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * 86ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * http://www.apache.org/licenses/LICENSE-2.0 96ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * 106ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * Unless required by applicable law or agreed to in writing, software 116ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * distributed under the License is distributed on an "AS IS" BASIS, 126ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * See the License for the specific language governing permissions and 146ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa * limitations under the License. 156ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa */ 166ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 176ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#ifndef MEDIA_CODECS_XML_PARSER_H_ 186ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 196ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#define MEDIA_CODECS_XML_PARSER_H_ 206ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 216ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <map> 226ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <vector> 236ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 246ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <media/stagefright/foundation/ABase.h> 256ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <media/stagefright/foundation/AString.h> 266ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 276ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <sys/types.h> 286ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <utils/Errors.h> 296ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <utils/Vector.h> 306ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#include <utils/StrongPointer.h> 316ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 326ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasanamespace android { 336ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 346ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasastruct AMessage; 356ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 366ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa// Quirk still supported, even though deprecated 376ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasaenum Quirks { 386ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa kRequiresAllocateBufferOnInputPorts = 1, 396ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa kRequiresAllocateBufferOnOutputPorts = 2, 406ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 416ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa kQuirksMask = kRequiresAllocateBufferOnInputPorts 426ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa | kRequiresAllocateBufferOnOutputPorts, 436ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa}; 446ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 456ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa// Lightweight struct for querying components. 466ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasastruct TypeInfo { 476ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa AString mName; 486ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, AString> mStringFeatures; 496ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, bool> mBoolFeatures; 506ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, AString> mDetails; 516ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa}; 526ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 536ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasastruct ProfileLevel { 546ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa uint32_t mProfile; 556ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa uint32_t mLevel; 566ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa}; 576ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 586ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasastruct CodecInfo { 596ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::vector<TypeInfo> mTypes; 606ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::vector<ProfileLevel> mProfileLevels; 616ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::vector<uint32_t> mColorFormats; 626ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa uint32_t mFlags; 636ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa bool mIsEncoder; 646ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa}; 656ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 666ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasaclass MediaCodecsXmlParser { 676ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasapublic: 686ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa MediaCodecsXmlParser(); 696ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa ~MediaCodecsXmlParser(); 706ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 716ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void getGlobalSettings(std::map<AString, AString> *settings) const; 726ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 736ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t getCodecInfo(const char *name, CodecInfo *info) const; 746ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 756ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t getQuirks(const char *name, std::vector<AString> *quirks) const; 766ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 776ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasaprivate: 786ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa enum Section { 796ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_TOPLEVEL, 806ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_SETTINGS, 816ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_DECODERS, 826ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_DECODER, 836ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_DECODER_TYPE, 846ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_ENCODERS, 856ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_ENCODER, 866ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_ENCODER_TYPE, 876ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa SECTION_INCLUDE, 886ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa }; 896ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 906ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t mInitCheck; 916ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa Section mCurrentSection; 926ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa bool mUpdate; 936ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa Vector<Section> mPastSections; 946ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa int32_t mDepth; 956ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa AString mHrefBase; 966ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 976ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, AString> mGlobalSettings; 986ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 996ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa // name -> CodecInfo 1006ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, CodecInfo> mCodecInfos; 1016ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::map<AString, std::vector<AString>> mQuirks; 1026ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa AString mCurrentName; 1036ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa std::vector<TypeInfo>::iterator mCurrentType; 1046ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1056ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t initCheck() const; 1066ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void parseTopLevelXMLFile(const char *path, bool ignore_errors = false); 1076ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1086ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void parseXMLFile(const char *path); 1096ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1106ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa static void StartElementHandlerWrapper( 1116ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void *me, const char *name, const char **attrs); 1126ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1136ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa static void EndElementHandlerWrapper(void *me, const char *name); 1146ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1156ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void startElementHandler(const char *name, const char **attrs); 1166ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void endElementHandler(const char *name); 1176ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1186ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t includeXMLFile(const char **attrs); 1196ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addSettingFromAttributes(const char **attrs); 1206ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addMediaCodecFromAttributes(bool encoder, const char **attrs); 1216ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void addMediaCodec(bool encoder, const char *name, const char *type = NULL); 1226ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1236ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addQuirk(const char **attrs); 1246ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addTypeFromAttributes(const char **attrs, bool encoder); 1256ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addLimit(const char **attrs); 1266ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa status_t addFeature(const char **attrs); 1276ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa void addType(const char *name); 1286ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1296ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa DISALLOW_EVIL_CONSTRUCTORS(MediaCodecsXmlParser); 1306ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa}; 1316ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1326ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa} // namespace android 1336ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 1346ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa#endif // MEDIA_CODECS_XML_PARSER_H_ 1356ed07dc02d4240f94e7fb0786fb263bdc7a610baPawin Vongmasa 136