From patchwork Mon Sep 18 08:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 19053 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 4098DC326C for ; Mon, 18 Sep 2023 08:52:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BDB636293A; Mon, 18 Sep 2023 10:52:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1695027151; bh=ofju62HOyCtZ6JUZksTiTTT6w3TW7UHt4tNWV4WHyOA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=od1h6r9IczlOrNbRGJ13pNNxVBThTA4nDcTZ8xdX6hW2Hp7lOhvjGtNjthgMIZ0Wg Cn3zIRoA8/WdxIIjyRwwqmfUMelg0hXXrUGXIaUSGrwCDJMgI0BC79bWPizKv71kxh 3ZHT5juq6BzsLdGdnrMYMLYrb6p1d9LwED/VYP6HrT8YRKr6oyn/ILi6J+CPg920JB ugqj1Iy9zlvG+zkFxX2mv7tW7Qsjz6L23mpSqFaqfCjrmKTEVsgzO8Z9ACbqiPLuj5 AWHhjFZC16b7ME9rB5TaDvcL/C+7LPo9OR+VhvRazhclpojy0TAJyBolY+n7cZiITG lKPpHkjcKeztA== Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B580061DEC for ; Mon, 18 Sep 2023 10:52:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="SIt2Y6+B"; dkim-atps=neutral Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bf6ea270b2so30799515ad.0 for ; Mon, 18 Sep 2023 01:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695027149; x=1695631949; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gFJVI0hL49KJbYXVhYGFATbY93lQH2D1fxPPxOdUZg4=; b=SIt2Y6+BaRBTKYsCcakYpX5dW1rAy/hLFGcDXqt+RAJpvWzDH8SRMlakLs0HGO955H DhpHJAj3I4cBpDgwO2Vls5ghKuhf9R59F/SvcyMu3f6JUKNnbwnJiQrkTffCOS6rqi0a ZyCLDrkY9iP0XMjrtFnyJtt6IZvw5hzmT2u9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695027149; x=1695631949; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gFJVI0hL49KJbYXVhYGFATbY93lQH2D1fxPPxOdUZg4=; b=CNUr+eaZ0nCbultd01B5/yFr9KMeJECD+CeT0HgOucJ8fJd7SsTlA6c7C5nSnmPTh5 F42pAveu/nmVJS0wRN8xjM4PqWcAyM6fgAi8MKU9haSzBP3fOzHgwBAMnauSpdcmvfSm q0Oc6LQWYmRQOsvrFR2IzO2rYnQkH5knFa6aMKF7QI+ogzz/NZ13WgLg8hVcRw71Ma1t zyeo5C2IRBKQ9edEvOpQPsI70yeiYPJyGWv467oKx7GCyjepH4debBhQS9EnckWFF/Da pj+JDb+Pnya0oPiIi+XkvVfCvnTk7IZp+/CbJSlm4T/Q7OaNHiAYWG3HaWS/UhuN0IKD PqWA== X-Gm-Message-State: AOJu0YwzH+VPwAql2hQtWIaQMomJns6d5H/1rneVge5Q6QUfjkPSwjXE zk8aHtlituQ6EU2NS9dkFBDTSLMme+3D6cCb9cfnuPXZ X-Google-Smtp-Source: AGHT+IG7Ut/8eBeULHlOgMw49uGEcRRBKLlh89u+p/vfZ0MmbQX1fTh7Cs3qvMZTwD6cacdt+OlcAA== X-Received: by 2002:a17:902:e845:b0:1b6:bced:1dc2 with SMTP id t5-20020a170902e84500b001b6bced1dc2mr8485331plg.0.1695027148855; Mon, 18 Sep 2023 01:52:28 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (148.175.199.104.bc.googleusercontent.com. [104.199.175.148]) by smtp.gmail.com with ESMTPSA id z4-20020a170902ee0400b001b88da737c6sm2387020plb.54.2023.09.18.01.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 01:52:28 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 18 Sep 2023 08:49:21 +0000 Message-ID: <20230918085222.500697-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog In-Reply-To: <20230918085222.500697-1-chenghaoyang@chromium.org> References: <20230918085222.500697-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/1] libcamera: Fix ipu3's issue of first black frame 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: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As ipu3 ISP requires two frames in the pipeline to generate non-delayed output, this CL fixes the problem of the first frame (preview and capture) being black by queueing the first buffer twice. Signed-off-by: Harvey Yang --- src/libcamera/pipeline/ipu3/ipu3.cpp | 50 ++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index a81c817a..fa4a8a10 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -86,11 +86,15 @@ public: ControlInfoMap ipaControls_; + bool firstRequest_ = true; + private: void metadataReady(unsigned int id, const ControlList &metadata); void paramsBufferReady(unsigned int id); void setSensorControls(unsigned int id, const ControlList &sensorControls, const ControlList &lensControls); + + std::map bufferReturnCounters_; }; class IPU3CameraConfiguration : public CameraConfiguration @@ -721,6 +725,8 @@ int PipelineHandlerIPU3::start(Camera *camera, [[maybe_unused]] const ControlLis ImgUDevice *imgu = data->imgu_; int ret; + data->firstRequest_ = true; + /* Disable test pattern mode on the sensor, if any. */ ret = cio2->sensor()->setTestPatternMode( controls::draft::TestPatternModeEnum::TestPatternModeOff); @@ -1224,22 +1230,37 @@ void IPU3CameraData::paramsBufferReady(unsigned int id) if (!info) return; + const int yuvCount = firstRequest_ ? 2 : 1; + firstRequest_ = false; /* Queue all buffers from the request aimed for the ImgU. */ for (auto it : info->request->buffers()) { const Stream *stream = it.first; FrameBuffer *outbuffer = it.second; - if (stream == &outStream_) - imgu_->output_->queueBuffer(outbuffer); - else if (stream == &vfStream_) - imgu_->viewfinder_->queueBuffer(outbuffer); + if (stream == &outStream_) { + for (int i = 0; i < yuvCount; ++i) { + bufferReturnCounters_[outbuffer] += 1; + imgu_->output_->queueBuffer(outbuffer); + } + } else if (stream == &vfStream_) { + for (int i = 0; i < yuvCount; ++i) { + bufferReturnCounters_[outbuffer] += 1; + imgu_->viewfinder_->queueBuffer(outbuffer); + } + } } info->paramBuffer->_d()->metadata().planes()[0].bytesused = sizeof(struct ipu3_uapi_params); - imgu_->param_->queueBuffer(info->paramBuffer); - imgu_->stat_->queueBuffer(info->statBuffer); - imgu_->input_->queueBuffer(info->rawBuffer); + for (int i = 0; i < yuvCount; ++i) { + bufferReturnCounters_[info->paramBuffer] += 1; + bufferReturnCounters_[info->statBuffer] += 1; + bufferReturnCounters_[info->rawBuffer] += 1; + + imgu_->param_->queueBuffer(info->paramBuffer); + imgu_->stat_->queueBuffer(info->statBuffer); + imgu_->input_->queueBuffer(info->rawBuffer); + } } void IPU3CameraData::metadataReady(unsigned int id, const ControlList &metadata) @@ -1268,6 +1289,11 @@ void IPU3CameraData::metadataReady(unsigned int id, const ControlList &metadata) */ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer) { + if (--bufferReturnCounters_[buffer] > 0) + return; + + bufferReturnCounters_.erase(buffer); + IPU3Frames::Info *info = frameInfos_.find(buffer); if (!info) return; @@ -1334,6 +1360,11 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) void IPU3CameraData::paramBufferReady(FrameBuffer *buffer) { + if (--bufferReturnCounters_[buffer] > 0) + return; + + bufferReturnCounters_.erase(buffer); + IPU3Frames::Info *info = frameInfos_.find(buffer); if (!info) return; @@ -1354,6 +1385,11 @@ void IPU3CameraData::paramBufferReady(FrameBuffer *buffer) void IPU3CameraData::statBufferReady(FrameBuffer *buffer) { + if (--bufferReturnCounters_[buffer] > 0) + return; + + bufferReturnCounters_.erase(buffer); + IPU3Frames::Info *info = frameInfos_.find(buffer); if (!info) return;