{"id":22928,"url":"https://patchwork.libcamera.org/api/1.1/patches/22928/?format=json","web_url":"https://patchwork.libcamera.org/patch/22928/","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":"<20250305135256.801351-4-stanislaw.gruszka@linux.intel.com>","date":"2025-03-05T13:52:54","name":"[v6,3/5] pipeline: simple: Enable frame start events","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2b33405506984bec765a8064bcb059160f047aeb","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/22928/mbox/","series":[{"id":5046,"url":"https://patchwork.libcamera.org/api/1.1/series/5046/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5046","date":"2025-03-05T13:52:51","name":"libcamera: start frame events changes","version":6,"mbox":"https://patchwork.libcamera.org/series/5046/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22928/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22928/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 3C295C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Mar 2025 13:53:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E4C5B68823;\n\tWed,  5 Mar 2025 14:53:18 +0100 (CET)","from mgamail.intel.com (mgamail.intel.com [198.175.65.13])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B011568823\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Mar 2025 14:53:16 +0100 (CET)","from orviesa004.jf.intel.com ([10.64.159.144])\n\tby orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n\t05 Mar 2025 05:53:17 -0800","from sgruszka-mobl.ger.corp.intel.com (HELO localhost)\n\t([10.245.112.97]) by orviesa004-auth.jf.intel.com with\n\tESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2025 05:53:14 -0800"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=intel.com header.i=@intel.com\n\theader.b=\"E2wbPZ2w\"; 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=1741182797; x=1772718797;\n\th=from:to:cc:subject:date:message-id:in-reply-to:\n\treferences:mime-version:content-transfer-encoding;\n\tbh=idfQbkN/xGzKp15crcBiqWgyKpcofe1e6bWptz43C2I=;\n\tb=E2wbPZ2wG3o/Gl9RMKCbod3vLsnXQ1RV9YumfOPhim3jlrWoYWa+YWlX\n\tbUDPVS1U5Ss8TUt+CeDB3yGeLaEsGXY17PbMGpy4VjQml0K8S8ZwcgIHE\n\tOPTmq2cPmcpKWHcbNIxATvQ+cRrj7XHJRNSzwxI6eMwSCtgkfgFA3MkBh\n\toBpoMer/5v0UpA0DrEs6tgPGrT+lhE5C7aYOXGvYBEyB6OShDyu2Oupy1\n\t0d+IvX6d5SbGMUkDPly/dKe37d9eo9czt3edm0YwzFhrJWi8KZ2MSZJNn\n\twM3fQQFiL4kriTzckvwG/ntEiLeC8sCZewKDebfsMrHVHDjKV/csEtjHz w==;","X-CSE-ConnectionGUID":["q5j2Qv4wRkmebpK97Pf1jQ==","vM1BAb64SRa6mOUyyw7Qzg=="],"X-CSE-MsgGUID":["Fw/i/xVJQtiI99fUxfzsPA==","6mjgmGQMTXuq3UTCmzgJXQ=="],"X-IronPort-AV":["E=McAfee;i=\"6700,10204,11363\"; a=\"53134786\"","E=Sophos;i=\"6.14,223,1736841600\"; d=\"scan'208\";a=\"53134786\"","E=Sophos;i=\"6.14,223,1736841600\"; d=\"scan'208\";a=\"123735793\""],"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 v6 3/5] pipeline: simple: Enable frame start events","Date":"Wed,  5 Mar 2025 14:52:54 +0100","Message-Id":"<20250305135256.801351-4-stanislaw.gruszka@linux.intel.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20250305135256.801351-1-stanislaw.gruszka@linux.intel.com>","References":"<20250305135256.801351-1-stanislaw.gruszka@linux.intel.com>","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":"The simple pipeline handler uses frame start events to apply sensor\ncontrols through the DelayedControls class. The setSensorControls()\nfunction applies the controls directly, which would result in controls\nbeing applied twice, if it wasn't for the fact that the pipeline handler\nforgot to enable the frame start events in the first place. Those two\nissues cancel each other, but cause controls to always be applied\ndirectly.\n\nFix the issue by only applying controls directly in setSensorControls()\nif no frame start event emitter is available, and by enabling the frame\nstart events in startDevice() otherwise. Disable them in stopDevice()\nfor symmetry.\n\nCo-developed-by: Hans de Goede <hdegoede@redhat.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\nCo-developed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>\n---\n src/libcamera/pipeline/simple/simple.cpp | 49 +++++++++++++++++++++---\n 1 file changed, 43 insertions(+), 6 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 8345a771..7be49017 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 *frameStartEmitter_;\n \n \tstd::vector<Configuration> configs_;\n \tstd::map<PixelFormat, std::vector<const Configuration *>> formats_;\n@@ -579,6 +580,20 @@ int SimpleCameraData::init()\n \n \tproperties_ = sensor_->properties();\n \n+\t/* Find the first subdev that can generate a frame start signal, if any. */\n+\tframeStartEmitter_ = nullptr;\n+\tfor (const Entity &entity : entities_) {\n+\t\tV4L2Subdevice *sd = pipe->subdev(entity.entity);\n+\t\tif (!sd || !sd->supportsFrameStartEvent())\n+\t\t\tcontinue;\n+\n+\t\tLOG(SimplePipeline, Debug)\n+\t\t\t<< \"Using frameStart signal from '\"\n+\t\t\t<< entity.entity->name() << \"'\";\n+\t\tframeStartEmitter_ = sd;\n+\t\tbreak;\n+\t}\n+\n \treturn 0;\n }\n \n@@ -897,8 +912,18 @@ 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/*\n+         * Directly apply controls now if there is no frameStart signal.\n+\t *\n+\t * \\todo Applying controls directly not only increases the risk of\n+\t * applying them to the wrong frame (or across a frame boundary),\n+\t * but it also bypasses delayedCtrls_, creating AGC regulation issues.\n+\t * Both problems should be fixed.\n+\t */\n+\tif (!frameStartEmitter_) {\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@@ -1323,6 +1348,7 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n {\n \tSimpleCameraData *data = cameraData(camera);\n \tV4L2VideoDevice *video = data->video_;\n+\tV4L2Subdevice *frameStartEmitter = data->frameStartEmitter_;\n \tint ret;\n \n \tconst MediaPad *pad = acquirePipeline(data);\n@@ -1352,8 +1378,15 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n \n \tvideo->bufferReady.connect(data, &SimpleCameraData::imageBufferReady);\n \n-\tdata->video_->frameStart.connect(data->delayedCtrls_.get(),\n-\t\t\t\t\t &DelayedControls::applyControls);\n+\tif (frameStartEmitter) {\n+\t\tret = frameStartEmitter->setFrameStartEnabled(true);\n+\t\tif (ret) {\n+\t\t\tstop(camera);\n+\t\t\treturn ret;\n+\t\t}\n+\t\tframeStartEmitter->frameStart.connect(data->delayedCtrls_.get(),\n+\t\t\t\t\t\t      &DelayedControls::applyControls);\n+\t}\n \n \tret = video->streamOn();\n \tif (ret < 0) {\n@@ -1386,9 +1419,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera)\n {\n \tSimpleCameraData *data = cameraData(camera);\n \tV4L2VideoDevice *video = data->video_;\n+\tV4L2Subdevice *frameStartEmitter = data->frameStartEmitter_;\n \n-\tdata->video_->frameStart.disconnect(data->delayedCtrls_.get(),\n-\t\t\t\t\t    &DelayedControls::applyControls);\n+\tif (frameStartEmitter) {\n+\t\tframeStartEmitter->setFrameStartEnabled(false);\n+\t\tframeStartEmitter->frameStart.disconnect(data->delayedCtrls_.get(),\n+\t\t\t\t\t\t\t &DelayedControls::applyControls);\n+\t}\n \n \tif (data->useConversion_) {\n \t\tif (data->converter_)\n","prefixes":["v6","3/5"]}