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

Commit 04d7e641 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 am: 9cedc5ad

am: a0861a71

Change-Id: I50bac7f3be35e0e4db1e2d124763a7c6fdf0002f
parents b02be352 a0861a71
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -431,19 +431,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();
}