From patchwork Mon Nov 15 16:12: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: 14611 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 B8372BF415 for ; Mon, 15 Nov 2021 16:13:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 18E0D60394; Mon, 15 Nov 2021 17:13:09 +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="SqRfhdN/"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 849196037A for ; Mon, 15 Nov 2021 17:13:01 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso211789wme.3 for ; Mon, 15 Nov 2021 08:13:01 -0800 (PST) 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=SqRfhdN/Vzo+apIhpnwUtHMCHyfqYHmrVfIVWXXhTqhlyvW9RclIapiTZ2E99AEaDk bjHnSGNAqJumylCGDOABx4pPEXUJeUYWK3xbY17lzmm1JJJbN1t+ag26+M7LsdRz+1cq a+aMPqrypaWtq5LxGACIec8AXzioE0iEh2+hczAAKnj2zF2GTVGdEBThyGdnwqYfKJYM HnRWeUleFf+LmHTH2krRLQTPy/NwuNvsGW5FcB5wbLohZFsb2nwxvNyapeNZ0iRaJVlU lrdBlqKsTMhr4IvyLN9o2ghzjbAld0FmoU/7ezemhikRa9XYLojK41Z/w57PrNFIJit9 IsGQ== 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=3usD1QUlFOlJ6QtZufztEvCkCSHyZgjmczyn3/iOcKyMR0ln00bHxq3vtdDIWWLZoK OPfxcpZPQsUthT1xlbfuGYt4i+vzGiHagJVwqG9VBx64vjpIKSZrc4NRri/aod0tlNJk hHICHAwQR0rOh4H7qJzVsMQoa+9DXDMGC1dWPuzepo8CfzieY11J0JSaMkdq8jIPjBFj t0tjPnVaS4wbrNkJ2a79Sf0EMd3N+A7dUmmFnhnX+1Zhlq/OYHleTMeSHNoZFPVtkDYV J6hGGlwW36d777htbe2nykxZJZpabuwY6h9jLXkd0t84KUhD1CAPBnTse8KGNXU+8FC2 bYtg== X-Gm-Message-State: AOAM530vLxoFNrvtcHvtH3i9ze83LOwgx6yRFhr8u5YFbT+qVqbw1Ee8 LCAESEtPTrOotXfDKYPHLI9xxA== X-Google-Smtp-Source: ABdhPJy6OM2KCpf4NIE0S3d8AvryM1KFBAWM68cQCd9HiM4gKMY9jPZR0IXDK3UfFcGh7XRgbq4KgQ== X-Received: by 2002:a05:600c:2118:: with SMTP id u24mr60624693wml.0.1636992781268; Mon, 15 Nov 2021 08:13:01 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id j40sm16315615wms.16.2021.11.15.08.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 08:13:00 -0800 (PST) From: David Plowman To: hverkuil-cisco@xs4all.nl, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, jacopo@jmondi.org, tfiga@google.com, naush@raspberrypi.com, libcamera-devel@lists.libcamera.org Date: Mon, 15 Nov 2021 16:12:03 +0000 Message-Id: <20211115161205.24335-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211115161205.24335-1-david.plowman@raspberrypi.com> References: <20211115161205.24335-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; }