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

Commit 146757db authored by Mingming Yin's avatar Mingming Yin Committed by Linux Build Service Account
Browse files

libstagefright: Add support for HW AAC decoder

- Add support for HW AAC decoder by including it in the
  list of available decoders and use it for decoding only
  if property 'media.aaccodectype' is set

Change-Id: I36c9ad178f6c9fd164e617af0fdec01d3e9656f2
parent 636d2fe9
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -152,8 +152,6 @@ struct ExtendedCodec {
            const sp<IOMX> &omx, IOMX::node_id nodeID, bool* isEnabled,
            const char* componentName);

    static bool useHWAACDecoder(const char *mime);

    static bool isSourcePauseRequired(const char *componentName);

private:
+13 −3
Original line number Diff line number Diff line
@@ -4654,7 +4654,7 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
    // MediaCodecSource does not pass the output format details when calling
    // kInit leading to msg passed not having enough details
    if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)
        && ExtendedUtils::UseQCHWAACEncoder()) {
        && ExtendedUtils::UseQCHWAACEncoder() && encoder) {
        //use hw aac encoder
        ALOGD("use QCOM HW AAC encoder");
        OMXCodec::findMatchingCodecs(
@@ -4663,14 +4663,24 @@ bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
                "OMX.qcom.audio.encoder.aac",  // OMX.qcom.audio.encoder.aac
                0,     // flags
                &matchingCodecs);
    }
    else
    } else if (!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)
        && ExtendedUtils::UseQCHWAACDecoder(mime.c_str()) && !encoder) {
        //use hw aac decoder
        ALOGD("use QCOM HW AAC decoder");
        OMXCodec::findMatchingCodecs(
                mime.c_str(),
                encoder, // createEncoder
                "OMX.qcom.audio.decoder.multiaac",  // OMX.qcom.audio.decoder.multiaac
                0,     // flags
                &matchingCodecs);
    } else {
        OMXCodec::findMatchingCodecs(
                mime.c_str(),
                encoder, // createEncoder
                NULL,  // matchComponentName
                0,     // flags
                &matchingCodecs);
    }
#else
    OMXCodec::findMatchingCodecs(
                mime.c_str(),
+0 −17
Original line number Diff line number Diff line
@@ -1157,18 +1157,6 @@ status_t ExtendedCodec::setAMRWBPLUSFormat(
    return err;
}

bool ExtendedCodec::useHWAACDecoder(const char *mime) {
    char value[PROPERTY_VALUE_MAX] = {0};
    int aaccodectype = 0;
    aaccodectype = property_get("media.aaccodectype", value, NULL);
    if (aaccodectype && !strncmp("0", value, 1) &&
        !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC)) {
        ALOGI("Using Hardware AAC Decoder");
        return true;
    }
    return false;
}

bool ExtendedCodec::isSourcePauseRequired(const char *componentName) {
    /* pause is required for hardware component to release adsp resources */
    if (!strncmp(componentName, "OMX.qcom.", 9)) {
@@ -1452,11 +1440,6 @@ namespace android {
        ARG_TOUCH(componentName);
    }

    bool ExtendedCodec::useHWAACDecoder(const char *mime) {
        ARG_TOUCH(mime);
        return false;
    }

    void ExtendedCodec::enableSmoothStreaming(
            const sp<IOMX> &omx, IOMX::node_id nodeID, bool* isEnabled,
            const char* componentName) {
+15 −0
Original line number Diff line number Diff line
@@ -940,6 +940,16 @@ bool ExtendedUtils::UseQCHWAACEncoder(audio_encoder Encoder,int32_t Channel,int3
    return mIsQCHWAACEncoder;
}

bool ExtendedUtils::UseQCHWAACDecoder(const char *mime) {
    if (!strncmp(mime, MEDIA_MIMETYPE_AUDIO_AAC, strlen(MEDIA_MIMETYPE_AUDIO_AAC))) {
        char value[PROPERTY_VALUE_MAX] = {0};
        if (property_get("media.aaccodectype", value, 0) && (atoi(value) == 1)) {
            return true;
        }
    }
    return false;
}


//- returns NULL if we dont really need a new extractor (or cannot),
//  valid extractor is returned otherwise
@@ -1716,6 +1726,11 @@ bool ExtendedUtils::UseQCHWAACEncoder(audio_encoder Encoder,int32_t Channel,
    return false;
}

bool ExtendedUtils::UseQCHWAACDecoder(const char *mime) {
    ARG_TOUCH(mime);
    return false;
}

sp<MediaExtractor> ExtendedUtils::MediaExtractor_CreateIfNeeded(
        sp<MediaExtractor> defaultExt,
        const sp<DataSource> &source,
+31 −2
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ void OMXCodec::findMatchingCodecs(
    size_t index = 0;

#ifdef ENABLE_AV_ENHANCEMENTS
    //Check if application specially reuqested for  aac hardware encoder
    //Check if application specially reuqested for aac hardware encoder/decoder
    //This is not a part of  mediacodec list
    if (matchComponentName &&
            !strncmp("OMX.qcom.audio.encoder.aac", matchComponentName, 26)) {
@@ -260,6 +260,17 @@ void OMXCodec::findMatchingCodecs(
        entry->mQuirks = 0;
        return;
    }

    if (matchComponentName &&
            !strncmp("OMX.qcom.audio.decoder.multiaac", matchComponentName, 31)) {
        matchingCodecs->add();

        CodecNameAndQuirks *entry = &matchingCodecs->editItemAt(index);
        entry->mName = String8("OMX.qcom.audio.decoder.multiaac");
        entry->mQuirks |= kRequiresAllocateBufferOnInputPorts;
        entry->mQuirks |= kRequiresAllocateBufferOnOutputPorts;
        return;
    }
#endif

    for (;;) {
@@ -354,6 +365,17 @@ bool OMXCodec::findCodecQuirks(const char *componentName, uint32_t *quirks) {
        return false;
    }

#ifdef ENABLE_AV_ENHANCEMENTS
    //Check for aac hardware decoder
    //This is not a part of  mediacodec list
    if (componentName &&
            !strncmp("OMX.qcom.audio.decoder.multiaac", componentName, 31)) {
        *quirks |= kRequiresAllocateBufferOnInputPorts;
        *quirks |= kRequiresAllocateBufferOnOutputPorts;
        return true;
    }
#endif

    const sp<MediaCodecInfo> info = list->getCodecInfo(index);
    CHECK(info != NULL);
    *quirks = getComponentQuirks(info);
@@ -383,8 +405,15 @@ sp<MediaSource> OMXCodec::Create(
    CHECK(success);

    Vector<CodecNameAndQuirks> matchingCodecs;

    if (!strncmp(mime, MEDIA_MIMETYPE_AUDIO_AAC, 15) &&
            ExtendedUtils::UseQCHWAACDecoder(mime)) {
        findMatchingCodecs(mime, createEncoder,
            "OMX.qcom.audio.decoder.multiaac", flags, &matchingCodecs);
    } else {
        findMatchingCodecs(
            mime, createEncoder, matchComponentName, flags, &matchingCodecs);
    }

    if (matchingCodecs.isEmpty()) {
        ALOGV("No matching codecs! (mime: %s, createEncoder: %s, "
Loading