From patchwork Wed Dec 18 14:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 22397 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 288F1C3301 for ; Wed, 18 Dec 2024 14:22:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 208BF680A0; Wed, 18 Dec 2024 15:22:25 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="UdLpReCY"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A9E968094 for ; Wed, 18 Dec 2024 15:22:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734531743; x=1766067743; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=j8kA/oWnUUx0uimLRynJr2w66GsOKJZUikFhte6+Lzg=; b=UdLpReCYzpfMkZ5OEHmiN/wzUwFM6TudFlR4HueaUvUR3GzFJIIecDCK kM+7pRy9QOCq4VMBTW8c5gkWNYdEvV4VqxpfFwlFDYRkt3toFOMpgY9aH SAamgyKIBbbsPR8qbMiksLgce5Pgo5qXEmixiXuYk6JW4sVs2uWEMWhSh /6lipbcCx63tPm1KOvZ9/3KshVj2wwJOSEv6Tjo5hgIvRqTk1SR9CFAWu O+VEf4RFcTCQg85kM8h4pF2232jp5GStu+kzZ8xLrWq7Q8lej+uSLXj8Y xbJC+fN8uSQs7XA4DCZxfJZprHEzoEFTmA7fVqjJo6vG7RjUvQgi+w5n0 A==; X-CSE-ConnectionGUID: cMiVUUQ2TGqF+i8Oi09RcQ== X-CSE-MsgGUID: n6L7j2syRFGVMwWEAteI0A== X-IronPort-AV: E=McAfee;i="6700,10204,11290"; a="45606103" X-IronPort-AV: E=Sophos;i="6.12,244,1728975600"; d="scan'208";a="45606103" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2024 06:22:21 -0800 X-CSE-ConnectionGUID: 4huhuFDyTZCE5dFm6xO60w== X-CSE-MsgGUID: AoB/BoMsSKyggV7rdnGOTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,244,1728975600"; d="scan'208";a="97724240" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.246.8.237]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2024 06:22:19 -0800 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Laurent Pinchart , Kieran Bingham , Naushir Patuck , Sakari Ailus , Hans de Goede Subject: [PATCH v2] pipeline: simple: Use proper device for frame start events Date: Wed, 18 Dec 2024 15:22:17 +0100 Message-Id: <20241218142217.437842-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 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" Currently we use frame start event from video capture device to apply controls. But the capture device might not generate the events. Usually CSI-2 receiver is proper device to subscribe for start frame events. Without DelayedConntrols:applyControls() is possible that we can get call to DelayedControls::get() with frame number that exceed number of saved entries and get below assertion failure: ../src/libcamera/delayed_controls.cpp:227: libcamera::ControlList libcamera::DelayedControls::get(uint32_t): Assertion `info.type() != ControlTypeNone' failed Assertion failure can happen at the beginning of streaming when ControlRingBuffer is not yet filled and there are errors on CSI-2. To fix, loop over devices in the pipeline (starting from the last one), find one that emits start frame events and connect applyControls() to it. Additionally remove direct call to sensor_->setControls() if the emitter device was found. Bug: https://bugs.libcamera.org/show_bug.cgi?id=241 Co-developed-by: Hans de Goede Signed-off-by: Hans de Goede Signed-off-by: Stanislaw Gruszka Reviewed-by: Hans de Goede Tested-by: Hans de Goede # Lenovo X1 Yoga IPU6 + ov2740 --- v1 -> v2: - make eventEmitter_ subdevice part of SimpleCameraData - add debug log when found event emitter device - nullify eventEmitter_ on stop - remove direct sensor_->setControls() - add delayedCtrls_->reset() on start src/libcamera/pipeline/simple/simple.cpp | 39 +++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) -- 2.43.0 diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 8ac24e6e..a7594c2c 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -277,6 +277,7 @@ public: std::list entities_; std::unique_ptr sensor_; V4L2VideoDevice *video_; + V4L2Subdevice *eventEmitter_; std::vector configs_; std::map> formats_; @@ -911,8 +912,11 @@ void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId) void SimpleCameraData::setSensorControls(const ControlList &sensorControls) { delayedCtrls_->push(sensorControls); - ControlList ctrls(sensorControls); - sensor_->setControls(&ctrls); + /* Directly apply controls now if there is no frameStart signal */ + if (!eventEmitter_) { + ControlList ctrls(sensorControls); + sensor_->setControls(&ctrls); + } } /* Retrieve all source pads connected to a sink pad through active routes. */ @@ -1299,8 +1303,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c) data->delayedCtrls_ = std::make_unique(data->sensor_->device(), params); - data->video_->frameStart.connect(data->delayedCtrls_.get(), - &DelayedControls::applyControls); StreamConfiguration inputCfg; inputCfg.pixelFormat = pipeConfig->captureFormat; @@ -1368,6 +1370,28 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL video->bufferReady.connect(data, &SimpleCameraData::imageBufferReady); + /* + * Enable frame start event on last device in the pipeline + * that provides the events. + */ + for (auto it = data->entities_.rbegin(); it != data->entities_.rend(); ++it) { + V4L2Subdevice *sd = subdev(it->entity); + if (!sd) + continue; + if (sd->setFrameStartEnabled(true) < 0) + continue; + + LOG(SimplePipeline, Debug) + << "Using " << it->entity->name() << " frameStart signal"; + + sd->frameStart.connect(data->delayedCtrls_.get(), + &DelayedControls::applyControls); + data->eventEmitter_ = sd; + break; + } + + data->delayedCtrls_->reset(); + ret = video->streamOn(); if (ret < 0) { stop(camera); @@ -1400,6 +1424,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera) SimpleCameraData *data = cameraData(camera); V4L2VideoDevice *video = data->video_; + if (data->eventEmitter_) { + data->eventEmitter_->setFrameStartEnabled(false); + data->eventEmitter_->frameStart.disconnect(data->delayedCtrls_.get(), + &DelayedControls::applyControls); + data->eventEmitter_ = NULL; + } + if (data->useConversion_) { if (data->converter_) data->converter_->stop();