Show a patch.

GET /api/patches/892/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 892,
    "url": "https://patchwork.libcamera.org/api/patches/892/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/892/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20190403080148.11479-7-jacopo@jmondi.org>",
    "date": "2019-04-03T08:01:41",
    "name": "[libcamera-devel,v8,06/13] libcamera: ipu3: Apply image format to the pipeline",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "3ab5c8a31d5bd652bcbdb76215b623d192b9e53b",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/892/mbox/",
    "series": [
        {
            "id": 235,
            "url": "https://patchwork.libcamera.org/api/series/235/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=235",
            "date": "2019-04-03T08:01:35",
            "name": "libcamera: ipu3: Add ImgU support",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/235/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/892/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/892/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 015F5611A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 10:01:15 +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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id E2A0C60007;\n\tWed,  3 Apr 2019 08:01:13 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  3 Apr 2019 10:01:41 +0200",
        "Message-Id": "<20190403080148.11479-7-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190403080148.11479-1-jacopo@jmondi.org>",
        "References": "<20190403080148.11479-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v8 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": "Wed, 03 Apr 2019 08:01:15 -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\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 298 ++++++++++++++++++++++-----\n 1 file changed, 249 insertions(+), 49 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 9274d35c8be8..a4e6f28d1da9 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@@ -34,22 +35,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(ImgUOutput *output,\n+\t\t\t    const StreamConfiguration &config);\n \n \tunsigned int index_;\n \tstd::string name_;\n@@ -57,9 +71,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@@ -79,6 +93,8 @@ public:\n \t}\n \n \tint init(const MediaDevice *media, unsigned int index);\n+\tint configure(const StreamConfiguration &config,\n+\t\t      V4L2DeviceFormat *outputFormat);\n \n \tstatic int mediaBusToFormat(unsigned int code);\n \n@@ -190,60 +206,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,21 +537,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(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@@ -631,6 +759,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] outputFormat 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 *outputFormat)\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 (CIO2Device::mediaBusToFormat(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+\toutputFormat->width = sensorFormat.width;\n+\toutputFormat->height = sensorFormat.height;\n+\toutputFormat->fourcc = CIO2Device::mediaBusToFormat(sensorFormat.mbus_code);\n+\toutputFormat->planesCount = 1;\n+\n+\tret = output_->setFormat(outputFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"CIO2 output format \" << outputFormat->toString();\n+\n+\treturn 0;\n+}\n+\n int CIO2Device::mediaBusToFormat(unsigned int code)\n {\n \tswitch (code) {\n",
    "prefixes": [
        "libcamera-devel",
        "v8",
        "06/13"
    ]
}