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

Commit 9cedc5ad authored by Yanqiang Fan's avatar Yanqiang Fan Committed by android-build-merger
Browse files

Merge "Fix rounding error accumulation of audio timestamp"

am: cfa3f496

Change-Id: I584c6b7b81f46ade75cb069ced5249b340b6f8de
parents b5857135 cfa3f496
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -427,19 +427,17 @@ status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) {
void AudioSource::queueInputBuffer_l(MediaBuffer *buffer, int64_t timeUs) {
    const size_t bufferSize = buffer->range_length();
    const size_t frameSize = mRecord->frameSize();
    const int64_t timestampUs =
                mPrevSampleTimeUs +
                    ((1000000LL * (bufferSize / frameSize)) +
                        (mSampleRate >> 1)) / mSampleRate;

    if (mNumFramesReceived == 0) {
        buffer->meta_data().setInt64(kKeyAnchorTime, mStartTimeUs);
    }

    mNumFramesReceived += bufferSize / frameSize;
    const int64_t timestampUs =
                mStartTimeUs +
                    ((1000000LL * mNumFramesReceived) +
                        (mSampleRate >> 1)) / mSampleRate;
    buffer->meta_data().setInt64(kKeyTime, mPrevSampleTimeUs);
    buffer->meta_data().setInt64(kKeyDriftTime, timeUs - mInitialReadTimeUs);
    mPrevSampleTimeUs = timestampUs;
    mNumFramesReceived += bufferSize / frameSize;
    mBuffersReceived.push_back(buffer);
    mFrameAvailableCondition.signal();
}