Home | History | Annotate | Download | only in stagefright
      1 /*
      2  * Copyright 2012, 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_CODEC_LIST_H_
     18 
     19 #define MEDIA_CODEC_LIST_H_
     20 
     21 #include <media/stagefright/foundation/ABase.h>
     22 #include <media/stagefright/foundation/AString.h>
     23 
     24 #include <sys/types.h>
     25 #include <utils/Errors.h>
     26 #include <utils/KeyedVector.h>
     27 #include <utils/Vector.h>
     28 
     29 namespace android {
     30 
     31 struct MediaCodecList {
     32     static const MediaCodecList *getInstance();
     33 
     34     ssize_t findCodecByType(
     35             const char *type, bool encoder, size_t startIndex = 0) const;
     36 
     37     ssize_t findCodecByName(const char *name) const;
     38 
     39     size_t countCodecs() const;
     40     const char *getCodecName(size_t index) const;
     41     bool isEncoder(size_t index) const;
     42     bool codecHasQuirk(size_t index, const char *quirkName) const;
     43 
     44     status_t getSupportedTypes(size_t index, Vector<AString> *types) const;
     45 
     46     struct ProfileLevel {
     47         uint32_t mProfile;
     48         uint32_t mLevel;
     49     };
     50     status_t getCodecCapabilities(
     51             size_t index, const char *type,
     52             Vector<ProfileLevel> *profileLevels,
     53             Vector<uint32_t> *colorFormats,
     54             uint32_t *flags) const;
     55 
     56 private:
     57     enum Section {
     58         SECTION_TOPLEVEL,
     59         SECTION_DECODERS,
     60         SECTION_DECODER,
     61         SECTION_ENCODERS,
     62         SECTION_ENCODER,
     63     };
     64 
     65     struct CodecInfo {
     66         AString mName;
     67         bool mIsEncoder;
     68         uint32_t mTypes;
     69         uint32_t mQuirks;
     70     };
     71 
     72     static MediaCodecList *sCodecList;
     73 
     74     status_t mInitCheck;
     75     Section mCurrentSection;
     76     int32_t mDepth;
     77 
     78     Vector<CodecInfo> mCodecInfos;
     79     KeyedVector<AString, size_t> mCodecQuirks;
     80     KeyedVector<AString, size_t> mTypes;
     81 
     82     MediaCodecList();
     83     ~MediaCodecList();
     84 
     85     status_t initCheck() const;
     86     void parseXMLFile(FILE *file);
     87 
     88     static void StartElementHandlerWrapper(
     89             void *me, const char *name, const char **attrs);
     90 
     91     static void EndElementHandlerWrapper(void *me, const char *name);
     92 
     93     void startElementHandler(const char *name, const char **attrs);
     94     void endElementHandler(const char *name);
     95 
     96     status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);
     97     void addMediaCodec(bool encoder, const char *name, const char *type = NULL);
     98 
     99     status_t addQuirk(const char **attrs);
    100     status_t addTypeFromAttributes(const char **attrs);
    101     void addType(const char *name);
    102 
    103     DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
    104 };
    105 
    106 }  // namespace android
    107 
    108 #endif  // MEDIA_CODEC_LIST_H_
    109 
    110