From patchwork Mon Nov 6 11:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 741680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83F9AC4332F for ; Mon, 6 Nov 2023 11:00:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbjKFLA5 (ORCPT ); Mon, 6 Nov 2023 06:00:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231314AbjKFLA4 (ORCPT ); Mon, 6 Nov 2023 06:00:56 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29291D61 for ; Mon, 6 Nov 2023 03:00:51 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7789923612dso284194085a.0 for ; Mon, 06 Nov 2023 03:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699268449; x=1699873249; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; b=FiTrByRLW/8vJfATcUPWsChwGVkH6eyJeGKrUuSrXCLrNiZghNCqKTJZ0tdkr19due zrYUc5KWMmXhqQ0FeAc2a79NR7NMiFqIhhlPUq20Vl1L68eEGaawpGpijncQ6YJK+Z70 J5UOViZ+UDty4kb6liEiiR1k09mkWasmMaPxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699268449; x=1699873249; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; b=OKMJQBg5LiX1lj5//euC4D9YrAsGmdqk/Cs+e6nUVQiWu3GshQmfX6aIBORQvC5AKs clWeFQ/RgnQCqpKkOhGtQePcqI22hEnTuUsLuCbvHqYN0cZ4kJU+oxliZH1eVxoJuVuQ S9Pux8MPbb3cwNmI2XI+CACV0L8vZ7fbroOtW6OSTAmdURMIRWiQzKa9sjydSYGQlTJQ Yet5SJGPVxPQ0ZM9Y/1R5ptloEHY9McfyCqvFr0Xg5nwgeDxg4JDNqc3N1aQx2jpP7ao jWterv4xKz8Na6nCvrxtaNzl5dcUMipxXnTCcj48dBeiBkqBSvei7G73quYPmTqLG6kY ppLw== X-Gm-Message-State: AOJu0YyRuxO4oxu7G+py7+fvRJ2i722tZtJd9M4caYGzi1VlN3d9Cm5Z i9+Nt0UOGLTWTYXIBYCePEyVrw== X-Google-Smtp-Source: AGHT+IG/qsPTlEshuDlwqMcy6FG/FrxW8iH4rewTKHPzTxKQN6hMQGMOqp939jEyrOYymGJq5qcaGQ== X-Received: by 2002:a05:620a:2908:b0:76c:e2db:42b0 with SMTP id m8-20020a05620a290800b0076ce2db42b0mr34443254qkp.64.1699268449628; Mon, 06 Nov 2023 03:00:49 -0800 (PST) Received: from denia.c.googlers.com (112.49.199.35.bc.googleusercontent.com. [35.199.49.112]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm3208519qkl.0.2023.11.06.03.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:00:49 -0800 (PST) From: Ricardo Ribalda Date: Mon, 06 Nov 2023 11:00:30 +0000 Subject: [PATCH v3] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC MIME-Version: 1.0 Message-Id: <20231106-uvc-event-v3-1-c2d2fdaa2e2c@chromium.org> X-B4-Tracking: v=1; b=H4sIAE3HSGUC/22Nyw7CIBREf6VhLYZHROvK/zAueFwKSQsNtETT9 N+l3WiMyzOZM7OgDMlDRtdmQQmKzz6GCvzQIO1k6AB7UxkxwjgljOC5aAwFwoQNN1QpZbRiFtW +khmwSjJoV40w930NxwTWP/eD+6Oy83mK6bX/Fbql/6YLxRRzJSWB1or2xG7apTj4eTjG1KFtq LCPTIn4llmVz+YCXFhiLBU/8rqubxbOayb3AAAA To: Laurent Pinchart , Mauro Carvalho Chehab , Ricardo Ribalda Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Esker Wong X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add support for the frame_sync event, so user-space can become aware earlier of new frames. Suggested-by: Esker Wong Tested-by: Esker Wong Signed-off-by: Ricardo Ribalda --- We have measured a latency of around 30msecs between frame sync and dqbuf. --- Changes in v3: - Sent wrong patch as v2 sorry :S - Link to v2: https://lore.kernel.org/r/20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org Changes in v2: - Suggested by Laurent. Split sequence++ and event init. - Link to v1: https://lore.kernel.org/r/20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org --- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvc_video.c | 7 +++++++ 2 files changed, 9 insertions(+) --- base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 change-id: 20231020-uvc-event-d3d1bbbdcb2f Best regards, diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4988f03640a..9f3fb5fd2375 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1352,6 +1352,8 @@ static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh, switch (sub->type) { case V4L2_EVENT_CTRL: return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops); + case V4L2_EVENT_FRAME_SYNC: + return v4l2_event_subscribe(fh, sub, 0, NULL); default: return -EINVAL; } diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 28dde08ec6c5..6a9410133908 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1073,9 +1073,16 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, * that discontinuous sequence numbers always indicate lost frames. */ if (stream->last_fid != fid) { + struct v4l2_event event = { + .type = V4L2_EVENT_FRAME_SYNC, + }; + stream->sequence++; if (stream->sequence) uvc_video_stats_update(stream); + + event.u.frame_sync.frame_sequence = stream->sequence; + v4l2_event_queue(&stream->vdev, &event); } uvc_video_clock_decode(stream, buf, data, len);