From patchwork Thu Nov 26 13:26:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 29098 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 501F9C3304 for ; Thu, 26 Nov 2026 13:26:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A8B56AA1F; Thu, 26 Nov 2026 14:26:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BD9k8h6M"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 428566A8C7 for ; Thu, 26 Nov 2026 14:26:52 +0100 (CET) Received: from pb-laptop.local (185.182.215.119.nat.pool.zt.hu [185.182.215.119]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B12722F8; Thu, 26 Nov 2026 14:24:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795699457; bh=0xzSMrzBsI3AwjJv9Xz68MWBp35jj6wlUtqFsa4wzw4=; h=From:To:Cc:Subject:Date:From; b=BD9k8h6MU/GTpipk74XT978INhH2B29KFbyJH706yNJ5GqEC+VfaQ9EvAZwqLLVxv fX/CUpnVX0oahJx6WyJmXNKff443W0e/DehI6qmVEaWSBf2P/JMPrAEbVXuUYxd1NX zy0vF3lRclJp/5vuMRaHkIeivyia/6Zxd5SKEUVw= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v1] libcamera: pipeline: simple: Handle failed capture better Date: Thu, 26 Nov 2026 14:26:49 +0100 Message-ID: <20261126132649.1928406-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.1 MIME-Version: 1.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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The handling of failed frame captures from the video device was not entirely correct. For example, assume (raw, processed) streams, and consider that all captures fail with an error. In that case, the "raw" buffer will be completed in the request, but since `tryCompleteRequest()` returns early due to the pending "processed" buffer, the request will never be completed and processing stops. Furthermore, there is an issue of uninitialized metadata. When the "raw" buffer fails, then the metadata of the "processed" buffer will not be filled, not even the `status` field. Since it starts out as uninitialized, it will stay as such. Fix both issues by always unconditionally completing the associated request (if any) when the "raw" capture fails for some reason, and ensure that the other buffers of the request have valid metadata. Signed-off-by: Barnabás Pőcze --- src/libcamera/pipeline/simple/simple.cpp | 71 ++++++++++++++++-------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 2f7f4c893f..9e9874f56f 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -41,6 +41,7 @@ #include "libcamera/internal/delayed_controls.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/formats.h" +#include "libcamera/internal/framebuffer.h" #include "libcamera/internal/global_configuration.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" @@ -889,36 +890,62 @@ void SimpleCameraData::imageBufferReady(FrameBuffer *buffer) * point converting an erroneous buffer. */ if (buffer->metadata().status != FrameMetadata::FrameSuccess) { + Request *request = buffer->request(); + const auto &metadata = buffer->metadata(); + const bool cancelled = metadata.status == FrameMetadata::FrameCancelled; + if (!useConversion_ || rawStream_) { - /* No conversion, just complete the request. */ - Request *request = buffer->request(); + /* The buffer is part of the request, complete it. */ pipe->completeBuffer(request, buffer); - SimpleFrameInfo *info = frameInfo_.find(request->sequence()); - if (info) - info->metadataRequired = false; - tryCompleteRequest(request); - return; + } else if (!cancelled) { + /* + * The converter or Software ISP is in use. Requeue the internal + * buffer for capture (unless the stream is being stopped), and + * complete the request with all the user-facing buffers. + */ + video_->queueBuffer(buffer); } /* - * The converter or Software ISP is in use. Requeue the internal - * buffer for capture (unless the stream is being stopped), and - * complete the request with all the user-facing buffers. + * \todo Due to the various queues here, it is assumed that buffers + * are returned in-order. But `V4L2VideoDevice::streamOff()` does not + * guarantee that. So it is assumed that cancellation is only possible + * due to that, and processing the `conversionQueue_` is skipped as + * it should be handled in `clearIncompleteRequests()` during the stop + * procedure. */ - if (buffer->metadata().status != FrameMetadata::FrameCancelled) - video_->queueBuffer(buffer); + if (!cancelled && !conversionQueue_.empty()) { + const RequestOutputs &outputs = conversionQueue_.front(); + ASSERT(!request || request == outputs.request); + request = outputs.request; - if (conversionQueue_.empty()) - return; + /* + * \todo There should probably be some common code to propagate + * metadata, as appropriate for the given status. + */ + for (auto &[stream, buf] : outputs.outputs) { + auto &m = buf->_d()->metadata(); - const RequestOutputs &outputs = conversionQueue_.front(); - for (auto &[stream, buf] : outputs.outputs) - pipe->completeBuffer(outputs.request, buf); - SimpleFrameInfo *info = frameInfo_.find(outputs.request->sequence()); - if (info) - info->metadataRequired = false; - tryCompleteRequest(outputs.request); - conversionQueue_.pop(); + m.status = metadata.status; + m.sequence = metadata.sequence; + m.timestamp = metadata.timestamp; + + pipe->completeBuffer(request, buf); + } + + conversionQueue_.pop(); + } + + /* + * \todo The `hasPendingBuffers()` check is only needed + * due to the out-of-order cancellation of buffers by + * `V4L2VideoDevice::streamOff()`, as described above. + */ + ASSERT(cancelled || !request->hasPendingBuffers()); + if (request && !request->hasPendingBuffers()) { + frameInfo_.destroy(request->sequence()); + pipe->completeRequest(request); + } return; }