[{"id":1445,"web_url":"https://patchwork.libcamera.org/comment/1445/","msgid":"<20190418102035.GB761@pendragon.ideasonboard.com>","date":"2019-04-18T10:20:35","subject":"Re: [libcamera-devel] [RFC 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 Sun, Apr 14, 2019 at 03:35:06AM +0200, Niklas Söderlund wrote:\n> To allow more then one application using libcamera simultaneously there\n\ns/then/than/\n\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> needs to be tied to the same process.\n\ns/needs/need/\n\nUitimately that should be a pipeline handler's decision, as there may\nnot be shared resources. We don't have to implement this today, but we\nshould start thinking about it. For instance, should we pass the camera\npointer to the pipeline handler's lock() function ?\n\n> Allow for this by locking the whole pipeline when one of it's cameras\n\ns/it's/its/\n\n> are acquired by the user. Other processes can still enumerate and list\n\ns/are/is/\n\n> all cameras in the system but cant progress a camera in a locked\n\ns/cant/can't/\n\n> pipeline handler to the Acquired state.\n\n\"can't acquire a camera from a locked pipeline handler\" ?\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/camera.cpp | 7 +++++++\n>  1 file changed, 7 insertions(+)\n> \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index bdf14b31d8eeba9c..b3860952efa6446f 100644\n> --- a/src/libcamera/camera.cpp\n> +++ b/src/libcamera/camera.cpp\n> @@ -495,6 +495,11 @@ int Camera::acquire()\n>  \tif (!stateIs(CameraAvailable))\n>  \t\treturn -EBUSY;\n>  \n> +\tif (!pipe_->lock()) {\n> +\t\tLOG(Camera, Info) << \"Camera in use by other process\";\n\ns/Camera/Pipeline handler/ ?\n\n> +\t\treturn -EBUSY;\n> +\t}\n> +\n>  \tstate_ = CameraAcquired;\n>  \n>  \treturn 0;\n> @@ -516,6 +521,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[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E36E760DB4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 12:20:43 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 58557333;\n\tThu, 18 Apr 2019 12:20:43 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555582843;\n\tbh=/efJjoP+c3dTxka9014bWDRGME5GsubQnAp+uwKsbtM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=oO6LCH2No6yZ3SAAzeVJBDn45QUZWYngwYHdLDhtuF1Mm9mi5B3CGEwyl+iUKADpZ\n\tppEZiVAAW7BvEh+EqszyeC8kxXNgO4odghvVCSf4BZPmUUcuUN+wPtmNPNO48zEhB9\n\twF6sahYclB97YO4rJLASQ5chuGelxKBxl5d62PfI=","Date":"Thu, 18 Apr 2019 13:20:35 +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":"<20190418102035.GB761@pendragon.ideasonboard.com>","References":"<20190414013506.10515-1-niklas.soderlund@ragnatech.se>\n\t<20190414013506.10515-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":"<20190414013506.10515-12-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC 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":"Thu, 18 Apr 2019 10:20:44 -0000"}}]