[{"id":4044,"web_url":"https://patchwork.libcamera.org/comment/4044/","msgid":"<20200317105950.GD4864@pendragon.ideasonboard.com>","date":"2020-03-17T10:59:50","subject":"Re: [libcamera-devel] [PATCH v2 4/8] libcamera: pipeline: uvcvideo:\n\tTranslate from V4L2 to DRM pixel formats","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 Tue, Mar 17, 2020 at 04:52:35AM +0100, Niklas Söderlund wrote:\n> When generating a camera configuration pixel formats directly from the\n> video device are used that contains V4L2 pixel formats. Translate the\n> pixel formats to DRM before using them i the camera configuration.\n\ns/them i/them in/\n\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/pipeline/uvcvideo.cpp | 9 ++++++++-\n>  1 file changed, 8 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index 320da2685795c041..14f7ddb18a765834 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -154,7 +154,14 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,\n>  \t\treturn config;\n>  \n>  \tImageFormats v4l2formats = data->video_->formats();\n> -\tStreamFormats formats(v4l2formats.data());\n> +\tstd::map<PixelFormat, std::vector<SizeRange>> deviceformats;\n\ns/deviceformats/deviceFormats/\n\n> +\tfor (const auto &it : v4l2formats.data()) {\n> +\t\tPixelFormat pixelformat = V4L2VideoDevice::toPixelFormat(it.first);\n\ns/pixelformat/pixelFormat/\n\nMaybe data->video_->toPixelFormat(it.first) ?\n\n> +\t\tconst std::vector<SizeRange> &ranges = it.second;\n> +\t\tdeviceformats[pixelformat] = ranges;\n\n\t\tdeviceFormats.emplace(pixelFormat, ranges);\n\nor maybe even\n\n\t\tdeviceFormats.emplace(pixelFormat, it.second);\n\n> +\t}\n\nI'm pretty sure you won't like that, but the C++ way of doing this would\nbe as follows :-)\n\n        std::map<unsigned int, std::vector<SizeRange>> v4l2Formats = data->video_->formats();;\n        std::map<PixelFormat, std::vector<SizeRange>> deviceformats;\n        std::transform(v4l2Formats.begin(), v4l2Formats.end(),\n                       std::inserter(deviceformats, deviceformats.begin()),\n                       [&](const decltype(v4l2Formats)::value_type &format) {\n                               return decltype(deviceformats)::value_type{\n                                       data->video_->toPixelFormat(format.first),\n                                       format.second\n                               };\n                       });\n\nI think I've developed a Stockholm syndrome for C++...\n\nEither way,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\n> +\n> +\tStreamFormats formats(deviceformats);\n>  \tStreamConfiguration cfg(formats);\n>  \n>  \tcfg.pixelFormat = formats.pixelformats().front();","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A0CA560418\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Mar 2020 11:59:55 +0100 (CET)","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 1A411F9;\n\tTue, 17 Mar 2020 11:59:55 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584442795;\n\tbh=MuPo4dZV9SM2CdjSVzaSlF2Vr2y+J7IzgnlHC8jVW7g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DUusJfxbwvPqNKnwLi+k1swUzfBRoPYI9gDlk+kLDip12Wfc1NtUqnI07K5L6alDE\n\taSfg5Gb3E4wTWPcCl+f9V4Ldd1nm+zXG+kNuUSNw4Q2CZEHvh02ZA3ggTv4IYx3jvD\n\tmkv5Tp8WzuVGXa/MEbj8JUW2n8FFMnPaEZJGxN5I=","Date":"Tue, 17 Mar 2020 12:59:50 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200317105950.GD4864@pendragon.ideasonboard.com>","References":"<20200317035239.2697679-1-niklas.soderlund@ragnatech.se>\n\t<20200317035239.2697679-5-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200317035239.2697679-5-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 4/8] libcamera: pipeline: uvcvideo:\n\tTranslate from V4L2 to DRM pixel formats","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>","X-List-Received-Date":"Tue, 17 Mar 2020 10:59:55 -0000"}}]