summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2022-05-02 16:42:49 +0200
committerKieran Bingham <kieran.bingham@ideasonboard.com>2022-06-27 10:32:06 +0100
commit1c9dc0fd89cfb32d31e25c4d14501c891d329307 (patch)
treeef74b3507657560e375da02949f38be79a7115f9
parent27cc0a6b58bcca32071cb6ab96e5ee79c75031e5 (diff)
libcamera: v4l2_videodevice: Identify non-zero stream starts
V4L2 Video devices should always start streaming from index zero. Identify and report a warning if they don't, and correct for any offset. Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--include/libcamera/internal/v4l2_videodevice.h1
-rw-r--r--src/libcamera/v4l2_videodevice.cpp15
2 files changed, 16 insertions, 0 deletions
diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h
index 23f37f83..8525acbc 100644
--- a/include/libcamera/internal/v4l2_videodevice.h
+++ b/include/libcamera/internal/v4l2_videodevice.h
@@ -276,6 +276,7 @@ private:
EventNotifier *fdBufferNotifier_;
State state_;
+ std::optional<unsigned int> firstFrame_;
Timer watchdog_;
utils::Duration watchdogDuration_;
diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 430715af..63911339 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1771,6 +1771,19 @@ FrameBuffer *V4L2VideoDevice::dequeueBuffer()
if (V4L2_TYPE_IS_OUTPUT(buf.type))
return buffer;
+ /*
+ * Detect kernel drivers which do not reset the sequence number to zero
+ * on stream start.
+ */
+ if (!firstFrame_) {
+ if (buf.sequence)
+ LOG(V4L2, Warning)
+ << "Zero sequence expected for first frame (got "
+ << buf.sequence << ")";
+ firstFrame_ = buf.sequence;
+ }
+ buffer->metadata_.sequence -= firstFrame_.value();
+
unsigned int numV4l2Planes = multiPlanar ? buf.length : 1;
FrameMetadata &metadata = buffer->metadata_;
@@ -1847,6 +1860,8 @@ int V4L2VideoDevice::streamOn()
{
int ret;
+ firstFrame_.reset();
+
ret = ioctl(VIDIOC_STREAMON, &bufferType_);
if (ret < 0) {
LOG(V4L2, Error)