[{"id":321,"web_url":"https://patchwork.libcamera.org/comment/321/","msgid":"<beb74b0c-3446-5b73-101c-95d11428e190@ideasonboard.com>","date":"2019-01-15T15:15:23","subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 15/01/2019 14:07, Jacopo Mondi wrote:\n> Add a pipeline handler for the Intel IPU3 device.\n> \n> The pipeline handler creates a Camera for each image sensor it finds to be\n> connected to an IPU3 CSI-2 receiver, and enables the link between the two.\n> \n> Tested on Soraka, listing detected cameras on the system, verifying the\n> pipeline handler gets matched and links properly enabled.\n> \n\nThis looks like a really good start, and I can start to understand how\nthe matching is going on now.\n\nAside from some discussion below I don't think there's anything really\nmajor to block this IMO.\n\nI left in my text about putting ->release in the destructor in case it\nwas actually relevant - but I think reading further down it became clear\nthat what I was suggesting is not a viable structure to the code.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp    | 249 ++++++++++++++++++++++++\n>  src/libcamera/pipeline/ipu3/meson.build |   3 +\n>  src/libcamera/pipeline/meson.build      |   2 +\n>  3 files changed, 254 insertions(+)\n>  create mode 100644 src/libcamera/pipeline/ipu3/ipu3.cpp\n>  create mode 100644 src/libcamera/pipeline/ipu3/meson.build\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> new file mode 100644\n> index 0000000..4c24c79\n> --- /dev/null\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -0,0 +1,249 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * ipu3.cpp - Pipeline handler for Intel IPU3\n> + */\n> +\n> +#include <map>\n> +#include <vector>\n> +\n> +#include <libcamera/camera.h>\n> +\n> +#include \"device_enumerator.h\"\n> +#include \"log.h\"\n> +#include \"media_device.h\"\n> +#include \"pipeline_handler.h\"\n> +\n> +namespace libcamera {\n> +\n> +class PipelineHandlerIPU3 : public PipelineHandler\n> +{\n> +public:\n> +\tPipelineHandlerIPU3();\n> +\t~PipelineHandlerIPU3();\n> +\n> +\tbool match(DeviceEnumerator *enumerator);\n> +\n> +\tunsigned int count();\n> +\tCamera *camera(unsigned int id) final;\n> +\n> +private:\n> +\tMediaDevice *cio2_;\n> +\tMediaDevice *imgu_;\n> +\n> +\tunsigned int numCameras_;\n> +\tstd::map<unsigned int, Camera *> cameras_;\n> +\n> +\tunsigned int registerCameras();\n> +};\n> +\n> +PipelineHandlerIPU3::PipelineHandlerIPU3()\n> +\t: cio2_(nullptr), imgu_(nullptr), numCameras_(0)\n> +{\n> +}\n> +\n> +PipelineHandlerIPU3::~PipelineHandlerIPU3()\n> +{\n> +\tif (cio2_)\n> +\t\tcio2_->release();\n\nDoes the MediaDevice destructor not do this call to ->release()?\n (And should it?)\n\n\t<edit - I read below... :) >\n\nThen these two would just be:\n\n\tdelete cio2_;\n\tdelete imgu_;\n\nBTW: I'm not objecting to a direct call to release() here - just\nconsidering options.\n\n\n> +\n> +\tif (imgu_)\n> +\t\timgu_->release();\n> +\n> +\tfor (auto camera : cameras_) {\n\nReading here - it's not clear what a camera.second is?\nI'll go dig in the code - but as it's not obvious (unless I'm missing\nsomething obvious) - perhaps it needs some description ?\n\n\n> +\t\tif (!camera.second)\n> +\t\t\tcontinue;\n> +\n> +\t\tcamera.second->put();\n> +\n> +\t\t/*\n> +\t\t * FIXME\n> +\t\t * The lifetime management of Camera instances will be\n> +\t\t * soon changed: as of now, the handler creates cameras, and\n> +\t\t * -shall- destroy them as well to avoid leaks.\n> +\t\t */\n> +\t\tdelete camera.second;\n\nAlthough - perhaps this '.second' is going to disappear - so it doesn't\nmatter.\n\n> +\t}\n> +\n> +\tcio2_ = nullptr;\n> +\timgu_ = nullptr;\n> +\tcameras_.clear();\n> +}\n> +\n> +unsigned int PipelineHandlerIPU3::count()\n> +{\n> +\treturn numCameras_;\n> +}\n> +\n> +Camera *PipelineHandlerIPU3::camera(unsigned int id)\n> +{\n> +\tif (id >= numCameras_)\n> +\t\treturn nullptr;\n> +\n> +\t/*\n> +\t * The requested camera id does not match the key index used to store\n> +\t * Camera instances in the 'cameras_' map.\n> +\t *\n> +\t * The 'id' argument represent the n-th valid cameras registered\n> +\t * in the system, while the indexing key is the CSI-2 receiver index\n> +\t * the camera sensor is associated to, and some receiver might have no\n> +\t * camera sensor connected.\n> +\t */\n> +\tfor (auto it = cameras_.begin(); it != cameras_.end(); ++it, --id) {\n> +\t\tif (id == 0)\n> +\t\t\treturn (*it).second;\n> +\t}\n> +\n> +\treturn nullptr;\n> +}\n> +\n> +bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n> +{\n> +\tDeviceMatch cio2_dm(\"ipu3-cio2\");\n> +\tcio2_dm.add(\"ipu3-csi2 0\");\n> +\tcio2_dm.add(\"ipu3-cio2 0\");\n> +\tcio2_dm.add(\"ipu3-csi2 1\");\n> +\tcio2_dm.add(\"ipu3-cio2 1\");\n> +\tcio2_dm.add(\"ipu3-csi2 2\");\n> +\tcio2_dm.add(\"ipu3-cio2 2\");\n> +\tcio2_dm.add(\"ipu3-csi2 3\");\n> +\tcio2_dm.add(\"ipu3-cio2 3\");\n> +\n> +\tcio2_ = enumerator->search(cio2_dm);\n> +\tif (!cio2_)\n> +\t\treturn false;\n> +\n> +\tcio2_->acquire();\n\nAha - never mind the above comments - We don't own the object to delete\nit ... nor should it be deleted above :)\n\n> +\n> +\tDeviceMatch imgu_dm(\"ipu3-imgu\");\n> +\timgu_dm.add(\"ipu3-imgu 0\");\n> +\timgu_dm.add(\"ipu3-imgu 0 input\");\n> +\timgu_dm.add(\"ipu3-imgu 0 parameters\");\n> +\timgu_dm.add(\"ipu3-imgu 0 output\");\n> +\timgu_dm.add(\"ipu3-imgu 0 viewfinder\");\n> +\timgu_dm.add(\"ipu3-imgu 0 3a stat\");\n> +\timgu_dm.add(\"ipu3-imgu 1\");\n> +\timgu_dm.add(\"ipu3-imgu 1 input\");\n> +\timgu_dm.add(\"ipu3-imgu 1 parameters\");\n> +\timgu_dm.add(\"ipu3-imgu 1 output\");\n> +\timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n> +\timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n> +\n> +\timgu_ = enumerator->search(imgu_dm);\n> +\tif (!imgu_) {\n> +\t\tcio2_->release();\n> +\t\treturn false;\n> +\t}\n> +\n> +\timgu_->acquire();\n> +\n> +\t/*\n> +\t * Disable all links that are enabled by default on CIO2, as camera\n> +\t * creation enables all valid links it finds.\n> +\t *\n> +\t * Close the CIO2 media device after, as links are enabled and should\n> +\t * not need to be changed after.\n> +\t */\n> +\tif (cio2_->open()) {\n> +\t\tcio2_->release();\n> +\t\timgu_->release();\n> +\t\treturn false;\n> +\t}\n> +\tcio2_->disableLinks();\n> +\n> +\tnumCameras_ = registerCameras();\n> +\tLOG(Debug) << \"\\\"Intel IPU3\\\" pipeline handler initialized with \"\n> +\t\t   << numCameras_ << \" cameras registered\";\n> +\n> +\tcio2_->close();\n> +\n> +\treturn true;\n> +}\n> +\n> +/*\n> + * Cameras are created associating an image sensor (represented by a\n> + * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four\n> + * CIO2 CSI-2 receivers.\n> + *\n> + * Cameras are here created and stored in the member field 'cameras_' map,\n> + * indexed by the id of the CSI-2 receiver they are connected, to maintain\n> + * an ordering that does not depend on the device enumeration order.\n> + *\n> + * The function returns the number of cameras found in the system.\n> + */\n> +unsigned int PipelineHandlerIPU3::registerCameras()\n> +{\n> +\tconst std::vector<MediaEntity *> entities = cio2_->entities();\n> +\tunsigned int numCameras = 0;\n> +\tstruct {\n> +\t\tunsigned int id;\n> +\t\tMediaEntity *csi2;\n> +\t} csi2Receivers[] = {\n> +\t\t{ 0, cio2_->getEntityByName(\"ipu3-csi2 0\") },\n> +\t\t{ 1, cio2_->getEntityByName(\"ipu3-csi2 1\") },\n> +\t\t{ 2, cio2_->getEntityByName(\"ipu3-csi2 2\") },\n> +\t\t{ 3, cio2_->getEntityByName(\"ipu3-csi2 3\") },\n> +\t};\n> +\n> +\t/*\n> +\t * For each CSI-2 receiver on the IPU3, create a Camera if an\n> +\t * image sensor is connected to it.\n> +\t */\n> +\tfor (auto csi2Receiver : csi2Receivers) {\n> +\t\tMediaEntity *csi2 = csi2Receiver.csi2;\n> +\t\tunsigned int id = csi2Receiver.id;\n> +\n> +\t\t/* IPU3 CSI-2 receivers have a single sink pad. */\n> +\t\tstd::vector<MediaPad *> pads = csi2->pads();\n> +\t\tMediaPad *sink;\n> +\t\tfor (MediaPad *pad : pads) {\n> +\t\t\tif (!(pad->flags() & MEDIA_PAD_FL_SINK))\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tsink = pad;\n> +\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\t/* Verify that the receiver is connected to a sensor. */\n> +\t\tstd::vector<MediaLink *> links = sink->links();\n> +\t\tif (links.empty())\n> +\t\t\tcontinue;\n> +\n> +\t\t/*\n> +\t\t * FIXME\n> +\t\t * This supports creating a single camera per CSI-2 receiver.\n> +\t\t */\n> +\t\tfor (MediaLink *link : links) {\n> +\t\t\tMediaEntity *sensor = link->source()->entity();\n> +\t\t\tif (!sensor)\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\tif (sensor->function() != MEDIA_ENT_F_CAM_SENSOR)\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\t/* Enable the link between sensor and CSI-2 receiver. */\n> +\t\t\tif (link->setEnabled(true))\n> +\t\t\t\tcontinue;\n> +\n> +\t\t\t/* Create the camera using the sensor name. */\n> +\t\t\tstd::size_t pos = sensor->name().find(\" \");\n> +\t\t\tstd::string cameraName = sensor->name().substr(0, pos);\n\nI presume we'll have to make sure that this string is unique in the\nsystem somewhere / somehow - but for now this is a good way to map the\ncameras.\n\n> +\n> +\t\t\tcameras_[id] = new Camera(cameraName);\n> +\n> +\t\t\tLOG(Debug) << \"Registered Camera[\" << numCameras\n> +\t\t\t\t   << \"] \\\"\" << cameraName << \"\\\"\"\n> +\t\t\t\t   << \" connected to CSI-2 receiver \" << id;\n> +\n> +\t\t\tnumCameras++;\n> +\t\t\tbreak;\n> +\t\t}\n> +\t}\n> +\n> +\treturn numCameras;\n> +}\n> +\n> +REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/ipu3/meson.build b/src/libcamera/pipeline/ipu3/meson.build\n> new file mode 100644\n> index 0000000..0ab766a\n> --- /dev/null\n> +++ b/src/libcamera/pipeline/ipu3/meson.build\n> @@ -0,0 +1,3 @@\n> +libcamera_sources += files([\n> +    'ipu3.cpp',\n> +])\n> diff --git a/src/libcamera/pipeline/meson.build b/src/libcamera/pipeline/meson.build\n> index 615ecd2..811c075 100644\n> --- a/src/libcamera/pipeline/meson.build\n> +++ b/src/libcamera/pipeline/meson.build\n> @@ -1,3 +1,5 @@\n>  libcamera_sources += files([\n>      'vimc.cpp',\n>  ])\n> +\n> +subdir('ipu3')\n>","headers":{"Return-Path":"<kieran.bingham@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 B6F1860C78\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 16:15:27 +0100 (CET)","from [192.168.0.21]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DA7F04F8;\n\tTue, 15 Jan 2019 16:15:26 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547565327;\n\tbh=1KFFhEMkgMIH9RO/SBvkcMsoxVGHVXIanXgOZmo66cw=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=ekBaVpx73b+LRUbfZim2iAMjBqhyIU1gruAGaZFVmp3zzOhe3B9uWSUVeE3FUblkx\n\tCp8n6CIgR5+ZpX8eVBVjTYgKoUR4fLTdcrSedsDkskYzWOacTAdT0IcnvwUljcDy5R\n\t9cq4thwLLmY6w8vJrXoRxxKDNTI7wwgkxakuFwN4=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Jacopo Mondi <jacopo@jmondi.org>, libcamera-devel@lists.libcamera.org","References":"<20190115140749.8297-1-jacopo@jmondi.org>\n\t<20190115140749.8297-5-jacopo@jmondi.org>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yM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LKeRhxxfiXCIYEf3vwOsP3YMx2JkD5doseXmWBGW1U0T/oJF+DVfKB6mv5UfsTzpVhJRgee7\n\t4jkjqFq4qsUGxcvF2xtRkfHFpZDbRgRlVmiWkqDkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<beb74b0c-3446-5b73-101c-95d11428e190@ideasonboard.com>","Date":"Tue, 15 Jan 2019 15:15:23 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.2.1","MIME-Version":"1.0","In-Reply-To":"<20190115140749.8297-5-jacopo@jmondi.org>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","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":"Tue, 15 Jan 2019 15:15:27 -0000"}},{"id":333,"web_url":"https://patchwork.libcamera.org/comment/333/","msgid":"<20190115173755.tpj2tlpxuotww2wv@uno.localdomain>","date":"2019-01-15T17:37:55","subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Kieran,\n\nOn Tue, Jan 15, 2019 at 03:15:23PM +0000, Kieran Bingham wrote:\n> Hi Jacopo,\n>\n> On 15/01/2019 14:07, Jacopo Mondi wrote:\n> > Add a pipeline handler for the Intel IPU3 device.\n> >\n> > The pipeline handler creates a Camera for each image sensor it finds to be\n> > connected to an IPU3 CSI-2 receiver, and enables the link between the two.\n> >\n> > Tested on Soraka, listing detected cameras on the system, verifying the\n> > pipeline handler gets matched and links properly enabled.\n> >\n>\n> This looks like a really good start, and I can start to understand how\n> the matching is going on now.\n>\n> Aside from some discussion below I don't think there's anything really\n> major to block this IMO.\n>\n> I left in my text about putting ->release in the destructor in case it\n> was actually relevant - but I think reading further down it became clear\n> that what I was suggesting is not a viable structure to the code.\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/libcamera/pipeline/ipu3/ipu3.cpp    | 249 ++++++++++++++++++++++++\n> >  src/libcamera/pipeline/ipu3/meson.build |   3 +\n> >  src/libcamera/pipeline/meson.build      |   2 +\n> >  3 files changed, 254 insertions(+)\n> >  create mode 100644 src/libcamera/pipeline/ipu3/ipu3.cpp\n> >  create mode 100644 src/libcamera/pipeline/ipu3/meson.build\n> >\n> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > new file mode 100644\n> > index 0000000..4c24c79\n> > --- /dev/null\n> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> > @@ -0,0 +1,249 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2019, Google Inc.\n> > + *\n> > + * ipu3.cpp - Pipeline handler for Intel IPU3\n> > + */\n> > +\n> > +#include <map>\n> > +#include <vector>\n> > +\n> > +#include <libcamera/camera.h>\n> > +\n> > +#include \"device_enumerator.h\"\n> > +#include \"log.h\"\n> > +#include \"media_device.h\"\n> > +#include \"pipeline_handler.h\"\n> > +\n> > +namespace libcamera {\n> > +\n> > +class PipelineHandlerIPU3 : public PipelineHandler\n> > +{\n> > +public:\n> > +\tPipelineHandlerIPU3();\n> > +\t~PipelineHandlerIPU3();\n> > +\n> > +\tbool match(DeviceEnumerator *enumerator);\n> > +\n> > +\tunsigned int count();\n> > +\tCamera *camera(unsigned int id) final;\n> > +\n> > +private:\n> > +\tMediaDevice *cio2_;\n> > +\tMediaDevice *imgu_;\n> > +\n> > +\tunsigned int numCameras_;\n> > +\tstd::map<unsigned int, Camera *> cameras_;\n> > +\n> > +\tunsigned int registerCameras();\n> > +};\n> > +\n> > +PipelineHandlerIPU3::PipelineHandlerIPU3()\n> > +\t: cio2_(nullptr), imgu_(nullptr), numCameras_(0)\n> > +{\n> > +}\n> > +\n> > +PipelineHandlerIPU3::~PipelineHandlerIPU3()\n> > +{\n> > +\tif (cio2_)\n> > +\t\tcio2_->release();\n>\n> Does the MediaDevice destructor not do this call to ->release()?\n>  (And should it?)\n>\n> \t<edit - I read below... :) >\n>\n> Then these two would just be:\n>\n> \tdelete cio2_;\n> \tdelete imgu_;\n>\n> BTW: I'm not objecting to a direct call to release() here - just\n> considering options.\n\nAs you found out below, I shall not delete MediaDevices from here.\n\n>\n>\n> > +\n> > +\tif (imgu_)\n> > +\t\timgu_->release();\n> > +\n> > +\tfor (auto camera : cameras_) {\n>\n> Reading here - it's not clear what a camera.second is?\n> I'll go dig in the code - but as it's not obvious (unless I'm missing\n> something obvious) - perhaps it needs some description ?\n>\n\nCameras_' a std::map, just look at the type of the template.\nI can add a small comments, even if I have commented extensively on\nthe indexing of cameras in the class..\n\n>\n> > +\t\tif (!camera.second)\n> > +\t\t\tcontinue;\n> > +\n> > +\t\tcamera.second->put();\n> > +\n> > +\t\t/*\n> > +\t\t * FIXME\n> > +\t\t * The lifetime management of Camera instances will be\n> > +\t\t * soon changed: as of now, the handler creates cameras, and\n> > +\t\t * -shall- destroy them as well to avoid leaks.\n> > +\t\t */\n> > +\t\tdelete camera.second;\n>\n> Although - perhaps this '.second' is going to disappear - so it doesn't\n> matter.\n>\n\nLifetime management of cameras is not IPU3 specific. The use of a map\nto index cameras according to their CSI-2 receiver indexes (so that\ncamera connected to CSI-2 0 always comes first than camera connected\nto CSI-2 3) is specific of this implementation. If that does not get\nchanged after this review round, the '.second' stays.\n\nI could:\n        Camera *cam = camera->second;\n\n> > +\t}\n> > +\n> > +\tcio2_ = nullptr;\n> > +\timgu_ = nullptr;\n> > +\tcameras_.clear();\n> > +}\n> > +\n> > +unsigned int PipelineHandlerIPU3::count()\n> > +{\n> > +\treturn numCameras_;\n> > +}\n> > +\n> > +Camera *PipelineHandlerIPU3::camera(unsigned int id)\n> > +{\n> > +\tif (id >= numCameras_)\n> > +\t\treturn nullptr;\n> > +\n> > +\t/*\n> > +\t * The requested camera id does not match the key index used to store\n> > +\t * Camera instances in the 'cameras_' map.\n> > +\t *\n> > +\t * The 'id' argument represent the n-th valid cameras registered\n> > +\t * in the system, while the indexing key is the CSI-2 receiver index\n> > +\t * the camera sensor is associated to, and some receiver might have no\n> > +\t * camera sensor connected.\n> > +\t */\n> > +\tfor (auto it = cameras_.begin(); it != cameras_.end(); ++it, --id) {\n> > +\t\tif (id == 0)\n> > +\t\t\treturn (*it).second;\n> > +\t}\n> > +\n> > +\treturn nullptr;\n> > +}\n> > +\n> > +bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n> > +{\n> > +\tDeviceMatch cio2_dm(\"ipu3-cio2\");\n> > +\tcio2_dm.add(\"ipu3-csi2 0\");\n> > +\tcio2_dm.add(\"ipu3-cio2 0\");\n> > +\tcio2_dm.add(\"ipu3-csi2 1\");\n> > +\tcio2_dm.add(\"ipu3-cio2 1\");\n> > +\tcio2_dm.add(\"ipu3-csi2 2\");\n> > +\tcio2_dm.add(\"ipu3-cio2 2\");\n> > +\tcio2_dm.add(\"ipu3-csi2 3\");\n> > +\tcio2_dm.add(\"ipu3-cio2 3\");\n> > +\n> > +\tcio2_ = enumerator->search(cio2_dm);\n> > +\tif (!cio2_)\n> > +\t\treturn false;\n> > +\n> > +\tcio2_->acquire();\n>\n> Aha - never mind the above comments - We don't own the object to delete\n> it ... nor should it be deleted above :)\n>\n> > +\n> > +\tDeviceMatch imgu_dm(\"ipu3-imgu\");\n> > +\timgu_dm.add(\"ipu3-imgu 0\");\n> > +\timgu_dm.add(\"ipu3-imgu 0 input\");\n> > +\timgu_dm.add(\"ipu3-imgu 0 parameters\");\n> > +\timgu_dm.add(\"ipu3-imgu 0 output\");\n> > +\timgu_dm.add(\"ipu3-imgu 0 viewfinder\");\n> > +\timgu_dm.add(\"ipu3-imgu 0 3a stat\");\n> > +\timgu_dm.add(\"ipu3-imgu 1\");\n> > +\timgu_dm.add(\"ipu3-imgu 1 input\");\n> > +\timgu_dm.add(\"ipu3-imgu 1 parameters\");\n> > +\timgu_dm.add(\"ipu3-imgu 1 output\");\n> > +\timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n> > +\timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n> > +\n> > +\timgu_ = enumerator->search(imgu_dm);\n> > +\tif (!imgu_) {\n> > +\t\tcio2_->release();\n> > +\t\treturn false;\n> > +\t}\n> > +\n> > +\timgu_->acquire();\n> > +\n> > +\t/*\n> > +\t * Disable all links that are enabled by default on CIO2, as camera\n> > +\t * creation enables all valid links it finds.\n> > +\t *\n> > +\t * Close the CIO2 media device after, as links are enabled and should\n> > +\t * not need to be changed after.\n> > +\t */\n> > +\tif (cio2_->open()) {\n> > +\t\tcio2_->release();\n> > +\t\timgu_->release();\n> > +\t\treturn false;\n> > +\t}\n> > +\tcio2_->disableLinks();\n> > +\n> > +\tnumCameras_ = registerCameras();\n> > +\tLOG(Debug) << \"\\\"Intel IPU3\\\" pipeline handler initialized with \"\n> > +\t\t   << numCameras_ << \" cameras registered\";\n> > +\n> > +\tcio2_->close();\n> > +\n> > +\treturn true;\n> > +}\n> > +\n> > +/*\n> > + * Cameras are created associating an image sensor (represented by a\n> > + * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four\n> > + * CIO2 CSI-2 receivers.\n> > + *\n> > + * Cameras are here created and stored in the member field 'cameras_' map,\n> > + * indexed by the id of the CSI-2 receiver they are connected, to maintain\n> > + * an ordering that does not depend on the device enumeration order.\n> > + *\n> > + * The function returns the number of cameras found in the system.\n> > + */\n> > +unsigned int PipelineHandlerIPU3::registerCameras()\n> > +{\n> > +\tconst std::vector<MediaEntity *> entities = cio2_->entities();\n> > +\tunsigned int numCameras = 0;\n> > +\tstruct {\n> > +\t\tunsigned int id;\n> > +\t\tMediaEntity *csi2;\n> > +\t} csi2Receivers[] = {\n> > +\t\t{ 0, cio2_->getEntityByName(\"ipu3-csi2 0\") },\n> > +\t\t{ 1, cio2_->getEntityByName(\"ipu3-csi2 1\") },\n> > +\t\t{ 2, cio2_->getEntityByName(\"ipu3-csi2 2\") },\n> > +\t\t{ 3, cio2_->getEntityByName(\"ipu3-csi2 3\") },\n> > +\t};\n> > +\n> > +\t/*\n> > +\t * For each CSI-2 receiver on the IPU3, create a Camera if an\n> > +\t * image sensor is connected to it.\n> > +\t */\n> > +\tfor (auto csi2Receiver : csi2Receivers) {\n> > +\t\tMediaEntity *csi2 = csi2Receiver.csi2;\n> > +\t\tunsigned int id = csi2Receiver.id;\n> > +\n> > +\t\t/* IPU3 CSI-2 receivers have a single sink pad. */\n> > +\t\tstd::vector<MediaPad *> pads = csi2->pads();\n> > +\t\tMediaPad *sink;\n> > +\t\tfor (MediaPad *pad : pads) {\n> > +\t\t\tif (!(pad->flags() & MEDIA_PAD_FL_SINK))\n> > +\t\t\t\tcontinue;\n> > +\n> > +\t\t\tsink = pad;\n> > +\t\t\tbreak;\n> > +\t\t}\n> > +\n> > +\t\t/* Verify that the receiver is connected to a sensor. */\n> > +\t\tstd::vector<MediaLink *> links = sink->links();\n> > +\t\tif (links.empty())\n> > +\t\t\tcontinue;\n> > +\n> > +\t\t/*\n> > +\t\t * FIXME\n> > +\t\t * This supports creating a single camera per CSI-2 receiver.\n> > +\t\t */\n> > +\t\tfor (MediaLink *link : links) {\n> > +\t\t\tMediaEntity *sensor = link->source()->entity();\n> > +\t\t\tif (!sensor)\n> > +\t\t\t\tcontinue;\n> > +\n> > +\t\t\tif (sensor->function() != MEDIA_ENT_F_CAM_SENSOR)\n> > +\t\t\t\tcontinue;\n> > +\n> > +\t\t\t/* Enable the link between sensor and CSI-2 receiver. */\n> > +\t\t\tif (link->setEnabled(true))\n> > +\t\t\t\tcontinue;\n> > +\n> > +\t\t\t/* Create the camera using the sensor name. */\n> > +\t\t\tstd::size_t pos = sensor->name().find(\" \");\n> > +\t\t\tstd::string cameraName = sensor->name().substr(0, pos);\n>\n> I presume we'll have to make sure that this string is unique in the\n> system somewhere / somehow - but for now this is a good way to map the\n> cameras.\n>\n\nI cut off the bus address, if we keep that the name would be unique\nindeed. Otherwise yes, two sensors with the same name would give two\ncameras with the same name -> very bad. This needs to be changed, but\ninstead of the bus address I would use the CSI-2 receiver index to\nform a unique name...\n\n> > +\n> > +\t\t\tcameras_[id] = new Camera(cameraName);\n> > +\n> > +\t\t\tLOG(Debug) << \"Registered Camera[\" << numCameras\n> > +\t\t\t\t   << \"] \\\"\" << cameraName << \"\\\"\"\n> > +\t\t\t\t   << \" connected to CSI-2 receiver \" << id;\n> > +\n> > +\t\t\tnumCameras++;\n> > +\t\t\tbreak;\n> > +\t\t}\n> > +\t}\n> > +\n> > +\treturn numCameras;\n> > +}\n> > +\n> > +REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);\n> > +\n> > +} /* namespace libcamera */\n> > diff --git a/src/libcamera/pipeline/ipu3/meson.build b/src/libcamera/pipeline/ipu3/meson.build\n> > new file mode 100644\n> > index 0000000..0ab766a\n> > --- /dev/null\n> > +++ b/src/libcamera/pipeline/ipu3/meson.build\n> > @@ -0,0 +1,3 @@\n> > +libcamera_sources += files([\n> > +    'ipu3.cpp',\n> > +])\n> > diff --git a/src/libcamera/pipeline/meson.build b/src/libcamera/pipeline/meson.build\n> > index 615ecd2..811c075 100644\n> > --- a/src/libcamera/pipeline/meson.build\n> > +++ b/src/libcamera/pipeline/meson.build\n> > @@ -1,3 +1,5 @@\n> >  libcamera_sources += files([\n> >      'vimc.cpp',\n> >  ])\n> > +\n> > +subdir('ipu3')\n> >\n>\n> --\n> Regards\n> --\n> Kieran","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E5E660C88\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 18:37:47 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 9085024000B;\n\tTue, 15 Jan 2019 17:37:46 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Tue, 15 Jan 2019 18:37:55 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190115173755.tpj2tlpxuotww2wv@uno.localdomain>","References":"<20190115140749.8297-1-jacopo@jmondi.org>\n\t<20190115140749.8297-5-jacopo@jmondi.org>\n\t<beb74b0c-3446-5b73-101c-95d11428e190@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"o3jnkrwvrdofavjg\"","Content-Disposition":"inline","In-Reply-To":"<beb74b0c-3446-5b73-101c-95d11428e190@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","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":"Tue, 15 Jan 2019 17:37:47 -0000"}},{"id":334,"web_url":"https://patchwork.libcamera.org/comment/334/","msgid":"<e58c783c-fa37-0215-5c35-423011973572@ideasonboard.com>","date":"2019-01-15T19:35:19","subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn 15/01/2019 17:37, Jacopo Mondi wrote:\n> Hi Kieran,\n> \n> On Tue, Jan 15, 2019 at 03:15:23PM +0000, Kieran Bingham wrote:\n>> Hi Jacopo,\n>>\n>> On 15/01/2019 14:07, Jacopo Mondi wrote:\n>>> Add a pipeline handler for the Intel IPU3 device.\n>>>\n>>> The pipeline handler creates a Camera for each image sensor it finds to be\n>>> connected to an IPU3 CSI-2 receiver, and enables the link between the two.\n>>>\n>>> Tested on Soraka, listing detected cameras on the system, verifying the\n>>> pipeline handler gets matched and links properly enabled.\n>>>\n>>\n>> This looks like a really good start, and I can start to understand how\n>> the matching is going on now.\n>>\n>> Aside from some discussion below I don't think there's anything really\n>> major to block this IMO.\n>>\n>> I left in my text about putting ->release in the destructor in case it\n>> was actually relevant - but I think reading further down it became clear\n>> that what I was suggesting is not a viable structure to the code.\n>>\n>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>>\n>>> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n>>> ---\n>>>  src/libcamera/pipeline/ipu3/ipu3.cpp    | 249 ++++++++++++++++++++++++\n>>>  src/libcamera/pipeline/ipu3/meson.build |   3 +\n>>>  src/libcamera/pipeline/meson.build      |   2 +\n>>>  3 files changed, 254 insertions(+)\n>>>  create mode 100644 src/libcamera/pipeline/ipu3/ipu3.cpp\n>>>  create mode 100644 src/libcamera/pipeline/ipu3/meson.build\n>>>\n>>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>>> new file mode 100644\n>>> index 0000000..4c24c79\n>>> --- /dev/null\n>>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>>> @@ -0,0 +1,249 @@\n>>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n>>> +/*\n>>> + * Copyright (C) 2019, Google Inc.\n>>> + *\n>>> + * ipu3.cpp - Pipeline handler for Intel IPU3\n>>> + */\n>>> +\n>>> +#include <map>\n>>> +#include <vector>\n>>> +\n>>> +#include <libcamera/camera.h>\n>>> +\n>>> +#include \"device_enumerator.h\"\n>>> +#include \"log.h\"\n>>> +#include \"media_device.h\"\n>>> +#include \"pipeline_handler.h\"\n>>> +\n>>> +namespace libcamera {\n>>> +\n>>> +class PipelineHandlerIPU3 : public PipelineHandler\n>>> +{\n>>> +public:\n>>> +\tPipelineHandlerIPU3();\n>>> +\t~PipelineHandlerIPU3();\n>>> +\n>>> +\tbool match(DeviceEnumerator *enumerator);\n>>> +\n>>> +\tunsigned int count();\n>>> +\tCamera *camera(unsigned int id) final;\n>>> +\n>>> +private:\n>>> +\tMediaDevice *cio2_;\n>>> +\tMediaDevice *imgu_;\n>>> +\n>>> +\tunsigned int numCameras_;\n>>> +\tstd::map<unsigned int, Camera *> cameras_;\n>>> +\n>>> +\tunsigned int registerCameras();\n>>> +};\n>>> +\n>>> +PipelineHandlerIPU3::PipelineHandlerIPU3()\n>>> +\t: cio2_(nullptr), imgu_(nullptr), numCameras_(0)\n>>> +{\n>>> +}\n>>> +\n>>> +PipelineHandlerIPU3::~PipelineHandlerIPU3()\n>>> +{\n>>> +\tif (cio2_)\n>>> +\t\tcio2_->release();\n>>\n>> Does the MediaDevice destructor not do this call to ->release()?\n>>  (And should it?)\n>>\n>> \t<edit - I read below... :) >\n>>\n>> Then these two would just be:\n>>\n>> \tdelete cio2_;\n>> \tdelete imgu_;\n>>\n>> BTW: I'm not objecting to a direct call to release() here - just\n>> considering options.\n> \n> As you found out below, I shall not delete MediaDevices from here.\n> \n>>\n>>\n>>> +\n>>> +\tif (imgu_)\n>>> +\t\timgu_->release();\n>>> +\n>>> +\tfor (auto camera : cameras_) {\n>>\n>> Reading here - it's not clear what a camera.second is?\n>> I'll go dig in the code - but as it's not obvious (unless I'm missing\n>> something obvious) - perhaps it needs some description ?\n>>\n> \n> Cameras_' a std::map, just look at the type of the template.\n> I can add a small comments, even if I have commented extensively on\n> the indexing of cameras in the class..\n\nSo I'm still really confused by the naming.\n\nWhy is it called a second? Does it represent a period of time? Is it a\nsecond instance of the camera? Why does the camera need a second instance...\n\n\nOH. *it's not a libcamera::Camera*\n\n\nYou know what -  I think I'm afraid I've just validated Laurent's\nreasoning not to use auto.\n\n\nI read: for (auto camera : cameras_) { ... as\n\t'for each \"libcamera::Camera\" in cameras_ ... so I had no idea what a\n'second' was.\n\nBut we're not dealing with libcamera::Camera here - we're dealing with a\nstd::pair from the map iterator.\n\nI fear that's really not clear without naming the type here...\n\n\n\n>>\n>>> +\t\tif (!camera.second)\n>>> +\t\t\tcontinue;\n>>> +\n>>> +\t\tcamera.second->put();\n>>> +\n>>> +\t\t/*\n>>> +\t\t * FIXME\n>>> +\t\t * The lifetime management of Camera instances will be\n>>> +\t\t * soon changed: as of now, the handler creates cameras, and\n>>> +\t\t * -shall- destroy them as well to avoid leaks.\n>>> +\t\t */\n>>> +\t\tdelete camera.second;\n>>\n>> Although - perhaps this '.second' is going to disappear - so it doesn't\n>> matter.\n>>\n> \n> Lifetime management of cameras is not IPU3 specific. The use of a map\n> to index cameras according to their CSI-2 receiver indexes (so that\n> camera connected to CSI-2 0 always comes first than camera connected\n> to CSI-2 3) is specific of this implementation. If that does not get\n> changed after this review round, the '.second' stays.\n> \n> I could:\n>         Camera *cam = camera->second;\n\nYes - that would make things a lot clearer too.\nPerhaps we could also rename the iterator?\n\n\n> \n>>> +\t}\n>>> +\n>>> +\tcio2_ = nullptr;\n>>> +\timgu_ = nullptr;\n>>> +\tcameras_.clear();\n>>> +}\n>>> +\n>>> +unsigned int PipelineHandlerIPU3::count()\n>>> +{\n>>> +\treturn numCameras_;\n>>> +}\n>>> +\n>>> +Camera *PipelineHandlerIPU3::camera(unsigned int id)\n>>> +{\n>>> +\tif (id >= numCameras_)\n>>> +\t\treturn nullptr;\n>>> +\n>>> +\t/*\n>>> +\t * The requested camera id does not match the key index used to store\n>>> +\t * Camera instances in the 'cameras_' map.\n>>> +\t *\n>>> +\t * The 'id' argument represent the n-th valid cameras registered\n>>> +\t * in the system, while the indexing key is the CSI-2 receiver index\n>>> +\t * the camera sensor is associated to, and some receiver might have no\n>>> +\t * camera sensor connected.\n>>> +\t */\n>>> +\tfor (auto it = cameras_.begin(); it != cameras_.end(); ++it, --id) {\n>>> +\t\tif (id == 0)\n>>> +\t\t\treturn (*it).second;\n>>> +\t}\n>>> +\n>>> +\treturn nullptr;\n>>> +}\n>>> +\n>>> +bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>>> +{\n>>> +\tDeviceMatch cio2_dm(\"ipu3-cio2\");\n>>> +\tcio2_dm.add(\"ipu3-csi2 0\");\n>>> +\tcio2_dm.add(\"ipu3-cio2 0\");\n>>> +\tcio2_dm.add(\"ipu3-csi2 1\");\n>>> +\tcio2_dm.add(\"ipu3-cio2 1\");\n>>> +\tcio2_dm.add(\"ipu3-csi2 2\");\n>>> +\tcio2_dm.add(\"ipu3-cio2 2\");\n>>> +\tcio2_dm.add(\"ipu3-csi2 3\");\n>>> +\tcio2_dm.add(\"ipu3-cio2 3\");\n>>> +\n>>> +\tcio2_ = enumerator->search(cio2_dm);\n>>> +\tif (!cio2_)\n>>> +\t\treturn false;\n>>> +\n>>> +\tcio2_->acquire();\n>>\n>> Aha - never mind the above comments - We don't own the object to delete\n>> it ... nor should it be deleted above :)\n>>\n>>> +\n>>> +\tDeviceMatch imgu_dm(\"ipu3-imgu\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0 input\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0 parameters\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0 output\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0 viewfinder\");\n>>> +\timgu_dm.add(\"ipu3-imgu 0 3a stat\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1 input\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1 parameters\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1 output\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n>>> +\timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n>>> +\n>>> +\timgu_ = enumerator->search(imgu_dm);\n>>> +\tif (!imgu_) {\n>>> +\t\tcio2_->release();\n>>> +\t\treturn false;\n>>> +\t}\n>>> +\n>>> +\timgu_->acquire();\n>>> +\n>>> +\t/*\n>>> +\t * Disable all links that are enabled by default on CIO2, as camera\n>>> +\t * creation enables all valid links it finds.\n>>> +\t *\n>>> +\t * Close the CIO2 media device after, as links are enabled and should\n>>> +\t * not need to be changed after.\n>>> +\t */\n>>> +\tif (cio2_->open()) {\n>>> +\t\tcio2_->release();\n>>> +\t\timgu_->release();\n>>> +\t\treturn false;\n>>> +\t}\n>>> +\tcio2_->disableLinks();\n>>> +\n>>> +\tnumCameras_ = registerCameras();\n>>> +\tLOG(Debug) << \"\\\"Intel IPU3\\\" pipeline handler initialized with \"\n>>> +\t\t   << numCameras_ << \" cameras registered\";\n>>> +\n>>> +\tcio2_->close();\n>>> +\n>>> +\treturn true;\n>>> +}\n>>> +\n>>> +/*\n>>> + * Cameras are created associating an image sensor (represented by a\n>>> + * media entity with function MEDIA_ENT_F_CAM_SENSOR) to one of the four\n>>> + * CIO2 CSI-2 receivers.\n>>> + *\n>>> + * Cameras are here created and stored in the member field 'cameras_' map,\n>>> + * indexed by the id of the CSI-2 receiver they are connected, to maintain\n>>> + * an ordering that does not depend on the device enumeration order.\n>>> + *\n>>> + * The function returns the number of cameras found in the system.\n>>> + */\n>>> +unsigned int PipelineHandlerIPU3::registerCameras()\n>>> +{\n>>> +\tconst std::vector<MediaEntity *> entities = cio2_->entities();\n>>> +\tunsigned int numCameras = 0;\n>>> +\tstruct {\n>>> +\t\tunsigned int id;\n>>> +\t\tMediaEntity *csi2;\n>>> +\t} csi2Receivers[] = {\n>>> +\t\t{ 0, cio2_->getEntityByName(\"ipu3-csi2 0\") },\n>>> +\t\t{ 1, cio2_->getEntityByName(\"ipu3-csi2 1\") },\n>>> +\t\t{ 2, cio2_->getEntityByName(\"ipu3-csi2 2\") },\n>>> +\t\t{ 3, cio2_->getEntityByName(\"ipu3-csi2 3\") },\n>>> +\t};\n>>> +\n>>> +\t/*\n>>> +\t * For each CSI-2 receiver on the IPU3, create a Camera if an\n>>> +\t * image sensor is connected to it.\n>>> +\t */\n>>> +\tfor (auto csi2Receiver : csi2Receivers) {\n>>> +\t\tMediaEntity *csi2 = csi2Receiver.csi2;\n>>> +\t\tunsigned int id = csi2Receiver.id;\n>>> +\n>>> +\t\t/* IPU3 CSI-2 receivers have a single sink pad. */\n>>> +\t\tstd::vector<MediaPad *> pads = csi2->pads();\n>>> +\t\tMediaPad *sink;\n>>> +\t\tfor (MediaPad *pad : pads) {\n>>> +\t\t\tif (!(pad->flags() & MEDIA_PAD_FL_SINK))\n>>> +\t\t\t\tcontinue;\n>>> +\n>>> +\t\t\tsink = pad;\n>>> +\t\t\tbreak;\n>>> +\t\t}\n>>> +\n>>> +\t\t/* Verify that the receiver is connected to a sensor. */\n>>> +\t\tstd::vector<MediaLink *> links = sink->links();\n>>> +\t\tif (links.empty())\n>>> +\t\t\tcontinue;\n>>> +\n>>> +\t\t/*\n>>> +\t\t * FIXME\n>>> +\t\t * This supports creating a single camera per CSI-2 receiver.\n>>> +\t\t */\n>>> +\t\tfor (MediaLink *link : links) {\n>>> +\t\t\tMediaEntity *sensor = link->source()->entity();\n>>> +\t\t\tif (!sensor)\n>>> +\t\t\t\tcontinue;\n>>> +\n>>> +\t\t\tif (sensor->function() != MEDIA_ENT_F_CAM_SENSOR)\n>>> +\t\t\t\tcontinue;\n>>> +\n>>> +\t\t\t/* Enable the link between sensor and CSI-2 receiver. */\n>>> +\t\t\tif (link->setEnabled(true))\n>>> +\t\t\t\tcontinue;\n>>> +\n>>> +\t\t\t/* Create the camera using the sensor name. */\n>>> +\t\t\tstd::size_t pos = sensor->name().find(\" \");\n>>> +\t\t\tstd::string cameraName = sensor->name().substr(0, pos);\n>>\n>> I presume we'll have to make sure that this string is unique in the\n>> system somewhere / somehow - but for now this is a good way to map the\n>> cameras.\n>>\n> \n> I cut off the bus address, if we keep that the name would be unique\n> indeed. Otherwise yes, two sensors with the same name would give two\n> cameras with the same name -> very bad. This needs to be changed, but\n> instead of the bus address I would use the CSI-2 receiver index to\n> form a unique name...\n\nI'm not too worried here at the moment.\nWe can add in assertions to make sure we don't add a camera name which\nalready exists, and we can work out a unique naming later because it's\nnot going to be an ABI string. It's just a representation.\n\nMight be worth adding a \"Make sure camera names must be unique\" task to\nour task list though.\n\n\n\n> \n>>> +\n>>> +\t\t\tcameras_[id] = new Camera(cameraName);\n>>> +\n>>> +\t\t\tLOG(Debug) << \"Registered Camera[\" << numCameras\n>>> +\t\t\t\t   << \"] \\\"\" << cameraName << \"\\\"\"\n>>> +\t\t\t\t   << \" connected to CSI-2 receiver \" << id;\n>>> +\n>>> +\t\t\tnumCameras++;\n>>> +\t\t\tbreak;\n>>> +\t\t}\n>>> +\t}\n>>> +\n>>> +\treturn numCameras;\n>>> +}\n>>> +\n>>> +REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);\n>>> +\n>>> +} /* namespace libcamera */\n>>> diff --git a/src/libcamera/pipeline/ipu3/meson.build b/src/libcamera/pipeline/ipu3/meson.build\n>>> new file mode 100644\n>>> index 0000000..0ab766a\n>>> --- /dev/null\n>>> +++ b/src/libcamera/pipeline/ipu3/meson.build\n>>> @@ -0,0 +1,3 @@\n>>> +libcamera_sources += files([\n>>> +    'ipu3.cpp',\n>>> +])\n>>> diff --git a/src/libcamera/pipeline/meson.build b/src/libcamera/pipeline/meson.build\n>>> index 615ecd2..811c075 100644\n>>> --- a/src/libcamera/pipeline/meson.build\n>>> +++ b/src/libcamera/pipeline/meson.build\n>>> @@ -1,3 +1,5 @@\n>>>  libcamera_sources += files([\n>>>      'vimc.cpp',\n>>>  ])\n>>> +\n>>> +subdir('ipu3')\n>>>\n>>\n>> --\n>> Regards\n>> --\n>> Kieran","headers":{"Return-Path":"<kieran.bingham@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 DE7BF60C96\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 20:35:23 +0100 (CET)","from [192.168.0.21]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DBB174F8;\n\tTue, 15 Jan 2019 20:35:22 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547580923;\n\tbh=t1bYYMeAJNpfbDazVDDC5zn9KxRBQ5zctMY9Wsiah2w=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=mdcmFZyg6Q3sH6OEgrZYiqa7BYMKh4SAboJsKRHPp6Ct+PCjtZTPaMgYWKDW+VFEa\n\tFfLtm0jHycn6885iI91qTszqaU/RzKmYVR7CesXpT0Ih74J1pZOyQu2AVq5kdGQnwk\n\tbYkWa8df4ag2grAvJoWImympYGT7XXUTVB1xdS3w=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","References":"<20190115140749.8297-1-jacopo@jmondi.org>\n\t<20190115140749.8297-5-jacopo@jmondi.org>\n\t<beb74b0c-3446-5b73-101c-95d11428e190@ideasonboard.com>\n\t<20190115173755.tpj2tlpxuotww2wv@uno.localdomain>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07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sFCQeA/gIACgkQoR5GchCkYf1yYRAAq+Yo\n\tnbf9DGdK1kTAm2RTFg+w9oOp2Xjqfhds2PAhFFvrHQg1XfQR/UF/SjeUmaOmLSczM0s6XMeO\n\tVcE77UFtJ/+hLo4PRFKm5X1Pcar6g5m4xGqa+Xfzi9tRkwC29KMCoQOag1BhHChgqYaUH3yo\n\tUzaPwT/fY75iVI+yD0ih/e6j8qYvP8pvGwMQfrmN9YB0zB39YzCSdaUaNrWGD3iCBxg6lwSO\n\tLKeRhxxfiXCIYEf3vwOsP3YMx2JkD5doseXmWBGW1U0T/oJF+DVfKB6mv5UfsTzpVhJRgee7\n\t4jkjqFq4qsUGxcvF2xtRkfHFpZDbRgRlVmiWkqDkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<e58c783c-fa37-0215-5c35-423011973572@ideasonboard.com>","Date":"Tue, 15 Jan 2019 19:35:19 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.2.1","MIME-Version":"1.0","In-Reply-To":"<20190115173755.tpj2tlpxuotww2wv@uno.localdomain>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: pipeline: Add Intel\n\tIPU3 pipeline","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":"Tue, 15 Jan 2019 19:35:24 -0000"}}]