From patchwork Tue Dec 10 14:23:55 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: 22270 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 9A93EC3257 for ; Tue, 10 Dec 2024 14:26:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9AF6F67E90; Tue, 10 Dec 2024 15:26:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="h5eX9RwO"; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B1E9967E85 for ; Tue, 10 Dec 2024 15:26:06 +0100 (CET) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2ee76929a98so4409264a91.1 for ; Tue, 10 Dec 2024 06:26:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733840765; x=1734445565; 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=7RSUBsgMlBRQcCiQn/OQffu9bSxAh/8WGY8/nToqTB8=; b=h5eX9RwOsDCzRlFcxaZwTRyvkbvklv7RTOSZ+tJc9BBhB6ZI9YJfymmNw9O2JB4y30 NL/g2RSCA+YNdwOZzoK7iLWORQuZr08OuWDtCQXmdPtmEt+O3+w5Z5PIzSqFiRtVoWah eRjj+0cEeVvZqQLGmtzhbK0C57ZyKmqZpijuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733840765; x=1734445565; 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=7RSUBsgMlBRQcCiQn/OQffu9bSxAh/8WGY8/nToqTB8=; b=QmEr6y4GdBXRG0OubaXi96l0B+4oa5O1eKXxnHya9yZ+DDocV1Umym6bzwqXvb+Pg2 4FEx1TXUB2AaTrnq+0ql+/+wEjxLK6Ji2ZDUEVhlUZZNRtysCvDZQQ0vNk0XK5zhaC9f u+a34C7MBhSgrDAtnfvosrH57i7rgD00JHNVWboxebjWsI9IaEG9E0udqwUitXoHXAeo 5LIfAMxetHU1bFnjZrsWDQaKpROQ/s29OZ0HyHNa8K6m8CWR4KudSdGbVkD2kfSdbYhC 82CppxYn5zy/fdgiKf8pJxpYkrvWmsAYwSPyqxUm5BTmDmInQc1WYHgK4QfwptYdOET7 xXug== X-Gm-Message-State: AOJu0YwWjjADhhWYxIQ2BDcBe3W61cuWIhuJNlscmBb5Ql4eSqnn579V ZIA98CLdS2LcmaitAVqSOedlN8cVS/I9mbjjKjeL16UU0zAJufwIFxh24su5bM0G6u8kfxwZoRc = X-Gm-Gg: ASbGncs/bQsvTBY50Zdx3HIMe1Pun74ozTj1CoumDV/xYfwVd/KTXBoWMzS2OmcNQex 13rf6jAaPsTR1OyPxunaYODyA7CfYNDpxb2B5ci03vSRZXdBoCBItuHhIExH8s7HxTDPrd+BhtX qzK6Y51DkeGhI/D1vsagPT5gtZGqfl1xgt129QosIRa+ihsuvcTubJgLDQKK4xHIKaanKpvsEP3 wNWkANh+wplqqdGmn/jm6OPfwaQaRzOsxldCnhpG049oU1RR3Y6ltP4yZC57raAUGwIXNyDkZTL eopgfE0GaJMdIIRvNg+GW4qjf7RSGVODJgcjdyxybtAkxZ7s6eSagEdxWKYS X-Google-Smtp-Source: AGHT+IGaw2zjiZPuu8FAyKww2a8rQvWXahex/o8HhofuiRnIMe4kuxYH2faKSsmsZYOEX55D3wrO3A== X-Received: by 2002:a17:90b:17c8:b0:2ee:ee77:226d with SMTP id 98e67ed59e1d1-2efd597dfb8mr5339886a91.4.1733840764875; Tue, 10 Dec 2024 06:26:04 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (112.212.229.35.bc.googleusercontent.com. [35.229.212.112]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ef26ff97f2sm11812053a91.11.2024.12.10.06.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 06:26:04 -0800 (PST) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Han-Lin Chen Subject: [PATCH v4 2/7] android: Set StreamBuffer::srcBuffer in CameraDevice::processCaptureRequest Date: Tue, 10 Dec 2024 14:23:55 +0000 Message-ID: <20241210142557.2886315-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241210142557.2886315-1-chenghaoyang@chromium.org> References: <20241210142557.2886315-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. `requestedStreams` is refactored from std::set to std::map to find the correct srcBuffer accordingly. The change also helps cleaning up the post process pipeline's dependency on `Camera3RequestDescriptor::pendingStreamsToProcess_`, which is going to be cleaned up in the following patches. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4e3bdc9cc..f6dadaf22 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -967,9 +966,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(); @@ -1021,6 +1020,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ frameBuffer = cameraStream->getBuffer(); buffer.internalBuffer = frameBuffer; + buffer.srcBuffer = frameBuffer; + LOG(HAL, Debug) << ss.str() << " (internal)"; descriptor->pendingStreamsToProcess_.insert( @@ -1037,7 +1038,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->request_->addBuffer(cameraStream->stream(), frameBuffer, std::move(fence)); - requestedStreams.insert(cameraStream); + requestedBuffers[cameraStream] = frameBuffer; } /* @@ -1067,9 +1068,19 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * added to the request. */ CameraStream *sourceStream = cameraStream->sourceStream(); - ASSERT(sourceStream); - if (requestedStreams.find(sourceStream) != requestedStreams.end()) + ASSERT(sourceStream && 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 +1088,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 +1248,6 @@ void CameraDevice::requestComplete(Request *request) continue; } - buffer->srcBuffer = src; - ++iter; int ret = stream->process(buffer); if (ret) {