From patchwork Mon Mar 30 10:14:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 26384 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 E513ABE086 for ; Mon, 30 Mar 2026 10:17:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2879A62CFD; Mon, 30 Mar 2026 12:17:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FPKBd5sC"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA2C962733 for ; Mon, 30 Mar 2026 12:16:57 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-43cf3ee0fc1so1010685f8f.1 for ; Mon, 30 Mar 2026 03:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1774865817; x=1775470617; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=24RHKpIgZmtyY1fGa2ArRF9nFVbAxTh6oyve8jry8zM=; b=FPKBd5sCxk+S0Rt7CJwjJdHqhIJhuZQb2iYuRHbT2qL7o9yKyF/Vz9V4csfkeknIUA jxkylvr13OizVU4rZ5CXDgFjoEcMMHeqjch2V7LzFGaDQMXnDCxvoUvs0AEg06Ba5moE 7xFfe/Gg27yND5advzUdI4ko0yQ9je+/lxhy1L0PEPFXDjYx+sMkJs8elWYZDbOyaVH1 xQCd9Hy0L0W2TJjTZZ3+t8wzng+/0aIInReT82W+iPvqlZc4WBx4ZGWTtUP3+WvflSjO hQV6GWKwapcyb4P2SNTaKVjhVNuijbwhKlpXykNAK8ltuFDbmnYcx7TQmk38TGrlxUxZ f5cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774865817; x=1775470617; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=24RHKpIgZmtyY1fGa2ArRF9nFVbAxTh6oyve8jry8zM=; b=T6PmKLWHMJHkKx/EgBTEGGJb5XrjHfOPbX7XKgJ8K2JW1UdLY7Zu90qKHBGsTsYpjm I1QlxloWLuA+jyr/m+vs2S/Utmft/xaHv9HDtvKFYNhT9//pnkAoxoWiEuF6q0HNkkXu Sdck+UBeuPE2xtJjR/LQsmx9wrfApNsF38t+op+xSxcg+sKkvxTxwweAO05d4UHtZmGl IQ+xt/fwtp5l7h4ijX5ts7Ya5NCMKxRZOaob8yd+ac1fXTp3hAym7J55G4rB7vkMiVTC /Hx2CSm/jzxYrN46F8Mm//LQ5zSgmho7ZHpHN7zTuAOy79qQBxoPnE5aXa4UqS1QoAKB rE+A== X-Gm-Message-State: AOJu0YweEVu4hi5O1ncbPlFfXIKqhgEQDr8axkG/3G3jDsZcUjBmREBk UYQRhn66mRlqiygBzfQKweRe34m1A1D/ksg3IrEpBgGnCvkyAxlHSVg8rwCxw6zXSelg/pxAYkr aYrh2 X-Gm-Gg: ATEYQzzKlDaTBTiyxMXtJJKyRG+TExugxj31oG8XNVmjp5L4FE20i/ALVGp++qhPD4T sY+k8jW9jMyRj6tlhw3Po6tG+dj8c063FSqMCImK/SlF3rTrnlMT/7HADfAnD37+797Viq10+0t eWOqvTSm4+ccrTYZwr52hUpSpnLx+FOCKGacNkNs+yFoLPjtNNhCksO+5IaVBP2HE0tImNJY8bt uV54h3hKgIeKEQp/lOAlzc1FxqlssUJmhLic//sZGZsHDRM9ZdI0uqE9rcKsPeCBzuuJlor8qvo /+xU4EDNaPLfY5b9qG3d0Ljr5J3YwUV4NKWqfwHChk5n+KcsZP07xIeYVjKWyUnnt7loM0qB+mm IvN+eeJLeMOOgLGpDtyAB2mEYzQCTo3aRzNg9z+RDC5DR5JzKV6MDtxUYAUNWr9bwrSFtFVll8U NA/41qfrPV1M6KAuyW3EXl1wpCrchsaZ81z5r1vx/vCKGdTNoXna50ItGcZANO5BPGCoq6kz8QV pitpt/ZdvGIEx34QkMDS5rak3It1N7HH2Rde3WD2Q== X-Received: by 2002:a05:6000:3109:b0:43c:a352:c34f with SMTP id ffacd0b85a97d-43ca352c69cmr16818445f8f.7.1774865816655; Mon, 30 Mar 2026 03:16:56 -0700 (PDT) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:88ea:c658:5b20:5e46]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf21e2a7asm19744293f8f.7.2026.03.30.03.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 03:16:56 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Nicolas Dufresne Subject: [PATCH v4] gstreamer: Add sensor-config property Date: Mon, 30 Mar 2026 11:14:43 +0100 Message-ID: <20260330101654.3332-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 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" The sensor-config property may optionally be specified to give the outputSize and bitDepth of the SensorConfiguration that is applied to the camera configuration. For example, use libcamerasrc sensor-config="sensor/config,width=2304,height=1296,depth=10" to request the 10-bit 2304x1296 mode of a sensor. All three parameters, width, height and bit depth, must be present, or it will issue a warning and revert to automatic mode selection (as if there were no sensor-config at all). If a mode is requested that doesn't exist then camera configuration will fail and the pipeline won't start. As future-proofing, the SensorConfiguration's binning, increment and analog-crop parameters may be specified, though libcamera currently ignores them. Signed-off-by: David Plowman Reviewed-by: Nicolas Dufresne Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/300 --- src/gstreamer/gstlibcamerasrc.cpp | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index a7241e9b..5d3ee3a2 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -141,6 +141,7 @@ struct _GstLibcameraSrc { GstTask *task; gchar *camera_name; + GstStructure *sensor_config; std::atomic pending_eos; @@ -152,6 +153,7 @@ struct _GstLibcameraSrc { enum { PROP_0, PROP_CAMERA_NAME, + PROP_SENSOR_CONFIG, PROP_LAST }; @@ -846,6 +848,55 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread, } g_assert(state->config_->size() == state->srcpads_.size()); + /* Apply optional sensor configuration. */ + if (self->sensor_config) { + gint w = 0, h = 0, depth = 0; + if (!gst_structure_get_int(self->sensor_config, "width", &w) || + !gst_structure_get_int(self->sensor_config, "height", &h) || + !gst_structure_get_int(self->sensor_config, "depth", &depth) || + w <= 0 || h <= 0 || depth <= 0) { + GST_ELEMENT_WARNING(self, RESOURCE, SETTINGS, + ("sensor-config requires non-zero width, height and depth" + " fields, ignoring"), + (nullptr)); + } else { + SensorConfiguration sensorCfg; + sensorCfg.outputSize = Size(w, h); + sensorCfg.bitDepth = depth; + + /* Optional binning (defaults to 1x1). */ + gint binX, binY; + if (gst_structure_get_int(self->sensor_config, "bin-x", &binX) && binX > 0) + sensorCfg.binning.binX = binX; + if (gst_structure_get_int(self->sensor_config, "bin-y", &binY) && binY > 0) + sensorCfg.binning.binY = binY; + + /* Optional skipping (defaults to 1 for all increments). */ + gint xOddInc, xEvenInc, yOddInc, yEvenInc; + if (gst_structure_get_int(self->sensor_config, "x-odd-inc", &xOddInc) && xOddInc > 0) + sensorCfg.skipping.xOddInc = xOddInc; + if (gst_structure_get_int(self->sensor_config, "x-even-inc", &xEvenInc) && xEvenInc > 0) + sensorCfg.skipping.xEvenInc = xEvenInc; + if (gst_structure_get_int(self->sensor_config, "y-odd-inc", &yOddInc) && yOddInc > 0) + sensorCfg.skipping.yOddInc = yOddInc; + if (gst_structure_get_int(self->sensor_config, "y-even-inc", &yEvenInc) && yEvenInc > 0) + sensorCfg.skipping.yEvenInc = yEvenInc; + + /* Optional analog crop (defaults to "unset"). */ + gint cropX, cropY, cropW, cropH; + if (gst_structure_get_int(self->sensor_config, "analog-crop-x", &cropX) && + gst_structure_get_int(self->sensor_config, "analog-crop-y", &cropY) && + gst_structure_get_int(self->sensor_config, "analog-crop-width", &cropW) && + gst_structure_get_int(self->sensor_config, "analog-crop-height", &cropH) && + cropX >= 0 && cropY >= 0 && cropW > 0 && cropH > 0) + sensorCfg.analogCrop = Rectangle(cropX, cropY, + static_cast(cropW), + static_cast(cropH)); + + state->config_->sensorConfig = sensorCfg; + } + } + if (!gst_libcamera_src_negotiate(self)) { state->initControls_.clear(); GST_ELEMENT_FLOW_ERROR(self, GST_FLOW_NOT_NEGOTIATED); @@ -934,6 +985,10 @@ gst_libcamera_src_set_property(GObject *object, guint prop_id, g_free(self->camera_name); self->camera_name = g_value_dup_string(value); break; + case PROP_SENSOR_CONFIG: + g_clear_pointer(&self->sensor_config, gst_structure_free); + self->sensor_config = (GstStructure *)g_value_dup_boxed(value); + break; default: if (!state->controls_.setProperty(prop_id - PROP_LAST, value, pspec)) G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -953,6 +1008,9 @@ gst_libcamera_src_get_property(GObject *object, guint prop_id, GValue *value, case PROP_CAMERA_NAME: g_value_set_string(value, self->camera_name); break; + case PROP_SENSOR_CONFIG: + g_value_set_boxed(value, self->sensor_config); + break; default: if (!state->controls_.getProperty(prop_id - PROP_LAST, value, pspec)) G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); @@ -1040,6 +1098,7 @@ gst_libcamera_src_finalize(GObject *object) g_clear_object(&self->task); g_mutex_clear(&self->state->lock_); g_free(self->camera_name); + g_clear_pointer(&self->sensor_config, gst_structure_free); delete self->state; return klass->finalize(object); @@ -1162,6 +1221,20 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, PROP_CAMERA_NAME, spec); + spec = g_param_spec_boxed("sensor-config", "Sensor Config", + "Desired sensor configuration as a GstStructure with mandatory " + "fields width, height and depth, and optional fields bin-x, bin-y, " + "x-odd-inc, x-even-inc, y-odd-inc, y-even-inc, " + "analog-crop-x, analog-crop-y, analog-crop-width, analog-crop-height " + "(e.g. \"sensor/config,width=2304,height=1296,depth=10\"). " + "Leave unset to let the pipeline negotiate the sensor mode automatically.", + GST_TYPE_STRUCTURE, + (GParamFlags)(GST_PARAM_MUTABLE_READY + | G_PARAM_CONSTRUCT + | G_PARAM_READWRITE + | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, PROP_SENSOR_CONFIG, spec); + GstCameraControls::installProperties(object_class, PROP_LAST); }