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

Commit 51d75479 authored by Andreas Huber's avatar Andreas Huber
Browse files

Only emit padding at the end of the stream in the aac and mp3 decoders

if we actually discarded content at the beginning of the stream.

Change-Id: I1e79835bb3a02350060a137b94f85f2c90f4a12b
parent e6712071
Loading
Loading
Loading
Loading
+36 −16
Original line number Diff line number Diff line
@@ -320,22 +320,39 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
            inInfo->mOwnedByUs = false;
            notifyEmptyBufferDone(inHeader);

            // flush out the decoder's delayed data by calling DecodeFrame one more time, with
            // the AACDEC_FLUSH flag set
            if (!mIsFirst) {
                // flush out the decoder's delayed data by calling DecodeFrame
                // one more time, with the AACDEC_FLUSH flag set
                INT_PCM *outBuffer =
                    reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset);
            AAC_DECODER_ERROR decoderErr = aacDecoder_DecodeFrame(mAACDecoder,
                        reinterpret_cast<INT_PCM *>(
                                outHeader->pBuffer + outHeader->nOffset);

                AAC_DECODER_ERROR decoderErr =
                    aacDecoder_DecodeFrame(mAACDecoder,
                                           outBuffer,
                                           outHeader->nAllocLen,
                                           AACDEC_FLUSH);

                if (decoderErr != AAC_DEC_OK) {
                    mSignalledError = true;
                notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL);

                    notify(OMX_EventError, OMX_ErrorUndefined, decoderErr,
                           NULL);

                    return;
                }

                outHeader->nFilledLen =
                    mStreamInfo->frameSize * sizeof(int16_t) * mStreamInfo->numChannels;
                        mStreamInfo->frameSize
                            * sizeof(int16_t)
                            * mStreamInfo->numChannels;
            } else {
                // Since we never discarded frames from the start, we won't have
                // to add any padding at the end either.

                outHeader->nFilledLen = 0;
            }

            outHeader->nFlags = OMX_BUFFERFLAG_EOS;

            outQueue.erase(outQueue.begin());
@@ -404,7 +421,9 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
        }

        // Fill and decode
        INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset);
        INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>(
                outHeader->pBuffer + outHeader->nOffset);

        bytesValid[0] = inBufferLength[0];

        int prevSampleRate = mStreamInfo->sampleRate;
@@ -493,7 +512,8 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
            // (decode failed) we'll output a silent frame.
            if (mIsFirst) {
                mIsFirst = false;
                // the first decoded frame should be discarded to account for decoder delay
                // the first decoded frame should be discarded to account
                // for decoder delay
                numOutBytes = 0;
            }

+18 −6
Original line number Diff line number Diff line
@@ -191,10 +191,19 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) {
            inInfo->mOwnedByUs = false;
            notifyEmptyBufferDone(inHeader);

            if (!mIsFirst) {
                // pad the end of the stream with 529 samples, since that many samples
                // were trimmed off the beginning when decoding started
            outHeader->nFilledLen = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
                outHeader->nFilledLen =
                    kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);

                memset(outHeader->pBuffer, 0, outHeader->nFilledLen);
            } else {
                // Since we never discarded frames from the start, we won't have
                // to add any padding at the end either.
                outHeader->nFilledLen = 0;
            }

            outHeader->nFlags = OMX_BUFFERFLAG_EOS;

            outQueue.erase(outQueue.begin());
@@ -260,8 +269,11 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) {
            // The decoder delay is 529 samples, so trim that many samples off
            // the start of the first output buffer. This essentially makes this
            // decoder have zero delay, which the rest of the pipeline assumes.
            outHeader->nOffset = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
            outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t) - outHeader->nOffset;
            outHeader->nOffset =
                kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);

            outHeader->nFilledLen =
                mConfig->outputFrameSize * sizeof(int16_t) - outHeader->nOffset;
        } else {
            outHeader->nOffset = 0;
            outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t);
+14 −3
Original line number Diff line number Diff line
@@ -515,7 +515,10 @@ static const char *GetURLForMime(const char *mime) {

static sp<MediaSource> CreateSourceForMime(const char *mime) {
    const char *url = GetURLForMime(mime);
    CHECK(url != NULL);

    if (url == NULL) {
        return NULL;
    }

    sp<MediaExtractor> extractor = CreateExtractorFromURI(url);

@@ -571,7 +574,7 @@ status_t Harness::testSeek(
    const char *mime = GetMimeFromComponentRole(componentRole);

    if (!mime) {
        ALOGI("Cannot perform seek test with this componentRole (%s)",
        printf("  * Cannot perform seek test with this componentRole (%s)\n",
               componentRole);

        return OK;
@@ -579,6 +582,14 @@ status_t Harness::testSeek(

    sp<MediaSource> source = CreateSourceForMime(mime);

    if (source == NULL) {
        printf("  * Unable to open test content for type '%s', "
               "skipping test of componentRole %s\n",
               mime, componentRole);

        return OK;
    }

    sp<MediaSource> seekSource = CreateSourceForMime(mime);
    if (source == NULL || seekSource == NULL) {
        return UNKNOWN_ERROR;