[{"id":1611,"web_url":"https://patchwork.libcamera.org/comment/1611/","msgid":"<20190517231058.GE4960@pendragon.ideasonboard.com>","date":"2019-05-17T23:10:58","subject":"Re: [libcamera-devel] [PATCH/RFC 11/12] libcamera: pipeline:\n\tuvcvideo: Validate format in UVCCameraConfiguration::validate()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Sat, May 18, 2019 at 02:06:20AM +0300, Laurent Pinchart wrote:\n> From: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> Validate and potentially adjust the requested format with a list of\n> discrete formats retrieved from the video device.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/pipeline/uvcvideo.cpp | 44 ++++++++++++++++++++++++-----\n>  1 file changed, 37 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 286d19b0af01..e02d5b19e82a 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -37,6 +37,7 @@ public:\n>  \n>  \tV4L2Device *video_;\n>  \tStream stream_;\n> +\tStreamFormats formats_;\n>  };\n>  \n>  class UVCCameraConfiguration : public CameraConfiguration\n> @@ -45,6 +46,7 @@ public:\n>  \tUVCCameraConfiguration();\n>  \n>  \tStatus validate() override;\n> +\tStreamFormats formats;\n\nYou can instead store a pointer to the UVCCameraData in\nUVCCameraConfiguration (see the IPU3 or RkISP1 pipeline handlers to see\nhow this should be done), and access the formats from there.\n\n>  };\n>  \n>  class PipelineHandlerUVC : public PipelineHandler\n> @@ -96,21 +98,42 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()\n>  \n>  \tStreamConfiguration &cfg = config_[0];\n>  \n> -\t/* \\todo: Validate the configuration against the device capabilities. */\n>  \tconst unsigned int pixelFormat = cfg.pixelFormat;\n>  \tconst Size size = cfg.size;\n> +\tconst unsigned int bufferCount = cfg.bufferCount;\n>  \n>  \tcfg.pixelFormat = V4L2_PIX_FMT_YUYV;\n> -\tcfg.size = { 640, 480 };\n> +\tif (cfg.pixelFormat != pixelFormat) {\n> +\t\tLOG(UVC, Debug)\n> +\t\t\t<< \"Adjusting pixel format from \" << pixelFormat\n> +\t\t\t<< \" to \" << cfg.pixelFormat;\n> +\t\tstatus = Adjusted;\n> +\t}\n\nWe shouldn't hardcode the format to YUYV but instead support any pixel\nformat supported by the camera (or at the very least both YUYV and\nMJPEG).\n\n>  \n> -\tif (cfg.pixelFormat != pixelFormat || cfg.size != size) {\n> +\tconst std::vector<Size> &formatSizes = formats.sizes(cfg.pixelFormat);\n> +\tcfg.size = formatSizes.front();\n> +\tfor (const Size &formatsSize : formatSizes) {\n> +\t\tif (formatsSize <= size)\n> +\t\t\tcfg.size = formatsSize;\n> +\n> +\t\tif (formatsSize == size)\n> +\t\t\tbreak;\n> +\t}\n> +\n> +\tif (cfg.size != size) {\n>  \t\tLOG(UVC, Debug)\n> -\t\t\t<< \"Adjusting configuration from \" << cfg.toString()\n> -\t\t\t<< \" to \" << cfg.size.toString() << \"-YUYV\";\n> +\t\t\t<< \"Adjusting size from \" << size.toString()\n> +\t\t\t<< \" to \" << cfg.size.toString();\n>  \t\tstatus = Adjusted;\n>  \t}\n>  \n> -\tcfg.bufferCount = 4;\n> +\tif (bufferCount < 4) {\n> +\t\tcfg.bufferCount = 4;\n> +\t\tLOG(UVC, Debug)\n> +\t\t\t<< \"Adjusting buffer count from \" << bufferCount\n> +\t\t\t<< \" to \" << cfg.bufferCount;\n> +\t\tstatus = Adjusted;\n> +\t}\n\nI've left this out for now, with a \\todo in one of the patches to decide\non how to handle buffers count adjustement. Let's not mix it with this\npatc.\n\n>  \n>  \treturn status;\n>  }\n> @@ -123,7 +146,10 @@ PipelineHandlerUVC::PipelineHandlerUVC(CameraManager *manager)\n>  CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,\n>  \tconst StreamRoles &roles)\n>  {\n> -\tCameraConfiguration *config = new UVCCameraConfiguration();\n> +\tUVCCameraData *data = cameraData(camera);\n> +\tUVCCameraConfiguration *config = new UVCCameraConfiguration();\n> +\n> +\tconfig->formats = data->formats_;\n>  \n>  \tif (!roles.empty()) {\n>  \t\tStreamConfiguration cfg{};\n\nShould we pick a default configuration based on the enumerated formats ?\n\n> @@ -242,6 +268,10 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n>  \tif (data->video_->open())\n>  \t\treturn false;\n>  \n> +\tdata->formats_ = StreamFormats(data->video_->enumerateFrameSizes({ V4L2_PIX_FMT_YUYV }));\n\nNo need for the StreamFormats(), is there ?\n\n> +\tfor (const Size &size : data->formats_.sizes(V4L2_PIX_FMT_YUYV))\n> +\t\tLOG(UVC, Info) << size.toString();\n\nThis should be debug messages. Or if you think they're useful as info\nmessages, should we print all resolutions on a single line ?\n\n> +\n>  \tdata->video_->bufferReady.connect(data.get(), &UVCCameraData::bufferReady);\n>  \n>  \t/* Create and register the camera. */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 5EAE360DE9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 May 2019 01:11:15 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C3BDA2F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 May 2019 01:11:14 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1558134674;\n\tbh=gr3HfrE9H70sFLcCi0IvroCT+vEeNg6u643Z2JULWYo=;\n\th=Date:From:To:Subject:References:In-Reply-To:From;\n\tb=CfEVvBGjlDzW6EX3Xyj7HSjOazpMnnuTAzg4QCTO9f2zLLzxLtWmG0Wn0xLCX8jYX\n\tXQcq5Yrx5a1qEZkj7XKcuIOdxshPByxNT23Z8DAbTFg88hWQJbtNOxuM7d/A0aERHL\n\t40yaO1i2jp+w93oV48lysNPeIxbXF+Iwsic9W9X0=","Date":"Sat, 18 May 2019 02:10:58 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190517231058.GE4960@pendragon.ideasonboard.com>","References":"<20190517230621.24668-1-laurent.pinchart@ideasonboard.com>\n\t<20190517230621.24668-12-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190517230621.24668-12-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH/RFC 11/12] libcamera: pipeline:\n\tuvcvideo: Validate format in UVCCameraConfiguration::validate()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Fri, 17 May 2019 23:11:15 -0000"}}]