[{"id":11295,"web_url":"https://patchwork.libcamera.org/comment/11295/","msgid":"<20200709182414.GB4320@pendragon.ideasonboard.com>","date":"2020-07-09T18:24:14","subject":"Re: [libcamera-devel] [PATCH v5 13/23] libcamera: raspberrypi: 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 Thu, Jul 09, 2020 at 10:28:25PM +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\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> Changes in v5:\n> - clean up code a bit\n> - move setting default size and width into separate patch\n> \n> Changes in v4:\n> - mention motivation in commit message\n> - also fill stride and frameSize in the default format\n> \n> New in v3\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 34 +++++++++++++++----\n>  1 file changed, 27 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 1822ac9..a08ad6a 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -427,6 +427,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>  \t\t\t */\n>  \t\t\tV4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats();\n>  \t\t\tV4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size);\n> +\t\t\tint ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat);\n> +\t\t\tif (ret)\n> +\t\t\t\treturn Invalid;\n> +\n>  \t\t\tPixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat();\n>  \t\t\tif (cfg.size != sensorFormat.size ||\n>  \t\t\t    cfg.pixelFormat != sensorPixFormat) {\n> @@ -434,6 +438,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>  \t\t\t\tcfg.pixelFormat = sensorPixFormat;\n>  \t\t\t\tstatus = Adjusted;\n>  \t\t\t}\n> +\n> +\t\t\tcfg.stride = sensorFormat.planes[0].bpl;\n> +\t\t\tcfg.frameSize = sensorFormat.planes[0].size;\n> +\n>  \t\t\trawCount++;\n>  \t\t} else {\n>  \t\t\toutSize[outCount] = std::make_pair(count, cfg.size);\n> @@ -478,19 +486,34 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>  \t\t * have that fixed up in the code above.\n>  \t\t *\n>  \t\t */\n> -\t\tPixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat;\n> -\t\tV4L2PixFmtMap fmts;\n> +\t\tStreamConfiguration &cfg = config_.at(outSize[i].first);\n> +\t\tPixelFormat &cfgPixFmt = cfg.pixelFormat;\n> +\t\tV4L2VideoDevice *dev;\n>  \n>  \t\tif (i == maxIndex)\n> -\t\t\tfmts = data_->isp_[Isp::Output0].dev()->formats();\n> +\t\t\tdev = data_->isp_[Isp::Output0].dev();\n>  \t\telse\n> -\t\t\tfmts = data_->isp_[Isp::Output1].dev()->formats();\n> +\t\t\tdev = data_->isp_[Isp::Output1].dev();\n> +\n> +\t\tV4L2PixFmtMap fmts = dev->formats();\n>  \n>  \t\tif (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) {\n>  \t\t\t/* If we cannot find a native format, use a default one. */\n>  \t\t\tcfgPixFmt = formats::NV12;\n>  \t\t\tstatus = Adjusted;\n>  \t\t}\n> +\n> +\t\tV4L2DeviceFormat format = {};\n> +\t\tformat.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat);\n> +\t\tformat.size = cfg.size;\n> +\n> +\t\tint ret = dev->tryFormat(&format);\n> +\t\tif (ret)\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}\n>  \n>  \treturn status;\n> @@ -655,7 +678,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \n>  \t\tif (isRaw(cfg.pixelFormat)) {\n>  \t\t\tcfg.setStream(&data->isp_[Isp::Input]);\n> -\t\t\tcfg.stride = sensorFormat.planes[0].bpl;\n>  \t\t\tdata->isp_[Isp::Input].setExternal(true);\n>  \t\t\tcontinue;\n>  \t\t}\n> @@ -679,7 +701,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\t\t}\n>  \n>  \t\t\tcfg.setStream(&data->isp_[Isp::Output0]);\n> -\t\t\tcfg.stride = format.planes[0].bpl;\n>  \t\t\tdata->isp_[Isp::Output0].setExternal(true);\n>  \t\t}\n>  \n> @@ -705,7 +726,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>  \t\t */\n>  \t\tif (!cfg.stream()) {\n>  \t\t\tcfg.setStream(&data->isp_[Isp::Output1]);\n> -\t\t\tcfg.stride = format.planes[0].bpl;\n>  \t\t\tdata->isp_[Isp::Output1].setExternal(true);\n>  \t\t}\n>  \t}","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 5748FBD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2020 18:24:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D2D8D61253;\n\tThu,  9 Jul 2020 20:24:23 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C9AE66123A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2020 20:24:21 +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 3597A56E;\n\tThu,  9 Jul 2020 20:24:21 +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=\"uMzAbsvU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594319061;\n\tbh=cPZCtMpJz6vUvC+yLd8LEYi6VsNVTJ64m/GCas2NitQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uMzAbsvU5twCn8sPERemQVQA2x+1BUXmE42xtNi/cx15uvlHVmkjRMc+HvNzLweUg\n\t5oEtbMN3HdDQUvgz8wYfK6df3Sp/mp0GVRrs/YrHk3vskNW4QqlQzhSBZqgidRpx+2\n\tsTPJ2iHiSDhxmOen5MIwrM+zU7WhG5iqftCh8YHY=","Date":"Thu, 9 Jul 2020 21:24:14 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Message-ID":"<20200709182414.GB4320@pendragon.ideasonboard.com>","References":"<20200709132835.112593-1-paul.elder@ideasonboard.com>\n\t<20200709132835.112593-14-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200709132835.112593-14-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v5 13/23] libcamera: raspberrypi: 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":11305,"web_url":"https://patchwork.libcamera.org/comment/11305/","msgid":"<CAEmqJPob8g3eDFOM02BAXv17TMObOOqtXGhaj4Y2YfcL88JDSg@mail.gmail.com>","date":"2020-07-10T06:56:59","subject":"Re: [libcamera-devel] [PATCH v5 13/23] libcamera: raspberrypi: Fill\n\tstride and frameSize at config validation","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Thu, 9 Jul 2020 at 14:29, Paul Elder <paul.elder@ideasonboard.com> wrote:\n>\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\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n>\n> ---\n> Changes in v5:\n> - clean up code a bit\n> - move setting default size and width into separate patch\n>\n> Changes in v4:\n> - mention motivation in commit message\n> - also fill stride and frameSize in the default format\n>\n> New in v3\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 34 +++++++++++++++----\n>  1 file changed, 27 insertions(+), 7 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 1822ac9..a08ad6a 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -427,6 +427,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                          */\n>                         V4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats();\n>                         V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size);\n> +                       int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat);\n> +                       if (ret)\n> +                               return Invalid;\n> +\n>                         PixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat();\n>                         if (cfg.size != sensorFormat.size ||\n>                             cfg.pixelFormat != sensorPixFormat) {\n> @@ -434,6 +438,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                                 cfg.pixelFormat = sensorPixFormat;\n>                                 status = Adjusted;\n>                         }\n> +\n> +                       cfg.stride = sensorFormat.planes[0].bpl;\n> +                       cfg.frameSize = sensorFormat.planes[0].size;\n> +\n>                         rawCount++;\n>                 } else {\n>                         outSize[outCount] = std::make_pair(count, cfg.size);\n> @@ -478,19 +486,34 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n>                  * have that fixed up in the code above.\n>                  *\n>                  */\n> -               PixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat;\n> -               V4L2PixFmtMap fmts;\n> +               StreamConfiguration &cfg = config_.at(outSize[i].first);\n> +               PixelFormat &cfgPixFmt = cfg.pixelFormat;\n> +               V4L2VideoDevice *dev;\n>\n>                 if (i == maxIndex)\n> -                       fmts = data_->isp_[Isp::Output0].dev()->formats();\n> +                       dev = data_->isp_[Isp::Output0].dev();\n>                 else\n> -                       fmts = data_->isp_[Isp::Output1].dev()->formats();\n> +                       dev = data_->isp_[Isp::Output1].dev();\n> +\n> +               V4L2PixFmtMap fmts = dev->formats();\n>\n>                 if (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) {\n>                         /* If we cannot find a native format, use a default one. */\n>                         cfgPixFmt = formats::NV12;\n>                         status = Adjusted;\n>                 }\n> +\n> +               V4L2DeviceFormat format = {};\n> +               format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat);\n> +               format.size = cfg.size;\n> +\n> +               int ret = dev->tryFormat(&format);\n> +               if (ret)\n> +                       return Invalid;\n> +\n> +               cfg.stride = format.planes[0].bpl;\n> +               cfg.frameSize = format.planes[0].size;\n> +\n>         }\n>\n>         return status;\n> @@ -655,7 +678,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>\n>                 if (isRaw(cfg.pixelFormat)) {\n>                         cfg.setStream(&data->isp_[Isp::Input]);\n> -                       cfg.stride = sensorFormat.planes[0].bpl;\n>                         data->isp_[Isp::Input].setExternal(true);\n>                         continue;\n>                 }\n> @@ -679,7 +701,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>                         }\n>\n>                         cfg.setStream(&data->isp_[Isp::Output0]);\n> -                       cfg.stride = format.planes[0].bpl;\n>                         data->isp_[Isp::Output0].setExternal(true);\n>                 }\n>\n> @@ -705,7 +726,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n>                  */\n>                 if (!cfg.stream()) {\n>                         cfg.setStream(&data->isp_[Isp::Output1]);\n> -                       cfg.stride = format.planes[0].bpl;\n>                         data->isp_[Isp::Output1].setExternal(true);\n>                 }\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 CC1BBBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Jul 2020 07:04:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6305261253;\n\tFri, 10 Jul 2020 09:04:44 +0200 (CEST)","from mail-lj1-x241.google.com (mail-lj1-x241.google.com\n\t[IPv6:2a00:1450:4864:20::241])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 32322603A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jul 2020 09:04:42 +0200 (CEST)","by mail-lj1-x241.google.com with SMTP id d17so5254280ljl.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Jul 2020 00:04:42 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"EA6S1Ywg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=fss6j8Iu3pRjnuPPSizfix9c5xtAQklYnbLLLXC/xk0=;\n\tb=EA6S1YwgCMmdiOj1rZN9i2s0AG3YDTqZqgiJL7y6q3ahfXgLhQnOLdRJk7Ar3LME7n\n\tjBdvRGfrw8512e+gnCr1YUGDSdj/89ox1sUx/Jw4H6Ec/qSYtIHz9OD4nKL4Dj2Uwu4J\n\tFGs+Q5+Yg0g97u3kK0AzkJoVeeOxCBJ+HvdjPNwNRUYnD2RR1GhP3iMHbKcwDjJAWUvI\n\tTAUcZXJO3sp4dCzp61uZ6lwp9w79tzXLniH7CY0FsQqiW/9c9G5P5xndgjXLxKm0hJ/7\n\tM1rGWXXwKem1EzTxD05E87ra0nB5iOYFNXOTZYbpzFd7kPG5j6suNyTtbineOFXhqrQL\n\tfPFA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=fss6j8Iu3pRjnuPPSizfix9c5xtAQklYnbLLLXC/xk0=;\n\tb=TzGmCbhhvtrjJJxXQhyJBDAWJzwevups2M4L1IDk7YHsK2uSCV8dbP1XojRl/IiHYO\n\tNvEkSltyRcgNMUNHLgNlGVvyf1edh1bO5/8QKx6pGUy9JSt1jNWDKj+wHtnQnpIyemYR\n\t0gD2IORX3h0K0kCiu0B3uybtku4UcLYt6MGUH72KexSj2oXD4kF7b3yN+enSy6uMGKRm\n\tDrChh9qmE+xhKMtiifLTtgp+KPTX5mgj6jVe1okJEiUHxVtZqp9mQ5t/K70x5Fo2KwS4\n\tLR2QE+cfexaOnw5wmXT4DEJHh9cxKqzE0H8+1UydesbDyGSXRN11aKaG5HzwdOzdAIA0\n\tTfqw==","X-Gm-Message-State":"AOAM532VMOSUeIOrrK/xZ9pwq1i4Wsbbyd57QkcK7ubCLlbso+QZtzup\n\t9B8WH8rQbdBzADYK9VmEzZhK1/bwRykJJk+aLLEWvK5K","X-Google-Smtp-Source":"ABdhPJzsWMDvv9A6NME+TdivG18m1L44moBlDA/NQnrjWJzPDCGwzWGfZ05WS78scs/ynYlBZl4WzJbsIfX17JJKvpQ=","X-Received":"by 2002:a2e:a30f:: with SMTP id\n\tl15mr39091364lje.228.1594364236288; \n\tThu, 09 Jul 2020 23:57:16 -0700 (PDT)","MIME-Version":"1.0","References":"<20200709132835.112593-1-paul.elder@ideasonboard.com>\n\t<20200709132835.112593-14-paul.elder@ideasonboard.com>","In-Reply-To":"<20200709132835.112593-14-paul.elder@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 10 Jul 2020 07:56:59 +0100","Message-ID":"<CAEmqJPob8g3eDFOM02BAXv17TMObOOqtXGhaj4Y2YfcL88JDSg@mail.gmail.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v5 13/23] libcamera: raspberrypi: 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>"}}]