From patchwork Thu Nov 4 13:58:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14462 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6EB00C324E for ; Thu, 4 Nov 2021 13:58:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 202BB6034F; Thu, 4 Nov 2021 14:58:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="T893C1jc"; dkim-atps=neutral Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 04E7460352 for ; Thu, 4 Nov 2021 14:58:26 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id y196so4588360wmc.3 for ; Thu, 04 Nov 2021 06:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HsQlhHnuhc87TaSXhA5f4OVRdGAu3zIVZXBgg53nXBM=; b=T893C1jc5/OBi28MfxZnXec0O+Ab2vOFs58ObSFvTaOiWxjS1oMrF0LIiVPRyV1gda EzEgQL4IoDZv8llqkwqmk5Xz1JKerfnUVlfZhd6Xdub5ssMnV7YPpxnlejJ1P9ZPSgz3 KoKSE8X+/tLpU01/+Kj7IhF7hOQbqyGsbScpmYmel9otED6xd+o7mizJc6tYt5A5prPZ SqvFVBsaFhMpO+QtSxQIAWP73L+Kpi8+OPCJ41wKcnq2hyWvYkjLn6P7uKrq9y4e80vb 3K2+iMHRE6tB5lOzbOZuvIW5LllvPnvHmXxLUPysORy4vTMnA+Q9PMEZMV3LYxj/v2sb PTyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HsQlhHnuhc87TaSXhA5f4OVRdGAu3zIVZXBgg53nXBM=; b=OMaeaXue+FcZIwd3Ru5pjWFAjpk6rNlITpQmFba+rIB8qAFB+Q0XgjjtslyD3EeiUB F+XxYHrFK2NL2SUq5JHLitwrLSAjdLxfLpgGvgAfiTXD+C75RttI2kBHthYLoFyWyLUu 2tIiiyXxGqnvA5ZPIP3CQx5xPvuf/Lr+rDIhKNw6DYP41/O97Ksbq9dTqs/Imj5XEyPM oFFwNGUBvFVCGgMjthPHZm410Dpeg/Wve+OWCrzSYzb4vEBIz9wqmR26elXXya85NmjA d5IojsRGQRRGSXSJ3VGA+GULzTDLFRmixwZ7QzXbswlZDmpvR/zdtn3Hfu9qGIW49P0U r+mw== X-Gm-Message-State: AOAM532DobuI3T7iDGxTLTe3LtTuE+mMdXLRGqVGd8qJW57Jusl3YdGH EINuc0zv2reEumEmxXUua0E5HHQqIPhmdQ== X-Google-Smtp-Source: ABdhPJzyTMWuCyBZkFT84bCCTS1nrqpBrpkj+fb7d4leHwdHbMiRmkWuOZQaYRpMcGHluEtUgKr0Jg== X-Received: by 2002:a7b:c744:: with SMTP id w4mr18525399wmk.50.1636034305546; Thu, 04 Nov 2021 06:58:25 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id i20sm2264736wmq.41.2021.11.04.06.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 06:58:25 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Nov 2021 13:58:03 +0000 Message-Id: <20211104135805.5269-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211104135805.5269-1-david.plowman@raspberrypi.com> References: <20211104135805.5269-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 5/7] libcamera: Support passing ColorSpaces to V4L2 subdevices X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The ColorSpace from the StreamConfiguration is now handled appropriately in the V4L2Subdevice. Signed-off-by: David Plowman --- include/libcamera/internal/v4l2_subdevice.h | 2 + src/libcamera/camera_sensor.cpp | 1 + src/libcamera/v4l2_subdevice.cpp | 42 ++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..f3ab8454 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -14,6 +14,7 @@ #include #include +#include #include #include "libcamera/internal/formats.h" @@ -27,6 +28,7 @@ class MediaDevice; struct V4L2SubdeviceFormat { uint32_t mbus_code; Size size; + ColorSpace colorSpace; const std::string toString() const; uint8_t bitsPerPixel() const; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..6fcd1c1d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -613,6 +613,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu V4L2SubdeviceFormat format{ .mbus_code = bestCode, .size = *bestSize, + .colorSpace = ColorSpace::Raw, }; return format; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..b348170f 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -168,6 +168,18 @@ const std::map formatInfoMap = { * \brief The image size in pixels */ +/** + * \var V4L2SubdeviceFormat::colorSpace + * \brief The color space of the pixels + * + * When setting or trying a format, passing in "Undefined" fields in the + * ColorSpace is not recommended because the driver will then make an + * arbitrary choice of its own. Choices made by the driver will be + * passed back in the normal way, though note that "Undefined" values can + * be returned if the device has chosen something that the ColorSpace + * cannot represent. + */ + /** * \brief Assemble and return a string describing the format * \return A string describing the V4L2SubdeviceFormat @@ -400,6 +412,17 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); + /* + * This warning can be ignored on metadata pads. These are normally + * pads other than zero. + * \todo find a way to detect metadata pads and ignore them + */ + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Retrieved undefined color space on pad " << pad + << ": " << format->colorSpace.toString(); + return 0; } @@ -418,6 +441,11 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence) { + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Error) + << "Trying to set undefined color space: " + << format->colorSpace.toString(); + struct v4l2_subdev_format subdevFmt = {}; subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; @@ -427,7 +455,13 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, subdevFmt.format.code = format->mbus_code; subdevFmt.format.field = V4L2_FIELD_NONE; - int ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); + int ret = fromColorSpace(format->colorSpace, subdevFmt.format); + if (ret < 0) + LOG(V4L2, Warning) + << "Setting color space unrecognised by V4L2: " + << format->colorSpace.toString(); + + ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); if (ret) { LOG(V4L2, Error) << "Unable to set format on pad " << pad @@ -439,6 +473,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; + format->colorSpace = toColorSpace(subdevFmt.format); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Undefined color space has been set: " + << format->colorSpace.toString(); + return 0; }