Show a patch.

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

{
    "id": 17144,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17144/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17144/",
    "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": "<20220817172541.72339-2-rishikeshdonadkar@gmail.com>",
    "date": "2022-08-17T17:25:41",
    "name": "[libcamera-devel,v4,1/1] gstreamer: Provide mulitple colorimetry support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f7c61cf095e1929c06500ecda27708fafdf0bd0a",
    "submitter": {
        "id": 118,
        "url": "https://patchwork.libcamera.org/api/1.1/people/118/?format=api",
        "name": "Rishikesh Donadkar",
        "email": "rishikeshdonadkar@gmail.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17144/mbox/",
    "series": [
        {
            "id": 3422,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3422/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3422",
            "date": "2022-08-17T17:25:40",
            "name": "Multiple colorimetry support for libcamerasrc",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3422/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17144/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17144/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 C3A38BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 17 Aug 2022 17:26:11 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 77D4A61FC3;\n\tWed, 17 Aug 2022 19:26:11 +0200 (CEST)",
            "from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com\n\t[IPv6:2607:f8b0:4864:20::1032])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E875F61FA8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Aug 2022 19:26:09 +0200 (CEST)",
            "by mail-pj1-x1032.google.com with SMTP id\n\ts5-20020a17090a13c500b001f4da9ffe5fso2428696pjf.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Aug 2022 10:26:09 -0700 (PDT)",
            "from localhost.localdomain ([49.36.99.40])\n\tby smtp.googlemail.com with ESMTPSA id\n\tj5-20020a170902da8500b0016be834d54asm142071plx.306.2022.08.17.10.26.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 17 Aug 2022 10:26:07 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660757171;\n\tbh=0IeUkll8r/dmyymZcyKf7gyPTv8BgndMCkleyHzhbto=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=IwoLeFQmgihHHbuFazjQd2X783SaQ3TEOTVkY7abeiPLpi3j3l794P3WLnmTTiszB\n\tdUlH1w91MFao6J2bBQJn4gKKTDs9++6fOOJfZCBfDLGTmb6RFptwhRG9yh1TKwN7uE\n\t5xICk4qROEJcqkLF+zuYo29S/BFmpiyE41qmM09Cd2KIVS42le9Ffkvh4dB21e/dTO\n\tuBzhgxBJ08gNOcFUTMF40DUteZmEpOi5SffJlEBtMHexH4E3YtSXsUGioPTHpGLr7r\n\tfk4EwPgexCWoU5/adcapOliRYzXPiXSZLLqoUssR3/Lz/0cRLMmdmtY2LnyQ3eGeuf\n\t1FyxxEvvHMZiA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=vwDaES6dhbej3HqHxgtDOibtwCuqve0Ja+S6krTxfk8=;\n\tb=EEwzrJflNojn6jTAaMtLre9KfozIkeWdSp+oJtZHg67AWo4mgftWC3JVGnu4SvOdw/\n\t+/IVCnR6baIPxe8g2pizusMsQ6wGnfNwfn14RfGibxhu5akhuBP+cKmi8geIZ/mRMTFd\n\tFXO3t26ZFICvC8byUXls5RbBRTk3zv7tyJDUnv28FwiRJyQBIB6HXIllSFJ07qL+R7te\n\tDpbDEQdjqyZVru4jkfD9rsHjOirvR4PcjTySaV1nSgFSE2o8S0Wy7yFFR6pTqwU+Gngk\n\tpRAP6c+oc5u75PF3CFlSA5I2/S1AxbOKI+2DDCNnP6zSBwrJR+x+DIdiyxTVN8i+AraM\n\tfjbQ=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"EEwzrJfl\"; dkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=vwDaES6dhbej3HqHxgtDOibtwCuqve0Ja+S6krTxfk8=;\n\tb=SvjYnWbhJxmD7SFAkm3GpL60kppHiBhSw9pJd+hnDKrWc8FBlGGVuIve3VT0xyIcPo\n\tf5NdRs/pknRjWxrtqObT+HJoRsLJjJeplnT+o6d9MxgKjem2GQKeCs/Fq1NrK5sFNhI3\n\t6IG8QGnyzxJO12UZ62C5deHqn2pf+RSMaZ8DT6k3xUupM9iISjOqsoxaFTn90qyWkKq7\n\t6FCxfbVNb13kg5kGnXfjtVQyQt7oLlBwFEB3VUrOkESrKj9Nm8CuKCTxJrOvAZgw5ATh\n\t2zar8FDZWtfAEIdgzFEAmM6SV1ZBKH6KuihDF6VzfxakChmgmZ9yf6DvCpOn9rwU2hKP\n\tRDCQ==",
        "X-Gm-Message-State": "ACgBeo1ahuPxvvjxPUzf5FDpObGgF2qNBshzNXLaYLfsYDoV9Zz8ZpTw\n\t+oSH9eeyTg4PbAHO2OVESicgYqU7A3tOPg==",
        "X-Google-Smtp-Source": "AA6agR4dTO/evt/Ti8xHwDGhm5r9+uboquPMqsiak7cOdyBfin5IG5TP0mLFrPjaIs6t4e/kCi1eow==",
        "X-Received": "by 2002:a17:903:22c1:b0:16f:3d1:f5c with SMTP id\n\ty1-20020a17090322c100b0016f03d10f5cmr27381198plg.155.1660757168306; \n\tWed, 17 Aug 2022 10:26:08 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 17 Aug 2022 22:55:41 +0530",
        "Message-Id": "<20220817172541.72339-2-rishikeshdonadkar@gmail.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20220817172541.72339-1-rishikeshdonadkar@gmail.com>",
        "References": "<20220817172541.72339-1-rishikeshdonadkar@gmail.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 1/1] gstreamer: Provide mulitple\n\tcolorimetry support",
        "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>",
        "From": "Rishikesh Donadkar via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Rishikesh Donadkar <rishikeshdonadkar@gmail.com>",
        "Cc": "Rishikesh Donadkar <rishikeshdonadkar@gmail.com>,\n\tnicolas.dufresne@collabora.com, vedantparanjape160201@gmail.com",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Iterate over each GValue in the colorimetry list,\nretrieve the colorimetry string, convert to colorspace using the\nfunction colorspace_from_colorimetry() and validate the camera configuration.\nRetrieve the colorspace after validation, convert to colorimetry and\ncheck if the it is same as the colorimetry requested.\n\nIf none of the colorimetry requested is supported by the camera (i.e. not\nthe same after validation) then set the stream_cfg to the previous\nconfiguration that was present before trying new colorimetry.\n\nSigned-off-by: Rishikesh Donadkar <rishikeshdonadkar@gmail.com>\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n src/gstreamer/gstlibcamera-utils.cpp | 75 +++++++++++++++++++++-------\n src/gstreamer/gstlibcamera-utils.h   |  4 +-\n src/gstreamer/gstlibcamerasrc.cpp    |  2 +-\n 3 files changed, 62 insertions(+), 19 deletions(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nindex d895a67d..2a88444c 100644\n--- a/src/gstreamer/gstlibcamera-utils.cpp\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -302,13 +302,39 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg\n \treturn caps;\n }\n \n+static int\n+configure_colorspace_from_caps(StreamConfiguration &stream_cfg,\n+\t\t\t       const gchar *colorimetry_str)\n+{\n+\tgint colorimetry_valid = 1, colorimetry_invalid = 0;\n+\tif (colorimetry_str) {\n+\t\tGstVideoColorimetry colorimetry;\n+\n+\t\tif (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str)) {\n+\t\t\tg_critical(\"Invalid colorimetry %s\", colorimetry_str);\n+\t\t\treturn colorimetry_invalid;\n+\t\t}\n+\n+\t\tstream_cfg.colorSpace = colorspace_from_colorimetry(colorimetry);\n+\t\t/* Check if colorimetry had any identifiers which did not map */\n+\t\tif (colorimetry.primaries != GST_VIDEO_COLOR_PRIMARIES_UNKNOWN &&\n+\t\t    stream_cfg.colorSpace == ColorSpace::Raw) {\n+\t\t\tGST_ERROR(\"One or more identifiers could not be mapped for %s colorimetry\",\n+\t\t\t\t  colorimetry_str);\n+\t\t\tstream_cfg.colorSpace = std::nullopt;\n+\t\t}\n+\t}\n+\treturn colorimetry_valid;\n+}\n+\n void\n-gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n+gst_libcamera_configure_stream_from_caps(std::unique_ptr<CameraConfiguration> &cam_cfg,\n+\t\t\t\t\t StreamConfiguration &stream_cfg,\n \t\t\t\t\t GstCaps *caps)\n {\n \tGstVideoFormat gst_format = pixel_format_to_gst_format(stream_cfg.pixelFormat);\n \tguint i;\n-\tgint best_fixed = -1, best_in_range = -1;\n+\tgint best_fixed = -1, best_in_range = -1, ret;\n \tGstStructure *s;\n \n \t/*\n@@ -381,23 +407,38 @@ gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n \tstream_cfg.size.width = width;\n \tstream_cfg.size.height = height;\n \n-\t/* Configure colorimetry */\n-\tif (gst_structure_has_field(s, \"colorimetry\")) {\n-\t\tconst gchar *colorimetry_str = gst_structure_get_string(s, \"colorimetry\");\n-\t\tGstVideoColorimetry colorimetry;\n-\n-\t\tif (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str))\n-\t\t\tg_critical(\"Invalid colorimetry %s\", colorimetry_str);\n-\n-\t\tstream_cfg.colorSpace = colorspace_from_colorimetry(colorimetry);\n-\t\t/* Check if colorimetry had any identifiers which did not map */\n-\t\tif (colorimetry.primaries != GST_VIDEO_COLOR_PRIMARIES_UNKNOWN &&\n-\t\t    stream_cfg.colorSpace == ColorSpace::Raw) {\n-\t\t\tGST_ERROR(\"One or more identifiers could not be mapped for %s colorimetry\",\n-\t\t\t\t  colorimetry_str);\n-\t\t\tstream_cfg.colorSpace = std::nullopt;\n+\tconst GValue *colorimetry = gst_structure_get_value(s, \"colorimetry\");\n+\tif (!colorimetry)\n+\t\treturn;\n+\n+\t/* Configure Colorimetry */\n+\tif (GST_VALUE_HOLDS_LIST(colorimetry)) {\n+\t\tStreamConfiguration pristine_stream_cfg = stream_cfg;\n+\t\tfor (i = 0; i < gst_value_list_get_size(colorimetry); i++) {\n+\t\t\tconst GValue *val = gst_value_list_get_value(colorimetry, i);\n+\t\t\tGstVideoColorimetry colorimetry_old, colorimetry_new;\n+\n+\t\t\tret = configure_colorspace_from_caps(stream_cfg, g_value_get_string(val));\n+\t\t\tif (!ret)\n+\t\t\t\tcontinue;\n+\n+\t\t\tcolorimetry_old = colorimetry_from_colorspace(stream_cfg.colorSpace.value());\n+\n+\t\t\t/* Validate the configuration and check if the requested\n+\t\t\t * colorimetry can be applied to the sensor.\n+\t\t\t */\n+\t\t\tif (cam_cfg->validate() != CameraConfiguration::Invalid) {\n+\t\t\t\tcolorimetry_new = colorimetry_from_colorspace(stream_cfg.colorSpace.value());\n+\t\t\t\tif (gst_video_colorimetry_is_equal(&colorimetry_old, &colorimetry_new)) {\n+\t\t\t\t\tg_print(\"Selected colorimetry %s\\n\", gst_video_colorimetry_to_string(&colorimetry_new));\n+\t\t\t\t\tbreak;\n+\t\t\t\t} else\n+\t\t\t\t\tstream_cfg = pristine_stream_cfg;\n+\t\t\t}\n \t\t}\n \t}\n+\tif (G_VALUE_TYPE(colorimetry) == G_TYPE_STRING)\n+\t\tconfigure_colorspace_from_caps(stream_cfg, g_value_get_string(colorimetry));\n }\n \n #if !GST_CHECK_VERSION(1, 17, 1)\ndiff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h\nindex 164189a2..7afad576 100644\n--- a/src/gstreamer/gstlibcamera-utils.h\n+++ b/src/gstreamer/gstlibcamera-utils.h\n@@ -8,6 +8,7 @@\n \n #pragma once\n \n+#include <libcamera/camera.h>\n #include <libcamera/camera_manager.h>\n #include <libcamera/stream.h>\n \n@@ -16,7 +17,8 @@\n \n GstCaps *gst_libcamera_stream_formats_to_caps(const libcamera::StreamFormats &formats);\n GstCaps *gst_libcamera_stream_configuration_to_caps(const libcamera::StreamConfiguration &stream_cfg);\n-void gst_libcamera_configure_stream_from_caps(libcamera::StreamConfiguration &stream_cfg,\n+void gst_libcamera_configure_stream_from_caps(std::unique_ptr<libcamera::CameraConfiguration> &cam_cfg,\n+\t\t\t\t\t      libcamera::StreamConfiguration &stream_cfg,\n \t\t\t\t\t      GstCaps *caps);\n #if !GST_CHECK_VERSION(1, 17, 1)\n gboolean gst_task_resume(GstTask *task);\ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex 16d70fea..25059914 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -503,7 +503,7 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,\n \n \t\t/* Fixate caps and configure the stream. */\n \t\tcaps = gst_caps_make_writable(caps);\n-\t\tgst_libcamera_configure_stream_from_caps(stream_cfg, caps);\n+\t\tgst_libcamera_configure_stream_from_caps(state->config_, stream_cfg, caps);\n \t}\n \n \tif (flow_ret != GST_FLOW_OK)\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "1/1"
    ]
}