From patchwork Mon Mar 7 12:46:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15426 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 0715FC3261 for ; Mon, 7 Mar 2022 12:46:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 77CAA604EC; Mon, 7 Mar 2022 13:46:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657201; bh=yvZddnRTtjoThmsHUks+8mxudSbdofrYzJUoaHH94Ys=; 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=2Os/ifDYPRVN8pwmFkKFA4p8jqT3WKBdBl381bGi1oW0XErxlH7p9U83q2/XpgbKi nIg9FQW+VEY06FNvXitA8eMlo3JASwT3VCGFVvOXoyCQZ8UgBH6/L/sE6s1p6PcVso WvZHyO3cYf0GjsYr48+0bXbBhGFJMQZNYW5TH0BbZ2n8G43KbrY396OydJz/D1Qeu3 kP2PrjvQmYMToqVmFzatj+ECxl7r50P80Q/DHRc9uO3/Q8QYl/2SB4rrWezPnqmXJ5 fBXWXvv2n9RUo25VWXmMjSknrWRHLBMItCdDN6bvdVUaXoiHojrldlzmLK5T/ZfO5T SgDkBP3TJSvpg== Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C7EC8604EC for ; Mon, 7 Mar 2022 13:46:39 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hQR849S1"; dkim-atps=neutral Received: by mail-wr1-x42e.google.com with SMTP id n15so8963434wra.6 for ; Mon, 07 Mar 2022 04:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ygJkOrdw8Zj5D+CKG9Kj3kJ5HukkraTyrN0mscQXzlk=; b=hQR849S1sp0jmrG4WkY/rLlFU5qTrLj/CyZ6j8unlgwlVEVTaPztxnopwAtl+BNqhq u5DTB5UgMb4Je5cK1bra6aKTuYZfODl0x3CY9OhswDHuiqrZI4EkXcVjrljRRRRM9jv4 dyfm6pCqnDho5Qj9JZ+OWOIwK4eI+IZd/K38Jtu6dCU31jjz18TS/NasuDGGZsX9BQKY y+eHKp53KbPnoTya8efW/+2CgHFD6Vqs46Q5gKWg+xsQpvZIVCnCWHGO3hwu+UTSofn3 ZR+ZsNCUGB2RoBDrYsA/UlyQG+b2sbXKLbM3fFYGk/tCNRRFB0H5wQtlGNbra6+lekn7 LDEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ygJkOrdw8Zj5D+CKG9Kj3kJ5HukkraTyrN0mscQXzlk=; b=667oWzQUV6TaPpu5tF9Ax9+YAyRCnIhMG4+5lFZanYm+SVyrGCKrQKXgewlNdAh+wf 6ygh6wU2MuxkmoGt6VH45dOF9oGx7v1a2RQM38WU1bNRJTyzUT5DWCa/pltXkaPksn90 Nke5or5bWB3tnY7yVi5B0DZfoqZoJCD1qgHYIBbQf5/8BP76RL0A6VZr4X8TxES9TQxA vTvmD5QEooOk5lj+ypu/kLilrZEA76sKJBJnCAcISLfXm7jaiH/+bnjWl3XbD1nI+set LalpMuk+uE+gWA8g71pCuystuIH1WSNTR2qrwb32AgZBMpW3sZDBpa4fi/G5Xmlwdj7I 8Bjw== X-Gm-Message-State: AOAM530czSRkL6NjGlmMtPfI99cG4fV3db9bFCd7ZYY4wEHreL7voR+Q fwsy6naeaXM8eGoRMwVSM/TyGHoo0dXkLA== X-Google-Smtp-Source: ABdhPJzfGYBwvMa1TWcE78yi43B7EPsOl6//SbWpzUEE8amtTpp6bR9frQYMj77wjtdBViNrQq1EUA== X-Received: by 2002:adf:e19d:0:b0:1f1:d7eb:71f with SMTP id az29-20020adfe19d000000b001f1d7eb071fmr8281495wrb.512.1646657199320; Mon, 07 Mar 2022 04:46:39 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:38 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:28 +0000 Message-Id: <20220307124633.115452-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/6] pipeline: raspberrypi: Avoid over-allocation for ISP Output 1 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" The V4L2DeviceFormat structure for the ISP Output 1 node was a copy of what is used ISP Output 1 node, but with the size changed. However, the plane size and stride values were not updated. So there is a possibility that the buffer might be over-sized for the requested resolution. Fix this by only copying the relevent fields from the ISP Output 0 V4L2DeviceFormat structure, and let the device driver size the planes as needed. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 29bff9d6eee4..d604c473c26c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -844,11 +844,13 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) * colour denoise will not run. */ if (!output1Set) { - V4L2DeviceFormat output1Format = format; + V4L2DeviceFormat output1Format; constexpr Size maxDimensions(1200, 1200); const Size limit = maxDimensions.boundedToAspectRatio(format.size); output1Format.size = (format.size / 2).boundedTo(limit).alignedDownTo(2, 2); + output1Format.colorSpace = format.colorSpace; + output1Format.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420); LOG(RPI, Debug) << "Setting ISP Output1 (internal) to " << output1Format.toString(); From patchwork Mon Mar 7 12:46:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15427 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 1520ABF415 for ; Mon, 7 Mar 2022 12:46:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F1DAB6118F; Mon, 7 Mar 2022 13:46:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657203; bh=FyyHGeWhlB5LY2jQX1WYbJUW6Xuvj0MggkhDKWIoB/4=; 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=KcpoggUDAC6RUHKsC42UXx4atXB6guIh/GHf/FEwBX2aBDZQ3GFJtEQjscnRRLpTx LyAzNtUzkRnLXFMhHRiukruU4ntmjiprQdwemS/WGRewSe4vCW2MkW63QZlLVQ29ot m2G5h3w6+aaBYDYI53ZEw4NZupdTG9vyiAJd3nV9sx9kbrBgAJYXeJOcJyqExDPp4i l6LYS4hft5XxR8+GcP7zwLRpWfeyMWOru9YsL+98IRJfCz2ZeUfmeU1k3DHrYpHJvZ zRWv14B4cMOtwdU2ltDTwIm1i8KVmid8QSEzhknRqIbsMnxFFeHDDRB+4Z5IyZGakP d5SmBi3+hwsUw== Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9303561184 for ; Mon, 7 Mar 2022 13:46:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="UwPGii3N"; dkim-atps=neutral Received: by mail-wm1-x334.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so10674901wmq.4 for ; Mon, 07 Mar 2022 04:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wi8Ibf1/9HKLHB0vE2sv4ocKlb9cP2TxaZ7cUSBfnZw=; b=UwPGii3NnV5tIrttOPYx+AEtOzGE77qpv25+yKHBmsXQ1CjwoOCTW5B7rTeZugbX9k S6mthUZHSjTBLTM/hqER6kwvZX9MUNBtOZ21PAhUTw3ar9blBp1W+YLjQ5ic1k/axWBi ad6qp2Igi3SsldVhvOpWUpLiuTejcTxOMVqRZzy4VR4DA3mGrfuQIS3EVEeDWDmT5ZOQ LOHjsi6fsQAVD3uEJm5BXOWLIXyGC45Zn15T1DO3EAD+spLueY1oBSIranD8oL2keHdC SZGy5fDe/8CcazZeiOvqWW85iXNSza1zrEl6stQDWo5amOVy73tiETfN7DwErmM4qj5d C1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wi8Ibf1/9HKLHB0vE2sv4ocKlb9cP2TxaZ7cUSBfnZw=; b=0LFzA5XVa6bOCMn/9EDyahhIotErm5VkH2OW1W/mucGnbO0RZjP1acgkQ6PDslf7nt kDi2KT8HDDsh6sZqOPNp8eez6t4If+iPCqinf2EGTks6sgGJ5FZi2JyicPaXm6nIrzzh frxStKLyEai0Urw8P8sgLk81yUT0JvnUsswjfBj006oiWMcHgOaGnhhe+jd1lj136R2b BjjWmGk2IoY19R6NDM7cbGpGla+92IiTrruuP5PW0HuQv0fJubAHCZBf9fuwThH2Ez7J WQ0bfx2r9VEGsQszOoiAXtbxT4DLn+NNrmZHgXAh/OptVSLLcCgt8qB47QBWOqki2346 SuOg== X-Gm-Message-State: AOAM532BBthX5wDaO6iStkWAusI1fMDkATptWd8Y2V00n4v1N5OnHi/0 2yFJMu2hR67vsd05XaN1jhqaSVSonkF9aQ== X-Google-Smtp-Source: ABdhPJw0GUBTMoWa6Yb1gGqo5NQ/JHcK1KojjzJd7sW4APXGdPexncv0HerYDqXQzbXgbqv7E8HUoQ== X-Received: by 2002:a7b:cc8f:0:b0:389:844e:9e28 with SMTP id p15-20020a7bcc8f000000b00389844e9e28mr8769874wma.67.1646657200025; Mon, 07 Mar 2022 04:46:40 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:39 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:29 +0000 Message-Id: <20220307124633.115452-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/6] pipeline: raspberrypi: Move freeBuffers() to the RPiCameraData class 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" This function used to clear the camera buffers does not belong in the PipelineHandlerRPi class as it only access members of the RPiCameraData, so move it. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index d604c473c26c..3781e4e0e3c4 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -189,6 +189,7 @@ public: { } + void freeBuffers(); void frameStarted(uint32_t sequence); int loadIPA(ipa::RPi::SensorConfig *sensorConfig); @@ -329,7 +330,6 @@ private: int registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity); int queueAllBuffers(Camera *camera); int prepareBuffers(Camera *camera); - void freeBuffers(Camera *camera); void mapBuffers(Camera *camera, const RPi::BufferMap &buffers, unsigned int mask); }; @@ -1049,7 +1049,7 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - freeBuffers(camera); + data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) @@ -1445,16 +1445,14 @@ void PipelineHandlerRPi::mapBuffers(Camera *camera, const RPi::BufferMap &buffer data->ipa_->mapBuffers(ipaBuffers); } -void PipelineHandlerRPi::freeBuffers(Camera *camera) +void RPiCameraData::freeBuffers() { - RPiCameraData *data = cameraData(camera); - /* Copy the buffer ids from the unordered_set to a vector to pass to the IPA. */ - std::vector ipaBuffers(data->ipaBuffers_.begin(), data->ipaBuffers_.end()); - data->ipa_->unmapBuffers(ipaBuffers); - data->ipaBuffers_.clear(); + std::vector ipaBuffers(ipaBuffers_.begin(), ipaBuffers_.end()); + ipa_->unmapBuffers(ipaBuffers); + ipaBuffers_.clear(); - for (auto const stream : data->streams_) + for (auto const stream : streams_) stream->releaseBuffers(); } From patchwork Mon Mar 7 12:46:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15428 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 C57C5C3261 for ; Mon, 7 Mar 2022 12:46:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 87F796118E; Mon, 7 Mar 2022 13:46:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657204; bh=Ny4pRakMea6WwmHE/ip3My7NZuljg35QW0IflMAlaAY=; 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=02JSk1F/C/0yJgsBzLhmaJAYiZpUrPzqw8bidVHACk2YUPmgxhgrlmx/6A3XfIsFn 4ft1p1q1t8Rjt6wsHp3mPDU79pj+WN0aGZXeMFUF1M1FZ17enHHDW2eIKJOAnvVTd4 p7sBivsl70qXcI8BdCLP6DH9IbFprJQ6zyl4/vCwsyJLLG8Zagd2fnAQwhF2Ljm9tE sACN+qgwAg7nmr1KABihebxZUzDDZNMUrg5LtynySm2oOqsYiY1FoboSJxZmaGsTMq e+zKYj1auhdMQ91bBxpxFYovLK5VheroIcfV41jp30QhjswQhyPVfLqGG65y610Zx1 tjJqBIuzcTm2w== Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69E2F6118D for ; Mon, 7 Mar 2022 13:46:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gJbUeA8a"; dkim-atps=neutral Received: by mail-wm1-x335.google.com with SMTP id m42-20020a05600c3b2a00b00382ab337e14so10083243wms.3 for ; Mon, 07 Mar 2022 04:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hlaMJcXVUCEb9tdJXTlISVfKaEdBnc5bcEQgwsCnoqA=; b=gJbUeA8aBoq0NPOhNRuKUyKjHEJUt19Lb+xzjzROFNTlIBgvC0nDy+ZYWgBOWhSnSD JacqFvXM4fogQti7l/gGYpNtySSqzuLxk7GqubBsAm9JhOnNhPoUW1qSoelj69S2++ax N37xxqLyePtrUmjmGSdD2cFxgwobTtg3/NCrKWALYZmFfbgEJDRyHOZc1Jry328SZN5L s07nEIfCuk1JyjNLGyH1nd6i47lr+8y5ReI11K6cDU0DCu5ZTJSwzyeimVzb8C3K5Y6F hF06l4ulaOVdmG8fm7b7lgWDsyz0XhDwl4aDXMXhO172uIYKWFSklXwd05RUv/0o/bBe 63Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hlaMJcXVUCEb9tdJXTlISVfKaEdBnc5bcEQgwsCnoqA=; b=JsCVZVFScwcutrkTt8a8os1wOJ5larIrPB54d/4+IG22Kx/q99y8mmcPDkGKvFyE1e IWwA9lMOQ6klLHx2I7mCQBnxnvERLou2y0RSaCV8TKMQNKkbleTq51ud/IcduzOnsu+/ HCwyXpRuYkJliW5ismhjksE3q5Dnx79LIlCHzfRucvWTUkmrmzPLL2rQZ45YdesOx2C1 udf4a/D8JQWz9FGx/+Nm/6wL2WccrgypYLzUHR4HI4nZv6Quq6+9m1/EhuHqZ+wiudfh IXOct6gXeJ8vlEfd8VsGaru8pdXwqT0mtliU+QLmU1yVrJR98dV/zyE/PIFxFVQN6J8g qf8A== X-Gm-Message-State: AOAM533Z8QglRa78M3YPE6wDY64L7YvxAWiQNefy2FjCVpgnNMrb9Z3Z 5ptQrTy3kLj1bsasjeH3lYCbezeE5G04PA== X-Google-Smtp-Source: ABdhPJzqOd1E3i6pfIhSxg1uBHCV03uLDuc0Re2ZmlJTJbVZE432npcqjvmy091n9tCGw/5VXWfKLA== X-Received: by 2002:a7b:c19a:0:b0:381:8495:9dd with SMTP id y26-20020a7bc19a000000b00381849509ddmr18282751wmi.33.1646657200753; Mon, 07 Mar 2022 04:46:40 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:40 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:30 +0000 Message-Id: <20220307124633.115452-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/6] pipeline: raspberrypi: Free buffers in the RPiCamera destructor and re-configure 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" Currently, all framebuffer allocations get freed and cleared on a stop in PipelineHandlerRPi::stopDevice(). If PipelineHandlerRPi::start() is then called without an intermediate PipelineHandlerRPi::configure(), it will re-allocate and prepare all the buffers again, which is unnecessary. Fix this by not freeing the buffer in PipelineHandlerRPi::stopDevice(), but insted doing it in PipelineHandlerRPi::configure(), as the buffers might have to be resized. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 3781e4e0e3c4..8bb9fc429912 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -189,6 +189,11 @@ public: { } + ~RPiCameraData() + { + freeBuffers(); + } + void freeBuffers(); void frameStarted(uint32_t sequence); @@ -681,7 +686,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) RPiCameraData *data = cameraData(camera); int ret; - /* Start by resetting the Unicam and ISP stream states. */ + /* Start by freeing all buffers and resetting the Unicam and ISP stream states. */ + data->freeBuffers(); for (auto const stream : data->streams_) stream->reset(); @@ -1048,8 +1054,6 @@ void PipelineHandlerRPi::stopDevice(Camera *camera) /* Stop the IPA. */ data->ipa_->stop(); - - data->freeBuffers(); } int PipelineHandlerRPi::queueRequestDevice(Camera *camera, Request *request) From patchwork Mon Mar 7 12:46:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15429 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 448D4BF415 for ; Mon, 7 Mar 2022 12:46:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E32B061188; Mon, 7 Mar 2022 13:46:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657204; bh=6MgXuBq9A5ndq932NEyBE2cXkbnHy+qmvaaXMto9RgY=; 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=YStwT8rIQMschB9lngTvWnJx7qyvOtT+eFkum81/VU4VH/N1c3Zbd0QsC0AcNxIn1 +Llk/dcYdI3EPm6gV2nYVN0ba6dBMFvCDWJXZSTE6w7k33x13qzJ+BENbersD9u9kw Cgvl5ggXTcHwN11TCLxkK7Nzr8FgHNvO4v9k01i8N/vk2lmHrJv/Nb+RaraIH9uY4P 1FsaympICs8IUmIio0mBdt2AoOynNj5oepcnQKXfCmZTYDkJ0VnL5M2tp5dsIKToX9 uRjfPYhdO1Qku50pAJAlQz/U/G1TcvTB/9KkOB8B3MFmXGD0ALZK7waX2ixSzDYq/G kOBjE1aTyMA+A== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 120DB61188 for ; Mon, 7 Mar 2022 13:46:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="XTgw/cZz"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id n33-20020a05600c3ba100b003832caf7f3aso6574792wms.0 for ; Mon, 07 Mar 2022 04:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FwE3is+453vYZw7fiwo7M2TBoZaBxbvn3vvjqH/LPPA=; b=XTgw/cZzOJfhCziGhFlRnazkHr1DwSpYgM/pSzyDVV/+wUM4uoarDHqcRkIS+44zO+ bWCIh0iufvkIh54eRjuAqsDgbSYdy0QOKL+ZJAmlhTMpU5gfyHTW1oeHSnok/FCuO7xE hUdINGht/H/FJom2Yu/S8s79Um7oph3vDdvIC5cNPQwibFZ+klF7Mw8maD6Ug6ZUoZIP ypM1VqoHzmd8jUGS/1htueeatAn9WPsOTV81qACcJXGFUW9mvuRoe0e6dOvvkSEAsUXg aol+lF6qixrWwN/NLuSKz4QZrqgp8up2agwpd9RZLURF+K0jFbucMkK/RB4MHI6V2se/ VCuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FwE3is+453vYZw7fiwo7M2TBoZaBxbvn3vvjqH/LPPA=; b=mPe9axvR7Z9IxBYr/DSxK/zCMRJ1zSbbsaFCok3g9m1NGh8vH3Q2myQZ/pnji++Lh7 gj8RgStcwdpBzoA36ppTCnm1RWMfLJ9AwYGhrQjaUoJUZHRQrP2d/6RbDaRn/ZvowIZ/ V30rdqDC/or2oYtvelW23QzfuLuUzwxMCn2TMU+b7+JaLAJzLJjr0/qhIP2OzCK2N6j9 H8s5zttmeLnFRYokquBfSNRurwoKJRm5+bQ3QEhR81H1a6XVQ93cOR7OSLGBnCEYrH2I uiIT2kG+y0TqEi8Wo2DXi5k6PoRt2fgD606TmXMUprcW4AYJQ31ZeyA72+lbeD+GLM49 e3ww== X-Gm-Message-State: AOAM530KC0j+txggl+FqdDtihn5VCZjGaycurbOdYCblR7Vc6bl1N9XN d9V4eFOZwbGGlxUqS84z+xR77z8zbHVUnw== X-Google-Smtp-Source: ABdhPJwrUWK2VfOYlNyb/PwqsFEpFRS5QIuKNuBMqlVbsig02OwCrZCALIeENg/7AUau04GKA3pLpw== X-Received: by 2002:a05:600c:3009:b0:381:194a:8cb5 with SMTP id j9-20020a05600c300900b00381194a8cb5mr8774892wmh.43.1646657201552; Mon, 07 Mar 2022 04:46:41 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:40 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:31 +0000 Message-Id: <20220307124633.115452-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 4/6] pipeline: raspberrypi: Add a reconfigured flag 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" Add a flag to indicate a call to PipelineHandlerRPi::configure() has taken place. This flag signals that buffer allocations need to be done on the next call to PipelineHandlerRPi::start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- .../pipeline/raspberrypi/raspberrypi.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 8bb9fc429912..b17ffa235ac7 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -185,7 +185,7 @@ public: RPiCameraData(PipelineHandler *pipe) : Camera::Private(pipe), state_(State::Stopped), supportsFlips_(false), flipsAlterBayerOrder_(false), - dropFrameCount_(0), ispOutputCount_(0) + dropFrameCount_(0), reconfigured_(true), ispOutputCount_(0) { } @@ -284,6 +284,9 @@ public: */ std::optional notifyGainsUnity_; + /* Has this camera been reconfigured? */ + bool reconfigured_; + private: void checkRequestCompleted(); void fillRequestMetadata(const ControlList &bufferControls, @@ -961,6 +964,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) << " on pad " << sinkPad->index(); } + data->reconfigured_ = true; return ret; } @@ -981,12 +985,15 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; - /* Allocate buffers for internal pipeline usage. */ - ret = prepareBuffers(camera); - if (ret) { - LOG(RPI, Error) << "Failed to allocate buffers"; - stop(camera); - return ret; + if (data->reconfigured_) { + /* Allocate buffers for internal pipeline usage. */ + ret = prepareBuffers(camera); + if (ret) { + LOG(RPI, Error) << "Failed to allocate buffers"; + stop(camera); + return ret; + } + data->reconfigured_ = false; } /* Check if a ScalerCrop control was specified. */ From patchwork Mon Mar 7 12:46:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15430 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 B3F4FBF415 for ; Mon, 7 Mar 2022 12:46:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7340B611AA; Mon, 7 Mar 2022 13:46:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657206; bh=89vP4h/0JGP1S0biwi5aT70xvGgC0Q2ql9qcMP/BapY=; 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=h8OxAXJwRq67UePrkE4bBHAiqVMKdhM2eQ6qvogfTJ79oiMnxSXsZQfAils37JpGU 3sSOJwKO24cOImlxr6wbPpCS3BhJX6mEoaEDlDlTQyCmk4W0LztLNLvFHH3aJeh/1V LuKGN/oUKHJJGjsdxbNITpg0Yf9UU1tipqFJuGBueO94cS7UPMxv3FvP8zR2c8CSAr gc5NQCd4j0H0ltJfjRqZJf62Mj5njYAibfA3aI57BAiVX4uY/c8E/x3deS9Up2V0yo XybJgnQHSXKqGM1c54ikaFVyLO2cC78ztemPgJcYWygmSKwHXGySbeFnaSx/ZKN3Zr voWxc+LT1kYrQ== Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCC9361187 for ; Mon, 7 Mar 2022 13:46:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="X7sGvniJ"; dkim-atps=neutral Received: by mail-wr1-x42d.google.com with SMTP id p9so23068375wra.12 for ; Mon, 07 Mar 2022 04:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bnmw6O5W7PZnoxsUF508AY4VM/IN+j4579ahBbZHVc4=; b=X7sGvniJQC59sOcX5aWGyi89Nu7r4sryVVMxgqb0K3flEntjvDwBsSDd9avP7emSLT 3+JEDwrASHeruiViHvp9FsrrLpDbBPZgRSuoQMKpisfpdj+rKA0iSOLfhN3TcJEHQ+fV w3zpxqy3khFq4Gs+vUgxCMWOv0dMJGDqapWXr44mSh+A7ZycSMmRUZPOPFGZTUp8vMvF FdYxbSTKMB4nwDFJiRa3Qv1z9OuTLXZXvT1t7HbhVJ1gx1AdEn8AvZzFq1aJJCNF5Dp6 jBlppHrfba6ta2x90VLKdULmHtjgwxWMIi+DC7O8Xz45zOdDjoli+sInfBPyuhSEtdDU 5maA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bnmw6O5W7PZnoxsUF508AY4VM/IN+j4579ahBbZHVc4=; b=MN0fph7RRN2/4tnfE1hHO2tpvBLnWE4RDAjJL1ssmGD4LLVi30DEYBZEJuh6e/FIrL 4qKoTAlmMF7A3rKRguvQkiXd6ZKcVDpdl7980B+wBdHjPHpSua+Zeo6Jl9LrTMS+ukGB NXOIeb2RGV+UQzBa449Quabf8lkyJ99sllLMT5zFxqvhfPJrsWidh0HS1nlHT/LHMA5V 62h2dUOp7UH+BRFuo84jvWJrsELAxzxhv3iCN2b2dvYf1sP8i/K8FOHqTdsp0O8p5xTM gbaMTDvqzl1C0TFttD4wx4FiEkiTXHHHR2p1ZfaequEDiXSup0JF3FO5HrbSQMawCyon 8FjA== X-Gm-Message-State: AOAM533YHcmT0ucYuaspiCvvFNqXtM8y6QGq5sCGzVRibv93uXFB67vD VFYRGvj653ACnmZkdci0QbASR15jLR1QYg== X-Google-Smtp-Source: ABdhPJzMzJSUhF8aji/7BJMx93k19GwQSj9pfAaGoeIVLu2gjPM+Ix3Jxil3zwtidUp+j+IW8tulIg== X-Received: by 2002:adf:f48e:0:b0:1f0:636a:1bbd with SMTP id l14-20020adff48e000000b001f0636a1bbdmr8472956wro.580.1646657202339; Mon, 07 Mar 2022 04:46:42 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:41 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:32 +0000 Message-Id: <20220307124633.115452-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 5/6] pipeline: raspberrypi: Repurpose RPi::Stream::reset() 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" The original use of RPi::Stream::reset() was to clear the external flag state and free/clear out the framebuffers for the stream. However, the latter is now done through PipelineHandlerRPi::configure(). Rework PipelineHandlerRPi::configure() to call RPi::Stream::setExternal() instead of RPi::Stream::reset() to achieve the same thing. Repurpose RPi::Stream::reset() to instead reset the state of the buffer handling logic, where all internally allocated buffers are put back into the queue of available buffers. This reset() is now called from PipelineHandlerRPi::start(), allowing the pipeline handler to correctly deal with start()/stop()/start() sequences and reusing the buffers allocated on the first start(). Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Tested-by: David Plowman --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 5 ++++- src/libcamera/pipeline/raspberrypi/rpi_stream.cpp | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index b17ffa235ac7..193361686d3c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -692,7 +692,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) /* Start by freeing all buffers and resetting the Unicam and ISP stream states. */ data->freeBuffers(); for (auto const stream : data->streams_) - stream->reset(); + stream->setExternal(false); BayerFormat::Packing packing = BayerFormat::Packing::CSI2; Size maxSize, sensorSize; @@ -985,6 +985,9 @@ int PipelineHandlerRPi::start(Camera *camera, const ControlList *controls) RPiCameraData *data = cameraData(camera); int ret; + for (auto const stream : data->streams_) + stream->reset(); + if (data->reconfigured_) { /* Allocate buffers for internal pipeline usage. */ ret = prepareBuffers(camera); diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp index f446e1ce66c7..0840ec4f54a0 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -28,8 +28,10 @@ std::string Stream::name() const void Stream::reset() { - external_ = false; - clearBuffers(); + /* Add all internal buffers to the queue of usable buffers. */ + availableBuffers_ = {}; + for (auto const &buffer : internalBuffers_) + availableBuffers_.push(buffer.get()); } void Stream::setExternal(bool external) @@ -97,10 +99,7 @@ int Stream::prepareBuffers(unsigned int count) /* Add these exported buffers to the internal/external buffer list. */ setExportedBuffers(&internalBuffers_); - - /* Add these buffers to the queue of internal usable buffers. */ - for (auto const &buffer : internalBuffers_) - availableBuffers_.push(buffer.get()); + reset(); } /* We must import all internal/external exported buffers. */ From patchwork Mon Mar 7 12:46:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15431 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 29282C3261 for ; Mon, 7 Mar 2022 12:46:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D696761192; Mon, 7 Mar 2022 13:46:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1646657206; bh=j1yifcg2H5tqFnHv5TxW4VZaUjGkXmlKngikuNYDKKU=; 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=VFdU59WONTNb0hMSL+4X/6LbD3vujt65mXWqeKA+CFnrmZs1gM1O7wenqBZBNwmvi 8rpuw8+47RglGsCFMmH3orXxDFlLOEGWfs9P2cRgPKOZYlfbE5pc7awYDW19cethH9 NaKQ/Yf8sfKQPSZf4amFiyAU9r8i7iR/3Cuog/iW4W+mtVhqml3ArGkWSqZLXUfEL6 0f31PUfZAn16Svln0mIrwSQU8B7hI26eBBrlogOHdHHtEmQ0aBeS4vm+mZcQ2mVjAh ptx9TykYEEhJoTwd3VTNJ6zshw1MT61xJ9LP1qhRRpmW1vdHV+eeQ9yUW6MTHHc4h1 uNRc8D14DwugA== Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBDB761189 for ; Mon, 7 Mar 2022 13:46:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="f9lzWf3G"; dkim-atps=neutral Received: by mail-wr1-x436.google.com with SMTP id u1so23051409wrg.11 for ; Mon, 07 Mar 2022 04:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=; b=f9lzWf3G7OIDRAoSKWl1YLJqgzVINBtEdrq+w69QuV5t/v4AkHf4qAoXBz7deLa4ZP VRCwjURp6ufZ5teFeV3TllWt2EDL1nzNmYZ+RWYNUbNrkb/RIoHR+Vmsu4a/eSxitl5R cvZrAgakNNzIUjhlDkhgiR5mcDH84VpcHvN9Isjce0PNbd/mat9B0e2a71scRgsP7xkY HRv71Q09YF1xYEXALKgyVaDAHnryxyMm3nzkqw1u8N5wkBuityoe7qHyvm/2AU+1MGZi /QfcKsiyY4/QxBnXJJg1xTkORPJf6LCiaPwtalkip2J7axsa+6RuXhhDFdhbVeFE02PD 6LXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PRkhqrlp04FHuT3lgzDxfAUE/vo6bJn9nSQyQ3qDDVQ=; b=ayWcLpj5wJnz+Ww0AVS3bIIioA2rYouq7G91nyCzi6LF49KqQz2DVjQuhjNXIAw6e7 T6fLp6dx/xiNBUrbpY8TRA6vif3TZnatG4KQiMI0ORQ479D6m4BUVH7R/NYnzfQYnMz/ I4tOVGZQ6rPMJh2sU0wNkIv89925fa7f5wajQ0weWluGvaEKFEv+ucMTn4fKSPNWxrc5 KwT4Vlrna2U6wCShiqUaYHZeNVH/ASZDLj4dDVfnT3aKXLL9/wuEW09t7TSFmrUP5U7x QDK2CF4wdVaA/2CSY9MbaClfJD0PrzrqIUePc5WzvsKUF3zaxkv9l3C34BusEkVES/EM nTVQ== X-Gm-Message-State: AOAM531MWUQKmDvFEOy9lUVlMVwHQiT/is/nyQvYYROwhjW9apsaNl5C Jw03b1KMgoLYfq/qqb7g98f0AdK3XM+OZA== X-Google-Smtp-Source: ABdhPJxke08C4cGunZzAowhxRMzVxMnRtJWGXX3Kkrrxocln93zHO1Htesai7RgbKdttpuheFhpVQw== X-Received: by 2002:a5d:538b:0:b0:1f1:e60b:20c2 with SMTP id d11-20020a5d538b000000b001f1e60b20c2mr5982636wrv.294.1646657203211; Mon, 07 Mar 2022 04:46:43 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:c644:e9b3:de0b:54c5]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b0037c4e2d3baesm19759582wma.19.2022.03.07.04.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 04:46:42 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Mar 2022 12:46:33 +0000 Message-Id: <20220307124633.115452-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307124633.115452-1-naush@raspberrypi.com> References: <20220307124633.115452-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 6/6] libcamera: v4l2_videodevice: Empty the V4L2 buffer cache on streamOff() 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" When streamOff() is called, ensure the cache entires for the remaining queued buffers are freed since this will not happen via the dequeueBuffer() mechanism. Additionally, add a V4L2BufferCache::isEmpty() function and assert that the cache is empty at the end of the streamOff() call. Signed-off-by: Naushir Patuck Tested-by: David Plowman --- include/libcamera/internal/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 2d2ccc477c91..37747c0b2f27 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -126,6 +126,7 @@ public: int get(const FrameBuffer &buffer); void put(unsigned int index); + bool isEmpty() const; private: class Entry diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 5f36ee20710d..9da82697e7f0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -262,6 +262,19 @@ void V4L2BufferCache::put(unsigned int index) cache_[index].free_ = true; } +/** + * \brief Check if all the entries in the cache are unused + */ +bool V4L2BufferCache::isEmpty() const +{ + for (auto const &entry : cache_) { + if (!entry.free_) + return false; + } + + return true; +} + V4L2BufferCache::Entry::Entry() : free_(true), lastUsed_(0) { @@ -1832,10 +1845,13 @@ int V4L2VideoDevice::streamOff() for (auto it : queuedBuffers_) { FrameBuffer *buffer = it.second; + cache_->put(it.first); buffer->metadata_.status = FrameMetadata::FrameCancelled; bufferReady.emit(buffer); } + ASSERT(cache_->isEmpty()); + queuedBuffers_.clear(); fdBufferNotifier_->setEnabled(false); streaming_ = false;