Patch Detail
Show a patch.
GET /api/patches/17041/?format=api
{ "id": 17041, "url": "https://patchwork.libcamera.org/api/patches/17041/?format=api", "web_url": "https://patchwork.libcamera.org/patch/17041/", "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": "<20220809143531.7473-3-rishikeshdonadkar@gmail.com>", "date": "2022-08-09T14:35:31", "name": "[libcamera-devel,v2,2/2] gstreamer: Add multiple colorimetry support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "be9be65fed7a8b9c1bf7cb40a7a507fa19ac7d26", "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/17041/mbox/", "series": [ { "id": 3396, "url": "https://patchwork.libcamera.org/api/series/3396/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3396", "date": "2022-08-09T14:35:29", "name": "Multiple colorimetry support for libcamerasrc.", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3396/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/17041/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/17041/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 EF8E4C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 9 Aug 2022 14:36:26 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AAC3863326;\n\tTue, 9 Aug 2022 16:36:26 +0200 (CEST)", "from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com\n\t[IPv6:2607:f8b0:4864:20::102f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0732A63326\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 9 Aug 2022 16:36:25 +0200 (CEST)", "by mail-pj1-x102f.google.com with SMTP id\n\tw11-20020a17090a380b00b001f73f75a1feso6981206pjb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 09 Aug 2022 07:36:24 -0700 (PDT)", "from localhost.localdomain ([49.36.99.220])\n\tby smtp.googlemail.com with ESMTPSA id\n\th12-20020a17090ac38c00b001f4fb21c11asm10269264pjt.21.2022.08.09.07.36.20\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 09 Aug 2022 07:36:23 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660055786;\n\tbh=T0WmI2RWLr2c6dBiNrTdJ4MTRV+QU5vFXoEu5EEgxBs=;\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=s/zaw+dvJpx0JImHOqX28ogYeQSXxpP4GKbyl4kTLmtlVWUsWzIsTHxi5e3P7m/KY\n\tH5eQFynZHZSVJfSb2Q3GJskwamLYKPjP98JcDJ3+k40e/TAz7IKkqh8HzTI1Yk7X0S\n\tx4zF/7FHzTubtxxOoc41mxfTEBRolgSbY+ZTz5YS13SjpooPCivCwtGs7F9xnvozFj\n\tA1w0O4FRVL7FpOfgd9f5WlZTbt8LccML0h1ifraZYI1yD3ZDsXnCWtKy4rH5RbbBC+\n\tbMZVtbtqJ5eLgSOJhuGpqPcIHqyLzoBjvEhC8+w9FbF2w9+7WQQvi17ZpNgVwdJRAD\n\tiEzfcskeQ77qw==", "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=3w3bA9gQ8JT3rGEZQtYRbMOQfEpMY/08pD8JogJ972M=;\n\tb=MaUYhful8PdKqsAHkLoW/w031SD/VvcBfeCUmQdcp/SaGCevl0LMT9mo3Aog4EPSrZ\n\tUpZHTFXSNChUEtJWmEMv/TAO171QGXafPjJ5OLe5/BGVro5LeuAvRz3jc0dBswY2VSOn\n\t7dfjydR+VUfAEdyzZlyZhhUUmgecs/r+aY1tVymn3BiW/HJJ4z7FiHI4AYjVCLiY31o9\n\t4LM541stl6Sw+vGkgO9oXQ0QtJRWss7FKPtctSFR/YrUtASkMsKfLxya2U8ra+os6YQD\n\tHAtGj7VtgGw+pk5M7AfvJbtNv41VGAgsY3b/s76RlPnr3C57McjFHQAgscJT9CotcQci\n\t3fSA==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"MaUYhful\"; 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=3w3bA9gQ8JT3rGEZQtYRbMOQfEpMY/08pD8JogJ972M=;\n\tb=EWAF09JpcBFVYuGEEZj8ljOEaCz0wvQTUQEfoLvISxIwOTNeOPMPuhcGnhK5l4F+RG\n\tPzzo9CtmsFsoCRL/EDDKXrDACvx6Q/e7Zd3ha3Bxws4Nzdd1Vstw76K5B05JvqXPJDzW\n\twzpTeneXkkXUIUQsDpgQyYecV/JufvdCMVMbK1JYCLiflqMAAB8C+rSIpb2vXnuE/Mt0\n\tD0l6Umm0+XDJf7S+rNFQDmPAMrGxWOoFfuwaUyizocZMn8rAvcZPJzhOH/loNcvolefp\n\tgpqg9Mmk3koAJ0t2vsVkg44auQe1VTZrPE+jWyfxaX3qDLqmtkPHymzkLYzYbSSCkSIE\n\tEM3Q==", "X-Gm-Message-State": "ACgBeo0LefRmd2hGURGMDSPIvSzQjMS2A+eF8A3xS1ULyYUE84uIQ9H/\n\t9H4BcKSQbkmjWvNIPEMV1qnptCARPtLMiiXa", "X-Google-Smtp-Source": "AA6agR5+xHt/bgRsE6pLfqn+qRCwhrN4SrtSXTF4bXfaGD03Zacnh4T74y1Q7usPPTQb3NzBf7sVTA==", "X-Received": "by 2002:a17:90b:4c12:b0:1f5:958:c313 with SMTP id\n\tna18-20020a17090b4c1200b001f50958c313mr35038462pjb.6.1660055783288; \n\tTue, 09 Aug 2022 07:36:23 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 9 Aug 2022 20:05:31 +0530", "Message-Id": "<20220809143531.7473-3-rishikeshdonadkar@gmail.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20220809143531.7473-1-rishikeshdonadkar@gmail.com>", "References": "<20220809143531.7473-1-rishikeshdonadkar@gmail.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 2/2] gstreamer: Add multiple\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": "This patch provides the following:\n- Add support to handle colorimetry in the GStreamer->libcamera\n direction.\n- Add support for multiple colorimetry.\n\nThe function colorspace_from_colorimetry() takes in a\nGstVideoColorimetry and returns libcamera::ColorSpace\n\nAppend 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 | 152 ++++++++++++++++++++++++++-\n src/gstreamer/gstlibcamera-utils.h | 4 +-\n src/gstreamer/gstlibcamerasrc.cpp | 3 +-\n 3 files changed, 153 insertions(+), 6 deletions(-)", "diff": "diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nindex dbb47c5a..078b9343 100644\n--- a/src/gstreamer/gstlibcamera-utils.cpp\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -104,6 +104,93 @@ colorimetry_from_colorspace(const ColorSpace &colorSpace)\n \treturn colorimetry;\n }\n \n+static ColorSpace\n+colorspace_from_colorimetry(const GstVideoColorimetry &colorimetry)\n+{\n+\tColorSpace colorspace = ColorSpace::Raw;\n+\n+\tswitch (colorimetry.primaries) {\n+\tcase GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:\n+\t\t/* Unknown primaries map to raw colorspace in GStreamer */\n+\t\treturn ColorSpace::Raw;\n+\tcase GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:\n+\t\tcolorspace.primaries = ColorSpace::Primaries::Smpte170m;\n+\t\tbreak;\n+\tcase GST_VIDEO_COLOR_PRIMARIES_BT709:\n+\t\tcolorspace.primaries = ColorSpace::Primaries::Rec709;\n+\t\tbreak;\n+\tcase GST_VIDEO_COLOR_PRIMARIES_BT2020:\n+\t\tcolorspace.primaries = ColorSpace::Primaries::Rec2020;\n+\t\tbreak;\n+\tdefault:\n+\t\tGST_WARNING(\"Colorimetry primaries %d not mapped in gstlibcamera\",\n+\t\t\t colorimetry.primaries);\n+\t\treturn ColorSpace::Raw;\n+\t}\n+\n+\tswitch (colorimetry.transfer) {\n+\t/* Transfer function mappings inspired from v4l2src plugin */\n+\tcase GST_VIDEO_TRANSFER_GAMMA18:\n+\tcase GST_VIDEO_TRANSFER_GAMMA20:\n+\tcase GST_VIDEO_TRANSFER_GAMMA22:\n+\tcase GST_VIDEO_TRANSFER_GAMMA28:\n+\t\tGST_WARNING(\"GAMMA 18, 20, 22, 28 transfer functions not supported\");\n+\t/* fallthrough */\n+\tcase GST_VIDEO_TRANSFER_GAMMA10:\n+\t\tcolorspace.transferFunction = ColorSpace::TransferFunction::Linear;\n+\t\tbreak;\n+\tcase GST_VIDEO_TRANSFER_SRGB:\n+\t\tcolorspace.transferFunction = ColorSpace::TransferFunction::Srgb;\n+\t\tbreak;\n+\tcase GST_VIDEO_TRANSFER_BT601:\n+\tcase GST_VIDEO_TRANSFER_BT2020_12:\n+\tcase GST_VIDEO_TRANSFER_BT2020_10:\n+\tcase GST_VIDEO_TRANSFER_BT709:\n+\t\tcolorspace.transferFunction = ColorSpace::TransferFunction::Rec709;\n+\t\tbreak;\n+\tdefault:\n+\t\tGST_WARNING(\"Colorimetry transfer function %d not mapped in gstlibcamera\",\n+\t\t\t colorimetry.transfer);\n+\t\treturn ColorSpace::Raw;\n+\t}\n+\n+\tswitch (colorimetry.matrix) {\n+\tcase GST_VIDEO_COLOR_MATRIX_RGB:\n+\t\tcolorspace.ycbcrEncoding = ColorSpace::YcbcrEncoding::None;\n+\t\tbreak;\n+\t/* FCC is about the same as BT601 with less digits */\n+\tcase GST_VIDEO_COLOR_MATRIX_FCC:\n+\tcase GST_VIDEO_COLOR_MATRIX_BT601:\n+\t\tcolorspace.ycbcrEncoding = ColorSpace::YcbcrEncoding::Rec601;\n+\t\tbreak;\n+\tcase GST_VIDEO_COLOR_MATRIX_BT709:\n+\t\tcolorspace.ycbcrEncoding = ColorSpace::YcbcrEncoding::Rec709;\n+\t\tbreak;\n+\tcase GST_VIDEO_COLOR_MATRIX_BT2020:\n+\t\tcolorspace.ycbcrEncoding = ColorSpace::YcbcrEncoding::Rec2020;\n+\t\tbreak;\n+\tdefault:\n+\t\tGST_WARNING(\"Colorimetry matrix %d not mapped in gstlibcamera\",\n+\t\t\t colorimetry.matrix);\n+\t\treturn ColorSpace::Raw;\n+\t}\n+\n+\tswitch (colorimetry.range) {\n+\tcase GST_VIDEO_COLOR_RANGE_0_255:\n+\t\tcolorspace.range = ColorSpace::Range::Full;\n+\t\tbreak;\n+\tcase GST_VIDEO_COLOR_RANGE_16_235:\n+\t\tcolorspace.range = ColorSpace::Range::Limited;\n+\t\tbreak;\n+\tdefault:\n+\t\tGST_WARNING(\"Colorimetry range %d not mapped in gstlibcamera\",\n+\t\t\t colorimetry.range);\n+\t\treturn ColorSpace::Raw;\n+\t}\n+\n+\treturn colorspace;\n+}\n+\n static GstVideoFormat\n pixel_format_to_gst_format(const PixelFormat &format)\n {\n@@ -215,13 +302,47 @@ 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+static gboolean\n+check_colorspace(const ColorSpace colorSpace, const gchar *colorimetry_old)\n+{\n+\tGstVideoColorimetry colorimetry = colorimetry_from_colorspace(colorSpace);\n+\tg_autofree gchar *colorimetry_new = gst_video_colorimetry_to_string(&colorimetry);\n+\tif (!g_strcmp0(colorimetry_old, colorimetry_new)) {\n+\t\treturn true;\n+\t}\n+\treturn false;\n+}\n+\n void\n-gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n+gst_libcamera_configure_stream_from_caps(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@@ -267,10 +388,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@@ -293,6 +417,26 @@ gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n \tgst_structure_get_int(s, \"height\", &height);\n \tstream_cfg.size.width = width;\n \tstream_cfg.size.height = height;\n+\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 dup_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\tconfigure_colorspace_from_caps(stream_cfg, ns);\n+\t\tg_autofree const gchar *colorimetry_old = gst_structure_get_string(ns, \"colorimetry\");\n+\t\tif (cam_cfg.validate() != CameraConfiguration::Invalid) {\n+\t\t\tif (check_colorspace(stream_cfg.colorSpace.value(), colorimetry_old))\n+\t\t\t\tbreak;\n+\t\t\telse\n+\t\t\t\tstream_cfg = dup_stream_cfg;\n+\t\t}\n+\t}\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..90be6abe 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(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..3617170e 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -492,6 +492,7 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,\n \tfor (gsize i = 0; i < state->srcpads_.size(); i++) {\n \t\tGstPad *srcpad = state->srcpads_[i];\n \t\tStreamConfiguration &stream_cfg = state->config_->at(i);\n+\t\tCameraConfiguration &cam_cfg = *(state->config_);\n \n \t\t/* Retrieve the supported caps. */\n \t\tg_autoptr(GstCaps) filter = gst_libcamera_stream_formats_to_caps(stream_cfg.formats());\n@@ -503,7 +504,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(cam_cfg, stream_cfg, caps);\n \t}\n \n \tif (flow_ret != GST_FLOW_OK)\n", "prefixes": [ "libcamera-devel", "v2", "2/2" ] }