From patchwork Sat Nov 21 18:52:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denys Pasishnyi X-Patchwork-Id: 29065 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 914A4C3355 for ; Sat, 21 Nov 2026 18:52:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 836666A974; Sat, 21 Nov 2026 19:52:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ws3VD09D"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 26E136A80C for ; Sat, 21 Nov 2026 19:52:29 +0100 (CET) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-48e09aa5264so1056297f8f.2 for ; Sat, 21 Nov 2026 10:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795287149; x=1795891949; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=8hXsbrqpi19Dv2X0rQEY1Z5tmUTSe7ZaTFnf4Xx5VhY=; b=Ws3VD09DUvnO+tz6Fe1B/w6Qo1TISagJr1mMkIZq2AX5d+fP4xbP2BIm4SU4Nf40mz kg/NbOSRNjhQGdAsLVo/IPSW3pNkAxSqHzv1Y4v1FiecT3KZ1mKHM87z/jU0/1gDxDnF 1k41IR64vKi8aG3Ll0gldh/zSbwykj+UQPiXdHUIn061b4v5ods7EUeZyP8dMnCm79Il vuSATgR21XBIzItUJR5fKiyOumQlx4y2g5Y1xv1KUQjh22GypMsA/3iUeyqH2loqPDM6 /nY5DtkUkMI7QV/eE9CVDank6Z7igdo+nxxwWyTMOYF1CGHzU2vGrbbQbiGR4Fvn23G7 NUlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795287149; x=1795891949; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8hXsbrqpi19Dv2X0rQEY1Z5tmUTSe7ZaTFnf4Xx5VhY=; b=FUyUKlRYIJXKUx+3zIO9vzIfyaY1aesyyAbU5KfdAfobmiN/iA3lLcWS5Li4BGX6l1 UmD3q8kqzsyQA8c01tW3JB8pI84FFOMon9ifUY2ecjOc0jusoyFSxeIHk4eSCuo2I2m8 XJk4kEFIRQW/LgZ6dcrKnoy7+ewPof3kzMXLXt5yBygN4NKrT1d/S9n52Ct7g2LwFULt Aj4WpaCkFw8Kaji4E17KPoRN1H7xPYOWfYggFOFCcJ3N0mJbZq3vuhU6lRhuCrsR4bvZ YIc9xJLE+Sw/58tLKI9sb2mf9d2C5Er9/8qlGuWTC1dOMq9tktcV7WmppX2oqdgSaUJc /Gzg== X-Gm-Message-State: APuU4Z/hluKhlrNa+W6ohex85M7/bYBhg4DvUgrIk3qOdHxdB40dE/RC jpuKcc5Pbro4tUPXAy0QZMOkeJWW8apOc3oHQrvqQnZROb/oO7D61ir9T08nGg== X-Gm-Gg: AZFdTZcVwBLx3qI9x8Rg3/FGY65O0kYHKTKDEhTtRd4tRGiuKGvre/b7YBBhfwIj0GM Ln8QuOLFqrn2OPAnHhZ6sBpleXdEm4I4NJ9wS+9xY38SddINkt/paAdHbtXNkRJIi+MCbRfREUq h6BVwXpsogk8oybk672dm78i0JA82WRVOCLW99jUCWSxPshFpozVZ5ik6EvZ8jgCfk3sf/3OIHM umAe/kFenmCBzsBkOwGc+9KAmJh7N0OqZNXh0M9mNfKVTuV+VWkZpbwbDh2isQVxz3Gj92wudBZ IrGTgm55Qgw1k5e1LSZYJBafH+rOFDQDp1IEGPmzkrN5FL0t8lgXIvZSZsQSmKfBFfMxQ4UU0Yk i2kqK6k8Zl4j7UkLs5RVJhaLPfWCOGaR7Y2qRdcxkbqqCuYy26rH8fNlSTvXODOGGhvnFWb3NQ1 oTJR+DFI9kyO32IYq0JpYn3TohF8vANp7nE4bJ49Hl/aEjyvQ04M4N8hjdQcnBNYTGgUPR2vD9X N6vZceb6IQK+3OOsO1Susn6E5Eq6DrZlemZibmy/H1tLhW2/80PKHTV9JkAex3Cy96+A2g1SPDm aHSxEPjB67lRPZ1tmzVf4f9sNlzsS0ElVCnDQbE97CZIUIp0SH4l/S0IPzqnUS0Fp5pFfnRTMXg = X-Received: by 2002:a05:6000:47d4:b0:4aa:5396:a7bc with SMTP id ffacd0b85a97d-4abb4b849fbmr9973039f8f.40.1795287148506; Sat, 21 Nov 2026 10:52:28 -0800 (PST) Received: from denys-Ubuntu.home (207.pool90-175-214.dynamic.orange.es. [90.175.214.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b9add26sm12921686f8f.44.2026.11.21.10.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2026 10:52:27 -0800 (PST) From: Denys Pasishnyi To: libcamera-devel@lists.libcamera.org Cc: Denys Pasishnyi Subject: [PATCH] libcamera: pipeline: simple: Complete pending requests on stop Date: Sat, 21 Nov 2026 19:52:06 +0100 Message-ID: <20261121185207.1268373-1-dpcat237@gmail.com> X-Mailer: git-send-email 2.53.0 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" When a camera using the software ISP is stopped while requests are still in flight, those requests can be left behind in the pipeline handler. A request needs both its buffers and, when the IPA provides metadata, the IPA metadata before tryCompleteRequest() completes it. Once the software ISP and the IPA are stopped, the metadata of the in-flight requests never arrives, so they are never completed. The Camera then trips the assertion in PipelineHandler::stop(): assertion "data->queuedRequests_.empty()" failed in stop() and the application aborts. This was observed on an OV01A10 sensor behind an Intel IPU6 (Dell XPS 9320) using the simple pipeline handler with the software ISP, in a long-lived process that repeatedly starts and stops the camera. With GStreamer, the process aborted after a few start/stop cycles (in one run on current master, 7 clean cycles and an abort on the 8th). On v0.7.2 the same assertion also took down the PipeWire daemon when libcamera ran inside it. Fix this in SimplePipelineHandler::stopDevice() by completing, once the converter or software ISP has been stopped, every request still tracked in frameInfo_. Requests whose buffers have all been returned are completed, with the same ScalerCrop metadata as a regular completion, and the others are cancelled. Their frame information is destroyed before the request is handed back, as the application is free to reuse or delete the request once it is completed. Apply the same ordering in clearIncompleteRequests() for the requests that were queued for conversion, and clear frameInfo_ only after both steps. Signed-off-by: Denys Pasishnyi --- Notes: Tested on a Dell XPS 9320 (Intel IPU6, OV01A10 sensor) with the simple pipeline handler and the software ISP, on top of master adfa719f, using a GStreamer libcamerasrc pipeline that starts and stops the camera in a single process: master: one run: 7 start/stop cycles, abort on the 8th stop with this patch: 20 cycles without an abort, frames delivered normally The full meson test suite gives the same results as master (the 'process' tests pass; the one failing test, gstreamer multi_stream_test, also fails without the patch). There is no automated test for this path, as it needs a camera. Not tested on other platforms or with cam/qcam. This patch was developed with the help of an AI tool (Claude Code) and reviewed by the submitter. src/libcamera/pipeline/simple/simple.cpp | 50 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) base-commit: adfa719f8ed67d18fd8a0739fc088a1f8b9e7252 diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 2f7f4c89..04bc865e 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -209,6 +209,7 @@ public: void clear(); SimpleFrameInfo *find(uint32_t frame); + std::vector requests() const; private: std::map frameInfo_; @@ -239,6 +240,15 @@ SimpleFrameInfo *SimpleFrames::find(uint32_t frame) return &info->second; } +std::vector SimpleFrames::requests() const +{ + std::vector requests; + requests.reserve(frameInfo_.size()); + for (const auto &[frame, info] : frameInfo_) + requests.push_back(info.request); + return requests; +} + struct SimplePipelineInfo { const char *driver; /* @@ -293,6 +303,7 @@ public: Transform transform = Transform::Identity); void imageBufferReady(FrameBuffer *buffer); void clearIncompleteRequests(); + void completePendingRequests(); unsigned int streamIndex(const Stream *stream) const { @@ -982,8 +993,42 @@ void SimpleCameraData::imageBufferReady(FrameBuffer *buffer) void SimpleCameraData::clearIncompleteRequests() { while (!conversionQueue_.empty()) { - pipe()->cancelRequest(conversionQueue_.front().request); + Request *request = conversionQueue_.front().request; conversionQueue_.pop(); + + /* + * Drop the frame information first: once the request is + * completed the application may reuse or free it. + */ + frameInfo_.destroy(request->sequence()); + pipe()->cancelRequest(request); + } +} + +/* + * Complete the requests that are still tracked when the camera is stopped. + * + * Requests that were being processed by the converter or the software ISP have + * had their buffers returned (completed or cancelled) when the ISP was + * stopped. If they were also waiting for metadata from the IPA, that metadata + * will never arrive as the IPA is stopped too, so tryCompleteRequest() would + * never complete them and they would be left in the queue of requests pending + * in the pipeline handler. + */ +void SimpleCameraData::completePendingRequests() +{ + const std::vector requests = frameInfo_.requests(); + + for (Request *request : requests) { + /* See clearIncompleteRequests() for the order of operations. */ + frameInfo_.destroy(request->sequence()); + + if (request->hasPendingBuffers()) { + pipe()->cancelRequest(request); + } else { + request->_d()->metadata().set(controls::ScalerCrop, scalerCrop_); + pipe()->completeRequest(request); + } } } @@ -1775,8 +1820,9 @@ void SimplePipelineHandler::stopDevice(Camera *camera) video->bufferReady.disconnect(data, &SimpleCameraData::imageBufferReady); - data->frameInfo_.clear(); data->clearIncompleteRequests(); + data->completePendingRequests(); + data->frameInfo_.clear(); data->conversionBuffers_.clear(); releasePipeline(data);