@@ -209,6 +209,7 @@ public:
void clear();
SimpleFrameInfo *find(uint32_t frame);
+ std::vector<Request *> requests() const;
private:
std::map<uint32_t, SimpleFrameInfo> frameInfo_;
@@ -239,6 +240,15 @@ SimpleFrameInfo *SimpleFrames::find(uint32_t frame)
return &info->second;
}
+std::vector<Request *> SimpleFrames::requests() const
+{
+ std::vector<Request *> 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<Request *> 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);
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 <dpcat237@gmail.com> --- 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