{"id":22397,"url":"https://patchwork.libcamera.org/api/1.1/patches/22397/?format=json","web_url":"https://patchwork.libcamera.org/patch/22397/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20241218142217.437842-1-stanislaw.gruszka@linux.intel.com>","date":"2024-12-18T14:22:17","name":"[v2] pipeline: simple: Use proper device for frame start events","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"50edd8549bf1b6d922d953bcc55c4d2c41eab9e1","submitter":{"id":211,"url":"https://patchwork.libcamera.org/api/1.1/people/211/?format=json","name":"Stanislaw Gruszka","email":"stanislaw.gruszka@linux.intel.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22397/mbox/","series":[{"id":4912,"url":"https://patchwork.libcamera.org/api/1.1/series/4912/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4912","date":"2024-12-18T14:22:17","name":"[v2] pipeline: simple: Use proper device for frame start events","version":2,"mbox":"https://patchwork.libcamera.org/series/4912/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22397/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22397/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 288F1C3301\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Dec 2024 14:22:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 208BF680A0;\n\tWed, 18 Dec 2024 15:22:25 +0100 (CET)","from mgamail.intel.com (mgamail.intel.com [192.198.163.11])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A9E968094\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Dec 2024 15:22:22 +0100 (CET)","from fmviesa007.fm.intel.com ([10.60.135.147])\n\tby fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n\t18 Dec 2024 06:22:21 -0800","from sgruszka-mobl.ger.corp.intel.com (HELO localhost)\n\t([10.246.8.237]) by fmviesa007-auth.fm.intel.com with\n\tESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2024 06:22:19 -0800"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=intel.com header.i=@intel.com\n\theader.b=\"UdLpReCY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n\tt=1734531743; x=1766067743;\n\th=from:to:cc:subject:date:message-id:mime-version:\n\tcontent-transfer-encoding;\n\tbh=j8kA/oWnUUx0uimLRynJr2w66GsOKJZUikFhte6+Lzg=;\n\tb=UdLpReCYzpfMkZ5OEHmiN/wzUwFM6TudFlR4HueaUvUR3GzFJIIecDCK\n\tkM+7pRy9QOCq4VMBTW8c5gkWNYdEvV4VqxpfFwlFDYRkt3toFOMpgY9aH\n\tSAamgyKIBbbsPR8qbMiksLgce5Pgo5qXEmixiXuYk6JW4sVs2uWEMWhSh\n\t/6lipbcCx63tPm1KOvZ9/3KshVj2wwJOSEv6Tjo5hgIvRqTk1SR9CFAWu\n\tO+VEf4RFcTCQg85kM8h4pF2232jp5GStu+kzZ8xLrWq7Q8lej+uSLXj8Y\n\txbJC+fN8uSQs7XA4DCZxfJZprHEzoEFTmA7fVqjJo6vG7RjUvQgi+w5n0 A==;","X-CSE-ConnectionGUID":["cMiVUUQ2TGqF+i8Oi09RcQ==","4huhuFDyTZCE5dFm6xO60w=="],"X-CSE-MsgGUID":["n6L7j2syRFGVMwWEAteI0A==","AoB/BoMsSKyggV7rdnGOTg=="],"X-IronPort-AV":["E=McAfee;i=\"6700,10204,11290\"; a=\"45606103\"","E=Sophos;i=\"6.12,244,1728975600\"; d=\"scan'208\";a=\"45606103\"","E=Sophos;i=\"6.12,244,1728975600\"; d=\"scan'208\";a=\"97724240\""],"X-ExtLoop1":"1","From":"Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tSakari Ailus <sakari.ailus@linux.intel.com>,\n\tHans de Goede <hdegoede@redhat.com>","Subject":"[PATCH v2] pipeline: simple: Use proper device for frame start\n\tevents","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","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":"Currently we use frame start event from video capture device to\napply controls. But the capture device might not generate the events.\nUsually CSI-2 receiver is proper device to subscribe for start\nframe events.\n\nWithout DelayedConntrols:applyControls() is possible that we can get\ncall to DelayedControls::get() with frame number that exceed number\nof saved entries and get below assertion failure:\n\n../src/libcamera/delayed_controls.cpp:227:\nlibcamera::ControlList libcamera::DelayedControls::get(uint32_t):\nAssertion `info.type() != ControlTypeNone' failed\n\nAssertion failure can happen at the beginning of streaming when\nControlRingBuffer is not yet filled and there are errors on CSI-2.\n\nTo fix, loop over devices in the pipeline (starting from the last one),\nfind one that emits start frame events and connect applyControls()\nto it. Additionally remove direct call to sensor_->setControls() if\nthe emitter device was found.\n\nBug: https://bugs.libcamera.org/show_bug.cgi?id=241\nCo-developed-by: Hans de Goede <hdegoede@redhat.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\nSigned-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>\n---\nv1 -> v2:\n - make eventEmitter_ subdevice part of SimpleCameraData\n - add debug log when found event emitter device\n - nullify eventEmitter_ on stop\n - remove direct sensor_->setControls()\n - add delayedCtrls_->reset() on start\n\n src/libcamera/pipeline/simple/simple.cpp | 39 +++++++++++++++++++++---\n 1 file changed, 35 insertions(+), 4 deletions(-)\n\n--\n2.43.0","diff":"diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 8ac24e6e..a7594c2c 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -277,6 +277,7 @@ public:\n \tstd::list<Entity> entities_;\n \tstd::unique_ptr<CameraSensor> sensor_;\n \tV4L2VideoDevice *video_;\n+\tV4L2Subdevice *eventEmitter_;\n\n \tstd::vector<Configuration> configs_;\n \tstd::map<PixelFormat, std::vector<const Configuration *>> formats_;\n@@ -911,8 +912,11 @@ void SimpleCameraData::ispStatsReady(uint32_t frame, uint32_t bufferId)\n void SimpleCameraData::setSensorControls(const ControlList &sensorControls)\n {\n \tdelayedCtrls_->push(sensorControls);\n-\tControlList ctrls(sensorControls);\n-\tsensor_->setControls(&ctrls);\n+\t/* Directly apply controls now if there is no frameStart signal */\n+\tif (!eventEmitter_) {\n+\t\tControlList ctrls(sensorControls);\n+\t\tsensor_->setControls(&ctrls);\n+\t}\n }\n\n /* Retrieve all source pads connected to a sink pad through active routes. */\n@@ -1299,8 +1303,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n \tdata->delayedCtrls_ =\n \t\tstd::make_unique<DelayedControls>(data->sensor_->device(),\n \t\t\t\t\t\t  params);\n-\tdata->video_->frameStart.connect(data->delayedCtrls_.get(),\n-\t\t\t\t\t &DelayedControls::applyControls);\n\n \tStreamConfiguration inputCfg;\n \tinputCfg.pixelFormat = pipeConfig->captureFormat;\n@@ -1368,6 +1370,28 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n\n \tvideo->bufferReady.connect(data, &SimpleCameraData::imageBufferReady);\n\n+\t/*\n+\t * Enable frame start event on last device in the pipeline\n+\t * that provides the events.\n+\t */\n+\tfor (auto it = data->entities_.rbegin(); it != data->entities_.rend(); ++it) {\n+\t\tV4L2Subdevice *sd = subdev(it->entity);\n+\t\tif (!sd)\n+\t\t\tcontinue;\n+\t\tif (sd->setFrameStartEnabled(true) < 0)\n+\t\t\tcontinue;\n+\n+\t\tLOG(SimplePipeline, Debug)\n+\t\t\t<< \"Using \" << it->entity->name() << \" frameStart signal\";\n+\n+\t\tsd->frameStart.connect(data->delayedCtrls_.get(),\n+\t\t\t\t       &DelayedControls::applyControls);\n+\t\tdata->eventEmitter_ = sd;\n+\t\tbreak;\n+\t}\n+\n+\tdata->delayedCtrls_->reset();\n+\n \tret = video->streamOn();\n \tif (ret < 0) {\n \t\tstop(camera);\n@@ -1400,6 +1424,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera)\n \tSimpleCameraData *data = cameraData(camera);\n \tV4L2VideoDevice *video = data->video_;\n\n+\tif (data->eventEmitter_) {\n+\t\tdata->eventEmitter_->setFrameStartEnabled(false);\n+\t\tdata->eventEmitter_->frameStart.disconnect(data->delayedCtrls_.get(),\n+\t\t\t\t\t\t\t   &DelayedControls::applyControls);\n+\t\tdata->eventEmitter_ = NULL;\n+\t}\n+\n \tif (data->useConversion_) {\n \t\tif (data->converter_)\n \t\t\tdata->converter_->stop();\n","prefixes":["v2"]}