From patchwork Tue Aug 10 12:17:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siyuan Fan X-Patchwork-Id: 13280 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 98C7CBD87D for ; Tue, 10 Aug 2021 12:17:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D225168822; Tue, 10 Aug 2021 14:17:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=foxmail.com header.i=@foxmail.com header.b="gZGZlkGD"; dkim-atps=neutral Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 803BA687F0 for ; Tue, 10 Aug 2021 14:17:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1628597868; bh=mXMXe7CWiDVhtsmqftTQA/LJdcJ3kEt425pMngds3h0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gZGZlkGDQkPYgDLzYhfqvkMNl+P96xxbUNB5awNS4pvs+w2Ru4pgjo3b+zTLM7WgP SDnAopS8Z/EKJkL5QjBX+az0Frr/L118KDNMWgWQQcC5vbc4+M6cqLmI3WCeZgif7g NWjGlWDkKVF9gJ6B7Auidf8mkdos9CneA43wKLyw= Received: from localhost.localdomain ([123.126.82.8]) by newxmesmtplogicsvrsza5.qq.com (NewEsmtp) with SMTP id 46D0AC53; Tue, 10 Aug 2021 20:17:45 +0800 X-QQ-mid: xmsmtpt1628597866tal6d1nll Message-ID: X-QQ-XMAILINFO: NCwFnk+fWy3TPq0AMWOCu+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13:17:39 +0100 X-OQ-MSGID: <20210810121742.11012-2-siyuan.fan@foxmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210810121742.11012-1-siyuan.fan@foxmail.com> References: <20210810121742.11012-1-siyuan.fan@foxmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 1/4] pipeline: isp: The software ISP-based pipeline handler 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" From: Fan Siyuan Changes in V2: -fix the raw and rgb data flow based queue model in pipeline handler -move buffer alloc and thread to ISP class -Fill metadata information in dstBuffer Signed-off-by: Fan Siyuan --- src/libcamera/pipeline/isp/isp.cpp | 81 ++++++++++++------------------ 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/src/libcamera/pipeline/isp/isp.cpp b/src/libcamera/pipeline/isp/isp.cpp index e5fbd536..c6b7808c 100644 --- a/src/libcamera/pipeline/isp/isp.cpp +++ b/src/libcamera/pipeline/isp/isp.cpp @@ -5,9 +5,10 @@ * isp.cpp - The software ISP-based pipeline handler */ -#include "isp_processing.h" +#include "../../swisp/isp.h" #include +#include #include #include #include @@ -17,7 +18,6 @@ #include #include -#include "libcamera/base/thread.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" @@ -38,7 +38,6 @@ public: ~ISPCameraData() { delete video_; - delete rawBuffers; } int init(); @@ -46,16 +45,16 @@ public: void ISPCompleted(FrameBuffer *buffer); Stream stream_; - ISP isp_; - Thread threadISP_; - int width; - int height; + CPU_ISP isp_; + int width_; + int height_; + + std::vector> rawBuffers_; + std::vector rawQueueBuffers_; + std::vector rgbQueueBuffers_; MediaDevice *media_; V4L2VideoDevice *video_; - std::vector> *tempCopyExportBuffers; - std::vector> *rawBuffers; - std::map bufferPair; }; @@ -158,8 +157,8 @@ int PipelineHandlerISP::configure(Camera *camera, CameraConfiguration *config) format.fourcc = v4l2Format; format.size = cfg.size; - data->width = format.size.width; - data->height = format.size.height; + data->width_ = format.size.width; + data->height_ = format.size.height; int ret = data->video_->setFormat(&format); if (ret) @@ -176,30 +175,8 @@ int PipelineHandlerISP::exportFrameBuffers(Camera *camera, Stream *stream, { unsigned int count = stream->configuration().bufferCount; ISPCameraData *data = cameraData(camera); - - for (unsigned int i = 0; i < count; i++) { - std::string name = "frame-" + std::to_string(i); - const int isp_fd = memfd_create(name.c_str(), 0); - int ret = ftruncate(isp_fd, data->width * data->height * 3); - if (ret < 0) { - LOG(ISP, Error) - << "truncate: " - << strerror(-ret); - return ret; - } - FileDescriptor temp = FileDescriptor(std::move(isp_fd)); - - FrameBuffer::Plane rgbPlane; - rgbPlane.fd = std::move(temp); - rgbPlane.length = data->width * data->height * 3; - - std::vector planes; - planes.push_back(std::move(rgbPlane)); - std::unique_ptr buffer = std::make_unique(std::move(planes)); - buffers->push_back(std::move(buffer)); - } - data->tempCopyExportBuffers = buffers; + count = data->isp_.exportBuffers(buffers, count, data->width_, data->height_); return count; @@ -210,15 +187,16 @@ int PipelineHandlerISP::start(Camera *camera, [[maybe_unused]] const ControlList ISPCameraData *data = cameraData(camera); unsigned int count = data->stream_.configuration().bufferCount; - data->rawBuffers = new std::vector>; - int ret = data->video_->allocateBuffers(count, data->rawBuffers); + int ret = data->video_->allocateBuffers(count, &data->rawBuffers_); if (ret < 0) { LOG(ISP, Error) << strerror(-ret); return ret; } - for (unsigned int i = 0; i < count; i++) - data->bufferPair[data->tempCopyExportBuffers->at(i).get()] = data->rawBuffers->at(i).get(); + for (unsigned int i = 0; i < count; i++) { + data->rawQueueBuffers_.push_back(data->rawBuffers_[i].get()); + } + ret = data->video_->streamOn(); if (ret < 0) { @@ -226,7 +204,7 @@ int PipelineHandlerISP::start(Camera *camera, [[maybe_unused]] const ControlList return ret; } - data->threadISP_.start(); + data->isp_.startThreadISP(); return 0; } @@ -235,8 +213,11 @@ void PipelineHandlerISP::stop(Camera *camera) { ISPCameraData *data = cameraData(camera); - data->threadISP_.exit(); - data->threadISP_.wait(); + if (!(data->rawBuffers_.empty())) { + data->rawBuffers_.clear(); + } + + data->isp_.stopThreadISP(); data->video_->streamOff(); data->video_->releaseBuffers(); @@ -246,15 +227,19 @@ int PipelineHandlerISP::queueRequestDevice(Camera *camera, Request *request) { ISPCameraData *data = cameraData(camera); FrameBuffer *rgbBuffer = request->findBuffer(&data->stream_); + data->rgbQueueBuffers_.push_back(rgbBuffer); if (!rgbBuffer) { LOG(ISP, Error) << "Attempt to queue request with invalid stream"; return -ENOENT; } - int ret = data->video_->queueBuffer(data->bufferPair[rgbBuffer]); + int ret = data->video_->queueBuffer(data->rawQueueBuffers_[0]); if (ret < 0) return ret; + FrameBuffer *temp = data->rawQueueBuffers_[0]; + data->rawQueueBuffers_.erase(data->rawQueueBuffers_.begin()); + data->rawQueueBuffers_.push_back(std::move(temp)); return 0; } @@ -297,10 +282,10 @@ void ISPCameraData::ISPCompleted(FrameBuffer *buffer) void ISPCameraData::bufferReady(FrameBuffer *buffer) { - for (std::map::iterator it = bufferPair.begin(); it != bufferPair.end(); it++) { - if (it->second == buffer) - isp_.invokeMethod(&ISP::processing, ConnectionTypeQueued, buffer, it->first, width, height); - } + LOG(ISP, Debug) << rgbQueueBuffers_[0]->planes()[0].fd.fd(); + isp_.invokeMethod(&CPU_ISP::processing, ConnectionTypeQueued, buffer, rgbQueueBuffers_[0], width_, height_); + rgbQueueBuffers_.erase(rgbQueueBuffers_.begin()); + rgbQueueBuffers_.shrink_to_fit(); } @@ -311,8 +296,6 @@ int ISPCameraData::init() return -ENODEV; video_->bufferReady.connect(this, &ISPCameraData::bufferReady); - - isp_.moveToThread(&threadISP_); isp_.ispCompleted.connect(this, &ISPCameraData::ISPCompleted); return 0;