<div dir="ltr"><div dir="ltr">Hi Kieran,<div><br></div><div>Thank you for your patch.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 6 Dec 2021 at 23:39, Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com">kieran.bingham@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The SensorSequence metadata provides the sequence number associated with<br>
the image capture directly.<br>
<br>
While we already report sequence numbers in the metadata of the buffers,<br>
this can lead to mis-leading parsing of those sequence numbers which may<br>
be purely monotonic sequences from an ISP, and not represent the true<br>
sequence counts from a capture device.<br>
<br>
Use the newly added SensorSequence metadata control and populate<br>
completed requests with the sequence number from the appropriate stream.<br>
For ISP based devices, such as the IPU3, RPi, and RkISP1, this comes<br>
from the CSI2 receiver capture device, while for the Simple pipeline and<br>
the UVC Video pipeline, this comes from the single video capture device.<br>
<br>
Signed-off-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 src/libcamera/pipeline/ipu3/ipu3.cpp               |  4 +++-<br>
 src/libcamera/pipeline/raspberrypi/raspberrypi.cpp |  3 +++<br>
 src/libcamera/pipeline/rkisp1/rkisp1.cpp           |  4 +++-<br>
 src/libcamera/pipeline/simple/simple.cpp           | 12 ++++++++----<br>
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp       |  2 ++<br>
 5 files changed, 19 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp<br>
index 313220624aff..a7f35840afbb 100644<br>
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp<br>
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp<br>
@@ -1372,13 +1372,15 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)<br>
        }<br>
<br>
        /*<br>
-        * Record the sensor's timestamp in the request metadata.<br>
+        * Record the sensor's timestamp and sequence in the request metadata.<br>
         *<br>
         * \todo The sensor timestamp should be better estimated by connecting<br>
         * to the V4L2Device::frameStart signal.<br>
         */<br>
        request->metadata().set(controls::SensorTimestamp,<br>
                                buffer->metadata().timestamp);<br>
+       request->metadata().set(controls::SensorSequence,<br>
+                               buffer->metadata().sequence);<br>
<br>
        info->effectiveSensorControls = delayedCtrls_->get(buffer->metadata().sequence);<br>
<br>
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
index 321b72adbbf7..f458587a8920 100644<br>
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
@@ -1549,6 +1549,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)<br>
                 * as it does not receive the FrameBuffer object.<br>
                 */<br>
                ctrl.set(controls::SensorTimestamp, buffer->metadata().timestamp);<br>
+               ctrl.set(controls::SensorSequence, buffer->metadata().sequence);<br>
                bayerQueue_.push({ buffer, std::move(ctrl) });<br>
        } else {<br>
                embeddedQueue_.push(buffer);<br>
@@ -1786,6 +1787,8 @@ void RPiCameraData::fillRequestMetadata(const ControlList &bufferControls,<br>
 {<br>
        request->metadata().set(controls::SensorTimestamp,<br>
                                bufferControls.get(controls::SensorTimestamp));<br>
+       request->metadata().set(controls::SensorSequence,<br>
+                               bufferControls.get(controls::SensorSequence));<br>
<br>
        request->metadata().set(controls::ScalerCrop, scalerCrop_);<br>
 }<br>
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp<br>
index 36ef6a02ae90..27592e473c14 100644<br>
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp<br>
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp<br>
@@ -1077,13 +1077,15 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer)<br>
        Request *request = buffer->request();<br>
<br>
        /*<br>
-        * Record the sensor's timestamp in the request metadata.<br>
+        * Record the sensor's timestamp and sequence in the request metadata.<br>
         *<br>
         * \todo The sensor timestamp should be better estimated by connecting<br>
         * to the V4L2Device::frameStart signal.<br>
         */<br>
        request->metadata().set(controls::SensorTimestamp,<br>
                                buffer->metadata().timestamp);<br>
+       request->metadata().set(controls::SensorSequence,<br>
+                               buffer->metadata().sequence);<br>
<br>
        completeBuffer(request, buffer);<br>
        tryCompleteRequest(request);<br>
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp<br>
index 701fb4be0b71..4c5d9c0b9919 100644<br>
--- a/src/libcamera/pipeline/simple/simple.cpp<br>
+++ b/src/libcamera/pipeline/simple/simple.cpp<br>
@@ -667,9 +667,10 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer)<br>
        }<br>
<br>
        /*<br>
-        * Record the sensor's timestamp in the request metadata. The request<br>
-        * needs to be obtained from the user-facing buffer, as internal<br>
-        * buffers are free-wheeling and have no request associated with them.<br>
+        * Record the sensor's timestamp and sequence in the request metadata.<br>
+        * The request needs to be obtained from the user-facing buffer, as<br>
+        * internal buffers are free-wheeling and have no request associated<br>
+        * with them.<br>
         *<br>
         * \todo The sensor timestamp should be better estimated by connecting<br>
         * to the V4L2Device::frameStart signal if the platform provides it.<br>
@@ -686,9 +687,12 @@ void SimpleCameraData::bufferReady(FrameBuffer *buffer)<br>
                }<br>
        }<br>
<br>
-       if (request)<br>
+       if (request) {<br>
                request->metadata().set(controls::SensorTimestamp,<br>
                                        buffer->metadata().timestamp);<br>
+               request->metadata().set(controls::SensorSequence,<br>
+                                       buffer->metadata().sequence);<br>
+       }<br>
<br>
        /*<br>
         * Queue the captured and the request buffer to the converter if format<br>
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp<br>
index 264f5370cf32..f5fab3b69e6d 100644<br>
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp<br>
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp<br>
@@ -666,6 +666,8 @@ void UVCCameraData::bufferReady(FrameBuffer *buffer)<br>
        /* \todo Use the UVC metadata to calculate a more precise timestamp */<br>
        request->metadata().set(controls::SensorTimestamp,<br>
                                buffer->metadata().timestamp);<br>
+       request->metadata().set(controls::SensorSequence,<br>
+                               buffer->metadata().sequence);<br>
<br>
        pipe()->completeBuffer(request, buffer);<br>
        pipe()->completeRequest(request);<br>
-- <br>
2.30.2<br>
<br>
</blockquote></div></div>