Show a patch.

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

{
    "id": 11876,
    "url": "https://patchwork.libcamera.org/api/patches/11876/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11876/",
    "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": "<20210409043208.1823330-3-hiroh@chromium.org>",
    "date": "2021-04-09T04:32:05",
    "name": "[libcamera-devel,RFC,2/5] libcamera: V4L2Subdevice: Add getter/setter function for test pattern mode",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": false,
    "hash": "b155d161e53f5b49fd8bb764f8f646eb19e71b89",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11876/mbox/",
    "series": [
        {
            "id": 1906,
            "url": "https://patchwork.libcamera.org/api/series/1906/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1906",
            "date": "2021-04-09T04:32:03",
            "name": "Report available test pattern modes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1906/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11876/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11876/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 996D7BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  9 Apr 2021 04:32:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E854C687FE;\n\tFri,  9 Apr 2021 06:32:19 +0200 (CEST)",
            "from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com\n\t[IPv6:2607:f8b0:4864:20::52c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 65C5A6879F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Apr 2021 06:32:18 +0200 (CEST)",
            "by mail-pg1-x52c.google.com with SMTP id f29so2943970pgm.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 08 Apr 2021 21:32:18 -0700 (PDT)",
            "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:7567:510e:1b47:ce92])\n\tby smtp.gmail.com with ESMTPSA id\n\til6sm737275pjb.56.2021.04.08.21.32.15\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 08 Apr 2021 21:32:16 -0700 (PDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"WVE1s0Hk\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=VUGAIDjTkjuUhahNCh14V0cenxuZqjvdUJFw7LfwF1E=;\n\tb=WVE1s0Hk8a3Wdb6GKXvk7onpUWcf2W3qdAmGBanCrWMOsJEziuihgJtK2cFg/RnMY8\n\tlIBWrojr151gtw6NtZWsC6mcKO/5Pg97vv5t1N5qnSDVzaQs/GO/1wDs01JbquRZ3fOC\n\tNvN4PDahvtydh1zRwLWX9aWAkcVCu/UOo9hhU=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=VUGAIDjTkjuUhahNCh14V0cenxuZqjvdUJFw7LfwF1E=;\n\tb=DfL5Hr7jAkaqvVMlHetbd91ExqNhxbD9U5cz5RvIBgyBzml4WAt6ghW7A8XZdsG6QT\n\t2lD21dQPzgJ4PS8Gq9+6u7TzPhYDIWRHiIcSaBm+9Hz2+9brXPAoBTwzxaZyqjl102my\n\tvrz9uapkU3oTKGU1AxBEBXnV+ha0SE18EhCPAOA06Hlxrsv5BWVjX0NhFJNaA2txytKy\n\tUdsmpOGVH34mnlKvhReFeHWWG0+sWgWPKhMlidTv5n+rXRe/uUOdJKWhxq4HrD5q39gs\n\tXYjrAPi8YulmYqszahx0qBPSEouq4AMstIAN2lDrDBkn6BOXgLuaGNxH/Lvbk0kQ8RRY\n\tJKhg==",
        "X-Gm-Message-State": "AOAM532DftIZaKAaw5jLt4/1b8pQ/W5++xRtFn6l+5LKWdk3ZdngnCl+\n\t0mBqZCjL9Kt0wHJO/mGXALTEWf+4TO10aA==",
        "X-Google-Smtp-Source": "ABdhPJwPuthi3o/kdXblhPm/LEkrQWGyJzUjY9XZnvD6kmSGOONZkZP2uG9mNgvW5pYUcLNZ9N+GzQ==",
        "X-Received": "by 2002:a65:4383:: with SMTP id m3mr11334327pgp.57.1617942736863;\n\tThu, 08 Apr 2021 21:32:16 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  9 Apr 2021 13:32:05 +0900",
        "Message-Id": "<20210409043208.1823330-3-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.31.1.295.g9ea45b61b8-goog",
        "In-Reply-To": "<20210409043208.1823330-1-hiroh@chromium.org>",
        "References": "<20210409043208.1823330-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [RFC PATCH 2/5] libcamera: V4L2Subdevice: Add\n\tgetter/setter function for test pattern mode",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The supported test pattern modes can be obtained by calling\nVIDIOC_QUERYMENU to a camera sensor device. This implements the\ngetter and setter functions for the test pattern mode in\nV4L2SubDevice.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/v4l2_subdevice.h |   5 +\n src/libcamera/v4l2_subdevice.cpp            | 104 ++++++++++++++++++++\n 2 files changed, 109 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\nindex d2b9ca55..f2f5d3f6 100644\n--- a/include/libcamera/internal/v4l2_subdevice.h\n+++ b/include/libcamera/internal/v4l2_subdevice.h\n@@ -60,6 +60,9 @@ public:\n \tint setFormat(unsigned int pad, V4L2SubdeviceFormat *format,\n \t\t      Whence whence = ActiveFormat);\n \n+\tstd::vector<int32_t> getAvailableTestPatternModes();\n+\tint setTestPatternMode(int32_t testPatternMode);\n+\n \tstatic std::unique_ptr<V4L2Subdevice>\n \tfromEntityName(const MediaDevice *media, const std::string &entity);\n \n@@ -74,6 +77,8 @@ private:\n \t\t\t\t\t    unsigned int code);\n \n \tconst MediaEntity *entity_;\n+\n+\tstd::map<int32_t, uint32_t> testPatternModeMap_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 721ff5a9..130e9c4d 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -24,6 +24,7 @@\n #include \"libcamera/internal/media_object.h\"\n #include \"libcamera/internal/utils.h\"\n \n+#include \"android/metadata/system/camera_metadata_tags.h\"\n /**\n  * \\file v4l2_subdevice.h\n  * \\brief V4L2 Subdevice API\n@@ -523,4 +524,107 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n \treturn sizes;\n }\n \n+/**\n+ * \\var V4L2Subdevice::testPatternModeMap_\n+ * \\brief The map from controls::SensorTestPatternMode to an index value to be\n+ * used for V4L2_CID_TEST_PATTERN.\n+ *\n+ * The map is constructed in getAvailableTestPatternModes() and referred in\n+ * setTestPatternMode() to find a value associated with the requested test\n+ * pattern mode.\n+ */\n+/**\n+ * \\fn V4L2Subdevice::getAvailableTestPatternModes()\n+ * \\brief Retrieve the available test pattern modes.\n+ *\n+ * \\return The available control::SensorTestPatternMode values.\n+ */\n+std::vector<int32_t> V4L2Subdevice::getAvailableTestPatternModes()\n+{\n+\tstd::vector<int32_t> patternModes;\n+\tif (!testPatternModeMap_.empty()) {\n+\t\tfor (const auto &mode : testPatternModeMap_)\n+\t\t\tpatternModes.push_back(mode.first);\n+\t\treturn patternModes;\n+\t}\n+\n+\tv4l2_queryctrl ctrl;\n+\tmemset(&ctrl, 0, sizeof(ctrl));\n+\tctrl.id = V4L2_CID_TEST_PATTERN;\n+\tint ret = ioctl(VIDIOC_QUERYCTRL, &ctrl);\n+\tif (ret < 0) {\n+\t\tLOG(V4L2, Error) << \"Unable to get test pattern mode :\"\n+\t\t\t\t << strerror(-ret);\n+\t\treturn {};\n+\t}\n+\n+\tv4l2_querymenu menu;\n+\tmemset(&menu, 0, sizeof(menu));\n+\tmenu.id = ctrl.id;\n+\tfor (menu.index = ctrl.minimum;\n+\t     static_cast<int>(menu.index) <= ctrl.maximum; menu.index++) {\n+\t\tif (ioctl(VIDIOC_QUERYMENU, &menu) != 0) {\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tconst std::string modeName(reinterpret_cast<char *>(menu.name));\n+\t\tstd::optional<int32_t> androidTestPatternMode;\n+\t\t/*\n+\t\t * ov13858 and ov5670.\n+\t\t * No corresponding value for \"Vertical Color Bar Type 3\" and\n+\t\t * \"Vertical Color Bar Type 4\".\n+\t\t */\n+\t\tif (modeName == \"Disabled\") {\n+\t\t\tandroidTestPatternMode =\n+\t\t\t\tANDROID_SENSOR_TEST_PATTERN_MODE_OFF;\n+\t\t} else if (modeName == \"Vertical Color Bar Type 1\") {\n+\t\t\tandroidTestPatternMode =\n+\t\t\t\tANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS;\n+\t\t} else if (modeName == \"Vertical Color Bar Type 2\") {\n+\t\t\tandroidTestPatternMode =\n+\t\t\t\tANDROID_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY;\n+\t\t}\n+\n+\t\tif (androidTestPatternMode) {\n+\t\t\ttestPatternModeMap_[*androidTestPatternMode] = menu.index;\n+\t\t\tpatternModes.push_back(*androidTestPatternMode);\n+\t\t} else {\n+\t\t\tLOG(V4L2, Debug) << \"Skip test pattern mode: \"\n+\t\t\t\t\t << modeName;\n+\t\t}\n+\t}\n+\n+\treturn patternModes;\n+}\n+\n+/**\n+ * \\fn V4L2Subdevice::getAvailableTestPatternModes()\n+ * \\brief Set the test pattern mode.\n+ *\n+ * \\return 0 on success or a negative error code otherwise.\n+ */\n+int V4L2Subdevice::setTestPatternMode(int32_t testPatternMode)\n+{\n+\tauto it = testPatternModeMap_.find(testPatternMode);\n+\tif (it != testPatternModeMap_.end()) {\n+\t\tLOG(V4L2, Error) << \"Unsupported test pattern mode: \"\n+\t\t\t\t << testPatternMode;\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tv4l2_control ctrl;\n+\tmemset(&ctrl, 0, sizeof(ctrl));\n+\tctrl.id = V4L2_CID_TEST_PATTERN;\n+\tctrl.value = it->second;\n+\tint ret = ioctl(VIDIOC_S_CTRL, &ctrl);\n+\tif (ret < 0) {\n+\t\tLOG(V4L2, Error) << \"Unable to set test pattern mode: \"\n+\t\t\t\t << strerror(-ret);\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "2/5"
    ]
}