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

Commit 4358fd9a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "aacenc: handle and warn overlapping timestamps" into qt-aml-media-dev

parents 31d9f589 8767f614
Loading
Loading
Loading
Loading
+25 −16
Original line number Diff line number Diff line
@@ -155,9 +155,7 @@ C2SoftAacEnc::C2SoftAacEnc(
      mNumBytesPerInputFrame(0u),
      mOutBufferSize(0u),
      mSentCodecSpecificData(false),
      mInputTimeSet(false),
      mInputSize(0),
      mNextFrameTimestampUs(0),
      mSignalledError(false),
      mOutIndex(0u),
      mRemainderLen(0u) {
@@ -182,9 +180,9 @@ status_t C2SoftAacEnc::initEncoder() {

c2_status_t C2SoftAacEnc::onStop() {
    mSentCodecSpecificData = false;
    mInputTimeSet = false;
    mInputSize = 0u;
    mNextFrameTimestampUs = 0;
    mNextFrameTimestampUs.reset();
    mLastFrameEndTimestampUs.reset();
    mSignalledError = false;
    mRemainderLen = 0;
    return C2_OK;
@@ -201,9 +199,9 @@ void C2SoftAacEnc::onRelease() {

c2_status_t C2SoftAacEnc::onFlush_sm() {
    mSentCodecSpecificData = false;
    mInputTimeSet = false;
    mInputSize = 0u;
    mNextFrameTimestampUs = 0;
    mNextFrameTimestampUs.reset();
    mLastFrameEndTimestampUs.reset();
    return C2_OK;
}

@@ -366,9 +364,19 @@ void C2SoftAacEnc::process(
        data = view.data();
        capacity = view.capacity();
    }
    if (!mInputTimeSet && capacity > 0) {
    c2_cntr64_t inputTimestampUs = work->input.ordinal.timestamp;
    if (inputTimestampUs < mLastFrameEndTimestampUs.value_or(inputTimestampUs)) {
        ALOGW("Correcting overlapping timestamp: last frame ended at %lldus but "
              "current frame is starting at %lldus. Using the last frame's end timestamp",
              mLastFrameEndTimestampUs->peekll(), inputTimestampUs.peekll());
        inputTimestampUs = *mLastFrameEndTimestampUs;
    }
    if (capacity > 0) {
        if (!mNextFrameTimestampUs) {
            mNextFrameTimestampUs = work->input.ordinal.timestamp;
        mInputTimeSet = true;
        }
        mLastFrameEndTimestampUs = inputTimestampUs
                + (capacity / sizeof(int16_t) * 1000000ll / channelCount / sampleRate);
    }

    size_t numFrames =
@@ -376,8 +384,7 @@ void C2SoftAacEnc::process(
        / mNumBytesPerInputFrame;
    ALOGV("capacity = %zu; mInputSize = %zu; numFrames = %zu "
          "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu",
          capacity, mInputSize, numFrames,
          mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll(),
          capacity, mInputSize, numFrames, mNumBytesPerInputFrame, inputTimestampUs.peekll(),
          mRemainderLen);

    std::shared_ptr<C2LinearBlock> block;
@@ -505,8 +512,10 @@ void C2SoftAacEnc::process(
                mInputSize = 0;
                int consumed = (capacity / sizeof(int16_t)) - inargs.numInSamples
                        + outargs.numInSamples;
                c2_cntr64_t currentFrameTimestampUs = mNextFrameTimestampUs;
                mNextFrameTimestampUs = work->input.ordinal.timestamp
                ALOGV("consumed = %d, capacity = %zu, inSamples = %d, outSamples = %d",
                      consumed, capacity, inargs.numInSamples, outargs.numInSamples);
                c2_cntr64_t currentFrameTimestampUs = *mNextFrameTimestampUs;
                mNextFrameTimestampUs = inputTimestampUs
                        + (consumed * 1000000ll / channelCount / sampleRate);
                std::shared_ptr<C2Buffer> buffer = createLinearBuffer(block, 0, outargs.numOutBytes);
#if 0
@@ -533,7 +542,7 @@ void C2SoftAacEnc::process(
        }
        ALOGV("encoderErr = %d mInputSize = %zu "
              "inargs.numInSamples = %d, mNextFrameTimestampUs = %lld",
              encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs.peekll());
              encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs->peekll());
    }
    if (eos && inBufferSize[0] > 0) {
        if (numFrames && !block) {
@@ -617,9 +626,9 @@ c2_status_t C2SoftAacEnc::drain(

    (void)pool;
    mSentCodecSpecificData = false;
    mInputTimeSet = false;
    mInputSize = 0u;
    mNextFrameTimestampUs = 0;
    mNextFrameTimestampUs.reset();
    mLastFrameEndTimestampUs.reset();

    // TODO: we don't have any pending work at this time to drain.
    return C2_OK;
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define ANDROID_C2_SOFT_AAC_ENC_H_

#include <atomic>
#include <optional>

#include <SimpleC2Component.h>

@@ -54,9 +55,9 @@ private:
    UINT mOutBufferSize;

    bool mSentCodecSpecificData;
    bool mInputTimeSet;
    size_t mInputSize;
    c2_cntr64_t mNextFrameTimestampUs;
    std::optional<c2_cntr64_t> mNextFrameTimestampUs;
    std::optional<c2_cntr64_t> mLastFrameEndTimestampUs;

    bool mSignalledError;
    std::atomic_uint64_t mOutIndex;