[{"id":32976,"web_url":"https://patchwork.libcamera.org/comment/32976/","msgid":"<173643944247.2992722.6661137709264404813@ping.linuxembedded.co.uk>","date":"2025-01-09T16:17:22","subject":"Re: [PATCH v3 4/7] pipeline: rpi:: Add wallclock timestamp support","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting David Plowman (2025-01-09 14:32:08)\n> A ClockRecovery object is added for derived classes to use, and\n> wallclock timetamps are copied into the request metadata for\n> applications.\n> \n> In the derived class, wallclock timestamps are derived corresponding\n> to the sensor timestamp, and made available to the base pipeline\n> handler class.\n\nThanks, this looks like a clear and easy way to use this and to\nfacilitate implementing the same in all pipeline handlers.\n\nBut we'll deal with other pipeline handlers on top.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  src/libcamera/pipeline/rpi/common/pipeline_base.cpp |  5 +++++\n>  src/libcamera/pipeline/rpi/common/pipeline_base.h   |  3 +++\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp              | 10 ++++++++--\n>  3 files changed, 16 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 4b147fdb..56f3c4df 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -686,6 +686,9 @@ int PipelineHandlerBase::start(Camera *camera, const ControlList *controls)\n>                 return ret;\n>         }\n>  \n> +       /* A good moment to add an initial clock sample. */\n> +       data->wallClockRecovery_.addSample();\n> +\n>         /*\n>          * Reset the delayed controls with the gain and exposure values set by\n>          * the IPA.\n> @@ -1510,6 +1513,8 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request\n>  {\n>         request->metadata().set(controls::SensorTimestamp,\n>                                 bufferControls.get(controls::SensorTimestamp).value_or(0));\n> +       request->metadata().set(controls::FrameWallClock,\n> +                               bufferControls.get(controls::FrameWallClock).value_or(0));\n>  \n>         if (cropParams_.size()) {\n>                 std::vector<Rectangle> crops;\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> index aae0c2f3..ca706bf3 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> @@ -20,6 +20,7 @@\n>  #include \"libcamera/internal/bayer_format.h\"\n>  #include \"libcamera/internal/camera.h\"\n>  #include \"libcamera/internal/camera_sensor.h\"\n> +#include \"libcamera/internal/clock_recovery.h\"\n>  #include \"libcamera/internal/framebuffer.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/media_object.h\"\n> @@ -177,6 +178,8 @@ public:\n>  \n>         Config config_;\n>  \n> +       ClockRecovery wallClockRecovery_;\n> +\n>  protected:\n>         void fillRequestMetadata(const ControlList &bufferControls,\n>                                  Request *request);\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index fd8d84b1..3d8c65c6 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -781,9 +781,15 @@ void Vc4CameraData::unicamBufferDequeue(FrameBuffer *buffer)\n>                 auto [ctrl, delayContext] = delayedCtrls_->get(buffer->metadata().sequence);\n>                 /*\n>                  * Add the frame timestamp to the ControlList for the IPA to use\n> -                * as it does not receive the FrameBuffer object.\n> +                * as it does not receive the FrameBuffer object. Also derive a\n> +                * corresponding wallclock value.\n>                  */\n> -               ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp);\n> +               wallClockRecovery_.addSample();\n> +               uint64_t sensorTimestamp = buffer->metadata().timestamp;\n> +               uint64_t wallClockTimestamp = wallClockRecovery_.getOutput(sensorTimestamp / 1000);\n> +\n> +               ctrl.set(controls::SensorTimestamp, sensorTimestamp);\n> +               ctrl.set(controls::FrameWallClock, wallClockTimestamp);\n>                 bayerQueue_.push({ buffer, std::move(ctrl), delayContext });\n>         } else {\n>                 embeddedQueue_.push(buffer);\n> -- \n> 2.39.5\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 13AA0C32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jan 2025 16:17:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1FCA1684EA;\n\tThu,  9 Jan 2025 17:17:27 +0100 (CET)","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 5807A61880\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jan 2025 17:17:25 +0100 (CET)","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 88E65110F;\n\tThu,  9 Jan 2025 17:16:31 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Hsjjzp9s\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736439391;\n\tbh=0ivFcw863cH5DID5JxaPcDzsPb92t+z/vmX5xx4UZy4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Hsjjzp9sTRDP1HVp53NiZU6VpB4fYfDMOAIYKFuq6Qj7RxnIWsftfDqlFTr6GA3Ef\n\tCIL7n4h/PLnbYHkauVdr4MWjFJIYtz1XkdVUjulcBYZzWrDVIf5DnsIl6qs/V0szfg\n\ta4HNQGxyrBDif+XjBSPM4K6q64t4VkrAmurucOAI=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250109143211.11939-5-david.plowman@raspberrypi.com>","References":"<20250109143211.11939-1-david.plowman@raspberrypi.com>\n\t<20250109143211.11939-5-david.plowman@raspberrypi.com>","Subject":"Re: [PATCH v3 4/7] pipeline: rpi:: Add wallclock timestamp support","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"David Plowman <david.plowman@raspberrypi.com>","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 09 Jan 2025 16:17:22 +0000","Message-ID":"<173643944247.2992722.6661137709264404813@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>"}},{"id":33088,"web_url":"https://patchwork.libcamera.org/comment/33088/","msgid":"<CAEmqJPrDV6nmne8Vvc8okJWEoqi+ROAe+Cm+FDJcjhYzo-0csA@mail.gmail.com>","date":"2025-01-17T09:08:02","subject":"Re: [PATCH v3 4/7] pipeline: rpi:: Add wallclock timestamp support","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nOn Thu, 9 Jan 2025 at 14:32, David Plowman\n<david.plowman@raspberrypi.com> wrote:\n>\n> A ClockRecovery object is added for derived classes to use, and\n> wallclock timetamps are copied into the request metadata for\n\ns/timetamps/timestamps/\n\n> applications.\n>\n> In the derived class, wallclock timestamps are derived corresponding\n> to the sensor timestamp, and made available to the base pipeline\n> handler class.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  src/libcamera/pipeline/rpi/common/pipeline_base.cpp |  5 +++++\n>  src/libcamera/pipeline/rpi/common/pipeline_base.h   |  3 +++\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp              | 10 ++++++++--\n>  3 files changed, 16 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 4b147fdb..56f3c4df 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -686,6 +686,9 @@ int PipelineHandlerBase::start(Camera *camera, const ControlList *controls)\n>                 return ret;\n>         }\n>\n> +       /* A good moment to add an initial clock sample. */\n> +       data->wallClockRecovery_.addSample();\n> +\n>         /*\n>          * Reset the delayed controls with the gain and exposure values set by\n>          * the IPA.\n> @@ -1510,6 +1513,8 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request\n>  {\n>         request->metadata().set(controls::SensorTimestamp,\n>                                 bufferControls.get(controls::SensorTimestamp).value_or(0));\n> +       request->metadata().set(controls::FrameWallClock,\n> +                               bufferControls.get(controls::FrameWallClock).value_or(0));\n>\n>         if (cropParams_.size()) {\n>                 std::vector<Rectangle> crops;\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> index aae0c2f3..ca706bf3 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> @@ -20,6 +20,7 @@\n>  #include \"libcamera/internal/bayer_format.h\"\n>  #include \"libcamera/internal/camera.h\"\n>  #include \"libcamera/internal/camera_sensor.h\"\n> +#include \"libcamera/internal/clock_recovery.h\"\n>  #include \"libcamera/internal/framebuffer.h\"\n>  #include \"libcamera/internal/media_device.h\"\n>  #include \"libcamera/internal/media_object.h\"\n> @@ -177,6 +178,8 @@ public:\n>\n>         Config config_;\n>\n> +       ClockRecovery wallClockRecovery_;\n> +\n>  protected:\n>         void fillRequestMetadata(const ControlList &bufferControls,\n>                                  Request *request);\n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index fd8d84b1..3d8c65c6 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -781,9 +781,15 @@ void Vc4CameraData::unicamBufferDequeue(FrameBuffer *buffer)\n>                 auto [ctrl, delayContext] = delayedCtrls_->get(buffer->metadata().sequence);\n>                 /*\n>                  * Add the frame timestamp to the ControlList for the IPA to use\n> -                * as it does not receive the FrameBuffer object.\n> +                * as it does not receive the FrameBuffer object. Also derive a\n> +                * corresponding wallclock value.\n>                  */\n> -               ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp);\n> +               wallClockRecovery_.addSample();\n> +               uint64_t sensorTimestamp = buffer->metadata().timestamp;\n> +               uint64_t wallClockTimestamp = wallClockRecovery_.getOutput(sensorTimestamp / 1000);\n> +\n> +               ctrl.set(controls::SensorTimestamp, sensorTimestamp);\n> +               ctrl.set(controls::FrameWallClock, wallClockTimestamp);\n>                 bayerQueue_.push({ buffer, std::move(ctrl), delayContext });\n>         } else {\n>                 embeddedQueue_.push(buffer);\n> --\n> 2.39.5\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 EDC2CBD7D8\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jan 2025 09:08:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B234768549;\n\tFri, 17 Jan 2025 10:08:39 +0100 (CET)","from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com\n\t[IPv6:2607:f8b0:4864:20::b30])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDE966851D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2025 10:08:37 +0100 (CET)","by mail-yb1-xb30.google.com with SMTP id\n\t3f1490d57ef6-e3a0d9aab47so296176276.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2025 01:08:37 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"HNIiR7LP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1737104917; x=1737709717;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=6M4CI4eS+TneM7UeLg2dxp0MmRz9MGMZnIitGt+kYAI=;\n\tb=HNIiR7LPZMh31KwyRBY2gh5gULUDnT5ncy6rz/RNAbnlIQ+mKuCGHn6UI1XJSB7XBr\n\tYUzeaVnm5nEIBOTxxlLaN1/57C6N4MZb+gb9KLvMFMJAorLgPDBXdqOwAXagkuzIBAFX\n\tuHdi7PWtkBlJT5l6se8+fPP9WjAngqX2CM4spjDTPO5YGXnzLr4xEsEpw0YtdMtbegAJ\n\tkjcAhTxbl5F+yhadHY0pN7iV+ALL77zCFSBuI0oBUosmM/yJDoiPsrfKhr2WU4n5/WD8\n\tn4ItzBS/ucibP0mnHqlTJnN1NDm1MWP99B2DUev+P2otQdosysz8eR3o5iFh/o5rbBl6\n\thrbA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1737104917; x=1737709717;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=6M4CI4eS+TneM7UeLg2dxp0MmRz9MGMZnIitGt+kYAI=;\n\tb=ofK2VkCHraiS6lViTxFi3i2RYiLd4+TPSPnyTyr6R6AVQ0POYLRfAErzbarw3JHCAr\n\tx7hvDHBuuw+sDZU9Sfq9HAI8oC/QBjj0YLBTTIrM0FLaDEhUnwai5gg2V2j9zGhswJb2\n\tjBdFjLhtysybVVNzkd+CKl2Up6i2Evm0eylgf0QmpEJKazabAUhEWZpD+sqRY4x1SoZf\n\tAe4nmrSOp57gK3seA0QJuL/LxLQex3MOBg8nlqTTd+BiJwlmKRAOclCBhFNQMkmXtUpQ\n\tXmBjng2X1+ZyoknTgteeh38a9bck3SVCUe/G+VoiiLJMp2/iRlFl7XwcPcvWNO2NrKSX\n\tzn8g==","X-Gm-Message-State":"AOJu0YwPQ+QH8UaEiEm7s9hFfobM0+mw8nlp+ma+Tf2MOHaGILgYIFm6\n\tigW59gZV0uGhZlEBJ7qfMNMb6f48YVPWGRhdrD2wWK6u9mFwSKuKrqvPLi3BF771WhiZ4UhL469\n\tAdIyFJfDoacyBxiu8s0m4HADpdFvDKyzai5czAQ==","X-Gm-Gg":"ASbGnct+QMSyLCgXa6JBzoJeOUfZt1xFeizfNQZhZsMpUjfWtvxt+3CRvyjhjehXzUS\n\tAM3XpdNt3EVrxaP9PPMxPbIDWavgGllxdBHM7GZQUas6ixrDohESdIevAikyGOPKGPx/Wtw==","X-Google-Smtp-Source":"AGHT+IGx5+9I2NcJ9yV5lIgokVq6SokmjfcuF7vkzC/wjlzTWgZTQTf9VxLjwEm8Kt85kgd4H+6XHwnGSRVrUhEE5vY=","X-Received":"by 2002:a05:6902:1023:b0:e57:87b3:d2f1 with SMTP id\n\t3f1490d57ef6-e57b1351a1dmr496991276.8.1737104916852; Fri, 17 Jan 2025\n\t01:08:36 -0800 (PST)","MIME-Version":"1.0","References":"<20250109143211.11939-1-david.plowman@raspberrypi.com>\n\t<20250109143211.11939-5-david.plowman@raspberrypi.com>","In-Reply-To":"<20250109143211.11939-5-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 17 Jan 2025 09:08:02 +0000","X-Gm-Features":"AbW1kvZj6-_ZvVpOTfI5UsShUJ2ewpUjHdd27IujThlDFXXGAQi25SMV1sBLFzk","Message-ID":"<CAEmqJPrDV6nmne8Vvc8okJWEoqi+ROAe+Cm+FDJcjhYzo-0csA@mail.gmail.com>","Subject":"Re: [PATCH v3 4/7] pipeline: rpi:: Add wallclock timestamp support","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","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>"}}]