{"id":718,"url":"https://patchwork.libcamera.org/api/1.1/patches/718/?format=json","web_url":"https://patchwork.libcamera.org/patch/718/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","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-4-jacopo@jmondi.org>","date":"2019-03-12T12:12:31","name":"[libcamera-devel,v2,03/14] libcamera: ipu3: Get default image sizes from sensor","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6ff20af550e1d21b7da17725916d8924446c7f0a","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/718/mbox/","series":[{"id":205,"url":"https://patchwork.libcamera.org/api/1.1/series/205/?format=json","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/718/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/718/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 4E44E610D5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Mar 2019 13:12:21 +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 D67011C000A;\n\tTue, 12 Mar 2019 12:12:20 +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:31 +0100","Message-Id":"<20190312121242.2253-4-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 03/14] libcamera: ipu3: Get default\n\timage sizes from sensor","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:22 -0000"},"content":"Inspect all image sizes provided by the sensor and select the\nbiggest of them, associated with an image format code supported by the\nCIO2 unit.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 94 ++++++++++++++++++++++++----\n 1 file changed, 82 insertions(+), 12 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 55489c31df2d..0f18e4692e77 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -6,8 +6,11 @@\n  */\n \n #include <memory>\n+#include <iomanip>\n #include <vector>\n \n+#include <linux/media-bus-format.h>\n+\n #include <libcamera/camera.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n@@ -72,12 +75,16 @@ private:\n \t\tStream stream_;\n \t};\n \n+\tstatic constexpr unsigned int IPU3_BUFFER_COUNT = 4;\n+\n \tIPU3CameraData *cameraData(const Camera *camera)\n \t{\n \t\treturn static_cast<IPU3CameraData *>(\n \t\t\tPipelineHandler::cameraData(camera));\n \t}\n \n+\tint mediaBusToCIO2Format(unsigned int code);\n+\n \tvoid registerCameras();\n \n \tstd::shared_ptr<MediaDevice> cio2_;\n@@ -102,26 +109,45 @@ std::map<Stream *, StreamConfiguration>\n PipelineHandlerIPU3::streamConfiguration(Camera *camera,\n \t\t\t\t\t std::set<Stream *> &streams)\n {\n-\tIPU3CameraData *data = cameraData(camera);\n \tstd::map<Stream *, StreamConfiguration> configs;\n-\tV4L2SubdeviceFormat format = {};\n+\tIPU3CameraData *data = cameraData(camera);\n+\tV4L2Subdevice *sensor = data->sensor_;\n+\tStreamConfiguration *config = &configs[&data->stream_];\n \n \t/*\n-\t * FIXME: As of now, return the image format reported by the sensor.\n-\t * In future good defaults should be provided for each stream.\n+\t * Make sure the sensor produces a raw format compatible with the\n+\t * CIO2 and use the largest image size the sensor provides.\n \t */\n-\tif (data->sensor_->getFormat(0, &format)) {\n-\t\tLOG(IPU3, Error) << \"Failed to create stream configurations\";\n+\tconst SubdevFormatEnum formats = sensor->formats(0);\n+\tfor (auto it = formats.begin(); it != formats.end(); ++it) {\n+\t\tint cio2Code = mediaBusToCIO2Format(it->first);\n+\t\tif (cio2Code == -EINVAL)\n+\t\t\tcontinue;\n+\n+\t\tfor (const SizeRange &range : it->second) {\n+\t\t\tif (range.maxWidth <= config->width ||\n+\t\t\t    range.maxHeight <= config->height)\n+\t\t\t\tcontinue;\n+\n+\t\t\tconfig->width = range.maxWidth;\n+\t\t\tconfig->height = range.maxHeight;\n+\t\t\tconfig->pixelFormat = cio2Code;\n+\t\t}\n+\t}\n+\n+\t/* If not suitable format has been found, return an empty config. */\n+\tif (!config->pixelFormat) {\n+\t\tLOG(IPU3, Error) << \"Sensor image format not supported\";\n+\n \t\treturn configs;\n \t}\n \n-\tStreamConfiguration config = {};\n-\tconfig.width = format.width;\n-\tconfig.height = format.height;\n-\tconfig.pixelFormat = V4L2_PIX_FMT_IPU3_SGRBG10;\n-\tconfig.bufferCount = 4;\n+\tconfig->bufferCount = IPU3_BUFFER_COUNT;\n \n-\tconfigs[&data->stream_] = config;\n+\tLOG(IPU3, Debug)\n+\t\t<< \"Stream format set to = (\" << config->width << \"x\"\n+\t\t<< config->height << \") - 0x\" << std::hex << std::setfill('0')\n+\t\t<< std::setw(8) << config->pixelFormat;\n \n \treturn configs;\n }\n@@ -327,6 +353,50 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n \treturn true;\n }\n \n+int PipelineHandlerIPU3::mediaBusToCIO2Format(unsigned int code)\n+{\n+\tswitch(code) {\n+\tcase MEDIA_BUS_FMT_SBGGR8_1X8:\n+\tcase MEDIA_BUS_FMT_SBGGR10_1X10:\n+\tcase MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE:\n+\tcase MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE:\n+\tcase MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE:\n+\tcase MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE:\n+\tcase MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8:\n+\tcase MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8:\n+\tcase MEDIA_BUS_FMT_SBGGR12_1X12:\n+\tcase MEDIA_BUS_FMT_SBGGR14_1X14:\n+\tcase MEDIA_BUS_FMT_SBGGR16_1X16:\n+\t\treturn V4L2_PIX_FMT_IPU3_SBGGR10;\n+\tcase MEDIA_BUS_FMT_SGBRG8_1X8:\n+\tcase MEDIA_BUS_FMT_SGBRG10_1X10:\n+\tcase MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8:\n+\tcase MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8:\n+\tcase MEDIA_BUS_FMT_SGBRG12_1X12:\n+\tcase MEDIA_BUS_FMT_SGBRG14_1X14:\n+\tcase MEDIA_BUS_FMT_SGBRG16_1X16:\n+\t\treturn V4L2_PIX_FMT_IPU3_SGBRG10;\n+\tcase MEDIA_BUS_FMT_SGRBG8_1X8:\n+\tcase MEDIA_BUS_FMT_SGRBG10_1X10:\n+\tcase MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8:\n+\tcase MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8:\n+\tcase MEDIA_BUS_FMT_SGRBG12_1X12:\n+\tcase MEDIA_BUS_FMT_SGRBG14_1X14:\n+\tcase MEDIA_BUS_FMT_SGRBG16_1X16:\n+\t\treturn V4L2_PIX_FMT_IPU3_SGRBG10;\n+\tcase MEDIA_BUS_FMT_SRGGB8_1X8:\n+\tcase MEDIA_BUS_FMT_SRGGB10_1X10:\n+\tcase MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8:\n+\tcase MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8:\n+\tcase MEDIA_BUS_FMT_SRGGB12_1X12:\n+\tcase MEDIA_BUS_FMT_SRGGB14_1X14:\n+\tcase MEDIA_BUS_FMT_SRGGB16_1X16:\n+\t\treturn V4L2_PIX_FMT_IPU3_SRGGB10;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\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","03/14"]}