From patchwork Mon Sep 6 22:56:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13676 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 0E68ABE175 for ; Mon, 6 Sep 2021 22:57:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 966A46916D; Tue, 7 Sep 2021 00:57:14 +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="EgbkBjFn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 177146917A for ; Tue, 7 Sep 2021 00:57:03 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB877B75; Tue, 7 Sep 2021 00:57:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969022; bh=yKy+10GjDbrM8APjEW8E8CZpYga7jglPDb7x0BCWsUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EgbkBjFnIqo9ahAcx7zCA1asx1YfMDrBO9QN/AUzNR0DQsc+Wc5dA56Ju9lS0+j0C XxYfGERUEy79vvlaay06F+VQjBceiXQb/SoLPEgzQinoBrqcbq7W0t7HFvg3VOOQ/c Z4x68KTTjkfpSuQAghf0YvOrkwIFD416NW0M40vY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:16 +0300 Message-Id: <20210906225636.14683-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 10/30] libcamera: v4l2_videodevice: Cache PixelFormatInfo 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" Cache the PixelFormatInfo instead of looking it up in every call to createBuffer(). This prepares for usage of the info in queueBuffer(), to avoid a looking every time a buffer is queued. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda --- Changes since v1: - Add a comment to explain why formatInfo_ isn't guaranteed to be valid --- include/libcamera/internal/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 087ad067e37e..efe34d47e72b 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -241,6 +241,7 @@ private: V4L2Capability caps_; V4L2DeviceFormat format_; + const PixelFormatInfo *formatInfo_; enum v4l2_buf_type bufferType_; enum v4l2_memory memoryType_; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 1c4e6fbf7fe7..1483181a0856 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -482,8 +482,8 @@ const std::string V4L2DeviceFormat::toString() const * \param[in] deviceNode The file-system path to the video device node */ V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) - : V4L2Device(deviceNode), cache_(nullptr), fdBufferNotifier_(nullptr), - streaming_(false) + : V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr), + fdBufferNotifier_(nullptr), streaming_(false) { /* * We default to an MMAP based CAPTURE video device, however this will @@ -586,6 +586,8 @@ int V4L2VideoDevice::open() return ret; } + formatInfo_ = &PixelFormatInfo::info(format_.fourcc); + return 0; } @@ -681,6 +683,8 @@ int V4L2VideoDevice::open(int handle, enum v4l2_buf_type type) return ret; } + formatInfo_ = &PixelFormatInfo::info(format_.fourcc); + return 0; } @@ -695,6 +699,8 @@ void V4L2VideoDevice::close() releaseBuffers(); delete fdBufferNotifier_; + formatInfo_ = nullptr; + V4L2Device::close(); } @@ -787,6 +793,8 @@ int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format) return ret; format_ = *format; + formatInfo_ = &PixelFormatInfo::info(format_.fourcc); + return 0; } @@ -1325,19 +1333,23 @@ std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) planes.push_back(std::move(plane)); } - const auto &info = PixelFormatInfo::info(format_.fourcc); - if (info.isValid() && info.numPlanes() != numPlanes) { + /* + * The format info is not guaranteed to be valid, as there are no + * PixelFormatInfo for metadata formats, so check it first. + */ + if (formatInfo_->isValid() && formatInfo_->numPlanes() != numPlanes) { ASSERT(numPlanes == 1u); - const size_t numColorPlanes = info.numPlanes(); - planes.resize(numColorPlanes); + + planes.resize(formatInfo_->numPlanes()); const FileDescriptor &fd = planes[0].fd; size_t offset = 0; - for (size_t i = 0; i < numColorPlanes; ++i) { + + for (size_t i = 0; i < planes.size(); ++i) { planes[i].fd = fd; planes[i].offset = offset; /* \todo Take the V4L2 stride into account */ - planes[i].length = info.planeSize(format_.size, i); + planes[i].length = formatInfo_->planeSize(format_.size, i); offset += planes[i].length; } }