From patchwork Wed Oct 21 23:55:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth R X-Patchwork-Id: 28549 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 8EFA5C3261 for ; Wed, 21 Oct 2026 23:55:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A7B368F5E; Thu, 22 Oct 2026 01:55:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZCj0VwdL"; dkim-atps=neutral Received: from mail-dl1-x1233.google.com (mail-dl1-x1233.google.com [IPv6:2607:f8b0:4864:20::1233]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4340A68E58 for ; Thu, 22 Oct 2026 01:55:39 +0200 (CEST) Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-1517bda04a0so1311378c88.0 for ; Wed, 21 Oct 2026 16:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792626937; x=1793231737; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=rZgMn5tZJZ/RWEm79AUJeikjiPxyj6ebEDqS9nXQK+4=; b=ZCj0VwdLLMPHiChua2WoV9wo23XK1rDkLCZr+NJ+mLb6ESsXSHVQb8GPrKpOhY2HGp 5qLbPaP7Hmkds6bS5M4JNCcccLc/ajvGLy9l1bNfWlHoxF5uUbhLfVsOS+Qe9rO5HtuQ zeMV6m9njKOvpWkCDK5KiNiH+Nrvz38592lqVaj6qQ7b16qd3Z5dMkAIW+p72AuRm9sg ExmUw2+ZFBXlzaN18zJkY2ZQrXMwqQqastgVVzwoh0Dkqh5vKGTCN0TXfdG4CV772yze +KYAlTkxlfT5W1JMV91bAwGkiR8WJZIo38P4kYKKs0FVgSjWy3inbF6zaQAWYGUPIqeU D+vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792626937; x=1793231737; h=content-transfer-encoding:mime-version: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=rZgMn5tZJZ/RWEm79AUJeikjiPxyj6ebEDqS9nXQK+4=; b=Fs72dv+aVOIDqELFBhma8ycPUW7dULkBs7f40n3/e1NN57dlcqcB+5fYylkNatscxt dFCCTCa8o8+mefHpmSOA1VRDAnnliQz90YHgyb6QQ0ooE0ky7I2GZufA8qCOgbpZoDqI FmhhfOSlWeGw18ma+zITo02+DQ2xZ5HNoCIAxu3lDO6DbDvjiy4mPamf35CFoI02m+Nj 0WJQG3OkZV2pVnXoxV4V26h92Ncm1lRFC8Z4K//Sj88drUYkJD9z1cDYzOeJfk2IhnrA XG13JaGpoJqFR4meNAh4LSERrOGNjPHuAJQg6YyXxi1ntjCkuHp5uYK7oJ/K2NyCr4K0 JUsw== X-Gm-Message-State: AFq9FYLo7nR6vNHcVsXE1mGWW1X4GJbnmuFJ905VqqGxVjTPlE0eTh+6 cr6Rww9GT3Uqt8KID3vwH76SiZ2ehwUUKe0ORF50w2goWgHtxBdAK5/idET3PZZd X-Gm-Gg: AYBFou2FTkjr5xz9gIh7TJ7CXjE7MhOrk0C3cwR68IiJcrGJoZzrGYch1bgaTdUBg9W hsxy8bt1vXTom9iftZuhHYyXYrwkBDcNx5y6s5bHC/2/aollpRmLWbkrLvITlhouCbEKrdX1Qgs I+2vKObC32ger/BdhGaraZ2FwMd1BKiX0Zfia/MiwhHZCtzLAGApLPGrHVW2HMCFThCIVGnLRIC lT84qYVyA+xOFyZKjUPPqor4MAb5ACigckFCeVn7dHNyo5wO+V/F0wJ6kOhUrT4uTs9B7NAM+Nb cX3+AhSSvU/jqY6eZVN0Q8dtXzgGv+sovf7VCd2CD9mi3fSw1yc0004UGqRDvGIaEi3Gi1lsBFP 6a7xYgoViTREm4kroZkJydJWadIXvj6XEnvgdF8KYfBM+11FgRgozvfJlcVV3UTAsiCP9jr1tgo DyZueyxLck0C2nhlfahUpHvlSJ6mGM8V2XV8NQ2tsD6NQSHAiDdEOesVXnOGKcr1U7MIY/ya6NK UBUi8v8Vtqhy+CgPlI2U5laOJRQ6Wd6lRHXKX7AA9Nnwg/aOqS7zTojgVp5IqInJRccPo2nowhx LtG+mXddt5VBj3E= X-Received: by 2002:a05:7022:2507:b0:14c:efa5:ee7 with SMTP id a92af1059eb24-190a4d18cc9mr5798769c88.14.1792626937181; Wed, 21 Oct 2026 16:55:37 -0700 (PDT) Received: from prasanth.alps.lineo.co.jp (vpn1.lineo.co.jp. [203.141.200.204]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1903a180ca2sm8678137c88.6.2026.10.21.16.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2026 16:55:36 -0700 (PDT) From: Prasanth R To: libcamera-devel@lists.libcamera.org Cc: paul.elder@ideasonboard.com, barnabas.pocze@ideasonboard.com, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, Prasanth R Subject: [PATCH v2] v4l2: v4l2_camera_proxy: Handle 64-bit time_t buffer ioctls Date: Thu, 22 Oct 2026 08:55:24 +0900 Message-Id: <20261021235524.848347-1-ragaprasanth@gmail.com> X-Mailer: git-send-email 2.34.1 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 --- This applies on top of Paul's "v4l2: v4l2_compat: Handle __ioctl_time64" (https://patchwork.libcamera.org/patch/25925/), which is needed for the ioctls to reach the proxy at all. Tested on a Raspberry Pi 4 with a 32-bit, 64-bit time_t userspace (Yocto) and a UVC camera, libcamera v0.4.0 with both patches: libcamerify v4l2-ctl --stream-mmap --stream-count=30 streams at 15 fps, 5/5 runs; without this patch VIDIOC_QUERYBUF fails with ENOTTY. 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 559ffc617..554e81f8d 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), @@ -873,6 +932,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; @@ -955,6 +1028,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long longRequest, void return -1; } + if (buf64) + bufferToTime64(buf, buf64); + return ret; }