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: 161943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2575868vqu; Mon, 6 Nov 2023 03:01:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2XWi6bbrFPBQAeGx8id53GzDMjNFRpVSli22vabIzVI+juziTV+TcNuRZvTvhOkWFFML9 X-Received: by 2002:a05:6a20:6a09:b0:138:2fb8:6c48 with SMTP id p9-20020a056a206a0900b001382fb86c48mr25718972pzk.8.1699268499527; Mon, 06 Nov 2023 03:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699268499; cv=none; d=google.com; s=arc-20160816; b=Oy+RPLdlAw74p1sea/h8UPJqZoa5tY7CNNc15bT3FZzV0Z8rRdARWbcUOO3qmmfQzl 9JQePTz1c6CdJSOUbbUR+80vjRhDJNqd5IxxzM3GPaeQrzb7UdxImSQogPHhM/RlhjR5 SP5px1uYyAGChbmFrDs9TccGlTd83uPBq/i6zDT7s5sj5+nSd82AAoyOkIN6SSpk6cUT esM2qhiFNyrp02LSLb+PQ0WTyLWiljBrzh5GfHnr/ey0IDbHi3nwWh7WYpUSiGvZn5Nq M4B+T+xszno70emJgEf+FLzPMHkY6HqQnGkkZ4g8xxfePoz2tUxPsDJNMaDE2aCrB5x5 S3mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; fh=juUYT8HK8LGpjZXsXX23mnx6oe4bv7mQPkb8s5QbVrc=; b=cPK9/Hl3WNM9RprhNF/Mqdv+I4rPGnity/9tab+64nCht/eQy/mMXlv2o+++kQDCIZ aEfwrK9C80uriTLSdAk9hxONx0bA1czWxY147Om3UW5xN066nRzHQQa56sFqaKKKGGeD ElvqsO/qU5WC/dWc37hVS+CM/KRBt0/j522Fj0iGc6B5y50H5GxEsCtHTytKtCiaBX2f 5HCZrZrLidukLwmJ0qYIW3fW/DgAwKUXaKsoeEtoSrjVOcKA/RbtrWMCDhOd9oIqGmKJ O86wOFBWCcENWryBFpzEZDURywXcYTOJr44rqd/Ib7cHxxwmnrn7thTBazMDAtRKuDOq agWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FiTrByRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id jx5-20020a170903138500b001cc32df8ecesi7383388plb.513.2023.11.06.03.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FiTrByRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 75F55808E8E5; Mon, 6 Nov 2023 03:01:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbjKFLA6 (ORCPT + 36 others); Mon, 6 Nov 2023 06:00:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjKFLA4 (ORCPT ); Mon, 6 Nov 2023 06:00:56 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29B72D69 for ; Mon, 6 Nov 2023 03:00:51 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7789cb322deso282240385a.3 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=fO+G11OCUIwBh/yqabN4PfE356HfUHBr6EyHn0XC/7HYzgvVP+LzE4IB/Ay5iBDGPF PVi3G0JsTjKGw94TfvO1rCCNM/ADCOs7dXb1R/Tgr5/o8IrDmoyB2w/+SbDvMjCL6X6w Uze2NiIVVWftLUO9b6UnEhQBhQydAuHeha/PV7L+8ggFLZWaxNGDWZkSbsBGCSXT1x9W 31lBjF9l+X+2PlVMBZuoOBMnZPykso+n/YdqfRqxvUfdfoxRh3qeziajFzOn50ksh0Ns OxVw5Dr48Od7Jan4VjQIvIEQTNUrkMV1bvHdtVjiRGnM/BtLDl4VfnZEKJVg9lcLtSrq viag== X-Gm-Message-State: AOJu0Yws4PdJyZAKUmG76fP3kY0udGwr2EwHh7EH+P8QlKtOi2mbLn8k HeBftstesCNNecOPcE6zdO7Ydg== 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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 03:01:35 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781812166490629617 X-GMAIL-MSGID: 1781812166490629617 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);