[{"id":11182,"web_url":"https://patchwork.libcamera.org/comment/11182/","msgid":"<20200704215849.GI10773@pendragon.ideasonboard.com>","date":"2020-07-04T21:58:49","subject":"Re: [libcamera-devel] [PATCH v3 19/22] libcamera: simple: Fill\n\tstride and frameSize at config validation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Sat, Jul 04, 2020 at 10:31:37PM +0900, Paul Elder wrote:\n> Fill the stride and frameSize fields of the StreamConfiguration at\n> configuration validation time instead of at camera configuration time.\n\nYou may want to explain why this is desired (same for patch 16/22 to\n18/22). Just mentioning that it allows applications to get the stride\nwhen trying a configuration without modifying the active configuration\nof the camera should be enough.\n\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> New in v3\n> ---\n>  src/libcamera/pipeline/simple/converter.cpp | 14 +++++++++++\n>  src/libcamera/pipeline/simple/converter.h   |  5 ++++\n>  src/libcamera/pipeline/simple/simple.cpp    | 28 +++++++++++++++++++--\n>  3 files changed, 45 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\n> index e5e2f0f..a015e8e 100644\n> --- a/src/libcamera/pipeline/simple/converter.cpp\n> +++ b/src/libcamera/pipeline/simple/converter.cpp\n> @@ -261,4 +261,18 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer)\n>  \t}\n>  }\n>  \n> +unsigned int SimpleConverter::stride(const Size &size,\n> +\t\t\t\t     const PixelFormat &pixelFormat) const\n> +{\n> +\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n> +\treturn info.stride(size.width, 0);\n\nThis (and frameSize) should come from tryFormat() on the V4L2 capture\ndevice of the converter.\n\n> +}\n> +\n> +unsigned int SimpleConverter::frameSize(const Size &size,\n> +\t\t\t\t\tconst PixelFormat &pixelFormat) const\n> +{\n> +\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n> +\treturn info.frameSize(size);\n> +}\n> +\n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h\n> index ef18cf7..0696b8f 100644\n> --- a/src/libcamera/pipeline/simple/converter.h\n> +++ b/src/libcamera/pipeline/simple/converter.h\n> @@ -46,6 +46,11 @@ public:\n>  \n>  \tint queueBuffers(FrameBuffer *input, FrameBuffer *output);\n>  \n> +\tunsigned int stride(const Size &size,\n> +\t\t\t    const PixelFormat &pixelFormat) const;\n> +\tunsigned int frameSize(const Size &size,\n> +\t\t\t       const PixelFormat &pixelFormat) const;\n\nYou may want to turn these two in a single function as they're always\ncalled together (and also because stride and frameSize are not\nindependent, as explained in the review of previous patches).\n\n> +\n>  \tSignal<FrameBuffer *, FrameBuffer *> bufferReady;\n>  \n>  private:\n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 1ec8d0f..39a29a7 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -457,6 +457,32 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>  \n>  \tcfg.bufferCount = 3;\n>  \n> +\tSimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(data_->pipe_);\n> +\tSimpleConverter *converter = pipe->converter();\n> +\n> +\t/* Set the stride and frameSize. */\n> +\tif (!converter) {\n\nEven if there's a converter, if may not be used for this particular\nconfiguration. You should check\n\n\tif (!needConversion_) {\n\ninstead. You can then move the pipe and converter variables below.\n\n> +\t\tV4L2DeviceFormat format = {};\n> +\t\tformat.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);\n> +\t\tformat.size = cfg.size;\n> +\n> +\t\tint ret = data_->video_->tryFormat(&format);\n> +\t\tif (ret < 0) {\n> +\t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n> +\t\t\tcfg.stride = info.stride(cfg.size.width, 0);\n> +\t\t\tcfg.frameSize = info.frameSize(cfg.size);\n> +\t\t\treturn status;\n\nIf tryFormat() fails I think you should just return an error, there's no\npoint in continuing if the kernel fails on us here.\n\n> +\t\t}\n> +\n> +\t\tcfg.stride = format.planes[0].bpl;\n> +\t\tcfg.frameSize = format.planes[0].size;\n> +\n> +\t\treturn status;\n> +\t}\n> +\n> +\tcfg.stride = converter->stride(cfg.size, cfg.pixelFormat);\n> +\tcfg.frameSize = converter->frameSize(cfg.size, cfg.pixelFormat);\n> +\n>  \treturn status;\n>  }\n>  \n> @@ -557,8 +583,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> -\tcfg.stride = captureFormat.planes[0].bpl;\n> -\n>  \t/* Configure the converter if required. */\n>  \tuseConverter_ = config->needConversion();\n>","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 53C60BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  4 Jul 2020 21:58:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E1CAF60E05;\n\tSat,  4 Jul 2020 23:58:53 +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 665FD609C7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Jul 2020 23:58:53 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E0A78296;\n\tSat,  4 Jul 2020 23:58:52 +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=\"U8zbxLSU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593899933;\n\tbh=H4Bbt74wDJw9MofHZNzKDIxdl1rh98ImrXtff1e0PYU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=U8zbxLSUed0rOK9ixpKs3ni6uE0kI4DJX6WbhbxCNwKJtOiJRMBq/XLwdTNdkBltN\n\tfsbArjdGLQnhb9INnHLwIVy/C0hoKTROfaYSLji0TkVE3hTbksgjuYBndgJf+zNjBJ\n\tgANVNKVPzlFXXzgNZvZg+q5A+ga1AlIE2HpNDJfw=","Date":"Sun, 5 Jul 2020 00:58:49 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200704215849.GI10773@pendragon.ideasonboard.com>","References":"<20200704133140.1738660-1-paul.elder@ideasonboard.com>\n\t<20200704133140.1738660-20-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200704133140.1738660-20-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 19/22] libcamera: simple: Fill\n\tstride and frameSize at config validation","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","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]