MediaCodecList.h revision a09152c6317e0295773b91f529e63c4d7c107752
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
35extern const char *kMaxEncoderInputBuffers;
36
37struct AMessage;
38
39struct MediaCodecList : public BnMediaCodecList {
40    static sp<IMediaCodecList> getInstance();
41
42    virtual ssize_t findCodecByType(
43            const char *type, bool encoder, size_t startIndex = 0) const;
44
45    virtual ssize_t findCodecByName(const char *name) const;
46
47    virtual size_t countCodecs() const;
48
49    virtual sp<MediaCodecInfo> getCodecInfo(size_t index) const {
50        return mCodecInfos.itemAt(index);
51    }
52
53    virtual const sp<AMessage> getGlobalSettings() const;
54
55    // to be used by MediaPlayerService alone
56    static sp<IMediaCodecList> getLocalInstance();
57
58    // only to be used by getLocalInstance
59    static void *profilerThreadWrapper(void * /*arg*/);
60
61    // only to be used by MediaPlayerService
62    void parseTopLevelXMLFile(const char *path, bool ignore_errors = false);
63
64private:
65    class BinderDeathObserver : public IBinder::DeathRecipient {
66        void binderDied(const wp<IBinder> &the_late_who __unused);
67    };
68
69    static sp<BinderDeathObserver> sBinderDeathObserver;
70
71    enum Section {
72        SECTION_TOPLEVEL,
73        SECTION_SETTINGS,
74        SECTION_DECODERS,
75        SECTION_DECODER,
76        SECTION_DECODER_TYPE,
77        SECTION_ENCODERS,
78        SECTION_ENCODER,
79        SECTION_ENCODER_TYPE,
80        SECTION_INCLUDE,
81    };
82
83    static sp<IMediaCodecList> sCodecList;
84    static sp<IMediaCodecList> sRemoteList;
85
86    status_t mInitCheck;
87    Section mCurrentSection;
88    bool mUpdate;
89    Vector<Section> mPastSections;
90    int32_t mDepth;
91    AString mHrefBase;
92
93    sp<AMessage> mGlobalSettings;
94    KeyedVector<AString, CodecSettings> mOverrides;
95
96    Vector<sp<MediaCodecInfo> > mCodecInfos;
97    sp<MediaCodecInfo> mCurrentInfo;
98    sp<IOMX> mOMX;
99
100    MediaCodecList();
101    ~MediaCodecList();
102
103    status_t initCheck() const;
104    void parseXMLFile(const char *path);
105
106    static void StartElementHandlerWrapper(
107            void *me, const char *name, const char **attrs);
108
109    static void EndElementHandlerWrapper(void *me, const char *name);
110
111    void startElementHandler(const char *name, const char **attrs);
112    void endElementHandler(const char *name);
113
114    status_t includeXMLFile(const char **attrs);
115    status_t addSettingFromAttributes(const char **attrs);
116    status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);
117    void addMediaCodec(bool encoder, const char *name, const char *type = NULL);
118
119    void setCurrentCodecInfo(bool encoder, const char *name, const char *type);
120
121    status_t addQuirk(const char **attrs);
122    status_t addTypeFromAttributes(const char **attrs);
123    status_t addLimit(const char **attrs);
124    status_t addFeature(const char **attrs);
125    void addType(const char *name);
126
127    status_t initializeCapabilities(const char *type);
128
129    DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
130};
131
132}  // namespace android
133
134#endif  // MEDIA_CODEC_LIST_H_
135
136