{"id":12528,"url":"https://patchwork.libcamera.org/api/1.1/patches/12528/?format=json","web_url":"https://patchwork.libcamera.org/patch/12528/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210608151633.73465-7-jacopo@jmondi.org>","date":"2021-06-08T15:16:31","name":"[libcamera-devel,v5,6/8] android: Guard access to the camera state","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"18545b0f91c5c3ec68f4f2b35948b2090d6d8f75","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/12528/mbox/","series":[{"id":2112,"url":"https://patchwork.libcamera.org/api/1.1/series/2112/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2112","date":"2021-06-08T15:16:25","name":"Implement flush() camera operation","version":5,"mbox":"https://patchwork.libcamera.org/series/2112/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12528/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12528/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D90D1C3206\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Jun 2021 15:15:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A86296892F;\n\tTue,  8 Jun 2021 17:15:57 +0200 (CEST)","from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E4B7E68930\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jun 2021 17:15:54 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id C8C7260005;\n\tTue,  8 Jun 2021 15:15:53 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jun 2021 17:16:31 +0200","Message-Id":"<20210608151633.73465-7-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210608151633.73465-1-jacopo@jmondi.org>","References":"<20210608151633.73465-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 6/8] android: Guard access to the\n\tcamera state","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Guard access to the camera state and the start/stop sequences\nwith a mutex.\n\nCurrently only stop() and the first call to processCaptureRequest()\nstart and stop the camera, and they're not meant to race with each\nother. With the introduction of flush() the camera can be stopped\nconcurrently to a processCaptureRequest() call, hence access to the\ncamera state will need to be protected.\n\nPrepare for that by guarding the existing paths with a mutex.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.cpp | 23 ++++++++++++++---------\n src/android/camera_device.h   |  1 +\n 2 files changed, 15 insertions(+), 9 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 3346811b19e7..d3581c70c96b 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -800,6 +800,7 @@ void CameraDevice::close()\n \n void CameraDevice::stop()\n {\n+\tMutexLocker stateLock(stateMutex_);\n \tif (state_ == State::Stopped)\n \t\treturn;\n \n@@ -1900,17 +1901,21 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \tif (!isValidRequest(camera3Request))\n \t\treturn -EINVAL;\n \n-\t/* Start the camera if that's the first request we handle. */\n-\tif (state_ == State::Stopped) {\n-\t\tworker_.start();\n+\t{\n+\t\tMutexLocker stateLock(stateMutex_);\n \n-\t\tint ret = camera_->start();\n-\t\tif (ret) {\n-\t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n-\t\t\treturn ret;\n-\t\t}\n+\t\t/* Start the camera if that's the first request we handle. */\n+\t\tif (state_ == State::Stopped) {\n+\t\t\tworker_.start();\n \n-\t\tstate_ = State::Running;\n+\t\t\tint ret = camera_->start();\n+\t\t\tif (ret) {\n+\t\t\t\tLOG(HAL, Error) << \"Failed to start camera\";\n+\t\t\t\treturn ret;\n+\t\t\t}\n+\n+\t\t\tstate_ = State::Running;\n+\t\t}\n \t}\n \n \t/*\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 70c29755bcfc..117d829ec932 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -120,6 +120,7 @@ private:\n \n \tCameraWorker worker_;\n \n+\tlibcamera::Mutex stateMutex_; /* Protects access to the camera state. */\n \tState state_;\n \n \tstd::shared_ptr<libcamera::Camera> camera_;\n","prefixes":["libcamera-devel","v5","6/8"]}