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