From patchwork Mon Jun 13 10:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 16208 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 68D98BD808 for ; Mon, 13 Jun 2022 10:34:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9CDE565635; Mon, 13 Jun 2022 12:34:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655116496; bh=fmZJoXDqVd5bKTQXCh6+VNo1JQNhRaCOaS2yJkt2K0Q=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=m2pak3cjxKCSmEUOBuK0+ET7h63NzKBJT2Mvn/0VCju1gR6jeeUy5h0yA9xM15P8V vZXo0E8nqwdTNB/HPRh7KtsNT+FjmDVevoH6RJIKNDBckpdBeYFTUba1IL/FNpHhFR nFtxv2GPz3S1kRHFz1OJManfh9OV0Hy4a6NiIGTiuupAL4BMB9YqmTTavBXv68+JHV eTmBva1w0J1rBfbWsRQ9qDT+nxREmpdAudxNGFoMT44LI9R9EC5q5IMZpvikKA/Ece 77krCoLHyCbdi2xQVWtAMS7okXVBYnx8OSp/p2+KLPnERVwIFmhz01gO76XSItwoOS /7c3/6lpmNXKQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 75BBE600F1 for ; Mon, 13 Jun 2022 12:34:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="emAQoGXZ"; dkim-atps=neutral Received: from Q.ksquared.org.uk.beta.tailscale.net (unknown [178.237.134.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DCBDD268; Mon, 13 Jun 2022 12:34:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655116495; bh=fmZJoXDqVd5bKTQXCh6+VNo1JQNhRaCOaS2yJkt2K0Q=; h=From:To:Cc:Subject:Date:From; b=emAQoGXZya9LlIliCJChewuq77UdlfYNBg/C477npzTj/fpz7BJGCg+CqPYWmEg2p 0y0/QhFQk30CFPcEMm5o7HV+oXFuKODmsuJ+eVa72hwIki7Zl60tA97ZdsoSr44+KN e6NBNXD1OaniNZ2e2x8rbvRLP6cdfTgx9uAQA74Y= To: libcamera devel Date: Mon, 13 Jun 2022 12:35:28 +0200 Message-Id: <20220613103528.226610-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Identify non-zero stream starts X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" V4L2 Video devices should always start streaming from index zero. Identify and report a warning if they don't, and correct for any offset. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- I'm not yet sure if the Warning print is perhaps just unhelpful. It doesn't really affect us if we have this work around in - so we can be silent, and I'm not yet sure if V4L2 has any 'requirement' that it should start at 0 at every stream on. include/libcamera/internal/v4l2_videodevice.h | 1 + src/libcamera/v4l2_videodevice.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index 23f37f83f8e2..8525acbc558d 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 firstFrame_; Timer watchdog_; utils::Duration watchdogDuration_; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 430715afd554..63911339f96e 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)