{"id":23946,"url":"https://patchwork.libcamera.org/api/patches/23946/?format=json","web_url":"https://patchwork.libcamera.org/patch/23946/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250724133343.353044-4-uajain@igalia.com>","date":"2025-07-24T13:33:43","name":"[v4,3/3] gstreamer: Report camera properties as device properties","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"db26ca9634555323113d7f8f8a4829b5caf68257","submitter":{"id":232,"url":"https://patchwork.libcamera.org/api/people/232/?format=json","name":"Umang Jain","email":"uajain@igalia.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23946/mbox/","series":[{"id":5323,"url":"https://patchwork.libcamera.org/api/series/5323/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5323","date":"2025-07-24T13:33:41","name":"gstreamer: Report camera properties as device properties","version":4,"mbox":"https://patchwork.libcamera.org/series/5323/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23946/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23946/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 16F89C3323\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Jul 2025 13:33:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E971869116;\n\tThu, 24 Jul 2025 15:33:47 +0200 (CEST)","from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DAE6B690F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Jul 2025 15:33:41 +0200 (CEST)","from [49.36.71.87] (helo=uajain) by fanzine2.igalia.com with\n\tesmtpsa \n\t(Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)\n\t(Exim) id 1uew4q-003CfR-VO; Thu, 24 Jul 2025 15:33:41 +0200"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=igalia.com header.i=@igalia.com\n\theader.b=\"fMOegIcj\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com;\n\ts=20170329;\n\th=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=X3aUhfq1vNmHLfj4hgENauGM5sf+f87bJJirO/GZEEc=;\n\tb=fMOegIcjvJaPS5eK1shGoP5OZ+\n\tkTx1k+/OQtAEG7t2eikyIoNNKqwUdSNqiqz21gmFMxPDGSRjCfUrgfECxoyztEa7Mna/5YRbk69E6\n\tkwkW3ZlqUNlK+kfk+/4MNWU0fsqss1Vsw2p63ZzTS5O33i8EsGiUe7XhcvpqyHGET7Hdy3Gi/xqHp\n\tmnFnRcvCcc7qHcX5aO2C9GKVgyFVEz1hEXtON54Sv9Jzof2f5nuF1Qgi8DP5Er9Jkw+WKX/5K97Rc\n\tA7Rj2mW0vLmFoIlxL2xLijtSxPz7DFcdN5WNp8NBAh742koTNpC31Rc9tE4440m42p+vbMmHMcBle\n\tYl1fr+Kg==;","From":"Umang Jain <uajain@igalia.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Jaslo Ziska <jaslo@ziska.de>,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>,\n\tUmang Jain <uajain@igalia.com>","Subject":"[PATCH v4 3/3] gstreamer: Report camera properties as device\n\tproperties","Date":"Thu, 24 Jul 2025 19:03:43 +0530","Message-ID":"<20250724133343.353044-4-uajain@igalia.com>","X-Mailer":"git-send-email 2.50.0","In-Reply-To":"<20250724133343.353044-1-uajain@igalia.com>","References":"<20250724133343.353044-1-uajain@igalia.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Iterate over all libcamera camera properties and report them as\ndevice properties. Each libcamera ControlType is mapped to the corresponding\ngstreamer GType. If the ControlValue is an array of values\n(ControlValue::isArray()), GValue with type GST_TYPE_ARRAY is used to set the\nvalue of that ControlValue with the corresponding GType.\n\nSigned-off-by: Umang Jain <uajain@igalia.com>\n---\n src/gstreamer/gstlibcamera-utils.cpp   | 199 +++++++++++++++++++++++++\n src/gstreamer/gstlibcamera-utils.h     |   3 +\n src/gstreamer/gstlibcameraprovider.cpp |  16 ++\n 3 files changed, 218 insertions(+)","diff":"diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nindex 63e00fe0..3d728cbc 100644\n--- a/src/gstreamer/gstlibcamera-utils.cpp\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -333,6 +333,33 @@ bare_structure_from_format(const PixelFormat &format)\n \t}\n }\n \n+static const struct {\n+\tControlType c_type;\n+\tGType g_type;\n+} control_type_gtype_map[]{\n+\t{ ControlTypeBool, G_TYPE_BOOLEAN },\n+\t{ ControlTypeByte, G_TYPE_UINT },\n+\t{ ControlTypeUnsigned16, G_TYPE_UINT },\n+\t{ ControlTypeUnsigned32, G_TYPE_UINT },\n+\t{ ControlTypeInteger32, G_TYPE_LONG },\n+\t{ ControlTypeInteger64, G_TYPE_INT64 },\n+\t{ ControlTypeFloat, G_TYPE_FLOAT },\n+\t{ ControlTypeString, G_TYPE_STRING },\n+\t{ ControlTypeRectangle, GST_TYPE_ARRAY },\n+\t{ ControlTypeSize, GST_TYPE_ARRAY },\n+\t{ ControlTypePoint, GST_TYPE_ARRAY },\n+};\n+\n+static GType\n+control_type_to_gtype(const ControlType &type)\n+{\n+\tfor (auto &a : control_type_gtype_map) {\n+\t\tif (a.c_type == type)\n+\t\t\treturn a.g_type;\n+\t}\n+\treturn G_TYPE_INVALID;\n+}\n+\n GstCaps *\n gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)\n {\n@@ -706,3 +733,175 @@ gst_libcamera_get_camera_manager(int &ret)\n \n \treturn cm;\n }\n+\n+int gst_libcamera_set_structure_field(GstStructure *structure, GString *field,\n+\t\t\t\t      const ControlId *id, const ControlValue &value)\n+{\n+\tGValue v = G_VALUE_INIT;\n+\tGValue x = G_VALUE_INIT;\n+\tgboolean is_array = value.isArray();\n+\n+\tGType type = control_type_to_gtype(value.type());\n+\tif (type == G_TYPE_INVALID)\n+\t\treturn -EINVAL;\n+\n+\tif (is_array || type == GST_TYPE_ARRAY) {\n+\t\tg_value_init(&v, GST_TYPE_ARRAY);\n+\t\tg_value_init(&x, type);\n+\t}\n+\n+\tswitch (value.type()) {\n+\tcase ControlTypeBool:\n+\t\tif (is_array) {\n+\t\t\tSpan<const bool> data = value.get<Span<const bool>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_boolean(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_BOOLEAN,\n+\t\t\t\t\t  value.get<const bool>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeByte:\n+\t\tif (is_array) {\n+\t\t\tSpan<const uint8_t> data = value.get<Span<const uint8_t>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_uint(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_UINT,\n+\t\t\t\t\t  value.get<const uint8_t>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeUnsigned16:\n+\t\tif (is_array) {\n+\t\t\tSpan<const uint16_t> data = value.get<Span<const uint16_t>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_uint(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_UINT,\n+\t\t\t\t\t  value.get<const uint16_t>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeUnsigned32:\n+\t\tif (is_array) {\n+\t\t\tSpan<const uint32_t> data = value.get<Span<const uint32_t>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_ulong(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_ULONG,\n+\t\t\t\t\t  value.get<const uint32_t>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeInteger32:\n+\t\tif (is_array) {\n+\t\t\tSpan<const int32_t> data = value.get<Span<const int32_t>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_long(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tif (!id->enumerators().empty()) {\n+\t\t\t\tint32_t val = value.get<int32_t>();\n+\t\t\t\tconst auto &iter = id->enumerators().find(val);\n+\t\t\t\tif (iter != id->enumerators().end()) {\n+\t\t\t\t\tgst_structure_set(structure, field->str,\n+\t\t\t\t\t\t\t  G_TYPE_STRING,\n+\t\t\t\t\t\t\t  iter->second.c_str(),\n+\t\t\t\t\t\t\t  nullptr);\n+\t\t\t\t} else {\n+\t\t\t\t\treturn -EINVAL;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tgst_structure_set(structure, field->str, G_TYPE_LONG,\n+\t\t\t\t\t\t  value.get<const int32_t>(), nullptr);\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeInteger64:\n+\t\tif (is_array) {\n+\t\t\tSpan<const int64_t> data = value.get<Span<const int64_t>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_int64(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_INT64,\n+\t\t\t\t\t  value.get<const int64_t>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeFloat:\n+\t\tif (is_array) {\n+\t\t\tSpan<const float> data = value.get<Span<const float>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it) {\n+\t\t\t\tg_value_set_float(&x, *it);\n+\t\t\t\tgst_value_array_append_and_take_value(&v, &x);\n+\t\t\t\tg_value_init(&x, type);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tgst_structure_set(structure, field->str, G_TYPE_FLOAT,\n+\t\t\t\t\t  value.get<const float>(), nullptr);\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeString:\n+\t\tgst_structure_set(structure, field->str, G_TYPE_STRING,\n+\t\t\t\t  value.toString().c_str(), nullptr);\n+\t\tbreak;\n+\tcase ControlTypeSize:\n+\t\tif (is_array) {\n+\t\t\tSpan<const Size> data = value.get<Span<const Size>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it)\n+\t\t\t\tgst_libcamera_gvalue_set_size(&v, *it);\n+\t\t} else {\n+\t\t\tgst_libcamera_gvalue_set_size(&v, value.get<const Size>());\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypePoint:\n+\t\tif (is_array) {\n+\t\t\tSpan<const Point> data = value.get<Span<const Point>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it)\n+\t\t\t\tgst_libcamera_gvalue_set_point(&v, *it);\n+\t\t} else {\n+\t\t\tgst_libcamera_gvalue_set_point(&v, value.get<const Point>());\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeRectangle:\n+\t\tif (is_array) {\n+\t\t\tSpan<const Rectangle> data = value.get<Span<const Rectangle>>();\n+\t\t\tfor (auto it = data.begin(); it != data.end(); ++it)\n+\t\t\t\tgst_libcamera_gvalue_set_rectangle(&v, *it);\n+\t\t} else {\n+\t\t\tgst_libcamera_gvalue_set_rectangle(&v, value.get<const Rectangle>());\n+\t\t}\n+\t\tbreak;\n+\tcase ControlTypeNone:\n+\t\t[[fallthrough]];\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/*\n+\t * Set values for array types with the only exception of strings which\n+\t * is handled by ControlValue::toString() helper directly above.\n+\t */\n+\tif ((is_array || type == GST_TYPE_ARRAY) &&\n+\t    (value.type() != ControlTypeString))\n+\t\tgst_structure_set_value(structure, field->str, &v);\n+\n+\tg_value_unset(&v);\n+\tg_value_unset(&x);\n+\n+\treturn 0;\n+}\ndiff --git a/src/gstreamer/gstlibcamera-utils.h b/src/gstreamer/gstlibcamera-utils.h\nindex 1812be75..53ad6911 100644\n--- a/src/gstreamer/gstlibcamera-utils.h\n+++ b/src/gstreamer/gstlibcamera-utils.h\n@@ -29,6 +29,9 @@ void gst_libcamera_gvalue_set_point(GValue *value, const libcamera::Point &point\n void gst_libcamera_gvalue_set_size(GValue *value, const libcamera::Size &size);\n void gst_libcamera_gvalue_set_rectangle(GValue *value, const libcamera::Rectangle &rect);\n libcamera::Rectangle gst_libcamera_gvalue_get_rectangle(const GValue *value);\n+int gst_libcamera_set_structure_field(GstStructure *structure, GString *field,\n+\t\t\t\t      const libcamera::ControlId *id,\n+\t\t\t\t      const libcamera::ControlValue &value);\n \n #if !GST_CHECK_VERSION(1, 16, 0)\n static inline void gst_clear_event(GstEvent **event_ptr)\ndiff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\nindex 5da96ea3..06501fd8 100644\n--- a/src/gstreamer/gstlibcameraprovider.cpp\n+++ b/src/gstreamer/gstlibcameraprovider.cpp\n@@ -12,6 +12,7 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/camera_manager.h>\n+#include <libcamera/property_ids.h>\n \n #include \"gstlibcamerasrc.h\"\n #include \"gstlibcamera-utils.h\"\n@@ -144,12 +145,27 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)\n \t\t\tgst_caps_append(caps, sub_caps);\n \t}\n \n+\tg_autoptr(GstStructure) props = gst_structure_new_empty(\"camera-properties\");\n+\tfor (const auto &[key, value] : camera->properties()) {\n+\t\tconst ControlId *id = properties::properties.at(key);\n+\n+\t\tg_autoptr(GString) prop_str = g_string_new(\"api.libcamera.\");\n+\t\tg_string_append(prop_str, id->name().c_str());\n+\n+\t\tint ret = gst_libcamera_set_structure_field(props, prop_str, id, value);\n+\t\tif (ret < 0) {\n+\t\t\tGST_ERROR(\"Failed to retrieve value for %s property\", id->name().c_str());\n+\t\t\treturn nullptr;\n+\t\t}\n+\t}\n+\n \treturn GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,\n \t\t\t\t       /* \\todo Use a unique identifier instead of camera name. */\n \t\t\t\t       \"name\", name,\n \t\t\t\t       \"display-name\", name,\n \t\t\t\t       \"caps\", caps,\n \t\t\t\t       \"device-class\", \"Source/Video\",\n+\t\t\t\t       \"properties\", props,\n \t\t\t\t       nullptr));\n }\n \n","prefixes":["v4","3/3"]}