Show a patch.

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

{
    "id": 1427,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1427/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1427/",
    "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": "<20190613112046.25260-4-jacopo@jmondi.org>",
    "date": "2019-06-13T11:20:43",
    "name": "[libcamera-devel,v3,3/6] libcamera: v4l2_device: Implement get and set controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "41e5b5c8ccc079000c061cb43a9993114376ef33",
    "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/1427/mbox/",
    "series": [
        {
            "id": 357,
            "url": "https://patchwork.libcamera.org/api/1.1/series/357/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=357",
            "date": "2019-06-13T11:20:40",
            "name": "Add support for V4L2 Controls",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/357/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1427/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1427/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B20F61BE0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 13:19:43 +0200 (CEST)",
            "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 1CD41C0015;\n\tThu, 13 Jun 2019 11:19:42 +0000 (UTC)"
        ],
        "X-Originating-IP": "2.224.242.101",
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 13 Jun 2019 13:20:43 +0200",
        "Message-Id": "<20190613112046.25260-4-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190613112046.25260-1-jacopo@jmondi.org>",
        "References": "<20190613112046.25260-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 3/6] libcamera: v4l2_device: Implement\n\tget and set controls",
        "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": "Thu, 13 Jun 2019 11:19:43 -0000"
    },
    "content": "Implement getControls() and setControls() operations in V4L2Device class.\n\nBoth operations take a V4L2Controls instance and read or write the V4L2\ncontrols on the V4L2 device.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_device.h |   6 +\n src/libcamera/v4l2_device.cpp       | 188 ++++++++++++++++++++++++++++\n 2 files changed, 194 insertions(+)",
    "diff": "diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 727b9d2e210a..28463922b984 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -13,12 +13,17 @@\n namespace libcamera {\n \n class V4L2ControlInfo;\n+class V4L2Controls;\n \n class V4L2Device\n {\n public:\n \tvirtual ~V4L2Device();\n \n+\tV4L2ControlInfo *getControlInfo(unsigned int id);\n+\tint getControls(V4L2Controls *ctrls);\n+\tint setControls(V4L2Controls *ctrls);\n+\n protected:\n \tV4L2Device();\n \n@@ -32,6 +37,7 @@ protected:\n \n private:\n \tint listControls();\n+\tint validateControlType(V4L2ControlInfo *info);\n \n \tint fd_;\n \tstd::map<unsigned int, V4L2ControlInfo *> controls_;\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex b60b446050e9..c3400e0c448e 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -159,4 +159,192 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n \treturn 0;\n }\n \n+/**\n+ * \\brief Get informations for control with \\a id\n+ * \\param id The control id to search info for\n+ * \\return The V4L2ControlInfo associated to the V4L2 control with \\a id or\n+ * nullptr if the control is not supported by the V4L2Device\n+ */\n+V4L2ControlInfo *V4L2Device::getControlInfo(unsigned int id)\n+{\n+\tauto it = controls_.find(id);\n+\tif (it == controls_.end())\n+\t\treturn nullptr;\n+\n+\treturn it->second;\n+}\n+\n+/**\n+ * \\brief Read values of a list of controls from the device\n+ * \\param ctrls The list of controls to read\n+ *\n+ * Read the value of each V4L2Controls contained in \\a ctrls, overwriting\n+ * it's current value with the one returned by the device.\n+ *\n+ * Each V4L2Control instance in \\a ctrls should be supported by the device.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::getControls(V4L2Controls *ctrls)\n+{\n+\tunsigned int count = ctrls->size();\n+\tif (count == 0)\n+\t\treturn 0;\n+\n+\tstruct V4L2ControlInfo *controlInfo[count];\n+\tstruct v4l2_ext_control v4l2Ctrls[count];\n+\tfor (unsigned int i = 0; i < count; ++i) {\n+\t\tV4L2Control *ctrl = (*ctrls)[i];\n+\n+\t\t/* Validate the control. */\n+\t\tV4L2ControlInfo *info = getControlInfo(ctrl->id());\n+\t\tif (!info) {\n+\t\t\tLOG(V4L2, Error) << \"Control '\" << ctrl->id()\n+\t\t\t\t\t << \"' not valid\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (validateControlType(info))\n+\t\t\treturn -EINVAL;\n+\n+\t\tcontrolInfo[i] = info;\n+\n+\t\t/* Prepare the v4l2_ext_control entry for the read operation. */\n+\t\tstruct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n+\t\tv4l2Ctrl->id = info->id();\n+\t\tv4l2Ctrl->size = info->size();\n+\t}\n+\n+\tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n+\tv4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL;\n+\tv4l2ExtCtrls.controls = v4l2Ctrls;\n+\tv4l2ExtCtrls.count = count;\n+\n+\tint ret = ioctl(VIDIOC_G_EXT_CTRLS, &v4l2ExtCtrls);\n+\tif (ret) {\n+\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n+\t\t\t\t << strerror(ret);\n+\t\treturn ret;\n+\t}\n+\n+\t/*\n+\t * For each control read from the device, set the value in the\n+\t * V4L2ControlValue provided by the caller.\n+\t */\n+\tfor (unsigned int i = 0; i < count; ++i) {\n+\t\tstruct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n+\t\tV4L2ControlInfo *info = controlInfo[i];\n+\t\tV4L2Control *ctrl = (*ctrls)[i];\n+\n+\t\tswitch (info->type()) {\n+\t\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\t\t\tctrl->setValue(v4l2Ctrl->value64);\n+\t\t\tbreak;\n+\t\tcase V4L2_CTRL_TYPE_INTEGER:\n+\t\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\t\tcase V4L2_CTRL_TYPE_BUTTON:\n+\t\tcase V4L2_CTRL_TYPE_MENU:\n+\t\t\tctrl->setValue(static_cast<long int>(v4l2Ctrl->value));\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Write a list of controls to the device\n+ * \\param ctrls The list of controls to apply\n+ *\n+ * Write the value of each V4L2Control contained in \\a ctrls. Each\n+ * control should be initialized by the caller with a value, otherwise\n+ * the result of the operation is undefined.\n+ *\n+ * The value of each control is not updated to reflect what has been\n+ * actually applied on the device. To read the actual value of a control\n+ * after a setControls(), users should read the control value back with\n+ * getControls().\n+ *\n+ * Each V4L2Control instance in \\a ctrls should be supported by the device.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::setControls(V4L2Controls *ctrls)\n+{\n+\tunsigned int count = ctrls->size();\n+\tif (count == 0)\n+\t\treturn 0;\n+\n+\tstruct v4l2_ext_control v4l2Ctrls[count];\n+\tfor (unsigned int i = 0; i < count; ++i) {\n+\t\tV4L2Control *ctrl = (*ctrls)[i];\n+\n+\t\t/* Validate the control. */\n+\t\tV4L2ControlInfo *info = getControlInfo(ctrl->id());\n+\t\tif (!info) {\n+\t\t\tLOG(V4L2, Error) << \"Control '\" << ctrl->id()\n+\t\t\t\t\t << \"' not valid\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tif (validateControlType(info))\n+\t\t\treturn -EINVAL;\n+\n+\t\t/* Prepare the v4l2_ext_control entry for the write operation. */\n+\t\tstruct v4l2_ext_control *v4l2Ctrl = &v4l2Ctrls[i];\n+\t\tv4l2Ctrl->id = info->id();\n+\t\tv4l2Ctrl->size = info->size();\n+\n+\t\tswitch (info->type()) {\n+\t\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\t\t\tv4l2Ctrl->value64 = ctrl->value();\n+\t\t\tbreak;\n+\t\tcase V4L2_CTRL_TYPE_INTEGER:\n+\t\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\t\tcase V4L2_CTRL_TYPE_BUTTON:\n+\t\tcase V4L2_CTRL_TYPE_MENU:\n+\t\t\tv4l2Ctrl->value = static_cast<int32_t>(ctrl->value());\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n+\tv4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL;\n+\tv4l2ExtCtrls.controls = v4l2Ctrls;\n+\tv4l2ExtCtrls.count = count;\n+\n+\tint ret = ioctl(VIDIOC_S_EXT_CTRLS, &v4l2ExtCtrls);\n+\tif (ret) {\n+\t\tLOG(V4L2, Error) << \"Unable to write controls: \"\n+\t\t\t\t << strerror(ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * \\brief Make sure the control type is supported\n+ * \\param info The V4L2ControlInfo to inspect type of\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2Device::validateControlType(V4L2ControlInfo *info)\n+{\n+\t/* \\todo support compound and menu controls. */\n+\tswitch (info->type()) {\n+\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\tcase V4L2_CTRL_TYPE_INTEGER:\n+\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\tcase V4L2_CTRL_TYPE_BUTTON:\n+\tcase V4L2_CTRL_TYPE_MENU:\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(V4L2, Error) << \"Control type '\" << info->type()\n+\t\t\t\t << \"' not supported\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "3/6"
    ]
}