{"id":8505,"url":"https://patchwork.libcamera.org/api/1.1/patches/8505/?format=json","web_url":"https://patchwork.libcamera.org/patch/8505/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200629151411.216477-7-paul.elder@ideasonboard.com>","date":"2020-06-29T15:14:11","name":"[libcamera-devel,6/6] v4l2: v4l2_camera_proxy: Use libcamera formats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"64023a86a1eb571f447c4dc1905bfdb1f6448141","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8505/mbox/","series":[{"id":1056,"url":"https://patchwork.libcamera.org/api/1.1/series/1056/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1056","date":"2020-06-29T15:14:05","name":"Move formats from v4l2-compat into libcamera","version":1,"mbox":"https://patchwork.libcamera.org/series/1056/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8505/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8505/checks/","tags":{},"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 1D49CBFFE2\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Jun 2020 15:14:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D1C7E609DB;\n\tMon, 29 Jun 2020 17:14:36 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C49F603B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2020 17:14:34 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 414E3299;\n\tMon, 29 Jun 2020 17:14:31 +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=\"byHQX/5X\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593443673;\n\tbh=a1kQ2Qhnudlq7IfVoZ7DTM0MgafcnQ8k5bpI83qIHmo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=byHQX/5XSwGFcgYyskuCUK1Ao2dydC6PO4TH8UD8Wc7t+P9yMcrnpjhRoHaCR6Qz4\n\tfEjQPpKZwRvhDT0pDdJR2DwDV2NzexZ0KTa8lCmADPfaYDRGSkmjHV3K/MlZY4kst+\n\t4fB9C4DNT71V5KAb/8fwkBSxu5myqGzt7nQkMWLM=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 30 Jun 2020 00:14:11 +0900","Message-Id":"<20200629151411.216477-7-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200629151411.216477-1-paul.elder@ideasonboard.com>","References":"<20200629151411.216477-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 6/6] v4l2: v4l2_camera_proxy: Use\n\tlibcamera 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>","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>"},"content":"Now that calculation of bytes per line, image size, and conversions to\nand from v4l2 and drm formats have been moved into libcamera core,\nremoved them from V4L2CameraProxy. This has a positive side-effect of\ncleaning up the code.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/v4l2/v4l2_camera_proxy.cpp | 167 +++++++--------------------------\n src/v4l2/v4l2_camera_proxy.h   |   7 --\n 2 files changed, 36 insertions(+), 138 deletions(-)","diff":"diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex c246570..0869797 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -20,6 +20,7 @@\n #include <libcamera/formats.h>\n #include <libcamera/object.h>\n \n+#include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/log.h\"\n #include \"libcamera/internal/utils.h\"\n \n@@ -164,22 +165,21 @@ bool V4L2CameraProxy::validateMemoryType(uint32_t memory)\n \n void V4L2CameraProxy::setFmtFromConfig(StreamConfiguration &streamConfig)\n {\n-\tcurV4L2Format_.fmt.pix.width = streamConfig.size.width;\n-\tcurV4L2Format_.fmt.pix.height = streamConfig.size.height;\n-\tcurV4L2Format_.fmt.pix.pixelformat = drmToV4L2(streamConfig.pixelFormat);\n-\tcurV4L2Format_.fmt.pix.field = V4L2_FIELD_NONE;\n-\tcurV4L2Format_.fmt.pix.bytesperline =\n-\t\tbplMultiplier(curV4L2Format_.fmt.pix.pixelformat) *\n-\t\tcurV4L2Format_.fmt.pix.width;\n-\tcurV4L2Format_.fmt.pix.sizeimage =\n-\t\timageSize(curV4L2Format_.fmt.pix.pixelformat,\n-\t\t\t  curV4L2Format_.fmt.pix.width,\n-\t\t\t  curV4L2Format_.fmt.pix.height);\n-\tcurV4L2Format_.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;\n-\tcurV4L2Format_.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;\n-\tcurV4L2Format_.fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;\n+\tPixelFormatInfo formatInfo = PixelFormatInfo::info(streamConfig.pixelFormat);\n+\tunsigned int width = streamConfig.size.width;\n+\tunsigned int height = streamConfig.size.height;\n+\n+\tcurV4L2Format_.fmt.pix.width        = width;\n+\tcurV4L2Format_.fmt.pix.height       = height;\n+\tcurV4L2Format_.fmt.pix.pixelformat  = formatInfo.v4l2Format;\n+\tcurV4L2Format_.fmt.pix.field        = V4L2_FIELD_NONE;\n+\tcurV4L2Format_.fmt.pix.bytesperline = formatInfo.bytesPerLine(width);\n+\tcurV4L2Format_.fmt.pix.sizeimage    = formatInfo.imageSize(width, height);\n+\tcurV4L2Format_.fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;\n+\tcurV4L2Format_.fmt.pix.priv         = V4L2_PIX_FMT_PRIV_MAGIC;\n+\tcurV4L2Format_.fmt.pix.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;\n \tcurV4L2Format_.fmt.pix.quantization = V4L2_QUANTIZATION_DEFAULT;\n-\tcurV4L2Format_.fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT;\n+\tcurV4L2Format_.fmt.pix.xfer_func    = V4L2_XFER_FUNC_DEFAULT;\n }\n \n unsigned int V4L2CameraProxy::calculateSizeImage(StreamConfiguration &streamConfig)\n@@ -188,9 +188,11 @@ unsigned int V4L2CameraProxy::calculateSizeImage(StreamConfiguration &streamConf\n \t * \\todo Merge this method with setFmtFromConfig (need imageSize to\n \t * support all libcamera formats first, or filter out MJPEG for now).\n \t */\n-\treturn imageSize(drmToV4L2(streamConfig.pixelFormat),\n-\t\t\t streamConfig.size.width,\n-\t\t\t streamConfig.size.height);\n+\tPixelFormatInfo formatInfo = PixelFormatInfo::info(streamConfig.pixelFormat);\n+\tunsigned int width = streamConfig.size.width;\n+\tunsigned int height = streamConfig.size.height;\n+\n+\treturn formatInfo.imageSize(width, height);\n }\n \n void V4L2CameraProxy::querycap(std::shared_ptr<Camera> camera)\n@@ -253,12 +255,13 @@ int V4L2CameraProxy::vidioc_enum_framesizes(V4L2CameraFile *file, struct v4l2_fr\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing vidioc_enum_framesizes fd = \" << file->efd();\n \n-\tPixelFormat argFormat = v4l2ToDrm(arg->pixel_format);\n+\tV4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->pixel_format);\n+\tPixelFormat format = PixelFormatInfo::info(v4l2Format).format;\n \t/*\n \t * \\todo This might need to be expanded as few pipeline handlers\n \t * report StreamFormats.\n \t */\n-\tconst std::vector<Size> &frameSizes = streamConfig_.formats().sizes(argFormat);\n+\tconst std::vector<Size> &frameSizes = streamConfig_.formats().sizes(format);\n \n \tif (arg->index >= frameSizes.size())\n \t\treturn -EINVAL;\n@@ -284,7 +287,8 @@ int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc *\n \t/* \\todo Add map from format to description. */\n \tutils::strlcpy(reinterpret_cast<char *>(arg->description),\n \t\t       \"Video Format Description\", sizeof(arg->description));\n-\targ->pixelformat = drmToV4L2(streamConfig_.formats().pixelformats()[arg->index]);\n+\targ->pixelformat =\n+\t\tPixelFormatInfo::info(streamConfig_.formats().pixelformats()[arg->index]).v4l2Format;\n \n \tmemset(arg->reserved, 0, sizeof(arg->reserved));\n \n@@ -306,7 +310,8 @@ int V4L2CameraProxy::vidioc_g_fmt(V4L2CameraFile *file, struct v4l2_format *arg)\n \n void V4L2CameraProxy::tryFormat(struct v4l2_format *arg)\n {\n-\tPixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);\n+\tV4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat);\n+\tPixelFormat format = PixelFormatInfo::info(v4l2Format).format;\n \tconst std::vector<PixelFormat> &formats =\n \t\tstreamConfig_.formats().pixelformats();\n \tif (std::find(formats.begin(), formats.end(), format) == formats.end())\n@@ -317,15 +322,14 @@ void V4L2CameraProxy::tryFormat(struct v4l2_format *arg)\n \tif (std::find(sizes.begin(), sizes.end(), size) == sizes.end())\n \t\tsize = streamConfig_.formats().sizes(format)[0];\n \n+\tPixelFormatInfo formatInfo = PixelFormatInfo::info(format);\n+\n \targ->fmt.pix.width        = size.width;\n \targ->fmt.pix.height       = size.height;\n-\targ->fmt.pix.pixelformat  = drmToV4L2(format);\n+\targ->fmt.pix.pixelformat  = formatInfo.v4l2Format;\n \targ->fmt.pix.field        = V4L2_FIELD_NONE;\n-\targ->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *\n-\t\t\t\t    arg->fmt.pix.width;\n-\targ->fmt.pix.sizeimage    = imageSize(drmToV4L2(format),\n-\t\t\t\t\t      arg->fmt.pix.width,\n-\t\t\t\t\t      arg->fmt.pix.height);\n+\targ->fmt.pix.bytesperline = formatInfo.bytesPerLine(size.width);\n+\targ->fmt.pix.sizeimage    = formatInfo.imageSize(size.width, size.height);\n \targ->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;\n \targ->fmt.pix.priv         = V4L2_PIX_FMT_PRIV_MAGIC;\n \targ->fmt.pix.ycbcr_enc    = V4L2_YCBCR_ENC_DEFAULT;\n@@ -350,8 +354,9 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg)\n \ttryFormat(arg);\n \n \tSize size(arg->fmt.pix.width, arg->fmt.pix.height);\n+\tV4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat);\n \tret = vcam_->configure(&streamConfig_, size,\n-\t\t\t       v4l2ToDrm(arg->fmt.pix.pixelformat),\n+\t\t\t       PixelFormatInfo::info(v4l2Format).format,\n \t\t\t       bufferCount_);\n \tif (ret < 0)\n \t\treturn -EINVAL;\n@@ -495,8 +500,9 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf\n \t\tfreeBuffers();\n \n \tSize size(curV4L2Format_.fmt.pix.width, curV4L2Format_.fmt.pix.height);\n+\tV4L2PixelFormat v4l2Format = V4L2PixelFormat(curV4L2Format_.fmt.pix.pixelformat);\n \tint ret = vcam_->configure(&streamConfig_, size,\n-\t\t\t\t   v4l2ToDrm(curV4L2Format_.fmt.pix.pixelformat),\n+\t\t\t\t   PixelFormatInfo::info(v4l2Format).format,\n \t\t\t\t   arg->count);\n \tif (ret < 0)\n \t\treturn -EINVAL;\n@@ -835,104 +841,3 @@ void V4L2CameraProxy::release(V4L2CameraFile *file)\n \n \towner_ = nullptr;\n }\n-\n-struct PixelFormatPlaneInfo {\n-\tunsigned int bitsPerPixel;\n-\tunsigned int hSubSampling;\n-\tunsigned int vSubSampling;\n-};\n-\n-struct PixelFormatInfo {\n-\tPixelFormat format;\n-\tuint32_t v4l2Format;\n-\tunsigned int numPlanes;\n-\tstd::array<PixelFormatPlaneInfo, 3> planes;\n-};\n-\n-namespace {\n-\n-static const std::array<PixelFormatInfo, 16> pixelFormatInfo = {{\n-\t/* RGB formats. */\n-\t{ formats::RGB888,\tV4L2_PIX_FMT_BGR24,\t1, {{ { 24, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t{ formats::BGR888,\tV4L2_PIX_FMT_RGB24,\t1, {{ { 24, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t{ formats::BGRA8888,\tV4L2_PIX_FMT_ARGB32,\t1, {{ { 32, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t/* YUV packed formats. */\n-\t{ formats::UYVY,\tV4L2_PIX_FMT_UYVY,\t1, {{ { 16, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t{ formats::VYUY,\tV4L2_PIX_FMT_VYUY,\t1, {{ { 16, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t{ formats::YUYV,\tV4L2_PIX_FMT_YUYV,\t1, {{ { 16, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t{ formats::YVYU,\tV4L2_PIX_FMT_YVYU,\t1, {{ { 16, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-\t/* YUY planar formats. */\n-\t{ formats::NV12,\tV4L2_PIX_FMT_NV12,\t2, {{ {  8, 1, 1 }, { 16, 2, 2 }, {  0, 0, 0 } }} },\n-\t{ formats::NV21,\tV4L2_PIX_FMT_NV21,\t2, {{ {  8, 1, 1 }, { 16, 2, 2 }, {  0, 0, 0 } }} },\n-\t{ formats::NV16,\tV4L2_PIX_FMT_NV16,\t2, {{ {  8, 1, 1 }, { 16, 2, 1 }, {  0, 0, 0 } }} },\n-\t{ formats::NV61,\tV4L2_PIX_FMT_NV61,\t2, {{ {  8, 1, 1 }, { 16, 2, 1 }, {  0, 0, 0 } }} },\n-\t{ formats::NV24,\tV4L2_PIX_FMT_NV24,\t2, {{ {  8, 1, 1 }, { 16, 1, 1 }, {  0, 0, 0 } }} },\n-\t{ formats::NV42,\tV4L2_PIX_FMT_NV42,\t2, {{ {  8, 1, 1 }, { 16, 1, 1 }, {  0, 0, 0 } }} },\n-\t{ formats::YUV420,\tV4L2_PIX_FMT_YUV420,\t3, {{ {  8, 1, 1 }, {  8, 2, 2 }, {  8, 2, 2 } }} },\n-\t{ formats::YUV422,\tV4L2_PIX_FMT_YUV422P,\t3, {{ {  8, 1, 1 }, {  8, 2, 1 }, {  8, 2, 1 } }} },\n-\t/* Compressed formats. */\n-\t/*\n-\t * \\todo Get a better image size estimate for MJPEG, via\n-\t * StreamConfiguration, instead of using the worst-case\n-\t * width * height * bpp of uncompressed data.\n-\t */\n-\t{ formats::MJPEG,\tV4L2_PIX_FMT_MJPEG,\t1, {{ { 16, 1, 1 }, {  0, 0, 0 }, {  0, 0, 0 } }} },\n-}};\n-\n-} /* namespace */\n-\n-/* \\todo make libcamera export these */\n-unsigned int V4L2CameraProxy::bplMultiplier(uint32_t format)\n-{\n-\tauto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),\n-\t\t\t\t [format](const PixelFormatInfo &info) {\n-\t\t\t\t\t return info.v4l2Format == format;\n-\t\t\t\t });\n-\tif (info == pixelFormatInfo.end())\n-\t\treturn 0;\n-\n-\treturn info->planes[0].bitsPerPixel / 8;\n-}\n-\n-unsigned int V4L2CameraProxy::imageSize(uint32_t format, unsigned int width,\n-\t\t\t\t\tunsigned int height)\n-{\n-\tauto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),\n-\t\t\t\t [format](const PixelFormatInfo &info) {\n-\t\t\t\t\t return info.v4l2Format == format;\n-\t\t\t\t });\n-\tif (info == pixelFormatInfo.end())\n-\t\treturn 0;\n-\n-\tunsigned int multiplier = 0;\n-\tfor (unsigned int i = 0; i < info->numPlanes; ++i)\n-\t\tmultiplier += info->planes[i].bitsPerPixel\n-\t\t\t    / info->planes[i].hSubSampling\n-\t\t\t    / info->planes[i].vSubSampling;\n-\n-\treturn width * height * multiplier / 8;\n-}\n-\n-PixelFormat V4L2CameraProxy::v4l2ToDrm(uint32_t format)\n-{\n-\tauto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),\n-\t\t\t\t [format](const PixelFormatInfo &info) {\n-\t\t\t\t\t return info.v4l2Format == format;\n-\t\t\t\t });\n-\tif (info == pixelFormatInfo.end())\n-\t\treturn PixelFormat();\n-\n-\treturn info->format;\n-}\n-\n-uint32_t V4L2CameraProxy::drmToV4L2(const PixelFormat &format)\n-{\n-\tauto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),\n-\t\t\t\t [format](const PixelFormatInfo &info) {\n-\t\t\t\t\t return info.format == format;\n-\t\t\t\t });\n-\tif (info == pixelFormatInfo.end())\n-\t\treturn format;\n-\n-\treturn info->v4l2Format;\n-}\ndiff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\nindex d78a472..49184a1 100644\n--- a/src/v4l2/v4l2_camera_proxy.h\n+++ b/src/v4l2/v4l2_camera_proxy.h\n@@ -69,13 +69,6 @@ private:\n \tint acquire(V4L2CameraFile *file);\n \tvoid release(V4L2CameraFile *file);\n \n-\tstatic unsigned int bplMultiplier(uint32_t format);\n-\tstatic unsigned int imageSize(uint32_t format, unsigned int width,\n-\t\t\t\t      unsigned int height);\n-\n-\tstatic PixelFormat v4l2ToDrm(uint32_t format);\n-\tstatic uint32_t drmToV4L2(const PixelFormat &format);\n-\n \tstatic const std::set<unsigned long> supportedIoctls_;\n \n \tunsigned int refcount_;\n","prefixes":["libcamera-devel","6/6"]}