Patch Detail
Show a patch.
GET /api/1.1/patches/721/?format=api
{ "id": 721, "url": "https://patchwork.libcamera.org/api/1.1/patches/721/?format=api", "web_url": "https://patchwork.libcamera.org/patch/721/", "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": "<20190312121242.2253-7-jacopo@jmondi.org>", "date": "2019-03-12T12:12:34", "name": "[libcamera-devel,v2,06/14] libcamera: ipu3: Propagate image format", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "9ef26a136de7bb08090ce1edb1356d2c8c830b92", "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/721/mbox/", "series": [ { "id": 205, "url": "https://patchwork.libcamera.org/api/1.1/series/205/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=205", "date": "2019-03-12T12:12:28", "name": "libcamera: ipu3: ImgU support", "version": 2, "mbox": "https://patchwork.libcamera.org/series/205/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/721/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/721/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 42791611A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Mar 2019 13:12:23 +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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id BE6CE1C0005;\n\tTue, 12 Mar 2019 12:12:22 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 12 Mar 2019 13:12:34 +0100", "Message-Id": "<20190312121242.2253-7-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20190312121242.2253-1-jacopo@jmondi.org>", "References": "<20190312121242.2253-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 06/14] 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": "Tue, 12 Mar 2019 12:12:23 -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 009ee341f18c..3502c39f5e31 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@@ -29,6 +30,11 @@ LOG_DEFINE_CATEGORY(IPU3)\n \n class ImgUDevice {\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@@ -134,6 +140,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@@ -206,60 +219,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@@ -682,6 +721,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 SubdevFormatEnum 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", "v2", "06/14" ] }