{"id":15340,"url":"https://patchwork.libcamera.org/api/patches/15340/?format=json","web_url":"https://patchwork.libcamera.org/patch/15340/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220207151214.887140-1-naush@raspberrypi.com>","date":"2022-02-07T15:12:12","name":"[libcamera-devel,1/3] pipeline: raspberrypi: Allow Stream::returnBuffer() to handle internal buffers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d1b9d0a8073abc39b9d2262011597e7ed5cf5c58","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15340/mbox/","series":[{"id":2921,"url":"https://patchwork.libcamera.org/api/series/2921/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2921","date":"2022-02-07T15:12:12","name":"[libcamera-devel,1/3] pipeline: raspberrypi: Allow Stream::returnBuffer() to handle internal buffers","version":1,"mbox":"https://patchwork.libcamera.org/series/2921/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15340/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15340/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 60D36BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Feb 2022 15:12:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B119D61079;\n\tMon,  7 Feb 2022 16:12:20 +0100 (CET)","from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D90756105F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Feb 2022 16:12:18 +0100 (CET)","by mail-wm1-x32e.google.com with SMTP id\n\tq198-20020a1ca7cf000000b0037bb52545c6so3957688wme.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 07 Feb 2022 07:12:18 -0800 (PST)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:4a96:1adf:459f:8a7e])\n\tby smtp.gmail.com with ESMTPSA id\n\ti19sm21463085wmq.45.2022.02.07.07.12.17\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 07 Feb 2022 07:12:17 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"dqjhzCR/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=rj1o9/5KbUdeWSNNP5QvN6GcpJAssLWr3AsS+oiemXM=;\n\tb=dqjhzCR/74AipvO4bUAHnFDzXoNkVNzpWYp/DSh8xnlbsfrqxIKwgXQ43I4rlz+fiq\n\teV4yQ7CZC1MgvSOS4oSIYSDykYi1TAy1TVYeJlgsLZ6BgH4AAVw13kY8UcD6FWbCSAw7\n\tX00/fxl0cX+LgAcsouYczm4jAyKy0nSYsp7pWZs1/uWl4+rBR6S5Cofuj6Y3yy+DVI3e\n\tBiVoYp7zwnL1VTnS+tbvdIDepOrltm6mbQ5ijOsedeyyirMnqMKfK1HcWpqQ+P7Xi7AG\n\tcbSkKMpcofsWH/v34ub6jnsv1qtcaff6SZ2ZA8YKNSuajNKPOFNr3kKwUa9cS5Iq52jw\n\tG6xQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=rj1o9/5KbUdeWSNNP5QvN6GcpJAssLWr3AsS+oiemXM=;\n\tb=LxZCEru2Pqwt2/xCIt8qDNZOg7p59wMw5ScWRsmH2WwRYGdsIb5RV6//O7d6oVcbJL\n\tpYinIA3vgE5tddgUlwbwNeUqFMXBMLumzjp+CbrjJj810QxGanMCuHZkNrUmFgnCojea\n\txgEptuEa/7iBdjGn8eeAKCxtKgtRnldh+wa00fhnFKmhUQCJH2FH+O3Fn1xOsUs616gW\n\tSBd12ll9TQWPrWdJ9SKyOsuIeSRt8GvpzGxWLk9NwJH/JC1FMyr4WLalLhxKlHPqG5q0\n\twG4J65HFqoJ0N76a+KqlM1u6DludNHxe2Fb0bihOdTpZA2k/9SrcSRCgnvPS07n1BiZc\n\tEQJA==","X-Gm-Message-State":"AOAM532yQP5hM8ETHW1jv2mgVivLhAcXsa+QUTSf+knCHg2KP4Qz2vY5\n\tFrTlmuYPOCuQxmmr5olAnkbPLUoCUpc+ww==","X-Google-Smtp-Source":"ABdhPJwOhtzsE0/BCqd5ajhUpYFMTvM4wYSIVRllQAirO95ObkL6dQd67LnnLrKN4UD/DhEwuITBJA==","X-Received":"by 2002:a05:600c:2d45:: with SMTP id\n\ta5mr7956244wmg.170.1644246738182; \n\tMon, 07 Feb 2022 07:12:18 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  7 Feb 2022 15:12:12 +0000","Message-Id":"<20220207151214.887140-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/3] pipeline: raspberrypi: Allow\n\tStream::returnBuffer() to handle internal buffers","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"If Stream::returnBuffer() gets passed an internally allocated buffer, it now\nsimply re-queues it back to the device. With this change, the pipeline handler\ncode can be simplified slightly as it does not need multiple code paths for\ninternally allocated and non-internally allocated buffers.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 53 +++++++++----------\n .../pipeline/raspberrypi/rpi_stream.cpp       |  7 ++-\n 2 files changed, 29 insertions(+), 31 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 49af56edc1f9..0755de84c70c 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1877,34 +1877,29 @@ void RPiCameraData::clearIncompleteRequests()\n \n void RPiCameraData::handleStreamBuffer(FrameBuffer *buffer, RPi::Stream *stream)\n {\n-\tif (stream->isExternal()) {\n+\t/*\n+\t * It is possible to be here without a pending request, so check\n+\t * that we actually have one to action, otherwise we just return\n+\t * buffer back to the stream.\n+\t */\n+\tRequest *request = requestQueue_.empty() ? nullptr : requestQueue_.front();\n+\tif (!dropFrameCount_ && request && request->findBuffer(stream) == buffer) {\n \t\t/*\n-\t\t * It is possible to be here without a pending request, so check\n-\t\t * that we actually have one to action, otherwise we just return\n-\t\t * buffer back to the stream.\n+\t\t * Check if this is an externally provided buffer, and if\n+\t\t * so, we must stop tracking it in the pipeline handler.\n \t\t */\n-\t\tRequest *request = requestQueue_.empty() ? nullptr : requestQueue_.front();\n-\t\tif (!dropFrameCount_ && request && request->findBuffer(stream) == buffer) {\n-\t\t\t/*\n-\t\t\t * Check if this is an externally provided buffer, and if\n-\t\t\t * so, we must stop tracking it in the pipeline handler.\n-\t\t\t */\n-\t\t\thandleExternalBuffer(buffer, stream);\n-\t\t\t/*\n-\t\t\t * Tag the buffer as completed, returning it to the\n-\t\t\t * application.\n-\t\t\t */\n-\t\t\tpipe()->completeBuffer(request, buffer);\n-\t\t} else {\n-\t\t\t/*\n-\t\t\t * This buffer was not part of the Request, or there is no\n-\t\t\t * pending request, so we can recycle it.\n-\t\t\t */\n-\t\t\tstream->returnBuffer(buffer);\n-\t\t}\n+\t\thandleExternalBuffer(buffer, stream);\n+\t\t/*\n+\t\t * Tag the buffer as completed, returning it to the\n+\t\t * application.\n+\t\t */\n+\t\tpipe()->completeBuffer(request, buffer);\n \t} else {\n-\t\t/* Simply re-queue the buffer to the requested stream. */\n-\t\tstream->queueBuffer(buffer);\n+\t\t/*\n+\t\t * This buffer was not part of the Request, or there is no\n+\t\t * pending request, so we can recycle it.\n+\t\t */\n+\t\tstream->returnBuffer(buffer);\n \t}\n }\n \n@@ -2104,7 +2099,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \t\t\tFrameBuffer *b = embeddedQueue_.front();\n \t\t\tif (!unicam_[Unicam::Embedded].isExternal() && b->metadata().timestamp < ts) {\n \t\t\t\tembeddedQueue_.pop();\n-\t\t\t\tunicam_[Unicam::Embedded].queueBuffer(b);\n+\t\t\t\tunicam_[Unicam::Embedded].returnBuffer(b);\n \t\t\t\tembeddedRequeueCount++;\n \t\t\t\tLOG(RPI, Warning) << \"Dropping unmatched input frame in stream \"\n \t\t\t\t\t\t  << unicam_[Unicam::Embedded].name();\n@@ -2140,7 +2135,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \t\t\t\t * the front of the queue. This buffer is now orphaned, so requeue\n \t\t\t\t * it back to the device.\n \t\t\t\t */\n-\t\t\t\tunicam_[Unicam::Image].queueBuffer(bayerQueue_.front().buffer);\n+\t\t\t\tunicam_[Unicam::Image].returnBuffer(bayerQueue_.front().buffer);\n \t\t\t\tbayerQueue_.pop();\n \t\t\t\tbayerRequeueCount++;\n \t\t\t\tLOG(RPI, Warning) << \"Dropping unmatched input frame in stream \"\n@@ -2158,7 +2153,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \n \t\t\t\tLOG(RPI, Warning) << \"Flushing bayer stream!\";\n \t\t\t\twhile (!bayerQueue_.empty()) {\n-\t\t\t\t\tunicam_[Unicam::Image].queueBuffer(bayerQueue_.front().buffer);\n+\t\t\t\t\tunicam_[Unicam::Image].returnBuffer(bayerQueue_.front().buffer);\n \t\t\t\t\tbayerQueue_.pop();\n \t\t\t\t}\n \t\t\t\tflushedBuffers = true;\n@@ -2175,7 +2170,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em\n \n \t\t\t\tLOG(RPI, Warning) << \"Flushing embedded data stream!\";\n \t\t\t\twhile (!embeddedQueue_.empty()) {\n-\t\t\t\t\tunicam_[Unicam::Embedded].queueBuffer(embeddedQueue_.front());\n+\t\t\t\t\tunicam_[Unicam::Embedded].returnBuffer(embeddedQueue_.front());\n \t\t\t\t\tembeddedQueue_.pop();\n \t\t\t\t}\n \t\t\t\tflushedBuffers = true;\ndiff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\nindex a421ad09ba50..f446e1ce66c7 100644\n--- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp\n@@ -163,8 +163,11 @@ int Stream::queueBuffer(FrameBuffer *buffer)\n \n void Stream::returnBuffer(FrameBuffer *buffer)\n {\n-\t/* This can only be called for external streams. */\n-\tASSERT(external_);\n+\tif (!external_) {\n+\t\t/* For internal buffers, simply requeue back to the device. */\n+\t\tqueueToDevice(buffer);\n+\t\treturn;\n+\t}\n \n \t/* Push this buffer back into the queue to be used again. */\n \tavailableBuffers_.push(buffer);\n","prefixes":["libcamera-devel","1/3"]}