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 // add optional format, to further refine matching codecs 79 static void findMatchingCodecs( 80 const char *mime, 81 bool createEncoder, 82 uint32_t flags, 83 const sp<AMessage> &format, 84 Vector<AString> *matchingCodecs); 85 86 static bool isSoftwareCodec(const AString &componentName); 87 88 private: 89 class BinderDeathObserver : public IBinder::DeathRecipient { 90 void binderDied(const wp<IBinder> &the_late_who __unused); 91 }; 92 93 static sp<BinderDeathObserver> sBinderDeathObserver; 94 static sp<IBinder> sMediaPlayer; 95 96 static sp<IMediaCodecList> sCodecList; 97 static sp<IMediaCodecList> sRemoteList; 98 99 status_t mInitCheck{NO_INIT}; 100 101 sp<AMessage> mGlobalSettings; 102 std::vector<sp<MediaCodecInfo> > mCodecInfos; 103 104 /** 105 * This constructor will call `buildMediaCodecList()` from the given 106 * `MediaCodecListBuilderBase` objects. 107 */ 108 MediaCodecList(std::vector<MediaCodecListBuilderBase*> builders); 109 110 ~MediaCodecList(); 111 112 status_t initCheck() const; 113 114 MediaCodecList(const MediaCodecList&) = delete; 115 MediaCodecList& operator=(const MediaCodecList&) = delete; 116 117 static bool codecHandlesFormat( 118 const char *mime, 119 const sp<MediaCodecInfo> &info, 120 const sp<AMessage> &format); 121 }; 122 123 } // namespace android 124 125 #endif // MEDIA_CODEC_LIST_H_ 126 127