From patchwork Fri Oct 23 04:19:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth Ramesh X-Patchwork-Id: 28569 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 DBE45C3261 for ; Fri, 23 Oct 2026 04:20:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9945568FA3; Fri, 23 Oct 2026 06:20:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Lkq7bPKQ"; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD3B068E07 for ; Fri, 23 Oct 2026 06:20:14 +0200 (CEST) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-3ac9f49b984so250191a91.1 for ; Thu, 22 Oct 2026 21:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792729213; x=1793334013; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mnS5gBqe6jalcRYEK2CejlPQx07yYwEAOhC2DbBtaEQ=; b=Lkq7bPKQd4q7IPvqaC5Dei48QB9wfu5CoIB6CHgdsFn/UKtDRr1tV4M8xTKHE6MJeU R4G7ZQOpVXMvppq9YI96dgw/2vqailIsRPcTjAepQTBy+rzUugkkYe3nlM6V33lwo5AX ghCgLS0RT3iB/CqRaMooRbtaivSqxp/Xy0BxlXamxUZiW8eUzM9sz08lhzYzgTnjNCtD RjCaabdwQQefJoklteR8KCTDaxM28CJ16ReWJrLnYCNVkzkBzz+DZDEJbiroIKcvdmdY OxKDyShkctJyMm2DkHCaQtLLWhQVfdzjoq9bSsC2jMdyjFrRYa9nPPr+Cmf59mNw8PUm sSeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792729213; x=1793334013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mnS5gBqe6jalcRYEK2CejlPQx07yYwEAOhC2DbBtaEQ=; b=RS63BSu4PHPVi0F0gUGY1OV5xy4AGoMkVXCH20ZAR40upYqxkvbmP1Uq8F9DZ96n+H m+j2k/yNY3Q7x2ntS5/EGrgaRActklob1yYrmisgHDH8XQQrVIMiUaO1honEwtjXxPAO dKusTg9lLhSD1Je7d3UaThlPim6sEnLDdPm2QjyBqbXhQ/RhArJxScRa1gQWkJGpcrn8 GcYWQqh6rCsi0LpgRTr93QFD6lONiFk/hwDOYG1QHRUzaQW/g1nKP6p2WBJrsYJvKLSf FdetL6Rn42B6vOa3zgAKoIuMW2hunuBU75//YVRUOctqrlWrFvRK17q/yKaSLXQv2Z+c FGOw== X-Gm-Message-State: AFq9FYJ42mfcE2tYD+ZLutl9PzndW6VyMIbpLli+kaR1JDgOkPzI38z0 ZiG7ta2IorRz/73F5BtIgQ/tSE412HFazKVRgpeUB91ExraLcPrVES5EC7NAynQ1 X-Gm-Gg: AYBFou3u5scV0r4Z2vFCcwM8BBeHdLJXifkAoA5ec0ESjKyQeYPLSavMgzFT6jXOuy7 OPjbFWqtCbSGj7TA1v8v00k2mesXSGQuyURlWj5rNnlk2glYCsCyMxBEo66bg+ESfHuTZE34SWm FD55zm7c/9O5GOphjp1nvqnHLzHnOUdxQ3SkwZIKwbYvN/nJ5JwC+4slLYBrbvaein4saosKJdc RaTTtAYOVJSG3n1+bsN0A0WftPaJNMEq+KJ5mPFwYl7dyAQ0UpU9s8aBMP4fWdCpI/rCEcU8Rex XJSjrQxo/8SA49EuAZ6wo/CG8+nZDdd+gnEwNMKQ/YLNwU1jPqiTbLSyVZydyJGLbSx7vOASoKv 1dnKNW0A0NB7OWiG3z0C9GqrcegCt3j0Lpxl5xAGYt3TQJJyWYu3CqXr6RD1byuf1mLWUozrMlZ JZB47X5p75ahbidCjCSgTTA8d7PEGalmP4ZgRXAeAF8tI/EmNGpZOM8/Tp2hfEZw0uKiTrAjDgm ZqCLpWpFhQwRgqh3ltvx82LlwxiFvoH8DnIfCBzs66+7NUceyi9fFrZ/+iC0YdYfFmjJiqfxQ7C Rmvl16lnpbZ5lzc= X-Received: by 2002:a17:90b:39b0:b0:3a0:c31d:80c with SMTP id 98e67ed59e1d1-3adce6001e3mr613352a91.9.1792729213113; Thu, 22 Oct 2026 21:20:13 -0700 (PDT) Received: from prasanth.alps.lineo.co.jp (vpn1.lineo.co.jp. [203.141.200.204]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ada47f8ff1sm7070741a91.0.2026.10.22.21.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 21:20:12 -0700 (PDT) From: Prasanth R To: libcamera-devel@lists.libcamera.org Cc: laurent.pinchart@ideasonboard.com, paul.elder@ideasonboard.com, kieran.bingham@ideasonboard.com, barnabas.pocze@ideasonboard.com, Prasanth R Subject: [PATCH v2 2/2] v4l2: v4l2_camera_proxy: Handle 64-bit time_t buffer ioctls Date: Fri, 23 Oct 2026 13:19:54 +0900 Message-Id: <20261023041954.913108-2-ragaprasanth@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023041954.913108-1-ragaprasanth@gmail.com> References: <20261023041954.913108-1-ragaprasanth@gmail.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" On 32-bit platforms the V4L2 compatibility layer is built with a 32-bit time_t, but applications are now usually built with _TIME_BITS=64. struct v4l2_buffer embeds a struct timeval, so for them it grows from 68 to 80 bytes on 32-bit Arm, and VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF and VIDIOC_PREPARE_BUF get different request numbers. These fail with ENOTTY and streaming does not work. Recognise the 64-bit time_t requests and convert the buffer to and from the native layout around the existing handlers. Only the timestamp differs between the two layouts. Buffer timestamps are monotonic, so they fit in the native timeval. Nothing changes where both layouts are the same. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/290 Signed-off-by: Prasanth R --- Tested on a Raspberry Pi 4 with a 32-bit userspace built with 64-bit time_t (the OpenEmbedded default for 32-bit Arm) and a UVC camera. src/v4l2/v4l2_camera_proxy.cpp | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 210c8e87..89e95198 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,64 @@ using namespace std::literals::chrono_literals; LOG_DECLARE_CATEGORY(V4L2Compat) +namespace { + +/* + * On 32-bit platforms the V4L2 compatibility layer is built with a 32-bit + * time_t (see src/v4l2/meson.build), while applications are commonly built + * with _TIME_BITS=64. struct v4l2_buffer embeds a struct timeval, so the two + * disagree on the structure size, and thus on the buffer ioctl numbers. Only + * the timestamp differs, the fields before and after it are the same. + */ +struct v4l2_buffer_time64 { + __u8 head[offsetof(struct v4l2_buffer, timestamp)]; + struct { + long long tv_sec; + long long tv_usec; + } timestamp; + __u8 tail[sizeof(struct v4l2_buffer) - offsetof(struct v4l2_buffer, timecode)]; +}; + +/* + * Return the native request for a 64-bit time_t buffer ioctl, or 0 if the + * request is not one or both layouts are the same. + */ +unsigned int bufferRequestFromTime64(unsigned int request) +{ + if (sizeof(struct v4l2_buffer_time64) == sizeof(struct v4l2_buffer)) + return 0; + + switch (request) { + case _IOWR('V', 9, struct v4l2_buffer_time64): /* VIDIOC_QUERYBUF */ + case _IOWR('V', 15, struct v4l2_buffer_time64): /* VIDIOC_QBUF */ + case _IOWR('V', 17, struct v4l2_buffer_time64): /* VIDIOC_DQBUF */ + case _IOWR('V', 93, struct v4l2_buffer_time64): /* VIDIOC_PREPARE_BUF */ + return _IOWR('V', _IOC_NR(request), struct v4l2_buffer); + default: + return 0; + } +} + +void bufferFromTime64(const struct v4l2_buffer_time64 &src, + struct v4l2_buffer *dst) +{ + memcpy(dst, src.head, sizeof(src.head)); + dst->timestamp.tv_sec = src.timestamp.tv_sec; + dst->timestamp.tv_usec = src.timestamp.tv_usec; + memcpy(&dst->timecode, src.tail, sizeof(src.tail)); +} + +void bufferToTime64(const struct v4l2_buffer &src, + struct v4l2_buffer_time64 *dst) +{ + memcpy(dst->head, &src, sizeof(dst->head)); + dst->timestamp.tv_sec = src.timestamp.tv_sec; + dst->timestamp.tv_usec = src.timestamp.tv_usec; + memcpy(dst->tail, &src.timecode, sizeof(dst->tail)); +} + +} /* namespace */ + V4L2CameraProxy::V4L2CameraProxy(unsigned int index, std::shared_ptr camera) : refcount_(0), index_(index), bufferCount_(0), currentBuf_(0), @@ -875,6 +934,20 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long longRequest, void return -1; } + /* + * Translate buffer ioctls from applications built with a 64-bit + * time_t to the native struct v4l2_buffer layout. + */ + struct v4l2_buffer_time64 *buf64 = nullptr; + struct v4l2_buffer buf = {}; + unsigned int bufRequest = bufferRequestFromTime64(request); + if (bufRequest) { + buf64 = static_cast(arg); + bufferFromTime64(*buf64, &buf); + request = bufRequest; + arg = &buf; + } + if (supportedIoctls_.find(request) == supportedIoctls_.end()) { errno = ENOTTY; return -1; @@ -960,6 +1033,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long longRequest, void return -1; } + if (buf64) + bufferToTime64(buf, buf64); + return ret; }