From patchwork Fri Mar 28 16:07:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23069 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 78B96C323E for ; Fri, 28 Mar 2025 16:07:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7327F6897D; Fri, 28 Mar 2025 17:07:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aFWXDYfT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 104DF614E9 for ; Fri, 28 Mar 2025 17:07:41 +0100 (CET) Received: from pb-laptop.local (185.221.143.221.nat.pool.zt.hu [185.221.143.221]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6714E9FC for ; Fri, 28 Mar 2025 17:05:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743177951; bh=jLa1jqP8RpuJU/h79ARBMTUXxxCO9yHpv6aRS7vshVc=; h=From:To:Subject:Date:From; b=aFWXDYfT4zucbtqwi2CX+m/+oLUqCNL8kI6k5/pADsuC3rG8trvrZbrbHN+A1gsR4 8cnH5MfmN6B4tHb5wnxiwQh4aVT0nqYnG4BWlDT5cC0nOdyH6YpOFPOmVEFWFZzvxE utvTLeVZjmJOsTk+EdCt+PNxzHr4xXy1YhHcf1+A= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1] gstreamer: Use `Control<>` objects when setting controls Date: Fri, 28 Mar 2025 17:07:36 +0100 Message-ID: <20250328160736.94529-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `g_value_get_boolean()` returns `gboolean`, which is actually `int`. Thus // ControlValue x; auto val = g_value_get_boolean(...); x.set(val); will cause `ControlValue::set(const int&)` to be called, which will save the value as `ControlTypeInteger32`, not `ControlTypeBoolean`. Then, if something tries to retrieve the boolean value, it will run into an assertion failure: Assertion `type_ == details::control_type>::value' failed. in `ControlValue::set()`. Fix this by using the appropriately typed `Control<>` object when setting the value in the `ControlList` as this ensures that the value will be converted to the actual type of the control. Bug: https://bugs.libcamera.org/show_bug.cgi?id=261 Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Acked-by: Kieran Bingham --- There is a simpler fix to this issue as well: diff --git a/src/gstreamer/gstlibcamera-controls.cpp.in b/src/gstreamer/gstlibcamera-controls.cpp.in index d937b19e6..8378b5fd0 100644 --- a/src/gstreamer/gstlibcamera-controls.cpp.in +++ b/src/gstreamer/gstlibcamera-controls.cpp.in @@ -271,7 +271,7 @@ bool GstCameraControls::setProperty(guint propId, const GValue *value, } Rectangle val = value_get_rectangle(value); {%- else %} - auto val = g_value_get_{{ ctrl.gtype }}(value); + {{ ctrl.element_type }} val = g_value_get_{{ ctrl.gtype }}(value); {%- endif %} control.set(val); {%- endif %} --- src/gstreamer/gstlibcamera-controls.cpp.in | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) -- 2.49.0 diff --git a/src/gstreamer/gstlibcamera-controls.cpp.in b/src/gstreamer/gstlibcamera-controls.cpp.in index d937b19e6..89c530da0 100644 --- a/src/gstreamer/gstlibcamera-controls.cpp.in +++ b/src/gstreamer/gstlibcamera-controls.cpp.in @@ -223,7 +223,6 @@ bool GstCameraControls::setProperty(guint propId, const GValue *value, {%- for ctrl in ctrls %} case controls::{{ ctrl.namespace }}{{ ctrl.name|snake_case|upper }}: { - ControlValue control; {%- if ctrl.is_array %} size_t size = gst_value_array_get_size(value); {%- if ctrl.size != 0 %} @@ -254,12 +253,9 @@ bool GstCameraControls::setProperty(guint propId, const GValue *value, } {%- if ctrl.size == 0 %} - control.set(Span(values.data(), - size)); + Span val(values.data(), size); {%- else %} - control.set(Span(values.data(), - {{ ctrl.size }})); + Span val(values.data(), size); {%- endif %} {%- else %} {%- if ctrl.is_rectangle %} @@ -273,10 +269,9 @@ bool GstCameraControls::setProperty(guint propId, const GValue *value, {%- else %} auto val = g_value_get_{{ ctrl.gtype }}(value); {%- endif %} - control.set(val); {%- endif %} - controls_.set(propId, control); - controls_acc_.set(propId, control); + controls_.set(controls::{{ ctrl.namespace }}{{ ctrl.name }}, val); + controls_acc_.set(controls::{{ ctrl.namespace }}{{ ctrl.name }}, val); return true; } {%- endfor %}