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

Commit 0784ea6c authored by Marco Nelissen's avatar Marco Nelissen Committed by Android (Google) Code Review
Browse files

Merge "Fix AAC timestamps"

parents 7b428d51 a5a103c5
Loading
Loading
Loading
Loading
+26 −12
Original line number Original line Diff line number Diff line
@@ -65,10 +65,9 @@ SoftAAC2::SoftAAC2(
      mInputBufferCount(0),
      mInputBufferCount(0),
      mOutputBufferCount(0),
      mOutputBufferCount(0),
      mSignalledError(false),
      mSignalledError(false),
      mLastInHeader(NULL),
      mCurrentInputTime(0),
      mOutputPortSettingsChange(NONE) {
      mOutputPortSettingsChange(NONE) {
    for (unsigned int i = 0; i < kNumDelayBlocksMax; i++) {
        mAnchorTimeUs[i] = 0;
    }
    initPorts();
    initPorts();
    CHECK_EQ(initDecoder(), (status_t)OK);
    CHECK_EQ(initDecoder(), (status_t)OK);
}
}
@@ -496,14 +495,11 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
            } else {
            } else {
                mEndOfInput = false;
                mEndOfInput = false;
            }
            }
            if (inHeader->nOffset == 0) { // TODO: does nOffset != 0 happen?
                mAnchorTimeUs[mInputBufferCount % kNumDelayBlocksMax] =
                        inHeader->nTimeStamp;
            }


            if (inHeader->nFilledLen == 0) {
            if (inHeader->nFilledLen == 0) {
                inInfo->mOwnedByUs = false;
                inInfo->mOwnedByUs = false;
                inQueue.erase(inQueue.begin());
                inQueue.erase(inQueue.begin());
                mLastInHeader = NULL;
                inInfo = NULL;
                inInfo = NULL;
                notifyEmptyBufferDone(inHeader);
                notifyEmptyBufferDone(inHeader);
                inHeader = NULL;
                inHeader = NULL;
@@ -568,6 +564,18 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
                INT prevSampleRate = mStreamInfo->sampleRate;
                INT prevSampleRate = mStreamInfo->sampleRate;
                INT prevNumChannels = mStreamInfo->numChannels;
                INT prevNumChannels = mStreamInfo->numChannels;


                if (inHeader != mLastInHeader) {
                    mLastInHeader = inHeader;
                    mCurrentInputTime = inHeader->nTimeStamp;
                } else {
                    if (mStreamInfo->sampleRate) {
                        mCurrentInputTime += mStreamInfo->aacSamplesPerFrame *
                                1000000ll / mStreamInfo->sampleRate;
                    } else {
                        ALOGW("no sample rate yet");
                    }
                }
                mAnchorTimes.add(mCurrentInputTime);
                aacDecoder_Fill(mAACDecoder,
                aacDecoder_Fill(mAACDecoder,
                                inBuffer,
                                inBuffer,
                                inBufferLength,
                                inBufferLength,
@@ -671,6 +679,7 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
                            inInfo->mOwnedByUs = false;
                            inInfo->mOwnedByUs = false;
                            mInputBufferCount++;
                            mInputBufferCount++;
                            inQueue.erase(inQueue.begin());
                            inQueue.erase(inQueue.begin());
                            mLastInHeader = NULL;
                            inInfo = NULL;
                            inInfo = NULL;
                            notifyEmptyBufferDone(inHeader);
                            notifyEmptyBufferDone(inHeader);
                            inHeader = NULL;
                            inHeader = NULL;
@@ -687,11 +696,12 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
                    inInfo->mOwnedByUs = false;
                    inInfo->mOwnedByUs = false;
                    mInputBufferCount++;
                    mInputBufferCount++;
                    inQueue.erase(inQueue.begin());
                    inQueue.erase(inQueue.begin());
                    mLastInHeader = NULL;
                    inInfo = NULL;
                    inInfo = NULL;
                    notifyEmptyBufferDone(inHeader);
                    notifyEmptyBufferDone(inHeader);
                    inHeader = NULL;
                    inHeader = NULL;
                } else {
                } else {
                    ALOGW("inHeader->nFilledLen = %d", inHeader->nFilledLen);
                    ALOGV("inHeader->nFilledLen = %d", inHeader->nFilledLen);
                }
                }
            }
            }
        }
        }
@@ -779,8 +789,8 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
                outHeader->nFlags = 0;
                outHeader->nFlags = 0;
            }
            }


            outHeader->nTimeStamp = mAnchorTimeUs[mOutputBufferCount
            outHeader->nTimeStamp = mAnchorTimes.isEmpty() ? 0 : mAnchorTimes.itemAt(0);
                    % kNumDelayBlocksMax];
            mAnchorTimes.removeAt(0);


            mOutputBufferCount++;
            mOutputBufferCount++;
            outInfo->mOwnedByUs = false;
            outInfo->mOwnedByUs = false;
@@ -820,8 +830,8 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) {
                    outHeader->nFilledLen = 0;
                    outHeader->nFilledLen = 0;
                    outHeader->nFlags = OMX_BUFFERFLAG_EOS;
                    outHeader->nFlags = OMX_BUFFERFLAG_EOS;


                    outHeader->nTimeStamp = mAnchorTimeUs[mOutputBufferCount
                    outHeader->nTimeStamp = mAnchorTimes.itemAt(0);
                            % kNumDelayBlocksMax];
                    mAnchorTimes.removeAt(0);


                    mOutputBufferCount++;
                    mOutputBufferCount++;
                    outInfo->mOwnedByUs = false;
                    outInfo->mOwnedByUs = false;
@@ -842,6 +852,8 @@ void SoftAAC2::onPortFlushCompleted(OMX_U32 portIndex) {
        // depend on fragments from the last one decoded.
        // depend on fragments from the last one decoded.
        // drain all existing data
        // drain all existing data
        drainDecoder();
        drainDecoder();
        mAnchorTimes.clear();
        mLastInHeader = NULL;
    } else {
    } else {
        while (outputDelayRingBufferSamplesAvailable() > 0) {
        while (outputDelayRingBufferSamplesAvailable() > 0) {
            int32_t ns = outputDelayRingBufferGetSamples(0,
            int32_t ns = outputDelayRingBufferGetSamples(0,
@@ -896,6 +908,8 @@ void SoftAAC2::onReset() {
    mOutputDelayRingBufferReadPos = 0;
    mOutputDelayRingBufferReadPos = 0;
    mEndOfInput = false;
    mEndOfInput = false;
    mEndOfOutput = false;
    mEndOfOutput = false;
    mAnchorTimes.clear();
    mLastInHeader = NULL;


    // To make the codec behave the same before and after a reset, we need to invalidate the
    // To make the codec behave the same before and after a reset, we need to invalidate the
    // streaminfo struct. This does that:
    // streaminfo struct. This does that:
+3 −1
Original line number Original line Diff line number Diff line
@@ -58,7 +58,9 @@ private:
    size_t mInputBufferCount;
    size_t mInputBufferCount;
    size_t mOutputBufferCount;
    size_t mOutputBufferCount;
    bool mSignalledError;
    bool mSignalledError;
    int64_t mAnchorTimeUs[kNumDelayBlocksMax];
    OMX_BUFFERHEADERTYPE *mLastInHeader;
    int64_t mCurrentInputTime;
    Vector<int64_t> mAnchorTimes;


    CDrcPresModeWrapper mDrcWrap;
    CDrcPresModeWrapper mDrcWrap;