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

Commit e6712071 authored by Andreas Huber's avatar Andreas Huber
Browse files

Make sure codec names and corresponding quirks are returned together.

Previously they were returned in separate vectors and only one of them was sorted if
software codecs were preferred, leaving the quirks no longer matching the codec name
at the same index.

Change-Id: Id3f1e6f9f7f8c9cc4b6ebfb86a203b4d59de8604
related-to-bug: 6737884
parent 28620ee3
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -102,13 +102,17 @@ struct OMXCodec : public MediaSource,
        kOutputBuffersAreUnreadable           = 4096,
    };

    struct CodecNameAndQuirks {
        String8 mName;
        uint32_t mQuirks;
    };

    // for use by ACodec
    static void findMatchingCodecs(
            const char *mime,
            bool createEncoder, const char *matchComponentName,
            uint32_t flags,
            Vector<String8> *matchingCodecs,
            Vector<uint32_t> *matchingCodecQuirks = NULL);
            Vector<CodecNameAndQuirks> *matchingCodecNamesAndQuirks);

    static uint32_t getComponentQuirks(
            const MediaCodecList *list, size_t index);
+10 −10
Original line number Diff line number Diff line
@@ -2886,20 +2886,21 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    sp<IOMX> omx = client.interface();

    Vector<String8> matchingCodecs;
    Vector<uint32_t> matchingCodecQuirks;
    Vector<OMXCodec::CodecNameAndQuirks> matchingCodecs;

    AString mime;

    AString componentName;
    uint32_t quirks;
    if (msg->findString("componentName", &componentName)) {
        matchingCodecs.push_back(String8(componentName.c_str()));
        ssize_t index = matchingCodecs.add();
        OMXCodec::CodecNameAndQuirks *entry = &matchingCodecs.editItemAt(index);
        entry->mName = String8(componentName.c_str());

        if (!OMXCodec::findCodecQuirks(componentName.c_str(), &quirks)) {
            quirks = 0;
        if (!OMXCodec::findCodecQuirks(
                    componentName.c_str(), &entry->mQuirks)) {
            entry->mQuirks = 0;
        }
        matchingCodecQuirks.push_back(quirks);
    } else {
        CHECK(msg->findString("mime", &mime));

@@ -2913,8 +2914,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
                encoder, // createEncoder
                NULL,  // matchComponentName
                0,     // flags
                &matchingCodecs,
                &matchingCodecQuirks);
                &matchingCodecs);
    }

    sp<CodecObserver> observer = new CodecObserver;
