MediaCodecList.h revision 60b1c0e79d12a1c70758bc8d060156924635f8ba
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#include <media/IMediaCodecList.h>
24#include <media/IOMX.h>
25#include <media/MediaCodecInfo.h>
26
27#include <sys/types.h>
28#include <utils/Errors.h>
29#include <utils/KeyedVector.h>
30#include <utils/Vector.h>
31#include <utils/StrongPointer.h>
32
33namespace android {
34
35struct AMessage;
36
37struct MediaCodecList : public BnMediaCodecList {
38    static sp<IMediaCodecList> getInstance();
39
40    virtual ssize_t findCodecByType(
41            const char *type, bool encoder, size_t startIndex = 0) const;
42
43    virtual ssize_t findCodecByName(const char *name) const;
44
45    virtual size_t countCodecs() const;
46
47    virtual sp<MediaCodecInfo> getCodecInfo(size_t index) const {
48        return mCodecInfos.itemAt(index);
49    }
50
51    // to be used by MediaPlayerService alone
52    static sp<IMediaCodecList> getLocalInstance();
53
54private:
55    enum Section {
56        SECTION_TOPLEVEL,
57        SECTION_DECODERS,
58        SECTION_DECODER,
59        SECTION_DECODER_TYPE,
60        SECTION_ENCODERS,
61        SECTION_ENCODER,
62        SECTION_ENCODER_TYPE,
63        SECTION_INCLUDE,
64    };
65
66    static sp<IMediaCodecList> sCodecList;
67    static sp<IMediaCodecList> sRemoteList;
68
69    status_t mInitCheck;
70    Section mCurrentSection;
71    Vector<Section> mPastSections;
72    int32_t mDepth;
73    AString mHrefBase;
74
75    Vector<sp<MediaCodecInfo> > mCodecInfos;
76    sp<MediaCodecInfo> mCurrentInfo;
77    sp<IOMX> mOMX;
78
79    MediaCodecList();
80    ~MediaCodecList();
81
82    status_t initCheck() const;
83    void parseXMLFile(const char *path);
84    void parseTopLevelXMLFile(const char *path);
85
86    static void StartElementHandlerWrapper(
87            void *me, const char *name, const char **attrs);
88
89    static void EndElementHandlerWrapper(void *me, const char *name);
90
91    void startElementHandler(const char *name, const char **attrs);
92    void endElementHandler(const char *name);
93
94    status_t includeXMLFile(const char **attrs);
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    status_t addLimit(const char **attrs);
101    status_t addFeature(const char **attrs);
102    void addType(const char *name);
103
104    status_t initializeCapabilities(const char *type);
105
106    DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
107};
108
109}  // namespace android
110
111#endif  // MEDIA_CODEC_LIST_H_
112
113