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

Commit 5e5efde7 authored by Jamie Gennis's avatar Jamie Gennis
Browse files

BufferQueue: add a check for the max acquired bufs

This change adds an error check to ensure that consumers don't acquire more
buffers than the maximum that they set.

Change-Id: I026643564bde52732e4ee6146972b207ddbbba77
parent 72f096fb
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -812,6 +812,23 @@ void BufferQueue::freeAllBuffersLocked() {
status_t BufferQueue::acquireBuffer(BufferItem *buffer) {
status_t BufferQueue::acquireBuffer(BufferItem *buffer) {
    ATRACE_CALL();
    ATRACE_CALL();
    Mutex::Autolock _l(mMutex);
    Mutex::Autolock _l(mMutex);

    // Check that the consumer doesn't currently have the maximum number of
    // buffers acquired.  We allow the max buffer count to be exceeded by one
    // buffer, so that the consumer can successfully set up the newly acquired
    // buffer before releasing the old one.
    int numAcquiredBuffers = 0;
    for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
        if (mSlots[i].mBufferState == BufferSlot::ACQUIRED) {
            numAcquiredBuffers++;
        }
    }
    if (numAcquiredBuffers >= mMaxAcquiredBufferCount+1) {
        ST_LOGE("acquireBuffer: max acquired buffer count reached: %d (max=%d)",
                numAcquiredBuffers, mMaxAcquiredBufferCount);
        return INVALID_OPERATION;
    }

    // check if queue is empty
    // check if queue is empty
    // In asynchronous mode the list is guaranteed to be one buffer
    // In asynchronous mode the list is guaranteed to be one buffer
    // deep, while in synchronous mode we use the oldest buffer.
    // deep, while in synchronous mode we use the oldest buffer.