[{"id":16868,"web_url":"https://patchwork.libcamera.org/comment/16868/","msgid":"<YJmX+Hj4MKJZ9GLQ@oden.dyn.berto.se>","date":"2021-05-10T20:30:48","subject":"Re: [libcamera-devel] [PATCH 6/8] android: Guard access to the\n\tcamera state","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2021-05-10 12:52:33 +0200, Jacopo Mondi wrote:\n> Guard access to the camera state and the start/stop sequences\n> with a mutex.\n> \n> Currently only stop() and the first call to processCaptureRequest()\n> start and stop the camera, and they're not meant to race with each\n> other. With the introduction of flush() the camera can be stopped\n> concurrently to a processCaptureRequest() call, hence access to the\n> camera state will need to be protected.\n> \n> Prepare for that by guarding the existing paths with a mutex.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/android/camera_device.cpp | 23 ++++++++++++++---------\n>  src/android/camera_device.h   |  1 +\n>  2 files changed, 15 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index ff965a1c8c86..14a3f79a7402 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -758,6 +758,7 @@ void CameraDevice::close()\n>  \n>  void CameraDevice::stop()\n>  {\n> +\tMutexLocker cameraLock(cameraMutex_);\n>  \tif (state_ == CameraStopped)\n>  \t\treturn;\n>  \n> @@ -1913,17 +1914,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_ == CameraStopped) {\n> -\t\tworker_.start();\n> +\t{\n> +\t\tMutexLocker cameraLock(cameraMutex_);\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_ == CameraStopped) {\n> +\t\t\tworker_.start();\n>  \n> -\t\tstate_ = CameraRunning;\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_ = CameraRunning;\n> +\t\t}\n>  \t}\n>  \n>  \t/*\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 30b364decaab..f263fdae472a 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 cameraMutex_; /* Protects access to the camera state. */\n>  \tState state_;\n>  \n>  \tstd::shared_ptr<libcamera::Camera> camera_;\n> -- \n> 2.31.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 C7867BF829\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 10 May 2021 20:30:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87A54688E5;\n\tMon, 10 May 2021 22:30:52 +0200 (CEST)","from mail-lf1-x134.google.com (mail-lf1-x134.google.com\n\t[IPv6:2a00:1450:4864:20::134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C0E7602BE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 10 May 2021 22:30:50 +0200 (CEST)","by mail-lf1-x134.google.com with SMTP id m11so8882264lfg.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 10 May 2021 13:30:50 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\t17sm2372572lfr.187.2021.05.10.13.30.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 10 May 2021 13:30:49 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"oadprwoz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=FOhj6LQ+bjmgaI92hAKV6i9aCMViaWzTuw31A0Elz04=;\n\tb=oadprwozhJr6yTSWY8T5JovyrwFI6dM6yIeyHPMpgvSE8YmSwJRx++UPkUnB4EE7FC\n\ttYipwmvOUfDI0Eq9d9EG6+NxVoOIj5zI2AfhXAoE4Y1vhz5/dtcPkgLxbH3D/aj0b/NS\n\t72cChaut2+coF2qwCxmD7btSusBieV4dFI0LGn3+lgpVp99umnQwI0ZAdWN1PrHCcWaL\n\tvOJH1td6qMKg/vnxpdHs9AGCaw1hcnTqfMGYcWiz1MYAtwYxI5NrxVT2QmGoI+um0Bdz\n\tYjGa7qv2rE+tA4UEok2HilwDjO973/x+sWVBfMeD0pWbg8TbB05W01bW39bTEzAg7/C+\n\tut4w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=FOhj6LQ+bjmgaI92hAKV6i9aCMViaWzTuw31A0Elz04=;\n\tb=SN445V9um91gXTUWP+vU3fph2lFYoWLU6whA5UL8jdLF0fYkXvosCuwYgRfRqA7Ui1\n\t4wrDrU8UQrha+kPYzfyCTTcUlhRXlp+JV/paVeFHhvUokpYpLnQlCP56nwhR7ev695pm\n\t99Dk5XDMvLw1JdWvX/NrOYfZNDptVTCau6tEmwjJeGrma4gBC5YNlQ+JESr6fwNiAXMc\n\t5dqsLJyLQo9JtZtwThbieGEFEzPYnJSOcrOZB/AuH905jlToFLzQESsRn+ddaG+usNdd\n\tPPXOE8+WPWXNWLsvtUuNjZbzyGEXxTR94+SNXVyZMkzhAQwNnlp3XteSFcrkS7extHSf\n\tbk+A==","X-Gm-Message-State":"AOAM532ZKvJTQ5H3JtAqw+05rHej+s1ymwsAvGRiU+K3dk5aiZ8wHl7E\n\tO71jOyTdJ1/JsHUzXcKvUTrtpg==","X-Google-Smtp-Source":"ABdhPJxjdV9QzNHGnC9EkEIpkQ0HmiLNRpXmiTUVOvXKbAQQwRhZhNgeByIfWPAaPFVZhmfF0splfw==","X-Received":"by 2002:ac2:5456:: with SMTP id\n\td22mr7422750lfn.383.1620678649993; \n\tMon, 10 May 2021 13:30:49 -0700 (PDT)","Date":"Mon, 10 May 2021 22:30:48 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YJmX+Hj4MKJZ9GLQ@oden.dyn.berto.se>","References":"<20210510105235.28319-1-jacopo@jmondi.org>\n\t<20210510105235.28319-7-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210510105235.28319-7-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH 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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]