Show a patch.

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

{
    "id": 1552,
    "url": "https://patchwork.libcamera.org/api/patches/1552/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1552/",
    "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": "<20190630233817.10130-11-laurent.pinchart@ideasonboard.com>",
    "date": "2019-06-30T23:38:13",
    "name": "[libcamera-devel,v3,10/14] libcamera: pipeline: vimc: Add controls support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "eba8177eef478ca8f353bd6aa618de6f05e478ca",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1552/mbox/",
    "series": [
        {
            "id": 384,
            "url": "https://patchwork.libcamera.org/api/series/384/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=384",
            "date": "2019-06-30T23:38:03",
            "name": "libcamera Controls",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/384/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1552/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1552/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BBCA561F74\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 01:38:45 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 62C702F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  1 Jul 2019 01:38:45 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561937925;\n\tbh=VhOtoNNCSjMgydO5HMbTNoaRYEggWyxCXcNgLdgFwyk=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=wKy4mAfX6tM2iTcUBzaEwihc9LjygOWsfD0bN8vJDcIiTzURv6WdboPwhjoCVaXxi\n\tFEifQ+lEf3q4f457Q8CcUI99PjBmWLqhsyVLOl/ioQf3NG9QfNWF2GDewVwzJCAALh\n\tGlKguCSw86CmB3+xhTrsShbLd5wlV3DtnOrzQXvs=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  1 Jul 2019 02:38:13 +0300",
        "Message-Id": "<20190630233817.10130-11-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "In-Reply-To": "<20190630233817.10130-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190630233817.10130-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 10/14] libcamera: pipeline: vimc: Add\n\tcontrols support",
        "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, 30 Jun 2019 23:38:47 -0000"
    },
    "content": "Implement control support in the VIMC pipeline handler by dynamically\nquerying the V4L2 device for the supported V4L2 controls and populating\nthe list of camera controls accordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/vimc.cpp | 105 ++++++++++++++++++++++++++++++--\n 1 file changed, 100 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 6833213650dc..fb073f2d078e 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -7,19 +7,24 @@\n \n #include <algorithm>\n #include <array>\n+#include <iomanip>\n+#include <tuple>\n \n #include <libcamera/camera.h>\n+#include <libcamera/controls.h>\n #include <libcamera/ipa/ipa_interface.h>\n #include <libcamera/ipa/ipa_module_info.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\n \n+#include \"camera_sensor.h\"\n #include \"device_enumerator.h\"\n #include \"ipa_manager.h\"\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n+#include \"v4l2_controls.h\"\n #include \"v4l2_videodevice.h\"\n \n namespace libcamera {\n@@ -36,12 +41,15 @@ public:\n \n \t~VimcCameraData()\n \t{\n+\t\tdelete sensor_;\n \t\tdelete video_;\n \t}\n \n+\tint init(MediaDevice *media);\n \tvoid bufferReady(Buffer *buffer);\n \n \tV4L2VideoDevice *video_;\n+\tCameraSensor *sensor_;\n \tStream stream_;\n };\n \n@@ -75,6 +83,8 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n+\tint processControls(VimcCameraData *data, Request *request);\n+\n \tVimcCameraData *cameraData(const Camera *camera)\n \t{\n \t\treturn static_cast<VimcCameraData *>(\n@@ -215,6 +225,45 @@ void PipelineHandlerVimc::stop(Camera *camera)\n \tPipelineHandler::stop(camera);\n }\n \n+int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n+{\n+\tV4L2ControlList controls;\n+\n+\tfor (auto it : request->controls()) {\n+\t\tconst ControlInfo *ci = it.first;\n+\t\tControlValue &value = it.second;\n+\n+\t\tswitch (ci->id()) {\n+\t\tcase Brightness:\n+\t\t\tcontrols.add(V4L2_CID_BRIGHTNESS, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tcase Contrast:\n+\t\t\tcontrols.add(V4L2_CID_CONTRAST, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tcase Saturation:\n+\t\t\tcontrols.add(V4L2_CID_SATURATION, value.getInt());\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tfor (const V4L2Control &ctrl : controls)\n+\t\tLOG(VIMC, Debug)\n+\t\t\t<< \"Setting control 0x\"\n+\t\t\t<< std::hex << std::setw(8) << ctrl.id() << std::dec\n+\t\t\t<< \" to \" << ctrl.value();\n+\n+\tint ret = data->sensor_->setControls(&controls);\n+\tif (ret)\n+\t\tLOG(VIMC, Error) << \"Failed to set controls\";\n+\n+\treturn ret;\n+}\n+\n int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n {\n \tVimcCameraData *data = cameraData(camera);\n@@ -226,7 +275,11 @@ int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n \t\treturn -ENOENT;\n \t}\n \n-\tint ret = data->video_->queueBuffer(buffer);\n+\tint ret = processControls(data, request);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = data->video_->queueBuffer(buffer);\n \tif (ret < 0)\n \t\treturn ret;\n \n@@ -262,12 +315,9 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);\n \n \t/* Locate and open the capture video node. */\n-\tdata->video_ = new V4L2VideoDevice(media->getEntityByName(\"Raw Capture 1\"));\n-\tif (data->video_->open())\n+\tif (data->init(media))\n \t\treturn false;\n \n-\tdata->video_->bufferReady.connect(data.get(), &VimcCameraData::bufferReady);\n-\n \t/* Create and register the camera. */\n \tstd::set<Stream *> streams{ &data->stream_ };\n \tstd::shared_ptr<Camera> camera = Camera::create(this, \"VIMC Sensor B\",\n@@ -277,6 +327,51 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \treturn true;\n }\n \n+int VimcCameraData::init(MediaDevice *media)\n+{\n+\tint ret;\n+\n+\t/* Create and open the video device and the camera sensor. */\n+\tvideo_ = new V4L2VideoDevice(media->getEntityByName(\"Raw Capture 1\"));\n+\tif (video_->open())\n+\t\treturn -ENODEV;\n+\n+\tvideo_->bufferReady.connect(this, &VimcCameraData::bufferReady);\n+\n+\tsensor_ = new CameraSensor(media->getEntityByName(\"Sensor B\"));\n+\tret = sensor_->init();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Initialise the supported controls. */\n+\tconst V4L2ControlInfoMap &controls = sensor_->controls();\n+\tfor (const auto &ctrl : controls) {\n+\t\tunsigned int v4l2Id = ctrl.first;\n+\t\tconst V4L2ControlInfo &info = ctrl.second;\n+\t\tControlId id;\n+\n+\t\tswitch (v4l2Id) {\n+\t\tcase V4L2_CID_BRIGHTNESS:\n+\t\t\tid = Brightness;\n+\t\t\tbreak;\n+\t\tcase V4L2_CID_CONTRAST:\n+\t\t\tid = Contrast;\n+\t\t\tbreak;\n+\t\tcase V4L2_CID_SATURATION:\n+\t\t\tid = Saturation;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tcontrolInfo_.emplace(std::piecewise_construct,\n+\t\t\t\t     std::forward_as_tuple(id),\n+\t\t\t\t     std::forward_as_tuple(id, info.min(), info.max()));\n+\t}\n+\n+\treturn 0;\n+}\n+\n void VimcCameraData::bufferReady(Buffer *buffer)\n {\n \tRequest *request = queuedRequests_.front();\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "10/14"
    ]
}