From patchwork Wed Nov 27 09:25:57 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: 22118 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 29ED3C3213 for ; Wed, 27 Nov 2024 09:26:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A59F5660D7; Wed, 27 Nov 2024 10:26:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="csaFehX9"; dkim-atps=neutral Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C2947660C4 for ; Wed, 27 Nov 2024 10:26:49 +0100 (CET) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-71d4c462ab1so1390747a34.0 for ; Wed, 27 Nov 2024 01:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732699608; x=1733304408; 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=vtXzRx/bGtcOeUBwLnIhf0TSMieqneRSDdL6wR8sPsI=; b=csaFehX9ijCuzV5eHRoRACyV6/AlhPdJAO69mrUz20/1RU6VlbOyGyTpzpgZ5TtxeD DqqNt2ZBqyLG4eIdCp1M2Fdm8COtHbuTkzTS56siRekopRzoOuHAvaes81rk0jogcad6 jU3kQkbOihAMi2yLP+196Mt5dnRA3bArFJQKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732699608; x=1733304408; 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=vtXzRx/bGtcOeUBwLnIhf0TSMieqneRSDdL6wR8sPsI=; b=qKYVJJNfuLZ+amFoVvwu8qlf+d1sGYuWsQjVos1bxYms8SpMWUMVHTmS5okJN80pId VL9fGhRoXnYOp+vC23EHLFG4n+hW5+sIzFc+UWr2lF8zn1v8LUQClAl8zkT5KJY+88wh oVg1EPW4gjbgcKdgNBjrM6OjiG+1qj7xDIax2fhA6eu21ih738PO6Xii31mrkH1K9tpU 2OBVTre9yk2hZcIkJyrRnHKgYQaFJVyqkpgQSiv5UlyyKaPy/VDOLj96bvNZn+E9E+BY SBqQ/YfRSWoFVxZJpswEhqwQ6gtleqZs6oESbH8WAx1sTRf/ommLFcBZUXdEAWwaZIBT jYxw== X-Gm-Message-State: AOJu0YztDp4Eigr/9dIlQwdmIkYkJGFhbo4NxhSZHBfdhm11iDeGGaSu ojLU/34/7y0pnOmc2OnTGo+ctvxxDFHO4afOhqkm/1diDmKaQHPBd9meWCCs1tJ3Yx/gGHcajuU = X-Gm-Gg: ASbGnctNMSHoxpK/6Fi0Gaw5vU49U+46/CW/cKP89i5NXUzxVBdedr3jvl9FYSBiJdF owHxsxRtM/A2+jWgqV1YIEsJn30fSLxTEP/wJOGbttbvFnUSIVwDSekw/ZDFgK1tKrsoIQ+4uZK NLp+shnX/es78SqPoDF+f9Afl51I1XjsTxuhDlLhZnmLBQw+KDF0Cl3uwrv4BH7yDw93qjoRwCb iAmfvjr1Y+v+WAyTxKncbu3BF/45gw4NNNGCdunlWm+ntWNcXJEBB4ZedR1k6hB3tzAodVkizlc F7gnZnUjhkBUPR2rrW/0ZHqxBH1LcBdimAMCZJTJtJYVNekLx3WXUg== X-Google-Smtp-Source: AGHT+IEcBk0l7j0pXW0yfCYpqfM5tIad4tZ+ngME+MjUvHI6hhelFajbwNIyRv4Lmbfhcmgw0XKGng== X-Received: by 2002:a05:6830:6c09:b0:71d:5a2d:a1d9 with SMTP id 46e09a7af769-71d65c94f26mr1887976a34.12.1732699608267; Wed, 27 Nov 2024 01:26:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 01:26:47 -0800 (PST) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Harvey Yang , Han-Lin Chen Subject: [PATCH v2 7/9] android: Remove Camera3RequestDescriptor::streamsProcessMutex_ Date: Wed, 27 Nov 2024 09:25:57 +0000 Message-ID: <20241127092632.3145984-8-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" This mutex was needed when CameraStream's worker thread posts a result back to CameraDevice. We can simplify it by calling CameraDevice's function on libcamera::Camera's owner thread. With this delegation, `Camera3RequestDescriptor::pendingStreamsToProcess_` will be firstly setup in the application's thread in processCaptureRequest(), and the rest accesses will be done in libcamera::CameraManager's thread. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- src/android/camera_device.cpp | 33 +++++++++++++++++---------------- src/android/camera_device.h | 2 ++ src/android/camera_request.h | 4 +--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3fb92268e..9fd851bc8 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -991,8 +991,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques FrameBuffer *frameBuffer = nullptr; UniqueFD acquireFence; - MutexLocker lock(descriptor->streamsProcessMutex_); - switch (cameraStream->type()) { case CameraStream::Type::Mapped: /* Mapped streams will be handled in the next loop. */ @@ -1068,7 +1066,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques << cameraStream->configuration().pixelFormat << "]" << " (mapped)"; - MutexLocker lock(descriptor->streamsProcessMutex_); descriptor->pendingStreamsToProcess_.insert({ cameraStream, &buffer }); /* @@ -1242,9 +1239,6 @@ void CameraDevice::requestComplete(Request *request) descriptor->resultMetadata_ = std::make_unique(0, 0); } - /* Handle post-processing. */ - MutexLocker locker(descriptor->streamsProcessMutex_); - /* * Queue all the post-processing streams request at once. The completion * slot streamProcessingComplete() can only execute when we are out @@ -1272,10 +1266,8 @@ void CameraDevice::requestComplete(Request *request) } } - if (descriptor->pendingStreamsToProcess_.empty()) { - locker.unlock(); + if (descriptor->pendingStreamsToProcess_.empty()) completeDescriptor(descriptor); - } } /** @@ -1382,6 +1374,19 @@ void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer, } } +void CameraDevice::streamProcessingCompleteDelegate(StreamBuffer *streamBuffer, + StreamBuffer::Status status) +{ + /* + * Delegate the callback to the camera manager thread to simplify race condition. + */ + auto *method = new BoundMethodMember{ + this, camera_.get(), &CameraDevice::streamProcessingComplete, ConnectionTypeQueued + }; + + method->activate(streamBuffer, status); +} + /** * \brief Handle post-processing completion of a stream in a capture request * \param[in] streamBuffer The StreamBuffer for which processing is complete @@ -1402,13 +1407,9 @@ void CameraDevice::streamProcessingComplete(StreamBuffer *streamBuffer, Camera3RequestDescriptor *request = streamBuffer->request; - { - MutexLocker locker(request->streamsProcessMutex_); - - request->pendingStreamsToProcess_.erase(streamBuffer->stream); - if (!request->pendingStreamsToProcess_.empty()) - return; - } + request->pendingStreamsToProcess_.erase(streamBuffer->stream); + if (!request->pendingStreamsToProcess_.empty()) + return; completeDescriptor(streamBuffer->request); } diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 699aa8f17..815a695d1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -65,6 +65,8 @@ public: int configureStreams(camera3_stream_configuration_t *stream_list); int processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request); + void streamProcessingCompleteDelegate(StreamBuffer *bufferStream, + StreamBuffer::Status status); void streamProcessingComplete(StreamBuffer *bufferStream, StreamBuffer::Status status); diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 6b2a00795..bd75d4595 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -66,9 +66,7 @@ public: }; /* Keeps track of streams requiring post-processing. */ - std::map pendingStreamsToProcess_ - LIBCAMERA_TSA_GUARDED_BY(streamsProcessMutex_); - libcamera::Mutex streamsProcessMutex_; + std::map pendingStreamsToProcess_; Camera3RequestDescriptor(libcamera::Camera *camera, const camera3_capture_request_t *camera3Request);