Home | History | Annotate | Download | only in stagefright
      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 
     51     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 
     87     static sp<IMediaCodecList> sCodecList;
     88     static sp<IMediaCodecList> sRemoteList;
     89 
     90     status_t mInitCheck;
     91 
     92     sp<AMessage> mGlobalSettings;
     93     std::vector<sp<MediaCodecInfo> > mCodecInfos;
     94 
     95     /**
     96      * This constructor will call `buildMediaCodecList()` from the given
     97      * `MediaCodecListBuilderBase` objects.
     98      */
     99     MediaCodecList(std::vector<MediaCodecListBuilderBase*> builders);
    100 
    101     ~MediaCodecList();
    102 
    103     status_t initCheck() const;
    104 
    105     MediaCodecList(const MediaCodecList&) = delete;
    106     MediaCodecList& operator=(const MediaCodecList&) = delete;
    107 };
    108 
    109 }  // namespace android
    110 
    111 #endif  // MEDIA_CODEC_LIST_H_
    112 
    113