Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b60521e2 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: create findCodec methods in MediaCodecList

This is to delete them from OMXCodec later.
Use ACodec-specific quirks.

Bug: 17108024
Change-Id: I670b104cff5ef37f155a9843f68d291aa943d1c1
parent a485208f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -93,6 +93,12 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
            int width, int height, int rate, int bitrate,
            OMX_VIDEO_AVCPROFILETYPE profile = OMX_VIDEO_AVCProfileBaseline);

    // Quirk still supported, even though deprecated
    enum Quirks {
        kRequiresAllocateBufferOnInputPorts   = 1,
        kRequiresAllocateBufferOnOutputPorts  = 2,
    };

    static status_t getOMXChannelMapping(size_t numChannels, OMX_AUDIO_CHANNELTYPE map[]);

protected:
+16 −0
Original line number Diff line number Diff line
@@ -65,6 +65,22 @@ struct MediaCodecList : public BnMediaCodecList {
    // only to be used by MediaPlayerService
    void parseTopLevelXMLFile(const char *path, bool ignore_errors = false);

    enum Flags {
        kPreferSoftwareCodecs   = 1,
        kHardwareCodecsOnly     = 2,
    };

    static void findMatchingCodecs(
            const char *mime,
            bool createEncoder,
            uint32_t flags,
            Vector<AString> *matching);

    static uint32_t getQuirksFor(const char *mComponentName);

    static bool isSoftwareCodec(const AString &componentName);


private:
    class BinderDeathObserver : public IBinder::DeathRecipient {
        void binderDied(const wp<IBinder> &the_late_who __unused);
+0 −2
Original line number Diff line number Diff line
@@ -117,8 +117,6 @@ struct OMXCodec : public BnMediaSource,
    static uint32_t getComponentQuirks(
            const sp<MediaCodecInfo> &list);

    static bool findCodecQuirks(const char *componentName, uint32_t *quirks);

protected:
    virtual ~OMXCodec();

+10 −16
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
#include <media/stagefright/PersistentSurface.h>
#include <media/stagefright/SurfaceUtils.h>
#include <media/hardware/HardwareAPI.h>
@@ -828,8 +827,8 @@ status_t ACodec::allocateBuffersOnPort(OMX_U32 portIndex) {

                uint32_t requiresAllocateBufferBit =
                    (portIndex == kPortIndexInput)
                        ? OMXCodec::kRequiresAllocateBufferOnInputPorts
                        : OMXCodec::kRequiresAllocateBufferOnOutputPorts;
                        ? kRequiresAllocateBufferOnInputPorts
                        : kRequiresAllocateBufferOnOutputPorts;

                if ((portIndex == kPortIndexInput && (mFlags & kFlagIsSecure))
                        || (portIndex == kPortIndexOutput && usingMetadataOnEncoderOutput())) {
@@ -5480,7 +5479,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
        mDeathNotifier.clear();
    }

    Vector<OMXCodec::CodecNameAndQuirks> matchingCodecs;
    Vector<AString> matchingCodecs;

    AString mime;

@@ -5488,13 +5487,9 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
    uint32_t quirks = 0;
    int32_t encoder = false;
    if (msg->findString("componentName", &componentName)) {
        ssize_t index = matchingCodecs.add();
        OMXCodec::CodecNameAndQuirks *entry = &matchingCodecs.editItemAt(index);
        entry->mName = String8(componentName.c_str());

        if (!OMXCodec::findCodecQuirks(
                    componentName.c_str(), &entry->mQuirks)) {
            entry->mQuirks = 0;
        sp<IMediaCodecList> list = MediaCodecList::getInstance();
        if (list != NULL && list->findCodecByName(componentName.c_str()) >= 0) {
            matchingCodecs.add(componentName);
        }
    } else {
        CHECK(msg->findString("mime", &mime));
@@ -5503,10 +5498,9 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
            encoder = false;
        }

        OMXCodec::findMatchingCodecs(
        MediaCodecList::findMatchingCodecs(
                mime.c_str(),
                encoder, // createEncoder
                NULL,  // matchComponentName
                0,       // flags
                &matchingCodecs);
    }
@@ -5517,8 +5511,8 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
    status_t err = NAME_NOT_FOUND;
    for (size_t matchIndex = 0; matchIndex < matchingCodecs.size();
            ++matchIndex) {
        componentName = matchingCodecs.itemAt(matchIndex).mName.string();
        quirks = matchingCodecs.itemAt(matchIndex).mQuirks;
        componentName = matchingCodecs[matchIndex];
        quirks = MediaCodecList::getQuirksFor(componentName.c_str());

        pid_t tid = gettid();
        int prevPriority = androidGetThreadPriority(tid);
+82 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@

#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/ACodec.h>
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/OMXClient.h>
@@ -1115,4 +1116,85 @@ const sp<AMessage> MediaCodecList::getGlobalSettings() const {
    return mGlobalSettings;
}

//static
bool MediaCodecList::isSoftwareCodec(const AString &componentName) {
    return componentName.startsWithIgnoreCase("OMX.google.")
        || !componentName.startsWithIgnoreCase("OMX.");
}

static int compareSoftwareCodecsFirst(const AString *name1, const AString *name2) {
    // sort order 1: software codecs are first (lower)
    bool isSoftwareCodec1 = MediaCodecList::isSoftwareCodec(*name1);
    bool isSoftwareCodec2 = MediaCodecList::isSoftwareCodec(*name2);
    if (isSoftwareCodec1 != isSoftwareCodec2) {
        return isSoftwareCodec2 - isSoftwareCodec1;
    }

    // sort order 2: OMX codecs are first (lower)
    bool isOMX1 = name1->startsWithIgnoreCase("OMX.");
    bool isOMX2 = name2->startsWithIgnoreCase("OMX.");
    return isOMX2 - isOMX1;
}

//static
void MediaCodecList::findMatchingCodecs(
        const char *mime, bool encoder, uint32_t flags, Vector<AString> *matches) {
    matches->clear();

    const sp<IMediaCodecList> list = getInstance();
    if (list == NULL) {
        return;
    }

    size_t index = 0;
    for (;;) {
        ssize_t matchIndex =
            list->findCodecByType(mime, encoder, index);

        if (matchIndex < 0) {
            break;
        }

        index = matchIndex + 1;

        const sp<MediaCodecInfo> info = list->getCodecInfo(matchIndex);
        CHECK(info != NULL);
        AString componentName = info->getCodecName();

        if (!((flags & kHardwareCodecsOnly) && !isSoftwareCodec(componentName))) {
            matches->push(componentName);
            ALOGV("matching '%s'", componentName.c_str());
        }
    }

    if (flags & kPreferSoftwareCodecs) {
        matches->sort(compareSoftwareCodecsFirst);
    }
}

// static
uint32_t MediaCodecList::getQuirksFor(const char *componentName) {
    const sp<IMediaCodecList> list = getInstance();
    if (list == NULL) {
        return 0;
    }

    ssize_t ix = list->findCodecByName(componentName);
    if (ix < 0) {
        return 0;
    }

    const sp<MediaCodecInfo> info = list->getCodecInfo(ix);

    uint32_t quirks = 0;
    if (info->hasQuirk("requires-allocate-on-input-ports")) {
        quirks |= ACodec::kRequiresAllocateBufferOnInputPorts;
    }
    if (info->hasQuirk("requires-allocate-on-output-ports")) {
        quirks |= ACodec::kRequiresAllocateBufferOnOutputPorts;
    }

    return quirks;
}

}  // namespace android
Loading