Patch Detail
Show a patch.
GET /api/1.1/patches/862/?format=api
{ "id": 862, "url": "https://patchwork.libcamera.org/api/1.1/patches/862/?format=api", "web_url": "https://patchwork.libcamera.org/patch/862/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190402171309.6447-7-jacopo@jmondi.org>", "date": "2019-04-02T17:13:02", "name": "[libcamera-devel,v7,06/13] libcamera: ipu3: Apply image format to the pipeline", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "70223aef8ed2686ca4c24a62b979acaeeec27a22", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/862/mbox/", "series": [ { "id": 231, "url": "https://patchwork.libcamera.org/api/1.1/series/231/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=231", "date": "2019-04-02T17:12:56", "name": "libcamera: ipu3: Add ImgU support", "version": 7, "mbox": "https://patchwork.libcamera.org/series/231/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/862/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/862/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B916A610C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 2 Apr 2019 19:12:34 +0200 (CEST)", "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 1599DFF80C;\n\tTue, 2 Apr 2019 17:12:33 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 2 Apr 2019 19:13:02 +0200", "Message-Id": "<20190402171309.6447-7-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190402171309.6447-1-jacopo@jmondi.org>", "References": "<20190402171309.6447-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v7 06/13] libcamera: ipu3: Apply image\n\tformat to the 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, 02 Apr 2019 17:12:35 -0000" }, "content": "Apply the requested stream configuration to the CIO2 device, and\npropagate formats through the the ImgU subdevice and its input and\noutput video devices.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 304 ++++++++++++++++++++++-----\n 1 file changed, 252 insertions(+), 52 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 53e6b3b461a1..57e4bb89eaa7 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -5,6 +5,7 @@\n * ipu3.cpp - Pipeline handler for Intel IPU3\n */\n \n+#include <iomanip>\n #include <memory>\n #include <vector>\n \n@@ -50,22 +51,35 @@ public:\n \tstatic constexpr unsigned int PAD_VF = 3;\n \tstatic constexpr unsigned int PAD_STAT = 4;\n \n+\t/* ImgU output descriptor: group data specific to an ImgU output. */\n+\tstruct ImgUOutput {\n+\t\tV4L2Device *dev;\n+\t\tunsigned int pad;\n+\t\tstd::string name;\n+\t};\n+\n \tImgUDevice()\n-\t\t: imgu_(nullptr), input_(nullptr), output_(nullptr),\n-\t\t viewfinder_(nullptr), stat_(nullptr)\n+\t\t: imgu_(nullptr), input_(nullptr)\n \t{\n+\t\toutput_.dev = nullptr;\n+\t\tviewfinder_.dev = nullptr;\n+\t\tstat_.dev = nullptr;\n \t}\n \n \t~ImgUDevice()\n \t{\n \t\tdelete imgu_;\n \t\tdelete input_;\n-\t\tdelete output_;\n-\t\tdelete viewfinder_;\n-\t\tdelete stat_;\n+\t\tdelete output_.dev;\n+\t\tdelete viewfinder_.dev;\n+\t\tdelete stat_.dev;\n \t}\n \n \tint init(MediaDevice *media, unsigned int index);\n+\tint configureInput(const StreamConfiguration &config,\n+\t\t\t V4L2DeviceFormat *inputFormat);\n+\tint configureOutput(const ImgUOutput *output,\n+\t\t\t const StreamConfiguration &config);\n \n \tunsigned int index_;\n \tstd::string name_;\n@@ -73,9 +87,9 @@ public:\n \n \tV4L2Subdevice *imgu_;\n \tV4L2Device *input_;\n-\tV4L2Device *output_;\n-\tV4L2Device *viewfinder_;\n-\tV4L2Device *stat_;\n+\tImgUOutput output_;\n+\tImgUOutput viewfinder_;\n+\tImgUOutput stat_;\n \t/* \\todo Add param video device for 3A tuning */\n };\n \n@@ -95,6 +109,8 @@ public:\n \t}\n \n \tint init(const MediaDevice *media, unsigned int index);\n+\tint configure(const StreamConfiguration &config,\n+\t\t V4L2DeviceFormat *format);\n \n \tV4L2Device *output_;\n \tV4L2Subdevice *csi2_;\n@@ -204,60 +220,62 @@ int PipelineHandlerIPU3::configureStreams(Camera *camera,\n \t\t\t\t\t std::map<Stream *, StreamConfiguration> &config)\n {\n \tIPU3CameraData *data = cameraData(camera);\n-\tStreamConfiguration *cfg = &config[&data->stream_];\n-\tV4L2Subdevice *sensor = data->cio2_.sensor_;\n-\tV4L2Subdevice *csi2 = data->cio2_.csi2_;\n-\tV4L2Device *cio2 = data->cio2_.output_;\n-\tV4L2SubdeviceFormat subdevFormat = {};\n-\tV4L2DeviceFormat devFormat = {};\n+\tconst StreamConfiguration &cfg = config[&data->stream_];\n+\tCIO2Device *cio2 = &data->cio2_;\n+\tImgUDevice *imgu = data->imgu_;\n \tint ret;\n \n+\tLOG(IPU3, Info)\n+\t\t<< \"Requested image format \" << cfg.width << \"x\"\n+\t\t<< cfg.height << \"-0x\" << std::hex << std::setfill('0')\n+\t\t<< std::setw(8) << cfg.pixelFormat << \" on camera '\"\n+\t\t<< camera->name() << \"'\";\n+\n \t/*\n-\t * FIXME: as of now, the format gets applied to the sensor and is\n-\t * propagated along the pipeline. It should instead be applied on the\n-\t * capture device and the sensor format calculated accordingly.\n+\t * Verify that the requested size respects the IPU3 alignement\n+\t * requirements (the image width shall be a multiple of 8 pixels and\n+\t * its height a multiple of 4 pixels) and the camera maximum sizes.\n+\t *\n+\t * \\todo: consider the BDS scaling factor requirements:\n+\t * \"the downscaling factor must be an integer value multiple of 1/32\"\n \t */\n+\tif (cfg.width % 8 || cfg.height % 4) {\n+\t\tLOG(IPU3, Error) << \"Invalid stream size: bad alignment\";\n+\t\treturn -EINVAL;\n+\t}\n \n-\tret = sensor->getFormat(0, &subdevFormat);\n-\tif (ret)\n-\t\treturn ret;\n-\n-\tsubdevFormat.width = cfg->width;\n-\tsubdevFormat.height = cfg->height;\n-\tret = sensor->setFormat(0, &subdevFormat);\n-\tif (ret)\n-\t\treturn ret;\n-\n-\t/* Return error if the requested format cannot be applied to sensor. */\n-\tif (subdevFormat.width != cfg->width ||\n-\t subdevFormat.height != cfg->height) {\n+\tif (cfg.width > cio2->maxSize_.width ||\n+\t cfg.height > cio2->maxSize_.height) {\n \t\tLOG(IPU3, Error)\n-\t\t\t<< \"Failed to apply image format \"\n-\t\t\t<< subdevFormat.width << \"x\" << subdevFormat.height\n-\t\t\t<< \" - got: \" << cfg->width << \"x\" << cfg->height;\n+\t\t\t<< \"Invalid stream size: larger than sensor resolution\";\n \t\treturn -EINVAL;\n \t}\n \n-\tret = csi2->setFormat(0, &subdevFormat);\n+\t/*\n+\t * Pass the requested stream size to the CIO2 unit and get back the\n+\t * adjusted format to be propagated to the ImgU output devices.\n+\t */\n+\tV4L2DeviceFormat cio2Format = {};\n+\tret = cio2->configure(cfg, &cio2Format);\n \tif (ret)\n \t\treturn ret;\n \n-\tret = cio2->getFormat(&devFormat);\n+\tret = imgu->configureInput(cfg, &cio2Format);\n \tif (ret)\n \t\treturn ret;\n \n-\tdevFormat.width = subdevFormat.width;\n-\tdevFormat.height = subdevFormat.height;\n-\tdevFormat.fourcc = cfg->pixelFormat;\n+\t/* Apply the format to the ImgU output, viewfinder and stat. */\n+\tret = imgu->configureOutput(&imgu->output_, cfg);\n+\tif (ret)\n+\t\treturn ret;\n \n-\tret = cio2->setFormat(&devFormat);\n+\tret = imgu->configureOutput(&imgu->viewfinder_, cfg);\n \tif (ret)\n \t\treturn ret;\n \n-\tLOG(IPU3, Info) << cio2->driverName() << \": \"\n-\t\t\t<< devFormat.width << \"x\" << devFormat.height\n-\t\t\t<< \"- 0x\" << std::hex << devFormat.fourcc << \" planes: \"\n-\t\t\t<< devFormat.planes;\n+\tret = imgu->configureOutput(&imgu->stat_, cfg);\n+\tif (ret)\n+\t\treturn ret;\n \n \treturn 0;\n }\n@@ -519,9 +537,9 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \tmedia_ = media;\n \n \t/*\n-\t * The media entities presence has been verified by the match()\n-\t * function, no need to check for newly created video devices\n-\t * and subdevice validity here.\n+\t * The media entities presence in the media device has been verified\n+\t * by the match() function: no need to check for newly created\n+\t * video devices and subdevice validity here.\n \t */\n \timgu_ = V4L2Subdevice::fromEntityName(media, name_);\n \tret = imgu_->open();\n@@ -533,21 +551,131 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \tif (ret)\n \t\treturn ret;\n \n-\toutput_ = V4L2Device::fromEntityName(media, name_ + \" output\");\n-\tret = output_->open();\n+\toutput_.dev = V4L2Device::fromEntityName(media, name_ + \" output\");\n+\tret = output_.dev->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\toutput_.pad = PAD_OUTPUT;\n+\toutput_.name = \"output\";\n+\n+\tviewfinder_.dev = V4L2Device::fromEntityName(media,\n+\t\t\t\t\t\t name_ + \" viewfinder\");\n+\tret = viewfinder_.dev->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tviewfinder_.pad = PAD_VF;\n+\tviewfinder_.name = \"viewfinder\";\n+\n+\tstat_.dev = V4L2Device::fromEntityName(media, name_ + \" 3a stat\");\n+\tret = stat_.dev->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tstat_.pad = PAD_STAT;\n+\tstat_.name = \"stat\";\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Configure the ImgU unit input\n+ * \\param[in] config The requested stream configuration\n+ * \\param[in] inputFormat The format to be applied to ImgU input\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int ImgUDevice::configureInput(const StreamConfiguration &config,\n+\t\t\t V4L2DeviceFormat *inputFormat)\n+{\n+\t/* Configure the ImgU input video device with the requested sizes. */\n+\tint ret = input_->setFormat(inputFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"ImgU input format = \" << inputFormat->toString();\n+\n+\t/*\n+\t * \\todo The IPU3 driver implementation shall be changed to use the\n+\t * input sizes as 'ImgU Input' subdevice sizes, and use the desired\n+\t * GDC output sizes to configure the crop/compose rectangles.\n+\t *\n+\t * The current IPU3 driver implementation uses GDC sizes as the\n+\t * 'ImgU Input' subdevice sizes, and the input video device sizes\n+\t * to configure the crop/compose rectangles, contradicting the\n+\t * V4L2 specification.\n+\t */\n+\tRectangle rect = {\n+\t\t.x = 0,\n+\t\t.y = 0,\n+\t\t.w = inputFormat->width,\n+\t\t.h = inputFormat->height,\n+\t};\n+\tret = imgu_->setCrop(PAD_INPUT, &rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = imgu_->setCompose(PAD_INPUT, &rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"ImgU input feeder and BDS rectangle = \"\n+\t\t\t << rect.toString();\n+\n+\tV4L2SubdeviceFormat imguFormat = {};\n+\timguFormat.width = config.width;\n+\timguFormat.height = config.height;\n+\timguFormat.mbus_code = MEDIA_BUS_FMT_FIXED;\n+\n+\tret = imgu_->setFormat(PAD_INPUT, &imguFormat);\n \tif (ret)\n \t\treturn ret;\n \n-\tviewfinder_ = V4L2Device::fromEntityName(media, name_ + \" viewfinder\");\n-\tret = viewfinder_->open();\n+\tLOG(IPU3, Debug) << \"ImgU GDC format = \" << imguFormat.toString();\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Configure the ImgU unit \\a id video output\n+ * \\param[in] output The ImgU output device to configure\n+ * \\param[in] config The requested configuration\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int ImgUDevice::configureOutput(const ImgUOutput *output,\n+\t\t\t\tconst StreamConfiguration &config)\n+{\n+\tV4L2Device *dev = output->dev;\n+\tunsigned int pad = output->pad;\n+\n+\tV4L2SubdeviceFormat imguFormat = {};\n+\timguFormat.width = config.width;\n+\timguFormat.height = config.height;\n+\timguFormat.mbus_code = MEDIA_BUS_FMT_FIXED;\n+\n+\tint ret = imgu_->setFormat(pad, &imguFormat);\n \tif (ret)\n \t\treturn ret;\n \n-\tstat_ = V4L2Device::fromEntityName(media, name_ + \" 3a stat\");\n-\tret = stat_->open();\n+\t/* No need to apply format to the stat node. */\n+\tif (output == &stat_)\n+\t\treturn 0;\n+\n+\tV4L2DeviceFormat outputFormat = {};\n+\toutputFormat.width = config.width;\n+\toutputFormat.height = config.height;\n+\toutputFormat.fourcc = V4L2_PIX_FMT_NV12;\n+\toutputFormat.planesCount = 2;\n+\n+\tret = dev->setFormat(&outputFormat);\n \tif (ret)\n \t\treturn ret;\n \n+\tLOG(IPU3, Debug) << \"ImgU \" << output->name << \" format = \"\n+\t\t\t << outputFormat.toString();\n+\n \treturn 0;\n }\n \n@@ -645,6 +773,78 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Configure the CIO2 unit\n+ * \\param[in] config The requested configuration\n+ * \\param[out] cio2Format The CIO2 unit output image format\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int CIO2Device::configure(const StreamConfiguration &config,\n+\t\t\t V4L2DeviceFormat *cio2Format)\n+{\n+\tunsigned int imageSize = config.width * config.height;\n+\tV4L2SubdeviceFormat sensorFormat = {};\n+\tunsigned int best = ~0;\n+\tint ret;\n+\n+\tfor (auto it : sensor_->formats(0)) {\n+\t\t/* Only consider formats consumable by the CIO2 unit. */\n+\t\tif (mediaBusToCIO2Format(it.first) < 0)\n+\t\t\tcontinue;\n+\n+\t\tfor (const SizeRange &size : it.second) {\n+\t\t\t/*\n+\t\t\t * Only select formats bigger than the requested sizes\n+\t\t\t * as the IPU3 cannot up-scale.\n+\t\t\t *\n+\t\t\t * \\todo: Unconditionally scale on the sensor as much\n+\t\t\t * as possible. This will need to be revisited when\n+\t\t\t * implementing the scaling policy.\n+\t\t\t */\n+\t\t\tif (size.maxWidth < config.width ||\n+\t\t\t size.maxHeight < config.height)\n+\t\t\t\tcontinue;\n+\n+\t\t\tunsigned int diff = size.maxWidth * size.maxHeight\n+\t\t\t\t\t - imageSize;\n+\t\t\tif (diff >= best)\n+\t\t\t\tcontinue;\n+\n+\t\t\tbest = diff;\n+\n+\t\t\tsensorFormat.width = size.maxWidth;\n+\t\t\tsensorFormat.height = size.maxHeight;\n+\t\t\tsensorFormat.mbus_code = it.first;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Apply the selected format to the sensor, the CSI-2 receiver and\n+\t * the CIO2 output device.\n+\t */\n+\tret = sensor_->setFormat(0, &sensorFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = csi2_->setFormat(0, &sensorFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tcio2Format->width = sensorFormat.width;\n+\tcio2Format->height = sensorFormat.height;\n+\tcio2Format->fourcc = mediaBusToCIO2Format(sensorFormat.mbus_code);\n+\tcio2Format->planesCount = 1;\n+\n+\tret = output_->setFormat(cio2Format);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"CIO2 output format \" << cio2Format->toString();\n+\n+\treturn 0;\n+}\n+\n REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3);\n \n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v7", "06/13" ] }