Show a patch.

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

{
    "id": 753,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/753/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/753/",
    "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": "<20190320163055.22056-8-jacopo@jmondi.org>",
    "date": "2019-03-20T16:30:31",
    "name": "[libcamera-devel,v4,07/31] libcamera: ipu3: Propagate image format",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "fdd90f2078c16ad6db120274519da41cef363a53",
    "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/753/mbox/",
    "series": [
        {
            "id": 214,
            "url": "https://patchwork.libcamera.org/api/1.1/series/214/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=214",
            "date": "2019-03-20T16:30:24",
            "name": "libcamera: ipu3: Add ImgU support + multiple streams",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/214/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/753/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/753/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E88C611A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Mar 2019 17:30:32 +0100 (CET)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id 0B992200008;\n\tWed, 20 Mar 2019 16:30:31 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 20 Mar 2019 17:30:31 +0100",
        "Message-Id": "<20190320163055.22056-8-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190320163055.22056-1-jacopo@jmondi.org>",
        "References": "<20190320163055.22056-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 07/31] libcamera: ipu3: Propagate image\n\tformat",
        "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, 20 Mar 2019 16:30:32 -0000"
    },
    "content": "Apply the requested image format to the sensor device, and apply the\nadjusted one to the CIO2 device, 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 | 220 +++++++++++++++++++++++----\n 1 file changed, 189 insertions(+), 31 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 26fc56a76eb1..2975c218f6c9 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -16,6 +16,7 @@\n #include <libcamera/stream.h>\n \n #include \"device_enumerator.h\"\n+#include \"geometry.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n@@ -30,6 +31,11 @@ LOG_DEFINE_CATEGORY(IPU3)\n class ImgUDevice\n {\n public:\n+\tstatic constexpr unsigned int PAD_INPUT = 0;\n+\tstatic constexpr unsigned int PAD_OUTPUT = 2;\n+\tstatic constexpr unsigned int PAD_VF = 3;\n+\tstatic constexpr unsigned int PAD_STAT = 4;\n+\n \tImgUDevice()\n \t\t: imgu(nullptr), input(nullptr), output(nullptr),\n \t\t  viewfinder(nullptr), stat(nullptr)\n@@ -135,6 +141,13 @@ private:\n \n \tint initImgU(ImgUDevice *imgu);\n \n+\tint setImguFormat(ImgUDevice *imguDevice,\n+\t\t\t  const StreamConfiguration &config,\n+\t\t\t  Rectangle *rect);\n+\tint setCIO2Format(CIO2Device *cio2Device,\n+\t\t\t  const StreamConfiguration &config,\n+\t\t\t  V4L2SubdeviceFormat *format);\n+\n \tvoid registerCameras();\n \n \tImgUDevice imgus_[IPU3_IMGU_COUNT];\n@@ -202,60 +215,86 @@ 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+\tconst StreamConfiguration &cfg = config[&data->stream_];\n+\tV4L2Device *viewfinder = data->imgu->viewfinder;\n+\tV4L2Device *output = data->imgu->output;\n+\tV4L2Device *input = data->imgu->input;\n \tV4L2Device *cio2 = data->cio2.output;\n-\tV4L2SubdeviceFormat subdevFormat = {};\n-\tV4L2DeviceFormat devFormat = {};\n \tint ret;\n \n+\tLOG(IPU3, Info)\n+\t\t<< \"Requested image format: \" << cfg.width << \"x\"\n+\t\t<< cfg.height << \" - \" << std::hex << std::setw(8)\n+\t\t<< cfg.pixelFormat << \" on camera:'\" << 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.\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) << \"Stream format not support: bad alignement\";\n+\t\treturn -EINVAL;\n+\t}\n \n-\tret = sensor->getFormat(0, &subdevFormat);\n+\t/*\n+\t * Pass the requested output image size to the sensor and get back the\n+\t * adjusted one to be propagated to the CIO2 device and to the ImgU\n+\t * input.\n+\t */\n+\tV4L2SubdeviceFormat sensorFormat = {};\n+\tret = setCIO2Format(&data->cio2, cfg, &sensorFormat);\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+\t/* Apply the CIO2 image format to the CIO2 output and ImgU input. */\n+\tV4L2DeviceFormat cio2Format = {};\n+\tcio2Format.width = sensorFormat.width;\n+\tcio2Format.height = sensorFormat.height;\n+\tcio2Format.fourcc = mediaBusToCIO2Format(sensorFormat.mbus_code);\n+\tcio2Format.planesCount = 1;\n+\tret = cio2->setFormat(&cio2Format);\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-\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\treturn -EINVAL;\n-\t}\n+\tLOG(IPU3, Debug)\n+\t\t<< \"CIO2 output format = \" << cio2Format.toString();\n \n-\tret = csi2->setFormat(0, &subdevFormat);\n+\tret = input->setFormat(&cio2Format);\n \tif (ret)\n \t\treturn ret;\n \n-\tret = cio2->getFormat(&devFormat);\n+\t/* Apply pad formats and crop/compose rectangle to the ImgU. */\n+\tRectangle rect = {\n+\t\t.x = 0,\n+\t\t.y = 0,\n+\t\t.w = cio2Format.width,\n+\t\t.h = cio2Format.height,\n+\t};\n+\tret = setImguFormat(data->imgu, cfg, &rect);\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 and viewfinder devices. */\n+\tV4L2DeviceFormat outputFormat = {};\n+\toutputFormat.width = cfg.width;\n+\toutputFormat.height = cfg.height;\n+\toutputFormat.fourcc = V4L2_PIX_FMT_NV12;\n+\toutputFormat.planesCount = 2;\n \n-\tret = cio2->setFormat(&devFormat);\n+\tret = output->setFormat(&outputFormat);\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+\tLOG(IPU3, Debug)\n+\t\t<< \"ImgU output format = \" << outputFormat.toString();\n+\n+\tret = viewfinder->setFormat(&outputFormat);\n+\tif (ret)\n+\t\treturn ret;\n \n \treturn 0;\n }\n@@ -666,6 +705,125 @@ void PipelineHandlerIPU3::deleteCIO2(CIO2Device *cio2)\n \tdelete cio2->sensor;\n }\n \n+int PipelineHandlerIPU3::setImguFormat(ImgUDevice *imguDevice,\n+\t\t\t\t       const StreamConfiguration &config,\n+\t\t\t\t       Rectangle *rect)\n+{\n+\tV4L2Subdevice *imgu = imguDevice->imgu;\n+\tint ret;\n+\n+\t/*\n+\t * Configure the 'imgu' subdevice with the requested sizes.\n+\t *\n+\t * FIXME: the IPU3 driver implementation shall be changed to use the\n+\t * actual input sizes as 'imgu input' subdevice sizes, and use the\n+\t * desired output sizes to configure the crop/compose rectangles.  The\n+\t * current implementation uses output sizes as 'imgu input' sizes, and\n+\t * uses the input dimension to configure the crop/compose rectangles,\n+\t * which contradicts the V4L2 specifications.\n+\t */\n+\tret = imgu->setCrop(ImgUDevice::PAD_INPUT, rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = imgu->setCompose(ImgUDevice::PAD_INPUT, rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug)\n+\t\t<< \"ImgU input feeder and BDS rectangle = (0,0)/\"\n+\t\t<< rect->w << \"x\" << rect->h;\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(ImgUDevice::PAD_INPUT, &imguFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = imgu->setFormat(ImgUDevice::PAD_OUTPUT, &imguFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug)\n+\t\t<< \"ImgU GDC format = \" << imguFormat.toString();\n+\n+\tret = imgu->setFormat(ImgUDevice::PAD_VF, &imguFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = imgu->setFormat(ImgUDevice::PAD_STAT, &imguFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treturn 0;\n+}\n+\n+int PipelineHandlerIPU3::setCIO2Format(CIO2Device *cio2Device,\n+\t\t\t\t       const StreamConfiguration &config,\n+\t\t\t\t       V4L2SubdeviceFormat *format)\n+{\n+\tunsigned int imageSize = config.width * config.height;\n+\tV4L2Subdevice *sensor = cio2Device->sensor;\n+\tV4L2Subdevice *csi2 = cio2Device->csi2;\n+\tunsigned int best = ~0;\n+\tbool found = false;\n+\tint ret;\n+\n+\tconst FormatEnum formats = sensor->formats(0);\n+\tfor (auto it = formats.begin(); it != formats.end(); ++it) {\n+\t\t/* Only consider formats consumable by the CIO2 unit. */\n+\t\tint cio2Code = mediaBusToCIO2Format(it->first);\n+\t\tif (cio2Code == -EINVAL)\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\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+\t\t\tfound = true;\n+\n+\t\t\tformat->width = size.maxWidth;\n+\t\t\tformat->height = size.maxHeight;\n+\t\t\tformat->mbus_code = it->first;\n+\t\t}\n+\t}\n+\tif (!found) {\n+\t\tLOG(IPU3, Error)\n+\t\t\t<< \"Unable to find image format suitable to produce: \"\n+\t\t\t<< config.width << \"x\" << config.height\n+\t\t\t<< \"- 0x\" << std::hex << std::setfill('0')\n+\t\t\t<< std::setw(8) << config.pixelFormat;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Apply the selected format to the sensor and the CSI-2 receiver. */\n+\tret = sensor->setFormat(0, format);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = csi2->setFormat(0, format);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"CIO2 Image format: \" << format->toString();\n+\n+\treturn 0;\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",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "07/31"
    ]
}