From patchwork Thu Nov 18 15:19:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14630 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 95BECC324E for ; Thu, 18 Nov 2021 15:20:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 382C9603B5; Thu, 18 Nov 2021 16:20:36 +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="ACkt+fUo"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 824BD60233 for ; Thu, 18 Nov 2021 16:20:29 +0100 (CET) Received: by mail-wr1-x42d.google.com with SMTP id s13so12280860wrb.3 for ; Thu, 18 Nov 2021 07:20:29 -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=H7T104lkfLZPMGxIBUsm1hoLba7o7e864GWa57cAV/Y=; b=ACkt+fUokvvQHsIy9uFUbhdWJcz3M0oP4GJ8FiQLtjs1vNld/6bXsoHMJaEHDYKwHM 7UGHJ/Q2e2BijL4jCrahi25TfKk2qcPLa/HVcMAZqpIyRJ8vfm8ALpZo5WeIJsj2cank q6SPjRu3uSp2DzqPRf4PrwvPTl7Xblm+MKv0RsVp+4HoOW4gMOnBpIbWf3ZsvxfxDriZ FvnpSbyJIpHrHE3k/tM8sgufybZdsInbcXgC9C9gRFkVkTxX6VXOd7npazenpjBd9W0G 1b84KpEzjYsoTv6iB4W5Hw+KbAlQTEYQwHpyZuGme6fySCqh1E7keik7pnzHvEnGhc1F lc9A== 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=H7T104lkfLZPMGxIBUsm1hoLba7o7e864GWa57cAV/Y=; b=7cBbDZTsxUrkyvbWU//JuZG6qDD2BCpma1fmgTnhDQnGFYD7gccEJjoiW5m9q31oE8 FjXam2qeh2yhNKdhQz3TDNc2rhEwgEjMtP30GCtCskUbvBHzqBqLyxXKrHKVUYFEtZWm 9sosyR39zDax3YJAFtYmG23feavrNuCjSGEF7K24TClFiuM7j6ptrdaq7QXTg6uAsaPs Y7tAdqc6ek/5lVhuhw9sjQIKSYQpXAGqn4k4trS4F/o+U6QpQCpLW6njyxvwnVyshcma ybMsBY+1V6Ddnp2GqWrqSKb9m29ecim75h+ueAUWb9W+2UY7NK/+82pK7uQglWLE2N1E R6xQ== X-Gm-Message-State: AOAM530MmTReJo6cnSyUj9mrjMIeHnnbIvBIwFSvzGPPZ+MqZf3ujjFa GdxsMDPNg7XQAgVtJbNc+NxrNw== X-Google-Smtp-Source: ABdhPJy/9UgkTFGEUY085nCQBqw+HVOEPD7eaAkbIvZ4PMj+/CulRzgev3pKsRc2wCSBMmvQEwgbuQ== X-Received: by 2002:adf:f947:: with SMTP id q7mr31423192wrr.260.1637248829175; Thu, 18 Nov 2021 07:20:29 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id p12sm147367wro.33.2021.11.18.07.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 07:20:28 -0800 (PST) From: David Plowman To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, hverkuil-cisco@xs4all.nl, tfiga@google.com, jacopo@jmondi.org, naush@raspberrypi.com, libcamera-devel@lists.libcamera.org Date: Thu, 18 Nov 2021 15:19:31 +0000 Message-Id: <20211118151933.15627-6-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211118151933.15627-1-david.plowman@raspberrypi.com> References: <20211118151933.15627-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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 | 35 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..a6a0a870 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; + std::optional 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..b60ab69a 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -168,6 +168,16 @@ const std::map formatInfoMap = { * \brief The image size in pixels */ +/** + * \var V4L2SubdeviceFormat::colorSpace + * \brief The color space of the pixels + * + * The color space of the image. When setting the format this may be + * unset, in which case the driver gets to use its default color space. + * After being set, this value should contain the color space that the + * was actually used. + */ + /** * \brief Assemble and return a string describing the format * \return A string describing the V4L2SubdeviceFormat @@ -400,6 +410,16 @@ 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) + LOG(V4L2, Warning) + << "Retrieved unrecognised color space on pad " << pad; + return 0; } @@ -418,6 +438,9 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence) { + if (!format->colorSpace) + LOG(V4L2, Error) << "Setting an undefined color space"; + struct v4l2_subdev_format subdevFmt = {}; subdevFmt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; @@ -427,7 +450,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: " + << ColorSpace::toString(format->colorSpace); + + ret = ioctl(VIDIOC_SUBDEV_S_FMT, &subdevFmt); if (ret) { LOG(V4L2, Error) << "Unable to set format on pad " << pad @@ -439,6 +468,10 @@ 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) + LOG(V4L2, Warning) << "Unrecognised color space has been set"; + return 0; }