[{"id":21673,"web_url":"https://patchwork.libcamera.org/comment/21673/","msgid":"<163896565727.1970692.11836368791651577009@Monstersaurus>","date":"2021-12-08T12:14:17","subject":"Re: [libcamera-devel] [PATCH v1 1/2] pipeline: raspberrypi: Move\n\tsensor entity detection out of registerCamera()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2021-12-01 11:57:10)\n> Enumerate the sensor device entities in PipelineHandlerRPi::match() and loop\n> over PipelineHandlerRPi::registerCamera() for each sensor found. This will\n> allow the pipeline handler to register multiple cameras attached to a single\n> Unicam instance with a Video Mux device.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nThis sounds like a really interesting use case/demonstration of how MC\nexposes the hardware to userspace to do something useful with it. Even\nbefore personally I'd struggled with the extra complexitys that MC\nbrings, so I'm glad to be seeing some of the 'benefits' it\nfacilitates...\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 35 +++++++++++--------\n>  1 file changed, 20 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index e31fa3b23859..811160490f5c 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -314,7 +314,7 @@ private:\n>                 return static_cast<RPiCameraData *>(camera->_d());\n>         }\n>  \n> -       int registerCamera(MediaDevice *unicam, MediaDevice *isp);\n> +       int registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity);\n>         int queueAllBuffers(Camera *camera);\n>         int prepareBuffers(Camera *camera);\n>         void freeBuffers(Camera *camera);\n> @@ -1009,16 +1009,28 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator)\n>                 return false;\n>         }\n>  \n> -       int ret = registerCamera(unicamDevice, ispDevice);\n> -       if (ret) {\n> -               LOG(RPI, Error) << \"Failed to register camera: \" << ret;\n> -               return false;\n> +       /*\n> +        * The loop below is used to register multiple cameras behind one or more\n> +        * video mux devices that are attaced to a particular Unicam instance.\n> +        * Obviously these cameras cannot be used simultaneously.\n> +        */\n> +       unsigned int numCameras = 0;\n> +       for (MediaEntity *entity : unicamDevice->entities()) {\n> +               if (entity->function() != MEDIA_ENT_F_CAM_SENSOR)\n> +                       continue;\n> +\n> +               int ret = registerCamera(unicamDevice, ispDevice, entity);\n> +               if (ret)\n> +                       LOG(RPI, Error) << \"Failed to register camera \"\n> +                                       << entity->name() << \": \" << ret;\n> +               else\n> +                       numCameras++;\n>         }\n>  \n> -       return true;\n> +       return !!numCameras;\n>  }\n>  \n> -int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp)\n> +int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp, MediaEntity *sensorEntity)\n>  {\n>         std::unique_ptr<RPiCameraData> data = std::make_unique<RPiCameraData>(this);\n>  \n> @@ -1059,14 +1071,7 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp)\n>         data->isp_[Isp::Output1].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue);\n>         data->isp_[Isp::Stats].dev()->bufferReady.connect(data.get(), &RPiCameraData::ispOutputDequeue);\n>  \n> -       /* Identify the sensor. */\n> -       for (MediaEntity *entity : unicam->entities()) {\n> -               if (entity->function() == MEDIA_ENT_F_CAM_SENSOR) {\n> -                       data->sensor_ = std::make_unique<CameraSensor>(entity);\n> -                       break;\n> -               }\n> -       }\n> -\n> +       data->sensor_ = std::make_unique<CameraSensor>(sensorEntity);\n>         if (!data->sensor_)\n>                 return -EINVAL;\n>  \n> -- \n> 2.25.1\n>","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 83344BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  8 Dec 2021 12:14:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 843EE6086A;\n\tWed,  8 Dec 2021 13:14:21 +0100 (CET)","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 2761260225\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Dec 2021 13:14:20 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B5D188BB;\n\tWed,  8 Dec 2021 13:14:19 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"C4RGxcSn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638965659;\n\tbh=lNY0OUPMYxQTH/gmqPUhNqDlsLEggaJyqYv7sKJbXqg=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=C4RGxcSnAAlFxmCNIxeOvTxEMKYTyQVS5FGE454CjrWB94q7AHRKiKUaeBwutB27b\n\tNU0LbooBDOtCysrTecSwAPYACggZMbI3mKeqaoT4CltaXLMwoZmemkIC6NNEchrCqs\n\tsVtcInCRHFaTTJTyWTSzibPaUGORBdoqaN4QoGPw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20211201115711.1017822-2-naush@raspberrypi.com>","References":"<20211201115711.1017822-1-naush@raspberrypi.com>\n\t<20211201115711.1017822-2-naush@raspberrypi.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 08 Dec 2021 12:14:17 +0000","Message-ID":"<163896565727.1970692.11836368791651577009@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v1 1/2] pipeline: raspberrypi: Move\n\tsensor entity detection out of registerCamera()","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>"}}]