[{"id":24577,"web_url":"https://patchwork.libcamera.org/comment/24577/","msgid":"<YvpdtNmxWifISU8H@pendragon.ideasonboard.com>","date":"2022-08-15T14:52:36","subject":"Re: [libcamera-devel] [PATCH v3] libcamera: v4l2: Set colorspace\n\tflags","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Fri, Aug 12, 2022 at 02:23:24PM +0530, Umang Jain via libcamera-devel wrote:\n> The colorspace fields are read-only from an application point of view,\n> both on video devices and on subdevs, unless the\n> V4L2_PIX_FMT_FLAG_SET_CSC or V4L2_MBUS_FRAMEFMT_SET_CSC flags\n> (respectively) are set when calling the S_FMT ioctl.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/v4l2_subdevice.cpp   |  8 +++++++-\n>  src/libcamera/v4l2_videodevice.cpp | 14 ++++++++++++--\n>  2 files changed, 19 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index e5d20f2c..d8fd92e3 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -526,7 +526,13 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n>  \tsubdevFmt.format.height = format->size.height;\n>  \tsubdevFmt.format.code = format->mbus_code;\n>  \tsubdevFmt.format.field = V4L2_FIELD_NONE;\n> -\tfromColorSpace(format->colorSpace, subdevFmt.format);\n> +\tif (format->colorSpace) {\n> +\t\tfromColorSpace(format->colorSpace, subdevFmt.format);\n> +\n> +\t\t/* The CSC flag is only applicable to source pads. */\n> +\t\tif (entity_->pads()[pad]->flags() & MEDIA_PAD_FL_SOURCE)\n> +\t\t\tsubdevFmt.format.flags |= V4L2_MBUS_FRAMEFMT_SET_CSC;\n> +\t}\n>  \n>  \tint ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n>  \tif (ret) {\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index b80ee1cd..5a2d0e5b 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -953,7 +953,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>  \tpix->pixelformat = format->fourcc;\n>  \tpix->num_planes = format->planesCount;\n>  \tpix->field = V4L2_FIELD_NONE;\n> -\tfromColorSpace(format->colorSpace, *pix);\n> +\tif (format->colorSpace) {\n> +\t\tfromColorSpace(format->colorSpace, *pix);\n> +\n> +\t\tif (caps_.isVideoCapture())\n> +\t\t\tpix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;\n> +\t}\n>  \n>  \tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>  \n> @@ -1023,7 +1028,12 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n>  \tpix->pixelformat = format->fourcc;\n>  \tpix->bytesperline = format->planes[0].bpl;\n>  \tpix->field = V4L2_FIELD_NONE;\n> -\tfromColorSpace(format->colorSpace, *pix);\n> +\tif (format->colorSpace) {\n> +\t\tfromColorSpace(format->colorSpace, *pix);\n> +\n> +\t\tif (caps_.isVideoCapture())\n> +\t\t\tpix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;\n> +\t}\n>  \n>  \tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n>  \tif (ret) {","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 CA8DABE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 15 Aug 2022 14:52:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 39AC261FBC;\n\tMon, 15 Aug 2022 16:52:53 +0200 (CEST)","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 1D34B61FB9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Aug 2022 16:52:51 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7DA234A8;\n\tMon, 15 Aug 2022 16:52:50 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660575173;\n\tbh=4+pxzIfPKZfOHxXf9xQlBSiHxVwHMzRxdAP6tCPiDsE=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=zQumTRpFIHLVEM1v8zb5SwbqhD6SpMJsJyr9oGvWMU5Dn6/4l9JbFXAQjWuhdQp8d\n\tbhyaVUq4SH+QIA9BnT7YMtfb2skUkafDN5XekLQiTZfVGlraIGK5BIaZ/F31dQmQL0\n\tQUmMgdavuAav40yzyl0A8VolvJGL4CsG4YbzIKWQ8YymoMTvljwMedj681liU3eDDy\n\tNDWBdAB9L7v7fKPr4hsXThr2m2PRyABanvzkE3ihpOFCaawMZE6mxuxHajoUI0p9H+\n\twqGDk+OigkcYRdC7yPxCQCAG7PCklp43/VrKPuzw2BsLY8hYplIndexMKt4HxZzYrp\n\tkDyBDxvHwKphg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660575170;\n\tbh=4+pxzIfPKZfOHxXf9xQlBSiHxVwHMzRxdAP6tCPiDsE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fMiw6skNRjYhwxv7anTMjMC2B+Vj9aMBp8EKCCdMwKgiNn7pGS1wQjpM7SwCOOyO6\n\tQ6p89eln+dPom1aE0nWb8tV+VGF6bbZoYkyvmTDSbi/pprKIPjtRRFHJzTyR8pwuH0\n\t9GU1EFJmZ8/u6DjM3AyPd0F6WTNbId02nvLN9Od8="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"fMiw6skN\"; dkim-atps=neutral","Date":"Mon, 15 Aug 2022 17:52:36 +0300","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<YvpdtNmxWifISU8H@pendragon.ideasonboard.com>","References":"<20220812085324.266351-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220812085324.266351-1-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3] libcamera: v4l2: Set colorspace\n\tflags","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24606,"web_url":"https://patchwork.libcamera.org/comment/24606/","msgid":"<166064024271.2754132.8913358820610825506@Monstersaurus>","date":"2022-08-16T08:57:22","subject":"Re: [libcamera-devel] [PATCH v3] libcamera: v4l2: Set colorspace\n\tflags","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain via libcamera-devel (2022-08-12 09:53:24)\n> The colorspace fields are read-only from an application point of view,\n> both on video devices and on subdevs, unless the\n> V4L2_PIX_FMT_FLAG_SET_CSC or V4L2_MBUS_FRAMEFMT_SET_CSC flags\n> (respectively) are set when calling the S_FMT ioctl.\n\nThat describes the problem, but not what the patch does. I'd append:\n\n\"\"\"\nSet the flags accordingly within the V4L2SubDevice and V4L2Device when a\ncolorspace is being set by the application.\n\"\"\"\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/libcamera/v4l2_subdevice.cpp   |  8 +++++++-\n>  src/libcamera/v4l2_videodevice.cpp | 14 ++++++++++++--\n>  2 files changed, 19 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index e5d20f2c..d8fd92e3 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -526,7 +526,13 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n>         subdevFmt.format.height = format->size.height;\n>         subdevFmt.format.code = format->mbus_code;\n>         subdevFmt.format.field = V4L2_FIELD_NONE;\n> -       fromColorSpace(format->colorSpace, subdevFmt.format);\n> +       if (format->colorSpace) {\n> +               fromColorSpace(format->colorSpace, subdevFmt.format);\n> +\n> +               /* The CSC flag is only applicable to source pads. */\n> +               if (entity_->pads()[pad]->flags() & MEDIA_PAD_FL_SOURCE)\n> +                       subdevFmt.format.flags |= V4L2_MBUS_FRAMEFMT_SET_CSC;\n> +       }\n>  \n>         int ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt);\n>         if (ret) {\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index b80ee1cd..5a2d0e5b 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -953,7 +953,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n>         pix->pixelformat = format->fourcc;\n>         pix->num_planes = format->planesCount;\n>         pix->field = V4L2_FIELD_NONE;\n> -       fromColorSpace(format->colorSpace, *pix);\n> +       if (format->colorSpace) {\n> +               fromColorSpace(format->colorSpace, *pix);\n> +\n> +               if (caps_.isVideoCapture())\n> +                       pix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;\n> +       }\n>  \n>         ASSERT(pix->num_planes <= std::size(pix->plane_fmt));\n>  \n> @@ -1023,7 +1028,12 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\n>         pix->pixelformat = format->fourcc;\n>         pix->bytesperline = format->planes[0].bpl;\n>         pix->field = V4L2_FIELD_NONE;\n> -       fromColorSpace(format->colorSpace, *pix);\n> +       if (format->colorSpace) {\n> +               fromColorSpace(format->colorSpace, *pix);\n> +\n> +               if (caps_.isVideoCapture())\n> +                       pix->flags |= V4L2_PIX_FMT_FLAG_SET_CSC;\n> +       }\n>  \n>         ret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n>         if (ret) {\n> -- \n> 2.31.1\n>","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 15CDDBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Aug 2022 08:57:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5536C61FC0;\n\tTue, 16 Aug 2022 10:57:27 +0200 (CEST)","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 42D6561FA7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Aug 2022 10:57:26 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A8EC725B;\n\tTue, 16 Aug 2022 10:57:25 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660640247;\n\tbh=yrQA8OrWPgc2+J8zvFJkClKMfQSKJLZ0huGSqUWC6FE=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=KnYsJx6OykwBfIRy3/dLIYFS+//oxkzXtCmJDpaOXOL4vh0gYPXQxiFYi67zRuS0W\n\tA4owViosWKP34TEm4RzLI776ziDC1kUsGanQEu0gXOowqt27IwfEvI4zAXEkjkDH/9\n\tYCz8pKGGXs56H9+ilobsBT4qAfvxyNUHwWUwnghg56qL896bKbG3kS0kIh09Rn2sjw\n\tsmPgk8voa1pX5tFbNCNTQK/yJxTjhL7YkiXgZ3GWEcybUXoqg3NNj4PXZ+3lY9xq7W\n\tSFxhzBM4MxDAWPwMoJxypusdydjTb9VvHcKPYKWB2chLUS+fZsJpL39N8TGOWq9UCX\n\tQDKDn2IMl9yXQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660640245;\n\tbh=yrQA8OrWPgc2+J8zvFJkClKMfQSKJLZ0huGSqUWC6FE=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=juWzo0ZpKURxmlFbEc4Ga3EaMoxBluQqDpDYRJX87ZPqNmVqA5hZI+1VzH/1PA+RG\n\tZGeXJDmJVKzxl1LNtBQa0ofwwQ8OgiLyyJ9oKMKsnIDobQwWrqPkfEQwXvNia6CDG7\n\tOVsM5BJgjYBT9ObY+/AUjm/yG6Z8/2EsBIr97ZxI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"juWzo0Zp\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220812085324.266351-1-umang.jain@ideasonboard.com>","References":"<20220812085324.266351-1-umang.jain@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 16 Aug 2022 09:57:22 +0100","Message-ID":"<166064024271.2754132.8913358820610825506@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v3] libcamera: v4l2: Set colorspace\n\tflags","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]