Show a patch.

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

{
    "id": 1746,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1746/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1746/",
    "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": "<20190808000404.10841-3-niklas.soderlund@ragnatech.se>",
    "date": "2019-08-08T00:04:02",
    "name": "[libcamera-devel,v3,2/4] libcamera: pipeline: vimc: Switch to using the RGB/YUV Capture video node",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2201abc31085c025e1dbe07ee391405e252652a5",
    "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/1746/mbox/",
    "series": [
        {
            "id": 448,
            "url": "https://patchwork.libcamera.org/api/1.1/series/448/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=448",
            "date": "2019-08-08T00:04:00",
            "name": "libcamera: Fix issues with vimc and Linux v5.2",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/448/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1746/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1746/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 BFF8961623\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Aug 2019 02:04:10 +0200 (CEST)",
            "from bismarck.berto.se (unknown [145.14.112.32])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 06e79393-b970-11e9-bdc3-005056917a89;\n\tThu, 08 Aug 2019 02:04:01 +0200 (CEST)"
        ],
        "X-Halon-ID": "06e79393-b970-11e9-bdc3-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": "Thu,  8 Aug 2019 02:04:02 +0200",
        "Message-Id": "<20190808000404.10841-3-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.22.0",
        "In-Reply-To": "<20190808000404.10841-1-niklas.soderlund@ragnatech.se>",
        "References": "<20190808000404.10841-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 2/4] libcamera: pipeline: vimc: Switch\n\tto using the RGB/YUV Capture video node",
        "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, 08 Aug 2019 00:04:11 -0000"
    },
    "content": "Linux commit 85ab1aa1fac17bcd (\"media: vimc: deb: fix default sink bayer\nformat\") which is part of v5.2 changes the default media bus format for\nthe debayer subdevices. This leads to a -EPIPE error when trying to use\nthe raw capture video device nodes.\n\nFix this by moving the vimc pipeline to use the RGB/YUV Capture capture\nvideo node. As a consequence of this change the scaler in the vimc\npipeline is used and a hard coded upscale of 3 is present in the video\npipeline. This limits the sizes exposed and accepted by libcamera to\nmultiples of 3.\n\nThe raw capture video node still needs to be handled by the pipeline as\nits format needs to be updated to allow the pipeline format validation\nto pass.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/pipeline/vimc.cpp | 112 ++++++++++++++++++++++++++++----\n test/camera/buffer_import.cpp   |   8 +--\n 2 files changed, 104 insertions(+), 16 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 3d6808222a8a2c5d..55975cae066d71cd 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -10,6 +10,8 @@\n #include <iomanip>\n #include <tuple>\n \n+#include <linux/media-bus-format.h>\n+\n #include <libcamera/camera.h>\n #include <libcamera/controls.h>\n #include <libcamera/ipa/ipa_interface.h>\n@@ -25,6 +27,7 @@\n #include \"pipeline_handler.h\"\n #include \"utils.h\"\n #include \"v4l2_controls.h\"\n+#include \"v4l2_subdevice.h\"\n #include \"v4l2_videodevice.h\"\n \n namespace libcamera {\n@@ -35,21 +38,28 @@ class VimcCameraData : public CameraData\n {\n public:\n \tVimcCameraData(PipelineHandler *pipe)\n-\t\t: CameraData(pipe), video_(nullptr), sensor_(nullptr)\n+\t\t: CameraData(pipe), sensor_(nullptr), debayer_(nullptr),\n+\t\t  scaler_(nullptr), video_(nullptr), raw_(nullptr)\n \t{\n \t}\n \n \t~VimcCameraData()\n \t{\n \t\tdelete sensor_;\n+\t\tdelete debayer_;\n+\t\tdelete scaler_;\n \t\tdelete video_;\n+\t\tdelete raw_;\n \t}\n \n \tint init(MediaDevice *media);\n \tvoid bufferReady(Buffer *buffer);\n \n-\tV4L2VideoDevice *video_;\n \tCameraSensor *sensor_;\n+\tV4L2Subdevice *debayer_;\n+\tV4L2Subdevice *scaler_;\n+\tV4L2VideoDevice *video_;\n+\tV4L2VideoDevice *raw_;\n \tStream stream_;\n };\n \n@@ -80,6 +90,8 @@ public:\n \n \tint queueRequest(Camera *camera, Request *request) override;\n \n+\tint initLinks(MediaDevice *media);\n+\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n@@ -131,8 +143,11 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()\n \t/* Clamp the size based on the device limits. */\n \tconst Size size = cfg.size;\n \n-\tcfg.size.width = std::max(16U, std::min(4096U, cfg.size.width));\n-\tcfg.size.height = std::max(16U, std::min(2160U, cfg.size.height));\n+\t/* Dimensions need to be a multiple of 3 for the scaler to work. */\n+\tcfg.size.width = std::max(18U, std::min(4096U, cfg.size.width));\n+\tcfg.size.height = std::max(18U, std::min(2160U, cfg.size.height));\n+\tcfg.size.width -= cfg.size.width % 3;\n+\tcfg.size.height -= cfg.size.height % 3;\n \n \tif (cfg.size != size) {\n \t\tLOG(VIMC, Debug)\n@@ -160,7 +175,7 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,\n \n \tStreamConfiguration cfg{};\n \tcfg.pixelFormat = V4L2_PIX_FMT_RGB24;\n-\tcfg.size = { 640, 480 };\n+\tcfg.size = { 1920, 1080 };\n \tcfg.bufferCount = 4;\n \n \tconfig->addConfiguration(cfg);\n@@ -176,6 +191,33 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n \tStreamConfiguration &cfg = config->at(0);\n \tint ret;\n \n+\t/* The scaler hardcodes a x3 scale-up ratio. */\n+\tV4L2SubdeviceFormat subformat = {};\n+\tsubformat.mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8;\n+\tsubformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n+\n+\tret = data->sensor_->setFormat(&subformat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = data->debayer_->setFormat(0, &subformat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tsubformat.mbus_code = MEDIA_BUS_FMT_RGB888_1X24;\n+\tret = data->debayer_->setFormat(1, &subformat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = data->scaler_->setFormat(0, &subformat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tsubformat.size = cfg.size;\n+\tret = data->scaler_->setFormat(1, &subformat);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tV4L2DeviceFormat format = {};\n \tformat.fourcc = cfg.pixelFormat;\n \tformat.size = cfg.size;\n@@ -188,6 +230,17 @@ int PipelineHandlerVimc::configure(Camera *camera, CameraConfiguration *config)\n \t    format.fourcc != cfg.pixelFormat)\n \t\treturn -EINVAL;\n \n+\t/*\n+\t * Format has to be set on the raw capture video node, otherwise the\n+\t * vimc driver will fail pipeline validation.\n+\t */\n+\tformat.fourcc = V4L2_PIX_FMT_SGRBG8;\n+\tformat.size = { cfg.size.width / 3, cfg.size.height / 3 };\n+\n+\tret = data->raw_->setFormat(&format);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tcfg.setStream(&data->stream_);\n \n \treturn 0;\n@@ -292,6 +345,26 @@ int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)\n \treturn 0;\n }\n \n+int PipelineHandlerVimc::initLinks(MediaDevice *media)\n+{\n+\tMediaLink *link;\n+\tint ret;\n+\n+\tret = media->disableLinks();\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tlink = media->link(\"Debayer B\", 1, \"Scaler\", 0);\n+\tif (!link)\n+\t\treturn -ENODEV;\n+\n+\tret = link->setEnabled(true);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\treturn 0;\n+}\n+\n bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n {\n \tDeviceMatch dm(\"vimc\");\n@@ -318,6 +391,9 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \n \tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);\n \n+\tif (initLinks(media))\n+\t\treturn false;\n+\n \t/* Locate and open the capture video node. */\n \tif (data->init(media))\n \t\treturn false;\n@@ -335,18 +411,30 @@ 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+\t/* Create and open the camera sensor, debayer, scaler and video device. */\n \tsensor_ = new CameraSensor(media->getEntityByName(\"Sensor B\"));\n \tret = sensor_->init();\n \tif (ret)\n \t\treturn ret;\n \n+\tdebayer_ = new V4L2Subdevice(media->getEntityByName(\"Debayer B\"));\n+\tif (debayer_->open())\n+\t\treturn -ENODEV;\n+\n+\tscaler_ = new V4L2Subdevice(media->getEntityByName(\"Scaler\"));\n+\tif (scaler_->open())\n+\t\treturn -ENODEV;\n+\n+\tvideo_ = new V4L2VideoDevice(media->getEntityByName(\"RGB/YUV Capture\"));\n+\tif (video_->open())\n+\t\treturn -ENODEV;\n+\n+\tvideo_->bufferReady.connect(this, &VimcCameraData::bufferReady);\n+\n+\traw_ = new V4L2VideoDevice(media->getEntityByName(\"Raw Capture 1\"));\n+\tif (raw_->open())\n+\t\treturn -ENODEV;\n+\n \t/* Initialise the supported controls. */\n \tconst V4L2ControlInfoMap &controls = sensor_->controls();\n \tfor (const auto &ctrl : controls) {\ndiff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp\nindex 400d02b350c1aa8f..620ee66dee0570bc 100644\n--- a/test/camera/buffer_import.cpp\n+++ b/test/camera/buffer_import.cpp\n@@ -72,12 +72,12 @@ public:\n \t\t\treturn ret;\n \t\t}\n \n-\t\tformat_.size.width = 640;\n-\t\tformat_.size.height = 480;\n+\t\tformat_.size.width = 1920;\n+\t\tformat_.size.height = 1080;\n \t\tformat_.fourcc = V4L2_PIX_FMT_RGB24;\n \t\tformat_.planesCount = 1;\n-\t\tformat_.planes[0].size = 640 * 480 * 3;\n-\t\tformat_.planes[0].bpl = 640 * 3;\n+\t\tformat_.planes[0].size = 1920 * 1080 * 3;\n+\t\tformat_.planes[0].bpl = 1920 * 3;\n \n \t\tif (video_->setFormat(&format_)) {\n \t\t\tcleanup();\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "2/4"
    ]
}