[{"id":33903,"web_url":"https://patchwork.libcamera.org/comment/33903/","msgid":"<174366787246.4065590.7805882063805422131@ping.linuxembedded.co.uk>","date":"2025-04-03T08:11:12","subject":"Re: [PATCH v7 3/5] pipeline: simple: Enable frame start events","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stanislaw Gruszka (2025-04-03 08:45:49)\n> The simple pipeline handler uses frame start events to apply sensor\n> controls through the DelayedControls class. The setSensorControls()\n> function applies the controls directly, which would result in controls\n> being applied twice, if it wasn't for the fact that the pipeline handler\n> forgot to enable the frame start events in the first place. Those two\n> issues cancel each other, but cause controls to always be applied\n> directly.\n> \n> Fix the issue by only applying controls directly in setSensorControls()\n> if no frame start event emitter is available, and by enabling the frame\n> start events in startDevice() otherwise. Disable them in stopDevice()\n> for symmetry.\n> \n> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> # v6\n> Co-developed-by: Hans de Goede <hdegoede@redhat.com>\n> Signed-off-by: Hans de Goede <hdegoede@redhat.com>\n> Co-developed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-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(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 06e805d89caa..c97904076b63 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -327,6 +327,7 @@ public:\n>         std::list<Entity> entities_;\n>         std::unique_ptr<CameraSensor> sensor_;\n>         V4L2VideoDevice *video_;\n> +       V4L2Subdevice *frameStartEmitter_;\n>  \n>         std::vector<Configuration> configs_;\n>         std::map<PixelFormat, std::vector<const Configuration *>> formats_;\n> @@ -633,6 +634,20 @@ int SimpleCameraData::init()\n>  \n>         properties_ = sensor_->properties();\n>  \n> +       /* Find the first subdev that can generate a frame start signal, if any. */\n> +       frameStartEmitter_ = nullptr;\n> +       for (const Entity &entity : entities_) {\n> +               V4L2Subdevice *sd = pipe->subdev(entity.entity);\n> +               if (!sd || !sd->supportsFrameStartEvent())\n> +                       continue;\n> +\n> +               LOG(SimplePipeline, Debug)\n> +                       << \"Using frameStart signal from '\"\n> +                       << entity.entity->name() << \"'\";\n> +               frameStartEmitter_ = sd;\n> +               break;\n> +       }\n> +\n>         return 0;\n>  }\n>  \n> @@ -983,8 +998,18 @@ void SimpleCameraData::metadataReady(uint32_t frame, const ControlList &metadata\n>  void SimpleCameraData::setSensorControls(const ControlList &sensorControls)\n>  {\n>         delayedCtrls_->push(sensorControls);\n> -       ControlList ctrls(sensorControls);\n> -       sensor_->setControls(&ctrls);\n> +       /*\n> +         * Directly apply controls now if there is no frameStart signal.\n\nSmallest nit on whitespace here that I'll fix up when applying.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n> +        *\n> +        * \\todo Applying controls directly not only increases the risk of\n> +        * applying them to the wrong frame (or across a frame boundary),\n> +        * but it also bypasses delayedCtrls_, creating AGC regulation issues.\n> +        * Both problems should be fixed.\n> +        */\n> +       if (!frameStartEmitter_) {\n> +               ControlList ctrls(sensorControls);\n> +               sensor_->setControls(&ctrls);\n> +       }\n>  }\n>  \n>  /* Retrieve all source pads connected to a sink pad through active routes. */\n> @@ -1409,6 +1434,7 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n>  {\n>         SimpleCameraData *data = cameraData(camera);\n>         V4L2VideoDevice *video = data->video_;\n> +       V4L2Subdevice *frameStartEmitter = data->frameStartEmitter_;\n>         int ret;\n>  \n>         const MediaPad *pad = acquirePipeline(data);\n> @@ -1438,8 +1464,15 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n>  \n>         video->bufferReady.connect(data, &SimpleCameraData::imageBufferReady);\n>  \n> -       data->video_->frameStart.connect(data->delayedCtrls_.get(),\n> -                                        &DelayedControls::applyControls);\n> +       if (frameStartEmitter) {\n> +               ret = frameStartEmitter->setFrameStartEnabled(true);\n> +               if (ret) {\n> +                       stop(camera);\n> +                       return ret;\n> +               }\n> +               frameStartEmitter->frameStart.connect(data->delayedCtrls_.get(),\n> +                                                     &DelayedControls::applyControls);\n> +       }\n>  \n>         ret = video->streamOn();\n>         if (ret < 0) {\n> @@ -1472,9 +1505,13 @@ void SimplePipelineHandler::stopDevice(Camera *camera)\n>  {\n>         SimpleCameraData *data = cameraData(camera);\n>         V4L2VideoDevice *video = data->video_;\n> +       V4L2Subdevice *frameStartEmitter = data->frameStartEmitter_;\n>  \n> -       data->video_->frameStart.disconnect(data->delayedCtrls_.get(),\n> -                                           &DelayedControls::applyControls);\n> +       if (frameStartEmitter) {\n> +               frameStartEmitter->setFrameStartEnabled(false);\n> +               frameStartEmitter->frameStart.disconnect(data->delayedCtrls_.get(),\n> +                                                        &DelayedControls::applyControls);\n> +       }\n>  \n>         if (data->useConversion_) {\n>                 if (data->converter_)\n> -- \n> 2.43.0\n>","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 A342EC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  3 Apr 2025 08:11:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42DAE6899C;\n\tThu,  3 Apr 2025 10:11:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CC3F68967\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Apr 2025 10:11:15 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EBACD105D;\n\tThu,  3 Apr 2025 10:09:21 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"H5xO+/s6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743667762;\n\tbh=8tSUehGiuN+9pL56STnnKZ0MHn+Up/cZVHwZCvh5d6I=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=H5xO+/s6B8U4qbMILU3Nqv9izNH66E6mnnj9W+L60ZNcr8tfdeRASaVlYN5u1ubhB\n\tqH9/ZQ9QUw45/ZpmisH3Qu4Y/mvxgdHI6CreH30dtkQycL+WuZjSXyzutH3ydHwfTK\n\tm1FR1ju8Zfyx4h0cYHmIKrdycutDQaMjPGiNmZBs=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250403074551.263496-4-stanislaw.gruszka@linux.intel.com>","References":"<20250403074551.263496-1-stanislaw.gruszka@linux.intel.com>\n\t<20250403074551.263496-4-stanislaw.gruszka@linux.intel.com>","Subject":"Re: [PATCH v7 3/5] pipeline: simple: Enable frame start events","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, Hans de Goede <hdegoede@redhat.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tSakari Ailus <sakari.ailus@linux.intel.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>","To":"Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 03 Apr 2025 09:11:12 +0100","Message-ID":"<174366787246.4065590.7805882063805422131@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]