From patchwork Sun Jan 31 22:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11098 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 0D71BBD808 for ; Sun, 31 Jan 2021 22:47:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CC293683EF; Sun, 31 Jan 2021 23:47:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sqBTzKzL"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E13E2683FF for ; Sun, 31 Jan 2021 23:47:35 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6669315CF; Sun, 31 Jan 2021 23:47:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1612133255; bh=RfDpVTg62cT7shPfh0FX8KWfZyRzyHyYDgH3Dy37xWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sqBTzKzLvrIx/0M0H8Nmt3pzV5fQaahHiQg/FWyDP82GVt1uyV9sGavgegBSntdOf hUEulFsJaZpY4qd9BqbvzkTGS8tlGJlnCnm77h25Gef/QmlRQkyUdsivJrUaxOXEmH FpekhaCLuSLb3ePRQXIFtVe9tZaCEGboFlHL4/x8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Feb 2021 00:47:01 +0200 Message-Id: <20210131224702.8838-20-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210131224702.8838-1-laurent.pinchart@ideasonboard.com> References: <20210131224702.8838-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 19/20] libcamera: pipeline: simple: Support usage of multiple streams 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: , Cc: Phi-Bang Nguyen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To extend the multi-stream support to runtime operation of the pipeline, expand the converter queue to store multiple output buffers, and update the request queuing and buffer completion handlers accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/simple/simple.cpp | 93 ++++++++++++++---------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 58e5f0d23139..55a5528611c8 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -173,7 +173,7 @@ public: std::vector> converterBuffers_; bool useConverter_; - std::queue converterQueue_; + std::queue> converterQueue_; }; class SimpleCameraConfiguration : public CameraConfiguration @@ -762,10 +762,12 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream, * Export buffers on the converter or capture video node, depending on * whether the converter is used or not. */ - if (data->useConverter_) - return converter_->exportBuffers(0, count, buffers); - else + if (data->useConverter_) { + unsigned int index = stream - &data->streams_.front(); + return converter_->exportBuffers(index, count, buffers); + } else { return data->video_->exportBuffers(count, buffers); + } } int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] ControlList *controls) @@ -830,25 +832,30 @@ void SimplePipelineHandler::stop(Camera *camera) int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request) { SimpleCameraData *data = cameraData(camera); - Stream *stream = &data->streams_[0]; + int ret; - FrameBuffer *buffer = request->findBuffer(stream); - if (!buffer) { - LOG(SimplePipeline, Error) - << "Attempt to queue request with invalid stream"; - return -ENOENT; - } + std::map buffers; - /* - * If conversion is needed, push the buffer to the converter queue, it - * will be handed to the converter in the capture completion handler. - */ - if (data->useConverter_) { - data->converterQueue_.push(buffer); - return 0; + for (auto &[stream, buffer] : request->buffers()) { + /* + * If conversion is needed, push the buffer to the converter + * queue, it will be handed to the converter in the capture + * completion handler. + */ + if (data->useConverter_) { + unsigned int index = stream - &data->streams_.front(); + buffers.emplace(index, buffer); + } else { + ret = data->video_->queueBuffer(buffer); + if (ret < 0) + return ret; + } } - return data->video_->queueBuffer(buffer); + if (data->useConverter_) + data->converterQueue_.push(std::move(buffers)); + + return 0; } /* ----------------------------------------------------------------------------- @@ -1020,24 +1027,34 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer) * point converting an erroneous buffer. */ if (buffer->metadata().status != FrameMetadata::FrameSuccess) { - if (data->useConverter_) { - /* Requeue the buffer for capture. */ - data->video_->queueBuffer(buffer); + if (!data->useConverter_) { + /* No conversion, just complete the request. */ + Request *request = buffer->request(); + completeBuffer(request, buffer); + completeRequest(request); + return; + } + + /* + * The converter is in use. Requeue the internal buffer for + * capture, and complete the request with all the user-facing + * buffers. + */ + data->video_->queueBuffer(buffer); - /* - * Get the next user-facing buffer to complete the - * request. - */ - if (data->converterQueue_.empty()) - return; + if (data->converterQueue_.empty()) + return; - buffer = data->converterQueue_.front(); - data->converterQueue_.pop(); + Request *request = nullptr; + for (auto &item : data->converterQueue_.front()) { + FrameBuffer *outputBuffer = item.second; + request = outputBuffer->request(); + completeBuffer(request, outputBuffer); } + data->converterQueue_.pop(); - Request *request = buffer->request(); - completeBuffer(request, buffer); - completeRequest(request); + if (request) + completeRequest(request); return; } @@ -1052,10 +1069,8 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer) return; } - FrameBuffer *output = data->converterQueue_.front(); + converter_->queueBuffers(buffer, data->converterQueue_.front()); data->converterQueue_.pop(); - - converter_->queueBuffers(buffer, { { 0, output } }); return; } @@ -1078,10 +1093,10 @@ void SimplePipelineHandler::converterOutputDone(FrameBuffer *buffer) { ASSERT(activeCamera_); - /* Complete the request. */ + /* Complete the buffer and the request. */ Request *request = buffer->request(); - completeBuffer(request, buffer); - completeRequest(request); + if (completeBuffer(request, buffer)) + completeRequest(request); } REGISTER_PIPELINE_HANDLER(SimplePipelineHandler)