From patchwork Sat Sep 16 12:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19047 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 CEDFEC32B1 for ; Sat, 16 Sep 2023 12:19:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C2E462924; Sat, 16 Sep 2023 14:19:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694866789; bh=/ln7JqqBJ30qhFJf6xExSqV9yCyElhc+wER0kQIz3MI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gemnU+XvwySnPCDpomvVflJ71WX70mD92xDROfT5yDfXgVhp4JYqpWbI5I1pi0wxG m1ei7iJJh9NXmCUvR0/ax96KCO3gN1QTfAt4oU750U/hvmAJkC10tJ14jpYzYuAios C5mbH+YGnVmxaY9hO4p791tICBXslkCxkgaRO7VlTMK693lYD6Wgz+OeEjfwvpUTnQ eq+r+0GOcTFkrKJ5hz1YOx9O/6eI9Zz0/4hJwr8/dmQfrOFZyHLUC0ALXUFR2vk9Vd 1idXn42bru3HlS+Kbl74vTi5Jz6Yfu55eUAI8qbK1FO51+KOHpars8jgm55yUyGAZq sq58cHox0Xh2w== 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 3DE2D62929 for ; Sat, 16 Sep 2023 14:19:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kveqQFe6"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 277461536; Sat, 16 Sep 2023 14:18:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1694866687; bh=/ln7JqqBJ30qhFJf6xExSqV9yCyElhc+wER0kQIz3MI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kveqQFe6bZRWxbIFeLAd/aoP4LWCtpZyimpdSfVWsBAoFNvy2iXbguSDHB0siYNyq oS5I1yT3taOp8yNzsfISImepryKGPRDi13GaLqbvRN9DcywXVYUMCDVx+LELe9A90m GDGCCITtcg2q4xErXljgdq/zpyb1EpSu7GeyU3Dc= To: libcamera-devel@lists.libcamera.org Date: Sat, 16 Sep 2023 14:19:27 +0200 Message-ID: <20230916121930.29490-10-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230916121930.29490-1-jacopo.mondi@ideasonboard.com> References: <20230916121930.29490-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/12] libcamera: rpi: Add some helpers to PipelineHandlerBase 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Naushir Patuck Add a helper updateStreamConfig() that updates the format related fields in a StreamConfiguration from a given V4L2DeviceFormat structure. Add and override to the toV4L2DeviceFormat() helper that returns a V4L2DeviceFormat structure populated from the format related fields in a StreamConfiguration. Both these helper functions will be used in a future commit to simplify the Raspberry Pi pipeline handler configuration/validation code. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 47 +++++++++++++++++++ .../pipeline/rpi/common/pipeline_base.h | 4 ++ 2 files changed, 51 insertions(+) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index e7fedca7cc8d..93779556fd81 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -349,6 +349,53 @@ bool PipelineHandlerBase::isRaw(const PixelFormat &pixFmt) return BayerFormat::fromPixelFormat(pixFmt).isValid(); } +/* + * Adjust a StreamConfiguration fields to match a video device format. + * Returns true if the StreamConfiguration has been adjusted. + */ +bool PipelineHandlerBase::updateStreamConfig(StreamConfiguration *stream, + const V4L2DeviceFormat &format) +{ + const PixelFormat &pixFormat = format.fourcc.toPixelFormat(); + bool adjusted = false; + + if (stream->pixelFormat != pixFormat || stream->size != format.size) { + stream->pixelFormat = pixFormat; + stream->size = format.size; + adjusted = true; + } + + if (stream->colorSpace != format.colorSpace) { + stream->colorSpace = format.colorSpace; + adjusted = true; + LOG(RPI, Debug) + << "Color space changed from " + << ColorSpace::toString(stream->colorSpace) << " to " + << ColorSpace::toString(format.colorSpace); + } + + stream->stride = format.planes[0].bpl; + stream->frameSize = format.planes[0].size; + + return adjusted; +} + +/* + * Populate and return a video device format using a StreamConfiguration. */ +V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice *dev, + const StreamConfiguration *stream) +{ + V4L2DeviceFormat deviceFormat; + + const PixelFormatInfo &info = PixelFormatInfo::info(stream->pixelFormat); + deviceFormat.planesCount = info.numPlanes(); + deviceFormat.fourcc = dev->toV4L2PixelFormat(stream->pixelFormat); + deviceFormat.size = stream->size; + deviceFormat.colorSpace = stream->colorSpace; + + return deviceFormat; +} + V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice *dev, const V4L2SubdeviceFormat &format, BayerFormat::Packing packingReq) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 1a3a13dbb6cf..491c5e98c4a1 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -198,6 +198,10 @@ public: static bool isYuv(const PixelFormat &pixFmt); static bool isRaw(const PixelFormat &pixFmt); + static bool updateStreamConfig(StreamConfiguration *stream, + const V4L2DeviceFormat &format); + static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev, + const StreamConfiguration *stream); static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev, const V4L2SubdeviceFormat &format, BayerFormat::Packing packingReq);