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

Commit dd56603f authored by Wonsik Kim's avatar Wonsik Kim
Browse files

aacenc: reduce logspam for timestamp mismatch

Bug: 159416760
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Test: observe logspam is reduced for the scenario
Change-Id: I52f6400c873f4e3779878575dd09952169e6bf67
parent de38ff80
Loading
Loading
Loading
Loading
+25 −3
Original line number Original line Diff line number Diff line
@@ -293,6 +293,30 @@ status_t C2SoftAacEnc::setAudioParams() {
    return OK;
    return OK;
}
}


static void MaybeLogTimestampWarning(
        long long lastFrameEndTimestampUs, long long inputTimestampUs) {
    using Clock = std::chrono::steady_clock;
    thread_local Clock::time_point sLastLogTimestamp{};
    thread_local int32_t sOverlapCount = -1;
    if (Clock::now() - sLastLogTimestamp > std::chrono::minutes(1) || sOverlapCount < 0) {
        AString countMessage = "";
        if (sOverlapCount > 0) {
            countMessage = AStringPrintf(
                    "(%d overlapping timestamp detected since last log)", sOverlapCount);
        }
        ALOGI("Correcting overlapping timestamp: last frame ended at %lldus but "
                "current frame is starting at %lldus. Using the last frame's end timestamp %s",
                lastFrameEndTimestampUs, inputTimestampUs, countMessage.c_str());
        sLastLogTimestamp = Clock::now();
        sOverlapCount = 0;
    } else {
        ALOGV("Correcting overlapping timestamp: last frame ended at %lldus but "
                "current frame is starting at %lldus. Using the last frame's end timestamp",
                lastFrameEndTimestampUs, inputTimestampUs);
        ++sOverlapCount;
    }
}

void C2SoftAacEnc::process(
void C2SoftAacEnc::process(
        const std::unique_ptr<C2Work> &work,
        const std::unique_ptr<C2Work> &work,
        const std::shared_ptr<C2BlockPool> &pool) {
        const std::shared_ptr<C2BlockPool> &pool) {
@@ -366,9 +390,7 @@ void C2SoftAacEnc::process(
    }
    }
    c2_cntr64_t inputTimestampUs = work->input.ordinal.timestamp;
    c2_cntr64_t inputTimestampUs = work->input.ordinal.timestamp;
    if (inputTimestampUs < mLastFrameEndTimestampUs.value_or(inputTimestampUs)) {
    if (inputTimestampUs < mLastFrameEndTimestampUs.value_or(inputTimestampUs)) {
        ALOGW("Correcting overlapping timestamp: last frame ended at %lldus but "
        MaybeLogTimestampWarning(mLastFrameEndTimestampUs->peekll(), inputTimestampUs.peekll());
              "current frame is starting at %lldus. Using the last frame's end timestamp",
              mLastFrameEndTimestampUs->peekll(), inputTimestampUs.peekll());
        inputTimestampUs = *mLastFrameEndTimestampUs;
        inputTimestampUs = *mLastFrameEndTimestampUs;
    }
    }
    if (capacity > 0) {
    if (capacity > 0) {