Camera3: increase the buffer manager water mark by one
This reduces the chance of allocation during stream steady state.
It helps the cases where one stream is active, and other streams may
randomly request some buffers.
Change-Id: I3f29001a45e223dd2e7929452c4a2ac81a1213f2
diff --git a/services/camera/libcameraservice/device3/Camera3BufferManager.cpp b/services/camera/libcameraservice/device3/Camera3BufferManager.cpp
index 73d9d3d..ae20887 100644
--- a/services/camera/libcameraservice/device3/Camera3BufferManager.cpp
+++ b/services/camera/libcameraservice/device3/Camera3BufferManager.cpp
@@ -204,19 +204,24 @@
buffer.fenceFd = -1;
buffer.graphicBuffer = mAllocator->createGraphicBuffer(
info.width, info.height, info.format, info.combinedUsage, &res);
- ALOGV("%s: allocate a new graphic buffer %p with handle %p",
- __FUNCTION__, buffer.graphicBuffer.get(), buffer.graphicBuffer->handle);
+ ALOGV("%s: allocating a new graphic buffer (%dx%d, format 0x%x) %p with handle %p",
+ __FUNCTION__, info.width, info.height, info.format,
+ buffer.graphicBuffer.get(), buffer.graphicBuffer->handle);
if (res != OK) {
ALOGE("%s: graphic buffer allocation failed: (error %d %s) ",
__FUNCTION__, res, strerror(-res));
return res;
}
+ ALOGV("%s: allocation done", __FUNCTION__);
}
// Increase the hand-out buffer count for tracking purpose.
bufferCount++;
- if (bufferCount > streamSet.allocatedBufferWaterMark) {
- streamSet.allocatedBufferWaterMark = bufferCount;
+ // Update the water mark to be the max hand-out buffer count + 1. An additional buffer is
+ // added to reduce the chance of buffer allocation during stream steady state, especially
+ // for cases where one stream is active, the other stream may request some buffers randomly.
+ if (bufferCount + 1 > streamSet.allocatedBufferWaterMark) {
+ streamSet.allocatedBufferWaterMark = bufferCount + 1;
}
*gb = buffer.graphicBuffer;
*fenceFd = buffer.fenceFd;
@@ -248,6 +253,7 @@
totalAllocatedBufferCount += streamSet.handoutBufferCountMap[i];
}
if (totalAllocatedBufferCount > streamSet.allocatedBufferWaterMark) {
+ ALOGV("%s: free a buffer from stream %d", __FUNCTION__, firstOtherStreamId);
getFirstBufferFromBufferListLocked(streamSet.freeBuffers, firstOtherStreamId);
}
}