From patchwork Wed Apr 26 13:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18553 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 C949FBDCBD for ; Wed, 26 Apr 2023 13:13:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 83B38627ED; Wed, 26 Apr 2023 15:13:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1682514800; bh=PuwVw5sfY27SM6qjnb0dc5kXg13QrdtvEMENojSPR1E=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ia5FwDuTqMvr/QOKsk+W0psAAQ4rjNhUi6fv/KEiD0MbM7FsYCbL+CFW+Y0j9rTUL QKEoiNDI5/rjuztRiQHnwI/MXYdG/oDngkgUQXkfD6E1ciHfIZKFK0Jh04HUTaHw0d WmZhVu/Sm8/PFCNoOU3EWngxBkd0Bsslj/CvIpVr3AE30LLXFZZ8aqGhABrt3kS9h1 hB7opZT1PC2pkMoU8Yfum6tCKMnDchDT4Za7W+eyOUSeVK3k/oHScnDX+N6BeCgX6M h6BTw38/HiiRySUCvDqhfG8OisOnsnnED8bhMQN74iffmOImjWDP2ZEYxhVPdSohXg aQIxyWtE59x3Q== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 05278627D6 for ; Wed, 26 Apr 2023 15:13:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="p41tga7g"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-2f9b9aa9d75so4515476f8f.0 for ; Wed, 26 Apr 2023 06:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1682514795; x=1685106795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jexy6v+bzoE8dH/G3OuVccEeF4d1I3E44a60uWXBTjE=; b=p41tga7gx6+ud8CbXlKyZJEf8VVDQATcr2DUzXLivYm/zsOsuumGWdZV5MuQsrdJMS IqC9WG1krhjM+4jcC/EPDqNGNwpfYGMrlsPnAHV2L+7pU+31XZ6I9vrV00ftWkrEVQoU ibqEeQM7gjb5jB4cUcQcbHDZw/togT22Be4PfgCUA4MT0mijtJcKiykiSz7fJUOIAPDw ZWavCpJ3wYDvsYXpEr0nGLc+LcITj0KYvtx+nUMXvzoMySmMBDw+/G7uwEormuKtT0wU LbslpUgDagzbKq5Ma0NeXUQurlyG8+wWVs7LKUXsiXeM749ywgKowM9Lzt3kUF9Rr5+u ouGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682514795; x=1685106795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jexy6v+bzoE8dH/G3OuVccEeF4d1I3E44a60uWXBTjE=; b=lOwObQVGh2CuLVTzTAYApOpXTaoWc3YKf0JjWG4hbsaPObZqgQXxXvx6equQdAlTzD dupIfnIcyhE0RKm9y9FA4dQQ9Ajqtopk3BfvCnp837XLPVyritTbd1DZETnX0M+GRGSp LXrgKz/LJfhz8y6wpZcD3HgCvP6jMbID29MKPI6R2KhM3oXK845TJB/AevRCCxu7xv+T wTLjgdhnKv8bLShRKpJ6HUGmtKvUiFWEoefIFLG9qQYwgO8L4Vi5j+i3aahWha08P2Ut FGuH+NobbMW6iIkujLH8Aa92OYc/UJwV2oZ2owQs1cC/6G+ARMMmXvZdss5AKR4i0+fo /NqA== X-Gm-Message-State: AAQBX9dFROl5mLdSu9auwIsZ+0FbySiB6Ht3kyI6rVbkNngbf3ZBWKEc QAY+EQtw5WMdlsjGsLYMGqqa22jfl6E4OrmDe/UYxA== X-Google-Smtp-Source: AKy350aXx2/wiPbv1OobzGVccxfmcWeautFYhtRQol+UJ9DP7tzub71Ca8IXnm3QLfMZ7i2Femi5Xw== X-Received: by 2002:adf:f7c5:0:b0:2fb:87f7:3812 with SMTP id a5-20020adff7c5000000b002fb87f73812mr13930782wrq.1.1682514795045; Wed, 26 Apr 2023 06:13:15 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id k5-20020adff5c5000000b002f103ca90cdsm15780949wrp.101.2023.04.26.06.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 06:13:14 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 26 Apr 2023 14:10:49 +0100 Message-Id: <20230426131057.21550-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426131057.21550-1-naush@raspberrypi.com> References: <20230426131057.21550-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/13] pipeline: raspberrypi: rpi_stream: Set invalid buffer to id == 0 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" At present, the RPiStream buffer ids == -1 indicates an invalid value. As a simplification, use id == 0 to indicate an invalid value. This allows for better code readability. As a consequence of this, use unsigned int for the buffer id values. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- .../pipeline/rpi/common/rpi_stream.cpp | 10 +++++----- src/libcamera/pipeline/rpi/common/rpi_stream.h | 18 +++++++++--------- src/libcamera/pipeline/rpi/vc4/raspberrypi.cpp | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp index 2bb10f25d6ca..3690667e9aa6 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.cpp +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.cpp @@ -55,17 +55,17 @@ const BufferMap &Stream::getBuffers() const return bufferMap_; } -int Stream::getBufferId(FrameBuffer *buffer) const +unsigned int Stream::getBufferId(FrameBuffer *buffer) const { if (importOnly_) - return -1; + return 0; /* Find the buffer in the map, and return the buffer id. */ auto it = std::find_if(bufferMap_.begin(), bufferMap_.end(), [&buffer](auto const &p) { return p.second == buffer; }); if (it == bufferMap_.end()) - return -1; + return 0; return it->first; } @@ -77,10 +77,10 @@ void Stream::setExternalBuffer(FrameBuffer *buffer) void Stream::removeExternalBuffer(FrameBuffer *buffer) { - int id = getBufferId(buffer); + unsigned int id = getBufferId(buffer); /* Ensure we have this buffer in the stream, and it is marked external. */ - ASSERT(id != -1 && (id & BufferMask::MaskExternalBuffer)); + ASSERT(id & BufferMask::MaskExternalBuffer); bufferMap_.erase(id); } diff --git a/src/libcamera/pipeline/rpi/common/rpi_stream.h b/src/libcamera/pipeline/rpi/common/rpi_stream.h index b8bd79cf1535..1aae674967e1 100644 --- a/src/libcamera/pipeline/rpi/common/rpi_stream.h +++ b/src/libcamera/pipeline/rpi/common/rpi_stream.h @@ -58,7 +58,7 @@ public: void setExportedBuffers(std::vector> *buffers); const BufferMap &getBuffers() const; - int getBufferId(FrameBuffer *buffer) const; + unsigned int getBufferId(FrameBuffer *buffer) const; void setExternalBuffer(FrameBuffer *buffer); void removeExternalBuffer(FrameBuffer *buffer); @@ -74,25 +74,25 @@ private: class IdGenerator { public: - IdGenerator(int max) + IdGenerator(unsigned int max) : max_(max), id_(0) { } - int get() + unsigned int get() { - int id; + unsigned int id; if (!recycle_.empty()) { id = recycle_.front(); recycle_.pop(); } else { - id = id_++; + id = ++id_; ASSERT(id_ <= max_); } return id; } - void release(int id) + void release(unsigned int id) { recycle_.push(id); } @@ -104,9 +104,9 @@ private: } private: - int max_; - int id_; - std::queue recycle_; + unsigned int max_; + unsigned int id_; + std::queue recycle_; }; void clearBuffers(); diff --git a/src/libcamera/pipeline/rpi/vc4/raspberrypi.cpp b/src/libcamera/pipeline/rpi/vc4/raspberrypi.cpp index cfde7f2e2229..e54bf1ef2c17 100644 --- a/src/libcamera/pipeline/rpi/vc4/raspberrypi.cpp +++ b/src/libcamera/pipeline/rpi/vc4/raspberrypi.cpp @@ -1210,7 +1210,7 @@ int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) continue; FrameBuffer *buffer = request->findBuffer(stream); - if (buffer && stream->getBufferId(buffer) == -1) { + if (buffer && !stream->getBufferId(buffer)) { /* * This buffer is not recognised, so it must have been allocated * outside the v4l2 device. Store it in the stream buffer list @@ -2042,7 +2042,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer) for (RPi::Stream &s : unicam_) { index = s.getBufferId(buffer); - if (index != -1) { + if (index) { stream = &s; break; } @@ -2098,7 +2098,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer) for (RPi::Stream &s : isp_) { index = s.getBufferId(buffer); - if (index != -1) { + if (index) { stream = &s; break; }