From patchwork Tue Dec 17 10:52:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 22374 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 53CA0BD1F1 for ; Tue, 17 Dec 2024 10:52:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8830867FC6; Tue, 17 Dec 2024 11:52:15 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="N+xz73mr"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D739567FC0 for ; Tue, 17 Dec 2024 11:52:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734432733; x=1765968733; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=aS0bQ3IsO0Pfeh6bs94LVmWsbiHUe8SEPHRfLYV1k6w=; b=N+xz73mr/RWRiHcDnR0YPyI52u4M+p6tpUWMNES5IXVzQ480xg0wggxN lcRnq5YORmDIL6oUtqGhf6N23ho2yIdZPjRB+OkIl/1wQGhK+tOuzngi/ WFShTRgEiMr9bH+lV9yOF/iK+P9lcbBJZkaccS5CSBUBkui/QEApp5EvQ 234nFVAlBX5R3aVph9M8dfTIMp6zre1ojN9Hh6fWNjWHpCTtyPmdvpL75 5zE+2MoBDZWEFQqriVZdPsmv1TEJ7vvaZ194iSInVTNwZfSDQUgZJ8wLD ZixUt1TJZBLSHzUf7tinG9hQhynn7P8Rmjhe0X9Br3YWGwwrLnzJQyTCG A==; X-CSE-ConnectionGUID: oOWFAxMgQjexwHxt7+F5gw== X-CSE-MsgGUID: ottT8RuMQ8e3+uQ7tLCBIA== X-IronPort-AV: E=McAfee;i="6700,10204,11288"; a="34173626" X-IronPort-AV: E=Sophos;i="6.12,241,1728975600"; d="scan'208";a="34173626" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Dec 2024 02:52:11 -0800 X-CSE-ConnectionGUID: 2ecHtOTlThSKV20kiwRFwQ== X-CSE-MsgGUID: rxhL1ep3RLWzPWwgQFYxrg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="134832065" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.246.8.237]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Dec 2024 02:52:09 -0800 From: Stanislaw Gruszka To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Laurent Pinchart , Kieran Bingham , Naushir Patuck , Sakari Ailus Subject: [PATCH] pipeline: simple: Use proper device for frame start events Date: Tue, 17 Dec 2024 11:52:06 +0100 Message-Id: <20241217105206.357495-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. Bug: https://bugs.libcamera.org/show_bug.cgi?id=241 Signed-off-by: Stanislaw Gruszka Tested-by: Hans de Goede --- src/libcamera/pipeline/simple/simple.cpp | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 8ac24e6e..52f3d520 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -382,6 +382,7 @@ private: std::map entities_; MediaDevice *converter_; + V4L2Subdevice *eventEmitter_; bool swIspEnabled_; }; @@ -1299,8 +1300,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 +1367,23 @@ 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; + + sd->frameStart.connect(data->delayedCtrls_.get(), + &DelayedControls::applyControls); + eventEmitter_ = sd; + break; + } + ret = video->streamOn(); if (ret < 0) { stop(camera); @@ -1400,6 +1416,12 @@ void SimplePipelineHandler::stopDevice(Camera *camera) SimpleCameraData *data = cameraData(camera); V4L2VideoDevice *video = data->video_; + if (eventEmitter_) { + eventEmitter_->setFrameStartEnabled(false); + eventEmitter_->frameStart.disconnect(data->delayedCtrls_.get(), + &DelayedControls::applyControls); + } + if (data->useConversion_) { if (data->converter_) data->converter_->stop();