From patchwork Mon Feb 7 15:12:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 15340 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 60D36BF415 for ; Mon, 7 Feb 2022 15:12:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B119D61079; Mon, 7 Feb 2022 16:12:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="dqjhzCR/"; dkim-atps=neutral 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 D90756105F for ; Mon, 7 Feb 2022 16:12:18 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id q198-20020a1ca7cf000000b0037bb52545c6so3957688wme.1 for ; Mon, 07 Feb 2022 07:12:18 -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:mime-version :content-transfer-encoding; bh=rj1o9/5KbUdeWSNNP5QvN6GcpJAssLWr3AsS+oiemXM=; b=dqjhzCR/74AipvO4bUAHnFDzXoNkVNzpWYp/DSh8xnlbsfrqxIKwgXQ43I4rlz+fiq eV4yQ7CZC1MgvSOS4oSIYSDykYi1TAy1TVYeJlgsLZ6BgH4AAVw13kY8UcD6FWbCSAw7 X00/fxl0cX+LgAcsouYczm4jAyKy0nSYsp7pWZs1/uWl4+rBR6S5Cofuj6Y3yy+DVI3e BiVoYp7zwnL1VTnS+tbvdIDepOrltm6mbQ5ijOsedeyyirMnqMKfK1HcWpqQ+P7Xi7AG cbSkKMpcofsWH/v34ub6jnsv1qtcaff6SZ2ZA8YKNSuajNKPOFNr3kKwUa9cS5Iq52jw G6xQ== 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:mime-version :content-transfer-encoding; bh=rj1o9/5KbUdeWSNNP5QvN6GcpJAssLWr3AsS+oiemXM=; b=LxZCEru2Pqwt2/xCIt8qDNZOg7p59wMw5ScWRsmH2WwRYGdsIb5RV6//O7d6oVcbJL pYinIA3vgE5tddgUlwbwNeUqFMXBMLumzjp+CbrjJj810QxGanMCuHZkNrUmFgnCojea xgEptuEa/7iBdjGn8eeAKCxtKgtRnldh+wa00fhnFKmhUQCJH2FH+O3Fn1xOsUs616gW SBd12ll9TQWPrWdJ9SKyOsuIeSRt8GvpzGxWLk9NwJH/JC1FMyr4WLalLhxKlHPqG5q0 wG4J65HFqoJ0N76a+KqlM1u6DludNHxe2Fb0bihOdTpZA2k/9SrcSRCgnvPS07n1BiZc EQJA== X-Gm-Message-State: AOAM532yQP5hM8ETHW1jv2mgVivLhAcXsa+QUTSf+knCHg2KP4Qz2vY5 FrTlmuYPOCuQxmmr5olAnkbPLUoCUpc+ww== X-Google-Smtp-Source: ABdhPJwOhtzsE0/BCqd5ajhUpYFMTvM4wYSIVRllQAirO95ObkL6dQd67LnnLrKN4UD/DhEwuITBJA== X-Received: by 2002:a05:600c:2d45:: with SMTP id a5mr7956244wmg.170.1644246738182; Mon, 07 Feb 2022 07:12:18 -0800 (PST) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:4a96:1adf:459f:8a7e]) by smtp.gmail.com with ESMTPSA id i19sm21463085wmq.45.2022.02.07.07.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 07:12:17 -0800 (PST) From: Naushir Patuck 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 Subject: [libcamera-devel] [PATCH 1/3] pipeline: raspberrypi: Allow Stream::returnBuffer() to handle internal buffers 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" If Stream::returnBuffer() gets passed an internally allocated buffer, it now simply re-queues it back to the device. With this change, the pipeline handler code can be simplified slightly as it does not need multiple code paths for internally allocated and non-internally allocated buffers. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 53 +++++++++---------- .../pipeline/raspberrypi/rpi_stream.cpp | 7 ++- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 49af56edc1f9..0755de84c70c 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -1877,34 +1877,29 @@ void RPiCameraData::clearIncompleteRequests() void RPiCameraData::handleStreamBuffer(FrameBuffer *buffer, RPi::Stream *stream) { - if (stream->isExternal()) { + /* + * It is possible to be here without a pending request, so check + * that we actually have one to action, otherwise we just return + * buffer back to the stream. + */ + Request *request = requestQueue_.empty() ? nullptr : requestQueue_.front(); + if (!dropFrameCount_ && request && request->findBuffer(stream) == buffer) { /* - * It is possible to be here without a pending request, so check - * that we actually have one to action, otherwise we just return - * buffer back to the stream. + * Check if this is an externally provided buffer, and if + * so, we must stop tracking it in the pipeline handler. */ - Request *request = requestQueue_.empty() ? nullptr : requestQueue_.front(); - if (!dropFrameCount_ && request && request->findBuffer(stream) == buffer) { - /* - * Check if this is an externally provided buffer, and if - * so, we must stop tracking it in the pipeline handler. - */ - handleExternalBuffer(buffer, stream); - /* - * Tag the buffer as completed, returning it to the - * application. - */ - pipe()->completeBuffer(request, buffer); - } else { - /* - * This buffer was not part of the Request, or there is no - * pending request, so we can recycle it. - */ - stream->returnBuffer(buffer); - } + handleExternalBuffer(buffer, stream); + /* + * Tag the buffer as completed, returning it to the + * application. + */ + pipe()->completeBuffer(request, buffer); } else { - /* Simply re-queue the buffer to the requested stream. */ - stream->queueBuffer(buffer); + /* + * This buffer was not part of the Request, or there is no + * pending request, so we can recycle it. + */ + stream->returnBuffer(buffer); } } @@ -2104,7 +2099,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em FrameBuffer *b = embeddedQueue_.front(); if (!unicam_[Unicam::Embedded].isExternal() && b->metadata().timestamp < ts) { embeddedQueue_.pop(); - unicam_[Unicam::Embedded].queueBuffer(b); + unicam_[Unicam::Embedded].returnBuffer(b); embeddedRequeueCount++; LOG(RPI, Warning) << "Dropping unmatched input frame in stream " << unicam_[Unicam::Embedded].name(); @@ -2140,7 +2135,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em * the front of the queue. This buffer is now orphaned, so requeue * it back to the device. */ - unicam_[Unicam::Image].queueBuffer(bayerQueue_.front().buffer); + unicam_[Unicam::Image].returnBuffer(bayerQueue_.front().buffer); bayerQueue_.pop(); bayerRequeueCount++; LOG(RPI, Warning) << "Dropping unmatched input frame in stream " @@ -2158,7 +2153,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em LOG(RPI, Warning) << "Flushing bayer stream!"; while (!bayerQueue_.empty()) { - unicam_[Unicam::Image].queueBuffer(bayerQueue_.front().buffer); + unicam_[Unicam::Image].returnBuffer(bayerQueue_.front().buffer); bayerQueue_.pop(); } flushedBuffers = true; @@ -2175,7 +2170,7 @@ bool RPiCameraData::findMatchingBuffers(BayerFrame &bayerFrame, FrameBuffer *&em LOG(RPI, Warning) << "Flushing embedded data stream!"; while (!embeddedQueue_.empty()) { - unicam_[Unicam::Embedded].queueBuffer(embeddedQueue_.front()); + unicam_[Unicam::Embedded].returnBuffer(embeddedQueue_.front()); embeddedQueue_.pop(); } flushedBuffers = true; diff --git a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp index a421ad09ba50..f446e1ce66c7 100644 --- a/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp +++ b/src/libcamera/pipeline/raspberrypi/rpi_stream.cpp @@ -163,8 +163,11 @@ int Stream::queueBuffer(FrameBuffer *buffer) void Stream::returnBuffer(FrameBuffer *buffer) { - /* This can only be called for external streams. */ - ASSERT(external_); + if (!external_) { + /* For internal buffers, simply requeue back to the device. */ + queueToDevice(buffer); + return; + } /* Push this buffer back into the queue to be used again. */ availableBuffers_.push(buffer);