[{"id":19096,"web_url":"https://patchwork.libcamera.org/comment/19096/","msgid":"<YSeRnUugYPozwWSR@pendragon.ideasonboard.com>","date":"2021-08-26T13:05:33","subject":"Re: [libcamera-devel] [PATCH v3 8/9] android: camera_device: Fill\n\toffset and right length in CreateFrameBuffer()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Thu, Aug 26, 2021 at 08:25:38PM +0900, Hirokazu Honda wrote:\n> CameraDevice::CreateFrameBuffer() fills the length of the buffer to\n> each FrameBuffer::Plane::length. It should rather be the length of\n> plane. This also changes CreateFrameBuffer() to fill offset of\n> FrameBuffer::Plane.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/android/camera_device.cpp | 52 +++++++++++++++++++++--------------\n>  src/android/camera_device.h   |  6 +++-\n>  2 files changed, 37 insertions(+), 21 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index a69b687a..4702b332 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -12,6 +12,7 @@\n>  \n>  #include <algorithm>\n>  #include <fstream>\n> +#include <sys/mman.h>\n>  #include <unistd.h>\n>  #include <vector>\n>  \n> @@ -744,31 +745,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)\n>  \treturn 0;\n>  }\n>  \n> -FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer)\n> +FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer,\n> +\t\t\t\t\t     libcamera::PixelFormat pixelFormat,\n> +\t\t\t\t\t     const libcamera::Size &size)\n>  {\n> -\tstd::vector<FrameBuffer::Plane> planes;\n> +\tFileDescriptor fd;\n> +\t/*\n> +\t * This assumes all the planes are in the same dmabuf.\n> +\t *\n> +         * \\todo Verify that this assumption holds, fstat() can be used to check\n> +         * if two fds refer to the same dmabuf.\n\nTabs for indentation. I can fix this when pushing the series.\n\n> +\t */\n>  \tfor (int i = 0; i < camera3buffer->numFds; i++) {\n> -\t\t/* Skip unused planes. */\n> -\t\tif (camera3buffer->data[i] == -1)\n> +\t\tif (camera3buffer->data[i] != -1) {\n> +\t\t\tfd = FileDescriptor(camera3buffer->data[i]);\n>  \t\t\tbreak;\n> -\n> -\t\tFrameBuffer::Plane plane;\n> -\t\tplane.fd = FileDescriptor(camera3buffer->data[i]);\n> -\t\tif (!plane.fd.isValid()) {\n> -\t\t\tLOG(HAL, Error) << \"Failed to obtain FileDescriptor (\"\n> -\t\t\t\t\t<< camera3buffer->data[i] << \") \"\n> -\t\t\t\t\t<< \" on plane \" << i;\n> -\t\t\treturn nullptr;\n>  \t\t}\n> +\t}\n>  \n> -\t\toff_t length = lseek(plane.fd.fd(), 0, SEEK_END);\n> -\t\tif (length == -1) {\n> -\t\t\tLOG(HAL, Error) << \"Failed to query plane length\";\n> -\t\t\treturn nullptr;\n> -\t\t}\n> +\tif (!fd.isValid()) {\n> +\t\tLOG(HAL, Fatal) << \"No valid fd\";\n> +\t\treturn nullptr;\n> +\t}\n> +\n> +\tCameraBuffer buf(camera3buffer, pixelFormat, size, PROT_READ);\n> +\tif (!buf.isValid()) {\n> +\t\tLOG(HAL, Fatal) << \"Failed to create CameraBuffer\";\n> +\t\treturn nullptr;\n> +\t}\n>  \n> -\t\tplane.length = length;\n> -\t\tplanes.push_back(std::move(plane));\n> +\tstd::vector<FrameBuffer::Plane> planes(buf.numPlanes());\n> +\tfor (size_t i = 0; i < buf.numPlanes(); ++i) {\n> +\t\tplanes[i].fd = fd;\n> +\t\tplanes[i].offset = buf.offset(i);\n> +\t\tplanes[i].length = buf.size(i);\n>  \t}\n>  \n>  \treturn new FrameBuffer(std::move(planes));\n> @@ -976,7 +986,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>  \t\t\t * associate it with the Camera3RequestDescriptor for\n>  \t\t\t * lifetime management only.\n>  \t\t\t */\n> -\t\t\tbuffer = createFrameBuffer(*camera3Buffer.buffer);\n> +\t\t\tbuffer = createFrameBuffer(*camera3Buffer.buffer,\n> +\t\t\t\t\t\t   cameraStream->configuration().pixelFormat,\n> +\t\t\t\t\t\t   cameraStream->configuration().size);\n>  \t\t\tdescriptor.frameBuffers_.emplace_back(buffer);\n>  \t\t\tLOG(HAL, Debug) << ss.str() << \" (direct)\";\n>  \t\t\tbreak;\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index dd9aebba..a5576927 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -21,6 +21,8 @@\n>  \n>  #include <libcamera/camera.h>\n>  #include <libcamera/framebuffer.h>\n> +#include <libcamera/geometry.h>\n> +#include <libcamera/pixel_format.h>\n>  #include <libcamera/request.h>\n>  #include <libcamera/stream.h>\n>  \n> @@ -91,7 +93,9 @@ private:\n>  \n>  \tvoid stop();\n>  \n> -\tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);\n> +\tlibcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer,\n> +\t\t\t\t\t\t  libcamera::PixelFormat pixelFormat,\n> +\t\t\t\t\t\t  const libcamera::Size &size);\n>  \tvoid abortRequest(camera3_capture_request_t *request);\n>  \tbool isValidRequest(camera3_capture_request_t *request) const;\n>  \tvoid notifyShutter(uint32_t frameNumber, uint64_t timestamp);","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D8EAFBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Aug 2021 13:05:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F33B68922;\n\tThu, 26 Aug 2021 15:05:47 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE2D768915\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 15:05:45 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 639B3191F;\n\tThu, 26 Aug 2021 15:05:45 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WcKtia1W\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629983145;\n\tbh=kzM7R6btUNuSinXb4Gpo5LgYxu9RAOdevMoJONwI2Ps=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=WcKtia1W0Po83x1thTcbjpkZ5MAnt6sVZzFCwI8+BO3QDk9Moenws/npz/KDjxGn0\n\tDDe32vjQhqXvdL76eTZB+nYpNkala8u8z4lCTbQPwzsvUmuOtnIe/GDVgvsCK1CpGn\n\tnyi3h886YXSGayxmqdLS6QBGE9ty8v5nbWFLGSgw=","Date":"Thu, 26 Aug 2021 16:05:33 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YSeRnUugYPozwWSR@pendragon.ideasonboard.com>","References":"<20210826112539.170694-1-hiroh@chromium.org>\n\t<20210826112539.170694-9-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210826112539.170694-9-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v3 8/9] android: camera_device: Fill\n\toffset and right length in CreateFrameBuffer()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]