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 <vector>
22 
23 #include <media/stagefright/foundation/ABase.h>
24 #include <media/stagefright/foundation/AString.h>
25 #include <media/stagefright/MediaCodecListWriter.h>
26 #include <media/IMediaCodecList.h>
27 #include <media/MediaCodecInfo.h>
28 
29 #include <sys/types.h>
30 #include <utils/Errors.h>
31 #include <utils/KeyedVector.h>
32 #include <utils/Vector.h>
33 #include <utils/StrongPointer.h>
34 
35 namespace android {
36 
37 extern const char *kMaxEncoderInputBuffers;
38 
39 struct AMessage;
40 
41 struct MediaCodecList : public BnMediaCodecList {
42     static sp<IMediaCodecList> getInstance();
43 
44     virtual ssize_t findCodecByType(
45             const char *type, bool encoder, size_t startIndex = 0) const;
46 
47     virtual ssize_t findCodecByName(const char *name) const;
48 
49     virtual size_t countCodecs() const;
50 
getCodecInfoMediaCodecList51     virtual sp<MediaCodecInfo> getCodecInfo(size_t index) const {
52         if (index >= mCodecInfos.size()) {
53             ALOGE("b/24445127");
54             return NULL;
55         }
56         return mCodecInfos[index];
57     }
58 
59     virtual const sp<AMessage> getGlobalSettings() const;
60 
61     // to be used by MediaPlayerService alone
62     static sp<IMediaCodecList> getLocalInstance();
63 
64     // only to be used by getLocalInstance
65     static void *profilerThreadWrapper(void * /*arg*/);
66 
67     enum Flags {
68         kPreferSoftwareCodecs   = 1,
69         kHardwareCodecsOnly     = 2,
70     };
71 
72     static void findMatchingCodecs(
73             const char *mime,
74             bool createEncoder,
75             uint32_t flags,
76             Vector<AString> *matchingCodecs);
77 
78     static bool isSoftwareCodec(const AString &componentName);
79 
80 private:
81     class BinderDeathObserver : public IBinder::DeathRecipient {
82         void binderDied(const wp<IBinder> &the_late_who __unused);
83     };
84 
85     static sp<BinderDeathObserver> sBinderDeathObserver;
86     static sp<IBinder> sMediaPlayer;
87 
88     static sp<IMediaCodecList> sCodecList;
89     static sp<IMediaCodecList> sRemoteList;
90 
91     status_t mInitCheck;
92 
93     sp<AMessage> mGlobalSettings;
94     std::vector<sp<MediaCodecInfo> > mCodecInfos;
95 
96     /**
97      * This constructor will call `buildMediaCodecList()` from the given
98      * `MediaCodecListBuilderBase` objects.
99      */
100     MediaCodecList(std::vector<MediaCodecListBuilderBase*> builders);
101 
102     ~MediaCodecList();
103 
104     status_t initCheck() const;
105 
106     MediaCodecList(const MediaCodecList&) = delete;
107     MediaCodecList& operator=(const MediaCodecList&) = delete;
108 };
109 
110 }  // namespace android
111 
112 #endif  // MEDIA_CODEC_LIST_H_
113 
114