From patchwork Wed May 3 12:20:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 18592 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 DFA66C0DA4 for ; Wed, 3 May 2023 12:20:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F1037633B8; Wed, 3 May 2023 14:20:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1683116447; bh=gDPuWDR/FP8/Bt2bGbP2yMnGTelSriSCxRaC5mk3gxw=; 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=aeLhMJ1dAU2cBbdbe6bJHaL5XUUNj3lAEg9ovyVoeqik9rkXFJeyHMi6MEvR2qYMN jmNq+3R1iw7wEbLVQMrGBEALFPfglaKaD1Vx6vSmdrcLxke6z+683cR003lPknvK3v Ba54Gcki+hldSPAdoXSRZdELrnSbuOGsOfbDrxuEmU1vbvWdG+2xi98qgyCtAJRU58 PgEGYj1YsyMBAR7uuXceWny/v9E9tx0s3+M+9Io3J5AyNyu+OZrtdi2ChHoRdRIeVS GfBO6ejnzI+R1TuOrHDmdjWT7NOQBTZVTCLrnPOiv/7nithhxXKfau6ureEkYhU0BP fcTcjc+pb+vEQ== Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 64370633BA for ; Wed, 3 May 2023 14:20:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="W7pfy2kI"; dkim-atps=neutral Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f18dacd392so32165355e9.0 for ; Wed, 03 May 2023 05:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1683116441; x=1685708441; 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=clZyTVs1q3LNKsG/a/hXCidK6h8JM4hhBxtTJnVMTYQ=; b=W7pfy2kInTTXH4mRpbxTUR2ETGOilhbCjgHFjt4ga/bGj2qtzbMH+ls/WVvDbcqM4D cEQwSL1JlZ+GQKW4lnBlbImTprn4Bnt4YMAC5jl8dQp3s6KnX1E5tRuvUybDrvIkJzaK QVXfYIoPGYi+Gdv4XRKB7pujDcOCNY1HU3Y6UkH5dhLFMyseGAxMYmZiDf7BmbD/SJS3 1da2FDh44pu16weJy+L9s2oRbZ1y82hZoNvgmlOLw+XVxcxJr32Od41tOiz+HYwl8QeJ mq1o1U9Shji6PhhodreW70eQ0cFroefp/KynJ3oc4VRscThPm2MXnVxWDkvlwsl/GF3j oR7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683116441; x=1685708441; 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=clZyTVs1q3LNKsG/a/hXCidK6h8JM4hhBxtTJnVMTYQ=; b=HT0sSlMSYj8bse+oaXyV3U9GVU4qhqCJ8BvcB2UYB6rw5T5LmLeh2h0/4gi4oYsEts 6F3GqNUTqMPfnoENRpWMkhWNsZcE7c79hooKFyYNA3CyrRu3C6daQNgl/ataNk3bqyT3 a0C8hfLg9eZ5zFs4dm4RBCkV46cX0XeAL1od1+dMZ3dWu2Ku2gToG5zex7bXniwiPW/s kqY76AIKeHCrMUJeOxAyxi3aExWcv2YHVfT/OX5BHkA4QEuZhFvLWszewJ0LGXtnf/KF Bi5opGFmDT51nwTp3i3RzjS4J88wb/AHfQQzKeAxpQDNli3b60v/eKspURcPI+w9Yw/q wjfw== X-Gm-Message-State: AC+VfDxHGPf/xFeKDwC5yp6kipMULtWMU9QYcCX+faHDOE35n8rjlD9k SGSZMdfAgwDfSoXfWzfAaG8WGtIFC83fI5bkgez9cg== X-Google-Smtp-Source: ACHHUZ4TDCoOQMemFjoGofESQv/SdV76KrjshHCMLMKZGssgm/Mx/aiSqpSitV4zfJj3XqitgxuT6w== X-Received: by 2002:a1c:4b1a:0:b0:3f1:954f:82e3 with SMTP id y26-20020a1c4b1a000000b003f1954f82e3mr14926947wma.24.1683116441672; Wed, 03 May 2023 05:20:41 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id f23-20020a7bcd17000000b003ee443bf0c7sm1736785wmj.16.2023.05.03.05.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 05:20:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 May 2023 13:20:29 +0100 Message-Id: <20230503122035.32026-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230503122035.32026-1-naush@raspberrypi.com> References: <20230503122035.32026-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/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 Cc: Jacopo Mondi 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 af464d153f28..96749c0d1318 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; }