[4/5] libcamera: Add stride in FrameBuffer::Plane
diff mbox series

Message ID 20241009074642.2965791-5-chenghaoyang@chromium.org
State New
Headers show
Series
  • Add InfoFrame
Related show

Commit Message

Cheng-Hao Yang Oct. 9, 2024, 7:41 a.m. UTC
Some platforms, like mtkisp7, need the stride information in a
FrameBuffer. This patch adds the member variable in FrameBuffer::Plane,
and appends the member variable in IPA (de)serializer.

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
---
 include/libcamera/framebuffer.h       | 1 +
 src/libcamera/dma_buf_allocator.cpp   | 3 ++-
 src/libcamera/framebuffer.cpp         | 5 +++++
 src/libcamera/ipa_data_serializer.cpp | 3 +++
 4 files changed, 11 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h
index ff8392430..059c66f31 100644
--- a/include/libcamera/framebuffer.h
+++ b/include/libcamera/framebuffer.h
@@ -55,6 +55,7 @@  public:
 		SharedFD fd;
 		unsigned int offset = kInvalidOffset;
 		unsigned int length;
+		unsigned int stride;
 	};
 
 	FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
index 262eb53a0..e6a29c2d7 100644
--- a/src/libcamera/dma_buf_allocator.cpp
+++ b/src/libcamera/dma_buf_allocator.cpp
@@ -255,7 +255,8 @@  DmaBufAllocator::createBuffer(std::string name,
 		return nullptr;
 
 	for (auto planeSize : planeSizes) {
-		planes.emplace_back(FrameBuffer::Plane{ fd, offset, planeSize });
+		/* \todo Invalid stride information. Consider adding strides as input. */
+		planes.emplace_back(FrameBuffer::Plane{ fd, offset, planeSize, 0 });
 		offset += planeSize;
 	}
 
diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp
index 826848f75..61a3cc024 100644
--- a/src/libcamera/framebuffer.cpp
+++ b/src/libcamera/framebuffer.cpp
@@ -282,6 +282,11 @@  FrameBuffer::Private::~Private()
  * \brief The plane length in bytes
  */
 
+/**
+ * \var FrameBuffer::Plane::stride
+ * \brief The plane stride in bytes
+ */
+
 namespace {
 
 ino_t fileDescriptorInode(const SharedFD &fd)
diff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp
index 2189a2466..d9d76c57c 100644
--- a/src/libcamera/ipa_data_serializer.cpp
+++ b/src/libcamera/ipa_data_serializer.cpp
@@ -572,6 +572,7 @@  SharedFD IPADataSerializer<SharedFD>::deserialize(const std::vector<uint8_t> &da
  * 4 byte  - SharedFD
  * 4 bytes - uint32_t Offset
  * 4 bytes - uint32_t Length
+ * 4 bytes - uint32_t Stride
  */
 template<>
 std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
@@ -590,6 +591,7 @@  IPADataSerializer<FrameBuffer::Plane>::serialize(const FrameBuffer::Plane &data,
 
 	appendPOD<uint32_t>(dataVec, data.offset);
 	appendPOD<uint32_t>(dataVec, data.length);
+	appendPOD<uint32_t>(dataVec, data.stride);
 
 	return { dataVec, fdsVec };
 }
@@ -608,6 +610,7 @@  IPADataSerializer<FrameBuffer::Plane>::deserialize(std::vector<uint8_t>::const_i
 							  fdsBegin, fdsBegin + 1);
 	ret.offset = readPOD<uint32_t>(dataBegin, 4, dataEnd);
 	ret.length = readPOD<uint32_t>(dataBegin, 8, dataEnd);
+	ret.stride = readPOD<uint32_t>(dataBegin, 12, dataEnd);
 
 	return ret;
 }