From patchwork Mon Sep 19 02:57:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 17379 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 1C1C4C0DA4 for ; Mon, 19 Sep 2022 02:57:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D79DC62191; Mon, 19 Sep 2022 04:57:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1663556252; bh=ZDMbdykIvGeRwtJ/q5oqXpcMj4gGgSxe0VEhTKQ0YW4=; 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=0Nr4qk05jSyAS0XqIjKmRwNCJPJzirum3NbiL3kZwC05lwFQO6gQQHGzcDGcf30em N2lcPO88nKeWhn1Op3CADTCbiG/M4/z1ME6YHwTyHm/eq74A96hcgixz4HMyFW6Z0O AXwNtQTH+ZFng8INh1j3lpdeswTvZm0NALllehlTnV9+HDhcYGujXDfaPnLxPJgRqb R+uDpIsUEDy+iMhEyOB5twy4LV2cZEI6fwqnNc66bB9OimVSUbXwNHK3I7n1vku+2T 2yRo0Jf0JrTmph3PRqg/guomVyfSYotW24592Y8XbHXeD0MAGjaC+Y2wdnWlHqJuzg FxB3e8RuwaVBw== Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B98C26218A for ; Mon, 19 Sep 2022 04:57:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PckKWg1x"; dkim-atps=neutral Received: by mail-pj1-x1031.google.com with SMTP id fs14so26431524pjb.5 for ; Sun, 18 Sep 2022 19:57:31 -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:subject:date; bh=ReFAL9IdGX6D2qk/YUzwcdCVilF9NS71DQzJCDoUc+Q=; b=PckKWg1xYcmqjnYe16R64bGjuRkkAwVSRhBEK9a5O/VU5XpB7pLLjkgjwD1xZ9DaeP qfSqzBJ2x9WrDJN5c0FvkH/BlqH+H3FuMmCqem64fi9Ttgl0UopsEsVZgWevKUKOiId5 2Tb1V76ApjZobyB/M5VWAXMolj63XnV/U8tVpcmYo6Y+10iOq/+2PapCXk5dwMBnQzjS s+QW8A0MNbU6Pv25TCbq2CsF0+VHWXXw62AkVbQSiH1x56TPog/qBd+YMui4KytoWnjc F3/w/ePBpEx9fEiC+fyGwEXT4yDI3VW+tuEFY7LIuUeDAcOfaQuM+UybB6haq+e83G4M dZ1w== 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 :subject:date; bh=ReFAL9IdGX6D2qk/YUzwcdCVilF9NS71DQzJCDoUc+Q=; b=7hnQpw9dWOp82WG9EID3KzY6/7FGGE1JoeI3csmsuj8hKvYPHOT46Vr9FifHAVE4fd m8jqFe6kB3kWnuN2vtWmQ07TwpueBHhDNhe14VBKmQTC5PIUaeZJFmhb+z1vyigYs1cD Jat0H8m36hncFlQDCoeWo8lqMJpeOiVC6nd2+FnX+ZTPoOPXCEDONWSI9vYpzwI76VkA r5u6Uib0W+UpPGY8vKIHj8WReQFv/DK51FLYkf7DQ3t5Y6lyxbYQzBFi+bU+BA0Prbny 6xA4XyvzsfqcJ54PVfT+SdUWmpM6Hte/ox0Kbu9XTBsgDtX/oXS0xBdsjzHBQZTBDQxN TkaQ== X-Gm-Message-State: ACrzQf2qO7WLw42VmD+8Zm3y5gg9bZnCsvEwnD3vNMDFDnUylvvbzei7 dHRsCKZZ23+ZggDyGFR5VQMluZ76cSc= X-Google-Smtp-Source: AMsMyM4MQiqWlbbEC6mjiD4NaJCXgDad2WOFA5Vrox351xEurA1WJMCusvP4DD2cK/GaVXaQPsDfVw== X-Received: by 2002:a17:902:d490:b0:177:fc1d:6b0c with SMTP id c16-20020a170902d49000b00177fc1d6b0cmr10903877plg.28.1663556249963; Sun, 18 Sep 2022 19:57:29 -0700 (PDT) Received: from localhost.localdomain ([49.36.97.74]) by smtp.googlemail.com with ESMTPSA id a3-20020a656403000000b0042b291a89bfsm17303922pgv.11.2022.09.18.19.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Sep 2022 19:57:29 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 19 Sep 2022 08:27:09 +0530 Message-Id: <20220919025709.34528-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919025709.34528-1-rishikeshdonadkar@gmail.com> References: <20220919025709.34528-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/1] gstreamer: Provide multiple colorimetry support for libcamerasrc 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: 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, set the colorspace in the stream_cfg and validate the camera configuration. Retrieve the colorspace after validation, convert to colorimetry and check if 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 Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamera-utils.cpp | 49 +++++++++++++++++++++++----- src/gstreamer/gstlibcamera-utils.h | 4 ++- src/gstreamer/gstlibcamerasrc.cpp | 2 +- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index 244a4a79..f73b6349 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -316,9 +316,9 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg return caps; } -void -gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg, - GstCaps *caps) +void 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; @@ -395,15 +395,46 @@ 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; + const GValue *colorimetry_ = gst_structure_get_value(s, "colorimetry"); + if (!colorimetry_) + return; - if (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str)) - g_critical("Invalid colorimetry %s", colorimetry_str); + /* Configure Colorimetry */ + GstVideoColorimetry 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); + + if (!gst_video_colorimetry_from_string(&colorimetry, g_value_get_string(val))) { + g_warning("Invalid colorimetry %s, trying next option", g_value_get_string(val)); + continue; + } + + std::optional clrSpace = colorspace_from_colorimetry(colorimetry); + stream_cfg.colorSpace = clrSpace; + + /* Validate the configuration and check if the requested + * colorimetry can be applied to the sensor. Otherwise, + * restore the configuration back to pristine one. + */ + if (cam_cfg->validate() != CameraConfiguration::Invalid) { + /* Check the colorspace returned after validation, with the colorspace before validation */ + if (stream_cfg.colorSpace == clrSpace) { + g_print("Selected colorimetry %s\n", gst_video_colorimetry_to_string(&colorimetry)); + break; + } else { + stream_cfg = pristine_stream_cfg; + } + } + } + } else if (G_VALUE_HOLDS_STRING(colorimetry_)) { + if (!gst_video_colorimetry_from_string(&colorimetry, g_value_get_string(colorimetry_))) + g_critical("Invalid colorimetry %s", g_value_get_string(colorimetry_)); stream_cfg.colorSpace = colorspace_from_colorimetry(colorimetry); + } else { + GST_WARNING("colorimetry field type should only be string or list."); } } 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)