[{"id":4084,"web_url":"https://patchwork.libcamera.org/comment/4084/","msgid":"<20200319000414.GD3042581@oden.dyn.berto.se>","date":"2020-03-19T00:04:14","subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: v4l2_videodevice: Make\n\tV4L2PixelFormat constructor explicit","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-03-17 01:46:49 +0200, Laurent Pinchart wrote:\n> To achieve the goal of preventing unwanted conversion between a DRM and\n> a V4L2 FourCC, make the V4L2PixelFormat constructor that takes an\n> integer value explicit. All users of V4L2 pixel formats flagged by the\n> compiler are fixed.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/include/v4l2_videodevice.h      |  2 +-\n>  src/libcamera/pipeline/ipu3/ipu3.cpp          | 14 +++----\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  4 +-\n>  src/libcamera/pipeline/vimc.cpp               |  2 +-\n>  src/libcamera/v4l2_videodevice.cpp            | 42 ++++++++++---------\n>  .../v4l2_videodevice_test.cpp                 |  2 +-\n>  6 files changed, 35 insertions(+), 31 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 49d2ca357efa..9a123ce8c50e 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -157,7 +157,7 @@ public:\n>  \t{\n>  \t}\n>  \n> -\tV4L2PixelFormat(uint32_t fourcc)\n> +\texplicit V4L2PixelFormat(uint32_t fourcc)\n>  \t\t: fourcc_(fourcc)\n>  \t{\n>  \t}\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 90de7749f623..123b184023c3 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -121,7 +121,7 @@ public:\n>  \tint start();\n>  \tint stop();\n>  \n> -\tstatic int mediaBusToFormat(unsigned int code);\n> +\tstatic V4L2PixelFormat mediaBusToFormat(unsigned int code);\n>  \n>  \tV4L2VideoDevice *output_;\n>  \tV4L2Subdevice *csi2_;\n> @@ -1456,19 +1456,19 @@ int CIO2Device::stop()\n>  \treturn output_->streamOff();\n>  }\n>  \n> -int CIO2Device::mediaBusToFormat(unsigned int code)\n> +V4L2PixelFormat CIO2Device::mediaBusToFormat(unsigned int code)\n>  {\n>  \tswitch (code) {\n>  \tcase MEDIA_BUS_FMT_SBGGR10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SBGGR10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10);\n>  \tcase MEDIA_BUS_FMT_SGBRG10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SGBRG10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10);\n>  \tcase MEDIA_BUS_FMT_SGRBG10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SGRBG10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10);\n>  \tcase MEDIA_BUS_FMT_SRGGB10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SRGGB10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10);\n>  \tdefault:\n> -\t\treturn -EINVAL;\n> +\t\treturn {};\n>  \t}\n>  }\n>  \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index beed38956662..96ab8ea45931 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -645,13 +645,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \t}\n>  \n>  \tV4L2DeviceFormat paramFormat = {};\n> -\tparamFormat.fourcc = V4L2_META_FMT_RK_ISP1_PARAMS;\n> +\tparamFormat.fourcc = V4L2PixelFormat(V4L2_META_FMT_RK_ISP1_PARAMS);\n>  \tret = param_->setFormat(&paramFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n>  \tV4L2DeviceFormat statFormat = {};\n> -\tstatFormat.fourcc = V4L2_META_FMT_RK_ISP1_STAT_3A;\n> +\tstatFormat.fourcc = V4L2PixelFormat(V4L2_META_FMT_RK_ISP1_STAT_3A);\n>  \tret = stat_->setFormat(&statFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index eedef85866a1..83ffb5f16efa 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -247,7 +247,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n>  \t * Format has to be set on the raw capture video node, otherwise the\n>  \t * vimc driver will fail pipeline validation.\n>  \t */\n> -\tformat.fourcc = V4L2_PIX_FMT_SGRBG8;\n> +\tformat.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8);\n>  \tformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n>  \n>  \tret = data->raw_->setFormat(&format);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 40396c22aa45..6f59487593ae 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -286,6 +286,10 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>   * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n>   * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n>   * compile time.\n> + *\n> + * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> + * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> + * explicit value() and implicit uint32_t conversion operators may be used.\n>   */\n>  \n>  /**\n> @@ -719,7 +723,7 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n>  \n>  \tformat->size.width = 0;\n>  \tformat->size.height = 0;\n> -\tformat->fourcc = pix->dataformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->buffersize;\n>  \tformat->planes[0].size = pix->buffersize;\n> @@ -771,7 +775,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n>  \n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = pix->num_planes;\n>  \n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n> @@ -812,7 +816,7 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n>  \t */\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = pix->num_planes;\n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n>  \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n> @@ -837,7 +841,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n>  \n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> @@ -869,7 +873,7 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n>  \t */\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> @@ -913,7 +917,7 @@ std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats()\n>  \t\tif (ret)\n>  \t\t\tbreak;\n>  \n> -\t\tformats.push_back(pixelformatEnum.pixelformat);\n> +\t\tformats.push_back(V4L2PixelFormat(pixelformatEnum.pixelformat));\n>  \t}\n>  \n>  \tif (ret && ret != -EINVAL) {\n> @@ -1545,21 +1549,21 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \tswitch (pixelFormat.fourcc()) {\n>  \t/* RGB formats. */\n>  \tcase DRM_FORMAT_BGR888:\n> -\t\treturn V4L2_PIX_FMT_RGB24;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_RGB24);\n>  \tcase DRM_FORMAT_RGB888:\n> -\t\treturn V4L2_PIX_FMT_BGR24;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_BGR24);\n>  \tcase DRM_FORMAT_BGRA8888:\n> -\t\treturn V4L2_PIX_FMT_ARGB32;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_ARGB32);\n>  \n>  \t/* YUV packed formats. */\n>  \tcase DRM_FORMAT_YUYV:\n> -\t\treturn V4L2_PIX_FMT_YUYV;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YUYV);\n>  \tcase DRM_FORMAT_YVYU:\n> -\t\treturn V4L2_PIX_FMT_YVYU;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YVYU);\n>  \tcase DRM_FORMAT_UYVY:\n> -\t\treturn V4L2_PIX_FMT_UYVY;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_UYVY);\n>  \tcase DRM_FORMAT_VYUY:\n> -\t\treturn V4L2_PIX_FMT_VYUY;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_VYUY);\n>  \n>  \t/*\n>  \t * YUY planar formats.\n> @@ -1568,17 +1572,17 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \t * also take into account the formats supported by the device.\n>  \t */\n>  \tcase DRM_FORMAT_NV16:\n> -\t\treturn V4L2_PIX_FMT_NV16;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV16);\n>  \tcase DRM_FORMAT_NV61:\n> -\t\treturn V4L2_PIX_FMT_NV61;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV61);\n>  \tcase DRM_FORMAT_NV12:\n> -\t\treturn V4L2_PIX_FMT_NV12;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV12);\n>  \tcase DRM_FORMAT_NV21:\n> -\t\treturn V4L2_PIX_FMT_NV21;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV21);\n>  \n>  \t/* Compressed formats. */\n>  \tcase DRM_FORMAT_MJPEG:\n> -\t\treturn V4L2_PIX_FMT_MJPEG;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);\n>  \t}\n>  \n>  \t/*\n> @@ -1587,7 +1591,7 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \t */\n>  \tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()\n>  \t\t<< \"Unsupported V4L2 pixel format \" << pixelFormat.toString();\n> -\treturn 0;\n> +\treturn {};\n>  }\n>  \n>  /**\n> diff --git a/test/v4l2_videodevice/v4l2_videodevice_test.cpp b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> index 577da4cb601c..93b9e72da5b4 100644\n> --- a/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> +++ b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> @@ -69,7 +69,7 @@ int V4L2VideoDeviceTest::init()\n>  \t\tif (debayer_->open())\n>  \t\t\treturn TestFail;\n>  \n> -\t\tformat.fourcc = V4L2_PIX_FMT_SBGGR8;\n> +\t\tformat.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);\n>  \n>  \t\tV4L2SubdeviceFormat subformat = {};\n>  \t\tsubformat.mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8;\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x242.google.com (mail-lj1-x242.google.com\n\t[IPv6:2a00:1450:4864:20::242])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B10460419\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2020 01:04:16 +0100 (CET)","by mail-lj1-x242.google.com with SMTP id u15so124432lji.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Mar 2020 17:04:16 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\tj19sm135758lfg.49.2020.03.18.17.04.15\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 18 Mar 2020 17:04:15 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=SKpDknPi+T1EpBljgaEg8QWucoStRokda118fuumDbs=;\n\tb=qQhPjUUCXbo4MPc3V+ZT2UojHv2H6cxAKFOzW4Dgsd4x6yXXP2M4X7YCrN3L//mKLc\n\tDr2MAiTcVhNJj3+oJBorIs4QlO0khU86m42CZWVjDUEyn9fXmPQKseYeh5QLQ1vEKD4M\n\tGyNGOhNRDwo2so8Y3t2nxJZMv+YuhrAuuj4FGsv7Ysh+SKBUnPLYR3X3FXxNQhJtsHXw\n\tG4AalP+kvJKvGd8OFMIgLya9xgEiEWKve+QC/hETKaejhwqL+RxCCEAgElbLWt9ecknY\n\tcn0RAfEF2/vXLVRlZsNne0f5H+kRlIydJ9GA9Iomdc/4ilPXhcLESxlSs4lG6a3Ahwqn\n\t1TLA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=SKpDknPi+T1EpBljgaEg8QWucoStRokda118fuumDbs=;\n\tb=I9FR+LfJmqJReaH5CteKwb5p6lbURTqtKXPEcVYe+Af8MSMoF/RIxuCMG6QuVUZQli\n\tqstOIsZ5rerThdqSefKHq+FO8nT3zXcsE5rmh7gMaBtnKNuvbUPrKCQxMOwnkgErxf9o\n\tEkkIhZ830GL0fKb7s27cbWSNQPSNtGe6nhI7Y3y0P7x+leuCm0IZwTXjFBmiRc+118Gz\n\tnBsotqceNep73uk9ppwbntTQsRFJGPh5pT+uCpl3PlJKKnKuaCkgcipKLIPKvYLL7f+r\n\tuEmM948XO7nBez1uM1h09VFGIKZBKTHuEyTseo3sbJDAydUJ1B4KFZkWmUQ+/ALMaMiV\n\theOQ==","X-Gm-Message-State":"ANhLgQ26Zba9XCOIGEkbwF9b46+6IzyPT+INCIb6JPZXDX+EW1UbonFF\n\tu3BFiHwtEtpFj7FlDIKhcv3TgC8HzL4=","X-Google-Smtp-Source":"ADFU+vstdF0yykJdlwc426l29HvkNEZXpWWPU5WjmVcd4pjIJl4TF9Ncd/uCtWCJh3VGGCKo8S9+5w==","X-Received":"by 2002:a05:651c:552:: with SMTP id\n\tq18mr330835ljp.1.1584576255653; \n\tWed, 18 Mar 2020 17:04:15 -0700 (PDT)","Date":"Thu, 19 Mar 2020 01:04:14 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200319000414.GD3042581@oden.dyn.berto.se>","References":"<20200316234649.2545-1-laurent.pinchart@ideasonboard.com>\n\t<20200316234649.2545-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200316234649.2545-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: v4l2_videodevice: Make\n\tV4L2PixelFormat constructor explicit","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":"Thu, 19 Mar 2020 00:04:16 -0000"}},{"id":4092,"web_url":"https://patchwork.libcamera.org/comment/4092/","msgid":"<20200319123324.uvdnitgserjyqsed@uno.localdomain>","date":"2020-03-19T12:33:24","subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: v4l2_videodevice: Make\n\tV4L2PixelFormat constructor explicit","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Mar 17, 2020 at 01:46:49AM +0200, Laurent Pinchart wrote:\n> To achieve the goal of preventing unwanted conversion between a DRM and\n> a V4L2 FourCC, make the V4L2PixelFormat constructor that takes an\n> integer value explicit. All users of V4L2 pixel formats flagged by the\n> compiler are fixed.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThanks!\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\n\n> ---\n>  src/libcamera/include/v4l2_videodevice.h      |  2 +-\n>  src/libcamera/pipeline/ipu3/ipu3.cpp          | 14 +++----\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  4 +-\n>  src/libcamera/pipeline/vimc.cpp               |  2 +-\n>  src/libcamera/v4l2_videodevice.cpp            | 42 ++++++++++---------\n>  .../v4l2_videodevice_test.cpp                 |  2 +-\n>  6 files changed, 35 insertions(+), 31 deletions(-)\n>\n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index 49d2ca357efa..9a123ce8c50e 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -157,7 +157,7 @@ public:\n>  \t{\n>  \t}\n>\n> -\tV4L2PixelFormat(uint32_t fourcc)\n> +\texplicit V4L2PixelFormat(uint32_t fourcc)\n>  \t\t: fourcc_(fourcc)\n>  \t{\n>  \t}\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 90de7749f623..123b184023c3 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -121,7 +121,7 @@ public:\n>  \tint start();\n>  \tint stop();\n>\n> -\tstatic int mediaBusToFormat(unsigned int code);\n> +\tstatic V4L2PixelFormat mediaBusToFormat(unsigned int code);\n>\n>  \tV4L2VideoDevice *output_;\n>  \tV4L2Subdevice *csi2_;\n> @@ -1456,19 +1456,19 @@ int CIO2Device::stop()\n>  \treturn output_->streamOff();\n>  }\n>\n> -int CIO2Device::mediaBusToFormat(unsigned int code)\n> +V4L2PixelFormat CIO2Device::mediaBusToFormat(unsigned int code)\n>  {\n>  \tswitch (code) {\n>  \tcase MEDIA_BUS_FMT_SBGGR10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SBGGR10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SBGGR10);\n>  \tcase MEDIA_BUS_FMT_SGBRG10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SGBRG10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGBRG10);\n>  \tcase MEDIA_BUS_FMT_SGRBG10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SGRBG10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SGRBG10);\n>  \tcase MEDIA_BUS_FMT_SRGGB10_1X10:\n> -\t\treturn V4L2_PIX_FMT_IPU3_SRGGB10;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_IPU3_SRGGB10);\n>  \tdefault:\n> -\t\treturn -EINVAL;\n> +\t\treturn {};\n>  \t}\n>  }\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index beed38956662..96ab8ea45931 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -645,13 +645,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \t}\n>\n>  \tV4L2DeviceFormat paramFormat = {};\n> -\tparamFormat.fourcc = V4L2_META_FMT_RK_ISP1_PARAMS;\n> +\tparamFormat.fourcc = V4L2PixelFormat(V4L2_META_FMT_RK_ISP1_PARAMS);\n>  \tret = param_->setFormat(&paramFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n>\n>  \tV4L2DeviceFormat statFormat = {};\n> -\tstatFormat.fourcc = V4L2_META_FMT_RK_ISP1_STAT_3A;\n> +\tstatFormat.fourcc = V4L2PixelFormat(V4L2_META_FMT_RK_ISP1_STAT_3A);\n>  \tret = stat_->setFormat(&statFormat);\n>  \tif (ret)\n>  \t\treturn ret;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index eedef85866a1..83ffb5f16efa 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -247,7 +247,7 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n>  \t * Format has to be set on the raw capture video node, otherwise the\n>  \t * vimc driver will fail pipeline validation.\n>  \t */\n> -\tformat.fourcc = V4L2_PIX_FMT_SGRBG8;\n> +\tformat.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8);\n>  \tformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n>\n>  \tret = data->raw_->setFormat(&format);\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 40396c22aa45..6f59487593ae 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -286,6 +286,10 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n>   * V4L2 pixel formats. Its purpose is to prevent unintentional confusion of\n>   * V4L2 and DRM FourCCs in code by catching implicit conversion attempts at\n>   * compile time.\n> + *\n> + * To achieve this goal, construction of a V4L2PixelFormat from an integer value\n> + * is explicit. To retrieve the integer value of a V4L2PixelFormat, both the\n> + * explicit value() and implicit uint32_t conversion operators may be used.\n>   */\n>\n>  /**\n> @@ -719,7 +723,7 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n>\n>  \tformat->size.width = 0;\n>  \tformat->size.height = 0;\n> -\tformat->fourcc = pix->dataformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->buffersize;\n>  \tformat->planes[0].size = pix->buffersize;\n> @@ -771,7 +775,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n>\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = pix->num_planes;\n>\n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n> @@ -812,7 +816,7 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format)\n>  \t */\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = pix->num_planes;\n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n>  \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n> @@ -837,7 +841,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format)\n>\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> @@ -869,7 +873,7 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n>  \t */\n>  \tformat->size.width = pix->width;\n>  \tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n>  \tformat->planesCount = 1;\n>  \tformat->planes[0].bpl = pix->bytesperline;\n>  \tformat->planes[0].size = pix->sizeimage;\n> @@ -913,7 +917,7 @@ std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats()\n>  \t\tif (ret)\n>  \t\t\tbreak;\n>\n> -\t\tformats.push_back(pixelformatEnum.pixelformat);\n> +\t\tformats.push_back(V4L2PixelFormat(pixelformatEnum.pixelformat));\n>  \t}\n>\n>  \tif (ret && ret != -EINVAL) {\n> @@ -1545,21 +1549,21 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \tswitch (pixelFormat.fourcc()) {\n>  \t/* RGB formats. */\n>  \tcase DRM_FORMAT_BGR888:\n> -\t\treturn V4L2_PIX_FMT_RGB24;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_RGB24);\n>  \tcase DRM_FORMAT_RGB888:\n> -\t\treturn V4L2_PIX_FMT_BGR24;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_BGR24);\n>  \tcase DRM_FORMAT_BGRA8888:\n> -\t\treturn V4L2_PIX_FMT_ARGB32;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_ARGB32);\n>\n>  \t/* YUV packed formats. */\n>  \tcase DRM_FORMAT_YUYV:\n> -\t\treturn V4L2_PIX_FMT_YUYV;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YUYV);\n>  \tcase DRM_FORMAT_YVYU:\n> -\t\treturn V4L2_PIX_FMT_YVYU;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_YVYU);\n>  \tcase DRM_FORMAT_UYVY:\n> -\t\treturn V4L2_PIX_FMT_UYVY;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_UYVY);\n>  \tcase DRM_FORMAT_VYUY:\n> -\t\treturn V4L2_PIX_FMT_VYUY;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_VYUY);\n>\n>  \t/*\n>  \t * YUY planar formats.\n> @@ -1568,17 +1572,17 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \t * also take into account the formats supported by the device.\n>  \t */\n>  \tcase DRM_FORMAT_NV16:\n> -\t\treturn V4L2_PIX_FMT_NV16;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV16);\n>  \tcase DRM_FORMAT_NV61:\n> -\t\treturn V4L2_PIX_FMT_NV61;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV61);\n>  \tcase DRM_FORMAT_NV12:\n> -\t\treturn V4L2_PIX_FMT_NV12;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV12);\n>  \tcase DRM_FORMAT_NV21:\n> -\t\treturn V4L2_PIX_FMT_NV21;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_NV21);\n>\n>  \t/* Compressed formats. */\n>  \tcase DRM_FORMAT_MJPEG:\n> -\t\treturn V4L2_PIX_FMT_MJPEG;\n> +\t\treturn V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);\n>  \t}\n>\n>  \t/*\n> @@ -1587,7 +1591,7 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool mult\n>  \t */\n>  \tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()\n>  \t\t<< \"Unsupported V4L2 pixel format \" << pixelFormat.toString();\n> -\treturn 0;\n> +\treturn {};\n>  }\n>\n>  /**\n> diff --git a/test/v4l2_videodevice/v4l2_videodevice_test.cpp b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> index 577da4cb601c..93b9e72da5b4 100644\n> --- a/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> +++ b/test/v4l2_videodevice/v4l2_videodevice_test.cpp\n> @@ -69,7 +69,7 @@ int V4L2VideoDeviceTest::init()\n>  \t\tif (debayer_->open())\n>  \t\t\treturn TestFail;\n>\n> -\t\tformat.fourcc = V4L2_PIX_FMT_SBGGR8;\n> +\t\tformat.fourcc = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);\n>\n>  \t\tV4L2SubdeviceFormat subformat = {};\n>  \t\tsubformat.mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8;\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BEE6B629AC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 19 Mar 2020 13:30:27 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 52B2940002;\n\tThu, 19 Mar 2020 12:30:27 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Thu, 19 Mar 2020 13:33:24 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200319123324.uvdnitgserjyqsed@uno.localdomain>","References":"<20200316234649.2545-1-laurent.pinchart@ideasonboard.com>\n\t<20200316234649.2545-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200316234649.2545-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 2/2] libcamera: v4l2_videodevice: Make\n\tV4L2PixelFormat constructor explicit","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":"Thu, 19 Mar 2020 12:30:27 -0000"}}]