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) const;
     54 
     55 private:
     56     enum Section {
     57         SECTION_TOPLEVEL,
     58         SECTION_DECODERS,
     59         SECTION_DECODER,
     60         SECTION_ENCODERS,
     61         SECTION_ENCODER,
     62     };
     63 
     64     struct CodecInfo {
     65         AString mName;
     66         bool mIsEncoder;
     67         uint32_t mTypes;
     68         uint32_t mQuirks;
     69     };
     70 
     71     static MediaCodecList *sCodecList;
     72 
     73     status_t mInitCheck;
     74     Section mCurrentSection;
     75     int32_t mDepth;
     76 
     77     Vector<CodecInfo> mCodecInfos;
     78     KeyedVector<AString, size_t> mCodecQuirks;
     79     KeyedVector<AString, size_t> mTypes;
     80 
     81     MediaCodecList();
     82     ~MediaCodecList();
     83 
     84     status_t initCheck() const;
     85     void parseXMLFile(FILE *file);
     86 
     87     static void StartElementHandlerWrapper(
     88             void *me, const char *name, const char **attrs);
     89 
     90     static void EndElementHandlerWrapper(void *me, const char *name);
     91 
     92     void startElementHandler(const char *name, const char **attrs);
     93     void endElementHandler(const char *name);
     94 
     95     status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);
     96     void addMediaCodec(bool encoder, const char *name, const char *type = NULL);
     97 
     98     status_t addQuirk(const char **attrs);
     99     status_t addTypeFromAttributes(const char **attrs);
    100     void addType(const char *name);
    101 
    102     DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
    103 };
    104 
    105 }  // namespace android
    106 
    107 #endif  // MEDIA_CODEC_LIST_H_
    108 
    109