[{"id":11251,"web_url":"https://patchwork.libcamera.org/comment/11251/","msgid":"<20200708152555.GH20298@pendragon.ideasonboard.com>","date":"2020-07-08T15:25:55","subject":"Re: [libcamera-devel] [PATCH v4 17/21] 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 Wed, Jul 08, 2020 at 10:44:13PM +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> This allows applications to get the stride when trying a configuration\n> without modifying the active configuration of the camera.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> Changes in v4:\n> - fix converter's stride and frameSize (get it via tryFormat instead of\n>   calculation)\n> - merge converter's stride and frameSize to one function\n> - return error if tryFormat fails\n> - mention motivation in commit message\n> \n> New in v3\n> ---\n>  src/libcamera/pipeline/simple/converter.cpp | 19 +++++++++++++++\n>  src/libcamera/pipeline/simple/converter.h   |  4 +++\n>  src/libcamera/pipeline/simple/simple.cpp    | 27 +++++++++++++++++++--\n>  3 files changed, 48 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\n> index e5e2f0f..cef1503 100644\n> --- a/src/libcamera/pipeline/simple/converter.cpp\n> +++ b/src/libcamera/pipeline/simple/converter.cpp\n> @@ -261,4 +261,23 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer)\n>  \t}\n>  }\n>  \n> +int SimpleConverter::strideAndFrameSize(const Size &size,\n> +\t\t\t\t\tconst PixelFormat &pixelFormat,\n> +\t\t\t\t\tunsigned int *strideOut,\n> +\t\t\t\t\tunsigned int *frameSizeOut)\n> +{\n> +\tV4L2DeviceFormat format = {};\n> +\tformat.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat);\n> +\tformat.size = size;\n> +\n> +\tint ret = m2m_->capture()->tryFormat(&format);\n> +\tif (ret < 0)\n> +\t\treturn -1;\n> +\n> +\t*strideOut = format.planes[0].bpl;\n> +\t*frameSizeOut = format.planes[0].size;\n> +\n> +\treturn 0;\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..3e46988 100644\n> --- a/src/libcamera/pipeline/simple/converter.h\n> +++ b/src/libcamera/pipeline/simple/converter.h\n> @@ -46,6 +46,10 @@ public:\n>  \n>  \tint queueBuffers(FrameBuffer *input, FrameBuffer *output);\n>  \n> +\tint strideAndFrameSize(const Size &size, const PixelFormat &pixelFormat,\n> +\t\t\t       unsigned int *strideOut,\n> +\t\t\t       unsigned int *frameSizeOut);\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..0c52b47 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -457,6 +457,31 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>  \n>  \tcfg.bufferCount = 3;\n>  \n> +\n\nOne blank line is enough.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t/* Set the stride and frameSize. */\n> +\tif (!needConversion_) {\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\treturn Invalid;\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> +\tSimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(data_->pipe_);\n> +\tSimpleConverter *converter = pipe->converter();\n> +\n> +\tint ret = converter->strideAndFrameSize(cfg.size, cfg.pixelFormat,\n> +\t\t\t\t\t\t&cfg.stride, &cfg.frameSize);\n> +\tif (ret < 0)\n> +\t\treturn Invalid;\n> +\n>  \treturn status;\n>  }\n>  \n> @@ -557,8 +582,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 C36BFBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jul 2020 15:26:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A8EF6113A;\n\tWed,  8 Jul 2020 17:26:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DD22E61138\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jul 2020 17:26:03 +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 F3049543;\n\tWed,  8 Jul 2020 17:26:02 +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=\"V6U+jKCI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594221963;\n\tbh=WUTQzwd3cBDWHTMgWMm8hRMJIXOzJY74R55eZJ2B6iA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=V6U+jKCIYryKjgOG+Ms1BGCIdaTW2ZBSbxAO9Wfv7YgWXH2MDX9mi4RikL8tQY1BT\n\t42pRioW4DTLtCSbENJ1r3edjJ/1qTuR59OzZZSJbpkrfQutmdq2tC3ETfNKk6lcrDa\n\tkPSoRqrqznF/HC0GNXQbZ2oViOO9mpWul1dQSgiQ=","Date":"Wed, 8 Jul 2020 18:25:55 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200708152555.GH20298@pendragon.ideasonboard.com>","References":"<20200708134417.67747-1-paul.elder@ideasonboard.com>\n\t<20200708134417.67747-18-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200708134417.67747-18-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 17/21] 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>"}},{"id":11267,"web_url":"https://patchwork.libcamera.org/comment/11267/","msgid":"<20200708214018.lomt7hz2hc4pnrzr@uno.localdomain>","date":"2020-07-08T21:40:18","subject":"Re: [libcamera-devel] [PATCH v4 17/21] libcamera: simple: Fill\n\tstride and frameSize at config validation","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"On Wed, Jul 08, 2020 at 10:44:13PM +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> This allows applications to get the stride when trying a configuration\n> without modifying the active configuration of the camera.\n>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n>\n> ---\n> Changes in v4:\n> - fix converter's stride and frameSize (get it via tryFormat instead of\n>   calculation)\n> - merge converter's stride and frameSize to one function\n> - return error if tryFormat fails\n> - mention motivation in commit message\n>\n> New in v3\n> ---\n>  src/libcamera/pipeline/simple/converter.cpp | 19 +++++++++++++++\n>  src/libcamera/pipeline/simple/converter.h   |  4 +++\n>  src/libcamera/pipeline/simple/simple.cpp    | 27 +++++++++++++++++++--\n>  3 files changed, 48 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\n> index e5e2f0f..cef1503 100644\n> --- a/src/libcamera/pipeline/simple/converter.cpp\n> +++ b/src/libcamera/pipeline/simple/converter.cpp\n> @@ -261,4 +261,23 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer)\n>  \t}\n>  }\n>\n> +int SimpleConverter::strideAndFrameSize(const Size &size,\n> +\t\t\t\t\tconst PixelFormat &pixelFormat,\n> +\t\t\t\t\tunsigned int *strideOut,\n> +\t\t\t\t\tunsigned int *frameSizeOut)\n> +{\n> +\tV4L2DeviceFormat format = {};\n> +\tformat.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat);\n> +\tformat.size = size;\n> +\n> +\tint ret = m2m_->capture()->tryFormat(&format);\n> +\tif (ret < 0)\n> +\t\treturn -1;\n> +\n> +\t*strideOut = format.planes[0].bpl;\n> +\t*frameSizeOut = format.planes[0].size;\n> +\n> +\treturn 0;\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..3e46988 100644\n> --- a/src/libcamera/pipeline/simple/converter.h\n> +++ b/src/libcamera/pipeline/simple/converter.h\n> @@ -46,6 +46,10 @@ public:\n>\n>  \tint queueBuffers(FrameBuffer *input, FrameBuffer *output);\n>\n> +\tint strideAndFrameSize(const Size &size, const PixelFormat &pixelFormat,\n> +\t\t\t       unsigned int *strideOut,\n> +\t\t\t       unsigned int *frameSizeOut);\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..0c52b47 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -457,6 +457,31 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n>\n>  \tcfg.bufferCount = 3;\n>\n> +\n> +\t/* Set the stride and frameSize. */\n> +\tif (!needConversion_) {\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\treturn Invalid;\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> +\tSimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(data_->pipe_);\n> +\tSimpleConverter *converter = pipe->converter();\n> +\n> +\tint ret = converter->strideAndFrameSize(cfg.size, cfg.pixelFormat,\n> +\t\t\t\t\t\t&cfg.stride, &cfg.frameSize);\n\nIf you want to feel adventurous you can return a tuple and use\nstd::tie instead of two output parameters\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> +\tif (ret < 0)\n> +\t\treturn Invalid;\n> +\n>  \treturn status;\n>  }\n>\n> @@ -557,8 +582,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>\n> --\n> 2.27.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 8FF19BD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Jul 2020 21:36:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2080261179;\n\tWed,  8 Jul 2020 23:36:46 +0200 (CEST)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 81CD761163\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Jul 2020 23:36:44 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C2B44E0004;\n\tWed,  8 Jul 2020 21:36:43 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 8 Jul 2020 23:40:18 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200708214018.lomt7hz2hc4pnrzr@uno.localdomain>","References":"<20200708134417.67747-1-paul.elder@ideasonboard.com>\n\t<20200708134417.67747-18-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200708134417.67747-18-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4 17/21] 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>"}}]