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

Commit 4a446bd0 authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Add a few more APIs to MediaCodecList."

parents 73d22755 69829f3b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -36,9 +36,22 @@ struct MediaCodecList {

    ssize_t findCodecByName(const char *name) const;

    size_t countCodecs() const;
    const char *getCodecName(size_t index) const;
    bool isEncoder(size_t index) const;
    bool codecHasQuirk(size_t index, const char *quirkName) const;

    status_t getSupportedTypes(size_t index, Vector<AString> *types) const;

    struct ProfileLevel {
        uint32_t mProfile;
        uint32_t mLevel;
    };
    status_t getCodecCapabilities(
            size_t index, const char *type,
            Vector<ProfileLevel> *profileLevels,
            Vector<uint32_t> *colorFormats) const;

private:
    enum Section {
        SECTION_TOPLEVEL,
+5 −0
Original line number Diff line number Diff line
@@ -384,6 +384,11 @@ status_t QueryCodecs(
        const char *mimeType, bool queryDecoders,
        Vector<CodecCapabilities> *results);

status_t QueryCodec(
        const sp<IOMX> &omx,
        const char *componentName, const char *mime,
        bool isEncoder,
        CodecCapabilities *caps);

}  // namespace android

+80 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@

#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
#include <utils/threads.h>

#include <expat.h>
@@ -448,6 +450,10 @@ ssize_t MediaCodecList::findCodecByName(const char *name) const {
    return -ENOENT;
}

size_t MediaCodecList::countCodecs() const {
    return mCodecInfos.size();
}

const char *MediaCodecList::getCodecName(size_t index) const {
    if (index >= mCodecInfos.size()) {
        return NULL;
@@ -457,6 +463,15 @@ const char *MediaCodecList::getCodecName(size_t index) const {
    return info.mName.c_str();
}

bool MediaCodecList::isEncoder(size_t index) const {
    if (index >= mCodecInfos.size()) {
        return NULL;
    }

    const CodecInfo &info = mCodecInfos.itemAt(index);
    return info.mIsEncoder;
}

bool MediaCodecList::codecHasQuirk(
        size_t index, const char *quirkName) const {
    if (index >= mCodecInfos.size()) {
@@ -475,4 +490,69 @@ bool MediaCodecList::codecHasQuirk(
    return false;
}

status_t MediaCodecList::getSupportedTypes(
        size_t index, Vector<AString> *types) const {
    types->clear();

    if (index >= mCodecInfos.size()) {
        return -ERANGE;
    }

    const CodecInfo &info = mCodecInfos.itemAt(index);

    for (size_t i = 0; i < mTypes.size(); ++i) {
        uint32_t typeMask = 1ul << mTypes.valueAt(i);

        if (info.mTypes & typeMask) {
            types->push(mTypes.keyAt(i));
        }
    }

    return OK;
}

status_t MediaCodecList::getCodecCapabilities(
        size_t index, const char *type,
        Vector<ProfileLevel> *profileLevels,
        Vector<uint32_t> *colorFormats) const {
    profileLevels->clear();
    colorFormats->clear();

    if (index >= mCodecInfos.size()) {
        return -ERANGE;
    }

    const CodecInfo &info = mCodecInfos.itemAt(index);

    OMXClient client;
    status_t err = client.connect();
    if (err != OK) {
        return err;
    }

    CodecCapabilities caps;
    err = QueryCodec(
            client.interface(),
            info.mName.c_str(), type, info.mIsEncoder, &caps);

    if (err != OK) {
        return err;
    }

    for (size_t i = 0; i < caps.mProfileLevels.size(); ++i) {
        const CodecProfileLevel &src = caps.mProfileLevels.itemAt(i);

        ProfileLevel profileLevel;
        profileLevel.mProfile = src.mProfile;
        profileLevel.mLevel = src.mLevel;
        profileLevels->push(profileLevel);
    }

    for (size_t i = 0; i < caps.mColorFormats.size(); ++i) {
        colorFormats->push(caps.mColorFormats.itemAt(i));
    }

    return OK;
}

}  // namespace android
+57 −43
Original line number Diff line number Diff line
@@ -4509,13 +4509,30 @@ status_t QueryCodecs(
    for (size_t c = 0; c < matchingCodecs.size(); c++) {
        const char *componentName = matchingCodecs.itemAt(c).string();

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

        status_t err =
            QueryCodec(omx, componentName, mime, !queryDecoders, caps);

        if (err != OK) {
            results->removeAt(results->size() - 1);
        }
    }

    return OK;
}

status_t QueryCodec(
        const sp<IOMX> &omx,
        const char *componentName, const char *mime,
        bool isEncoder,
        CodecCapabilities *caps) {
    if (strncmp(componentName, "OMX.", 4)) {
        // Not an OpenMax component but a software codec.

            results->push();
            CodecCapabilities *caps = &results->editItemAt(results->size() - 1);
        caps->mComponentName = componentName;
            continue;
        return OK;
    }

    sp<OMXCodecObserver> observer = new OMXCodecObserver;
@@ -4523,19 +4540,17 @@ status_t QueryCodecs(
    status_t err = omx->allocateNode(componentName, observer, &node);

    if (err != OK) {
            continue;
        return err;
    }

        OMXCodec::setComponentRole(omx, node, !queryDecoders, mime);
    OMXCodec::setComponentRole(omx, node, isEncoder, mime);

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

    OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
    InitOMXParams(&param);

        param.nPortIndex = queryDecoders ? 0 : 1;
    param.nPortIndex = !isEncoder ? 0 : 1;

    for (param.nProfileIndex = 0;; ++param.nProfileIndex) {
        err = omx->getParameter(
@@ -4556,7 +4571,7 @@ status_t QueryCodecs(
    // Color format query
    OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
    InitOMXParams(&portFormat);
        portFormat.nPortIndex = queryDecoders ? 1 : 0;
    portFormat.nPortIndex = !isEncoder ? 1 : 0;
    for (portFormat.nIndex = 0;; ++portFormat.nIndex)  {
        err = omx->getParameter(
                node, OMX_IndexParamVideoPortFormat,
@@ -4568,7 +4583,6 @@ status_t QueryCodecs(
    }

    CHECK_EQ(omx->freeNode(node), (status_t)OK);
    }

    return OK;
}