From patchwork Mon Dec 6 10:50:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15045 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 BD88EBDB13 for ; Mon, 6 Dec 2021 10:51:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E95D60890; Mon, 6 Dec 2021 11:51:27 +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="bKx91MYY"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BB7C6086A for ; Mon, 6 Dec 2021 11:51:23 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id o29so7775083wms.2 for ; Mon, 06 Dec 2021 02:51:23 -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=7Z9S0RSj2zeDGxeJJB1gRj13Za+pW7JcT9rNai8iw68=; b=bKx91MYYzfyV+8sIYIX9zlHtdw9StqfQBy+Ls7++Pz2U+exMqlzLX5353YmcdHTq4Q zvWkqiA0CjYO6rr7SyRILcj7Qz5PWiOvDucBV1UaksuOX2qDb1t780lEVyUXh8hOVxpV xDGQboglgErJUEnS8pA4Ytw137Jn6mI5rMReskx7JAcgWWfz3lEI5639jICdklNBFn3O nwiZXv6huxKkOtZ+o9OPOmdU+jf1OHGOmvBsm9mTNB5dk1OGEtR+54zzLA7JFRt2tG7p KWeXwZpVUHfxbqk3Qi8ZXZn1EqHGPX52UD2aLYL+HVk/ziqcY+9JkhNB5NB5RqqNwD7Y +izA== 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=7Z9S0RSj2zeDGxeJJB1gRj13Za+pW7JcT9rNai8iw68=; b=Xq1r5FYmLv7rlOA/f3Ya8hCDkkVN/ZoQmCHnqrblXGG02qrOqCCYYO6xkBrSSPkvOz AK6DKYRUyj53HbKDR2PQHbkhBs6ogqjwwzh/k3J7wTWcisWkVbHoypX11us0cWx2FFJS FPnGigXqsPlcjMYrYYLlZ2fDFpGslTufg8OkiTUxAk5V/atIq7tCBwAFsqKrZqscK+P2 DD4yzSNF0g+3BQsrXKw3MVRsdMy6O+eP3MZyG3qmdAqaU/kwvoTsaW1/lNK4/hBfvFVR UCUxZX0jsHCJmIw1JG/kqXq73j+DRWkoTFKAheBLoopQqzcdvWxxhUWnrhke4SAXiKFn i3aA== X-Gm-Message-State: AOAM530PvoroyoY+q99Dcrh+3MYsMUdJDexBi6yZTtVgihCoUeZI6Tuu rb6hIGZtdCVX7rhGA/4k5Ah+KgbaLaLyAW/u X-Google-Smtp-Source: ABdhPJydW02aJHN1Ge8TK1wc17quwLO2bFKiUu8Rutb6brv70TlhUEFrPvZymHgu8wpCsgK8GkqnMw== X-Received: by 2002:a7b:c30e:: with SMTP id k14mr37191597wmj.156.1638787883145; Mon, 06 Dec 2021 02:51:23 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id r7sm10878186wrq.29.2021.12.06.02.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 02:51:22 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org, naush@raspberrypi.com, jacopo@jmondi.org, tfiga@google.com, hverkuil-cisco@xs4all.nl, kieran.bingham@ideasonboard.com, laurent.pinchart@ideasonboard.com Date: Mon, 6 Dec 2021 10:50:27 +0000 Message-Id: <20211206105032.13876-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211206105032.13876-1-david.plowman@raspberrypi.com> References: <20211206105032.13876-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 4/8] libcamera: Support passing ColorSpaces to V4L2 video devices 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 V4L2VideoDevice. Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 9b2ec3af..6a507a51 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -167,6 +168,7 @@ public: V4L2PixelFormat fourcc; Size size; + std::optional colorSpace; std::array planes; unsigned int planesCount = 0; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index b4b89e27..80a8c8e4 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -383,6 +383,21 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const * that identifies the image format pixel encoding scheme. */ +/** + * \var V4L2DeviceFormat::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 + * was actually used. If this value is unset, then the color space chosen + * by the driver could not be represented by the ColorSpace class (and + * should probably be added). + * + * It is up to the pipeline handler or application to check if the + * resulting color space is acceptable. + */ + /** * \var V4L2DeviceFormat::planes * \brief The per-plane memory size information @@ -871,6 +886,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) format->size.height = pix->height; format->fourcc = V4L2PixelFormat(pix->pixelformat); format->planesCount = pix->num_planes; + format->colorSpace = toColorSpace(*pix); for (unsigned int i = 0; i < format->planesCount; ++i) { format->planes[i].bpl = pix->plane_fmt[i].bytesperline; @@ -893,6 +909,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) pix->num_planes = format->planesCount; pix->field = V4L2_FIELD_NONE; + ret = fromColorSpace(format->colorSpace, *pix); + if (ret < 0) + LOG(V4L2, Warning) + << "Setting color space unrecognised by V4L2: " + << ColorSpace::toString(format->colorSpace); + ASSERT(pix->num_planes <= std::size(pix->plane_fmt)); for (unsigned int i = 0; i < pix->num_planes; ++i) { @@ -920,6 +942,7 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) format->planes[i].bpl = pix->plane_fmt[i].bytesperline; format->planes[i].size = pix->plane_fmt[i].sizeimage; } + format->colorSpace = toColorSpace(*pix); return 0; } @@ -943,6 +966,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format) format->planesCount = 1; format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; + format->colorSpace = toColorSpace(*pix); return 0; } @@ -959,6 +983,13 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) pix->pixelformat = format->fourcc; pix->bytesperline = format->planes[0].bpl; pix->field = V4L2_FIELD_NONE; + + ret = fromColorSpace(format->colorSpace, *pix); + if (ret < 0) + LOG(V4L2, Warning) + << "Set color space unrecognised by V4L2: " + << ColorSpace::toString(format->colorSpace); + ret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format); if (ret) { LOG(V4L2, Error) @@ -977,6 +1008,7 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) format->planesCount = 1; format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; + format->colorSpace = toColorSpace(*pix); return 0; }