[libcamera-devel] [PATCH v3 3/6] libcamera: buffer: Initialise status

Kieran Bingham kieran.bingham at ideasonboard.com
Wed Mar 24 16:01:22 CET 2021


Buffers queued to a pipeline handler may not be yet queued to a device
when the request is cancelled.

This can lead to the FrameMetadata having never been explicitly set by
an underlying V4L2 device.

The status field on this is used to check the state of the buffer to
determine if it was correctly filled, or if it was cancelled.

In the event that the buffer is not used, it must be marked as Cancelled
as the metadata associated with that frame will not be valid.

Initialise the FrameMetadata to FrameCancelled to prevent uninitialised access.
Furthermore, re-initialise the metadata to this state when the buffers
are re-used, or added to a Request to ensure that they are in the
correct state in the event that they do not get used at all.

Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

---
v3:
 - Initialise as FrameCancelled
 - Re-initialise to FrameCancelled when buffers are re-used
 - Do not re-order the enum

 include/libcamera/buffer.h | 2 +-
 src/libcamera/request.cpp  | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h
index 302fe3d3e86b..f6673e2f6eda 100644
--- a/include/libcamera/buffer.h
+++ b/include/libcamera/buffer.h
@@ -28,7 +28,7 @@ struct FrameMetadata {
 		unsigned int bytesused;
 	};
 
-	Status status;
+	Status status = FrameCancelled;
 	unsigned int sequence;
 	uint64_t timestamp;
 	std::vector<Plane> planes;
diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp
index 0071667e4a2c..9ea6ed09446b 100644
--- a/src/libcamera/request.cpp
+++ b/src/libcamera/request.cpp
@@ -118,8 +118,12 @@ void Request::reuse(ReuseFlag flags)
 	pending_.clear();
 	if (flags & ReuseBuffers) {
 		for (auto pair : bufferMap_) {
-			pair.second->request_ = this;
-			pending_.insert(pair.second);
+			FrameBuffer *buffer = pair.second;
+
+			buffer->metadata_.status = FrameMetadata::Status::FrameCancelled;
+			buffer->request_ = this;
+
+			pending_.insert(buffer);
 		}
 	} else {
 		bufferMap_.clear();
@@ -188,6 +192,7 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer)
 	}
 
 	buffer->request_ = this;
+	buffer->metadata_.status = FrameMetadata::Status::FrameCancelled;
 	pending_.insert(buffer);
 	bufferMap_[stream] = buffer;
 
-- 
2.25.1



More information about the libcamera-devel mailing list