From patchwork Wed Nov 27 09:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 22114 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 2F0D2C3213 for ; Wed, 27 Nov 2024 09:26:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14DD1660C2; Wed, 27 Nov 2024 10:26:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="INTFfrxP"; dkim-atps=neutral Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 00AB2660AD for ; Wed, 27 Nov 2024 10:26:43 +0100 (CET) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-2958ddf99a7so5985587fac.2 for ; Wed, 27 Nov 2024 01:26:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732699602; x=1733304402; 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=gkEafkQKLiXPZ/Jkv3BAtdyW3Syk3pi66hwIh5mX3Kg=; b=INTFfrxP0DlQMMccxCIangQVSC0HkMMXCkdjvUMgLdrEF75fPyMKfn5JWGYYvyWE7a aXzTqNv5sGR4MP+i7bAVmqvlllVexAtJF0hA8QyLJ47Ug2exoS6aBrrgHTSTDj587xvZ r1rvnbWhDpEPQry14KXhUkzPAhD9xepmTHi5I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732699602; x=1733304402; 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=gkEafkQKLiXPZ/Jkv3BAtdyW3Syk3pi66hwIh5mX3Kg=; b=ayEPQJthG79l/dDEDV/OWIEy3CB/rt3H5QZnebmIcqSgTG3qzXqnWu4jgwGQfQj4A3 GWi50ejcUrg0iI6JNR0UFgMbVHTA+30Alv/rrJ6x9PTJUVui6P2cdV/dJI0OT8LicVng TBLQuvIQMwhqOuaLT+p+yDefyFsg33Eu+Mi+atj/npKei9hQlwSmLaByYofmTCcmHXz+ P8uKLt4Sook6RwNVWsRKl9Nl2yBXdw4HgWjqKw7zV2H4QKnzspfok7iZEpaiR1cZuKnm 9MkY6OX79J8McJa1swYOyAeIH6r1bZTe/1EQsxfTekMuaxpNKXm5GxAmYfd/qb1NL6Xa 26MA== X-Gm-Message-State: AOJu0YxacKNJZnepM3+MKefWuWDhBUpwannRChsYrHJzZW6uw9oRBVoC B7WDbUPeo0hfhByanY23Y9SdjfCkwb9iSuudxozk40KDQVyngSLw8drndhBQe9yqDx1YeR9LYbU = X-Gm-Gg: ASbGnctmESWD/NG3Jreqo7YFcbNFgtEKhmFf8Fusy6UJl9R30P+CxSYTAT0lOGvOfdH fc/f3sppUOmMg5x0FzmpXP78gn0pFy43nSpshfP8OMTvLI/35jkcHL5qX9jzDid4DQ1arLjjGM3 CbJnvO3uCJuN+ayKTLYXw2yMvQRT6FtCpvQgG8Jy6uLy6fcgJyl5eovK19JsHDakh+7PKzqeMQQ 7kTzvm6AMqua9jOTlAMP3qLFIEYTkp2GnZgUZ17eWD/BS2vISzMMJVpbsz6LwiCrGIKSEgU5HON wKOle4Ut3ehhgZokSURWbCanPj3y7OXt6L5ya4RCmkyMnqFY3W4agw== X-Google-Smtp-Source: AGHT+IGX9O2+8wobsriZv6lS9Aiw/HSGc3NBv9b4jgBUH4erXX0pxZ0f2Yxzqz5DWIlSeaj896fO1Q== X-Received: by 2002:a05:6870:ab07:b0:297:2bdc:f533 with SMTP id 586e51a60fabf-29dc43056fdmr2179644fac.31.1732699602218; Wed, 27 Nov 2024 01:26:42 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (27.247.221.35.bc.googleusercontent.com. [35.221.247.27]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fbcbfc41f9sm8693027a12.8.2024.11.27.01.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 01:26:41 -0800 (PST) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Han-Lin Chen Subject: [PATCH v2 3/9] android: Set StreamBuffer::srcBuffer in CameraDevice::processCaptureRequest Date: Wed, 27 Nov 2024 09:25:53 +0000 Message-ID: <20241127092632.3145984-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241127092632.3145984-1-chenghaoyang@chromium.org> References: <20241127092632.3145984-1-chenghaoyang@chromium.org> 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" StreamBuffer::srcBuffer was set right before being processed, while it was already determined when being constructed. This patch sets the value in CameraDevice::processCaptureRequest. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- src/android/camera_device.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4e3bdc9cc..11613fac9 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -967,9 +967,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * to a libcamera stream. Streams of type Mapped will be handled later. * * Collect the CameraStream associated to each requested capture stream. - * Since requestedStreams is an std:set<>, no duplications can happen. + * Since requestedStreams is an std:map<>, no duplications can happen. */ - std::set requestedStreams; + std::map requestedBuffers; for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { CameraStream *cameraStream = buffer.stream; camera3_stream_t *camera3Stream = cameraStream->camera3Stream(); @@ -1008,6 +1008,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques cameraStream->configuration().size); frameBuffer = buffer.frameBuffer.get(); acquireFence = std::move(buffer.fence); + + requestedBuffers[cameraStream] = frameBuffer; LOG(HAL, Debug) << ss.str() << " (direct)"; break; @@ -1021,6 +1023,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ frameBuffer = cameraStream->getBuffer(); buffer.internalBuffer = frameBuffer; + buffer.srcBuffer = frameBuffer; + + requestedBuffers[cameraStream] = frameBuffer; LOG(HAL, Debug) << ss.str() << " (internal)"; descriptor->pendingStreamsToProcess_.insert( @@ -1036,8 +1041,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques auto fence = std::make_unique(std::move(acquireFence)); descriptor->request_->addBuffer(cameraStream->stream(), frameBuffer, std::move(fence)); - - requestedStreams.insert(cameraStream); } /* @@ -1068,8 +1071,19 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ CameraStream *sourceStream = cameraStream->sourceStream(); ASSERT(sourceStream); - if (requestedStreams.find(sourceStream) != requestedStreams.end()) + ASSERT(sourceStream->type() == CameraStream::Type::Direct); + + /* + * If the buffer for the source stream has been requested as + * Direct, use its framebuffer as the source buffer for + * post-processing. No need to recycle the buffer since it's + * owned by Android. + */ + auto iterDirectBuffer = requestedBuffers.find(sourceStream); + if (iterDirectBuffer != requestedBuffers.end()) { + buffer.srcBuffer = iterDirectBuffer->second; continue; + } /* * If that's not the case, we need to add a buffer to the request @@ -1077,11 +1091,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ FrameBuffer *frameBuffer = cameraStream->getBuffer(); buffer.internalBuffer = frameBuffer; + buffer.srcBuffer = frameBuffer; descriptor->request_->addBuffer(sourceStream->stream(), frameBuffer, nullptr); - requestedStreams.insert(sourceStream); + requestedBuffers[sourceStream] = frameBuffer; } /* @@ -1236,8 +1251,6 @@ void CameraDevice::requestComplete(Request *request) continue; } - buffer->srcBuffer = src; - ++iter; int ret = stream->process(buffer); if (ret) {