From 8b30dd1104d26c92acd14df3a100a1ede0b1f47f Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Mon, 25 Jan 2021 14:16:54 -0800 Subject: Allow BlastBufferQueue to acquire an additional buffer We want to be able to send buffers from BlastBufferQueue to the server as soon as possible. This allows us among other things, dropping the oldest buffer when multiple buffers with timestamps are queued up. To support this behavior with BlastBufferQueue, we need to acquire an additional buffer and send it to SurfaceFlinger. This requires changing the consumer owned by BlastBufferQueue to acquire an additional buffer. This change is safe because we will only acquire the buffer if its not droppable, maintaining the contract with the producer. If the buffer is not droppable, i.e. the producer is in sync mode, once the buffer has been queued, the buffer is owned by the queue until it is released or acquired by the consumer. By acquiring an additional buffer, we transfer the ownership to the consumer earlier. The server has more info to make decisions faster. The producer still has access the same number of buffers and is unaffected. If the producer is in async mode, then this buffer may be released by the producer when trying to queue a buffer. So we check if the buffer is droppable, and we do not acquire the extra buffer in this scenario. Test: atest BlastBufferQueueTests android.media.cts.PresentationSyncTest Bug: b/176507654, b/176967609 Change-Id: I494a9edcbea0b1c297ee75df2b840d8328e59eca --- libs/gui/BufferQueueConsumer.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'libs/gui/BufferQueueConsumer.cpp') diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp index da6143c59f..7f7a0437f1 100644 --- a/libs/gui/BufferQueueConsumer.cpp +++ b/libs/gui/BufferQueueConsumer.cpp @@ -94,7 +94,10 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, ++numAcquiredBuffers; } } - if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) { + const bool acquireNonDroppableBuffer = mCore->mAllowExtraAcquire && + numAcquiredBuffers == mCore->mMaxAcquiredBufferCount + 1; + if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1 && + !acquireNonDroppableBuffer) { BQ_LOGE("acquireBuffer: max acquired buffer count reached: %d (max %d)", numAcquiredBuffers, mCore->mMaxAcquiredBufferCount); return INVALID_OPERATION; @@ -254,6 +257,9 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, outBuffer->mIsStale = false; outBuffer->mAutoRefresh = mCore->mSharedBufferMode && mCore->mAutoRefresh; + } else if (acquireNonDroppableBuffer && front->mIsDroppable) { + BQ_LOGV("acquireBuffer: front buffer is not droppable"); + return NO_BUFFER_AVAILABLE; } else { slot = front->mSlot; *outBuffer = *front; @@ -824,4 +830,9 @@ status_t BufferQueueConsumer::dumpState(const String8& prefix, String8* outResul return NO_ERROR; } +void BufferQueueConsumer::setAllowExtraAcquire(bool allow) { + std::lock_guard lock(mCore->mMutex); + mCore->mAllowExtraAcquire = allow; +} + } // namespace android -- cgit v1.2.3-59-g8ed1b