From patchwork Wed Aug 17 17:25:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 17144 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C3A38BE173 for ; Wed, 17 Aug 2022 17:26:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 77D4A61FC3; Wed, 17 Aug 2022 19:26:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660757171; bh=0IeUkll8r/dmyymZcyKf7gyPTv8BgndMCkleyHzhbto=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=IwoLeFQmgihHHbuFazjQd2X783SaQ3TEOTVkY7abeiPLpi3j3l794P3WLnmTTiszB dUlH1w91MFao6J2bBQJn4gKKTDs9++6fOOJfZCBfDLGTmb6RFptwhRG9yh1TKwN7uE 5xICk4qROEJcqkLF+zuYo29S/BFmpiyE41qmM09Cd2KIVS42le9Ffkvh4dB21e/dTO uBzhgxBJ08gNOcFUTMF40DUteZmEpOi5SffJlEBtMHexH4E3YtSXsUGioPTHpGLr7r fk4EwPgexCWoU5/adcapOliRYzXPiXSZLLqoUssR3/Lz/0cRLMmdmtY2LnyQ3eGeuf 1FyxxEvvHMZiA== Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E875F61FA8 for ; Wed, 17 Aug 2022 19:26:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EEwzrJfl"; dkim-atps=neutral Received: by mail-pj1-x1032.google.com with SMTP id s5-20020a17090a13c500b001f4da9ffe5fso2428696pjf.5 for ; Wed, 17 Aug 2022 10:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=vwDaES6dhbej3HqHxgtDOibtwCuqve0Ja+S6krTxfk8=; b=EEwzrJflNojn6jTAaMtLre9KfozIkeWdSp+oJtZHg67AWo4mgftWC3JVGnu4SvOdw/ +/IVCnR6baIPxe8g2pizusMsQ6wGnfNwfn14RfGibxhu5akhuBP+cKmi8geIZ/mRMTFd FXO3t26ZFICvC8byUXls5RbBRTk3zv7tyJDUnv28FwiRJyQBIB6HXIllSFJ07qL+R7te DpbDEQdjqyZVru4jkfD9rsHjOirvR4PcjTySaV1nSgFSE2o8S0Wy7yFFR6pTqwU+Gngk pRAP6c+oc5u75PF3CFlSA5I2/S1AxbOKI+2DDCNnP6zSBwrJR+x+DIdiyxTVN8i+AraM fjbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=vwDaES6dhbej3HqHxgtDOibtwCuqve0Ja+S6krTxfk8=; b=SvjYnWbhJxmD7SFAkm3GpL60kppHiBhSw9pJd+hnDKrWc8FBlGGVuIve3VT0xyIcPo f5NdRs/pknRjWxrtqObT+HJoRsLJjJeplnT+o6d9MxgKjem2GQKeCs/Fq1NrK5sFNhI3 6IG8QGnyzxJO12UZ62C5deHqn2pf+RSMaZ8DT6k3xUupM9iISjOqsoxaFTn90qyWkKq7 6FCxfbVNb13kg5kGnXfjtVQyQt7oLlBwFEB3VUrOkESrKj9Nm8CuKCTxJrOvAZgw5ATh 2zar8FDZWtfAEIdgzFEAmM6SV1ZBKH6KuihDF6VzfxakChmgmZ9yf6DvCpOn9rwU2hKP RDCQ== X-Gm-Message-State: ACgBeo1ahuPxvvjxPUzf5FDpObGgF2qNBshzNXLaYLfsYDoV9Zz8ZpTw +oSH9eeyTg4PbAHO2OVESicgYqU7A3tOPg== X-Google-Smtp-Source: AA6agR4dTO/evt/Ti8xHwDGhm5r9+uboquPMqsiak7cOdyBfin5IG5TP0mLFrPjaIs6t4e/kCi1eow== X-Received: by 2002:a17:903:22c1:b0:16f:3d1:f5c with SMTP id y1-20020a17090322c100b0016f03d10f5cmr27381198plg.155.1660757168306; Wed, 17 Aug 2022 10:26:08 -0700 (PDT) Received: from localhost.localdomain ([49.36.99.40]) by smtp.googlemail.com with ESMTPSA id j5-20020a170902da8500b0016be834d54asm142071plx.306.2022.08.17.10.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 10:26:07 -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 Subject: [libcamera-devel] [PATCH v4 1/1] gstreamer: Provide mulitple colorimetry support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Rishikesh Donadkar via libcamera-devel From: Rishikesh Donadkar Reply-To: Rishikesh Donadkar Cc: Rishikesh Donadkar , nicolas.dufresne@collabora.com, vedantparanjape160201@gmail.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Iterate over each GValue in the colorimetry list, retrieve the colorimetry string, convert to colorspace using the function colorspace_from_colorimetry() and validate the camera configuration. Retrieve the colorspace after validation, convert to colorimetry and check if the it is same as the colorimetry requested. If none of the colorimetry requested is supported by the camera (i.e. not the same after validation) then set the stream_cfg to the previous configuration that was present before trying new colorimetry. Signed-off-by: Rishikesh Donadkar Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamera-utils.cpp | 75 +++++++++++++++++++++------- src/gstreamer/gstlibcamera-utils.h | 4 +- src/gstreamer/gstlibcamerasrc.cpp | 2 +- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index d895a67d..2a88444c 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -302,13 +302,39 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg return caps; } +static int +configure_colorspace_from_caps(StreamConfiguration &stream_cfg, + const gchar *colorimetry_str) +{ + gint colorimetry_valid = 1, colorimetry_invalid = 0; + if (colorimetry_str) { + GstVideoColorimetry colorimetry; + + if (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str)) { + g_critical("Invalid colorimetry %s", colorimetry_str); + return colorimetry_invalid; + } + + stream_cfg.colorSpace = colorspace_from_colorimetry(colorimetry); + /* Check if colorimetry had any identifiers which did not map */ + if (colorimetry.primaries != GST_VIDEO_COLOR_PRIMARIES_UNKNOWN && + stream_cfg.colorSpace == ColorSpace::Raw) { + GST_ERROR("One or more identifiers could not be mapped for %s colorimetry", + colorimetry_str); + stream_cfg.colorSpace = std::nullopt; + } + } + return colorimetry_valid; +} + void -gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg, +gst_libcamera_configure_stream_from_caps(std::unique_ptr &cam_cfg, + StreamConfiguration &stream_cfg, GstCaps *caps) { GstVideoFormat gst_format = pixel_format_to_gst_format(stream_cfg.pixelFormat); guint i; - gint best_fixed = -1, best_in_range = -1; + gint best_fixed = -1, best_in_range = -1, ret; GstStructure *s; /* @@ -381,23 +407,38 @@ gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg, stream_cfg.size.width = width; stream_cfg.size.height = height; - /* Configure colorimetry */ - if (gst_structure_has_field(s, "colorimetry")) { - const gchar *colorimetry_str = gst_structure_get_string(s, "colorimetry"); - GstVideoColorimetry colorimetry; - - if (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str)) - g_critical("Invalid colorimetry %s", colorimetry_str); - - stream_cfg.colorSpace = colorspace_from_colorimetry(colorimetry); - /* Check if colorimetry had any identifiers which did not map */ - if (colorimetry.primaries != GST_VIDEO_COLOR_PRIMARIES_UNKNOWN && - stream_cfg.colorSpace == ColorSpace::Raw) { - GST_ERROR("One or more identifiers could not be mapped for %s colorimetry", - colorimetry_str); - stream_cfg.colorSpace = std::nullopt; + const GValue *colorimetry = gst_structure_get_value(s, "colorimetry"); + if (!colorimetry) + return; + + /* Configure Colorimetry */ + if (GST_VALUE_HOLDS_LIST(colorimetry)) { + StreamConfiguration pristine_stream_cfg = stream_cfg; + for (i = 0; i < gst_value_list_get_size(colorimetry); i++) { + const GValue *val = gst_value_list_get_value(colorimetry, i); + GstVideoColorimetry colorimetry_old, colorimetry_new; + + ret = configure_colorspace_from_caps(stream_cfg, g_value_get_string(val)); + if (!ret) + continue; + + colorimetry_old = colorimetry_from_colorspace(stream_cfg.colorSpace.value()); + + /* Validate the configuration and check if the requested + * colorimetry can be applied to the sensor. + */ + if (cam_cfg->validate() != CameraConfiguration::Invalid) { + colorimetry_new = colorimetry_from_colorspace(stream_cfg.colorSpace.value()); + if (gst_video_colorimetry_is_equal(&colorimetry_old, &colorimetry_new)) { + g_print("Selected colorimetry %s\n", gst_video_colorimetry_to_string(&colorimetry_new)); + break; + } else + stream_cfg = pristine_stream_cfg; + } } } + if (G_VALUE_TYPE(colorimetry) == G_TYPE_STRING) + configure_colorspace_from_caps(stream_cfg, g_value_get_string(colorimetry)); } #if !GST_CHECK_VERSION(1, 17, 1) diff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h index 164189a2..7afad576 100644 --- a/src/gstreamer/gstlibcamera-utils.h +++ b/src/gstreamer/gstlibcamera-utils.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include @@ -16,7 +17,8 @@ GstCaps *gst_libcamera_stream_formats_to_caps(const libcamera::StreamFormats &formats); GstCaps *gst_libcamera_stream_configuration_to_caps(const libcamera::StreamConfiguration &stream_cfg); -void gst_libcamera_configure_stream_from_caps(libcamera::StreamConfiguration &stream_cfg, +void gst_libcamera_configure_stream_from_caps(std::unique_ptr &cam_cfg, + libcamera::StreamConfiguration &stream_cfg, GstCaps *caps); #if !GST_CHECK_VERSION(1, 17, 1) gboolean gst_task_resume(GstTask *task); diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 16d70fea..25059914 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -503,7 +503,7 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread, /* Fixate caps and configure the stream. */ caps = gst_caps_make_writable(caps); - gst_libcamera_configure_stream_from_caps(stream_cfg, caps); + gst_libcamera_configure_stream_from_caps(state->config_, stream_cfg, caps); } if (flow_ret != GST_FLOW_OK)