Camera3: add camera3 buffer manager support
* Add camera buffer manager for buffer allocation and sharing management across
multiple streams. Only gralloc v0 implementation is done, v1 implementation is
pending. With this, the max mem footprint for multiple streams in the same
stream set will be the max buffer count x max buffer size.
* API1 client will still use the old bufferQueue code path, buffer manager
is only targeting at API2 clients.
* Prepare and teardown should work with buffer manager.
* Some existing code typo fix and cleanup (to fix the compiling warnings).
Bug: 25088440
Change-Id: I68b246faa43080302acd02a8e976384bd3e26a23
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 6c07aef..ea1e5f6 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -167,6 +167,9 @@
return res;
}
+ /** Create buffer manager */
+ mBufferManager = new Camera3BufferManager();
+
bool aeLockAvailable = false;
camera_metadata_ro_entry aeLockAvailableEntry;
res = find_camera_metadata_ro_entry(info.static_camera_characteristics,
@@ -293,6 +296,7 @@
mRequestThread.clear();
mStatusTracker.clear();
+ mBufferManager.clear();
hal3Device = mHal3Device;
}
@@ -502,6 +506,10 @@
mOutputStreams[i]->dump(fd,args);
}
+ lines = String8(" Camera3 Buffer Manager:\n");
+ write(fd, lines.string(), lines.size());
+ mBufferManager->dump(fd, args);
+
lines = String8(" In-flight requests:\n");
if (mInFlightMap.size() == 0) {
lines.append(" None\n");
@@ -926,7 +934,7 @@
status_t Camera3Device::createStream(sp<Surface> consumer,
uint32_t width, uint32_t height, int format, android_dataspace dataSpace,
- camera3_stream_rotation_t rotation, int *id) {
+ camera3_stream_rotation_t rotation, int *id, int streamSetId) {
ATRACE_CALL();
Mutex::Autolock il(mInterfaceLock);
Mutex::Autolock l(mLock);
@@ -963,6 +971,11 @@
assert(mStatus != STATUS_ACTIVE);
sp<Camera3OutputStream> newStream;
+ // Overwrite stream set id to invalid for HAL3.1 or lower, as buffer manager does support
+ // such devices.
+ if (mDeviceVersion < CAMERA_DEVICE_API_VERSION_3_2) {
+ streamSetId = CAMERA3_STREAM_SET_ID_INVALID;
+ }
if (format == HAL_PIXEL_FORMAT_BLOB) {
ssize_t blobBufferSize;
if (dataSpace != HAL_DATASPACE_DEPTH) {
@@ -979,7 +992,7 @@
}
}
newStream = new Camera3OutputStream(mNextStreamId, consumer,
- width, height, blobBufferSize, format, dataSpace, rotation);
+ width, height, blobBufferSize, format, dataSpace, rotation, streamSetId);
} else if (format == HAL_PIXEL_FORMAT_RAW_OPAQUE) {
ssize_t rawOpaqueBufferSize = getRawOpaqueBufferSize(width, height);
if (rawOpaqueBufferSize <= 0) {
@@ -987,13 +1000,22 @@
return BAD_VALUE;
}
newStream = new Camera3OutputStream(mNextStreamId, consumer,
- width, height, rawOpaqueBufferSize, format, dataSpace, rotation);
+ width, height, rawOpaqueBufferSize, format, dataSpace, rotation, streamSetId);
} else {
newStream = new Camera3OutputStream(mNextStreamId, consumer,
- width, height, format, dataSpace, rotation);
+ width, height, format, dataSpace, rotation, streamSetId);
}
newStream->setStatusTracker(mStatusTracker);
+ /**
+ * Camera3 Buffer manager is only supported by HAL3.2 onwards, as the older HALs requires
+ * buffers to be statically allocated for internal static buffer registration, while the
+ * buffers provided by buffer manager are really dynamically allocated.
+ */
+ if (mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2) {
+ newStream->setBufferManager(mBufferManager);
+ }
+
res = mOutputStreams.add(mNextStreamId, newStream);
if (res < 0) {
SET_ERR_L("Can't add new stream to set: %s (%d)", strerror(-res), res);