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    class BinderDeathObserver : public IBinder::DeathRecipient {
56        void binderDied(const wp<IBinder> &the_late_who __unused);
57    };
58
59    static sp<BinderDeathObserver> sBinderDeathObserver;
60
61    enum Section {
62        SECTION_TOPLEVEL,
63        SECTION_DECODERS,
64        SECTION_DECODER,
65        SECTION_DECODER_TYPE,
66        SECTION_ENCODERS,
67        SECTION_ENCODER,
68        SECTION_ENCODER_TYPE,
69        SECTION_INCLUDE,
70    };
71
72    static sp<IMediaCodecList> sCodecList;
73    static sp<IMediaCodecList> sRemoteList;
74
75    status_t mInitCheck;
76    Section mCurrentSection;
77    Vector<Section> mPastSections;
78    int32_t mDepth;
79    AString mHrefBase;
80
81    Vector<sp<MediaCodecInfo> > mCodecInfos;
82    sp<MediaCodecInfo> mCurrentInfo;
83    sp<IOMX> mOMX;
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    status_t addLimit(const char **attrs);
107    status_t addFeature(const char **attrs);
108    void addType(const char *name);
109
110    status_t initializeCapabilities(const char *type);
111
112    DISALLOW_EVIL_CONSTRUCTORS(MediaCodecList);
113};
114
115}  // namespace android
116
117#endif  // MEDIA_CODEC_LIST_H_
118
119