From f0eaf25e9247edf4d124bedaeb863f7abdf35a3e Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Fri, 21 Mar 2014 13:05:51 -0700 Subject: BufferQueue: Add producer buffer-released callback Add a callback to the producer side, onBufferReleased, which will be called every time the consumer releases a buffer back to the BufferQueue. This will enable a buffer stream splitter to work autonomously without having to block on dequeueBuffer. The binder object used for the callback replaces the generic IBinder token that was passed into IGraphicBufferProducer::connect to detect the death of the producer. If a producer does not wish to listen for buffer release events, it can pass in an instance of the DummyProducerListener class defined in IProducerListener.h, if it even cares about death events (BufferQueue doesn't enforce the token being non-NULL, though perhaps we should). Change-Id: I23935760673524abeafea2b58dccc3583b368710 --- libs/gui/BufferQueueProducer.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libs/gui/BufferQueueProducer.cpp') diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 9dd90bab58..82d931ec7f 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -654,7 +655,7 @@ int BufferQueueProducer::query(int what, int *outValue) { return NO_ERROR; } -status_t BufferQueueProducer::connect(const sp &token, +status_t BufferQueueProducer::connect(const sp& listener, int api, bool producerControlledByApp, QueueBufferOutput *output) { ATRACE_CALL(); Mutex::Autolock lock(mCore->mMutex); @@ -711,16 +712,16 @@ status_t BufferQueueProducer::connect(const sp &token, // Set up a death notification so that we can disconnect // automatically if the remote producer dies - if (token != NULL && token->remoteBinder() != NULL) { - status = token->linkToDeath( + if (listener != NULL && + listener->asBinder()->remoteBinder() != NULL) { + status = listener->asBinder()->linkToDeath( static_cast(this)); - if (status == NO_ERROR) { - mCore->mConnectedProducerToken = token; - } else { + if (status != NO_ERROR) { BQ_LOGE("connect(P): linkToDeath failed: %s (%d)", strerror(-status), status); } } + mCore->mConnectedProducerListener = listener; break; default: BQ_LOGE("connect(P): unknown API %d", api); @@ -759,14 +760,15 @@ status_t BufferQueueProducer::disconnect(int api) { mCore->freeAllBuffersLocked(); // Remove our death notification callback if we have one - sp token = mCore->mConnectedProducerToken; - if (token != NULL) { + if (mCore->mConnectedProducerListener != NULL) { + sp token = + mCore->mConnectedProducerListener->asBinder(); // This can fail if we're here because of the death // notification, but we just ignore it token->unlinkToDeath( static_cast(this)); } - mCore->mConnectedProducerToken = NULL; + mCore->mConnectedProducerListener = NULL; mCore->mConnectedApi = BufferQueueCore::NO_CONNECTED_API; mCore->mSidebandStream.clear(); mCore->mDequeueCondition.broadcast(); -- cgit v1.2.3-59-g8ed1b