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

Commit 1fb4d80d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "aaudio: use minimum of one burst in buffer" into rvc-dev am: 4023d73e

Change-Id: Ib142dfa5de050cf203f6c09c1a614ff923dcb736
parents a82be3e7 4023d73e
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -714,12 +714,8 @@ void AudioStreamInternal::processTimestamp(uint64_t position, int64_t time) {
aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) {
    int32_t adjustedFrames = requestedFrames;
    const int32_t maximumSize = getBufferCapacity() - mFramesPerBurst;
    // The buffer size can be set to zero.
    // This means that the callback may be called when the internal buffer becomes empty.
    // This will be fine on some devices in ideal circumstances and will result in the
    // lowest possible latency.
    // If there are glitches then they should be detected as XRuns and the size can be increased.
    static const int32_t minimumSize = 0;
    // Minimum size should be a multiple number of bursts.
    const int32_t minimumSize = 1 * mFramesPerBurst;

    // Clip to minimum size so that rounding up will work better.
    adjustedFrames = std::max(minimumSize, adjustedFrames);
@@ -731,12 +727,14 @@ aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) {
        // Round to the next highest burst size.
        int32_t numBursts = (adjustedFrames + mFramesPerBurst - 1) / mFramesPerBurst;
        adjustedFrames = numBursts * mFramesPerBurst;
        // Clip just in case maximumSize is not a multiple of mFramesPerBurst.
        adjustedFrames = std::min(maximumSize, adjustedFrames);
    }

    // Clip against the actual size from the endpoint.
    int32_t actualFrames = 0;
    mAudioEndpoint.setBufferSizeInFrames(maximumSize, &actualFrames);
    // actualFrames should be <= maximumSize
    // actualFrames should be <= actual maximum size of endpoint
    adjustedFrames = std::min(actualFrames, adjustedFrames);

    mBufferSizeInFrames = adjustedFrames;