[libcamera-devel,08/10] android: jpeg: Use maxJpegBufferSize() for compatibility
diff mbox series

Message ID 20210301150111.61791-9-jacopo@jmondi.org
State Superseded
Headers show
Series
  • Support memory backends
Related show

Commit Message

Jacopo Mondi March 1, 2021, 3:01 p.m. UTC
Platforms that do not provide a memory backend implementation should
keep using the maxJpegBufferSize() value to calculate the location where
to place the JPEG blob id, as the android_generic backend returns the
allocated buffer size as calculated using lseek which is larger than
the maximum JPEG frame size, which is where the framework expects the
JPEG blob to be placed.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/jpeg/post_processor_jpeg.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
index 83244ce6769e..65ab6b196ad1 100644
--- a/src/android/jpeg/post_processor_jpeg.cpp
+++ b/src/android/jpeg/post_processor_jpeg.cpp
@@ -182,8 +182,16 @@  int PostProcessorJpeg::process(const FrameBuffer &source,
 	}
 
 	/* Fill in the JPEG blob header. */
-	uint8_t *resultPtr = destination->plane(0).data()
-			   + destination->plane(0).size()
+	/*
+	 * \todo For backward compatibility reasons with the android_generic
+	 * memory backend, continue using the maxJpegBufferSize in case the
+	 * computed buffer size is larger. This can be dropped once all
+	 * supported platforms will have a working memory backend that
+	 * returns the correct buffer size.
+	 */
+	size_t blobSize = std::min<unsigned int>(cameraDevice_->maxJpegBufferSize(),
+						 destination->plane(0).size());
+	uint8_t *resultPtr = destination->plane(0).data() + blobSize
 			   - sizeof(struct camera3_jpeg_blob);
 	auto *blob = reinterpret_cast<struct camera3_jpeg_blob *>(resultPtr);
 	blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;