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

Commit 1d038e6a authored by Steve Kondik's avatar Steve Kondik
Browse files

stagefright: Cleanup and improve format parsing

 * Move FFMPEG-specific exceptions to FFMPEGSoftCodec
 * Add handling for AAC MAIN profile
 * Use the new OMX_AUDIO_CodingAndroidAC3 to handle AC3

Change-Id: Ibb806cd2b9dd23dc1e1b2c862fcde40605023a49
parent cd3b1333
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -41,6 +41,15 @@ struct FFMPEGSoftCodec {
    static status_t convertMetaDataToMessage(
            const sp<MetaData> &meta, sp<AMessage> *format);

    static const char* overrideComponentName(
            uint32_t quirks, const sp<MetaData> &meta,
            const char *mime, bool isEncoder);

    static void overrideComponentName(
            uint32_t quirks, const sp<AMessage> &msg,
            AString* componentName, AString* mime,
            int32_t isEncoder);

    static status_t setSupportedRole(
            const sp<IOMX> &omx, IOMX::node_id node,
            bool isEncoder, const char *mime);
+1 −2
Original line number Diff line number Diff line
@@ -1586,8 +1586,7 @@ status_t ACodec::configureCodec(
        } else {
            err = setupRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
        }
    } else if (!strncmp(mComponentName.c_str(), "OMX.google.", 11) &&
            !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AC3)) {
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AC3)) {
        int32_t numChannels;
        int32_t sampleRate;
        if (!msg->findInt32("channel-count", &numChannels)
+12 −21
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@
#include <media/stagefright/ExtendedCodec.h>
#include <media/stagefright/OMXCodec.h>

#include <media/stagefright/FFMPEGSoftCodec.h>

#define ARG_TOUCH(x) (void)x

#ifdef ENABLE_AV_ENHANCEMENTS
@@ -89,6 +91,7 @@ static const MetaKeyEntry MetaKeyTable[] {

   {kkeyAacFormatAdif        , "aac-format-adif"        , INT32},  // bool (int32_t)
   {kkeyAacFormatLtp         , "aac-format-ltp"         , INT32},
   {kKeyAACAOT               , "aac-profile"            , INT32},

   //DTS subtype
   {kKeyDTSSubtype           , "dts-subtype"            , INT32},  //int32_t
@@ -195,11 +198,12 @@ uint32_t ExtendedCodec::getComponentQuirks(

const char* ExtendedCodec::overrideComponentName(
        uint32_t quirks, const sp<MetaData> &meta, const char *mime, bool isEncoder) {
    const char* componentName = NULL;
    char value[PROPERTY_VALUE_MAX] = {0};
    int sw_codectype = 0;
    int enableSwHevc = 0;

    const char* componentName = FFMPEGSoftCodec::overrideComponentName(quirks, meta, mime, isEncoder);

    if (quirks & kRequiresWMAProComponent)
    {
       int32_t version = 0;
@@ -221,6 +225,8 @@ const char* ExtendedCodec::overrideComponentName(
           componentName = "OMX.qcom.video.decoder.hevcswvdec";
        }
    }

    
    return componentName;
}

@@ -230,6 +236,8 @@ void ExtendedCodec::overrideComponentName(
    int sw_codectype = 0;
    int enableSwHevc = 0;

    FFMPEGSoftCodec::overrideComponentName(quirks, msg, componentName, mime, isEncoder);

    if (quirks & kRequiresWMAProComponent)
    {
       int32_t version = 0;
@@ -244,23 +252,6 @@ void ExtendedCodec::overrideComponentName(
       }
    }

    int32_t wmvVersion = 0;
    if (!strncasecmp(mime->c_str(), MEDIA_MIMETYPE_VIDEO_WMV, strlen(MEDIA_MIMETYPE_VIDEO_WMV)) &&
            msg->findInt32(getMsgKey(kKeyWMVVersion), &wmvVersion)) {
        ALOGD("Found WMV version key %d", wmvVersion);
        if (wmvVersion == 1) {
            ALOGD("Use FFMPEG for unsupported WMV track");
            componentName->setTo("OMX.ffmpeg.wmv.decoder");
        }
    }

    int32_t encodeOptions = 0;
    if (!isEncoder && !strncasecmp(mime->c_str(), MEDIA_MIMETYPE_AUDIO_WMA, strlen(MEDIA_MIMETYPE_AUDIO_WMA)) &&
            !msg->findInt32(getMsgKey(kKeyWMAEncodeOpt), &encodeOptions)) {
        ALOGD("Use FFMPEG for unsupported WMA track");
        componentName->setTo("OMX.ffmpeg.wma.decoder");
    }

    if (!isEncoder && !strncasecmp(mime->c_str(), MEDIA_MIMETYPE_VIDEO_HEVC, strlen(MEDIA_MIMETYPE_VIDEO_HEVC))) {
        sw_codectype = property_get("media.swhevccodectype", value, NULL);
        enableSwHevc = atoi(value);
@@ -389,8 +380,7 @@ status_t ExtendedCodec::setAudioFormat(
    ALOGV("setAudioFormat called");
    status_t err = OK;

    if ((!strcasecmp(MEDIA_MIMETYPE_AUDIO_AC3, mime)) ||
        (!strcasecmp(MEDIA_MIMETYPE_AUDIO_EAC3, mime))) {
    if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_EAC3, mime)) {
        int32_t numChannels, sampleRate;
        CHECK(msg->findInt32("channel-count", &numChannels));
        CHECK(msg->findInt32("sample-rate", &sampleRate));
@@ -1324,7 +1314,7 @@ namespace android {
        ARG_TOUCH(meta);
        ARG_TOUCH(mime);
        ARG_TOUCH(isEncoder);
        return NULL;
        return FFMPEGSoftCodec::overrideComponentName(quirks, meta, mime, isEncoder);
    }

    void ExtendedCodec::overrideComponentName(
@@ -1336,6 +1326,7 @@ namespace android {
        ARG_TOUCH(componentName);
        ARG_TOUCH(mime);
        ARG_TOUCH(isEncoder);
        return FFMPEGSoftCodec::overrideComponentName(quirks, msg, componentName, mime, isEncoder);
    }

    void ExtendedCodec::overrideMimeType(
+73 −5
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@
#include <media/stagefright/OMXCodec.h>

#include <OMX_Component.h>
#include <OMX_AudioExt.h>
#include <OMX_IndexExt.h>

namespace android {

@@ -59,6 +61,7 @@ static const MetaKeyEntry MetaKeyTable[] {
   {kKeySampleFormat         , "sample-format"          , INT32},
   {kKeySampleRate           , "sample-rate"            , INT32},
   {kKeyChannelCount         , "channel-count"          , INT32},
   {kKeyAACAOT               , "aac-profile"            , INT32},
};

const char* FFMPEGSoftCodec::getMsgKey(int key) {
@@ -151,6 +154,71 @@ static void InitOMXParams(T *params) {
    params->nVersion.s.nStep = 0;
}

const char* FFMPEGSoftCodec::overrideComponentName(
        uint32_t /*quirks*/, const sp<MetaData> &meta, const char *mime, bool isEncoder) {
    const char* componentName = NULL;

    int32_t wmvVersion = 0;
    if (!strncasecmp(mime, MEDIA_MIMETYPE_VIDEO_WMV, strlen(MEDIA_MIMETYPE_VIDEO_WMV)) &&
            meta->findInt32(kKeyWMVVersion, &wmvVersion)) {
        ALOGD("Found WMV version key %d", wmvVersion);
        if (wmvVersion == 1) {
            ALOGD("Use FFMPEG for unsupported WMV track");
            componentName = "OMX.ffmpeg.wmv.decoder";
        }
    }

    int32_t encodeOptions = 0;
    if (!isEncoder && !strncasecmp(mime, MEDIA_MIMETYPE_AUDIO_WMA, strlen(MEDIA_MIMETYPE_AUDIO_WMA)) &&
            !meta->findInt32(kKeyWMAEncodeOpt, &encodeOptions)) {
        ALOGD("Use FFMPEG for unsupported WMA track");
        componentName = "OMX.ffmpeg.wma.decoder";
    }

    // Google's decoder doesn't support MAIN profile
    int32_t aacProfile = 0;
    if (!isEncoder && !strncasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC, strlen(MEDIA_MIMETYPE_AUDIO_AAC)) &&
            meta->findInt32(kKeyAACAOT, &aacProfile)) {
        if (aacProfile == OMX_AUDIO_AACObjectMain) {
            ALOGD("Use FFMPEG for AAC MAIN profile");
            componentName = "OMX.ffmpeg.aac.decoder";
        }
    }
    
    return componentName;
}

void FFMPEGSoftCodec::overrideComponentName(
        uint32_t /*quirks*/, const sp<AMessage> &msg, AString* componentName, AString* mime, int32_t isEncoder) {

    int32_t wmvVersion = 0;
    if (!strncasecmp(mime->c_str(), MEDIA_MIMETYPE_VIDEO_WMV, strlen(MEDIA_MIMETYPE_VIDEO_WMV)) &&
            msg->findInt32(getMsgKey(kKeyWMVVersion), &wmvVersion)) {
        ALOGD("Found WMV version key %d", wmvVersion);
        if (wmvVersion == 1) {
            ALOGD("Use FFMPEG for unsupported WMV track");
            componentName->setTo("OMX.ffmpeg.wmv.decoder");
        }
    }

    int32_t encodeOptions = 0;
    if (!isEncoder && !strncasecmp(mime->c_str(), MEDIA_MIMETYPE_AUDIO_WMA, strlen(MEDIA_MIMETYPE_AUDIO_WMA)) &&
            !msg->findInt32(getMsgKey(kKeyWMAEncodeOpt), &encodeOptions)) {
        ALOGD("Use FFMPEG for unsupported WMA track");
        componentName->setTo("OMX.ffmpeg.wma.decoder");
    }

    // Google's decoder doesn't support MAIN profile
    int32_t aacProfile = 0;
    if (!isEncoder && !strncasecmp(mime->c_str(), MEDIA_MIMETYPE_AUDIO_AAC, strlen(MEDIA_MIMETYPE_AUDIO_AAC)) &&
            msg->findInt32(getMsgKey(kKeyAACAOT), &aacProfile)) {
        if (aacProfile == OMX_AUDIO_AACObjectMain) {
            ALOGD("Use FFMPEG for AAC MAIN profile");
            componentName->setTo("OMX.ffmpeg.aac.decoder");
        }
    }
}

status_t FFMPEGSoftCodec::handleSupportedAudioFormats(int format, AString* mime) {
    ALOGV("handleSupportedAudioFormats called for format:%x",format);
    status_t retVal = OK;
@@ -164,7 +232,7 @@ status_t FFMPEGSoftCodec::handleSupportedAudioFormats(int format, AString* mime)
        *mime = MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II;
    } else if (format == OMX_AUDIO_CodingWMA ) {
        *mime = MEDIA_MIMETYPE_AUDIO_WMA;
    } else if (format == OMX_AUDIO_CodingAC3 ) {
    } else if (format == OMX_AUDIO_CodingAC3 || format == OMX_AUDIO_CodingAndroidAC3) {
        *mime = MEDIA_MIMETYPE_AUDIO_AC3;
    } else if (format == OMX_AUDIO_CodingAPE) {
        *mime = MEDIA_MIMETYPE_AUDIO_APE;
@@ -696,7 +764,7 @@ status_t FFMPEGSoftCodec::setAC3Format(
    int32_t numChannels = 0;
    int32_t sampleRate = 0;
    int32_t bitsPerSample = 0;
    OMX_AUDIO_PARAM_AC3TYPE param;
    OMX_AUDIO_PARAM_ANDROID_AC3TYPE param;

    CHECK(msg->findInt32(getMsgKey(kKeyChannelCount), &numChannels));
    CHECK(msg->findInt32(getMsgKey(kKeySampleRate), &sampleRate));
@@ -708,15 +776,15 @@ status_t FFMPEGSoftCodec::setAC3Format(
    param.nPortIndex = kPortIndexInput;

    status_t err = OMXhandle->getParameter(
            nodeID, OMX_IndexParamAudioAc3, &param, sizeof(param));
            nodeID, (OMX_INDEXTYPE)OMX_IndexParamAudioAndroidAc3, &param, sizeof(param));
    if (err != OK)
        return err;

    param.nChannels = numChannels;
    param.nSamplingRate = sampleRate;
    param.nSampleRate = sampleRate;

    err = OMXhandle->setParameter(
            nodeID, OMX_IndexParamAudioAc3, &param, sizeof(param));
            nodeID, (OMX_INDEXTYPE)OMX_IndexParamAudioAndroidAc3, &param, sizeof(param));
    return err;
}