Patch Detail
Show a patch.
GET /api/patches/17124/?format=api
{ "id": 17124, "url": "https://patchwork.libcamera.org/api/patches/17124/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17124/", "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": "<20220815133105.15025-2-rishikeshdonadkar@gmail.com>", "date": "2022-08-15T13:31:05", "name": "[libcamera-devel,v3,1/1] gstreamer: Provide mulitple colorimetry support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "625b2e872f649e7d38b670eef327cb6170b57693", "submitter": { "id": 118, "url": "https://patchwork.libcamera.org/api/people/118/?format=api", "name": "Rishikesh Donadkar", "email": "rishikeshdonadkar@gmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/17124/mbox/", "series": [ { "id": 3416, "url": "https://patchwork.libcamera.org/api/series/3416/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3416", "date": "2022-08-15T13:31:04", "name": "Multiple colorimetry support for libcamerasrc.", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3416/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17124/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17124/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 19A95BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 15 Aug 2022 13:31:33 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAC3D61FC3;\n\tMon, 15 Aug 2022 15:31:32 +0200 (CEST)", "from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com\n\t[IPv6:2607:f8b0:4864:20::102a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DFEB461FBC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Aug 2022 15:31:31 +0200 (CEST)", "by mail-pj1-x102a.google.com with SMTP id\n\tc19-20020a17090ae11300b001f2f94ed5c6so11717881pjz.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 15 Aug 2022 06:31:31 -0700 (PDT)", "from localhost.localdomain ([49.36.101.94])\n\tby smtp.googlemail.com with ESMTPSA id\n\te3-20020aa798c3000000b00528bd940390sm6532068pfm.153.2022.08.15.06.31.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 15 Aug 2022 06:31:29 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660570292;\n\tbh=c4HDZss6r6Z017pyvGPJh1FOWQpdILDMYB9Q6/vtoE8=;\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=ZUSdawBRtbilq5oBT7NGtZmEEj2VID7hJcPJ5Y+6RdG6pVIPMPlsJc/p6MCKlZ1Ln\n\t7goFQN/jDC1e7sD+6lfkKzfhNEH5GUNYe8CmmzsJaZEzHf7KcC+8GwUAuu1hkFIG6n\n\t5rOIzlm8K2k+a8zHMKauqcX8RwXCEc3iBdAQo1+I/VYhloBWvysQ6ReNVzYR2dLcb5\n\tyBd8RXPGUt0+dsDBsDAzcZKhrFdqDYxyzLMFcXo33pVaj2+Qz54b6HauHIXyZTrx/d\n\tJ0CYgsqAj9XFU+unjQwg3ZPfDEgAgq60azmy8T9f6SZFv6I/a4p/Xyhe3tfjybZUsO\n\tEx4pdCWNyL9Ww==", "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=81Vs4Wg2AgP5FQLrkdCpH+GBIE+AopgMo3UgBS5G8fM=;\n\tb=C4Jn1coaDqnBCYFFaOxLcSlzPA7Mhzn+EXqecLW4vkniBGpye/i2LHt/E0WcVAxffz\n\t9rcaSz3HUguYLlD0M0+mIxWbqT72LiWOzhm7W2BZxJyW594iZKZ0Wgdf0tIrnbZS9GVx\n\tC0+MUwKAdWtRErTCdobim6bnhAMo3e/lhiVuhup/4NY8J0elB40d2weO8M/yyuWu+DyD\n\tsT9muAfw1+Fsw71N708Ux9MkuSOu2kpAWXNItnTAjeJ7PeKhur/f0TudNjrG+R9zPzTw\n\tJ1wqogXNnWIbcHpthDpYzuRvMGL43NCnTwRLuAYZ+FlDR+16k1bdOL6U6FgbdN/gtVAR\n\tcBvA==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"C4Jn1coa\"; 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=81Vs4Wg2AgP5FQLrkdCpH+GBIE+AopgMo3UgBS5G8fM=;\n\tb=xbjV25iayRoLaqX3W33cUTu7V9oVFv46Eqd3zLkPUp/PuW2jwiano1yQMNvVtIXT5h\n\tpZ2307Fo4asO/YQUyADxgzFdTnA6CbcB08q8Y0Rg0EkWwbzFVvXAmRxIFMfIIFmFTn95\n\t4dByGxreYH0Ur/rgamVQMZP8sw/V9rq6X5mgdaQ3kA7IsBfwboXK1kB+Xy8fLi+dmfts\n\tI/CutqwRbzvofNjxoySHtyvLF2XbhWLsPQyxIjS1DZtpDS7WMsw1HAx25ys1MU7JPF7z\n\tYzvt5u8uGK0/Do9JWpWdcN/7J8LcILjsIQOeIOqulNMosfZsMxAuufNQ9IHbkXr7kcy8\n\tfv7A==", "X-Gm-Message-State": "ACgBeo031O7T1V9MzU41CEvBJGhx+C4XCq6Q5bYeUe7EebArQKB6pc/n\n\tgMh6UmgVJQY5Ve/lCntBImHDLmZI3YXD/A==", "X-Google-Smtp-Source": "AA6agR4f1/gh894DxyVmC0irdAy6XJaAJ0UYkisPo7bv/y0494UnrDKrWdGuHStzO9ULKCwUFTlC6g==", "X-Received": "by 2002:a17:902:ecc8:b0:16f:9355:c103 with SMTP id\n\ta8-20020a170902ecc800b0016f9355c103mr17345232plh.122.1660570290273; \n\tMon, 15 Aug 2022 06:31:30 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 15 Aug 2022 19:01:05 +0530", "Message-Id": "<20220815133105.15025-2-rishikeshdonadkar@gmail.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20220815133105.15025-1-rishikeshdonadkar@gmail.com>", "References": "<20220815133105.15025-1-rishikeshdonadkar@gmail.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 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": "Append copy of the structure with best suitable resolution into a\nfresh new caps and normalize the caps using gst_caps_normalize().\nThis will return caps where the colorimetry list is expanded.\nThe ncaps will contain as many structures as the number of\ncolorimetry specified in the GStreamer pipeline.\n\nIterate over each structure in the ncaps, retrieve the colorimetry string,\nconvert to colorspace using the function colorspace_from_colorimetry()\nand validate the camera configuration. Retrieve the colorspace after\nvalidation, convert to colorimetry and check if the it is same as\nthe 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 | 73 ++++++++++++++++++++--------\n src/gstreamer/gstlibcamera-utils.h | 4 +-\n src/gstreamer/gstlibcamerasrc.cpp | 2 +-\n 3 files changed, 58 insertions(+), 21 deletions(-)", "diff": "diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nindex d895a67d..5dc3efcf 100644\n--- a/src/gstreamer/gstlibcamera-utils.cpp\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -302,13 +302,36 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg\n \treturn caps;\n }\n \n+static void\n+configure_colorspace_from_caps(StreamConfiguration &stream_cfg,\n+\t\t\t GstStructure *s)\n+{\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+\t\t}\n+\t}\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, colorimetry_index = -1;\n \tGstStructure *s;\n \n \t/*\n@@ -354,10 +377,13 @@ gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n \t}\n \n \t/* Prefer reliable fixed value over ranges */\n-\tif (best_fixed >= 0)\n+\tif (best_fixed >= 0) {\n \t\ts = gst_caps_get_structure(caps, best_fixed);\n-\telse\n+\t\tcolorimetry_index = best_fixed;\n+\t} else {\n \t\ts = gst_caps_get_structure(caps, best_in_range);\n+\t\tcolorimetry_index = best_in_range;\n+\t}\n \n \tif (gst_structure_has_name(s, \"video/x-raw\")) {\n \t\tconst gchar *format = gst_video_format_to_string(gst_format);\n@@ -381,21 +407,30 @@ 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+\t/* Create new caps, copy the structure with best resolutions\n+\t * and normalize the caps.\n+\t */\n+\tGstCaps *ncaps = gst_caps_copy_nth(caps, colorimetry_index);\n+\tncaps = gst_caps_normalize(ncaps);\n+\n+\t/* Configure Colorimetry */\n+\tStreamConfiguration pristine_stream_cfg = stream_cfg;\n+\tfor (i = 0; i < gst_caps_get_size(ncaps); i++) {\n+\t\tGstStructure *ns = gst_caps_get_structure(ncaps, i);\n+\t\tGstVideoColorimetry colorimetry_old, colorimetry_new;\n+\t\tcolorimetry_old = colorimetry_from_colorspace(stream_cfg.colorSpace.value());\n+\t\tconfigure_colorspace_from_caps(stream_cfg, ns);\n+\n+\t\t/* Validate the configuration and check if the requested\n+\t\t * colorimetry can be applied to the sensor.\n+\t\t */\n+\t\tif (cam_cfg->validate() != CameraConfiguration::Invalid) {\n+\t\t\tcolorimetry_new = colorimetry_from_colorspace(stream_cfg.colorSpace.value());\n+\t\t\tif (gst_video_colorimetry_is_equal(&colorimetry_old,&colorimetry_new)) {\n+\t\t\t\tg_print(\"Selected colorimetry %s\\n\", gst_video_colorimetry_to_string(&colorimetry_new));\n+\t\t\t\tbreak;\n+\t\t\t} else\n+\t\t\t\tstream_cfg = pristine_stream_cfg;\n \t\t}\n \t}\n }\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", "v3", "1/1" ] }