{"id":25455,"url":"https://patchwork.libcamera.org/api/patches/25455/?format=json","web_url":"https://patchwork.libcamera.org/patch/25455/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251210133704.2711629-2-barnabas.pocze@ideasonboard.com>","date":"2025-12-10T13:37:03","name":"[RFC,v1,1/2] libcamera: pipeline: uvcvideo: Report `FrameDuration`","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"540df61154dbd829e29a82bbbc659177b11659b5","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25455/mbox/","series":[{"id":5648,"url":"https://patchwork.libcamera.org/api/series/5648/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5648","date":"2025-12-10T13:37:02","name":"libcamera: pipeline: uvcvideo: FrameDurationLimits","version":1,"mbox":"https://patchwork.libcamera.org/series/5648/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25455/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25455/checks/","tags":{},"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 7CBB4C326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 10 Dec 2025 13:37:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7876A61463;\n\tWed, 10 Dec 2025 14:37:12 +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 7FA7E6143E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Dec 2025 14:37:10 +0100 (CET)","from pb-laptop.local (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3AF7210C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Dec 2025 14:37:07 +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=\"YL7R62NM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1765373827;\n\tbh=cubgMvdtQ+KzRQ8LxYpxreucREysBuJ9Xb5azFQkSMI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=YL7R62NMTtwW7lNcPU5dfuqh0QBJdPEfzRGXvkG2qsYaMkWxrYgA48fP+5yIluzcX\n\tv6uzWaMMWRka1zV7Spi/2iJC0pdkti9F06/8VB5kDqxw2c4XIrBZWJ+l1dueQ8Qado\n\tePlBelMQ39gsRoOL3mjoPtJXPKKz5gGPvc8qFBww=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[RFC PATCH v1 1/2] libcamera: pipeline: uvcvideo: Report\n\t`FrameDuration`","Date":"Wed, 10 Dec 2025 14:37:03 +0100","Message-ID":"<20251210133704.2711629-2-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20251210133704.2711629-1-barnabas.pocze@ideasonboard.com>","References":"<20251210133704.2711629-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","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>"},"content":"If available, query the time-per-frame parameter from the device after\nstarting, and report it in the metadata.\n\nThe reported frame duration remains constant during a particular streaming\nsession, and will most likely not accurately reflect the actual frame\nduration for any given frame, depending on the manual exposure time, or if\n`V4L2_CID_EXPOSURE_AUTO_PRIORITY` or similar is in effect. But at least it\nshows the \"intended\" frame duration.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/internal/v4l2_videodevice.h |  2 +\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  | 13 +++++\n src/libcamera/v4l2_videodevice.cpp            | 55 +++++++++++++++++++\n 3 files changed, 70 insertions(+)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 57db0036db..82d98184ed 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -208,6 +208,8 @@ public:\n \tint setFormat(V4L2DeviceFormat *format);\n \tFormats formats(uint32_t code = 0);\n \n+\tint getFrameInterval(std::chrono::microseconds *interval);\n+\n \tint getSelection(unsigned int target, Rectangle *rect);\n \tint setSelection(unsigned int target, Rectangle *rect);\n \ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex cb8cc82dff..3f98e8ece0 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -60,6 +60,7 @@ public:\n \n \tstd::optional<v4l2_exposure_auto_type> autoExposureMode_;\n \tstd::optional<v4l2_exposure_auto_type> manualExposureMode_;\n+\tstd::optional<std::chrono::microseconds> timePerFrame_;\n \n private:\n \tbool generateId();\n@@ -295,6 +296,8 @@ int PipelineHandlerUVC::start(Camera *camera, const ControlList *controls)\n \tUVCCameraData *data = cameraData(camera);\n \tunsigned int count = data->stream_.configuration().bufferCount;\n \n+\tdata->timePerFrame_.reset();\n+\n \tint ret = data->video_->importBuffers(count);\n \tif (ret < 0)\n \t\treturn ret;\n@@ -309,6 +312,13 @@ int PipelineHandlerUVC::start(Camera *camera, const ControlList *controls)\n \tif (ret < 0)\n \t\tgoto err_release_buffers;\n \n+\tif (!data->timePerFrame_) {\n+\t\tstd::chrono::microseconds interval;\n+\t\tret = data->video_->getFrameInterval(&interval);\n+\t\tif (ret == 0)\n+\t\t\tdata->timePerFrame_ = interval;\n+\t}\n+\n \treturn 0;\n \n err_release_buffers:\n@@ -898,6 +908,9 @@ void UVCCameraData::imageBufferReady(FrameBuffer *buffer)\n \trequest->metadata().set(controls::SensorTimestamp,\n \t\t\t\tbuffer->metadata().timestamp);\n \n+\tif (timePerFrame_)\n+\t\trequest->metadata().set(controls::FrameDuration, timePerFrame_->count());\n+\n \tpipe()->completeBuffer(request, buffer);\n \tpipe()->completeRequest(request);\n }\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 25b61d049a..3836dabef3 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1147,6 +1147,61 @@ V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code)\n \treturn formats;\n }\n \n+namespace {\n+\n+std::chrono::microseconds\n+v4l2FractionToMs(const v4l2_fract &f)\n+{\n+\tauto seconds = std::chrono::duration<float>(f.numerator) / f.denominator;\n+\treturn std::chrono::duration_cast<std::chrono::microseconds>(seconds);\n+}\n+\n+}\n+\n+/**\n+ * \\brief Retrieve the frame interval set on the V4L2 video device\n+ * \\param[out] interval The frame interval applied on the device\n+ *\n+ * Retrieve the current time-per-frame parameter from the device.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2VideoDevice::getFrameInterval(std::chrono::microseconds *interval)\n+{\n+\tconst v4l2_fract *frameInterval = nullptr;\n+\tv4l2_streamparm sparm = {};\n+\tuint32_t caps = 0;\n+\n+\tsparm.type = bufferType_;\n+\n+\tint ret = ioctl(VIDIOC_G_PARM, &sparm);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tswitch (sparm.type) {\n+\tcase V4L2_BUF_TYPE_VIDEO_CAPTURE:\n+\tcase V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:\n+\t\tframeInterval = &sparm.parm.capture.timeperframe;\n+\t\tcaps = sparm.parm.capture.capability;\n+\t\tbreak;\n+\tcase V4L2_BUF_TYPE_VIDEO_OUTPUT:\n+\tcase V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:\n+\t\tframeInterval = &sparm.parm.output.timeperframe;\n+\t\tcaps = sparm.parm.output.capability;\n+\t\tbreak;\n+\t}\n+\n+\tif (!frameInterval)\n+\t\treturn -EINVAL;\n+\n+\tif (!(caps & V4L2_CAP_TIMEPERFRAME))\n+\t\treturn -ENOTSUP;\n+\n+\t*interval = v4l2FractionToMs(*frameInterval);\n+\n+\treturn 0;\n+}\n+\n std::vector<V4L2PixelFormat> V4L2VideoDevice::enumPixelformats(uint32_t code)\n {\n \tstd::vector<V4L2PixelFormat> formats;\n","prefixes":["RFC","v1","1/2"]}