[{"id":1608,"web_url":"https://patchwork.libcamera.org/comment/1608/","msgid":"<20190517093101.GC4960@pendragon.ideasonboard.com>","date":"2019-05-17T09:31:01","subject":"Re: [libcamera-devel] [PATCH v4 11/11] libcamera: camera: Lock the\n\tpipeline handler in acquire()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Fri, May 17, 2019 at 02:54:47AM +0200, Niklas Söderlund wrote:\n> To allow more than one application using libcamera simultaneously there\n> can be no overlap between which cameras are in use by which user. As a\n> camera is part of a pipeline handler and there might be shared resources\n> between all cameras exposed by that pipeline handler it's not enough to\n> to only lock access to a single camera, all cameras from that pipeline\n> need to be tied to the same process.\n> \n> Allow for this by locking the whole pipeline when one of its cameras\n> is acquired by the user. Other processes can still enumerate and list\n> all cameras in the system but can't acquire a camera from a locked\n> pipeline handler.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/camera.cpp | 16 ++++++++++++++--\n>  1 file changed, 14 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index cb45bafe3fb1ff85..a83768fcde126c32 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -470,13 +470,17 @@ void Camera::disconnect()\n>   * not blocking, if the device has already been acquired (by the same or another\n>   * process) the -EBUSY error code is returned.\n>   *\n> + * Acquiring a camera will limit usage of any other camera(s) provided by the\n> + * same pipeline hander to the same instance of libcamera. The limit is in\n\ns/hander/handler/\n\n> + * effect until all cameras from the pipeline handler are released(). Other\n\n\"released\" isn't a function, you should write \"released\" or \"released\nwith release()\". As the release() function is mentioned elsewhere in\nthis documentation block, I would leave it out here.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + * instances of libcamera can still list and examine the cameras but will fail\n> + * if they attempt to acquire() any of them.\n> + *\n>   * Once exclusive access isn't needed anymore, the device should be released\n>   * with a call to the release() function.\n>   *\n>   * This function affects the state of the camera, see \\ref camera_operation.\n>   *\n> - * \\todo Implement exclusive access across processes.\n> - *\n>   * \\return 0 on success or a negative error code otherwise\n>   * \\retval -ENODEV The camera has been disconnected from the system\n>   * \\retval -EBUSY The camera is not free and can't be acquired by the caller\n> @@ -489,6 +493,12 @@ int Camera::acquire()\n>  \tif (!stateIs(CameraAvailable))\n>  \t\treturn -EBUSY;\n>  \n> +\tif (!pipe_->lock()) {\n> +\t\tLOG(Camera, Info)\n> +\t\t\t<< \"Pipeline handler in use by another process\";\n> +\t\treturn -EBUSY;\n> +\t}\n> +\n>  \tstate_ = CameraAcquired;\n>  \n>  \treturn 0;\n> @@ -510,6 +520,8 @@ int Camera::release()\n>  \tif (!stateBetween(CameraAvailable, CameraConfigured))\n>  \t\treturn -EBUSY;\n>  \n> +\tpipe_->unlock();\n> +\n>  \tstate_ = CameraAvailable;\n>  \n>  \treturn 0;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A501960C02\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 May 2019 11:31:25 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C08302FD;\n\tFri, 17 May 2019 11:31:17 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1558085477;\n\tbh=dZDUZJeNWt+HN7INI78AMccZqr971GCAs3eGs8XQgy0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qDymD3wOJwv0TrIQsVK47Hcg1MIwoK99Fb/D7Tbh6LchmyCl0u/G9VVw2kx7HsuPp\n\tKIFDn4hI5oKAb2mE3jQ/gEfu9iXAEFl5f8so+ndQfyVubGVMXjsUtbkmXRfXICiEtu\n\tKyKVZIez7YFIwX+qlUtleyOW1ZikkmD95Jk0ZZYI=","Date":"Fri, 17 May 2019 12:31:01 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190517093101.GC4960@pendragon.ideasonboard.com>","References":"<20190517005447.27171-1-niklas.soderlund@ragnatech.se>\n\t<20190517005447.27171-12-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190517005447.27171-12-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v4 11/11] libcamera: camera: Lock the\n\tpipeline handler in acquire()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Fri, 17 May 2019 09:31:25 -0000"}}]