Show a patch.

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

{
    "id": 1439,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1439/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1439/",
    "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": "<20190616133402.21934-9-niklas.soderlund@ragnatech.se>",
    "date": "2019-06-16T13:33:54",
    "name": "[libcamera-devel,v3,08/16] libcamera: v4l2_subdevice: Replace FormatEnum with ImageFormats",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "8cba7623d03886f59438d99e8a798502d9231ff8",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1439/mbox/",
    "series": [
        {
            "id": 358,
            "url": "https://patchwork.libcamera.org/api/1.1/series/358/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=358",
            "date": "2019-06-16T13:33:46",
            "name": "libcamera: Add support for format information and validation",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/358/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1439/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1439/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B2F964784\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 16 Jun 2019 15:35:37 +0200 (CEST)",
            "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 9819b4ee-903b-11e9-8ab4-005056917a89;\n\tSun, 16 Jun 2019 15:35:24 +0200 (CEST)"
        ],
        "X-Halon-ID": "9819b4ee-903b-11e9-8ab4-005056917a89",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sun, 16 Jun 2019 15:33:54 +0200",
        "Message-Id": "<20190616133402.21934-9-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190616133402.21934-1-niklas.soderlund@ragnatech.se>",
        "References": "<20190616133402.21934-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 08/16] libcamera: v4l2_subdevice:\n\tReplace FormatEnum with ImageFormats",
        "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": "Sun, 16 Jun 2019 13:35:37 -0000"
    },
    "content": "Replace all usage of FormatEnum with ImageFormats and completely\nremove FormatEnum which is no longer needed.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/camera_sensor.cpp        | 14 ++++++--------\n src/libcamera/formats.cpp              | 10 ----------\n src/libcamera/include/formats.h        |  2 --\n src/libcamera/include/v4l2_subdevice.h |  2 +-\n src/libcamera/v4l2_subdevice.cpp       | 26 +++++++++++++-------------\n test/v4l2_subdevice/list_formats.cpp   | 16 ++++++++--------\n 6 files changed, 28 insertions(+), 42 deletions(-)",
    "diff": "diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex cb6649efac3ff794..a804a68c9d91cda6 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -90,27 +90,25 @@ int CameraSensor::init()\n \t\treturn ret;\n \n \t/* Enumerate and cache media bus codes and sizes. */\n-\tconst FormatEnum formats = subdev_->formats(0);\n-\tif (formats.empty()) {\n+\tconst ImageFormats formats = subdev_->formats(0);\n+\tif (formats.isEmpty()) {\n \t\tLOG(CameraSensor, Error) << \"No image format found\";\n \t\treturn -EINVAL;\n \t}\n \n-\tstd::transform(formats.begin(), formats.end(),\n-\t\t       std::back_inserter(mbusCodes_),\n-\t\t       [](decltype(*formats.begin()) f) { return f.first; });\n+\tmbusCodes_ = formats.formats();\n \n \t/*\n \t * Extract the supported sizes from the first format as we only support\n \t * sensors that offer the same frame sizes for all media bus codes.\n \t * Verify this assumption and reject the sensor if it isn't true.\n \t */\n-\tconst std::vector<SizeRange> &sizes = formats.begin()->second;\n+\tconst std::vector<SizeRange> &sizes = formats.sizes(mbusCodes_[0]);\n \tstd::transform(sizes.begin(), sizes.end(), std::back_inserter(sizes_),\n \t\t       [](const SizeRange &range) { return range.max; });\n \n-\tfor (auto it = ++formats.begin(); it != formats.end(); ++it) {\n-\t\tif (it->second != sizes) {\n+\tfor (unsigned int code : mbusCodes_) {\n+\t\tif (formats.sizes(code) != sizes) {\n \t\t\tLOG(CameraSensor, Error)\n \t\t\t\t<< \"Frame sizes differ between media bus codes\";\n \t\t\treturn -EINVAL;\ndiff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 2fd0c5480324ce33..0d196ee3a83e9c0d 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -14,16 +14,6 @@\n \n namespace libcamera {\n \n-/**\n- * \\typedef FormatEnum\n- * \\brief Type definition for the map of image formats and sizes\n- *\n- * Type definition used to enumerate the supported pixel formats and image\n- * frame sizes. The type associates in a map a pixel format (for memory\n- * formats) or a media bus code (for bus formats), to a vector of image\n- * resolutions represented by SizeRange items.\n- */\n-\n /**\n  * \\class ImageFormats\n  * \\brief Describe V4L2Device and V4L2SubDevice image formats\ndiff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\nindex a49f83f3d8d60621..de63ba557e045585 100644\n--- a/src/libcamera/include/formats.h\n+++ b/src/libcamera/include/formats.h\n@@ -15,8 +15,6 @@\n \n namespace libcamera {\n \n-typedef std::map<unsigned int, std::vector<SizeRange>> FormatEnum;\n-\n class ImageFormats\n {\n public:\ndiff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex c6fdf417b43c0423..9afd28b6db023ddf 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -45,7 +45,7 @@ public:\n \tint setCrop(unsigned int pad, Rectangle *rect);\n \tint setCompose(unsigned int pad, Rectangle *rect);\n \n-\tFormatEnum formats(unsigned int pad);\n+\tImageFormats formats(unsigned int pad);\n \n \tint getFormat(unsigned int pad, V4L2SubdeviceFormat *format);\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format);\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 35052b4aa45d3e42..e109a00bcd3bdd46 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -187,22 +187,17 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)\n }\n \n /**\n- * \\brief List the sub-device image resolutions and formats on \\a pad\n+ * \\brief Enumerate all media bus codes and frame sizes on a \\a pad\n  * \\param[in] pad The 0-indexed pad number to enumerate formats on\n  *\n- * Retrieve a list of image formats and sizes on the \\a pad of a video\n- * subdevice. Subdevices can report either a list of discrete sizes they\n- * support or a list of intervals expressed as a [min-max] sizes range.\n+ * Enumerate all media bus codes  and frame sizes supported by the subdevice on\n+ * a \\a pad.\n  *\n- * Each image size list is associated with a media bus pixel code for which\n- * the reported resolutions are supported.\n- *\n- * \\return A map of image formats associated with a list of image sizes, or\n- * an empty map on error or if the pad does not exist\n+ * \\return A list of the supported device formats\n  */\n-FormatEnum V4L2Subdevice::formats(unsigned int pad)\n+ImageFormats V4L2Subdevice::formats(unsigned int pad)\n {\n-\tFormatEnum formatMap = {};\n+\tImageFormats formats;\n \n \tif (pad >= entity_->pads().size()) {\n \t\tLOG(V4L2Subdev, Error) << \"Invalid pad: \" << pad;\n@@ -215,10 +210,15 @@ FormatEnum V4L2Subdevice::formats(unsigned int pad)\n \t\tif (sizes.empty())\n \t\t\treturn {};\n \n-\t\tformatMap[code] = sizes;\n+\t\tif (formats.addFormat(code, sizes)) {\n+\t\t\tLOG(V4L2Subdev, Error)\n+\t\t\t\t<< \"Could not add sizes for media bus code \"\n+\t\t\t\t<< code << \"on pad \" << pad;\n+\t\t\treturn {};\n+\t\t}\n \t}\n \n-\treturn formatMap;\n+\treturn formats;\n }\n \n /**\ndiff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp\nindex 3f0edafcdcd72d6b..067dc5ed30f4edd9 100644\n--- a/test/v4l2_subdevice/list_formats.cpp\n+++ b/test/v4l2_subdevice/list_formats.cpp\n@@ -47,29 +47,29 @@ void ListFormatsTest::printFormats(unsigned int pad,\n int ListFormatsTest::run()\n {\n \t/* List all formats available on existing \"Scaler\" pads. */\n-\tstd::map<unsigned int, std::vector<SizeRange>> formats;\n+\tImageFormats formats;\n \n \tformats = scaler_->formats(0);\n-\tif (formats.empty()) {\n+\tif (formats.isEmpty()) {\n \t\tcerr << \"Failed to list formats on pad 0 of subdevice \"\n \t\t     << scaler_->entity()->name() << endl;\n \t\treturn TestFail;\n \t}\n-\tfor (auto it = formats.begin(); it != formats.end(); ++it)\n-\t\tprintFormats(0, it->first, it->second);\n+\tfor (unsigned int code : formats.formats())\n+\t\tprintFormats(0, code, formats.sizes(code));\n \n \tformats = scaler_->formats(1);\n-\tif (formats.empty()) {\n+\tif (formats.isEmpty()) {\n \t\tcerr << \"Failed to list formats on pad 1 of subdevice \"\n \t\t     << scaler_->entity()->name() << endl;\n \t\treturn TestFail;\n \t}\n-\tfor (auto it = formats.begin(); it != formats.end(); ++it)\n-\t\tprintFormats(1, it->first, it->second);\n+\tfor (unsigned int code : formats.formats())\n+\t\tprintFormats(1, code, formats.sizes(code));\n \n \t/* List format on a non-existing pad, format vector shall be empty. */\n \tformats = scaler_->formats(2);\n-\tif (!formats.empty()) {\n+\tif (!formats.isEmpty()) {\n \t\tcerr << \"Listing formats on non-existing pad 2 of subdevice \"\n \t\t     << scaler_->entity()->name()\n \t\t     << \" should return an empty format list\" << endl;\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "08/16"
    ]
}