From patchwork Wed Jul 8 13:43:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8670 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 CA04BBD792 for ; Wed, 8 Jul 2020 13:44:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9692161113; Wed, 8 Jul 2020 15:44:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="m6Gq0ud3"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1182B60E0D for ; Wed, 8 Jul 2020 15:44:32 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D9A6451B; Wed, 8 Jul 2020 15:44:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215871; bh=J1mYtl8y9ioXW3oCRqPcuLg6/kvOq/dUW0PJWivI2eY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m6Gq0ud3d2RnZn1P/uWEQusLy8NcwxoqizE4AJVutwHLehI513tOcRXdq6gvKV5x8 yvN/XUHVj9L3iBiTaDyOdcBqqIDfr+cuReweanKsXzwUXWOJobmGXV/qUWOsOCCuzX xLTajkSZxPl3DxNRrOCXsJOOc72/w0WfUKJXfN5U= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:43:57 +0900 Message-Id: <20200708134417.67747-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/21] libcamera: formats: Add NV24 and NV42, and reorder NV formats 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" Add formats for NV24 and NV42. While at it, reorder the NV formats so that NV12 and NV21 come first, followed by NV16, NV61, NV24, and NV42. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- No change in v4 No change in v3 --- src/libcamera/formats.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 436672e..d3b722c 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -256,6 +256,22 @@ const std::map pixelFormatInfo{ } }, /* YUV planar formats. */ + { formats::NV12, { + .name = "NV12", + .format = formats::NV12, + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12), + .bitsPerPixel = 12, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, + { formats::NV21, { + .name = "NV21", + .format = formats::NV21, + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21), + .bitsPerPixel = 12, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + } }, { formats::NV16, { .name = "NV16", .format = formats::NV16, @@ -272,19 +288,19 @@ const std::map pixelFormatInfo{ .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, } }, - { formats::NV12, { - .name = "NV12", - .format = formats::NV12, - .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12), - .bitsPerPixel = 12, + { formats::NV24, { + .name = "NV24", + .format = formats::NV24, + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV24), + .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, } }, - { formats::NV21, { - .name = "NV21", - .format = formats::NV21, - .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21), - .bitsPerPixel = 12, + { formats::NV42, { + .name = "NV42", + .format = formats::NV42, + .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV42), + .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, } }, From patchwork Wed Jul 8 13:43:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8671 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 28928BD792 for ; Wed, 8 Jul 2020 13:44:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E960D610B2; Wed, 8 Jul 2020 15:44:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kEDoGNBd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2ED00610F4 for ; Wed, 8 Jul 2020 15:44:34 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6DDB898D; Wed, 8 Jul 2020 15:44:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215873; bh=Nfaib4IhCD3KSptwgWpj6TioyweB84VcR/9b0uMjehY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kEDoGNBdcoZJuUMwpsWOjPgQYslVBRTQDonvVlu2MydnZZ7MEEg6f4/y3Yti2DMLh /0Tox6pw+3/fMt4yESXhi9blA3o/tl+qZh/BxI4hfsdW0+YWBat0dHcl4jtDOsv9Nr wiZYLzEt/zDQle/P3Jz67unfHFNi29e/1MX2UVT0= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:43:58 +0900 Message-Id: <20200708134417.67747-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 02/21] libcamera: formats: Add fields to info to ease calculating stride 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" Packed formats make it difficult to calculate stride as well as frame size with the fields that PixelFormatInfo currently has. bitsPerPixel is defined as the average number of bits per pixel, and only counts effective bits, so it is not useful for calculating stride and frame size. To fix this, we introduce a concept of a "pixel group". The size of this group is defined as the minimum number of pixels (including padding) necessary in a row when the image has only one column of effective pixels. The pixel group has one more attribute, that is the "bytes per group". This determines how many bytes one pixel group consumes. These are the fields pixelsPerGroup and bytesPerGroup that are defined in this patch. Defining these two values makes it really simple to calculate bytes-per-line, as ceil(width / pixelsPerGroup) * bytesPerGroup, where width is measured in number of pixels. The ceiling accounts for padding. The pixel group has another contraint, which is that the pixel group (bytesPerGroup and pixelsPerGroup) is the smallest repeatable unit. What this means is that, for example, in the IPU3 formats, if there is only one column of effective pixels, it looks like it could be fit in 5 bytes with 3 padding pixels (for a total of 4 pixels over 5 bytes). However, this unit is not repeatable, as at the 7th group in the same row, the pattern is broken. Therefore, the pixel group for IPU3 formats must be 25 pixels over 32 bytes. Clearly, pixelsPerGroup must be constant for all planes in the format. The bytesPerGroup then, must be a per-plane attribute. There is one more field, verticalSubSampling, that is per-plane. This is simply a divider, to divide the number of rows of pixels by the sub-sampling value, to obtain the number of rows of pixels for the subsampled plane. For example, for something simple like BGR888, it is self-explanatory: the pixel group size is 1, and the bytes necessary is 3, and there is only one plane with no (= 1) vertical subsampling. For YUYV, the CbCr pair is shared between two pixels, so even if you have only one pixel, you would still need a padded second Y, therefore the pixel group size is 2, and bytes necessary is 4 (as opposed to 1 and 2). YUYV also has no vertical subsampling. NV12 has a pixel group size of 2 pixels, due to the CbCr plane. The bytes per group then, for both planes, is 2. The first plane has no vertical subsampling, but the second plane is subsampled by a factor of 2. The IPU3 formats are also self-explanatory, as they are single-planar, and have a pixel group size of 25, consuming 32 bytes. Although a comment in the driver suggests that it should be 50 and 64, respectively, this is an attribute of the driver, and not the format, so this shall be set by the ipu3 pipeline handler. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- Changes in v4: - expanded documentation and definition of pixel group Changes in v3: - add planes - redefine the parameters for the formats - pixelsPerGroup is for whole format - add verticalSubSampling per plane Changes in v2: - add documentation for bytesPerGroup pixelsPerGroup - fix wording in commit message - bytes-per-line -> stride - buffer size -> frame size - changed MJPEG todo to allowing pipeline handlers to set parameters of format infos --- include/libcamera/internal/formats.h | 10 ++ src/libcamera/formats.cpp | 148 +++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index f59ac8f..61e5ff5 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -32,6 +32,12 @@ private: std::map> data_; }; +struct PixelFormatPlaneInfo +{ + unsigned int bytesPerGroup; + unsigned int verticalSubSampling; +}; + class PixelFormatInfo { public: @@ -52,6 +58,10 @@ public: unsigned int bitsPerPixel; enum ColourEncoding colourEncoding; bool packed; + + unsigned int pixelsPerGroup; + + std::array planes; }; } /* namespace libcamera */ diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index d3b722c..e6d3d3b 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -110,6 +110,22 @@ const std::map> &ImageFormats::data() const return data_; } +/** + * \class PixelFormatPlaneInfo + * \brief Information about a single plane of a pixel format + * + * \var PixelFormatPlaneInfo::bytesPerGroup + * \brief The number of bytes that a pixel group consumes + * + * \sa PixelFormatInfo::pixelsPerGroup + * + * \var PixelFormatPlaneInfo::verticalSubSampling + * \brief Vertical subsampling multiplier + * + * This value is the ratio between the number of rows of pixels in the frame + * to the number of rows of pixels in the plane. + */ + /** * \class PixelFormatInfo * \brief Information about pixel formats @@ -152,6 +168,49 @@ const std::map> &ImageFormats::data() const * bytes. For instance, 12-bit Bayer data with two pixels stored in three bytes * is packed, while the same data stored with 4 bits of padding in two bytes * per pixel is not packed. + * + * \var PixelFormatInfo::pixelsPerGroup + * \brief The number of pixels in a pixel group + * + * The minimum number of pixels (including padding) necessary in a row + * when the frame has only one column of effective pixels. + * + * A pixel group is defined as the minimum number of pixels (including padding) + * necessary in a row when the image has only one column of effective pixels. + * pixelsPerGroup refers to this value. PixelFormatPlaneInfo::bytesPerGroup, + * then, refers to the number of bytes that a pixel group consumes. This + * definition of a pixel group allows simple calculation of stride, as + * ceil(width / pixelsPerGroup) * bytesPerGroup. These values are determined + * only in terms of a row. The ceiling accounts for padding. + * + * A pixel group has a second constraint, such that the pixel group + * (bytesPerGroup and pixelsPerGroup) is the smallest repeatable unit. + * What this means is that, for example, in the IPU3 formats, if there is only + * one column of effective pixels, it looks like it could be fit in 5 bytes + * with 3 padding pixels (for a total of 4 pixels over 5 bytes). However, this + * unit is not repeatable, as at the 7th group in the same row, the pattern + * is broken. Therefore, the pixel group for IPU3 formats must be 25 pixels + * over 32 bytes. + * + * For example, for something simple like BGR888, it is self-explanatory: + * the pixel group size is 1, and the bytes necessary is 3, and there is + * only one plane with no (= 1) vertical subsampling. For YUYV, the + * CbCr pair is shared between two pixels, so even if you have only one + * pixel, you would still need a padded second Y sample, therefore the pixel + * group size is 2, and bytes necessary is 4. YUYV also has no vertical + * subsampling. NV12 has a pixel group size of 2 pixels, due to the CbCr plane. + * The bytes per group then, for both planes, is 2. The first plane has no + * vertical subsampling, but the second plane is subsampled by a factor of 2. + * The IPU3 formats are also self-explanatory, as they are single-planar, + * and have a pixel group size of 25, consuming 32 bytes. Although a + * comment in the driver suggests that it should be 50 and 64, + * respectively, this is an attribute of the driver, and not the format, so + * this shall be set by the ipu3 pipeline handler. + * + * \var PixelFormatInfo::planes + * \brief Information about pixels for each plane + * + * \sa PixelFormatPlaneInfo */ /** @@ -179,6 +238,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::RGB888, { .name = "RGB888", @@ -187,6 +248,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::ABGR8888, { .name = "ABGR8888", @@ -195,6 +258,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 32, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::ARGB8888, { .name = "ARGB8888", @@ -203,6 +268,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 32, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::BGRA8888, { .name = "BGRA8888", @@ -211,6 +278,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 32, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::RGBA8888, { .name = "RGBA8888", @@ -219,6 +288,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 32, .colourEncoding = PixelFormatInfo::ColourEncodingRGB, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, /* YUV packed formats. */ @@ -229,6 +300,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::YVYU, { .name = "YVYU", @@ -237,6 +310,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::UYVY, { .name = "UYVY", @@ -245,6 +320,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::VYUY, { .name = "VYUY", @@ -253,6 +330,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, /* YUV planar formats. */ @@ -263,6 +342,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 2, 2 }, { 0, 0 } }}, } }, { formats::NV21, { .name = "NV21", @@ -271,6 +352,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 2, 2 }, { 0, 0 } }}, } }, { formats::NV16, { .name = "NV16", @@ -279,6 +362,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 2, 1 }, { 0, 0 } }}, } }, { formats::NV61, { .name = "NV61", @@ -287,6 +372,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 2, 1 }, { 0, 0 } }}, } }, { formats::NV24, { .name = "NV24", @@ -295,6 +382,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 1, 1 }, { 2, 1 }, { 0, 0 } }}, } }, { formats::NV42, { .name = "NV42", @@ -303,6 +392,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 24, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 1, 1 }, { 2, 1 }, { 0, 0 } }}, } }, { formats::YUV420, { .name = "YUV420", @@ -311,6 +402,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 1, 2 }, { 1, 2 } }}, } }, { formats::YUV422, { .name = "YUV422", @@ -319,6 +412,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 16, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 1, 1 }, { 1, 1 } }}, } }, /* Greyscale formats. */ @@ -329,6 +424,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 8, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }}, } }, /* Bayer formats. */ @@ -339,6 +436,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 8, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG8, { .name = "SGBRG8", @@ -347,6 +446,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 8, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG8, { .name = "SGRBG8", @@ -355,6 +456,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 8, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB8, { .name = "SRGGB8", @@ -363,6 +466,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 8, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 2, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SBGGR10, { .name = "SBGGR10", @@ -371,6 +476,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG10, { .name = "SGBRG10", @@ -379,6 +486,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG10, { .name = "SGRBG10", @@ -387,6 +496,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB10, { .name = "SRGGB10", @@ -395,6 +506,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SBGGR10_CSI2P, { .name = "SBGGR10_CSI2P", @@ -403,6 +516,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 4, + .planes = {{ { 5, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG10_CSI2P, { .name = "SGBRG10_CSI2P", @@ -411,6 +526,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 4, + .planes = {{ { 5, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG10_CSI2P, { .name = "SGRBG10_CSI2P", @@ -419,6 +536,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 4, + .planes = {{ { 5, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB10_CSI2P, { .name = "SRGGB10_CSI2P", @@ -427,6 +546,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 4, + .planes = {{ { 5, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SBGGR12, { .name = "SBGGR12", @@ -435,6 +556,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG12, { .name = "SGBRG12", @@ -443,6 +566,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG12, { .name = "SGRBG12", @@ -451,6 +576,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB12, { .name = "SRGGB12", @@ -459,6 +586,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = false, + .pixelsPerGroup = 2, + .planes = {{ { 4, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SBGGR12_CSI2P, { .name = "SBGGR12_CSI2P", @@ -467,6 +596,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 2, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG12_CSI2P, { .name = "SGBRG12_CSI2P", @@ -475,6 +606,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 2, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG12_CSI2P, { .name = "SGRBG12_CSI2P", @@ -483,6 +616,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 2, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB12_CSI2P, { .name = "SRGGB12_CSI2P", @@ -491,6 +626,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 12, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 2, + .planes = {{ { 3, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SBGGR10_IPU3, { .name = "SBGGR10_IPU3", @@ -499,6 +636,9 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + /* \todo remember to double this in the ipu3 pipeline handler */ + .pixelsPerGroup = 25, + .planes = {{ { 32, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGBRG10_IPU3, { .name = "SGBRG10_IPU3", @@ -507,6 +647,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 25, + .planes = {{ { 32, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SGRBG10_IPU3, { .name = "SGRBG10_IPU3", @@ -515,6 +657,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 25, + .planes = {{ { 32, 1 }, { 0, 0 }, { 0, 0 } }}, } }, { formats::SRGGB10_IPU3, { .name = "SRGGB10_IPU3", @@ -523,6 +667,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 10, .colourEncoding = PixelFormatInfo::ColourEncodingRAW, .packed = true, + .pixelsPerGroup = 25, + .planes = {{ { 32, 1 }, { 0, 0 }, { 0, 0 } }}, } }, /* Compressed formats. */ @@ -533,6 +679,8 @@ const std::map pixelFormatInfo{ .bitsPerPixel = 0, .colourEncoding = PixelFormatInfo::ColourEncodingYUV, .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }}, } }, }; From patchwork Wed Jul 8 13:43:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8672 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 A7FB0BD792 for ; Wed, 8 Jul 2020 13:44:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7162761130; Wed, 8 Jul 2020 15:44:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VhHy43TX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 77DA760E0D for ; Wed, 8 Jul 2020 15:44:36 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ABAD151B; Wed, 8 Jul 2020 15:44:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215876; bh=4UVpqHMoycrn+HfPAUx7esnwTcyPAFJamfkL8e6JgCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VhHy43TXk3oDg9vWEFYNmvGeUfQtVUUT8RcwrQ4byHRnRV9kKc3BVeoajfDI3yjXV 7++l4DvibvjnH/m9iB0amIbvZHV1tBBtcM05ll5K2ER8pG+EN5cQWSTo4aysytJIv+ 6ZPIhmEGlwSg9ek5nBQ+7oVWTEaNPrEaPhQrWR6w= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:43:59 +0900 Message-Id: <20200708134417.67747-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/21] libcamera: StreamConfiguration: Add frameSize field 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" In addition to the stride field, we want the pipeline handler to be able to declare the frame size for the configuration. Add a frameSize field to StreamConfiguration for this purpose. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v4 New in v3 --- include/libcamera/stream.h | 1 + src/libcamera/stream.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h index 1a68bd2..f502b35 100644 --- a/include/libcamera/stream.h +++ b/include/libcamera/stream.h @@ -43,6 +43,7 @@ struct StreamConfiguration { PixelFormat pixelFormat; Size size; unsigned int stride; + unsigned int frameSize; unsigned int bufferCount; diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 6df5882..6d6e279 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -279,7 +279,8 @@ SizeRange StreamFormats::range(const PixelFormat &pixelformat) const * handlers provide StreamFormats. */ StreamConfiguration::StreamConfiguration() - : pixelFormat(0), stride(0), bufferCount(0), stream_(nullptr) + : pixelFormat(0), stride(0), frameSize(0), bufferCount(0), + stream_(nullptr) { } @@ -287,8 +288,8 @@ StreamConfiguration::StreamConfiguration() * \brief Construct a configuration with stream formats */ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) - : pixelFormat(0), stride(0), bufferCount(0), stream_(nullptr), - formats_(formats) + : pixelFormat(0), stride(0), frameSize(0), bufferCount(0), + stream_(nullptr), formats_(formats) { } @@ -315,6 +316,16 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) * the camera is configured. */ +/** + * \var StreamConfiguration::frameSize + * \brief Frame size for the stream, in bytes + * + * The frameSize value reports the number of bytes necessary to contain one + * frame of an image buffer for this stream. The value is valid after + * successfully validating the configuration with a call to + * CameraConfiguration::validate(). + */ + /** * \var StreamConfiguration::bufferCount * \brief Requested number of buffers to allocate for the stream From patchwork Wed Jul 8 13:44:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8673 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 1B3B3BD792 for ; Wed, 8 Jul 2020 13:44:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DBC806110E; Wed, 8 Jul 2020 15:44:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aB83DPqA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3812610B2 for ; Wed, 8 Jul 2020 15:44:38 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E961451B; Wed, 8 Jul 2020 15:44:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215878; bh=S1yYBgsYodW2MBXrCiolbEXcMDmCQ2tItVL/p2dD3S8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aB83DPqAFr0tzeGT2VeuTByD+g+mBIaxaL4G8GJrgGmzjclDYKfeycyoNExUquenx q4Ou3hocxpnkR0RqvlKkvzA+hlYukQLYw7QNjNDS0fn6a1coez4bYzqPwXKGeqdgX+ CAD4nsGd9EA/7Lrs+nu8pqXxzJhSlEbKZRM6Dqzs= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:00 +0900 Message-Id: <20200708134417.67747-5-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/21] libcamera: V4L2VideoDevice: Add tryFormat 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" Add tryFormat and its variations (meta, single-plane, multi-plane) to V4L2VideoDevice. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v4: - merge tryFormat{Meta,Multiplane,SinglePlane} into setFormat with a flag New in v3 --- include/libcamera/internal/v4l2_videodevice.h | 7 +-- src/libcamera/v4l2_videodevice.cpp | 50 ++++++++++++++----- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 4d21f5a..fb4c0aa 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -186,6 +186,7 @@ public: const V4L2Capability &caps() const { return caps_; } int getFormat(V4L2DeviceFormat *format); + int tryFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); std::map> formats(uint32_t code = 0); @@ -217,13 +218,13 @@ protected: private: int getFormatMeta(V4L2DeviceFormat *format); - int setFormatMeta(V4L2DeviceFormat *format); + int trySetFormatMeta(V4L2DeviceFormat *format, bool set); int getFormatMultiplane(V4L2DeviceFormat *format); - int setFormatMultiplane(V4L2DeviceFormat *format); + int trySetFormatMultiplane(V4L2DeviceFormat *format, bool set); int getFormatSingleplane(V4L2DeviceFormat *format); - int setFormatSingleplane(V4L2DeviceFormat *format); + int trySetFormatSingleplane(V4L2DeviceFormat *format, bool set); std::vector enumPixelformats(uint32_t code); std::vector enumSizes(V4L2PixelFormat pixelFormat); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 3614b2e..16c78b6 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -723,6 +723,26 @@ int V4L2VideoDevice::getFormat(V4L2DeviceFormat *format) return getFormatSingleplane(format); } +/** + * \brief Try an image format on the V4L2 video device + * \param[inout] format The image format to test applicability to the video device + * + * Try the supplied \a format on the video device without applying it, returning + * the format that would be applied. This is equivalent to setFormat(), except + * that the device configuration is not changed. + * + * \return 0 on success or a negative error code otherwise + */ +int V4L2VideoDevice::tryFormat(V4L2DeviceFormat *format) +{ + if (caps_.isMeta()) + return trySetFormatMeta(format, false); + else if (caps_.isMultiplanar()) + return trySetFormatMultiplane(format, false); + else + return trySetFormatSingleplane(format, false); +} + /** * \brief Configure an image format on the V4L2 video device * \param[inout] format The image format to apply to the video device @@ -735,11 +755,11 @@ int V4L2VideoDevice::getFormat(V4L2DeviceFormat *format) int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format) { if (caps_.isMeta()) - return setFormatMeta(format); + return trySetFormatMeta(format, true); else if (caps_.isMultiplanar()) - return setFormatMultiplane(format); + return trySetFormatMultiplane(format, true); else - return setFormatSingleplane(format); + return trySetFormatSingleplane(format, true); } int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format) @@ -765,7 +785,7 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format) return 0; } -int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format) +int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set) { struct v4l2_format v4l2Format = {}; struct v4l2_meta_format *pix = &v4l2Format.fmt.meta; @@ -774,9 +794,11 @@ int V4L2VideoDevice::setFormatMeta(V4L2DeviceFormat *format) v4l2Format.type = bufferType_; pix->dataformat = format->fourcc; pix->buffersize = format->planes[0].size; - ret = ioctl(VIDIOC_S_FMT, &v4l2Format); + ret = ioctl((set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT), &v4l2Format); if (ret) { - LOG(V4L2, Error) << "Unable to set format: " << strerror(-ret); + LOG(V4L2, Error) + << "Unable to " << (set ? "set" : "try") + << " format: " << strerror(-ret); return ret; } @@ -820,7 +842,7 @@ int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format) return 0; } -int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format) +int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set) { struct v4l2_format v4l2Format = {}; struct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp; @@ -838,9 +860,11 @@ int V4L2VideoDevice::setFormatMultiplane(V4L2DeviceFormat *format) pix->plane_fmt[i].sizeimage = format->planes[i].size; } - ret = ioctl(VIDIOC_S_FMT, &v4l2Format); + ret = ioctl((set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT), &v4l2Format); if (ret) { - LOG(V4L2, Error) << "Unable to set format: " << strerror(-ret); + LOG(V4L2, Error) + << "Unable to " << (set ? "set" : "try") + << " format: " << strerror(-ret); return ret; } @@ -883,7 +907,7 @@ int V4L2VideoDevice::getFormatSingleplane(V4L2DeviceFormat *format) return 0; } -int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format) +int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) { struct v4l2_format v4l2Format = {}; struct v4l2_pix_format *pix = &v4l2Format.fmt.pix; @@ -895,9 +919,11 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format) pix->pixelformat = format->fourcc; pix->bytesperline = format->planes[0].bpl; pix->field = V4L2_FIELD_NONE; - ret = ioctl(VIDIOC_S_FMT, &v4l2Format); + ret = ioctl((set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT), &v4l2Format); if (ret) { - LOG(V4L2, Error) << "Unable to set format: " << strerror(-ret); + LOG(V4L2, Error) + << "Unable to " << (set ? "set" : "try") + << " format: " << strerror(-ret); return ret; } From patchwork Wed Jul 8 13:44:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8674 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 87134BD792 for ; Wed, 8 Jul 2020 13:44:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5129861111; Wed, 8 Jul 2020 15:44:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KSCv6Tew"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F268E610B2 for ; Wed, 8 Jul 2020 15:44:40 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 32C6051B; Wed, 8 Jul 2020 15:44:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215880; bh=8LgF9NOvt4hYssHIdnkWKvBRkLxc9XOw36QpzihEHcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KSCv6TewGay3VzffVf3ab5wtPERxEY2qX0w79p3/sHTcmMeQM8TUVu21T7DMBXrvt 6OF5pJ8+m993hhyJBY1ma15xWNdMUZ5xQE/Jy5YgixTjKFUPLHJLhXGJ0wemRvPUq3 ZFn1YEES2u84ykarUEuxn6Nhezjx5/DvJFhfQ5hA= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:01 +0900 Message-Id: <20200708134417.67747-6-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/21] libcamera: formats: PixelFormatInfo: Add v4l2 lookup function 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" Add a lookup function for PixelFormatInfo that takes a V4L2PixelFormat. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v4 Changes in v3: - rename invalid PixelFormatInfo - make info const in PixelFormatInfo::info() Changes in v2: - move invalid PixelFormatInfo instance to anonymous namespace - add documentation --- include/libcamera/internal/formats.h | 1 + src/libcamera/formats.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 61e5ff5..054be37 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -50,6 +50,7 @@ public: bool isValid() const { return format.isValid(); } static const PixelFormatInfo &info(const PixelFormat &format); + static const PixelFormatInfo &info(const V4L2PixelFormat &format); /* \todo Add support for non-contiguous memory planes */ const char *name; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index e6d3d3b..6d96055 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -7,6 +7,7 @@ #include "libcamera/internal/formats.h" +#include #include #include @@ -229,6 +230,8 @@ const std::map> &ImageFormats::data() const namespace { +const PixelFormatInfo pixelFormatInfoInvalid{}; + const std::map pixelFormatInfo{ /* RGB formats. */ { formats::BGR888, { @@ -700,17 +703,33 @@ const std::map pixelFormatInfo{ */ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format) { - static const PixelFormatInfo invalid{}; - const auto iter = pixelFormatInfo.find(format); if (iter == pixelFormatInfo.end()) { LOG(Formats, Warning) << "Unsupported pixel format 0x" << utils::hex(format.fourcc()); - return invalid; + return pixelFormatInfoInvalid; } return iter->second; } +/** + * \brief Retrieve information about a pixel format + * \param[in] format The V4L2 pixel format + * \return The PixelFormatInfo describing the V4L2 \a format if known, or an + * invalid PixelFormatInfo otherwise + */ +const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) +{ + const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), + [format](auto pair) { + return pair.second.v4l2Format == format; + }); + if (info == pixelFormatInfo.end()) + return pixelFormatInfoInvalid; + + return info->second; +} + } /* namespace libcamera */ From patchwork Wed Jul 8 13:44:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8675 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 E52E9BD792 for ; Wed, 8 Jul 2020 13:44:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3EBF61124; Wed, 8 Jul 2020 15:44:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="izfWgpg4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC9FE610B2 for ; Wed, 8 Jul 2020 15:44:42 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 70D4D51B; Wed, 8 Jul 2020 15:44:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215882; bh=AyDMzbKkI5i3eRGnjzMm2HtvG29+dqw181TtVpwUvIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=izfWgpg4tYjOZKFJcpyfSrznTaSXh+V9OJY8tbmP9h44dkgbPlQHMQHY0YFcuxIAY ck5Fi7awq6GSuIsCLXsu43VHBFPfJlNptO5+Wd41GB8nmdgtKeMsQHSwdPLqkgO3FY IBucZLnVnIphuAu3Ue9hmQpyGIV7VCdyzTG8Y7mE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:02 +0900 Message-Id: <20200708134417.67747-7-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/21] libcamera: PixelFormatInfo: Add functions stride and frameSize 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" Add member functions to PixelFormatInfo for calculating stride and frame size. This will simplify existing code that calculates these things. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v4: - add overloaded frameSize() that takes array of strides - add optional parameter to stride() for byte alignment Changes in v3: - rename functions to stride and frameSize, from bytesPerLine and imageSize, respectively Changes in v2: - make these functions const - add documentation - inline DIV_ROUND_UP --- include/libcamera/internal/formats.h | 6 +++ src/libcamera/formats.cpp | 73 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 054be37..e347a46 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -52,6 +52,12 @@ public: static const PixelFormatInfo &info(const PixelFormat &format); static const PixelFormatInfo &info(const V4L2PixelFormat &format); + unsigned int stride(unsigned int width, unsigned int plane, + unsigned int align = 0) const; + unsigned int frameSize(const Size &size) const; + unsigned int frameSize(const Size &size, + const std::array &strides) const; + /* \todo Add support for non-contiguous memory planes */ const char *name; PixelFormat format; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 6d96055..c355e57 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -732,4 +732,77 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) return info->second; } +/** + * \brief Compute the stride + * \param[in] width The width of the line, in pixels + * \param[in] plane The index of the plane whose stride is to be computed + * \param[in] align The number of bytes to align to (0 for default alignment) + * \return The number of bytes necessary to store a line, or 0 if the + * PixelFormatInfo instance or the \a plane is not valid + */ +unsigned int PixelFormatInfo::stride(unsigned int width, unsigned int plane, + unsigned int align) const +{ + if (!isValid()) + return 0; + + if (plane > planes.size() || !planes[plane].bytesPerGroup) + return 0; + + /* ceil(width / pixelsPerGroup) * bytesPerGroup */ + unsigned int stride = (width + pixelsPerGroup - 1) / pixelsPerGroup + * planes[plane].bytesPerGroup; + + if (!align) + return stride; + + /* ceil(stride / align) * align */ + return (stride + align - 1) / align * align; +} + +/** + * \brief Compute the bytes necessary to store the frame + * \param[in] size The size of the frame, in pixels + * \return The number of bytes necessary to store the frame, or 0 if the + * PixelFormatInfo instance is not valid + */ +unsigned int PixelFormatInfo::frameSize(const Size &size) const +{ + /* stride * ceil(height / verticalSubSampling) */ + unsigned int sum = 0; + for (unsigned int i = 0; i < 3; i++) { + unsigned int vertSubSample = planes[i].verticalSubSampling; + if (!vertSubSample) + continue; + sum += stride(size.width, i) + * ((size.height + vertSubSample - 1) / vertSubSample); + } + + return sum; +} + +/** + * \brief Compute the bytes necessary to store the frame + * \param[in] size The size of the frame, in pixels + * \param[in] strides The strides to use for each plane + * \return The number of bytes necessary to store the frame, or 0 if the + * PixelFormatInfo instance is not valid + */ +unsigned int +PixelFormatInfo::frameSize(const Size &size, + const std::array &strides) const +{ + /* stride * ceil(height / verticalSubSampling) */ + unsigned int sum = 0; + for (unsigned int i = 0; i < 3; i++) { + unsigned int vertSubSample = planes[i].verticalSubSampling; + if (!vertSubSample) + continue; + sum += strides[i] + * ((size.height + vertSubSample - 1) / vertSubSample); + } + + return sum; +} + } /* namespace libcamera */ From patchwork Wed Jul 8 13:44:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8676 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 4F2E2BD792 for ; Wed, 8 Jul 2020 13:44:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B89761134; Wed, 8 Jul 2020 15:44:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="N+I8Guq5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2DA54610B2 for ; Wed, 8 Jul 2020 15:44:45 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 639F651B; Wed, 8 Jul 2020 15:44:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215884; bh=hkuYNV2ObJxY4DKu8MTYj46fActXDJrlaQiNEQWz7lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+I8Guq5mJqFdM4rDj9jtrB7hT0rsdFuHShT+tC/Ius26ShYB4VSt0j6Okw1o3Km6 5F/Zwr+38RyoOFDUT2QKwlUMXSKhNR7xBbpMhHRNkoBjqUsR2I1yNnpczCp+UKAf3r 9XesFi/ugVb/5b1wP2H4NGsQ+2i2Eh+f/O7zx9jI= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:03 +0900 Message-Id: <20200708134417.67747-8-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/21] v4l2: v4l2_camera_proxy: Get stride and frameSize from stream config 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 stride and frameSize should be obtained through StreamConfiguration rather than PixelFormatInfo, as pipeline handlers might have different values (eg. for alignment). Get the stride and frameSize values from StreamConfiguration instead of from PixelFormatInfo. This removes the need for V4L2CameraProxy's calculation helper functions (bplMultiplier, imageSize, v4l2ToDrm, drmToV4L2, calculateSizeImage) and formats, so remove them. This also removes the need for V4L2CameraProxy::calculateSizeImage, so remove it,. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v4: - squashed with "v4l2: v4l2_camera_proxy: Use libcamera formats" New in v3 --- src/v4l2/v4l2_camera_proxy.cpp | 192 ++++++--------------------------- src/v4l2/v4l2_camera_proxy.h | 8 -- 2 files changed, 32 insertions(+), 168 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index c246570..305ede0 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -20,6 +20,7 @@ #include #include +#include "libcamera/internal/formats.h" #include "libcamera/internal/log.h" #include "libcamera/internal/utils.h" @@ -70,7 +71,6 @@ int V4L2CameraProxy::open(V4L2CameraFile *file) vcam_->getStreamConfig(&streamConfig_); setFmtFromConfig(streamConfig_); - sizeimage_ = calculateSizeImage(streamConfig_); files_.insert(file); @@ -164,33 +164,22 @@ bool V4L2CameraProxy::validateMemoryType(uint32_t memory) void V4L2CameraProxy::setFmtFromConfig(StreamConfiguration &streamConfig) { - curV4L2Format_.fmt.pix.width = streamConfig.size.width; - curV4L2Format_.fmt.pix.height = streamConfig.size.height; - curV4L2Format_.fmt.pix.pixelformat = drmToV4L2(streamConfig.pixelFormat); - curV4L2Format_.fmt.pix.field = V4L2_FIELD_NONE; - curV4L2Format_.fmt.pix.bytesperline = - bplMultiplier(curV4L2Format_.fmt.pix.pixelformat) * - curV4L2Format_.fmt.pix.width; - curV4L2Format_.fmt.pix.sizeimage = - imageSize(curV4L2Format_.fmt.pix.pixelformat, - curV4L2Format_.fmt.pix.width, - curV4L2Format_.fmt.pix.height); - curV4L2Format_.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; - curV4L2Format_.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; - curV4L2Format_.fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; + const PixelFormatInfo &info = PixelFormatInfo::info(streamConfig.pixelFormat); + Size size = streamConfig.size; + + curV4L2Format_.fmt.pix.width = size.width; + curV4L2Format_.fmt.pix.height = size.height; + curV4L2Format_.fmt.pix.pixelformat = info.v4l2Format; + curV4L2Format_.fmt.pix.field = V4L2_FIELD_NONE; + curV4L2Format_.fmt.pix.bytesperline = info.stride(size.width, 0); + curV4L2Format_.fmt.pix.sizeimage = info.frameSize(size); + curV4L2Format_.fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; + curV4L2Format_.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; + curV4L2Format_.fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; curV4L2Format_.fmt.pix.quantization = V4L2_QUANTIZATION_DEFAULT; - curV4L2Format_.fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT; -} + curV4L2Format_.fmt.pix.xfer_func = V4L2_XFER_FUNC_DEFAULT; -unsigned int V4L2CameraProxy::calculateSizeImage(StreamConfiguration &streamConfig) -{ - /* - * \todo Merge this method with setFmtFromConfig (need imageSize to - * support all libcamera formats first, or filter out MJPEG for now). - */ - return imageSize(drmToV4L2(streamConfig.pixelFormat), - streamConfig.size.width, - streamConfig.size.height); + sizeimage_ = info.frameSize(size); } void V4L2CameraProxy::querycap(std::shared_ptr camera) @@ -253,12 +242,13 @@ int V4L2CameraProxy::vidioc_enum_framesizes(V4L2CameraFile *file, struct v4l2_fr { LOG(V4L2Compat, Debug) << "Servicing vidioc_enum_framesizes fd = " << file->efd(); - PixelFormat argFormat = v4l2ToDrm(arg->pixel_format); + V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->pixel_format); + PixelFormat format = PixelFormatInfo::info(v4l2Format).format; /* * \todo This might need to be expanded as few pipeline handlers * report StreamFormats. */ - const std::vector &frameSizes = streamConfig_.formats().sizes(argFormat); + const std::vector &frameSizes = streamConfig_.formats().sizes(format); if (arg->index >= frameSizes.size()) return -EINVAL; @@ -279,12 +269,14 @@ int V4L2CameraProxy::vidioc_enum_fmt(V4L2CameraFile *file, struct v4l2_fmtdesc * arg->index >= streamConfig_.formats().pixelformats().size()) return -EINVAL; + PixelFormat format = streamConfig_.formats().pixelformats()[arg->index]; + /* \todo Set V4L2_FMT_FLAG_COMPRESSED for compressed formats. */ arg->flags = 0; /* \todo Add map from format to description. */ utils::strlcpy(reinterpret_cast(arg->description), "Video Format Description", sizeof(arg->description)); - arg->pixelformat = drmToV4L2(streamConfig_.formats().pixelformats()[arg->index]); + arg->pixelformat = PixelFormatInfo::info(format).v4l2Format; memset(arg->reserved, 0, sizeof(arg->reserved)); @@ -306,7 +298,8 @@ int V4L2CameraProxy::vidioc_g_fmt(V4L2CameraFile *file, struct v4l2_format *arg) void V4L2CameraProxy::tryFormat(struct v4l2_format *arg) { - PixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat); + V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat); + PixelFormat format = PixelFormatInfo::info(v4l2Format).format; const std::vector &formats = streamConfig_.formats().pixelformats(); if (std::find(formats.begin(), formats.end(), format) == formats.end()) @@ -317,15 +310,14 @@ void V4L2CameraProxy::tryFormat(struct v4l2_format *arg) if (std::find(sizes.begin(), sizes.end(), size) == sizes.end()) size = streamConfig_.formats().sizes(format)[0]; + const PixelFormatInfo &formatInfo = PixelFormatInfo::info(format); + arg->fmt.pix.width = size.width; arg->fmt.pix.height = size.height; - arg->fmt.pix.pixelformat = drmToV4L2(format); + arg->fmt.pix.pixelformat = formatInfo.v4l2Format; arg->fmt.pix.field = V4L2_FIELD_NONE; - arg->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) * - arg->fmt.pix.width; - arg->fmt.pix.sizeimage = imageSize(drmToV4L2(format), - arg->fmt.pix.width, - arg->fmt.pix.height); + arg->fmt.pix.bytesperline = formatInfo.stride(size.width, 0); + arg->fmt.pix.sizeimage = formatInfo.frameSize(size); arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; arg->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; arg->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; @@ -350,18 +342,13 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg) tryFormat(arg); Size size(arg->fmt.pix.width, arg->fmt.pix.height); + V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat); ret = vcam_->configure(&streamConfig_, size, - v4l2ToDrm(arg->fmt.pix.pixelformat), + PixelFormatInfo::info(v4l2Format).format, bufferCount_); if (ret < 0) return -EINVAL; - unsigned int sizeimage = calculateSizeImage(streamConfig_); - if (sizeimage == 0) - return -EINVAL; - - sizeimage_ = sizeimage; - setFmtFromConfig(streamConfig_); return 0; @@ -495,27 +482,13 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf freeBuffers(); Size size(curV4L2Format_.fmt.pix.width, curV4L2Format_.fmt.pix.height); + V4L2PixelFormat v4l2Format = V4L2PixelFormat(curV4L2Format_.fmt.pix.pixelformat); int ret = vcam_->configure(&streamConfig_, size, - v4l2ToDrm(curV4L2Format_.fmt.pix.pixelformat), + PixelFormatInfo::info(v4l2Format).format, arg->count); if (ret < 0) return -EINVAL; - sizeimage_ = calculateSizeImage(streamConfig_); - /* - * If we return -EINVAL here then the application will think that we - * don't support streaming mmap. Since we don't support readwrite and - * userptr either, the application will get confused and think that - * we don't support anything. - * On the other hand, if the set format at the time of reqbufs has a - * zero sizeimage we'll get a floating point exception when we try to - * stream it. - */ - if (sizeimage_ == 0) - LOG(V4L2Compat, Warning) - << "sizeimage of at least one format is zero. " - << "Streaming this format will cause a floating point exception."; - setFmtFromConfig(streamConfig_); arg->count = streamConfig_.bufferCount; @@ -835,104 +808,3 @@ void V4L2CameraProxy::release(V4L2CameraFile *file) owner_ = nullptr; } - -struct PixelFormatPlaneInfo { - unsigned int bitsPerPixel; - unsigned int hSubSampling; - unsigned int vSubSampling; -}; - -struct PixelFormatInfo { - PixelFormat format; - uint32_t v4l2Format; - unsigned int numPlanes; - std::array planes; -}; - -namespace { - -static const std::array pixelFormatInfo = {{ - /* RGB formats. */ - { formats::RGB888, V4L2_PIX_FMT_BGR24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { formats::BGR888, V4L2_PIX_FMT_RGB24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { formats::BGRA8888, V4L2_PIX_FMT_ARGB32, 1, {{ { 32, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - /* YUV packed formats. */ - { formats::UYVY, V4L2_PIX_FMT_UYVY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { formats::VYUY, V4L2_PIX_FMT_VYUY, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { formats::YUYV, V4L2_PIX_FMT_YUYV, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - { formats::YVYU, V4L2_PIX_FMT_YVYU, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, - /* YUY planar formats. */ - { formats::NV12, V4L2_PIX_FMT_NV12, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, - { formats::NV21, V4L2_PIX_FMT_NV21, 2, {{ { 8, 1, 1 }, { 16, 2, 2 }, { 0, 0, 0 } }} }, - { formats::NV16, V4L2_PIX_FMT_NV16, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, - { formats::NV61, V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} }, - { formats::NV24, V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, - { formats::NV42, V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} }, - { formats::YUV420, V4L2_PIX_FMT_YUV420, 3, {{ { 8, 1, 1 }, { 8, 2, 2 }, { 8, 2, 2 } }} }, - { formats::YUV422, V4L2_PIX_FMT_YUV422P, 3, {{ { 8, 1, 1 }, { 8, 2, 1 }, { 8, 2, 1 } }} }, - /* Compressed formats. */ - /* - * \todo Get a better image size estimate for MJPEG, via - * StreamConfiguration, instead of using the worst-case - * width * height * bpp of uncompressed data. - */ - { formats::MJPEG, V4L2_PIX_FMT_MJPEG, 1, {{ { 16, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} }, -}}; - -} /* namespace */ - -/* \todo make libcamera export these */ -unsigned int V4L2CameraProxy::bplMultiplier(uint32_t format) -{ - auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), - [format](const PixelFormatInfo &info) { - return info.v4l2Format == format; - }); - if (info == pixelFormatInfo.end()) - return 0; - - return info->planes[0].bitsPerPixel / 8; -} - -unsigned int V4L2CameraProxy::imageSize(uint32_t format, unsigned int width, - unsigned int height) -{ - auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), - [format](const PixelFormatInfo &info) { - return info.v4l2Format == format; - }); - if (info == pixelFormatInfo.end()) - return 0; - - unsigned int multiplier = 0; - for (unsigned int i = 0; i < info->numPlanes; ++i) - multiplier += info->planes[i].bitsPerPixel - / info->planes[i].hSubSampling - / info->planes[i].vSubSampling; - - return width * height * multiplier / 8; -} - -PixelFormat V4L2CameraProxy::v4l2ToDrm(uint32_t format) -{ - auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), - [format](const PixelFormatInfo &info) { - return info.v4l2Format == format; - }); - if (info == pixelFormatInfo.end()) - return PixelFormat(); - - return info->format; -} - -uint32_t V4L2CameraProxy::drmToV4L2(const PixelFormat &format) -{ - auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(), - [format](const PixelFormatInfo &info) { - return info.format == format; - }); - if (info == pixelFormatInfo.end()) - return format; - - return info->v4l2Format; -} diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index d78a472..e962694 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -40,7 +40,6 @@ private: bool validateBufferType(uint32_t type); bool validateMemoryType(uint32_t memory); void setFmtFromConfig(StreamConfiguration &streamConfig); - unsigned int calculateSizeImage(StreamConfiguration &streamConfig); void querycap(std::shared_ptr camera); void tryFormat(struct v4l2_format *arg); enum v4l2_priority maxPriority(); @@ -69,13 +68,6 @@ private: int acquire(V4L2CameraFile *file); void release(V4L2CameraFile *file); - static unsigned int bplMultiplier(uint32_t format); - static unsigned int imageSize(uint32_t format, unsigned int width, - unsigned int height); - - static PixelFormat v4l2ToDrm(uint32_t format); - static uint32_t drmToV4L2(const PixelFormat &format); - static const std::set supportedIoctls_; unsigned int refcount_; From patchwork Wed Jul 8 13:44:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8677 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 BC303BD792 for ; Wed, 8 Jul 2020 13:44:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 871EA61130; Wed, 8 Jul 2020 15:44:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qJV/2lnC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20DA561136 for ; Wed, 8 Jul 2020 15:44:47 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A13C651B; Wed, 8 Jul 2020 15:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215886; bh=wV/EmtRy7qByINd29XeAOmiAY1i7R+jozVKVWd5lZL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJV/2lnCJvIqFZN5UJK4Tx4KRR49EoipH/4lwlsIIcjoezlfpvjNh+kK4s2gNDXBd HdDZICYy6ONsXx3QnTtvSTa+tXUdysqkjqmhrknE3p4j3s6bbG/De0qz3ZKMBWiMMr 8W0CJYPauQ2XCyI/BXK9ETmbpl8lKs5XUGeI3RX0= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:04 +0900 Message-Id: <20200708134417.67747-9-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/21] v4l2: v4l2_camera_proxy: Use stream config in tryFormat 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" For handling try_fmt, the values should be filled in by validating the stream configuration, and not by recalculating them or manually checking against the cached list of formats and sizes. Use V4L2Camera::validateConfiguration to obtain size, format, stride, and frameSize values. Also, implement this function in V4L2Camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v4: - clean up code a bit - squash the implementation and usage New in v3 --- src/v4l2/v4l2_camera.cpp | 20 ++++++++++++++++++++ src/v4l2/v4l2_camera.h | 3 +++ src/v4l2/v4l2_camera_proxy.cpp | 23 +++++++++-------------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index ffc1230..9f81c97 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -138,6 +138,26 @@ int V4L2Camera::configure(StreamConfiguration *streamConfigOut, return 0; } +int V4L2Camera::validateConfiguration(const PixelFormat &pixelFormat, + const Size &size, + StreamConfiguration *streamConfigOut) +{ + std::unique_ptr config = + camera_->generateConfiguration({ StreamRole::Viewfinder }); + StreamConfiguration &cfg = config->at(0); + cfg.size = size; + cfg.pixelFormat = pixelFormat; + cfg.bufferCount = 1; + + CameraConfiguration::Status validation = config->validate(); + if (validation == CameraConfiguration::Invalid) + return -EINVAL; + + *streamConfigOut = cfg; + + return 0; +} + int V4L2Camera::allocBuffers(unsigned int count) { Stream *stream = *camera_->streams().begin(); diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 515e906..be6c4e1 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -47,6 +47,9 @@ public: int configure(StreamConfiguration *streamConfigOut, const Size &size, const PixelFormat &pixelformat, unsigned int bufferCount); + int validateConfiguration(const PixelFormat &pixelformat, + const Size &size, + StreamConfiguration *streamConfigOut); int allocBuffers(unsigned int count); void freeBuffers(); diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 305ede0..5c92ff7 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -300,24 +300,19 @@ void V4L2CameraProxy::tryFormat(struct v4l2_format *arg) { V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat); PixelFormat format = PixelFormatInfo::info(v4l2Format).format; - const std::vector &formats = - streamConfig_.formats().pixelformats(); - if (std::find(formats.begin(), formats.end(), format) == formats.end()) - format = streamConfig_.formats().pixelformats()[0]; - Size size(arg->fmt.pix.width, arg->fmt.pix.height); - const std::vector &sizes = streamConfig_.formats().sizes(format); - if (std::find(sizes.begin(), sizes.end(), size) == sizes.end()) - size = streamConfig_.formats().sizes(format)[0]; - const PixelFormatInfo &formatInfo = PixelFormatInfo::info(format); + StreamConfiguration config; + vcam_->validateConfiguration(format, size, &config); + + const PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat); - arg->fmt.pix.width = size.width; - arg->fmt.pix.height = size.height; - arg->fmt.pix.pixelformat = formatInfo.v4l2Format; + arg->fmt.pix.width = config.size.width; + arg->fmt.pix.height = config.size.height; + arg->fmt.pix.pixelformat = info.v4l2Format; arg->fmt.pix.field = V4L2_FIELD_NONE; - arg->fmt.pix.bytesperline = formatInfo.stride(size.width, 0); - arg->fmt.pix.sizeimage = formatInfo.frameSize(size); + arg->fmt.pix.bytesperline = config.stride; + arg->fmt.pix.sizeimage = config.frameSize; arg->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; arg->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; arg->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; From patchwork Wed Jul 8 13:44:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8678 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 53DC4BD792 for ; Wed, 8 Jul 2020 13:44:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2051161111; Wed, 8 Jul 2020 15:44:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FkUFKhc4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CD4C6110E for ; Wed, 8 Jul 2020 15:44:49 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 93FF951B; Wed, 8 Jul 2020 15:44:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215889; bh=7AsjP/RSwx6wJiBdvga1b9O9G0aKSODLSpNJEBifihA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FkUFKhc4s/8EOfTk61TNZrS0WV+IgQL+RLCIF8vG4Wygf/Lm+Qfxa+tcZ3TsCGm6J mpDayVuqBxgHJrCuVtNQz+Hjg8EfZaMSEU5GEULA7h2cG1llmRcKUq1On7pqjbGvyw 0GjoBfyexodk7gZdeYCz/ORjdnu98pUKLL5nlmlo= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:05 +0900 Message-Id: <20200708134417.67747-10-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/21] libcamera: pipeline: raspberrypi: Simplify format fetching 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" Simplify code for looking up PixelFormatInfo using a V4L2 format by using the new PixelFormatInfo lookup function based on V4L2 format. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v4 No change in v3 Changes in v2: - just a few words in the commit message --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index f4966f8..1c0000b 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -81,8 +81,7 @@ V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req) /* Calculate the closest/best mode from the user requested size. */ for (const auto &iter : formatsMap) { V4L2PixelFormat v4l2Format = iter.first; - PixelFormat pixelFormat = v4l2Format.toPixelFormat(); - const PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat); + const PixelFormatInfo &info = PixelFormatInfo::info(v4l2Format); for (const SizeRange &sz : iter.second) { double modeWidth = sz.contains(req) ? req.width : sz.max.width; From patchwork Wed Jul 8 13:44:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8679 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 AA7CCBD792 for ; Wed, 8 Jul 2020 13:44:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 789F56110E; Wed, 8 Jul 2020 15:44:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="doTcMPge"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84FC1610B2 for ; Wed, 8 Jul 2020 15:44:51 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0BC651B; Wed, 8 Jul 2020 15:44:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215891; bh=ehz6Qvl2IPbvebt/pPa3jKsG2C9ufkwc/9WxOQI0+Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doTcMPgeCqBb02ehKIicRS/ueNoLIR77v6hgvDAcJ6B1rkAYMbelN6V9bhFVK/HAu rgXA7p9JPRgj06YnOPVo3AKM2zSP+lw0evQRRDwLqHfIHUNXDUwNx9eoqWX4eqUVoM pZkj64BLxhEaFB9zmYSK102XqKy5JOKX6WjjeIrU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:06 +0900 Message-Id: <20200708134417.67747-11-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 10/21] libcamera: pipeline: raspberrypi: Acquire media devices with acquireMediaDevice 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" Media devices should be acquired by pipeline handlers via PipelineHandler::acquireMediaDevice so that the media devices can be registered in the pipeline handler so that they can be automatically added to the devnum map for the v4l2 compatibility layer to use. Make the raspberrypi pipeline handler do this. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- No change in v4 No change in v3 --- .../pipeline/raspberrypi/raspberrypi.cpp | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 1c0000b..cbb6f1c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -374,7 +374,6 @@ class PipelineHandlerRPi : public PipelineHandler { public: PipelineHandlerRPi(CameraManager *manager); - ~PipelineHandlerRPi(); CameraConfiguration *generateConfiguration(Camera *camera, const StreamRoles &roles) override; int configure(Camera *camera, CameraConfiguration *config) override; @@ -401,8 +400,8 @@ private: int prepareBuffers(Camera *camera); void freeBuffers(Camera *camera); - std::shared_ptr unicam_; - std::shared_ptr isp_; + MediaDevice *unicam_; + MediaDevice *isp_; }; RPiCameraConfiguration::RPiCameraConfiguration(const RPiCameraData *data) @@ -502,15 +501,6 @@ PipelineHandlerRPi::PipelineHandlerRPi(CameraManager *manager) { } -PipelineHandlerRPi::~PipelineHandlerRPi() -{ - if (unicam_) - unicam_->release(); - - if (isp_) - isp_->release(); -} - CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, const StreamRoles &roles) { @@ -895,17 +885,14 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) isp.add("bcm2835-isp0-capture2"); /* Output 1 */ isp.add("bcm2835-isp0-capture3"); /* Stats */ - unicam_ = enumerator->search(unicam); + unicam_ = acquireMediaDevice(enumerator, unicam); if (!unicam_) return false; - isp_ = enumerator->search(isp); + isp_ = acquireMediaDevice(enumerator, isp); if (!isp_) return false; - unicam_->acquire(); - isp_->acquire(); - std::unique_ptr data = std::make_unique(this); /* Locate and open the unicam video streams. */ From patchwork Wed Jul 8 13:44:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8680 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 11068BD792 for ; Wed, 8 Jul 2020 13:44:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D08066113A; Wed, 8 Jul 2020 15:44:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YrpBVaq0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C31736112A for ; Wed, 8 Jul 2020 15:44:53 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0224D51B; Wed, 8 Jul 2020 15:44:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215893; bh=c89MD+LOXeobk9hIKyUv+20dlcY9m/6VtWWHeM7Qy1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YrpBVaq0kuJHk65NWOWyCv2rfmtK3jruEnLDjZiuSJjA/MpWRnbRVE6ljqgeiUQDY Dufhht7KmwrIYdHKaM6uRLUD7uB2PVMzjuWX5LswasY4cI/0kjGAC6f1cgRKpiAkj0 GpukfIN2Nw8WbkJ4Y+zBvWDMFSCtcK96DnBISb/k= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:07 +0900 Message-Id: <20200708134417.67747-12-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 11/21] libcamera: pipeline_handler: Fatal if registering camera without media 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" Pipeline handlers must acquire media devices via PipelineHander::acquireMediaDevice so that the media devices can be registered with the pipeline handler, so that they can be automatically added to the devnum map for the v4l2 compatibility layer to use. Die fatally if any camera trying to be registered has not acquired any media devices via acquireMediaDevice. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Cosmetic change in v4 No change in v3 --- src/libcamera/pipeline_handler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index de5ca09..ccd45ed 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -496,6 +496,10 @@ void PipelineHandler::registerCamera(std::shared_ptr camera, cameraData_[camera.get()] = std::move(data); cameras_.push_back(camera); + if (mediaDevices_.empty()) + LOG(Pipeline, Fatal) + << "Registering camera with no media devices!"; + /* * Walk the entity list and map the devnums of all capture video nodes * to the camera. From patchwork Wed Jul 8 13:44:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8681 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 662D8BD792 for ; Wed, 8 Jul 2020 13:44:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 326F961130; Wed, 8 Jul 2020 15:44:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rEOXAr2L"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A8A4610B2 for ; Wed, 8 Jul 2020 15:44:56 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3FFFB543; Wed, 8 Jul 2020 15:44:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215895; bh=JDAJxfXLGtJPbEVjdYdSlJVDeaNsQrWH2gcz/01jXk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rEOXAr2LCzKlS4OGBh41Sd/yzw+FlAt6stwqnDsbUNpgVOw7PVRFO3JyhuQyR8gNe vIzEfMJujeSZIktmpHc2KImG2jgTzJhmivNolN8/C2MhCfkQhcUSydBS9Ys5cpqsMR wJdorjTFQ9llHAaDq72mAM592zJG7HoZCgQy5Poc= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:08 +0900 Message-Id: <20200708134417.67747-13-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 12/21] libcamera: pipeline: raspberrypi: Filter out unsupported formats 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" Unsupported formats should not be added to the configuration when generating the configuration. Filter them out. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Cosmetic change in v4 No change in v3 --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index cbb6f1c..1822ac9 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -569,13 +569,11 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, /* Translate the V4L2PixelFormat to PixelFormat. */ std::map> deviceFormats; - std::transform(fmts.begin(), fmts.end(), std::inserter(deviceFormats, deviceFormats.end()), - [&](const decltype(fmts)::value_type &format) { - return decltype(deviceFormats)::value_type{ - format.first.toPixelFormat(), - format.second - }; - }); + for (const auto &format : fmts) { + PixelFormat pixelFormat = format.first.toPixelFormat(); + if (pixelFormat.isValid()) + deviceFormats[pixelFormat] = format.second; + } /* Add the stream format based on the device node used for the use case. */ StreamFormats formats(deviceFormats); From patchwork Wed Jul 8 13:44:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8682 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 C912CBD792 for ; Wed, 8 Jul 2020 13:44:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D8256110E; Wed, 8 Jul 2020 15:44:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wQTRy4gh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FAD7610B2 for ; Wed, 8 Jul 2020 15:44:58 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D84F51B; Wed, 8 Jul 2020 15:44:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215898; bh=fPY7M/0RpVuumEXbM3a4dtcC1l4V2CjWj3EppDjUAbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wQTRy4ghpNs9Y6SHZr/CInArA+CNN1azMdmCVecazbh81CLNfSSkh9c7ZXX9JnAJk oEks+BvU9yLygDKcoex7OpDIYs3XwNiazA/kqesuYljU2eB5vSblE97nkNeL2u8X+j LzfMO8hHH6RSEJiBdoTw99kTVKKBinWHtARZeoP4= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:09 +0900 Message-Id: <20200708134417.67747-14-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 13/21] libcamera: pipeline: uvcvideo: Filter out unsupported formats 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" Unsupported formats should not be added to the configuration when generating the configuration. Filter them out. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Cosmetic change in v4 No change in v3 --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 80a0e77..9db69dd 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -161,14 +161,11 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, std::map> v4l2Formats = data->video_->formats(); std::map> deviceFormats; - std::transform(v4l2Formats.begin(), v4l2Formats.end(), - std::inserter(deviceFormats, deviceFormats.begin()), - [&](const decltype(v4l2Formats)::value_type &format) { - return decltype(deviceFormats)::value_type{ - format.first.toPixelFormat(), - format.second - }; - }); + for (const auto &format : v4l2Formats) { + PixelFormat pixelFormat = format.first.toPixelFormat(); + if (pixelFormat.isValid()) + deviceFormats[pixelFormat] = format.second; + } StreamFormats formats(deviceFormats); StreamConfiguration cfg(formats); From patchwork Wed Jul 8 13:44:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8683 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 1E1D2BD792 for ; Wed, 8 Jul 2020 13:45:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E149B6113A; Wed, 8 Jul 2020 15:45:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jeWkBP+g"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CDA3610B2 for ; Wed, 8 Jul 2020 15:45:00 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A260551B; Wed, 8 Jul 2020 15:44:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215899; bh=GJxUpRt86Lep1STgHoHbsBtzVBV7BXPJyXTrsNluO1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jeWkBP+g2UhOyJHK8ONnEcgrWyaQtgs6ijYCA82tG067VwH48q9C43ZehrBktsnHL ZGm/MKCzrXAVdgF4HDhajfbUcjkA8126LFTe3sMFI5KTXxzwGgrW1/RFP0GL96nFZA USLNs6V2avfaoD914VV6ewFhL/PDAVQYIdKmOqxU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:10 +0900 Message-Id: <20200708134417.67747-15-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 14/21] libcamera: ipu3: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v4: - fix stride and frameSize calculation - mention motivation in commit message New in v3 --- src/libcamera/pipeline/ipu3/ipu3.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 00559ce..4a2d924 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -278,6 +278,21 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() << cfg.toString(); status = Adjusted; } + + const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); + bool packedRaw = info.packed && + info.colourEncoding == PixelFormatInfo::ColourEncodingRAW; + + if (packedRaw) { + cfg.stride = info.stride(cfg.size.width, 0, 64); + cfg.frameSize = cfg.stride * cfg.size.height; + } else { + cfg.stride = info.stride(cfg.size.width, 0); + std::array strides; + for (unsigned int j = 0; j < 3; j++) + strides[i] = info.stride(cfg.size.width, i, packedRaw ? 64 : 0); + cfg.frameSize = info.frameSize(cfg.size, strides); + } } return status; @@ -495,21 +510,13 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) if (ret) return ret; - cfg.stride = outputFormat.planes[0].bpl; outActive = true; } else if (stream == vfStream) { ret = imgu->configureViewfinder(cfg, &outputFormat); if (ret) return ret; - cfg.stride = outputFormat.planes[0].bpl; vfActive = true; - } else { - /* - * The RAW stream is configured as part of the CIO2 and - * no configuration is needed for the ImgU. - */ - cfg.stride = cio2Format.planes[0].bpl; } } From patchwork Wed Jul 8 13:44:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8684 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 8C279BD792 for ; Wed, 8 Jul 2020 13:45:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 55A5A6114A; Wed, 8 Jul 2020 15:45:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o2vN9I14"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE30A6112A for ; Wed, 8 Jul 2020 15:45:01 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C26651B; Wed, 8 Jul 2020 15:45:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215901; bh=vQsDGd/vlGY2JqCV6yA6cuhDncpUCfqX0sYfP5+q8fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2vN9I149UJYxXeogTh1cuINchK1a3KJahtpzYP6lIHKYnd3UZKcNn2aBVCGL2UjZ NFJQqUz8kYlSRz4x0iw+kJUiF4Ee7R1sFfKK670bjf9BpcIq1+oNTzMinqP60Vnk1U LD0ZK+8Dvudb+tZT4xo3M2zw/jBpngI2vxGCiDys= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:11 +0900 Message-Id: <20200708134417.67747-16-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 15/21] libcamera: raspberrypi: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Also set a default configuration size, in case the size is zero. Signed-off-by: Paul Elder --- Changes in v4: - mention motivation in commit message - also fill stride and frameSize in the default format New in v3 --- .../pipeline/raspberrypi/raspberrypi.cpp | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 1822ac9..d0ce446 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -427,6 +427,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() */ V4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size); + int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat); + if (ret) + return Invalid; + PixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat(); if (cfg.size != sensorFormat.size || cfg.pixelFormat != sensorPixFormat) { @@ -434,6 +438,10 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() cfg.pixelFormat = sensorPixFormat; status = Adjusted; } + + cfg.stride = sensorFormat.planes[0].bpl; + cfg.frameSize = sensorFormat.planes[0].size; + rawCount++; } else { outSize[outCount] = std::make_pair(count, cfg.size); @@ -478,19 +486,43 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * have that fixed up in the code above. * */ - PixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat; + StreamConfiguration &cfg = config_.at(outSize[i].first); + PixelFormat &cfgPixFmt = cfg.pixelFormat; + V4L2VideoDevice *dev; V4L2PixFmtMap fmts; - if (i == maxIndex) - fmts = data_->isp_[Isp::Output0].dev()->formats(); - else - fmts = data_->isp_[Isp::Output1].dev()->formats(); + if (i == maxIndex) { + dev = data_->isp_[Isp::Output0].dev(); + fmts = dev->formats(); + } else { + dev = data_->isp_[Isp::Output1].dev(); + fmts = dev->formats(); + } if (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) { /* If we cannot find a native format, use a default one. */ cfgPixFmt = formats::NV12; + + const PixelFormatInfo &info = PixelFormatInfo::info(cfgPixFmt); + cfg.size.width = 1920; + cfg.size.height = 1080; + cfg.stride = info.stride(cfg.size.width, 0); + cfg.frameSize = info.frameSize(cfg.size); + status = Adjusted; } + + V4L2DeviceFormat format = {}; + format.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = dev->tryFormat(&format); + if (ret) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + } return status; @@ -655,7 +687,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) if (isRaw(cfg.pixelFormat)) { cfg.setStream(&data->isp_[Isp::Input]); - cfg.stride = sensorFormat.planes[0].bpl; data->isp_[Isp::Input].setExternal(true); continue; } @@ -679,7 +710,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } cfg.setStream(&data->isp_[Isp::Output0]); - cfg.stride = format.planes[0].bpl; data->isp_[Isp::Output0].setExternal(true); } @@ -705,7 +735,6 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) */ if (!cfg.stream()) { cfg.setStream(&data->isp_[Isp::Output1]); - cfg.stride = format.planes[0].bpl; data->isp_[Isp::Output1].setExternal(true); } } From patchwork Wed Jul 8 13:44:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8685 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 21A41BD792 for ; Wed, 8 Jul 2020 13:45:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E434A6114E; Wed, 8 Jul 2020 15:45:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oR535Msj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E2E0E61143 for ; Wed, 8 Jul 2020 15:45:03 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6EADA51B; Wed, 8 Jul 2020 15:45:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215903; bh=adx+NstpqLwusRYFJCxGhc5+a16g4Y2IFq66xKcj2IE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oR535MsjZQC23sN24XnZCalelnighifu8gboDEjyg/wWkcHeOgsLDJD9B08dfyJO5 v4BVioFosygi1lE5RfShQhIep2pBceq4wTlCQj3Sali753QSYUGbfkkOVdZUw+Fdlc s06ftpVgiW3PmkZsl23VdVfiYIiSRbEy9BQGv5bg= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:12 +0900 Message-Id: <20200708134417.67747-17-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 16/21] libcamera: rkisp1: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- Changes in v4: - mention motivation in commit message - get stride and frameSize from tryFormat on the capture video node New in v3 --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 3c3f3f3..5ac2ecc 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -115,9 +115,9 @@ public: class RkISP1CameraData : public CameraData { public: - RkISP1CameraData(PipelineHandler *pipe) + RkISP1CameraData(PipelineHandler *pipe, V4L2VideoDevice *video) : CameraData(pipe), sensor_(nullptr), frame_(0), - frameInfo_(pipe) + frameInfo_(pipe), video_(video) { } @@ -135,6 +135,8 @@ public: RkISP1Frames frameInfo_; RkISP1Timeline timeline_; + V4L2VideoDevice *video_; + private: void queueFrameAction(unsigned int frame, const IPAOperationData &action); @@ -535,6 +537,17 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() cfg.bufferCount = RKISP1_BUFFER_COUNT; + V4L2DeviceFormat format = {}; + format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = data_->video_->tryFormat(&format); + if (ret) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + return status; } @@ -683,7 +696,6 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) return ret; cfg.setStream(&data->stream_); - cfg.stride = outputFormat.planes[0].bpl; return 0; } @@ -934,7 +946,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) int ret; std::unique_ptr data = - std::make_unique(this); + std::make_unique(this, video_); ControlInfoMap::Map ctrls; ctrls.emplace(std::piecewise_construct, From patchwork Wed Jul 8 13:44:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8686 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 752CBBD792 for ; Wed, 8 Jul 2020 13:45:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4214F6114D; Wed, 8 Jul 2020 15:45:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OqNp1CER"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AE7A6112A for ; Wed, 8 Jul 2020 15:45:06 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 61A0D51B; Wed, 8 Jul 2020 15:45:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215905; bh=r+Gazo8Aa1EouROuMjbG2l644fm1YCr6uy/wMMySwj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OqNp1CER/T/DDJZyqDPgDGR6OMYu59t9cMG8cbVqKDB35ydJqBNxyqzDbFA16LdH6 x42KdQJF2e4HfvQqF+dL2IayfoF21f9F2hbXVxN4rMsmj6/ZOeWL3GXzMx6pX95cNx GX4/eM8RgvLD7KK5vH9CqoSApX4RzvG2WpuweILc= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:13 +0900 Message-Id: <20200708134417.67747-18-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 17/21] libcamera: simple: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v4: - fix converter's stride and frameSize (get it via tryFormat instead of calculation) - merge converter's stride and frameSize to one function - return error if tryFormat fails - mention motivation in commit message New in v3 --- src/libcamera/pipeline/simple/converter.cpp | 19 +++++++++++++++ src/libcamera/pipeline/simple/converter.h | 4 +++ src/libcamera/pipeline/simple/simple.cpp | 27 +++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp index e5e2f0f..cef1503 100644 --- a/src/libcamera/pipeline/simple/converter.cpp +++ b/src/libcamera/pipeline/simple/converter.cpp @@ -261,4 +261,23 @@ void SimpleConverter::outputBufferReady(FrameBuffer *buffer) } } +int SimpleConverter::strideAndFrameSize(const Size &size, + const PixelFormat &pixelFormat, + unsigned int *strideOut, + unsigned int *frameSizeOut) +{ + V4L2DeviceFormat format = {}; + format.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat); + format.size = size; + + int ret = m2m_->capture()->tryFormat(&format); + if (ret < 0) + return -1; + + *strideOut = format.planes[0].bpl; + *frameSizeOut = format.planes[0].size; + + return 0; +} + } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h index ef18cf7..3e46988 100644 --- a/src/libcamera/pipeline/simple/converter.h +++ b/src/libcamera/pipeline/simple/converter.h @@ -46,6 +46,10 @@ public: int queueBuffers(FrameBuffer *input, FrameBuffer *output); + int strideAndFrameSize(const Size &size, const PixelFormat &pixelFormat, + unsigned int *strideOut, + unsigned int *frameSizeOut); + Signal bufferReady; private: diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 1ec8d0f..0c52b47 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -457,6 +457,31 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate() cfg.bufferCount = 3; + + /* Set the stride and frameSize. */ + if (!needConversion_) { + V4L2DeviceFormat format = {}; + format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = data_->video_->tryFormat(&format); + if (ret < 0) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + + return status; + } + + SimplePipelineHandler *pipe = static_cast(data_->pipe_); + SimpleConverter *converter = pipe->converter(); + + int ret = converter->strideAndFrameSize(cfg.size, cfg.pixelFormat, + &cfg.stride, &cfg.frameSize); + if (ret < 0) + return Invalid; + return status; } @@ -557,8 +582,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) return -EINVAL; } - cfg.stride = captureFormat.planes[0].bpl; - /* Configure the converter if required. */ useConverter_ = config->needConversion(); From patchwork Wed Jul 8 13:44:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8687 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 C0C96BD792 for ; Wed, 8 Jul 2020 13:45:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 905216113A; Wed, 8 Jul 2020 15:45:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lyqByvsp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 141AD6112A for ; Wed, 8 Jul 2020 15:45:08 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A09C851B; Wed, 8 Jul 2020 15:45:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215907; bh=iof/eFIAYUI83C0g4FhCc3+A81VxGgPrQS5fAebccvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyqByvspvDbUgonZv9z9fx9l4UsAKHz+CKDPg/sxp/RBTjE4Q0sCOQS5EMd2AVPYG 1kHB03OZ9R0X3KO6/Lk/uQULn9SwSAfJWwJIYIHN+lsOfzD4KCS+6u8Z0ssQDHIOTm 2xDvo2vBvNXO9U3jirRcgW/CQSIyQrXBQxlKzC1U= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:14 +0900 Message-Id: <20200708134417.67747-19-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 18/21] libcamera: uvcvideo: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v4: - return error if tryFormat fails - pass UVCCameraData to UVCCameraConfiguration, instead of V4l2VideoDevice - mention motivation in commit message New in v3 --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 9db69dd..47f383d 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -53,9 +53,12 @@ public: class UVCCameraConfiguration : public CameraConfiguration { public: - UVCCameraConfiguration(); + UVCCameraConfiguration(UVCCameraData *data); Status validate() override; + +private: + UVCCameraData *data_; }; class PipelineHandlerUVC : public PipelineHandler @@ -89,8 +92,8 @@ private: } }; -UVCCameraConfiguration::UVCCameraConfiguration() - : CameraConfiguration() +UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data) + : CameraConfiguration(), data_(data) { } @@ -141,6 +144,17 @@ CameraConfiguration::Status UVCCameraConfiguration::validate() cfg.bufferCount = 4; + V4L2DeviceFormat format = {}; + format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = data_->video_->tryFormat(&format); + if (ret) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + return status; } @@ -153,7 +167,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, const StreamRoles &roles) { UVCCameraData *data = cameraData(camera); - CameraConfiguration *config = new UVCCameraConfiguration(); + CameraConfiguration *config = new UVCCameraConfiguration(data); if (roles.empty()) return config; @@ -200,7 +214,6 @@ int PipelineHandlerUVC::configure(Camera *camera, CameraConfiguration *config) return -EINVAL; cfg.setStream(&data->stream_); - cfg.stride = format.planes[0].bpl; return 0; } From patchwork Wed Jul 8 13:44:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8688 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 1FCF6BD792 for ; Wed, 8 Jul 2020 13:45:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC0D06114E; Wed, 8 Jul 2020 15:45:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OrFHEoIu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1474C6112A for ; Wed, 8 Jul 2020 15:45:10 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 91FE451B; Wed, 8 Jul 2020 15:45:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215909; bh=A1GQXz7ImwqbDGp9VBrYQKOl1xTwPGCwgk2BOwYAQvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrFHEoIuR8cF+wJLRqiSULxl80d1qPmHm1v10TQMp0o8vvrAIkFgLMOW4N+LIUiX5 fXXMcZesglOmVDu7oaw5hVmw7u5gAxO5KIfSRQRCo66dMZVXmBAL4k7h6DXf5ulxt5 d/1CakFWk/us4+vP64M6ahZjlaSDswZViCler7tw= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:15 +0900 Message-Id: <20200708134417.67747-20-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 19/21] libcamera: vimc: Fill stride and frameSize at config validation 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" Fill the stride and frameSize fields of the StreamConfiguration at configuration validation time instead of at camera configuration time. This allows applications to get the stride when trying a configuration without modifying the active configuration of the camera. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- Changes in v4: - mention motivation in commit message - get stride and frameSize from tryFormat on capture video node New in v3 --- src/libcamera/pipeline/vimc/vimc.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index b653066..a6f457c 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -72,9 +72,12 @@ public: class VimcCameraConfiguration : public CameraConfiguration { public: - VimcCameraConfiguration(); + VimcCameraConfiguration(VimcCameraData *data); Status validate() override; + +private: + VimcCameraData *data_; }; class PipelineHandlerVimc : public PipelineHandler @@ -115,8 +118,8 @@ static const std::map pixelformats{ } /* namespace */ -VimcCameraConfiguration::VimcCameraConfiguration() - : CameraConfiguration() +VimcCameraConfiguration::VimcCameraConfiguration(VimcCameraData *data) + : CameraConfiguration(), data_(data) { } @@ -160,6 +163,17 @@ CameraConfiguration::Status VimcCameraConfiguration::validate() cfg.bufferCount = 4; + V4L2DeviceFormat format = {}; + format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat); + format.size = cfg.size; + + int ret = data_->video_->tryFormat(&format); + if (ret) + return Invalid; + + cfg.stride = format.planes[0].bpl; + cfg.frameSize = format.planes[0].size; + return status; } @@ -171,8 +185,8 @@ PipelineHandlerVimc::PipelineHandlerVimc(CameraManager *manager) CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera, const StreamRoles &roles) { - CameraConfiguration *config = new VimcCameraConfiguration(); VimcCameraData *data = cameraData(camera); + CameraConfiguration *config = new VimcCameraConfiguration(data); if (roles.empty()) return config; @@ -282,7 +296,6 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config) return ret; cfg.setStream(&data->stream_); - cfg.stride = format.planes[0].bpl; return 0; } From patchwork Wed Jul 8 13:44:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8689 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 7B595BD792 for ; Wed, 8 Jul 2020 13:45:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43FB66114B; Wed, 8 Jul 2020 15:45:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="El9dglL9"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 54D8A6112A for ; Wed, 8 Jul 2020 15:45:12 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84F6751B; Wed, 8 Jul 2020 15:45:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215912; bh=iUzgDUIl6wx+0Ba/u/OJHSInd7u/9mYQOHVAkRmnPaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=El9dglL9NHbaScqS7pA13Xk6CupFeOoPP34/QfVJibNfkVZVlA738DcVJj4NfE2VR zDXGPUgd8JjjxZQbNj1tru++TLI/+NL5Flh05mTUddIIWNCI5zc24BS8Ev3IPg5FcF xeWaUk0ONUzLmO7Q0/236+QzTfrp8lswwUU7Arp8= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:16 +0900 Message-Id: <20200708134417.67747-21-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 20/21] libcamera: StreamConfiguration: Update stride documentation 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" Now that all the pipeline handlers fill in the stride information at validation time, update the documentation accordingly. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- No change in v4 New in v3 --- src/libcamera/stream.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 6d6e279..d5da834 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -309,11 +309,8 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) * * The stride value reports the number of bytes between the beginning of * successive lines in an image buffer for this stream. The value is - * valid after successfully configuring the camera with this - * configuration with a call to Camera::Configure(). - * - * \todo Update this value when configuration is validated instead of when - * the camera is configured. + * valid after successfully validating the configuration with a call to + * CameraConfiguration::validate(). */ /** From patchwork Wed Jul 8 13:44:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8690 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 DB4E0BD792 for ; Wed, 8 Jul 2020 13:45:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A92246114B; Wed, 8 Jul 2020 15:45:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bbXoQ940"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F9BD6112A for ; Wed, 8 Jul 2020 15:45:14 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C26E451B; Wed, 8 Jul 2020 15:45:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594215914; bh=Y76cWm3jS1CcVT5hmHf3EU49LfWYrefHwqbT9EFavXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbXoQ940NX/2XLO4c6GVLsACrp6s/otVVxEGK9QJzvkyz2cl0TmwFAn4fpfCNyjG4 oS+NFCcaPduXfYy+gCzKWq3+xgTSzHNEzt0sonkh5Aq7Xa8ImHYDfeBhj4mGESAUjw rhqk6zXfywKgrvMh3DU28bXfdEtXBmrvaAR3jf4M= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Jul 2020 22:44:17 +0900 Message-Id: <20200708134417.67747-22-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708134417.67747-1-paul.elder@ideasonboard.com> References: <20200708134417.67747-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 21/21] v4l2: v4l2_camera: Fix stream selection for buffer operations 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 buffer operations in V4L2Camera were getting the stream from the wrong place. Fix it. Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- New in v4 --- src/v4l2/v4l2_camera.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index 9f81c97..61bca07 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -160,7 +160,7 @@ int V4L2Camera::validateConfiguration(const PixelFormat &pixelFormat, int V4L2Camera::allocBuffers(unsigned int count) { - Stream *stream = *camera_->streams().begin(); + Stream *stream = config_->at(0).stream(); return bufferAllocator_->allocate(stream); } @@ -169,13 +169,13 @@ void V4L2Camera::freeBuffers() { pendingRequests_.clear(); - Stream *stream = *camera_->streams().begin(); + Stream *stream = config_->at(0).stream(); bufferAllocator_->free(stream); } FileDescriptor V4L2Camera::getBufferFd(unsigned int index) { - Stream *stream = *camera_->streams().begin(); + Stream *stream = config_->at(0).stream(); const std::vector> &buffers = bufferAllocator_->buffers(stream);