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

Commit 081e11e5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AAudio: fix prepareBuffersForStop()" into main

parents 277a3dc7 8a447ed8
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -117,7 +117,8 @@ void AudioStreamInternalPlay::prepareBuffersForStop() {
        return;
    }
    // Sleep until the DSP has read all of the data written.
    int64_t validFramesInBuffer = getFramesWritten() - getFramesRead();
    int64_t validFramesInBuffer =
            mAudioEndpoint->getDataWriteCounter() - mAudioEndpoint->getDataReadCounter();
    if (validFramesInBuffer >= 0) {
        int64_t emptyFramesInBuffer = ((int64_t) getBufferCapacity()) - validFramesInBuffer;

@@ -131,7 +132,8 @@ void AudioStreamInternalPlay::prepareBuffersForStop() {
        // Sleep until we are confident the DSP has consumed all of the valid data.
        // Sleep for one extra burst as a safety margin because the IsochronousClockModel
        // is not perfectly accurate.
        int64_t positionInEmptyMemory = getFramesWritten() + getFramesPerBurst();
        // The ClockModel uses the server frame position so do not use getFramesWritten().
        int64_t positionInEmptyMemory = mAudioEndpoint->getDataWriteCounter() + getFramesPerBurst();
        int64_t timeAllConsumed = mClockModel.convertPositionToTime(positionInEmptyMemory);
        int64_t durationAllConsumed = timeAllConsumed - AudioClock::getNanoseconds();
        // Prevent sleeping for too long.
+2 −3
Original line number Diff line number Diff line
@@ -269,9 +269,8 @@ int64_t IsochronousClockModel::convertPositionToTime(int64_t framePosition) cons
    int64_t framesDelta = nextBurstPosition - mMarkerFramePosition;
    int64_t nanosDelta = convertDeltaPositionToTime(framesDelta);
    int64_t time = mMarkerNanoTime + nanosDelta;
//    ALOGD("convertPositionToTime: pos = %llu --> time = %llu",
//         (unsigned long long)framePosition,
//         (unsigned long long)time);
//    ALOGD("%s(): pos = %" PRId64 " --> time = %" PRId64, __func__,
//            framePosition, time);
    return time;
}