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

Commit 7ddd36e4 authored by Steve Kondik's avatar Steve Kondik
Browse files

stagefright: More bit depth plumbing

 * Plumb the bit depth thru more parts of Stagefright.

Change-Id: I0f2cfc17d7b9b6e8cf2e26237fc8d0ab261857cd
parent ba618dd4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ private:
            int32_t maxOutputChannelCount, const drcParams_t& drc,
            int32_t pcmLimiterEnable);

    status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate);
    status_t setupAC3Codec(bool encoder, int32_t numChannels, int32_t sampleRate, int32_t bitsPerSample);

    status_t selectAudioPortFormat(
            OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE desiredFormat);
@@ -304,11 +304,11 @@ private:
    status_t setupG711Codec(bool encoder, int32_t numChannels);

    status_t setupFlacCodec(
            bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel);
            bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel, int32_t bitsPerSample);

    status_t setupRawAudioFormat(
            OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels,
            int32_t bitsPerSample = 16);
            int32_t bitsPerSample);

    status_t setMinBufferSize(OMX_U32 portIndex, size_t size);

+21 −12
Original line number Diff line number Diff line
@@ -1504,17 +1504,20 @@ status_t ACodec::configureCodec(
#endif
        }
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
        int32_t numChannels, sampleRate;
        int32_t numChannels, sampleRate, bitsPerSample;

        if (!msg->findInt32("channel-count", &numChannels)
                || !msg->findInt32("sample-rate", &sampleRate)) {
            // Since we did not always check for these, leave them optional
            // and have the decoder figure it all out.
            err = OK;
        } else {
            int32_t bitsPerSample = 16;
            msg->findInt32("bits-per-sample", &bitsPerSample);
            err = setupRawAudioFormat(
                    encoder ? kPortIndexInput : kPortIndexOutput,
                    sampleRate,
                    numChannels);
                    numChannels, bitsPerSample);
        }
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC)) {
        int32_t numChannels, sampleRate;
@@ -1610,8 +1613,10 @@ status_t ACodec::configureCodec(
                    compressionLevel = 8;
                }
            }
            int32_t bitsPerSample = 16;
            msg->findInt32("bits-per-sample", &bitsPerSample);
            err = setupFlacCodec(
                    encoder, numChannels, sampleRate, compressionLevel);
                    encoder, numChannels, sampleRate, compressionLevel, bitsPerSample);
        }
    } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) {
        int32_t numChannels, sampleRate;
@@ -1631,14 +1636,16 @@ status_t ACodec::configureCodec(
                || !msg->findInt32("sample-rate", &sampleRate)) {
            err = INVALID_OPERATION;
        } else {
            err = setupAC3Codec(encoder, numChannels, sampleRate);
            int32_t bitsPerSample = 16;
            msg->findInt32("bits-per-sample", &bitsPerSample);
            err = setupAC3Codec(encoder, numChannels, sampleRate, bitsPerSample);
        }
    } else {
        if (encoder) {
            int32_t numChannels, sampleRate;
            if (msg->findInt32("channel-count", &numChannels)
                  && msg->findInt32("sample-rate", &sampleRate)) {
                setupRawAudioFormat(kPortIndexInput, sampleRate, numChannels);
                setupRawAudioFormat(kPortIndexInput, sampleRate, numChannels, 16);
            }
        }
#ifdef ENABLE_AV_ENHANCEMENTS
@@ -1764,7 +1771,7 @@ status_t ACodec::setupAACCodec(
    status_t err = setupRawAudioFormat(
            encoder ? kPortIndexInput : kPortIndexOutput,
            sampleRate,
            numChannels);
            numChannels, 16);

    if (err != OK) {
        return err;
@@ -1900,9 +1907,9 @@ status_t ACodec::setupAACCodec(
}

status_t ACodec::setupAC3Codec(
        bool encoder, int32_t numChannels, int32_t sampleRate) {
        bool encoder, int32_t numChannels, int32_t sampleRate, int32_t bitsPerSample) {
    status_t err = setupRawAudioFormat(
            encoder ? kPortIndexInput : kPortIndexOutput, sampleRate, numChannels);
            encoder ? kPortIndexInput : kPortIndexOutput, sampleRate, numChannels, bitsPerSample);

    if (err != OK) {
        return err;
@@ -2007,18 +2014,19 @@ status_t ACodec::setupAMRCodec(bool encoder, bool isWAMR, int32_t bitrate) {
    return setupRawAudioFormat(
            encoder ? kPortIndexInput : kPortIndexOutput,
            isWAMR ? 16000 : 8000 /* sampleRate */,
            1 /* numChannels */);
            1 /* numChannels */, 16);
}

status_t ACodec::setupG711Codec(bool encoder, int32_t numChannels) {
    CHECK(!encoder);  // XXX TODO

    return setupRawAudioFormat(
            kPortIndexInput, 8000 /* sampleRate */, numChannels);
            kPortIndexInput, 8000 /* sampleRate */, numChannels, 16);
}

status_t ACodec::setupFlacCodec(
        bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel) {
        bool encoder, int32_t numChannels, int32_t sampleRate, int32_t compressionLevel,
        int32_t bitsPerSample) {

    if (encoder) {
        OMX_AUDIO_PARAM_FLACTYPE def;
@@ -2042,7 +2050,7 @@ status_t ACodec::setupFlacCodec(
    return setupRawAudioFormat(
            encoder ? kPortIndexInput : kPortIndexOutput,
            sampleRate,
            numChannels);
            numChannels, bitsPerSample);
}

status_t ACodec::setupRawAudioFormat(
@@ -2051,6 +2059,7 @@ status_t ACodec::setupRawAudioFormat(
    InitOMXParams(&def);
    def.nPortIndex = portIndex;

    ALOGI("sampleRate=%d channels=%d bits=%d", sampleRate, numChannels, bitsPerSample);
    status_t err = mOMX->getParameter(
            mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));

+16 −6
Original line number Diff line number Diff line
@@ -258,8 +258,6 @@ status_t FFMPEGSoftCodec::setAudioFormat(
    ALOGV("setAudioFormat called");
    status_t err = OK;

    ALOGV("setAudioFormat: %s", msg->debugString(0).c_str());

    if (isEncoder) {
        ALOGE("Encoding not supported");
        err = BAD_VALUE;
@@ -311,6 +309,8 @@ status_t FFMPEGSoftCodec::setAudioFormat(
        }
    }

    ALOGV("setAudioFormat: %s", msg->debugString(0).c_str());

    return err;
}

@@ -503,12 +503,12 @@ status_t FFMPEGSoftCodec::setRawAudioFormat(
{
    int32_t numChannels = 0;
    int32_t sampleRate = 0;
    int32_t bitsPerSample = 16;
    int32_t bitsPerSample = 0;

    CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeyChannelCount), &numChannels));
    CHECK(msg->findInt32(ExtendedCodec::getMsgKey(kKeySampleRate), &sampleRate));
    if (!msg->findInt32(ExtendedCodec::getMsgKey(kKeyBitsPerSample), &bitsPerSample)) {
        ALOGD("No PCM format specified, using 16 bit");
        ALOGD("No PCM format specified, let decoder decide");
    }

    OMX_PARAM_PORTDEFINITIONTYPE def;
@@ -545,7 +545,9 @@ status_t FFMPEGSoftCodec::setRawAudioFormat(
    pcmParams.nChannels = numChannels;
    pcmParams.eNumData = OMX_NumericalDataSigned;
    pcmParams.bInterleaved = OMX_TRUE;
    if (bitsPerSample > 0) {
        pcmParams.nBitPerSample = bitsPerSample;
    }
    pcmParams.nSamplingRate = sampleRate;
    pcmParams.ePCMMode = OMX_AUDIO_PCMModeLinear;

@@ -553,8 +555,16 @@ status_t FFMPEGSoftCodec::setRawAudioFormat(
        return OMX_ErrorNone;
    }

    return OMXhandle->setParameter(
    err = OMXhandle->setParameter(
            nodeID, OMX_IndexParamAudioPcm, &pcmParams, sizeof(pcmParams));

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

    msg->setInt32("bits-per-sample", pcmParams.nBitPerSample);

    return OK;
}

status_t FFMPEGSoftCodec::setWMAFormat(