Home | History | Annotate | Download | only in xmlparser
      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_STAGEFRIGHT_XMLPARSER_H_
     18 #define MEDIA_STAGEFRIGHT_XMLPARSER_H_
     19 
     20 #include <sys/types.h>
     21 #include <utils/Errors.h>
     22 
     23 #include <map>
     24 #include <mutex>
     25 #include <set>
     26 #include <string>
     27 #include <vector>
     28 
     29 struct XML_ParserStruct; // from expat library
     30 
     31 namespace android {
     32 
     33 class MediaCodecsXmlParser {
     34 public:
     35 
     36     // Treblized media codec list will be located in /odm/etc or /vendor/etc.
     37     static std::vector<std::string> getDefaultSearchDirs() {
     38             return { "/odm/etc", "/vendor/etc", "/etc" };
     39     }
     40     static std::vector<std::string> getDefaultXmlNames() {
     41             return { "media_codecs.xml", "media_codecs_performance.xml" };
     42     }
     43     static constexpr char const* defaultProfilingResultsXmlPath =
     44             "/data/misc/media/media_codecs_profiling_results.xml";
     45 
     46     MediaCodecsXmlParser();
     47     ~MediaCodecsXmlParser();
     48 
     49     typedef std::pair<std::string, std::string> Attribute;
     50     typedef std::map<std::string, std::string> AttributeMap;
     51 
     52     typedef std::pair<std::string, AttributeMap> Type;
     53     typedef std::map<std::string, AttributeMap> TypeMap;
     54 
     55     typedef std::set<std::string> StringSet;
     56 
     57     /**
     58      * Properties of a codec (node)
     59      */
     60     struct CodecProperties {
     61         bool isEncoder;    ///< Whether this codec is an encoder or a decoder
     62         size_t order;      ///< Order of appearance in the file (starting from 0)
     63         StringSet quirkSet; ///< Set of quirks requested by this codec
     64         StringSet domainSet; ///< Set of domains this codec is in
     65         StringSet variantSet; ///< Set of variants this codec is enabled on
     66         TypeMap typeMap;   ///< Map of types supported by this codec
     67         std::vector<std::string> aliases; ///< Name aliases for this codec
     68         std::string rank;  ///< Rank of this codec. This is a numeric string.
     69     };
     70 
     71     typedef std::pair<std::string, CodecProperties> Codec;
     72     typedef std::map<std::string, CodecProperties> CodecMap;
     73 
     74     /**
     75      * Properties of a node (for IOmxStore)
     76      */
     77     struct NodeInfo {
     78         std::string name;
     79         std::vector<Attribute> attributeList;
     80         // note: aliases are not exposed here as they are not part of the role map
     81     };
     82 
     83     /**
     84      * Properties of a role (for IOmxStore)
     85      */
     86     struct RoleProperties {
     87         std::string type;
     88         bool isEncoder;
     89         std::multimap<size_t, NodeInfo> nodeList;
     90     };
     91 
     92     typedef std::pair<std::string, RoleProperties> Role;
     93     typedef std::map<std::string, RoleProperties> RoleMap;
     94 
     95     /**
     96      * Return a map for attributes that are service-specific.
     97      */
     98     const AttributeMap& getServiceAttributeMap() const;
     99 
    100     /**
    101      * Return a map for codecs and their properties.
    102      */
    103     const CodecMap& getCodecMap() const;
    104 
    105     /**
    106      * Return a map for roles and their properties.
    107      * This map is generated from the CodecMap.
    108      */
    109     const RoleMap& getRoleMap() const;
    110 
    111     /**
    112      * Return a common prefix of all node names.
    113      *
    114      * The prefix is not provided in the xml, so it has to be computed by taking
    115      * the longest common prefix of all node names.
    116      */
    117     const char* getCommonPrefix() const;
    118 
    119     status_t getParsingStatus() const;
    120 
    121     /**
    122      * Parse top level XML files from a group of search directories.
    123      *
    124      * @param xmlFiles ordered list of XML file names (no paths)
    125      * @param searchDirs ordered list of paths to consider
    126      *
    127      * @return parsing status
    128      */
    129     status_t parseXmlFilesInSearchDirs(
    130             const std::vector<std::string> &xmlFiles = getDefaultXmlNames(),
    131             const std::vector<std::string> &searchDirs = getDefaultSearchDirs());
    132 
    133 
    134     /**
    135      * Parse a top level XML file.
    136      *
    137      * @param path XML file path
    138      *
    139      * @return parsing status
    140      */
    141     status_t parseXmlPath(const std::string &path);
    142 
    143 private:
    144     struct Impl;
    145     std::shared_ptr<Impl> mImpl;
    146 
    147     MediaCodecsXmlParser(const MediaCodecsXmlParser&) = delete;
    148     MediaCodecsXmlParser& operator=(const MediaCodecsXmlParser&) = delete;
    149 };
    150 
    151 } // namespace android
    152 
    153 #endif // MEDIA_STAGEFRIGHT_XMLPARSER_H_
    154