From patchwork Wed Oct 20 11:08:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 14197 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 1F2E3C324E for ; Wed, 20 Oct 2021 11:08:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A93868F6D; Wed, 20 Oct 2021 13:08:34 +0200 (CEST) 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="kkqQDXkN"; dkim-atps=neutral Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8767768F60 for ; Wed, 20 Oct 2021 13:08:30 +0200 (CEST) Received: by mail-wm1-x334.google.com with SMTP id o24-20020a05600c511800b0030d9da600aeso9268614wms.4 for ; Wed, 20 Oct 2021 04:08:30 -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=PmSettw5PZPQKCMg1GXcyVLAY5F5dDI8K7YMj39hOXU=; b=kkqQDXkNoNzRKqzd3EONW9P2UpV4v4fxDeapviwEre0wn72lSOi+CfQAveTU3jym0B sLfY8a3WP57s66oARuBTxMFNkyztaucQNdB1ynMk0BYNIMNFnguFn8rJMYTZuvFwWCvq GcC2iY3/bnr/N+v2waHSs73+CSTA8hnv5s0n/LS3sKcv6N2MSvDstXSCheQixDcnkuLE 8ACwBLzGImnDxOpVVrW73uIhKIFx/eDixLevYiv7GIzzkbGF1L0/j7zs5TauYqzdoiWf wXnBz/JqtJr3gPy/uwsVXKJzVjTSk0Oke/pIArSTDQT1YSR66VjdqRPPNMcf+jxuw8iY k/BA== 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=PmSettw5PZPQKCMg1GXcyVLAY5F5dDI8K7YMj39hOXU=; b=SgXYDcjzDKZfhPXfiQZGr2f7ruEpesl0pOAEzLB16W9CO/wFYyQALM+x0TNRHiYktb EEC7uoA96Vl/t5iPwypB4QY2TIbWC5u123oydnYgyBcESO7a9INIqkqnhoTzs6inIECn o8mLg0o4yOqUKWKHtix60vj0Ot5yZZfE+ybU6JBCwQiPgy8mA+32vP8NgkkD4absYUbF 1nemmokYN19yT8Zan8k39hVQCEAr3M3NYd38q5eAlDR5bEvH3XUXa4k1MO8iPyAKzNbA 00tgmSmX8K4fOI7udj4KuBJiiCitWy2S+v+8gcT2CiDbZLVf8BkmVrIS0I0bSweip4q/ qNHg== X-Gm-Message-State: AOAM530j3chXhpKmk+le5nzKQisMd1ScRdogXwyVMAXTfTbjbF6g3CA9 xiDRpHRRsiYVVOrEnEp0tpL8hDcrXFQseg== X-Google-Smtp-Source: ABdhPJzDBxB+yRm43whssvSG72Ab49iOxzXVLJ0IBo0n/kirXlsReck+Kyp52NY8XnNs6BJvn2ieFg== X-Received: by 2002:a1c:cc09:: with SMTP id h9mr13084187wmb.191.1634728109947; Wed, 20 Oct 2021 04:08:29 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id f20sm1929654wmq.38.2021.10.20.04.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 04:08:29 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Oct 2021 12:08:22 +0100 Message-Id: <20211020110825.12902-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211020110825.12902-1-david.plowman@raspberrypi.com> References: <20211020110825.12902-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/7] 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: Naushir Patuck --- include/libcamera/internal/v4l2_videodevice.h | 2 + src/libcamera/v4l2_videodevice.cpp | 69 +++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index efe34d47..34cc9cdd 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -163,6 +164,7 @@ public: V4L2PixelFormat fourcc; Size size; + ColorSpace colorSpace; std::array planes; unsigned int planesCount = 0; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ba5f88cd..9e57e257 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -364,11 +364,6 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const * \brief The plane line stride (in bytes) */ -/** - * \var V4L2DeviceFormat::size - * \brief The image size in pixels - */ - /** * \var V4L2DeviceFormat::fourcc * \brief The fourcc code describing the pixel encoding scheme @@ -377,6 +372,23 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const * that identifies the image format pixel encoding scheme. */ +/** + * \var V4L2DeviceFormat::size + * \brief The image size in pixels + */ + +/** + * \var V4L2DeviceFormat::colorSpace + * \brief The color space of the pixels + * + * When setting or trying a format, passing in "Undefined" fields in the + * ColorSpace is not permitted 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 + * class cannot represent. + */ + /** * \var V4L2DeviceFormat::planes * \brief The per-plane memory size information @@ -873,6 +885,12 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) format->fourcc = V4L2PixelFormat(pix->pixelformat); format->planesCount = pix->num_planes; + format->colorSpace = v4l2ToColorSpace(*pix); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Retrieved undefined color space: " + << format->colorSpace.toString(); + for (unsigned int i = 0; i < format->planesCount; ++i) { format->planes[i].bpl = pix->plane_fmt[i].bytesperline; format->planes[i].size = pix->plane_fmt[i].sizeimage; @@ -887,6 +905,11 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) struct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp; int ret; + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Error) + << "Trying to set undefined color space: " + << format->colorSpace.toString(); + v4l2Format.type = bufferType_; pix->width = format->size.width; pix->height = format->size.height; @@ -894,6 +917,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) pix->num_planes = format->planesCount; pix->field = V4L2_FIELD_NONE; + ret = colorSpaceToV4l2(format->colorSpace, *pix); + if (ret < 0) + LOG(V4L2, Warning) + << "Setting color space unrecognised by V4L2: " + << format->colorSpace.toString(); + ASSERT(pix->num_planes <= std::size(pix->plane_fmt)); for (unsigned int i = 0; i < pix->num_planes; ++i) { @@ -922,6 +951,12 @@ int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) format->planes[i].size = pix->plane_fmt[i].sizeimage; } + format->colorSpace = v4l2ToColorSpace(*pix); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Undefined color space has been set: " + << format->colorSpace.toString(); + return 0; } @@ -945,6 +980,12 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format) format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; + format->colorSpace = v4l2ToColorSpace(*pix); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Retrieved undefined color space: " + << format->colorSpace.toString(); + return 0; } @@ -954,12 +995,24 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) struct v4l2_pix_format *pix = &v4l2Format.fmt.pix; int ret; + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Error) + << "Trying to set undefined color space: " + << format->colorSpace.toString(); + v4l2Format.type = bufferType_; pix->width = format->size.width; pix->height = format->size.height; pix->pixelformat = format->fourcc; pix->bytesperline = format->planes[0].bpl; pix->field = V4L2_FIELD_NONE; + + ret = colorSpaceToV4l2(format->colorSpace, *pix); + if (ret < 0) + LOG(V4L2, Warning) + << "Set color space unrecognised by V4L2: " + << format->colorSpace.toString(); + ret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format); if (ret) { LOG(V4L2, Error) @@ -979,6 +1032,12 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) format->planes[0].bpl = pix->bytesperline; format->planes[0].size = pix->sizeimage; + format->colorSpace = v4l2ToColorSpace(*pix); + if (!format->colorSpace.isFullyDefined()) + LOG(V4L2, Warning) + << "Undefined color space has been set: " + << format->colorSpace.toString(); + return 0; }