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