@@ -2922,8 +2922,8 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {

    for (size_t matchIndex = 0; matchIndex < matchingCodecs.size();
            ++matchIndex) {
        componentName = matchingCodecs.itemAt(matchIndex).string();
        quirks = matchingCodecQuirks.itemAt(matchIndex);
        componentName = matchingCodecs.itemAt(matchIndex).mName.string();
        quirks = matchingCodecs.itemAt(matchIndex).mQuirks;

        pid_t tid = androidGetTid();
        int prevPriority = androidGetThreadPriority(tid);
+21 −23
Original line number Diff line number Diff line
@@ -147,12 +147,13 @@ static bool IsSoftwareCodec(const char *componentName) {
// A sort order in which OMX software codecs are first, followed
// by other (non-OMX) software codecs, followed by everything else.
static int CompareSoftwareCodecsFirst(
        const String8 *elem1, const String8 *elem2) {
    bool isOMX1 = !strncmp(elem1->string(), "OMX.", 4);
    bool isOMX2 = !strncmp(elem2->string(), "OMX.", 4);
        const OMXCodec::CodecNameAndQuirks *elem1,
        const OMXCodec::CodecNameAndQuirks *elem2) {
    bool isOMX1 = !strncmp(elem1->mName.string(), "OMX.", 4);
    bool isOMX2 = !strncmp(elem2->mName.string(), "OMX.", 4);

    bool isSoftwareCodec1 = IsSoftwareCodec(elem1->string());
    bool isSoftwareCodec2 = IsSoftwareCodec(elem2->string());
    bool isSoftwareCodec1 = IsSoftwareCodec(elem1->mName.string());
    bool isSoftwareCodec2 = IsSoftwareCodec(elem2->mName.string());

    if (isSoftwareCodec1) {
        if (!isSoftwareCodec2) { return -1; }
@@ -182,14 +183,9 @@ void OMXCodec::findMatchingCodecs(
        const char *mime,
        bool createEncoder, const char *matchComponentName,
        uint32_t flags,
        Vector<String8> *matchingCodecs,
        Vector<uint32_t> *matchingCodecQuirks) {
        Vector<CodecNameAndQuirks> *matchingCodecs) {
    matchingCodecs->clear();

    if (matchingCodecQuirks) {
        matchingCodecQuirks->clear();
    }

    const MediaCodecList *list = MediaCodecList::getInstance();
    if (list == NULL) {
        return;
@@ -221,11 +217,13 @@ void OMXCodec::findMatchingCodecs(
            ((flags & kHardwareCodecsOnly) &&  !IsSoftwareCodec(componentName)) ||
            (!(flags & (kSoftwareCodecsOnly | kHardwareCodecsOnly)))) {

            matchingCodecs->push(String8(componentName));
            ssize_t index = matchingCodecs->add();
            CodecNameAndQuirks *entry = &matchingCodecs->editItemAt(index);
            entry->mName = String8(componentName);
            entry->mQuirks = getComponentQuirks(list, matchIndex);

            if (matchingCodecQuirks) {
                matchingCodecQuirks->push(getComponentQuirks(list, matchIndex));
            }
            ALOGV("matching '%s' quirks 0x%08x",
                  entry->mName.string(), entry->mQuirks);
        }
    }

@@ -294,11 +292,9 @@ sp<MediaSource> OMXCodec::Create(
    bool success = meta->findCString(kKeyMIMEType, &mime);
    CHECK(success);

    Vector<String8> matchingCodecs;
    Vector<uint32_t> matchingCodecQuirks;
    Vector<CodecNameAndQuirks> matchingCodecs;
    findMatchingCodecs(
            mime, createEncoder, matchComponentName, flags,
            &matchingCodecs, &matchingCodecQuirks);
            mime, createEncoder, matchComponentName, flags, &matchingCodecs);

    if (matchingCodecs.isEmpty()) {
        ALOGV("No matching codecs! (mime: %s, createEncoder: %s, "
@@ -311,8 +307,8 @@ sp<MediaSource> OMXCodec::Create(
    IOMX::node_id node = 0;

    for (size_t i = 0; i < matchingCodecs.size(); ++i) {
        const char *componentNameBase = matchingCodecs[i].string();
        uint32_t quirks = matchingCodecQuirks[i];
        const char *componentNameBase = matchingCodecs[i].mName.string();
        uint32_t quirks = matchingCodecs[i].mQuirks;
        const char *componentName = componentNameBase;

        AString tmp;
@@ -572,6 +568,8 @@ status_t OMXCodec::configureCodec(const sp<MetaData> &meta) {

    if ((mFlags & kClientNeedsFramebuffer)
            && !strncmp(mComponentName, "OMX.SEC.", 8)) {
        // This appears to no longer be needed???

        OMX_INDEXTYPE index;

        status_t err =
@@ -4489,7 +4487,7 @@ status_t QueryCodecs(
        const sp<IOMX> &omx,
        const char *mime, bool queryDecoders, bool hwCodecOnly,
        Vector<CodecCapabilities> *results) {
    Vector<String8> matchingCodecs;
    Vector<OMXCodec::CodecNameAndQuirks> matchingCodecs;
    results->clear();

    OMXCodec::findMatchingCodecs(mime,
@@ -4499,7 +4497,7 @@ status_t QueryCodecs(
            &matchingCodecs);

    for (size_t c = 0; c < matchingCodecs.size(); c++) {
        const char *componentName = matchingCodecs.itemAt(c).string();
        const char *componentName = matchingCodecs.itemAt(c).mName.string();

        results->push();
        CodecCapabilities *caps = &results->editItemAt(results->size() - 1);