From patchwork Fri Aug 19 06:53:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rishikesh Donadkar X-Patchwork-Id: 17174 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 53FBCBE173 for ; Fri, 19 Aug 2022 06:53:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 16AFD61FC4; Fri, 19 Aug 2022 08:53:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660892025; bh=uinBByPKYC7/sIpOsODtECJZOrfa/XxzAqPVTLMbL0Y=; 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=StpBhC1PBKmU3iNI8SzzzxSf9qEsij/1lWaX/3MLXuDszwp5g5b7faoE01er0eYmZ m3MSWfHwKZtjrw6v0wi/XJ61ec5BCZl38D9eQm0A1FThHb82Vds2BwzJ46gbruxQbx RdgxREoIe7PmXxaoJP6iypY5viDV1p+gyPf9w7VQxKJE1dtXKzgGC+BO0C0KY/a8mK 3+/U8V2ZpIRQuCy88t4Qc9FcsZOwo20gbG44jx/q61y74GaezuTrjqlhiG2+N4nfcw gZKQxFGKyBArIBFC5YN+dI7rNG5+T71Fpk9NFFAhdUWoBiqnC0ub7Cn5OJAkBjt6En s7B7QrLqawM0A== Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ACDC3603E2 for ; Fri, 19 Aug 2022 08:53:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FLGi6rYJ"; dkim-atps=neutral Received: by mail-pf1-x435.google.com with SMTP id y127so595262pfy.5 for ; Thu, 18 Aug 2022 23:53:43 -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=jmlxqwiHFTj3PvVBts++O8QHZgHqAZzRdjewWYirD+A=; b=FLGi6rYJip65h6PUCokUriaw6ZRlTHepGqGnDutms7itLBxPwI7iDXwcBrrHS8g1A/ b1lapa8nBaM05ruKKlOfpJAlyC8xJnk6HD5a/W7VPG5DolRvTcotRE/6uB+a1o/E0Ihu 4C89U3Ge5BVUJOVWpHfQYiREc1h3HW8UEgRiwUGMG1X/gbjnjq+9Bghor7oqhRVlvsAe xiO22OmjsKB4YfP+KmlYkyY0U1WOi7gIm4o4t1eQHw8CEktqSmMCUtXkVbKj5LAWLzyQ 1pqV+aNaJQ7WrY6ZMozQZBUEUcAJnyAzDrbhJDLPS0Zli0ZQLPGu4ZVYibmDEINP3Clt q+zg== 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=jmlxqwiHFTj3PvVBts++O8QHZgHqAZzRdjewWYirD+A=; b=ZgUq8DD/1Q8/sdi/fRVhXRHqK7NsdEbrUmqJ3Rwv98hcJoCu5wLDy2+oTQx5nbo/lv MliooabX/V3r6XrsbU+MEt9VYiExmOucCaIKRXR+6Vird3JW0RvLgHQTAstzkjkMR6BK PE8TjB2PYrt6SfAZxotdlBKszZiy0MEnx7wOrR+YfERAeHNo8Z6JGhMkN/QHE+mnpRij mzRvsbMHxJ18jAiuZ1t0mqTrDW7kay7XTU8ET/qJR1PzYhoLF3vOoweSE0rMGfmAvbEY Dt0IDowt/m7UxH2IT2lHBd/e/O3bRIQb78WX28P3jS+GLTm6tk2DG75HPUzVTXPEAiMK 1fRA== X-Gm-Message-State: ACgBeo3JREeq+vx3udwkhQc1qlnvwqSj18qPj28Jp5nlFso15+TkubuX 8hGBoMV32of7sZS1g8B9Rp4ubj5HLLSAEg== X-Google-Smtp-Source: AA6agR5vOj7SSeCig+TWsnWSjhViYWnKaMn+U1efEzsFBp1bas0PU4J5G31oHIj03iEeFjuRM6dqyA== X-Received: by 2002:a65:4984:0:b0:429:b7b2:46fb with SMTP id r4-20020a654984000000b00429b7b246fbmr5315857pgs.293.1660892022103; Thu, 18 Aug 2022 23:53:42 -0700 (PDT) Received: from localhost.localdomain ([49.36.101.190]) by smtp.googlemail.com with ESMTPSA id n17-20020a170902d2d100b0016d6c939332sm2451945plc.279.2022.08.18.23.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 23:53:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 19 Aug 2022 12:23:23 +0530 Message-Id: <20220819065323.10051-2-rishikeshdonadkar@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220819065323.10051-1-rishikeshdonadkar@gmail.com> References: <20220819065323.10051-1-rishikeshdonadkar@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 | 76 +++++++++++++++++++++------- src/gstreamer/gstlibcamera-utils.h | 4 +- src/gstreamer/gstlibcamerasrc.cpp | 2 +- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index d895a67d..218419fd 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -302,13 +302,38 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg return caps; } +static gboolean +configure_colorspace_from_caps(StreamConfiguration &stream_cfg, + const gchar *colorimetry_str) +{ + if (colorimetry_str) { + GstVideoColorimetry colorimetry; + + if (!gst_video_colorimetry_from_string(&colorimetry, colorimetry_str)) { + g_critical("Invalid colorimetry %s", colorimetry_str); + return false; + } + + 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 true; +} + 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,22 +406,39 @@ 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; + } } + } else if (G_VALUE_HOLDS_STRING(colorimetry)) { + configure_colorspace_from_caps(stream_cfg, g_value_get_string(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)